Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow securityContext.Privileged to be configurable #15643

Merged
merged 3 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions config/core/300-resources/configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,13 @@ spec:
description: Capability represent POSIX capabilities type
type: string
x-kubernetes-list-type: atomic
privileged:
description: |-
Run container in privileged mode.
Processes in privileged containers are essentially equivalent to root on the host.
Defaults to false.
Note that this field cannot be set when spec.os.name is windows.
type: boolean
readOnlyRootFilesystem:
description: |-
Whether this container has a read-only root filesystem.
Expand Down
7 changes: 7 additions & 0 deletions config/core/300-resources/revision.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,13 @@ spec:
description: Capability represent POSIX capabilities type
type: string
x-kubernetes-list-type: atomic
privileged:
description: |-
Run container in privileged mode.
Processes in privileged containers are essentially equivalent to root on the host.
Defaults to false.
Note that this field cannot be set when spec.os.name is windows.
type: boolean
readOnlyRootFilesystem:
description: |-
Whether this container has a read-only root filesystem.
Expand Down
7 changes: 7 additions & 0 deletions config/core/300-resources/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,13 @@ spec:
description: Capability represent POSIX capabilities type
type: string
x-kubernetes-list-type: atomic
privileged:
description: |-
Run container in privileged mode.
Processes in privileged containers are essentially equivalent to root on the host.
Defaults to false.
Note that this field cannot be set when spec.os.name is windows.
type: boolean
readOnlyRootFilesystem:
description: |-
Whether this container has a read-only root filesystem.
Expand Down
1 change: 1 addition & 0 deletions hack/schemapatch-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ k8s.io/api/core/v1.SecurityContext:
- RunAsNonRoot
- RunAsUser
- SeccompProfile
- Privileged
k8s.io/api/core/v1.Capabilities:
fieldMask:
- Add
Expand Down
6 changes: 4 additions & 2 deletions pkg/apis/serving/fieldmask.go
Original file line number Diff line number Diff line change
Expand Up @@ -710,10 +710,12 @@ func SecurityContextMask(ctx context.Context, in *corev1.SecurityContext) *corev
// SeccompProfile defaults to "unconstrained", but the safe values are
// "RuntimeDefault" or "Localhost" (with localhost path set)
out.SeccompProfile = in.SeccompProfile

// Only allow setting Privileged to false
if in.Privileged != nil && !*in.Privileged {
KapilSareen marked this conversation as resolved.
Show resolved Hide resolved
out.Privileged = in.Privileged
}
// Disallowed
// This list is unnecessary, but added here for clarity
out.Privileged = nil
out.SELinuxOptions = nil
out.ProcMount = nil

Expand Down
9 changes: 9 additions & 0 deletions pkg/apis/serving/k8s_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2703,6 +2703,15 @@ func getCommonContainerValidationTestCases() []containerValidationTestCase {
},
},
want: apis.ErrDisallowedFields("securityContext.privileged"),
}, {
name: "allowed setting security context field Privileged to false",
c: corev1.Container{
Image: "foo",
SecurityContext: &corev1.SecurityContext{
Privileged: ptr.Bool(false),
},
},
want: nil,
}, {
name: "too large uid",
c: corev1.Container{
Expand Down