Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
b45b809f
Unverified
Commit
b45b809f
authored
Oct 05, 2017
by
Jordan Liggitt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PodSecurityPolicy: Do not mutate nil privileged field to false
parent
77b83e44
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
17 deletions
+31
-17
provider.go
pkg/security/podsecuritypolicy/provider.go
+1
-6
admission_test.go
...kg/admission/security/podsecuritypolicy/admission_test.go
+30
-11
No files found.
pkg/security/podsecuritypolicy/provider.go
View file @
b45b809f
...
...
@@ -157,11 +157,6 @@ func (s *simpleProvider) CreateContainerSecurityContext(pod *api.Pod, container
return
nil
,
nil
,
err
}
if
sc
.
Privileged
==
nil
{
priv
:=
false
sc
.
Privileged
=
&
priv
}
// if we're using the non-root strategy set the marker that this container should not be
// run as root which will signal to the kubelet to do a final check either on the runAsUser
// or, if runAsUser is not set, the image UID will be checked.
...
...
@@ -284,7 +279,7 @@ func (s *simpleProvider) ValidateContainerSecurityContext(pod *api.Pod, containe
allErrs
=
append
(
allErrs
,
s
.
strategies
.
AppArmorStrategy
.
Validate
(
pod
,
container
)
...
)
allErrs
=
append
(
allErrs
,
s
.
strategies
.
SeccompStrategy
.
ValidateContainer
(
pod
,
container
)
...
)
if
!
s
.
psp
.
Spec
.
Privileged
&&
*
sc
.
Privileged
{
if
!
s
.
psp
.
Spec
.
Privileged
&&
sc
.
Privileged
!=
nil
&&
*
sc
.
Privileged
{
allErrs
=
append
(
allErrs
,
field
.
Invalid
(
fldPath
.
Child
(
"privileged"
),
*
sc
.
Privileged
,
"Privileged containers are not allowed"
))
}
...
...
plugin/pkg/admission/security/podsecuritypolicy/admission_test.go
View file @
b45b809f
...
...
@@ -204,37 +204,54 @@ func TestAdmitPrivileged(t *testing.T) {
privilegedPSP
.
Name
=
"priv"
privilegedPSP
.
Spec
.
Privileged
=
true
trueValue
:=
true
falseValue
:=
false
tests
:=
map
[
string
]
struct
{
pod
*
kapi
.
Pod
psps
[]
*
extensions
.
PodSecurityPolicy
shouldPass
bool
expectedPriv
bool
expectedPriv
*
bool
expectedPSP
string
}{
"pod with
out priv request
allowed under non priv PSP"
:
{
"pod with
priv=nil
allowed under non priv PSP"
:
{
pod
:
goodPod
(),
psps
:
[]
*
extensions
.
PodSecurityPolicy
{
nonPrivilegedPSP
},
shouldPass
:
true
,
expectedPriv
:
false
,
expectedPriv
:
nil
,
expectedPSP
:
nonPrivilegedPSP
.
Name
,
},
"pod with
out priv request
allowed under priv PSP"
:
{
"pod with
priv=nil
allowed under priv PSP"
:
{
pod
:
goodPod
(),
psps
:
[]
*
extensions
.
PodSecurityPolicy
{
privilegedPSP
},
shouldPass
:
true
,
expectedPriv
:
false
,
expectedPriv
:
nil
,
expectedPSP
:
privilegedPSP
.
Name
,
},
"pod with priv=false allowed under non priv PSP"
:
{
pod
:
createPodWithPriv
(
false
),
psps
:
[]
*
extensions
.
PodSecurityPolicy
{
nonPrivilegedPSP
},
shouldPass
:
true
,
expectedPriv
:
&
falseValue
,
expectedPSP
:
nonPrivilegedPSP
.
Name
,
},
"pod with priv=false allowed under priv PSP"
:
{
pod
:
createPodWithPriv
(
false
),
psps
:
[]
*
extensions
.
PodSecurityPolicy
{
privilegedPSP
},
shouldPass
:
true
,
expectedPriv
:
&
falseValue
,
expectedPSP
:
privilegedPSP
.
Name
,
},
"pod with priv
request
denied by non priv PSP"
:
{
"pod with priv
=true
denied by non priv PSP"
:
{
pod
:
createPodWithPriv
(
true
),
psps
:
[]
*
extensions
.
PodSecurityPolicy
{
nonPrivilegedPSP
},
shouldPass
:
false
,
},
"pod with priv
request
allowed by priv PSP"
:
{
"pod with priv
=true
allowed by priv PSP"
:
{
pod
:
createPodWithPriv
(
true
),
psps
:
[]
*
extensions
.
PodSecurityPolicy
{
nonPrivilegedPSP
,
privilegedPSP
},
shouldPass
:
true
,
expectedPriv
:
tr
ue
,
expectedPriv
:
&
trueVal
ue
,
expectedPSP
:
privilegedPSP
.
Name
,
},
}
...
...
@@ -243,9 +260,11 @@ func TestAdmitPrivileged(t *testing.T) {
testPSPAdmit
(
k
,
v
.
psps
,
v
.
pod
,
v
.
shouldPass
,
v
.
expectedPSP
,
t
)
if
v
.
shouldPass
{
if
v
.
pod
.
Spec
.
Containers
[
0
]
.
SecurityContext
.
Privileged
==
nil
||
*
v
.
pod
.
Spec
.
Containers
[
0
]
.
SecurityContext
.
Privileged
!=
v
.
expectedPriv
{
t
.
Errorf
(
"%s expected privileged to be %t"
,
k
,
v
.
expectedPriv
)
priv
:=
v
.
pod
.
Spec
.
Containers
[
0
]
.
SecurityContext
.
Privileged
if
(
priv
==
nil
)
!=
(
v
.
expectedPriv
==
nil
)
{
t
.
Errorf
(
"%s expected privileged to be %v, got %v"
,
k
,
v
.
expectedPriv
,
priv
)
}
else
if
priv
!=
nil
&&
*
priv
!=
*
v
.
expectedPriv
{
t
.
Errorf
(
"%s expected privileged to be %v, got %v"
,
k
,
*
v
.
expectedPriv
,
*
priv
)
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment