Skip to content

Set SeccompProfile to RuntimeDefault #3911

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

Merged
merged 3 commits into from
May 10, 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
8 changes: 8 additions & 0 deletions internal/controller/postgrescluster/instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,8 @@ func TestAddPGBackRestToInstancePodSpec(t *testing.T) {
privileged: false
readOnlyRootFilesystem: true
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
volumeMounts:
- mountPath: /etc/pgbackrest/server
name: pgbackrest-server
Expand Down Expand Up @@ -618,6 +620,8 @@ func TestAddPGBackRestToInstancePodSpec(t *testing.T) {
privileged: false
readOnlyRootFilesystem: true
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
volumeMounts:
- mountPath: /etc/pgbackrest/server
name: pgbackrest-server
Expand Down Expand Up @@ -676,6 +680,8 @@ func TestAddPGBackRestToInstancePodSpec(t *testing.T) {
privileged: false
readOnlyRootFilesystem: true
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
volumeMounts:
- mountPath: /etc/pgbackrest/server
name: pgbackrest-server
Expand Down Expand Up @@ -726,6 +732,8 @@ func TestAddPGBackRestToInstancePodSpec(t *testing.T) {
privileged: false
readOnlyRootFilesystem: true
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
volumeMounts:
- mountPath: /etc/pgbackrest/server
name: pgbackrest-server
Expand Down
2 changes: 2 additions & 0 deletions internal/controller/postgrescluster/pgbackrest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2519,6 +2519,8 @@ containers:
privileged: false
readOnlyRootFilesystem: true
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
volumeMounts:
- mountPath: /etc/pgbackrest/conf.d
name: pgbackrest-config
Expand Down
2 changes: 2 additions & 0 deletions internal/controller/postgrescluster/pgmonitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ securityContext:
privileged: false
readOnlyRootFilesystem: true
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
volumeMounts:
- mountPath: /conf
name: exporter-config
Expand Down
6 changes: 6 additions & 0 deletions internal/controller/postgrescluster/volumes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,8 @@ containers:
privileged: false
readOnlyRootFilesystem: true
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
Expand Down Expand Up @@ -834,6 +836,8 @@ containers:
privileged: false
readOnlyRootFilesystem: true
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
Expand Down Expand Up @@ -894,6 +898,8 @@ containers:
privileged: false
readOnlyRootFilesystem: true
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
Expand Down
8 changes: 8 additions & 0 deletions internal/controller/standalone_pgadmin/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ containers:
privileged: false
readOnlyRootFilesystem: true
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
volumeMounts:
- mountPath: /etc/pgadmin/conf.d
name: pgadmin-config
Expand Down Expand Up @@ -172,6 +174,8 @@ initContainers:
privileged: false
readOnlyRootFilesystem: true
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
volumeMounts:
- mountPath: /etc/pgadmin
name: pgadmin-config-system
Expand Down Expand Up @@ -298,6 +302,8 @@ containers:
privileged: false
readOnlyRootFilesystem: true
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
volumeMounts:
- mountPath: /etc/pgadmin/conf.d
name: pgadmin-config
Expand Down Expand Up @@ -354,6 +360,8 @@ initContainers:
privileged: false
readOnlyRootFilesystem: true
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
volumeMounts:
- mountPath: /etc/pgadmin
name: pgadmin-config-system
Expand Down
4 changes: 4 additions & 0 deletions internal/initialize/security.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,9 @@ func RestrictedSecurityContext() *corev1.SecurityContext {

// Fail to start the container if its image runs as UID 0 (root).
RunAsNonRoot: Bool(true),

SeccompProfile: &corev1.SeccompProfile{
Type: corev1.SeccompProfileTypeRuntimeDefault,
},
}
}
10 changes: 6 additions & 4 deletions internal/initialize/security_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"testing"

"gotest.tools/v3/assert"
corev1 "k8s.io/api/core/v1"

"github.com/crunchydata/postgres-operator/internal/initialize"
)
Expand Down Expand Up @@ -59,9 +60,10 @@ func TestPodSecurityContext(t *testing.T) {
assert.Assert(t, psc.RunAsUser == nil,
`Containers must not set runAsUser to 0`)

// TODO(cbandy): delegate to v1.SecurityContext
assert.Assert(t, psc.SeccompProfile == nil,
`Seccomp profile must be explicitly set to one of the allowed values. Both the Unconfined profile and the absence of a profile are prohibited.`)
if assert.Check(t, psc.SeccompProfile == nil) {
assert.Assert(t, initialize.RestrictedSecurityContext().SeccompProfile != nil,
`SeccompProfile should be delegated to the container-level v1.SecurityContext`)
}
})
}

Expand Down Expand Up @@ -121,7 +123,7 @@ func TestRestrictedSecurityContext(t *testing.T) {
// of OpenShift 4.11 uses the "runtime/default" profile.
// - https://docs.openshift.com/container-platform/4.10/security/seccomp-profiles.html
// - https://docs.openshift.com/container-platform/4.11/security/seccomp-profiles.html
assert.Assert(t, sc.SeccompProfile == nil,
assert.Assert(t, sc.SeccompProfile.Type == corev1.SeccompProfileTypeRuntimeDefault,
`Seccomp profile must be explicitly set to one of the allowed values. Both the Unconfined profile and the absence of a profile are prohibited.`)
})

Expand Down
8 changes: 8 additions & 0 deletions internal/pgadmin/reconcile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ containers:
privileged: false
readOnlyRootFilesystem: true
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
volumeMounts:
- mountPath: /etc/pgadmin
name: pgadmin-startup
Expand Down Expand Up @@ -284,6 +286,8 @@ initContainers:
privileged: false
readOnlyRootFilesystem: true
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
volumeMounts:
- mountPath: /etc/pgadmin
name: pgadmin-startup
Expand Down Expand Up @@ -482,6 +486,8 @@ containers:
privileged: false
readOnlyRootFilesystem: true
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
volumeMounts:
- mountPath: /etc/pgadmin
name: pgadmin-startup
Expand Down Expand Up @@ -526,6 +532,8 @@ initContainers:
privileged: false
readOnlyRootFilesystem: true
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
volumeMounts:
- mountPath: /etc/pgadmin
name: pgadmin-startup
Expand Down
12 changes: 12 additions & 0 deletions internal/pgbackrest/reconcile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,8 @@ func TestAddServerToInstancePod(t *testing.T) {
privileged: false
readOnlyRootFilesystem: true
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
volumeMounts:
- mountPath: /etc/pgbackrest/server
name: pgbackrest-server
Expand Down Expand Up @@ -669,6 +671,8 @@ func TestAddServerToInstancePod(t *testing.T) {
privileged: false
readOnlyRootFilesystem: true
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
volumeMounts:
- mountPath: /etc/pgbackrest/server
name: pgbackrest-server
Expand Down Expand Up @@ -736,6 +740,8 @@ func TestAddServerToInstancePod(t *testing.T) {
privileged: false
readOnlyRootFilesystem: true
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
volumeMounts:
- mountPath: /etc/pgbackrest/server
name: pgbackrest-server
Expand Down Expand Up @@ -787,6 +793,8 @@ func TestAddServerToInstancePod(t *testing.T) {
privileged: false
readOnlyRootFilesystem: true
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
volumeMounts:
- mountPath: /etc/pgbackrest/server
name: pgbackrest-server
Expand Down Expand Up @@ -855,6 +863,8 @@ func TestAddServerToRepoPod(t *testing.T) {
privileged: false
readOnlyRootFilesystem: true
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
volumeMounts:
- mountPath: /etc/pgbackrest/server
name: pgbackrest-server
Expand Down Expand Up @@ -900,6 +910,8 @@ func TestAddServerToRepoPod(t *testing.T) {
privileged: false
readOnlyRootFilesystem: true
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
volumeMounts:
- mountPath: /etc/pgbackrest/server
name: pgbackrest-server
Expand Down
12 changes: 12 additions & 0 deletions internal/pgbouncer/reconcile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ containers:
privileged: false
readOnlyRootFilesystem: true
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
volumeMounts:
- mountPath: /etc/pgbouncer
name: pgbouncer-config
Expand Down Expand Up @@ -179,6 +181,8 @@ containers:
privileged: false
readOnlyRootFilesystem: true
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
volumeMounts:
- mountPath: /etc/pgbouncer
name: pgbouncer-config
Expand Down Expand Up @@ -258,6 +262,8 @@ containers:
privileged: false
readOnlyRootFilesystem: true
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
volumeMounts:
- mountPath: /etc/pgbouncer
name: pgbouncer-config
Expand Down Expand Up @@ -294,6 +300,8 @@ containers:
privileged: false
readOnlyRootFilesystem: true
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
volumeMounts:
- mountPath: /etc/pgbouncer
name: pgbouncer-config
Expand Down Expand Up @@ -364,6 +372,8 @@ containers:
privileged: false
readOnlyRootFilesystem: true
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
volumeMounts:
- mountPath: /etc/pgbouncer
name: pgbouncer-config
Expand Down Expand Up @@ -399,6 +409,8 @@ containers:
privileged: false
readOnlyRootFilesystem: true
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
volumeMounts:
- mountPath: /etc/pgbouncer
name: pgbouncer-config
Expand Down
6 changes: 6 additions & 0 deletions internal/postgres/reconcile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ containers:
privileged: false
readOnlyRootFilesystem: true
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
volumeMounts:
- mountPath: /pgconf/tls
name: cert-volume
Expand Down Expand Up @@ -201,6 +203,8 @@ containers:
privileged: false
readOnlyRootFilesystem: true
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
volumeMounts:
- mountPath: /pgconf/tls
name: cert-volume
Expand Down Expand Up @@ -289,6 +293,8 @@ initContainers:
privileged: false
readOnlyRootFilesystem: true
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
volumeMounts:
- mountPath: /pgconf/tls
name: cert-volume
Expand Down