Skip to content

feat: snapshot, restore and clone CloudNativePG databases - #1

Merged
CalebSargeant merged 8 commits into
mainfrom
feat/first-release
Oct 23, 2026
Merged

CalebSargeant merged 8 commits into
mainfrom
feat/first-release

Conversation

@CalebSargeant

Copy link
Copy Markdown
Contributor

Lets app teams snapshot, restore and clone their own PostgreSQL databases on CloudNativePG, with access decided by Kubernetes RBAC in each database's namespace.

  • FastAPI and React console behind Entra ID sign-in, sealed cookies, CSRF and a strict CSP, built like secrets-ui and permissions-ui; one instance per cluster.
  • Access: a SubjectAccessReview for the user and groups the API server derives from the person's ID token, in the namespace a label on the Database resource names (view sees, edit snapshots and restores, admin restores production). Outside your namespaces a database does not exist.
  • Each action is a Job next to the database, connecting as its owner role: pg_dump streamed into Blob Storage; restores in one transaction (DROP OWNED, then pg_restore's script, COMMIT only once it succeeded), in place with the app scaled to 0, or into a <name>_copy.
  • Production restores wait for a second person; no production downloads; cross-environment clones need a share from someone who may snapshot the source; an audit log per environment.
  • Helm chart with RBAC and a ValidatingAdmissionPolicy that pins the Jobs to what the server builds; CI runs an end-to-end test on kind with CloudNativePG and Azurite.

Each action is a Job in the database's namespace that connects as the owner role; a production restore waits for a second person. The chart's admission policy keeps those Jobs to what the server builds.
A Database resource's label names its app's namespace; the server asks the API server, with a SubjectAccessReview for the user and groups the ID token gives a person, what they may do there. Cross-environment clones take a share from someone who may snapshot the source. A restore drops what the owner owns in the same transaction, so the database ends up exactly as the snapshot.
@github-actions

Copy link
Copy Markdown

Brimyr: Quality Assurance

Mode: pr · Gate: pass · Ecosystem: Python

Metric Value
Patch coverage 95.4%
Covered / changed executable lines 2350 / 2464
Total coverage (measured files) 95.4%
Covered / executable lines across 20 file(s) 2350 / 2464
Threshold 80.0%

✅ Patch coverage 95.4% meets the 80.0% threshold.

@chargate

chargate Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Chargate: Security Assurance

Mode: pr · Gate: ✅ pass

Net-new Pre-existing Suppressed Total in full SARIF
0 0 1 1

✅ No net-new findings introduced by this change.

Uploaded: SARIF in DefectDojo · SBOM in Dependency-Track

Pre-existing findings never block; in-source suppressions (accepted risks) and secret false positives are reported but never gate. The full, unfiltered SARIF ships to the Security tab or as an artifact.

Comment thread tests/e2e/run.py Resolved
Comment thread tests/e2e/run.py Resolved
Comment thread tests/e2e/run.py Resolved
Comment thread tests/e2e/run.py Resolved
Comment thread tests/e2e/run.py Resolved
Comment thread tests/e2e/run.py Resolved
Comment thread tests/e2e/run.py Resolved
Comment thread tests/e2e/run.py Resolved
Comment thread tests/e2e/run.py Resolved
Comment thread tests/e2e/run.py Resolved
Test code is where Chargate's Bandit default already stops counting asserts; the test people's ids are a sha256 prefix now, and the Azurite URL is marked as the local port-forward it is.
B105 on an empty token cache and a mount path, B108 on the Job pod's own emptyDir, and defused-xml on parsing Azure Storage's own listings.
They build a throwaway test cluster, RoleBindings to edit and admin included, and are applied nowhere else; the secret scanners still read them.
… its directory

Under the docker-container builder CI uses, COPY --chmod=0644 gives the directories it creates the same mode: /usr/share/postgresql-common/pgdg became 0644, and apt's sqv, running as _apt, could not read the key. A plain COPY keeps the file's 0644 from git and makes the directories 0755.
@CalebSargeant
CalebSargeant merged commit 0f9c9d6 into main Oct 23, 2026
9 checks passed
@CalebSargeant
CalebSargeant deleted the feat/first-release branch October 23, 2026 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant