From 33c52be1c56105fa1c01dd5cd63fd6b68959f90f Mon Sep 17 00:00:00 2001 From: Felix Wolf Date: Sun, 3 May 2026 00:52:45 +0200 Subject: [PATCH] feat(pss): drop 5 namespaces from PSS privileged to restricted MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit argocd, cert-manager, cloudnative-pg already compliant — label flip only. ocis: add overlay injecting seccompProfile=RuntimeDefault, drop ALL caps, allowPrivilegeEscalation=false across all chart Deployments/CronJobs; patch idm initContainer; harden custom precheck Job; refactor s3-backup to rclone/rclone image (avoids apk-add-as-root). victoria-metrics-single: overlay sets full restricted SC on the StatefulSet that ships with empty securityContext: {}. forgejo, traefik, kube-system stay privileged (hostPort / CSI driver). Co-Authored-By: Claude Opus 4.7 (1M context) --- prototypes/argocd/ytt/ns.ytt.yaml | 2 +- prototypes/cert-manager/ytt/ns.ytt.yaml | 2 +- prototypes/cloudnative-pg/ytt/ns.ytt.yaml | 2 +- .../ytt/external-secret-precheck-job.ytt.yaml | 12 +++ prototypes/ocis/ytt/ns.ytt.yaml | 2 +- prototypes/ocis/ytt/pss-restricted.ytt.yaml | 62 +++++++++++++ .../ocis/ytt/s3-backup-cronjob.ytt.yaml | 92 ++++++++++--------- .../victoria-metrics-single/ytt/ns.ytt.yaml | 2 +- .../ytt/pss-restricted.ytt.yaml | 25 +++++ .../production/argocd/namespace-argocd.yaml | 2 +- .../cert-manager/namespace-cert-manager.yaml | 2 +- .../cloudnative-pg/namespace-cnpg-system.yaml | 2 +- .../ocis/cronjob-ocis-s3-backup.yaml | 92 ++++++++++--------- ...b-storage-users-clean-expired-uploads.yaml | 6 ++ ...e-users-purge-expired-trash-bin-items.yaml | 6 ++ ...-storage-users-restart-postprocessing.yaml | 6 ++ .../ocis/cronjob-thumbnails-cleanup.yaml | 6 ++ .../ocis/deployment-activitylog.yaml | 6 ++ .../ocis/deployment-appregistry.yaml | 6 ++ .../production/ocis/deployment-audit.yaml | 6 ++ .../ocis/deployment-authmachine.yaml | 6 ++ .../ocis/deployment-authservice.yaml | 6 ++ .../production/ocis/deployment-clientlog.yaml | 6 ++ .../ocis/deployment-eventhistory.yaml | 6 ++ .../production/ocis/deployment-frontend.yaml | 6 ++ .../production/ocis/deployment-gateway.yaml | 6 ++ .../production/ocis/deployment-graph.yaml | 6 ++ .../production/ocis/deployment-groups.yaml | 6 ++ .../envs/production/ocis/deployment-idm.yaml | 10 ++ .../envs/production/ocis/deployment-idp.yaml | 6 ++ .../envs/production/ocis/deployment-nats.yaml | 6 ++ .../production/ocis/deployment-ocdav.yaml | 6 ++ .../envs/production/ocis/deployment-ocs.yaml | 6 ++ .../ocis/deployment-postprocessing.yaml | 6 ++ .../production/ocis/deployment-proxy.yaml | 6 ++ .../production/ocis/deployment-search.yaml | 6 ++ .../production/ocis/deployment-settings.yaml | 6 ++ .../production/ocis/deployment-sharing.yaml | 6 ++ .../envs/production/ocis/deployment-sse.yaml | 6 ++ .../ocis/deployment-storagepubliclink.yaml | 6 ++ .../ocis/deployment-storageshares.yaml | 6 ++ .../ocis/deployment-storagesystem.yaml | 6 ++ .../ocis/deployment-storageusers.yaml | 6 ++ .../ocis/deployment-thumbnails.yaml | 6 ++ .../production/ocis/deployment-userlog.yaml | 6 ++ .../production/ocis/deployment-users.yaml | 6 ++ .../envs/production/ocis/deployment-web.yaml | 6 ++ .../production/ocis/deployment-webdav.yaml | 6 ++ .../production/ocis/deployment-webfinger.yaml | 6 ++ .../job-ocis-external-secret-precheck.yaml | 12 +++ .../envs/production/ocis/namespace-ocis.yaml | 2 +- .../namespace-monitoring.yaml | 2 +- ...fulset-victoria-metrics-single-server.yaml | 15 ++- 53 files changed, 448 insertions(+), 102 deletions(-) create mode 100644 prototypes/ocis/ytt/pss-restricted.ytt.yaml create mode 100644 prototypes/victoria-metrics-single/ytt/pss-restricted.ytt.yaml diff --git a/prototypes/argocd/ytt/ns.ytt.yaml b/prototypes/argocd/ytt/ns.ytt.yaml index f66069b..1bc2a22 100644 --- a/prototypes/argocd/ytt/ns.ytt.yaml +++ b/prototypes/argocd/ytt/ns.ytt.yaml @@ -9,7 +9,7 @@ kind: Namespace metadata: name: #@ ns labels: - pod-security.kubernetes.io/enforce: privileged + pod-security.kubernetes.io/enforce: restricted #@overlay/match by=overlay.all, expects="1+" --- diff --git a/prototypes/cert-manager/ytt/ns.ytt.yaml b/prototypes/cert-manager/ytt/ns.ytt.yaml index f66069b..1bc2a22 100644 --- a/prototypes/cert-manager/ytt/ns.ytt.yaml +++ b/prototypes/cert-manager/ytt/ns.ytt.yaml @@ -9,7 +9,7 @@ kind: Namespace metadata: name: #@ ns labels: - pod-security.kubernetes.io/enforce: privileged + pod-security.kubernetes.io/enforce: restricted #@overlay/match by=overlay.all, expects="1+" --- diff --git a/prototypes/cloudnative-pg/ytt/ns.ytt.yaml b/prototypes/cloudnative-pg/ytt/ns.ytt.yaml index f66069b..1bc2a22 100644 --- a/prototypes/cloudnative-pg/ytt/ns.ytt.yaml +++ b/prototypes/cloudnative-pg/ytt/ns.ytt.yaml @@ -9,7 +9,7 @@ kind: Namespace metadata: name: #@ ns labels: - pod-security.kubernetes.io/enforce: privileged + pod-security.kubernetes.io/enforce: restricted #@overlay/match by=overlay.all, expects="1+" --- diff --git a/prototypes/ocis/ytt/external-secret-precheck-job.ytt.yaml b/prototypes/ocis/ytt/external-secret-precheck-job.ytt.yaml index 694dd6d..49a8f78 100644 --- a/prototypes/ocis/ytt/external-secret-precheck-job.ytt.yaml +++ b/prototypes/ocis/ytt/external-secret-precheck-job.ytt.yaml @@ -60,6 +60,12 @@ spec: spec: serviceAccountName: ocis-external-secret-precheck restartPolicy: OnFailure + securityContext: + runAsNonRoot: true + runAsUser: 65532 + runAsGroup: 65532 + seccompProfile: + type: RuntimeDefault containers: - name: precheck image: alpine/k8s:1.32.3 @@ -80,3 +86,9 @@ spec: valueFrom: fieldRef: fieldPath: metadata.namespace + securityContext: + allowPrivilegeEscalation: false + readOnlyRootFilesystem: true + capabilities: + drop: + - ALL diff --git a/prototypes/ocis/ytt/ns.ytt.yaml b/prototypes/ocis/ytt/ns.ytt.yaml index f66069b..1bc2a22 100644 --- a/prototypes/ocis/ytt/ns.ytt.yaml +++ b/prototypes/ocis/ytt/ns.ytt.yaml @@ -9,7 +9,7 @@ kind: Namespace metadata: name: #@ ns labels: - pod-security.kubernetes.io/enforce: privileged + pod-security.kubernetes.io/enforce: restricted #@overlay/match by=overlay.all, expects="1+" --- diff --git a/prototypes/ocis/ytt/pss-restricted.ytt.yaml b/prototypes/ocis/ytt/pss-restricted.ytt.yaml new file mode 100644 index 0000000..ca21d34 --- /dev/null +++ b/prototypes/ocis/ytt/pss-restricted.ytt.yaml @@ -0,0 +1,62 @@ +#@ load("@ytt:overlay", "overlay") + +#@ helm_match = overlay.subset({"metadata": {"labels": {"app.kubernetes.io/managed-by": "Helm"}}}) + +#@overlay/match by=overlay.and_op(overlay.subset({"kind": "Deployment"}), helm_match), expects="1+" +--- +spec: + template: + spec: + securityContext: + #@overlay/match missing_ok=True + seccompProfile: + type: RuntimeDefault + containers: + #@overlay/match by=overlay.all, expects="1+" + - + securityContext: + #@overlay/match missing_ok=True + allowPrivilegeEscalation: false + #@overlay/match missing_ok=True + capabilities: + drop: + - ALL + +#! idm is the only chart Deployment with initContainers +#@overlay/match by=overlay.subset({"kind": "Deployment", "metadata": {"name": "idm"}}) +--- +spec: + template: + spec: + initContainers: + #@overlay/match by=overlay.all, expects="1+" + - + securityContext: + #@overlay/match missing_ok=True + allowPrivilegeEscalation: false + #@overlay/match missing_ok=True + capabilities: + drop: + - ALL + +#@overlay/match by=overlay.and_op(overlay.subset({"kind": "CronJob"}), helm_match), expects="1+" +--- +spec: + jobTemplate: + spec: + template: + spec: + securityContext: + #@overlay/match missing_ok=True + seccompProfile: + type: RuntimeDefault + containers: + #@overlay/match by=overlay.all, expects="1+" + - + securityContext: + #@overlay/match missing_ok=True + allowPrivilegeEscalation: false + #@overlay/match missing_ok=True + capabilities: + drop: + - ALL diff --git a/prototypes/ocis/ytt/s3-backup-cronjob.ytt.yaml b/prototypes/ocis/ytt/s3-backup-cronjob.ytt.yaml index 329d2e0..b6e79cc 100644 --- a/prototypes/ocis/ytt/s3-backup-cronjob.ytt.yaml +++ b/prototypes/ocis/ytt/s3-backup-cronjob.ytt.yaml @@ -27,74 +27,76 @@ spec: spec: restartPolicy: OnFailure serviceAccountName: ocis-s3-backup + securityContext: + runAsNonRoot: true + runAsUser: 1009 + runAsGroup: 1009 + seccompProfile: + type: RuntimeDefault containers: - name: backup - image: alpine:3.20 + image: rclone/rclone:1.69.0 + args: + - sync + - "s3:ocis-tr1ceracop" + - "backup:" + - --transfers=4 + - -v resources: requests: memory: 128Mi cpu: 50m - command: - - sh - - -c - - | - set -e - apk add --no-cache rclone >/dev/null 2>&1 - - mkdir -p /tmp/rclone - cat > /tmp/rclone/rclone.conf </dev/null 2>&1 - - mkdir -p /tmp/rclone - cat > /tmp/rclone/rclone.conf <