Skip to content

Commit 9e38f3e

Browse files
SCC can't be patched via JSONPatch because users is nil
When users or groups are nil, standard JSONPatch can't be used to add a new item to the list because the array is nil instead of empty. Alter the serialization of SCC so that there is always a user or group array returned. This allows us to do declarative patching against SCC until we move to PSP in a future release.
1 parent ceadf12 commit 9e38f3e

File tree

6 files changed

+28
-5
lines changed

6 files changed

+28
-5
lines changed

api/protobuf-spec/github_com_openshift_origin_pkg_security_apis_security_v1.proto

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

api/swagger-spec/api-v1.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22774,7 +22774,9 @@
2277422774
"allowHostPorts",
2277522775
"allowHostPID",
2277622776
"allowHostIPC",
22777-
"readOnlyRootFilesystem"
22777+
"readOnlyRootFilesystem",
22778+
"users",
22779+
"groups"
2277822780
],
2277922781
"properties": {
2278022782
"kind": {

pkg/security/apis/security/v1/defaults.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ func SetDefaults_SCC(scc *SecurityContextConstraints) {
2323
scc.SupplementalGroups.Type = SupplementalGroupsStrategyRunAsAny
2424
}
2525

26+
if scc.Users == nil {
27+
scc.Users = []string{}
28+
}
29+
if scc.Groups == nil {
30+
scc.Groups = []string{}
31+
}
32+
2633
var defaultAllowedVolumes sets.String
2734
switch {
2835
case scc.Volumes == nil:

pkg/security/apis/security/v1/generated.proto

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

pkg/security/apis/security/v1/types.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,11 @@ type SecurityContextConstraints struct {
7979
ReadOnlyRootFilesystem bool `json:"readOnlyRootFilesystem" protobuf:"varint,17,opt,name=readOnlyRootFilesystem"`
8080

8181
// The users who have permissions to use this security context constraints
82-
Users []string `json:"users,omitempty" protobuf:"bytes,18,rep,name=users"`
82+
// +optional
83+
Users []string `json:"users" protobuf:"bytes,18,rep,name=users"`
8384
// The groups that have permission to use this security context constraints
84-
Groups []string `json:"groups,omitempty" protobuf:"bytes,19,rep,name=groups"`
85+
// +optional
86+
Groups []string `json:"groups" protobuf:"bytes,19,rep,name=groups"`
8587

8688
// SeccompProfiles lists the allowed profiles that may be set for the pod or
8789
// container's seccomp annotations. An unset (nil) or empty value means that no profiles may

pkg/security/apis/security/v1/zz_generated.conversion.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -518,8 +518,16 @@ func autoConvert_security_SecurityContextConstraints_To_v1_SecurityContextConstr
518518
}
519519
out.ReadOnlyRootFilesystem = in.ReadOnlyRootFilesystem
520520
out.SeccompProfiles = *(*[]string)(unsafe.Pointer(&in.SeccompProfiles))
521-
out.Users = *(*[]string)(unsafe.Pointer(&in.Users))
522-
out.Groups = *(*[]string)(unsafe.Pointer(&in.Groups))
521+
if in.Users == nil {
522+
out.Users = make([]string, 0)
523+
} else {
524+
out.Users = *(*[]string)(unsafe.Pointer(&in.Users))
525+
}
526+
if in.Groups == nil {
527+
out.Groups = make([]string, 0)
528+
} else {
529+
out.Groups = *(*[]string)(unsafe.Pointer(&in.Groups))
530+
}
523531
return nil
524532
}
525533

0 commit comments

Comments
 (0)