Harden securityContext on the bundled postgres StatefulSet

Open Beginner friendly
#4,171 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
77/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
go, kubernetes, yaml

Research direction

Start with manifests/ate-install/postgres/postgres.yaml and inspect the postgres and tls-reloader container security contexts alongside the existing pod-level fsGroup. Add the requested restrictions while preserving the postgres container's TLS-compatible identity settings; then review pod-certificate-controller.yaml for the unused NET_BIND_SERVICE capability. Done when the requested container restrictions and capability cleanup are represented in the manifests.

Written by the indexing model from the issue text.

Description

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.

Dominant language
Go
Stars
8.7k
Forks
969
Avg merge
5d 1h
Merged PRs (30d)
128

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from agent-substrate/substrate

All issues in agent-substrate/substrate

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.