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
43f0423d
Unverified
Commit
43f0423d
authored
Dec 29, 2018
by
Kubernetes Prow Robot
Committed by
GitHub
Dec 29, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #72419 from liggitt/allowed-proc-mount-validation
Validate PSP allowedProcMountTypes
parents
a65ba5f5
cb76da9f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
8 deletions
+34
-8
validation.go
pkg/apis/core/validation/validation.go
+7
-8
validation.go
pkg/apis/policy/validation/validation.go
+12
-0
validation_test.go
pkg/apis/policy/validation/validation_test.go
+15
-0
No files found.
pkg/apis/core/validation/validation.go
View file @
43f0423d
...
@@ -5221,8 +5221,8 @@ func ValidateSecurityContext(sc *core.SecurityContext, fldPath *field.Path) fiel
...
@@ -5221,8 +5221,8 @@ func ValidateSecurityContext(sc *core.SecurityContext, fldPath *field.Path) fiel
}
}
if
sc
.
ProcMount
!=
nil
{
if
sc
.
ProcMount
!=
nil
{
if
err
:=
IsValidProcMount
(
*
sc
.
ProcMount
);
err
!=
nil
{
if
err
:=
ValidateProcMountType
(
fldPath
.
Child
(
"procMount"
),
*
sc
.
ProcMount
);
err
!=
nil
{
allErrs
=
append
(
allErrs
,
field
.
NotSupported
(
fldPath
.
Child
(
"procMount"
),
*
sc
.
ProcMount
,
[]
string
{
string
(
core
.
DefaultProcMount
),
string
(
core
.
UnmaskedProcMount
)})
)
allErrs
=
append
(
allErrs
,
err
)
}
}
}
}
...
@@ -5323,13 +5323,12 @@ func IsDecremented(update, old *int32) bool {
...
@@ -5323,13 +5323,12 @@ func IsDecremented(update, old *int32) bool {
return
*
update
<
*
old
return
*
update
<
*
old
}
}
//
IsValidProcMount
tests that the argument is a valid ProcMountType.
//
ValidateProcMountType
tests that the argument is a valid ProcMountType.
func
IsValidProcMount
(
procMountType
core
.
ProcMountType
)
e
rror
{
func
ValidateProcMountType
(
fldPath
*
field
.
Path
,
procMountType
core
.
ProcMountType
)
*
field
.
E
rror
{
switch
procMountType
{
switch
procMountType
{
case
core
.
DefaultProcMount
:
case
core
.
DefaultProcMount
,
core
.
UnmaskedProcMount
:
case
core
.
UnmaskedProcMount
:
return
nil
default
:
default
:
return
f
mt
.
Errorf
(
"unsupported ProcMount type %s"
,
procMountType
)
return
f
ield
.
NotSupported
(
fldPath
,
procMountType
,
[]
string
{
string
(
core
.
DefaultProcMount
),
string
(
core
.
UnmaskedProcMount
)}
)
}
}
return
nil
}
}
pkg/apis/policy/validation/validation.go
View file @
43f0423d
...
@@ -121,6 +121,7 @@ func ValidatePodSecurityPolicySpec(spec *policy.PodSecurityPolicySpec, fldPath *
...
@@ -121,6 +121,7 @@ func ValidatePodSecurityPolicySpec(spec *policy.PodSecurityPolicySpec, fldPath *
allErrs
=
append
(
allErrs
,
validatePSPCapsAgainstDrops
(
spec
.
RequiredDropCapabilities
,
spec
.
DefaultAddCapabilities
,
field
.
NewPath
(
"defaultAddCapabilities"
))
...
)
allErrs
=
append
(
allErrs
,
validatePSPCapsAgainstDrops
(
spec
.
RequiredDropCapabilities
,
spec
.
DefaultAddCapabilities
,
field
.
NewPath
(
"defaultAddCapabilities"
))
...
)
allErrs
=
append
(
allErrs
,
validatePSPCapsAgainstDrops
(
spec
.
RequiredDropCapabilities
,
spec
.
AllowedCapabilities
,
field
.
NewPath
(
"allowedCapabilities"
))
...
)
allErrs
=
append
(
allErrs
,
validatePSPCapsAgainstDrops
(
spec
.
RequiredDropCapabilities
,
spec
.
AllowedCapabilities
,
field
.
NewPath
(
"allowedCapabilities"
))
...
)
allErrs
=
append
(
allErrs
,
validatePSPDefaultAllowPrivilegeEscalation
(
fldPath
.
Child
(
"defaultAllowPrivilegeEscalation"
),
spec
.
DefaultAllowPrivilegeEscalation
,
spec
.
AllowPrivilegeEscalation
)
...
)
allErrs
=
append
(
allErrs
,
validatePSPDefaultAllowPrivilegeEscalation
(
fldPath
.
Child
(
"defaultAllowPrivilegeEscalation"
),
spec
.
DefaultAllowPrivilegeEscalation
,
spec
.
AllowPrivilegeEscalation
)
...
)
allErrs
=
append
(
allErrs
,
validatePSPAllowedProcMountTypes
(
fldPath
.
Child
(
"allowedProcMountTypes"
),
spec
.
AllowedProcMountTypes
)
...
)
allErrs
=
append
(
allErrs
,
validatePSPAllowedHostPaths
(
fldPath
.
Child
(
"allowedHostPaths"
),
spec
.
AllowedHostPaths
)
...
)
allErrs
=
append
(
allErrs
,
validatePSPAllowedHostPaths
(
fldPath
.
Child
(
"allowedHostPaths"
),
spec
.
AllowedHostPaths
)
...
)
allErrs
=
append
(
allErrs
,
validatePSPAllowedFlexVolumes
(
fldPath
.
Child
(
"allowedFlexVolumes"
),
spec
.
AllowedFlexVolumes
)
...
)
allErrs
=
append
(
allErrs
,
validatePSPAllowedFlexVolumes
(
fldPath
.
Child
(
"allowedFlexVolumes"
),
spec
.
AllowedFlexVolumes
)
...
)
allErrs
=
append
(
allErrs
,
validatePodSecurityPolicySysctls
(
fldPath
.
Child
(
"allowedUnsafeSysctls"
),
spec
.
AllowedUnsafeSysctls
)
...
)
allErrs
=
append
(
allErrs
,
validatePodSecurityPolicySysctls
(
fldPath
.
Child
(
"allowedUnsafeSysctls"
),
spec
.
AllowedUnsafeSysctls
)
...
)
...
@@ -328,6 +329,17 @@ func validatePSPDefaultAllowPrivilegeEscalation(fldPath *field.Path, defaultAllo
...
@@ -328,6 +329,17 @@ func validatePSPDefaultAllowPrivilegeEscalation(fldPath *field.Path, defaultAllo
return
allErrs
return
allErrs
}
}
// validatePSPAllowedProcMountTypes validates the DefaultAllowPrivilegeEscalation field against the AllowPrivilegeEscalation field of a PodSecurityPolicy.
func
validatePSPAllowedProcMountTypes
(
fldPath
*
field
.
Path
,
allowedProcMountTypes
[]
core
.
ProcMountType
)
field
.
ErrorList
{
allErrs
:=
field
.
ErrorList
{}
for
i
,
procMountType
:=
range
allowedProcMountTypes
{
if
err
:=
apivalidation
.
ValidateProcMountType
(
fldPath
.
Index
(
i
),
procMountType
);
err
!=
nil
{
allErrs
=
append
(
allErrs
,
err
)
}
}
return
allErrs
}
const
sysctlPatternSegmentFmt
string
=
"([a-z0-9][-_a-z0-9]*)?[a-z0-9*]"
const
sysctlPatternSegmentFmt
string
=
"([a-z0-9][-_a-z0-9]*)?[a-z0-9*]"
const
SysctlPatternFmt
string
=
"("
+
apivalidation
.
SysctlSegmentFmt
+
"
\\
.)*"
+
sysctlPatternSegmentFmt
const
SysctlPatternFmt
string
=
"("
+
apivalidation
.
SysctlSegmentFmt
+
"
\\
.)*"
+
sysctlPatternSegmentFmt
...
...
pkg/apis/policy/validation/validation_test.go
View file @
43f0423d
...
@@ -384,6 +384,9 @@ func TestValidatePodSecurityPolicy(t *testing.T) {
...
@@ -384,6 +384,9 @@ func TestValidatePodSecurityPolicy(t *testing.T) {
nonEmptyFlexVolumes
:=
validPSP
()
nonEmptyFlexVolumes
:=
validPSP
()
nonEmptyFlexVolumes
.
Spec
.
AllowedFlexVolumes
=
[]
policy
.
AllowedFlexVolume
{{
Driver
:
"example/driver"
}}
nonEmptyFlexVolumes
.
Spec
.
AllowedFlexVolumes
=
[]
policy
.
AllowedFlexVolume
{{
Driver
:
"example/driver"
}}
invalidProcMount
:=
validPSP
()
invalidProcMount
.
Spec
.
AllowedProcMountTypes
=
[]
api
.
ProcMountType
{
api
.
ProcMountType
(
"bogus"
)}
type
testCase
struct
{
type
testCase
struct
{
psp
*
policy
.
PodSecurityPolicy
psp
*
policy
.
PodSecurityPolicy
errorType
field
.
ErrorType
errorType
field
.
ErrorType
...
@@ -550,6 +553,11 @@ func TestValidatePodSecurityPolicy(t *testing.T) {
...
@@ -550,6 +553,11 @@ func TestValidatePodSecurityPolicy(t *testing.T) {
errorType
:
field
.
ErrorTypeRequired
,
errorType
:
field
.
ErrorTypeRequired
,
errorDetail
:
"must specify a driver"
,
errorDetail
:
"must specify a driver"
,
},
},
"invalid allowedProcMountTypes"
:
{
psp
:
invalidProcMount
,
errorType
:
field
.
ErrorTypeNotSupported
,
errorDetail
:
`supported values: "Default", "Unmasked"`
,
},
}
}
for
k
,
v
:=
range
errorCases
{
for
k
,
v
:=
range
errorCases
{
...
@@ -643,6 +651,10 @@ func TestValidatePodSecurityPolicy(t *testing.T) {
...
@@ -643,6 +651,10 @@ func TestValidatePodSecurityPolicy(t *testing.T) {
flexvolumeWhenAllVolumesAllowed
.
Spec
.
AllowedFlexVolumes
=
[]
policy
.
AllowedFlexVolume
{
flexvolumeWhenAllVolumesAllowed
.
Spec
.
AllowedFlexVolumes
=
[]
policy
.
AllowedFlexVolume
{
{
Driver
:
"example/driver2"
},
{
Driver
:
"example/driver2"
},
}
}
validProcMount
:=
validPSP
()
validProcMount
.
Spec
.
AllowedProcMountTypes
=
[]
api
.
ProcMountType
{
api
.
DefaultProcMount
,
api
.
UnmaskedProcMount
}
successCases
:=
map
[
string
]
struct
{
successCases
:=
map
[
string
]
struct
{
psp
*
policy
.
PodSecurityPolicy
psp
*
policy
.
PodSecurityPolicy
}{
}{
...
@@ -682,6 +694,9 @@ func TestValidatePodSecurityPolicy(t *testing.T) {
...
@@ -682,6 +694,9 @@ func TestValidatePodSecurityPolicy(t *testing.T) {
"allow white-listed flexVolume when all volumes are allowed"
:
{
"allow white-listed flexVolume when all volumes are allowed"
:
{
psp
:
flexvolumeWhenAllVolumesAllowed
,
psp
:
flexvolumeWhenAllVolumesAllowed
,
},
},
"valid allowedProcMountTypes"
:
{
psp
:
validProcMount
,
},
}
}
for
k
,
v
:=
range
successCases
{
for
k
,
v
:=
range
successCases
{
...
...
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