Skip to content

fix: let OpenShift assign the gateway sidecar's UID (restricted-v2) - #532

Open
jedi-tal wants to merge 1 commit into
documentdb:mainfrom
jedi-tal:fix/openshift-gateway-uid
Open

jedi-tal wants to merge 1 commit into
documentdb:mainfrom
jedi-tal:fix/openshift-gateway-uid

Conversation

@jedi-tal

@jedi-tal jedi-tal commented Dec 1, 2026

Copy link
Copy Markdown

Fixes #531.

On OpenShift, CloudNativePG leaves the instance pod's securityContext unset, so that the platform assigns a UID from the namespace's range. The sidecar injector, however, pins the gateway to UID/GID 1000, so restricted-v2 rejects every instance pod. Separately, the gateway image can't run as any other UID.

Changes

  • gatewaySecurityContext(pod) keeps the 1000 pin when the pod pins its own user, which is every cluster without SCCs, since CNPG always sets the pod's runAsUser there. It pins nothing when the pod leaves the UID to the platform.
  • Tests:
    • the existing UID-1000 test now covers the pinned-pod case;
    • a new test covers both unpinned shapes and still asserts PSA restricted.
  • Dockerfile_gateway_public_image: /home/documentdb is owned by group 0 and group-writable. An arbitrary UID, always in group 0 on OpenShift, can then read the entrypoint and write its working config.
  • gateway_entrypoint.sh: names the gateway's PostgreSQL role (PG_USER, default documentdb) instead of inheriting the OS user's name, which an arbitrary UID doesn't have.

Testing

  • Unit checks for the sidecar injector all pass: gofmt, go vet ./... and go test ./....
  • End to end on OpenShift 4.22.22 (ROSA HCP) under restricted-v2, using chart 1.2.2 with this injector change, and gateway:1.0.1 with the Dockerfile and entrypoint changes layered on:
    • the instance pod is admitted under restricted-v2;
    • postgres and the gateway both run as the assigned UID;
    • both containers are ready with no restarts;
    • a 17-check MongoDB client suite passes through the gateway Service.
  • Controls on the same cluster:
    • The stock injector's pod is rejected: runAsUser: Invalid value: 1000: must be in the ranges: [...].
    • The stock gateway image fails under the assigned UID: gateway_entrypoint.sh: Permission denied.
    • With only the Dockerfile change, the gateway runs but connects as the bare UID: FATAL: role "1000890000" does not exist.

Diff

lifecycle.go (+16/-4), lifecycle_test.go (+24/-2), .github/dockerfiles/Dockerfile_gateway_public_image (+2/-1) and .github/dockerfiles/gateway_entrypoint.sh (+5).

🤖 Generated with Claude Code

https://claude.ai/code/session_01EMu2w11RXcEs2P7xNWD15f

@xgerman

xgerman commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Thank you for the contribution.

On OpenShift, CloudNativePG leaves the instance pod's securityContext unset
so that the platform assigns a UID from the namespace's range, but the
sidecar injector pinned the gateway to UID/GID 1000, so restricted-v2
rejected every instance pod. The gateway image also could not run as any
other UID.

- sidecar-injector: gatewaySecurityContext(pod) pins 1000 only when the pod
  pins its own user (every cluster without SCCs) and leaves the UID to the
  platform otherwise.
- gateway image: /home/documentdb is owned by group 0 and group-writable, so
  an arbitrary UID (always in group 0 on OpenShift) can read the entrypoint
  and write its working config.
- gateway entrypoint: names the gateway's PostgreSQL role (PG_USER, default
  documentdb) instead of inheriting the OS user's name, which an arbitrary
  UID does not have.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EMu2w11RXcEs2P7xNWD15f
Signed-off-by: jedi-tal <289941616+jedi-tal@users.noreply.github.com>
@jedi-tal
jedi-tal force-pushed the fix/openshift-gateway-uid branch from ce5c04d to 8999307 Compare December 1, 2026 19:29
@documentdb-triage-tool

Copy link
Copy Markdown

🤖 Auto-triaged by documentdb-triage-tool.

Applied: test
Project fields suggested: Component test · Priority P2 · Effort M · Status Needs Review
Confidence: 0.95 (deterministic)

Reasoning

component from path globs (test); effort from diff stats (47+7 LOC, 4 files)

If a label is wrong, ping @patty-chow so the rules can be tuned. Issues with component labels are left alone; PR component labels are reconciled from changed paths on every run.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenShift: restricted-v2 rejects every DocumentDB instance pod because the gateway sidecar pins runAsUser 1000

2 participants