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
9342eff2
Commit
9342eff2
authored
Feb 14, 2018
by
wackxu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rename func ValidatePodSecurityContext to ValidatePod
parent
50e28a5d
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
10 additions
and
12 deletions
+10
-12
provider.go
pkg/security/podsecuritypolicy/provider.go
+2
-4
provider_test.go
pkg/security/podsecuritypolicy/provider_test.go
+5
-5
types.go
pkg/security/podsecuritypolicy/types.go
+2
-2
admission.go
plugin/pkg/admission/security/podsecuritypolicy/admission.go
+1
-1
No files found.
pkg/security/podsecuritypolicy/provider.go
View file @
9342eff2
...
...
@@ -179,8 +179,8 @@ func (s *simpleProvider) DefaultContainerSecurityContext(pod *api.Pod, container
return
nil
}
//
Ensure a pod's SecurityContext
is in compliance with the given constraints.
func
(
s
*
simpleProvider
)
ValidatePod
SecurityContext
(
pod
*
api
.
Pod
,
fldPath
*
field
.
Path
)
field
.
ErrorList
{
//
ValidatePod ensure a pod
is in compliance with the given constraints.
func
(
s
*
simpleProvider
)
ValidatePod
(
pod
*
api
.
Pod
,
fldPath
*
field
.
Path
)
field
.
ErrorList
{
allErrs
:=
field
.
ErrorList
{}
sc
:=
securitycontext
.
NewPodSecurityContextAccessor
(
pod
.
Spec
.
SecurityContext
)
...
...
@@ -209,8 +209,6 @@ func (s *simpleProvider) ValidatePodSecurityContext(pod *api.Pod, fldPath *field
allErrs
=
append
(
allErrs
,
s
.
strategies
.
SysctlsStrategy
.
Validate
(
pod
)
...
)
// TODO(tallclair): ValidatePodSecurityContext should be renamed to ValidatePod since its scope
// is not limited to the PodSecurityContext.
if
len
(
pod
.
Spec
.
Volumes
)
>
0
{
allowsAllVolumeTypes
:=
psputil
.
PSPAllowsAllVolumes
(
s
.
psp
)
allowedVolumes
:=
psputil
.
FSTypeToStringSet
(
s
.
psp
.
Spec
.
Volumes
)
...
...
pkg/security/podsecuritypolicy/provider_test.go
View file @
9342eff2
...
...
@@ -369,7 +369,7 @@ func TestValidatePodSecurityContextFailures(t *testing.T) {
if
err
!=
nil
{
t
.
Fatalf
(
"unable to create provider %v"
,
err
)
}
errs
:=
provider
.
ValidatePod
SecurityContext
(
v
.
pod
,
field
.
NewPath
(
""
))
errs
:=
provider
.
ValidatePod
(
v
.
pod
,
field
.
NewPath
(
""
))
if
len
(
errs
)
==
0
{
t
.
Errorf
(
"%s expected validation failure but did not receive errors"
,
k
)
continue
...
...
@@ -732,7 +732,7 @@ func TestValidatePodSecurityContextSuccess(t *testing.T) {
if
err
!=
nil
{
t
.
Fatalf
(
"unable to create provider %v"
,
err
)
}
errs
:=
provider
.
ValidatePod
SecurityContext
(
v
.
pod
,
field
.
NewPath
(
""
))
errs
:=
provider
.
ValidatePod
(
v
.
pod
,
field
.
NewPath
(
""
))
if
len
(
errs
)
!=
0
{
t
.
Errorf
(
"%s expected validation pass but received errors %v"
,
k
,
errs
)
continue
...
...
@@ -1094,7 +1094,7 @@ func TestValidateAllowedVolumes(t *testing.T) {
}
// expect a denial for this PSP and test the error message to ensure it's related to the volumesource
errs
:=
provider
.
ValidatePod
SecurityContext
(
pod
,
field
.
NewPath
(
""
))
errs
:=
provider
.
ValidatePod
(
pod
,
field
.
NewPath
(
""
))
if
len
(
errs
)
!=
1
{
t
.
Errorf
(
"expected exactly 1 error for %s but got %v"
,
fieldVal
.
Name
,
errs
)
}
else
{
...
...
@@ -1105,14 +1105,14 @@ func TestValidateAllowedVolumes(t *testing.T) {
// now add the fstype directly to the psp and it should validate
psp
.
Spec
.
Volumes
=
[]
extensions
.
FSType
{
fsType
}
errs
=
provider
.
ValidatePod
SecurityContext
(
pod
,
field
.
NewPath
(
""
))
errs
=
provider
.
ValidatePod
(
pod
,
field
.
NewPath
(
""
))
if
len
(
errs
)
!=
0
{
t
.
Errorf
(
"directly allowing volume expected no errors for %s but got %v"
,
fieldVal
.
Name
,
errs
)
}
// now change the psp to allow any volumes and the pod should still validate
psp
.
Spec
.
Volumes
=
[]
extensions
.
FSType
{
extensions
.
All
}
errs
=
provider
.
ValidatePod
SecurityContext
(
pod
,
field
.
NewPath
(
""
))
errs
=
provider
.
ValidatePod
(
pod
,
field
.
NewPath
(
""
))
if
len
(
errs
)
!=
0
{
t
.
Errorf
(
"wildcard volume expected no errors for %s but got %v"
,
fieldVal
.
Name
,
errs
)
}
...
...
pkg/security/podsecuritypolicy/types.go
View file @
9342eff2
...
...
@@ -38,8 +38,8 @@ type Provider interface {
// DefaultContainerSecurityContext sets the default values of the required but not filled fields.
// It modifies the SecurityContext of the container and annotations of the pod.
DefaultContainerSecurityContext
(
pod
*
api
.
Pod
,
container
*
api
.
Container
)
error
// Ensure a pod
's SecurityContext
is in compliance with the given constraints.
ValidatePod
SecurityContext
(
pod
*
api
.
Pod
,
fldPath
*
field
.
Path
)
field
.
ErrorList
// Ensure a pod is in compliance with the given constraints.
ValidatePod
(
pod
*
api
.
Pod
,
fldPath
*
field
.
Path
)
field
.
ErrorList
// Ensure a container's SecurityContext is in compliance with the given constraints
ValidateContainerSecurityContext
(
pod
*
api
.
Pod
,
container
*
api
.
Container
,
fldPath
*
field
.
Path
)
field
.
ErrorList
// Get the name of the PSP that this provider was initialized with.
...
...
plugin/pkg/admission/security/podsecuritypolicy/admission.go
View file @
9342eff2
...
...
@@ -301,7 +301,7 @@ func assignSecurityContext(provider psp.Provider, pod *api.Pod, fldPath *field.P
errs
=
append
(
errs
,
field
.
Invalid
(
field
.
NewPath
(
"spec"
,
"securityContext"
),
pod
.
Spec
.
SecurityContext
,
err
.
Error
()))
}
errs
=
append
(
errs
,
provider
.
ValidatePod
SecurityContext
(
pod
,
field
.
NewPath
(
"spec"
,
"securityContext"
))
...
)
errs
=
append
(
errs
,
provider
.
ValidatePod
(
pod
,
field
.
NewPath
(
"spec"
,
"securityContext"
))
...
)
for
i
:=
range
pod
.
Spec
.
InitContainers
{
err
:=
provider
.
DefaultContainerSecurityContext
(
pod
,
&
pod
.
Spec
.
InitContainers
[
i
])
...
...
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