mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
Merge pull request #126011 from haircommander/sc-userns
securitycontext: add support for HostUsers
This commit is contained in:
commit
5b3040d12a
@ -27,6 +27,7 @@ type PodSecurityContextAccessor interface {
|
|||||||
HostNetwork() bool
|
HostNetwork() bool
|
||||||
HostPID() bool
|
HostPID() bool
|
||||||
HostIPC() bool
|
HostIPC() bool
|
||||||
|
HostUsers() *bool
|
||||||
SELinuxOptions() *api.SELinuxOptions
|
SELinuxOptions() *api.SELinuxOptions
|
||||||
RunAsUser() *int64
|
RunAsUser() *int64
|
||||||
RunAsGroup() *int64
|
RunAsGroup() *int64
|
||||||
@ -43,6 +44,7 @@ type PodSecurityContextMutator interface {
|
|||||||
SetHostNetwork(bool)
|
SetHostNetwork(bool)
|
||||||
SetHostPID(bool)
|
SetHostPID(bool)
|
||||||
SetHostIPC(bool)
|
SetHostIPC(bool)
|
||||||
|
SetHostUsers(*bool)
|
||||||
SetSELinuxOptions(*api.SELinuxOptions)
|
SetSELinuxOptions(*api.SELinuxOptions)
|
||||||
SetRunAsUser(*int64)
|
SetRunAsUser(*int64)
|
||||||
SetRunAsGroup(*int64)
|
SetRunAsGroup(*int64)
|
||||||
@ -120,6 +122,19 @@ func (w *podSecurityContextWrapper) SetHostIPC(v bool) {
|
|||||||
w.ensurePodSC()
|
w.ensurePodSC()
|
||||||
w.podSC.HostIPC = v
|
w.podSC.HostIPC = v
|
||||||
}
|
}
|
||||||
|
func (w *podSecurityContextWrapper) HostUsers() *bool {
|
||||||
|
if w.podSC == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return w.podSC.HostUsers
|
||||||
|
}
|
||||||
|
func (w *podSecurityContextWrapper) SetHostUsers(v *bool) {
|
||||||
|
if w.podSC == nil && v == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
w.ensurePodSC()
|
||||||
|
w.podSC.HostUsers = v
|
||||||
|
}
|
||||||
func (w *podSecurityContextWrapper) SELinuxOptions() *api.SELinuxOptions {
|
func (w *podSecurityContextWrapper) SELinuxOptions() *api.SELinuxOptions {
|
||||||
if w.podSC == nil {
|
if w.podSC == nil {
|
||||||
return nil
|
return nil
|
||||||
|
@ -30,6 +30,7 @@ func TestPodSecurityContextAccessor(t *testing.T) {
|
|||||||
runAsUser := int64(1)
|
runAsUser := int64(1)
|
||||||
runAsGroup := int64(1)
|
runAsGroup := int64(1)
|
||||||
runAsNonRoot := true
|
runAsNonRoot := true
|
||||||
|
hostUsers := false
|
||||||
|
|
||||||
testcases := []*api.PodSecurityContext{
|
testcases := []*api.PodSecurityContext{
|
||||||
nil,
|
nil,
|
||||||
@ -38,6 +39,7 @@ func TestPodSecurityContextAccessor(t *testing.T) {
|
|||||||
{HostIPC: true},
|
{HostIPC: true},
|
||||||
{HostNetwork: true},
|
{HostNetwork: true},
|
||||||
{HostPID: true},
|
{HostPID: true},
|
||||||
|
{HostUsers: &hostUsers},
|
||||||
{RunAsNonRoot: &runAsNonRoot},
|
{RunAsNonRoot: &runAsNonRoot},
|
||||||
{RunAsUser: &runAsUser},
|
{RunAsUser: &runAsUser},
|
||||||
{RunAsGroup: &runAsGroup},
|
{RunAsGroup: &runAsGroup},
|
||||||
@ -66,6 +68,9 @@ func TestPodSecurityContextAccessor(t *testing.T) {
|
|||||||
if v := a.HostPID(); !reflect.DeepEqual(expected.HostPID, v) {
|
if v := a.HostPID(); !reflect.DeepEqual(expected.HostPID, v) {
|
||||||
t.Errorf("%d: expected %#v, got %#v", i, expected.HostPID, v)
|
t.Errorf("%d: expected %#v, got %#v", i, expected.HostPID, v)
|
||||||
}
|
}
|
||||||
|
if v := a.HostUsers(); !reflect.DeepEqual(expected.HostUsers, v) {
|
||||||
|
t.Errorf("%d: expected %#v, got %#v", i, expected.HostUsers, v)
|
||||||
|
}
|
||||||
if v := a.RunAsNonRoot(); !reflect.DeepEqual(expected.RunAsNonRoot, v) {
|
if v := a.RunAsNonRoot(); !reflect.DeepEqual(expected.RunAsNonRoot, v) {
|
||||||
t.Errorf("%d: expected %#v, got %#v", i, expected.RunAsNonRoot, v)
|
t.Errorf("%d: expected %#v, got %#v", i, expected.RunAsNonRoot, v)
|
||||||
}
|
}
|
||||||
@ -103,6 +108,7 @@ func TestPodSecurityContextMutator(t *testing.T) {
|
|||||||
HostNetwork: true,
|
HostNetwork: true,
|
||||||
HostIPC: true,
|
HostIPC: true,
|
||||||
HostPID: true,
|
HostPID: true,
|
||||||
|
HostUsers: nil,
|
||||||
SELinuxOptions: &api.SELinuxOptions{},
|
SELinuxOptions: &api.SELinuxOptions{},
|
||||||
RunAsUser: nil,
|
RunAsUser: nil,
|
||||||
RunAsGroup: nil,
|
RunAsGroup: nil,
|
||||||
@ -133,6 +139,7 @@ func TestPodSecurityContextMutator(t *testing.T) {
|
|||||||
m.SetHostNetwork(m.HostNetwork())
|
m.SetHostNetwork(m.HostNetwork())
|
||||||
m.SetHostIPC(m.HostIPC())
|
m.SetHostIPC(m.HostIPC())
|
||||||
m.SetHostPID(m.HostPID())
|
m.SetHostPID(m.HostPID())
|
||||||
|
m.SetHostUsers(m.HostUsers())
|
||||||
m.SetRunAsNonRoot(m.RunAsNonRoot())
|
m.SetRunAsNonRoot(m.RunAsNonRoot())
|
||||||
m.SetRunAsUser(m.RunAsUser())
|
m.SetRunAsUser(m.RunAsUser())
|
||||||
m.SetRunAsGroup(m.RunAsGroup())
|
m.SetRunAsGroup(m.RunAsGroup())
|
||||||
@ -196,6 +203,19 @@ func TestPodSecurityContextMutator(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HostUsers
|
||||||
|
{
|
||||||
|
modifiedSC := nonNilSC(tc.newSC())
|
||||||
|
m := NewPodSecurityContextMutator(tc.newSC())
|
||||||
|
b := false
|
||||||
|
modifiedSC.HostUsers = &b
|
||||||
|
m.SetHostUsers(&b)
|
||||||
|
if !reflect.DeepEqual(m.PodSecurityContext(), modifiedSC) {
|
||||||
|
t.Errorf("%s: unexpected object:\n%s", k, diff.ObjectGoPrintSideBySide(modifiedSC, m.PodSecurityContext()))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// RunAsNonRoot
|
// RunAsNonRoot
|
||||||
{
|
{
|
||||||
modifiedSC := nonNilSC(tc.newSC())
|
modifiedSC := nonNilSC(tc.newSC())
|
||||||
|
Loading…
Reference in New Issue
Block a user