Harden securityContext on the bundled postgres StatefulSet

Aperta Adatta ai principianti
#4,171 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
77/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
go, kubernetes, yaml

Direzione di ricerca

Inizia da manifests/ate-install/postgres/postgres.yaml ed esamina i contesti di sicurezza dei container postgres e tls-reloader insieme al fsGroup esistente a livello di pod. Aggiungi le restrizioni richieste mantenendo le impostazioni di identità del container postgres compatibili con TLS; poi esamina pod-certificate-controller.yaml per individuare la capability NET_BIND_SERVICE inutilizzata. Il lavoro è completato quando le restrizioni richieste per i container e la rimozione della capability sono riportate nei manifests.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

area/security kind/feature

The default install StatefulSet in manifests/ate-install/postgres/postgres.yaml already sets a careful pod-level fsGroup: 70 and documents why the postgres container must not pin runAsUser: pinning it would make the projected TLS key group-readable, and PostgreSQL would refuse to start.

The main postgres container still has no container securityContext at all, and the tls-reloader sidecar only sets runAsUser: 70:

https://github.com/agent-substrate/substrate/blob/7319f1afa2ac90c8224117463f13f7bf782f63ac/manifests/ate-install/postgres/postgres.yaml#L122-L127

https://github.com/agent-substrate/substrate/blob/7319f1afa2ac90c8224117463f13f7bf782f63ac/manifests/ate-install/postgres/postgres.yaml#L149-L151

That leaves allowPrivilegeEscalation at the Kubernetes default (true), does not drop capabilities (including NET_RAW), and does not set runAsNonRoot. The official postgres:18-alpine image already runs as UID 70, so runAsNonRoot: true without runAsUser on the main container should be compatible with the TLS constraint above.

This is leftover install hardening after #2936 / #3028, which covered the Substrate control-plane pods but not the bundled database. Authentication for that database is already in good shape (client certificates, hostssl ... cert, and a NetworkPolicy that admits only ate-api-server). This request is only about the pod security context.

Suggested container securityContext:

For postgres (do not set runAsUser):

securityContext:
  allowPrivilegeEscalation: false
  runAsNonRoot: true
  capabilities:
    drop:
    - ALL

For tls-reloader, keep runAsUser: 70 and add the same allowPrivilegeEscalation: false, runAsNonRoot: true, and capabilities.drop: [ALL].

Optional: seccompProfile: {type: RuntimeDefault} on the pod or containers.

Related: unused NET_BIND_SERVICE on podcertificate-controller

ate-api-server correctly keeps NET_BIND_SERVICE because it binds :443. The same capability is still set on podcertificate-controller:

https://github.com/agent-substrate/substrate/blob/7319f1afa2ac90c8224117463f13f7bf782f63ac/manifests/ate-install/pod-certificate-controller.yaml#L179-L187

cmd/podcertcontroller is a kube-apiserver client; it does not listen on a privileged port (or any port). Dropping the add list would leave drop: [ALL] only.

Found with Rustmaninoff (https://github.com/jose-compu/rustmaninoff), a Checkov-compatible IaC scanner; check IDs CKV_K8S_20, CKV_K8S_23, CKV_K8S_28, and CKV_K8S_25.

Lingua principale
Go
Stelle
8.7k
Fork
969
Merge medio
5g 1h
PR unite (30g)
128

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di agent-substrate/substrate

Tutte le issue di agent-substrate/substrate

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.