Skip to content

Commit 1e8ff72

Browse files
author
Rohit Patil
committed
UPSTREAM: 1234: Fix user namespace validation for runAsGroup, fsGroup, and supplementalGroups2
1 parent c8d85b1 commit 1e8ff72

File tree

5 files changed

+99
-1
lines changed

5 files changed

+99
-1
lines changed

openshift-kube-apiserver/admission/customresourcevalidation/securitycontextconstraints/defaulting_scc_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ func TestDefaultingHappens(t *testing.T) {
8181
"priority": null,
8282
"readOnlyRootFilesystem": false,
8383
"requiredDropCapabilities": null,
84+
"runAsGroup": {
85+
"type": "RunAsAny"
86+
},
8487
"runAsUser": {
8588
"type": "RunAsAny"
8689
},

openshift-kube-apiserver/admission/customresourcevalidation/securitycontextconstraints/defaults.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
sccutil "github.com/openshift/apiserver-library-go/pkg/securitycontextconstraints/util"
88
)
99

10-
// Default SCCs for new fields. FSGroup and SupplementalGroups are
10+
// Default SCCs for new fields. FSGroup, SupplementalGroups, and RunAsGroup are
1111
// set to the RunAsAny strategy if they are unset on the scc.
1212
func SetDefaults_SCC(scc *securityv1.SecurityContextConstraints) {
1313
if len(scc.FSGroup.Type) == 0 {
@@ -16,6 +16,9 @@ func SetDefaults_SCC(scc *securityv1.SecurityContextConstraints) {
1616
if len(scc.SupplementalGroups.Type) == 0 {
1717
scc.SupplementalGroups.Type = securityv1.SupplementalGroupsStrategyRunAsAny
1818
}
19+
if len(scc.RunAsGroup.Type) == 0 {
20+
scc.RunAsGroup.Type = securityv1.RunAsGroupStrategyRunAsAny
21+
}
1922

2023
if scc.Users == nil {
2124
scc.Users = []string{}

openshift-kube-apiserver/admission/customresourcevalidation/securitycontextconstraints/validation/validation.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,23 @@ func ValidateSecurityContextConstraints(scc *securityv1.SecurityContextConstrain
7070
}
7171
allErrs = append(allErrs, validateIDRanges(scc.SupplementalGroups.Ranges, field.NewPath("supplementalGroups"))...)
7272

73+
// ensure the runAsGroup strategy has a valid type
74+
if len(scc.RunAsGroup.Type) > 0 {
75+
if scc.RunAsGroup.Type != securityv1.RunAsGroupStrategyMustRunAs &&
76+
scc.RunAsGroup.Type != securityv1.RunAsGroupStrategyRunAsAny {
77+
allErrs = append(allErrs, field.NotSupported(field.NewPath("runAsGroup", "type"), scc.RunAsGroup.Type,
78+
[]string{string(securityv1.RunAsGroupStrategyMustRunAs), string(securityv1.RunAsGroupStrategyRunAsAny)}))
79+
}
80+
allErrs = append(allErrs, validateIDRanges(scc.RunAsGroup.Ranges, field.NewPath("runAsGroup"))...)
81+
82+
// if specified, gid cannot be negative
83+
if scc.RunAsGroup.GID != nil {
84+
if *scc.RunAsGroup.GID < 0 {
85+
allErrs = append(allErrs, field.Invalid(field.NewPath("runAsGroup").Child("gid"), *scc.RunAsGroup.GID, "gid cannot be negative"))
86+
}
87+
}
88+
}
89+
7390
// validate capabilities
7491
allErrs = append(allErrs, validateSCCCapsAgainstDrops(scc.RequiredDropCapabilities, scc.DefaultAddCapabilities, field.NewPath("defaultAddCapabilities"))...)
7592
allErrs = append(allErrs, validateSCCCapsAgainstDrops(scc.RequiredDropCapabilities, scc.AllowedCapabilities, field.NewPath("allowedCapabilities"))...)

vendor/github.com/openshift/api/security/v1/types.go

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/openshift/apiserver-library-go/pkg/securitycontextconstraints/sccmatching/provider.go

Lines changed: 50 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)