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
d4c85e97
Commit
d4c85e97
authored
Dec 27, 2018
by
Zheng Dayu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Validation on RunAsGroup - Update DropDisabled[Alpha]Fields behaviour
parent
13e59ab9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
21 deletions
+24
-21
util.go
pkg/api/pod/util.go
+23
-17
util.go
pkg/api/podsecuritypolicy/util.go
+1
-4
No files found.
pkg/api/pod/util.go
View file @
d4c85e97
...
@@ -279,7 +279,7 @@ func DropDisabledFields(podSpec, oldPodSpec *api.PodSpec) {
...
@@ -279,7 +279,7 @@ func DropDisabledFields(podSpec, oldPodSpec *api.PodSpec) {
// dropDisabledRunAsGroupField removes disabled fields from PodSpec related
// dropDisabledRunAsGroupField removes disabled fields from PodSpec related
// to RunAsGroup
// to RunAsGroup
func
dropDisabledRunAsGroupField
(
podSpec
,
oldPodSpec
*
api
.
PodSpec
)
{
func
dropDisabledRunAsGroupField
(
podSpec
,
oldPodSpec
*
api
.
PodSpec
)
{
if
!
utilfeature
.
DefaultFeatureGate
.
Enabled
(
features
.
RunAsGroup
)
{
if
!
utilfeature
.
DefaultFeatureGate
.
Enabled
(
features
.
RunAsGroup
)
&&
!
runAsGroupInUse
(
oldPodSpec
)
{
if
podSpec
.
SecurityContext
!=
nil
{
if
podSpec
.
SecurityContext
!=
nil
{
podSpec
.
SecurityContext
.
RunAsGroup
=
nil
podSpec
.
SecurityContext
.
RunAsGroup
=
nil
}
}
...
@@ -293,22 +293,6 @@ func dropDisabledRunAsGroupField(podSpec, oldPodSpec *api.PodSpec) {
...
@@ -293,22 +293,6 @@ func dropDisabledRunAsGroupField(podSpec, oldPodSpec *api.PodSpec) {
podSpec
.
InitContainers
[
i
]
.
SecurityContext
.
RunAsGroup
=
nil
podSpec
.
InitContainers
[
i
]
.
SecurityContext
.
RunAsGroup
=
nil
}
}
}
}
if
oldPodSpec
!=
nil
{
if
oldPodSpec
.
SecurityContext
!=
nil
{
oldPodSpec
.
SecurityContext
.
RunAsGroup
=
nil
}
for
i
:=
range
oldPodSpec
.
Containers
{
if
oldPodSpec
.
Containers
[
i
]
.
SecurityContext
!=
nil
{
oldPodSpec
.
Containers
[
i
]
.
SecurityContext
.
RunAsGroup
=
nil
}
}
for
i
:=
range
oldPodSpec
.
InitContainers
{
if
oldPodSpec
.
InitContainers
[
i
]
.
SecurityContext
!=
nil
{
oldPodSpec
.
InitContainers
[
i
]
.
SecurityContext
.
RunAsGroup
=
nil
}
}
}
}
}
}
}
...
@@ -445,3 +429,25 @@ func volumeDevicesInUse(podSpec *api.PodSpec) bool {
...
@@ -445,3 +429,25 @@ func volumeDevicesInUse(podSpec *api.PodSpec) bool {
}
}
return
false
return
false
}
}
// runAsGroupInUse returns true if the pod spec is non-nil and has a SecurityContext's RunAsGroup field set
func
runAsGroupInUse
(
podSpec
*
api
.
PodSpec
)
bool
{
if
podSpec
==
nil
{
return
false
}
if
podSpec
.
SecurityContext
!=
nil
&&
podSpec
.
SecurityContext
.
RunAsGroup
!=
nil
{
return
true
}
for
i
:=
range
podSpec
.
Containers
{
if
podSpec
.
Containers
[
i
]
.
SecurityContext
!=
nil
&&
podSpec
.
Containers
[
i
]
.
SecurityContext
.
RunAsGroup
!=
nil
{
return
true
}
}
for
i
:=
range
podSpec
.
InitContainers
{
if
podSpec
.
InitContainers
[
i
]
.
SecurityContext
!=
nil
&&
podSpec
.
InitContainers
[
i
]
.
SecurityContext
.
RunAsGroup
!=
nil
{
return
true
}
}
return
false
}
pkg/api/podsecuritypolicy/util.go
View file @
d4c85e97
...
@@ -28,11 +28,8 @@ func DropDisabledFields(pspSpec, oldPSPSpec *policy.PodSecurityPolicySpec) {
...
@@ -28,11 +28,8 @@ func DropDisabledFields(pspSpec, oldPSPSpec *policy.PodSecurityPolicySpec) {
if
!
utilfeature
.
DefaultFeatureGate
.
Enabled
(
features
.
ProcMountType
)
&&
!
allowedProcMountTypesInUse
(
oldPSPSpec
)
{
if
!
utilfeature
.
DefaultFeatureGate
.
Enabled
(
features
.
ProcMountType
)
&&
!
allowedProcMountTypesInUse
(
oldPSPSpec
)
{
pspSpec
.
AllowedProcMountTypes
=
nil
pspSpec
.
AllowedProcMountTypes
=
nil
}
}
if
!
utilfeature
.
DefaultFeatureGate
.
Enabled
(
features
.
RunAsGroup
)
{
if
!
utilfeature
.
DefaultFeatureGate
.
Enabled
(
features
.
RunAsGroup
)
&&
(
oldPSPSpec
==
nil
||
oldPSPSpec
.
RunAsGroup
==
nil
)
{
pspSpec
.
RunAsGroup
=
nil
pspSpec
.
RunAsGroup
=
nil
if
oldPSPSpec
!=
nil
{
oldPSPSpec
.
RunAsGroup
=
nil
}
}
}
}
}
...
...
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