From 5a439bd99ed8c0627bd7717bf7815803feaff391 Mon Sep 17 00:00:00 2001 From: CalebSargeant <4991715+CalebSargeant@users.noreply.github.com> Date: Fri, 23 Oct 2026 16:43:39 +0200 Subject: [PATCH 1/8] feat: snapshot, restore and clone CloudNativePG databases 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. --- .dockerignore | 13 + .github/workflows/ci.yml | 133 ++ CLAUDE.md | 33 + Dockerfile | 53 + README.md | 247 +++- charts/databases-ui/.helmignore | 4 + charts/databases-ui/Chart.yaml | 36 + charts/databases-ui/ci/default-values.yaml | 51 + charts/databases-ui/ci/sas-values.yaml | 16 + charts/databases-ui/templates/NOTES.txt | 17 + charts/databases-ui/templates/_helpers.tpl | 153 ++ charts/databases-ui/templates/configmap.yaml | 12 + charts/databases-ui/templates/deployment.yaml | 165 +++ charts/databases-ui/templates/ingress.yaml | 34 + charts/databases-ui/templates/jobpolicy.yaml | 82 ++ .../databases-ui/templates/networkpolicy.yaml | 55 + charts/databases-ui/templates/pdb.yaml | 14 + charts/databases-ui/templates/rbac.yaml | 119 ++ charts/databases-ui/templates/secret.yaml | 15 + charts/databases-ui/templates/service.yaml | 16 + .../templates/serviceaccount.yaml | 15 + charts/databases-ui/values.yaml | 153 ++ docker-bake.hcl | 33 + e2e/fixtures.yaml | 193 +++ e2e/run.py | 401 +++++ examples/catalog.yaml | 44 + frontend/index.html | 15 + frontend/package-lock.json | 1295 +++++++++++++++++ frontend/package.json | 22 + frontend/public/favicon.svg | 1 + frontend/public/theme.css | 1 + frontend/src/App.tsx | 229 +++ frontend/src/api.ts | 123 ++ frontend/src/components/Dialog.tsx | 60 + frontend/src/components/Menu.tsx | 52 + frontend/src/components/ui.tsx | 52 + frontend/src/format.ts | 34 + frontend/src/main.tsx | 10 + frontend/src/styles.css | 863 +++++++++++ frontend/src/views/Activity.tsx | 132 ++ frontend/src/views/Audit.tsx | 70 + frontend/src/views/DatabaseView.tsx | 364 +++++ frontend/src/views/Databases.tsx | 63 + frontend/tsconfig.json | 17 + frontend/vite.config.ts | 14 + pyproject.toml | 30 + src/databases_ui/__init__.py | 1 + src/databases_ui/__main__.py | 90 ++ src/databases_ui/app.py | 352 +++++ src/databases_ui/audit.py | 43 + src/databases_ui/blob.py | 168 +++ src/databases_ui/catalog.py | 224 +++ src/databases_ui/config.py | 204 +++ src/databases_ui/entra.py | 107 ++ src/databases_ui/jobs.py | 188 +++ src/databases_ui/kube.py | 91 ++ src/databases_ui/oidc.py | 167 +++ src/databases_ui/runner.py | 228 +++ src/databases_ui/service.py | 393 +++++ src/databases_ui/session.py | 99 ++ tests/conftest.py | 366 +++++ tests/test_api.py | 327 +++++ tests/test_auth.py | 73 + tests/test_catalog.py | 68 + tests/test_config.py | 69 + tests/test_runner.py | 149 ++ uv.lock | 733 ++++++++++ 67 files changed, 9693 insertions(+), 1 deletion(-) create mode 100644 .dockerignore create mode 100644 .github/workflows/ci.yml create mode 100644 CLAUDE.md create mode 100644 Dockerfile create mode 100644 charts/databases-ui/.helmignore create mode 100644 charts/databases-ui/Chart.yaml create mode 100644 charts/databases-ui/ci/default-values.yaml create mode 100644 charts/databases-ui/ci/sas-values.yaml create mode 100644 charts/databases-ui/templates/NOTES.txt create mode 100644 charts/databases-ui/templates/_helpers.tpl create mode 100644 charts/databases-ui/templates/configmap.yaml create mode 100644 charts/databases-ui/templates/deployment.yaml create mode 100644 charts/databases-ui/templates/ingress.yaml create mode 100644 charts/databases-ui/templates/jobpolicy.yaml create mode 100644 charts/databases-ui/templates/networkpolicy.yaml create mode 100644 charts/databases-ui/templates/pdb.yaml create mode 100644 charts/databases-ui/templates/rbac.yaml create mode 100644 charts/databases-ui/templates/secret.yaml create mode 100644 charts/databases-ui/templates/service.yaml create mode 100644 charts/databases-ui/templates/serviceaccount.yaml create mode 100644 charts/databases-ui/values.yaml create mode 100644 docker-bake.hcl create mode 100644 e2e/fixtures.yaml create mode 100644 e2e/run.py create mode 100644 examples/catalog.yaml create mode 100644 frontend/index.html create mode 100644 frontend/package-lock.json create mode 100644 frontend/package.json create mode 100644 frontend/public/favicon.svg create mode 100644 frontend/public/theme.css create mode 100644 frontend/src/App.tsx create mode 100644 frontend/src/api.ts create mode 100644 frontend/src/components/Dialog.tsx create mode 100644 frontend/src/components/Menu.tsx create mode 100644 frontend/src/components/ui.tsx create mode 100644 frontend/src/format.ts create mode 100644 frontend/src/main.tsx create mode 100644 frontend/src/styles.css create mode 100644 frontend/src/views/Activity.tsx create mode 100644 frontend/src/views/Audit.tsx create mode 100644 frontend/src/views/DatabaseView.tsx create mode 100644 frontend/src/views/Databases.tsx create mode 100644 frontend/tsconfig.json create mode 100644 frontend/vite.config.ts create mode 100644 pyproject.toml create mode 100644 src/databases_ui/__init__.py create mode 100644 src/databases_ui/__main__.py create mode 100644 src/databases_ui/app.py create mode 100644 src/databases_ui/audit.py create mode 100644 src/databases_ui/blob.py create mode 100644 src/databases_ui/catalog.py create mode 100644 src/databases_ui/config.py create mode 100644 src/databases_ui/entra.py create mode 100644 src/databases_ui/jobs.py create mode 100644 src/databases_ui/kube.py create mode 100644 src/databases_ui/oidc.py create mode 100644 src/databases_ui/runner.py create mode 100644 src/databases_ui/service.py create mode 100644 src/databases_ui/session.py create mode 100644 tests/conftest.py create mode 100644 tests/test_api.py create mode 100644 tests/test_auth.py create mode 100644 tests/test_catalog.py create mode 100644 tests/test_config.py create mode 100644 tests/test_runner.py create mode 100644 uv.lock diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..6238be4 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,13 @@ +.git +.github +.venv +.pytest_cache +.coverage +**/__pycache__ +tests +e2e +examples +charts +docker-bake.hcl +frontend/node_modules +frontend/dist diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..1a28f7d --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,133 @@ +# Backend tests, the frontend's typecheck and build, the chart's lint and schema checks, the +# example catalog, and the whole thing end to end on a kind cluster with CloudNativePG. +# +# Its own file, not a step in release.yml, security.yml or quality.yml: those are rewritten +# from org-wide templates by Caldrith provisioning. +# +# All actions are SHA-pinned; the trailing comment is the tag each SHA corresponds to. +name: CI + +on: + pull_request: + push: + branches: [main] + paths-ignore: ['**/*.md', 'LICENSE', '.gitignore'] + workflow_dispatch: + +permissions: + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + backend: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - uses: astral-sh/setup-uv@1c37ad07a6a961277cf70c0d37d6f313000f5884 # v10.3.0 + with: + python-version: '3.12' + - run: uv sync --locked + - run: uv run pytest -q + + frontend: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 + with: + node-version: '24' + cache: npm + cache-dependency-path: frontend/package-lock.json + - name: Typecheck and build + working-directory: frontend + run: | + npm ci --ignore-scripts --no-audit --no-fund + npm run build + # The CSP allows no inline script or style, so the built page must carry none. + - name: No inline code in the page + run: | + set -euo pipefail + if grep -qE '|&2 + exit 1 + fi + + chart: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - uses: azure/setup-helm@9bc31f4ebc9c6b171d7bfbaa5d006ae7abdb4310 # v5.0.1 + - uses: yokawasa/action-setup-kube-tools@b16d49b2c459d33cf9d4c300a220ef0bcdbc730a # v0.14.0 + with: + setup-tools: kubeconform + kubeconform: '0.6.7' + - name: helm lint + run: helm lint charts/databases-ui --values charts/databases-ui/ci/default-values.yaml + # Everything switched on and the smallest working install, against the real API schemas. + - name: Render and validate + run: | + set -euo pipefail + for values in charts/databases-ui/ci/default-values.yaml charts/databases-ui/ci/sas-values.yaml; do + helm template t charts/databases-ui --namespace databases --values "$values" >rendered.yaml + kubeconform -strict -summary -kubernetes-version 1.33.0 -schema-location default rendered.yaml + done + # Missing required values must fail the render, not install something half-configured. + if helm template t charts/databases-ui >/dev/null 2>&1; then + echo "the chart rendered without azure.tenantId" >&2 + exit 1 + fi + + catalog: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - uses: astral-sh/setup-uv@1c37ad07a6a961277cf70c0d37d6f313000f5884 # v10.3.0 + with: + python-version: '3.12' + # The example catalog is the README's reference: it has to hold together. + - run: uv sync --locked --no-dev + - run: uv run python -m databases_ui check examples/catalog.yaml + + # The image, the chart, CloudNativePG, Azurite and real PostgreSQL: every action through the + # API, checked in the databases themselves (e2e/run.py). + e2e: + runs-on: ubuntu-latest + timeout-minutes: 30 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - uses: astral-sh/setup-uv@1c37ad07a6a961277cf70c0d37d6f313000f5884 # v10.3.0 + with: + python-version: '3.12' + - uses: azure/setup-helm@9bc31f4ebc9c6b171d7bfbaa5d006ae7abdb4310 # v5.0.1 + - name: Build the image + run: docker build --tag databases-ui:dev . + # kind comes with the runner image. + - name: A cluster with CloudNativePG + run: | + set -euo pipefail + kind create cluster --name dbui --wait 120s + kind load docker-image databases-ui:dev --name dbui + helm install cnpg cloudnative-pg --repo https://cloudnative-pg.github.io/charts --version 0.29.1 \ + --namespace cnpg-system --create-namespace --wait --timeout 5m + - run: uv sync --locked + - run: uv run python e2e/run.py + - name: What the cluster looked like + if: failure() + run: | + kubectl get pods,jobs -A -o wide + kubectl -n database get clusters,databases.postgresql.cnpg.io -o wide + kubectl -n databases-ui logs deployment/databases-ui --tail=200 + for pod in $(kubectl -n database get pods -l app.kubernetes.io/component=job -o name); do kubectl -n database logs "$pod" --tail=50; done diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 0000000..d1ceace --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,33 @@ +# databases-ui + +FastAPI backend (`src/databases_ui`) serving a React/TypeScript console (`frontend/`), and the Jobs' +runner (`runner.py`) in the same image, with a Helm chart (`charts/databases-ui`). State lives in +Kubernetes (Database resources, Jobs) and Blob Storage (snapshots, the audit log); the server +stores nothing. + +## Things that fail silently + +- **The session carries only the groups the catalog named at sign-in.** A team added to the + catalog reaches its members when they sign in again, not before. +- **The admission policy (`templates/jobpolicy.yaml`) knows the Job's shape.** It checks the + variables `PGPASSWORD`, `DBUI_STORAGE_SAS`, `PGHOST`, `PGSSLMODE`, `DBUI_BLOB_URL` and + `DBUI_AUDIT_URL`, the volume kinds and the `job` argument that `jobs.py` writes. Renaming one or + adding a Secret, a volume or a container in `jobs.py` without changing the policy in the same + change makes Kubernetes refuse every Job. +- **Job pods carry `app.kubernetes.io/component: job`, never `web`.** `web` is the Service and + PodDisruptionBudget selector; the chart's database NetworkPolicy admits `job`. +- **A storage lifecycle rule must be scoped to `snapshots/`.** One on the whole container also + deletes the audit log under `audit/`. +- **Snapshots leave extensions out** (`--exclude-extension=*`): the owner role can't drop one the + operator created. A copy gets its extensions from its `Database` resource, copied from the + source's `spec.extensions`; a restore into a database without them fails, and changes nothing. +- **No `from __future__ import annotations` in `app.py`.** The routes use `Annotated` path types; + postponed annotations turn them into strings and FastAPI answers 422 everywhere. +- **`{env}` in the catalog needs block lists.** YAML reads braces inside `[ ]` as a mapping. +- **The page may hold no inline script or style.** The CSP blocks it and the page renders blank; + CI greps `frontend/dist/index.html` for it. +- **The image name follows the repository name** (`ghcr.io/magmamoose/databases-ui`). The chart's + default image is that name, and the Jobs run the same image; a rename means a chart change in the + same PR. +- **No client or employer names anywhere in this public repository**: code, tests, fixtures, + docs, commits. Examples use example.com and fictional teams. diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d8a4973 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,53 @@ +# databases-ui: the FastAPI backend serving the built React frontend, and the Jobs' runner with the +# PostgreSQL client, as one image. + +# The frontend is static files, the same on every architecture, so it builds once on the +# build host rather than under emulation for each target. +FROM --platform=$BUILDPLATFORM node:25-slim@sha256:81db02c4b671288a03915da9534dbd54f96d0e7c24d80ccc54f5b36b2e684370 AS frontend +WORKDIR /frontend +COPY frontend/package.json frontend/package-lock.json ./ +RUN npm ci --ignore-scripts --no-audit --no-fund +COPY frontend/ ./ +RUN npm run build + +FROM python:3.14-slim@sha256:a2b82f3c48559aa0a8446d9af49826b6e2b2016f4cd2afabfe6013ec53729170 AS backend +RUN pip install --no-cache-dir uv==0.11.19 +ENV UV_COMPILE_BYTECODE=1 \ + UV_LINK_MODE=copy \ + UV_PYTHON_DOWNLOADS=never +WORKDIR /app +COPY pyproject.toml uv.lock README.md ./ +COPY src ./src +# The locked dependencies and the package itself, no dev group, into /app/.venv. +RUN uv sync --locked --no-dev --no-editable + +FROM python:3.14-slim@sha256:a2b82f3c48559aa0a8446d9af49826b6e2b2016f4cd2afabfe6013ec53729170 + +# pg_dump, pg_restore and psql from the PostgreSQL project's repository: pg_dump has to be at +# least the server's version, and Debian's own lags behind. The signing key is checked by hash. +ADD --checksum=sha256:0144068502a1eddd2a0280ede10ef607d1ec592ce819940991203941564e8e76 \ + https://www.postgresql.org/media/keys/ACCC4CF8.asc /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc +# hadolint ignore=DL3008 +RUN set -eux; \ + chmod 0644 /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc; \ + codename="$(. /etc/os-release && echo "$VERSION_CODENAME")"; \ + echo "deb [signed-by=/usr/share/postgresql-common/pgdg/apt.postgresql.org.asc] https://apt.postgresql.org/pub/repos/apt ${codename}-pgdg main" > /etc/apt/sources.list.d/pgdg.list; \ + apt-get update; \ + apt-get install -y --no-install-recommends postgresql-client-18; \ + rm -rf /var/lib/apt/lists/* + +ARG VERSION=dev +ENV PATH=/app/.venv/bin:/usr/lib/postgresql/18/bin:$PATH \ + PYTHONUNBUFFERED=1 \ + PYTHONDONTWRITEBYTECODE=1 \ + APP_VERSION=${VERSION} \ + PORT=8080 + +COPY --from=backend /app/.venv /app/.venv +COPY --from=frontend /frontend/dist /app/static + +# Numeric and above 10000, so a pod's runAsUser can match the image exactly. +USER 10001:10001 +EXPOSE 8080 +HEALTHCHECK --interval=30s --timeout=3s CMD ["python", "-c", "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8080/healthz', timeout=2)"] +ENTRYPOINT ["python", "-m", "databases_ui"] diff --git a/README.md b/README.md index 34e7f4b..3e6e2f2 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,248 @@ # databases-ui -Let app teams snapshot, restore and clone their own PostgreSQL databases on CloudNativePG. +Let app teams snapshot, restore and clone their own PostgreSQL databases on +[CloudNativePG](https://cloudnative-pg.io/), without asking the platform team. People sign in with +Entra ID, see the databases their team owns, and every action runs as a Kubernetes Job next to the +database. + +- **Snapshots on demand.** `pg_dump` in the custom format, streamed straight into Azure Blob + Storage with who took it and why. Nothing touches a disk, and nothing leaves the cluster. +- **Restore in place or into a copy.** `pg_restore` in a single transaction: if anything fails, + nothing changes. In place, the app's workloads are scaled to 0 first and back afterwards; into a + copy, a second database `_copy` appears next to it, created and dropped by CloudNativePG. +- **Clone across environments.** Restore a snapshot of acc into dev, for instance, where the + catalog allows it. +- **Production is careful.** A restore in a production environment waits for a second person to + approve it, and snapshots taken there can't be downloaded. +- **An audit log** of who asked for what, who approved it and how it ended, per environment. +- **No superuser.** Each Job connects as the database's owner role, with the password from that + managed role's Secret. The server itself never reads a password. + +## How it works + +```mermaid +sequenceDiagram + participant P as Person + participant U as databases-ui + participant K as Kubernetes API + participant J as Job (in the database namespace) + participant D as PostgreSQL + participant B as Blob Storage + P->>U: snapshot payments_dev + U->>K: read the Database resource and the Cluster's managed roles + U->>K: create a Job (owner role, its password Secret, the CA certificate) + K->>J: start the pod + J->>D: pg_dump --format=custom + J->>B: stream the dump into a block blob, commit it with its metadata + J->>B: append the outcome to the audit log + P->>U: restore it + U->>K: create a Job + J->>K: scale the app's workloads to 0 + J->>B: stream the snapshot + J->>D: pg_restore --clean --if-exists --no-owner --no-acl --single-transaction + J->>K: scale the workloads back +``` + +The server reads `Database` resources (`postgresql.cnpg.io/v1`) and their `Cluster`, creates Jobs, +and lists snapshots and the audit log in storage. The Jobs run this app's own image, which carries +the PostgreSQL client, as `python -m databases_ui job`. A Job's pod reads the owner's password from +the kubelet, verifies the server's certificate against the cluster's CA (`verify-full`), and talks +to storage with its own workload identity. + +## The catalog + +One YAML file says which environments the app reaches and which team acts on which database (see +[`examples/catalog.yaml`](examples/catalog.yaml)): + +```yaml +environments: + - name: dev + # The CloudNativePG Cluster (default: the environment's name) and its namespace (default: + # database), which holds the Database resources, the role Secrets and the Jobs. + cluster: dev + namespace: database + storage: + url: https://.blob.core.windows.net/dev-snapshots + cloneFrom: [acc] # environments whose snapshots may be restored here + - name: acc + # in-cluster (default), none (only read its snapshots, to clone from), or another cluster's + # API server: {server, caFile, tokenFile}. + kubernetes: none + storage: + url: https://.blob.core.windows.net/acc-snapshots + - name: prd + production: true # restores wait for a second person; no downloads + cluster: prod + storage: + url: https://.blob.core.windows.net/prd-snapshots + +teams: + - id: payments + name: Payments + groups: [6f1c2b7e-3a44-4d0e-9a51-2b8e0c7d9f10] # Entra ID group object ids + databases: + - name: payments_{env} # the Database resource's spec.name + environments: [dev, acc, prd] # default: every environment + workloads: # scaled to 0 for a restore in place + - deployment/{env}-payments/payments-api +``` + +`{env}` is the environment's name. Write lists that use it as block lists: YAML reads braces inside +`[ ]` as a mapping. Check the file in CI before it reaches the server, which refuses to start with +a catalog that does not hold together: + +```bash +docker run --rm -v "$PWD/catalog.yaml:/catalog.yaml:ro" ghcr.io/magmamoose/databases-ui: check /catalog.yaml +``` + +## Who does what + +| | Sees | Can | +|---|---|---| +| A team's members | their databases, their snapshots, Jobs and audit entries | snapshot, restore, clone, download outside production, approve a teammate's production restore | +| App role `Admin` | every database in every environment | everything a member can | +| App role `Auditor` | everything | nothing: read-only | + +## What a restore does + +- **One transaction.** `pg_restore --single-transaction`: on any error, the database is as it was. +- **Objects in the snapshot are replaced; others stay.** `--clean --if-exists` drops and recreates + what the snapshot holds. A table created after the snapshot was taken is left alone, so an app + whose migrations created it may find it already there. +- **No owners or grants from the snapshot.** `--no-owner --no-acl`: everything restored belongs to + the database's owner role, so a snapshot moves between environments whose roles differ. +- **Extensions stay as they are.** Snapshots leave extensions out (`--exclude-extension=*`): the + owner role can't drop one the operator created. The target database needs the same extensions; + a copy gets those its `Database` resource lists. +- **In place, the workloads go first.** Each listed Deployment or StatefulSet is scaled to 0, its + replica count kept in the annotation `databases-ui/replicas-before-restore`, and other sessions + of the owner role are ended. Afterwards it gets its count back, also when the restore failed. If + the Job itself dies halfway, the next restore restores the count from the annotation. A GitOps + tool that sets `replicas` may scale the app back up during the restore; the transaction keeps the + data right either way. +- **The owner must read everything.** `pg_dump` runs as the owner role, so objects in the database + that belong to other roles and that it can't read stop the snapshot. + +## Setting up + +### 1. Storage + +A container per environment, for example in a storage account per environment, with: + +- a lifecycle rule that deletes blobs under `snapshots/` after as many days as snapshots should + live; the audit log is under `audit/`, one append blob per month; +- network rules that admit the clusters' egress addresses: every transfer happens inside a + cluster, the browser's downloads included, which the server streams; +- Storage Blob Data Contributor on the container for the app registration below. + +A Job that clones reads the source environment's container, so that container must admit the +target cluster and grant the same app reading rights. + +### 2. The Entra ID app registration + +- Platform **Web**, redirect URI `https:///auth/callback`. +- **Group claims** in the ID token, emitting group object ids, best restricted to *groups assigned + to the application*; assign each team's group to the app. A person in more groups than fit in a + token is refused with a message that says so. +- App roles `Admin` and `Auditor`, assigned to who needs them. +- Federated credentials, audience `api://AzureADTokenExchange`, issuer your cluster's + service-account issuer, for the server + (`system:serviceaccount::`) and for the Jobs in each namespace + (`system:serviceaccount::databases-ui-job`). No secret to rotate. The server can use a + client secret instead; the Jobs then reach storage through a SAS (`storage.sas`), which suits + Azurite and tests more than production. + +### 3. Kubernetes + +The chart installs, in each namespace of `rbac.namespaces` (the namespaces of the in-cluster +environments): + +- a Role for the server: Database resources (get, list, create and delete, for copies), + Clusters (get), Jobs (get, list, create, patch, delete) and pods (list); no Secrets; +- the Jobs' service account, `databases-ui-job`; +- with `networkPolicy.databases.enabled`, a NetworkPolicy that lets the Jobs' pods reach + PostgreSQL on the CloudNativePG pods, for clusters that admit only listed clients. + +In each namespace of `jobs.scaleNamespaces`, the Jobs' service account may get and patch +Deployments and StatefulSets and list pods, to scale the workloads of a restore in place. + +Creating Jobs in a namespace lets a client mount any Secret there, so the chart also installs a +ValidatingAdmissionPolicy (`jobPolicy`, Kubernetes 1.30+) that holds the Jobs the server creates to +what it builds: this image, run as `job`; one owner's password and never a `*-superuser` Secret; the +CA certificate and no other Secret file; `verify-full` TLS to a `-rw` service in the Job's own +namespace; and only the catalog's storage. + +### 4. Install + +```bash +helm install databases-ui oci://ghcr.io/magmamoose/charts/databases-ui \ + --namespace databases-ui --create-namespace \ + --set azure.tenantId= --set azure.clientId= \ + --set config.publicOrigin=https://databases.example.com \ + --set-file catalog.content=catalog.yaml \ + --set 'jobs.scaleNamespaces={dev-payments}' \ + --set ingress.enabled=true +``` + +Every value is described in [`charts/databases-ui/values.yaml`](charts/databases-ui/values.yaml). +The catalog can also come from your own ConfigMap (`catalog.existingConfigMap`); the server reads +it at startup, and the chart rolls the pods when its own copy changes. + +## Configuration + +| Variable | | +|---|---| +| `AZURE_TENANT_ID`, `AZURE_CLIENT_ID` | the app registration | +| `AZURE_FEDERATED_TOKEN_FILE` or `AZURE_CLIENT_SECRET[_FILE]` | its credential | +| `AZURE_AUTHORITY_HOST` | a sovereign cloud's login host; default `https://login.microsoftonline.com` | +| `DATABASES_UI_PUBLIC_ORIGIN` | where people open it, `https://host` | +| `DATABASES_UI_SESSION_KEY[_FILE]` | at least 32 characters, the same on every replica | +| `DATABASES_UI_SESSION_HOURS` | 1 to 24, default 8 | +| `DATABASES_UI_CATALOG` | the catalog file | +| `DATABASES_UI_JOB_IMAGE` | the image the Jobs run: this app's own | +| `DATABASES_UI_JOB_SERVICE_ACCOUNT` | the Jobs' service account; default `databases-ui-job` | +| `DATABASES_UI_STORAGE_SAS[_FILE]` and `DATABASES_UI_STORAGE_SAS_SECRET` | instead of Entra ID: a SAS for the server, and `/` of the same SAS in each Job namespace | +| `DATABASES_UI_ADMIN_ROLE`, `DATABASES_UI_AUDITOR_ROLE` | app role values; default `Admin`, `Auditor` | +| `DATABASES_UI_BRAND_ACCENT`, `_ACCENT_TEXT`, `_ACCENT_DARK`, `_ACCENT_TEXT_DARK` | your colours as `#rrggbb` | + +`python -m databases_ui [serve | check | job]`: the server (default), the catalog check, +and a Job's work. + +## Security + +- **Backend for frontend.** The browser holds no token it can read: the session is an AES-GCM + sealed, `__Host-`, `HttpOnly`, `Secure`, `SameSite=Strict` cookie, and every write also needs a + CSRF token and this origin. No inline script or style, under a strict Content Security Policy. +- **Decided on the server.** Who may see and do what follows from the catalog and the groups in + the person's ID token, checked on every call. +- **No passwords in the server.** It reads no Secret; a Job's pod gets the owner's password from + the kubelet, and the admission policy above keeps the server's Jobs to what it builds. +- **A production restore takes two people.** It is created suspended and starts only when someone + else who may act on the database approves it; a Job's pod template can't change after + creation, so what runs is what was asked for. Unapproved requests expire after a day. +- **Snapshots stay in the cluster's storage.** Downloads, outside production only, stream through + the server and are recorded in the audit log. + +## Development + +```bash +uv sync +uv run pytest +uv run python -m databases_ui check examples/catalog.yaml +cd frontend && npm install && npm run dev # the UI on 5173, the API proxied to 8080 +``` + +[`e2e/run.py`](e2e/run.py) runs every action against a real cluster with CloudNativePG and +Azurite; CI runs it on kind: + +```bash +k3d cluster create dbui +helm install cnpg cloudnative-pg --repo https://cloudnative-pg.github.io/charts --version 0.29.1 \ + --namespace cnpg-system --create-namespace --wait +docker buildx bake app-local && k3d image import databases-ui:dev -c dbui +uv run python e2e/run.py +``` + +## Licence + +Apache-2.0, see [LICENSE](LICENSE). diff --git a/charts/databases-ui/.helmignore b/charts/databases-ui/.helmignore new file mode 100644 index 0000000..a53304e --- /dev/null +++ b/charts/databases-ui/.helmignore @@ -0,0 +1,4 @@ +.DS_Store +*.tmp +*.orig +ci/ diff --git a/charts/databases-ui/Chart.yaml b/charts/databases-ui/Chart.yaml new file mode 100644 index 0000000..9609bbc --- /dev/null +++ b/charts/databases-ui/Chart.yaml @@ -0,0 +1,36 @@ +apiVersion: v2 +name: databases-ui +description: Let app teams snapshot, restore and clone their own PostgreSQL databases on CloudNativePG, with Entra ID sign-in, Kubernetes Jobs and Azure Blob Storage. +type: application + +# version is the CHART version and appVersion the application version. The release +# workflow publishes the chart at the release version with appVersion set to the release +# tag, so these two are only what a local `helm install ./charts/databases-ui` uses. +# appVersion is the default image tag and keeps the leading "v" the image tags carry. +version: 0.1.0 +appVersion: "v0.1.0" + +home: https://github.com/MagmaMoose/databases-ui +sources: + - https://github.com/MagmaMoose/databases-ui +keywords: + - postgresql + - cloudnative-pg + - backup + - restore + - entra-id + - workload-identity +maintainers: + - name: Caleb Sargeant + url: https://github.com/CalebSargeant + +annotations: + artifacthub.io/license: Apache-2.0 + artifacthub.io/category: database + artifacthub.io/prerelease: "true" + artifacthub.io/links: | + - name: Source + url: https://github.com/MagmaMoose/databases-ui + artifacthub.io/changes: | + - kind: added + description: First release. diff --git a/charts/databases-ui/ci/default-values.yaml b/charts/databases-ui/ci/default-values.yaml new file mode 100644 index 0000000..97b002d --- /dev/null +++ b/charts/databases-ui/ci/default-values.yaml @@ -0,0 +1,51 @@ +# Everything on, for CI's lint and render. +azure: + tenantId: 11111111-2222-3333-4444-555555555555 + clientId: aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee +config: + publicOrigin: https://databases.example.com +catalog: + content: + environments: + - name: dev + storage: + url: https://examplesnapshots.blob.core.windows.net/dev + - name: prd + production: true + storage: + url: https://examplesnapshots.blob.core.windows.net/prd + teams: + - id: payments + name: Payments + groups: [6f1c2b7e-3a44-4d0e-9a51-2b8e0c7d9f10] + databases: + - name: payments + workloads: + - deployment/{env}-payments/api +rbac: + namespaces: [database] +jobs: + scaleNamespaces: [dev-payments, prd-payments] +branding: + accent: "#0b6e4f" + accentText: "#ffffff" + accentDark: "#5fd3a8" +image: + digest: sha256:0000000000000000000000000000000000000000000000000000000000000000 +ingress: + enabled: true + className: traefik + tls: + secretName: databases-ui-tls +networkPolicy: + enabled: true + ingressFrom: + - namespaceSelector: + matchLabels: + kubernetes.io/metadata.name: kube-system + databases: + enabled: true +priorityClassName: medium +topologySpread: + whenUnsatisfiable: DoNotSchedule + nodeTaintsPolicy: Honor diff --git a/charts/databases-ui/ci/sas-values.yaml b/charts/databases-ui/ci/sas-values.yaml new file mode 100644 index 0000000..9ebcade --- /dev/null +++ b/charts/databases-ui/ci/sas-values.yaml @@ -0,0 +1,16 @@ +# The smallest install: a client secret for sign-in, a SAS for storage and your own catalog. +azure: + tenantId: 11111111-2222-3333-4444-555555555555 + clientId: aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee + workloadIdentity: + enabled: false + clientSecret: + existingSecret: databases-ui-entra +config: + publicOrigin: https://databases.example.com +catalog: + existingConfigMap: databases-ui-catalog +storage: + sas: + existingSecret: databases-ui-storage +replicaCount: 1 diff --git a/charts/databases-ui/templates/NOTES.txt b/charts/databases-ui/templates/NOTES.txt new file mode 100644 index 0000000..b61e647 --- /dev/null +++ b/charts/databases-ui/templates/NOTES.txt @@ -0,0 +1,17 @@ +databases-ui is running as {{ include "databases-ui.fullname" . }} in {{ .Release.Namespace }}. + +Open {{ .Values.config.publicOrigin }} and sign in. Register this redirect URI on the app +registration ({{ .Values.azure.clientId }}): + + {{ .Values.config.publicOrigin }}/auth/callback +{{- if .Values.azure.workloadIdentity.enabled }} + +and federated credentials, audience {{ .Values.azure.workloadIdentity.audience }}, for these subjects: + + system:serviceaccount:{{ .Release.Namespace }}:{{ include "databases-ui.serviceAccountName" . }} +{{- range .Values.rbac.namespaces }} + system:serviceaccount:{{ . }}:{{ $.Values.jobs.serviceAccountName }} +{{- end }} +{{- end }} + +Jobs run in: {{ join ", " .Values.rbac.namespaces }}. diff --git a/charts/databases-ui/templates/_helpers.tpl b/charts/databases-ui/templates/_helpers.tpl new file mode 100644 index 0000000..4188c91 --- /dev/null +++ b/charts/databases-ui/templates/_helpers.tpl @@ -0,0 +1,153 @@ +{{- define "databases-ui.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{- define "databases-ui.fullname" -}} +{{- if .Values.fullnameOverride }} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} +{{- else if contains (include "databases-ui.name" .) .Release.Name }} +{{- .Release.Name | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- printf "%s-%s" .Release.Name (include "databases-ui.name" .) | trunc 63 | trimSuffix "-" }} +{{- end }} +{{- end }} + +{{- /* The web pods only: the Jobs' pods carry app.kubernetes.io/component: job. */}} +{{- define "databases-ui.selectorLabels" -}} +app.kubernetes.io/name: {{ include "databases-ui.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +app.kubernetes.io/component: web +{{- end }} + +{{- define "databases-ui.labels" -}} +app.kubernetes.io/name: {{ include "databases-ui.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +app.kubernetes.io/version: {{ .Values.image.tag | default .Chart.AppVersion | quote }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +helm.sh/chart: {{ printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{- define "databases-ui.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "databases-ui.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- required "serviceAccount.name is required when serviceAccount.create is false" .Values.serviceAccount.name }} +{{- end }} +{{- end }} + +{{- define "databases-ui.image" -}} +{{- $tag := .Values.image.tag | default .Chart.AppVersion }} +{{- if .Values.image.digest }} +{{- printf "%s:%s@%s" .Values.image.repository $tag .Values.image.digest }} +{{- else }} +{{- printf "%s:%s" .Values.image.repository $tag }} +{{- end }} +{{- end }} + +{{- define "databases-ui.sessionSecret" -}} +{{- default (printf "%s-session" (include "databases-ui.fullname" .)) .Values.session.existingSecret }} +{{- end }} + +{{- define "databases-ui.catalogConfigMap" -}} +{{- default (printf "%s-catalog" (include "databases-ui.fullname" .)) .Values.catalog.existingConfigMap }} +{{- end }} + +{{- /* The catalog as YAML text: catalog.content is a map in values, or a string from --set-file. */}} +{{- define "databases-ui.catalogContent" -}} +{{- if kindIs "string" .Values.catalog.content }} +{{- .Values.catalog.content }} +{{- else }} +{{- toYaml .Values.catalog.content }} +{{- end }} +{{- end }} + +{{- define "databases-ui.host" -}} +{{- default (regexReplaceAll "^https?://([^/:]+).*$" .Values.config.publicOrigin "${1}") .Values.ingress.host }} +{{- end }} + +{{- /* Fails the render on a missing required value, instead of installing something half-configured. */}} +{{- define "databases-ui.validate" -}} +{{- $_ := required "config.publicOrigin is required, such as https://databases.example.com" .Values.config.publicOrigin }} +{{- $_ := required "azure.tenantId is required" .Values.azure.tenantId }} +{{- $_ := required "azure.clientId is required" .Values.azure.clientId }} +{{- if and (not .Values.catalog.existingConfigMap) (not .Values.catalog.content) }} +{{- fail "set catalog.content (environments and teams) or catalog.existingConfigMap" }} +{{- end }} +{{- if and (not .Values.azure.workloadIdentity.enabled) (not .Values.azure.clientSecret.existingSecret) }} +{{- fail "set azure.workloadIdentity.enabled, or azure.clientSecret.existingSecret" }} +{{- end }} +{{- if and (not .Values.azure.workloadIdentity.enabled) (not .Values.storage.sas.existingSecret) }} +{{- fail "without workload identity the Jobs reach storage through storage.sas.existingSecret" }} +{{- end }} +{{- end }} + +{{- define "databases-ui.env" -}} +- name: AZURE_TENANT_ID + value: {{ .Values.azure.tenantId | quote }} +- name: AZURE_CLIENT_ID + value: {{ .Values.azure.clientId | quote }} +{{- with .Values.azure.authorityHost }} +- name: AZURE_AUTHORITY_HOST + value: {{ . | quote }} +{{- end }} +{{- if .Values.azure.workloadIdentity.enabled }} +- name: AZURE_FEDERATED_TOKEN_FILE + value: /var/run/secrets/azure/tokens/azure-identity-token +{{- else }} +# Mounted files rather than env vars: an environment variable is readable in /proc//environ +# and inherited by child processes. +- name: AZURE_CLIENT_SECRET_FILE + value: /etc/databases-ui/client/{{ .Values.azure.clientSecret.key }} +{{- end }} +# The tag deployed, not the one baked in: a release promotes its pull request's image as it is, +# so the image itself still says pr-. +- name: APP_VERSION + value: {{ .Values.image.tag | default .Chart.AppVersion | quote }} +- name: DATABASES_UI_PUBLIC_ORIGIN + value: {{ .Values.config.publicOrigin | quote }} +- name: DATABASES_UI_SESSION_HOURS + value: {{ .Values.config.sessionHours | quote }} +- name: DATABASES_UI_SESSION_KEY_FILE + value: /etc/databases-ui/session/{{ .Values.session.key }} +- name: DATABASES_UI_CATALOG + value: /etc/databases-ui/catalog/{{ .Values.catalog.key }} +- name: DATABASES_UI_JOB_IMAGE + value: {{ include "databases-ui.image" . | quote }} +- name: DATABASES_UI_JOB_SERVICE_ACCOUNT + value: {{ .Values.jobs.serviceAccountName | quote }} +{{- if .Values.storage.sas.existingSecret }} +- name: DATABASES_UI_STORAGE_SAS_FILE + value: /etc/databases-ui/storage/{{ .Values.storage.sas.key }} +- name: DATABASES_UI_STORAGE_SAS_SECRET + value: {{ printf "%s/%s" .Values.storage.sas.existingSecret .Values.storage.sas.key | quote }} +{{- end }} +- name: DATABASES_UI_ADMIN_ROLE + value: {{ .Values.config.adminRole | quote }} +- name: DATABASES_UI_AUDITOR_ROLE + value: {{ .Values.config.auditorRole | quote }} +{{- range $key, $env := dict "accent" "ACCENT" "accentText" "ACCENT_TEXT" "accentDark" "ACCENT_DARK" "accentTextDark" "ACCENT_TEXT_DARK" }} +{{- with index $.Values.branding $key }} +- name: DATABASES_UI_BRAND_{{ $env }} + value: {{ . | quote }} +{{- end }} +{{- end }} +{{- with .Values.extraEnv }} +{{ toYaml . }} +{{- end }} +{{- end }} + +{{- define "databases-ui.podSecurityContext" -}} +runAsNonRoot: true +runAsUser: 10001 +runAsGroup: 10001 +fsGroup: 10001 +seccompProfile: + type: RuntimeDefault +{{- end }} + +{{- define "databases-ui.containerSecurityContext" -}} +allowPrivilegeEscalation: false +readOnlyRootFilesystem: true +capabilities: + drop: ["ALL"] +{{- end }} diff --git a/charts/databases-ui/templates/configmap.yaml b/charts/databases-ui/templates/configmap.yaml new file mode 100644 index 0000000..eb38279 --- /dev/null +++ b/charts/databases-ui/templates/configmap.yaml @@ -0,0 +1,12 @@ +{{- if not .Values.catalog.existingConfigMap }} +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "databases-ui.catalogConfigMap" . }} + namespace: {{ .Release.Namespace }} + labels: + {{- include "databases-ui.labels" . | nindent 4 }} +data: + {{ .Values.catalog.key }}: | + {{- include "databases-ui.catalogContent" . | nindent 4 }} +{{- end }} diff --git a/charts/databases-ui/templates/deployment.yaml b/charts/databases-ui/templates/deployment.yaml new file mode 100644 index 0000000..3146b33 --- /dev/null +++ b/charts/databases-ui/templates/deployment.yaml @@ -0,0 +1,165 @@ +{{- include "databases-ui.validate" . }} +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "databases-ui.fullname" . }} + namespace: {{ .Release.Namespace }} + labels: + {{- include "databases-ui.labels" . | nindent 4 }} + app.kubernetes.io/component: web +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + {{- include "databases-ui.selectorLabels" . | nindent 6 }} + template: + metadata: + labels: + {{- include "databases-ui.selectorLabels" . | nindent 8 }} + {{- with .Values.podLabels }} + {{- toYaml . | nindent 8 }} + {{- end }} + annotations: + # The catalog is read at startup: a change rolls the pods. + checksum/catalog: {{ toYaml .Values.catalog | sha256sum }} + {{- with .Values.podAnnotations }} + {{- toYaml . | nindent 8 }} + {{- end }} + spec: + serviceAccountName: {{ include "databases-ui.serviceAccountName" . }} + # The server reads Database resources and creates Jobs through the Kubernetes API. + automountServiceAccountToken: true + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.priorityClassName }} + priorityClassName: {{ . }} + {{- end }} + securityContext: + {{- include "databases-ui.podSecurityContext" . | nindent 8 }} + {{- if .Values.topologySpreadConstraints }} + topologySpreadConstraints: + {{- toYaml .Values.topologySpreadConstraints | nindent 8 }} + {{- else if .Values.topologySpread.enabled }} + topologySpreadConstraints: + - maxSkew: 1 + topologyKey: kubernetes.io/hostname + whenUnsatisfiable: {{ .Values.topologySpread.whenUnsatisfiable }} + {{- with .Values.topologySpread.nodeTaintsPolicy }} + nodeTaintsPolicy: {{ . }} + {{- end }} + matchLabelKeys: + - pod-template-hash + labelSelector: + matchLabels: + {{- include "databases-ui.selectorLabels" . | nindent 14 }} + {{- end }} + containers: + - name: databases-ui + image: {{ include "databases-ui.image" . }} + imagePullPolicy: {{ .Values.image.pullPolicy }} + securityContext: + {{- include "databases-ui.containerSecurityContext" . | nindent 12 }} + ports: + - name: http + containerPort: 8080 + protocol: TCP + env: + {{- include "databases-ui.env" . | nindent 12 }} + readinessProbe: + httpGet: + path: /healthz + port: http + periodSeconds: 10 + livenessProbe: + httpGet: + path: /healthz + port: http + periodSeconds: 30 + failureThreshold: 3 + resources: + {{- toYaml .Values.resources | nindent 12 }} + volumeMounts: + - name: tmp + mountPath: /tmp + - name: session + mountPath: /etc/databases-ui/session + readOnly: true + - name: catalog + mountPath: /etc/databases-ui/catalog + readOnly: true + {{- if .Values.storage.sas.existingSecret }} + - name: storage + mountPath: /etc/databases-ui/storage + readOnly: true + {{- end }} + {{- if .Values.azure.workloadIdentity.enabled }} + - name: azure-identity-token + mountPath: /var/run/secrets/azure/tokens + readOnly: true + {{- else }} + - name: client-secret + mountPath: /etc/databases-ui/client + readOnly: true + {{- end }} + volumes: + - name: tmp + emptyDir: + sizeLimit: 16Mi + - name: session + secret: + secretName: {{ include "databases-ui.sessionSecret" . }} + defaultMode: 0440 + items: + - key: {{ .Values.session.key }} + path: {{ .Values.session.key }} + - name: catalog + configMap: + name: {{ include "databases-ui.catalogConfigMap" . }} + items: + - key: {{ .Values.catalog.key }} + path: {{ .Values.catalog.key }} + {{- with .Values.storage.sas }} + {{- if .existingSecret }} + - name: storage + secret: + secretName: {{ .existingSecret }} + defaultMode: 0440 + items: + - key: {{ .key }} + path: {{ .key }} + {{- end }} + {{- end }} + {{- if .Values.azure.workloadIdentity.enabled }} + # The service-account token Entra ID exchanges through the federated credential. The kubelet + # renews it in place before it expires; the app reads the file on every use. + - name: azure-identity-token + projected: + defaultMode: 0440 + sources: + - serviceAccountToken: + path: azure-identity-token + audience: {{ .Values.azure.workloadIdentity.audience }} + expirationSeconds: 3600 + {{- else }} + - name: client-secret + secret: + secretName: {{ .Values.azure.clientSecret.existingSecret }} + defaultMode: 0440 + items: + - key: {{ .Values.azure.clientSecret.key }} + path: {{ .Values.azure.clientSecret.key }} + {{- end }} + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/charts/databases-ui/templates/ingress.yaml b/charts/databases-ui/templates/ingress.yaml new file mode 100644 index 0000000..31e555c --- /dev/null +++ b/charts/databases-ui/templates/ingress.yaml @@ -0,0 +1,34 @@ +{{- if .Values.ingress.enabled }} +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: {{ include "databases-ui.fullname" . }} + namespace: {{ .Release.Namespace }} + labels: + {{- include "databases-ui.labels" . | nindent 4 }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- with .Values.ingress.className }} + ingressClassName: {{ . }} + {{- end }} + rules: + - host: {{ include "databases-ui.host" . }} + http: + paths: + - path: / + pathType: Prefix + backend: + service: + name: {{ include "databases-ui.fullname" . }} + port: + name: http + {{- with .Values.ingress.tls.secretName }} + tls: + - hosts: + - {{ include "databases-ui.host" $ }} + secretName: {{ . }} + {{- end }} +{{- end }} diff --git a/charts/databases-ui/templates/jobpolicy.yaml b/charts/databases-ui/templates/jobpolicy.yaml new file mode 100644 index 0000000..47573f9 --- /dev/null +++ b/charts/databases-ui/templates/jobpolicy.yaml @@ -0,0 +1,82 @@ +{{- if .Values.jobPolicy.enabled }} +{{- $urls := list }} +{{- range (default list (fromYaml (include "databases-ui.catalogContent" .)).environments) }} +{{- $urls = append $urls (printf "%q" (trimSuffix "/" .storage.url)) }} +{{- end }} +# Creating Jobs in a namespace is, to Kubernetes, reading every Secret there. This keeps the Jobs +# this app creates to what it builds itself: its own image as `job`, one owner's password (never +# a superuser's), the server's CA certificate and no other Secret, TLS to a database in the Job's +# own namespace, and the catalog's storage. +apiVersion: admissionregistration.k8s.io/v1 +kind: ValidatingAdmissionPolicy +metadata: + name: {{ include "databases-ui.fullname" . }}-jobs + labels: + {{- include "databases-ui.labels" . | nindent 4 }} +spec: + failurePolicy: Fail + matchConstraints: + resourceRules: + - apiGroups: [batch] + apiVersions: [v1] + operations: [CREATE, UPDATE] + resources: [jobs] + matchConditions: + - name: created-by-databases-ui + expression: request.userInfo.username == "system:serviceaccount:{{ .Release.Namespace }}:{{ include "databases-ui.serviceAccountName" . }}" + variables: + - name: pod + expression: object.spec.template.spec + - name: env + expression: "has(variables.pod.containers[0].env) ? variables.pod.containers[0].env : []" + validations: + - expression: >- + variables.pod.containers.size() == 1 && variables.pod.containers.all(c, c.image == {{ include "databases-ui.image" . | quote }} + && !has(c.command) && has(c.args) && c.args == ["job"] && !has(c.envFrom)) + && !has(variables.pod.initContainers) && !has(variables.pod.ephemeralContainers) + message: databases-ui Jobs run only this app's own image, as `job` + - expression: >- + variables.pod.serviceAccountName == {{ .Values.jobs.serviceAccountName | quote }} + && !(has(variables.pod.hostNetwork) && variables.pod.hostNetwork) + && !(has(variables.pod.hostPID) && variables.pod.hostPID) + && !(has(variables.pod.hostIPC) && variables.pod.hostIPC) + message: databases-ui Jobs run as their own service account, in their own network + - expression: >- + !has(variables.pod.volumes) || variables.pod.volumes.all(v, has(v.emptyDir) + || (has(v.projected) && v.projected.sources.all(s, has(s.serviceAccountToken))) + || (has(v.secret) && has(v.secret.items) && v.secret.items.all(i, i.key == "ca.crt"))) + message: databases-ui Jobs mount scratch space, tokens and a CA certificate, nothing else + - expression: >- + variables.env.all(e, !has(e.valueFrom) || (has(e.valueFrom.secretKeyRef) + && ((e.name == "PGPASSWORD" && e.valueFrom.secretKeyRef.key == "password" && !e.valueFrom.secretKeyRef.name.endsWith("-superuser")) + {{- with .Values.storage.sas.existingSecret }} + || (e.name == "DBUI_STORAGE_SAS" && e.valueFrom.secretKeyRef.name == {{ . | quote }} && e.valueFrom.secretKeyRef.key == {{ $.Values.storage.sas.key | quote }}) + {{- end }} + ))) + message: databases-ui Jobs read one owner's password from its Secret, never a superuser's + - expression: >- + variables.env.exists(e, e.name == "PGSSLMODE" && e.value == "verify-full") + && variables.env.all(e, e.name != "PGHOST" || (has(e.value) && e.value.matches("^[a-z0-9-]+-rw[.]" + request.namespace + "[.]svc$"))) + message: databases-ui Jobs connect over verified TLS to a database in their own namespace + {{- if $urls }} + - expression: >- + variables.env.all(e, !(e.name in ["DBUI_BLOB_URL", "DBUI_AUDIT_URL"]) || (has(e.value) && e.value in [{{ join ", " $urls }}])) + message: databases-ui Jobs read and write only the catalog's storage + {{- end }} +--- +apiVersion: admissionregistration.k8s.io/v1 +kind: ValidatingAdmissionPolicyBinding +metadata: + name: {{ include "databases-ui.fullname" . }}-jobs + labels: + {{- include "databases-ui.labels" . | nindent 4 }} +spec: + policyName: {{ include "databases-ui.fullname" . }}-jobs + validationActions: [Deny] + matchResources: + namespaceSelector: + matchExpressions: + - key: kubernetes.io/metadata.name + operator: In + values: {{ toJson .Values.rbac.namespaces }} +{{- end }} diff --git a/charts/databases-ui/templates/networkpolicy.yaml b/charts/databases-ui/templates/networkpolicy.yaml new file mode 100644 index 0000000..3b459d8 --- /dev/null +++ b/charts/databases-ui/templates/networkpolicy.yaml @@ -0,0 +1,55 @@ +{{- if .Values.networkPolicy.enabled }} +# In: the http port, from ingressFrom. Out: DNS, and public addresses on 443 for Entra ID and +# Azure Storage. Private, CGNAT, link-local and loopback ranges are excluded, so this opens nothing +# inside the cluster or its network: the Kubernetes API needs a rule in extraEgress. A +# NetworkPolicy cannot name a host, so it is any public address on 443. +apiVersion: networking.k8s.io/v1 +kind: NetworkPolicy +metadata: + name: {{ include "databases-ui.fullname" . }} + namespace: {{ .Release.Namespace }} + labels: + {{- include "databases-ui.labels" . | nindent 4 }} +spec: + podSelector: + matchLabels: + {{- include "databases-ui.selectorLabels" . | nindent 6 }} + policyTypes: + - Ingress + - Egress + ingress: + - ports: + - port: http + protocol: TCP + {{- with .Values.networkPolicy.ingressFrom }} + from: + {{- toYaml . | nindent 8 }} + {{- end }} + egress: + - to: + - namespaceSelector: {} + podSelector: + matchLabels: + k8s-app: kube-dns + ports: + - port: 53 + protocol: UDP + - port: 53 + protocol: TCP + - to: + - ipBlock: + cidr: 0.0.0.0/0 + except: + - 10.0.0.0/8 + - 172.16.0.0/12 + - 192.168.0.0/16 + - 100.64.0.0/10 + - 169.254.0.0/16 + - 127.0.0.0/8 + ports: + - port: 443 + protocol: TCP + {{- with .Values.networkPolicy.extraEgress }} + {{- toYaml . | nindent 4 }} + {{- end }} +{{- end }} diff --git a/charts/databases-ui/templates/pdb.yaml b/charts/databases-ui/templates/pdb.yaml new file mode 100644 index 0000000..21e4fa4 --- /dev/null +++ b/charts/databases-ui/templates/pdb.yaml @@ -0,0 +1,14 @@ +{{- if and .Values.podDisruptionBudget.enabled (gt (int .Values.replicaCount) 1) }} +apiVersion: policy/v1 +kind: PodDisruptionBudget +metadata: + name: {{ include "databases-ui.fullname" . }} + namespace: {{ .Release.Namespace }} + labels: + {{- include "databases-ui.labels" . | nindent 4 }} +spec: + minAvailable: {{ .Values.podDisruptionBudget.minAvailable }} + selector: + matchLabels: + {{- include "databases-ui.selectorLabels" . | nindent 6 }} +{{- end }} diff --git a/charts/databases-ui/templates/rbac.yaml b/charts/databases-ui/templates/rbac.yaml new file mode 100644 index 0000000..fa564f9 --- /dev/null +++ b/charts/databases-ui/templates/rbac.yaml @@ -0,0 +1,119 @@ +{{- $fullname := include "databases-ui.fullname" . }} +{{- $labels := include "databases-ui.labels" . }} +{{- range $ns := .Values.rbac.namespaces }} +--- +# The server reads the Database resources and the Cluster's managed roles, creates and approves +# Jobs, reads their pods' outcome and keeps one copy database per database. It reads no Secret: +# the Jobs' pods get the owner's password from the kubelet. +apiVersion: rbac.authorization.k8s.io/v1 +kind: Role +metadata: + name: {{ $fullname }} + namespace: {{ $ns }} + labels: + {{- $labels | nindent 4 }} +rules: + - apiGroups: [postgresql.cnpg.io] + resources: [databases] + verbs: [get, list, create, delete] + - apiGroups: [postgresql.cnpg.io] + resources: [clusters] + verbs: [get] + - apiGroups: [batch] + resources: [jobs] + verbs: [get, list, create, patch, delete] + - apiGroups: [""] + resources: [pods] + verbs: [list] +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: {{ $fullname }} + namespace: {{ $ns }} + labels: + {{- $labels | nindent 4 }} +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: Role + name: {{ $fullname }} +subjects: + - kind: ServiceAccount + name: {{ include "databases-ui.serviceAccountName" $ }} + namespace: {{ $.Release.Namespace }} +--- +# The Jobs' identity: the subject of their federated credential on the app registration, and of +# the scale rights below. A Job mounts its Kubernetes token only for a restore in place. +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ $.Values.jobs.serviceAccountName }} + namespace: {{ $ns }} + labels: + {{- $labels | nindent 4 }} +automountServiceAccountToken: false +{{- if $.Values.networkPolicy.databases.enabled }} +--- +# The Jobs' pods to PostgreSQL on the CloudNativePG pods, added to whatever else lets clients in. +apiVersion: networking.k8s.io/v1 +kind: NetworkPolicy +metadata: + name: {{ $fullname }}-jobs-to-postgres + namespace: {{ $ns }} + labels: + {{- $labels | nindent 4 }} +spec: + podSelector: + matchExpressions: + - key: cnpg.io/cluster + operator: Exists + policyTypes: + - Ingress + ingress: + - from: + - podSelector: + matchLabels: + app.kubernetes.io/name: {{ include "databases-ui.name" $ }} + app.kubernetes.io/component: job + ports: + - port: 5432 + protocol: TCP +{{- end }} +{{- end }} +{{- if .Values.jobs.scaleNamespaces }} +--- +# A restore in place scales the database's workloads to 0 and back, and waits for their pods. +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: {{ $fullname }}-scale + labels: + {{- $labels | nindent 4 }} +rules: + - apiGroups: [apps] + resources: [deployments, statefulsets] + verbs: [get, patch] + - apiGroups: [""] + resources: [pods] + verbs: [list] +{{- range $ns := .Values.jobs.scaleNamespaces }} +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: {{ $fullname }}-scale + namespace: {{ $ns }} + labels: + {{- $labels | nindent 4 }} +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: {{ $fullname }}-scale +subjects: + {{- range $jobs := $.Values.rbac.namespaces }} + - kind: ServiceAccount + name: {{ $.Values.jobs.serviceAccountName }} + namespace: {{ $jobs }} + {{- end }} +{{- end }} +{{- end }} diff --git a/charts/databases-ui/templates/secret.yaml b/charts/databases-ui/templates/secret.yaml new file mode 100644 index 0000000..7770653 --- /dev/null +++ b/charts/databases-ui/templates/secret.yaml @@ -0,0 +1,15 @@ +{{- if not .Values.session.existingSecret }} +{{- $name := include "databases-ui.sessionSecret" . }} +{{- $existing := lookup "v1" "Secret" .Release.Namespace $name }} +# The key that seals session cookies. Generated once and kept: a new key signs everyone out. +apiVersion: v1 +kind: Secret +metadata: + name: {{ $name }} + namespace: {{ .Release.Namespace }} + labels: + {{- include "databases-ui.labels" . | nindent 4 }} +type: Opaque +data: + {{ .Values.session.key }}: {{ if and $existing (index $existing.data .Values.session.key) }}{{ index $existing.data .Values.session.key }}{{ else }}{{ randAlphaNum 64 | b64enc }}{{ end }} +{{- end }} diff --git a/charts/databases-ui/templates/service.yaml b/charts/databases-ui/templates/service.yaml new file mode 100644 index 0000000..48db4a9 --- /dev/null +++ b/charts/databases-ui/templates/service.yaml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "databases-ui.fullname" . }} + namespace: {{ .Release.Namespace }} + labels: + {{- include "databases-ui.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + selector: + {{- include "databases-ui.selectorLabels" . | nindent 4 }} + ports: + - name: http + port: {{ .Values.service.port }} + targetPort: http + protocol: TCP diff --git a/charts/databases-ui/templates/serviceaccount.yaml b/charts/databases-ui/templates/serviceaccount.yaml new file mode 100644 index 0000000..85dfb31 --- /dev/null +++ b/charts/databases-ui/templates/serviceaccount.yaml @@ -0,0 +1,15 @@ +{{- if .Values.serviceAccount.create }} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "databases-ui.serviceAccountName" . }} + namespace: {{ .Release.Namespace }} + labels: + {{- include "databases-ui.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +# The pod asks for its Kubernetes token itself (deployment.yaml); nothing else here needs one. +automountServiceAccountToken: false +{{- end }} diff --git a/charts/databases-ui/values.yaml b/charts/databases-ui/values.yaml new file mode 100644 index 0000000..f7e14f8 --- /dev/null +++ b/charts/databases-ui/values.yaml @@ -0,0 +1,153 @@ +# databases-ui. Required: azure.tenantId, azure.clientId, config.publicOrigin and the catalog. The +# setup is in the repository README. + +replicaCount: 2 + +image: + repository: ghcr.io/magmamoose/databases-ui + # Defaults to the chart's appVersion. + tag: "" + # sha256:..., pins the image whatever the tag says. The Jobs run the same image. + digest: "" + pullPolicy: IfNotPresent + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +azure: + # The Entra ID tenant (a GUID) and the app registration's client id. One app signs people in + # and, with workload identity, reaches storage for the server and the Jobs. + tenantId: "" + clientId: "" + # Leave empty for the public cloud (https://login.microsoftonline.com). + authorityHost: "" + # The app authenticates with its own service-account token, which Entra ID accepts through a + # federated credential (issuer: the cluster's service-account issuer, subject: + # system:serviceaccount::). The Jobs do the same as + # jobs.serviceAccountName in each namespace of rbac.namespaces. + workloadIdentity: + enabled: true + audience: api://AzureADTokenExchange + # Used instead when workloadIdentity.enabled is false: a Secret holding a client secret. The + # Jobs then need storage.sas. + clientSecret: + existingSecret: "" + key: client-secret + +config: + # Where people open the UI, scheme and host only. The redirect URI to register on the app is + # /auth/callback. + publicOrigin: "" + # How long a sign-in lasts, 1 to 24. + sessionHours: 8 + # The app roles that act on every database (Admin) or read everything (Auditor). + adminRole: Admin + auditorRole: Auditor + +# The environments and the teams (see the README). Rendered into a ConfigMap from `content`, a +# map here or the file's text with --set-file catalog.content=catalog.yaml, or read from your own +# ConfigMap in the release namespace. +catalog: + existingConfigMap: "" + key: catalog.yaml + content: "" + +# Where the Jobs run: the namespace of every in-cluster environment in the catalog, usually the +# one that holds the CloudNativePG Clusters. Each gets a Role for this app, the Jobs' service +# account and, with networkPolicy.databases, a rule that lets the Jobs reach the databases. +rbac: + namespaces: [database] + +jobs: + serviceAccountName: databases-ui-job + # Namespaces of the workloads a restore in place scales to 0: the Jobs may scale Deployments + # and StatefulSets there, nothing else. + scaleNamespaces: [] + +# A ValidatingAdmissionPolicy (Kubernetes 1.30+) that holds the Jobs this app creates to what it +# builds: its image, one owner's password, the CA certificate, TLS to its own namespace and the +# catalog's storage. Creating Jobs would otherwise let it mount any Secret in those namespaces. +jobPolicy: + enabled: true + +storage: + # A SAS token instead of Entra ID, for an emulator such as Azurite or one storage account: a + # Secret with this name in the release namespace AND in every namespace of rbac.namespaces. + sas: + existingSecret: "" + key: sas + +# Your colours, as quoted "#rrggbb"; empty keeps the default. The accent fills buttons, links, the +# selected page and the logo; accentText is the text on it. The dark ones default to these two. +branding: + accent: "" + accentText: "" + accentDark: "" + accentTextDark: "" + +session: + # A Secret holding the key that seals session cookies (at least 32 characters), shared by + # every replica. Empty: the chart creates one on install and keeps it on upgrade. + existingSecret: "" + key: session-key + +serviceAccount: + create: true + # Defaults to the release's full name. It is the subject of the federated credential. + name: "" + annotations: {} + +service: + type: ClusterIP + port: 80 + +ingress: + enabled: false + className: "" + annotations: {} + # Defaults to the host of config.publicOrigin. + host: "" + tls: + # The TLS Secret for the host; empty for no tls block. + secretName: "" + +podDisruptionBudget: + enabled: true + minAvailable: 1 + +# One replica per node where possible. DoNotSchedule makes it strict. +topologySpread: + enabled: true + whenUnsatisfiable: ScheduleAnyway + # Honor keeps tainted nodes out of the count; empty leaves the Kubernetes default. + nodeTaintsPolicy: "" +# Or your own constraints, rendered as they are instead of the one above. +topologySpreadConstraints: [] + +networkPolicy: + # The server: ingress to the http port from ingressFrom (any pod when empty); egress to DNS + # and to public addresses on 443 (Entra ID, Azure Storage). The Kubernetes API and storage on + # a private address need extraEgress. + enabled: false + ingressFrom: [] + extraEgress: [] + # In each namespace of rbac.namespaces: let the Jobs' pods reach PostgreSQL (5432) on the + # CloudNativePG pods, for clusters whose pods take only listed clients. + databases: + enabled: false + +resources: + requests: + cpu: 10m + memory: 96Mi + limits: + memory: 256Mi + +priorityClassName: "" +podLabels: {} +podAnnotations: {} +nodeSelector: {} +tolerations: [] +affinity: {} +extraEnv: [] diff --git a/docker-bake.hcl b/docker-bake.hcl new file mode 100644 index 0000000..7ea9fef --- /dev/null +++ b/docker-bake.hcl @@ -0,0 +1,33 @@ +# Diatreme sets these for a release: VERSION (pr- on a pull request, the release tag +# after a merge), REGISTRY and IMAGE_NAME (/). +variable "VERSION" { default = "latest" } +variable "REGISTRY" { default = "ghcr.io" } +variable "IMAGE_NAME" { default = "magmamoose/databases-ui" } +variable "PLATFORMS" { default = "linux/amd64,linux/arm64" } + +group "default" { + targets = ["app"] +} + +target "app" { + context = "." + dockerfile = "Dockerfile" + platforms = split(",", PLATFORMS) + tags = ["${REGISTRY}/${IMAGE_NAME}:${VERSION}"] + args = { + VERSION = "${VERSION}" + } + labels = { + "org.opencontainers.image.source" = "https://github.com/MagmaMoose/databases-ui" + "org.opencontainers.image.description" = "Snapshot, restore and clone your own PostgreSQL databases on CloudNativePG" + "org.opencontainers.image.licenses" = "Apache-2.0" + } +} + +# Local single-arch build that loads into Docker: docker buildx bake app-local +target "app-local" { + inherits = ["app"] + platforms = [] + tags = ["databases-ui:dev"] + output = ["type=docker"] +} diff --git a/e2e/fixtures.yaml b/e2e/fixtures.yaml new file mode 100644 index 0000000..7b4a434 --- /dev/null +++ b/e2e/fixtures.yaml @@ -0,0 +1,193 @@ +# The world the end-to-end test runs in: two CloudNativePG clusters standing in for two +# environments (dev, and tst as production), an app in each that holds a connection open, Azurite +# for storage, and NetworkPolicies that let only listed clients reach PostgreSQL. +apiVersion: v1 +kind: Namespace +metadata: + name: database +--- +apiVersion: v1 +kind: Namespace +metadata: + name: storage +--- +apiVersion: v1 +kind: Namespace +metadata: + name: dev-payments +--- +apiVersion: v1 +kind: Namespace +metadata: + name: tst-payments +--- +apiVersion: v1 +kind: Namespace +metadata: + name: databases-ui +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: azurite + namespace: storage +spec: + replicas: 1 + selector: + matchLabels: {app: azurite} + template: + metadata: + labels: {app: azurite} + spec: + containers: + - name: azurite + image: mcr.microsoft.com/azure-storage/azurite:3.35.0 + command: [azurite-blob, --blobHost, 0.0.0.0, --blobPort, "10000", --skipApiVersionCheck, --disableProductStyleUrl, --location, /data] + envFrom: + # AZURITE_ACCOUNTS=:, written by run.sh: a key made for this run. + - secretRef: {name: azurite-account} + ports: + - containerPort: 10000 + volumeMounts: + - {name: data, mountPath: /data} + volumes: + - {name: data, emptyDir: {}} +--- +apiVersion: v1 +kind: Service +metadata: + name: azurite + namespace: storage +spec: + selector: {app: azurite} + ports: + - {port: 10000, targetPort: 10000} +--- +apiVersion: postgresql.cnpg.io/v1 +kind: Cluster +metadata: + name: dev + namespace: database +spec: + instances: 1 + imageName: ghcr.io/cloudnative-pg/postgresql:18.6-system-trixie + storage: + size: 1Gi + managed: + roles: + - name: payments_dev + ensure: present + login: true + superuser: false + passwordSecret: {name: payments-dev-db} +--- +apiVersion: postgresql.cnpg.io/v1 +kind: Cluster +metadata: + name: tst + namespace: database +spec: + instances: 1 + imageName: ghcr.io/cloudnative-pg/postgresql:18.6-system-trixie + storage: + size: 1Gi + managed: + roles: + - name: payments_tst + ensure: present + login: true + superuser: false + passwordSecret: {name: payments-tst-db} +--- +apiVersion: postgresql.cnpg.io/v1 +kind: Database +metadata: + name: payments-dev + namespace: database +spec: + cluster: {name: dev} + name: payments_dev + owner: payments_dev + ensure: present + # Created by the operator, not by the owner: a dump must leave it out to restore as the owner. + extensions: + - name: citext + ensure: present +--- +apiVersion: postgresql.cnpg.io/v1 +kind: Database +metadata: + name: payments-tst + namespace: database +spec: + cluster: {name: tst} + name: payments_tst + owner: payments_tst + ensure: present + extensions: + - name: citext + ensure: present +--- +# The platform's pattern: CloudNativePG pods take only their own cluster, the operator and the +# apps listed per cluster. The chart's own rule adds the Jobs. +apiVersion: networking.k8s.io/v1 +kind: NetworkPolicy +metadata: + name: cnpg-default-deny + namespace: database +spec: + podSelector: + matchExpressions: + - {key: cnpg.io/cluster, operator: Exists} + policyTypes: [Ingress, Egress] +--- +apiVersion: networking.k8s.io/v1 +kind: NetworkPolicy +metadata: + name: cnpg-allow-clients + namespace: database +spec: + podSelector: + matchExpressions: + - {key: cnpg.io/cluster, operator: Exists} + policyTypes: [Ingress] + ingress: + - from: + - podSelector: + matchExpressions: + - {key: cnpg.io/cluster, operator: Exists} + - namespaceSelector: + matchLabels: {kubernetes.io/metadata.name: cnpg-system} + - from: + - namespaceSelector: + matchExpressions: + - {key: kubernetes.io/metadata.name, operator: In, values: [dev-payments, tst-payments]} + ports: + - {protocol: TCP, port: 5432} +--- +apiVersion: networking.k8s.io/v1 +kind: NetworkPolicy +metadata: + name: cnpg-allow-required-egress + namespace: database +spec: + podSelector: + matchExpressions: + - {key: cnpg.io/cluster, operator: Exists} + policyTypes: [Egress] + egress: + - to: + - podSelector: + matchExpressions: + - {key: cnpg.io/cluster, operator: Exists} + - to: + - namespaceSelector: + matchLabels: {kubernetes.io/metadata.name: kube-system} + ports: + - {protocol: UDP, port: 53} + - {protocol: TCP, port: 53} + - to: + - ipBlock: {cidr: 0.0.0.0/0} + ports: + - {protocol: TCP, port: 443} + - {protocol: TCP, port: 6443} diff --git a/e2e/run.py b/e2e/run.py new file mode 100644 index 0000000..bbc06ea --- /dev/null +++ b/e2e/run.py @@ -0,0 +1,401 @@ +"""End to end on a real cluster: CloudNativePG, Azurite, this chart and this image. + + k3d cluster create dbui --k3s-arg "--disable=traefik@server:0" + helm install cnpg cloudnative-pg --repo https://cloudnative-pg.github.io/charts \ + --version 0.29.1 --namespace cnpg-system --create-namespace --wait + docker buildx bake app-local && k3d image import databases-ui:dev -c dbui + uv run python e2e/run.py + +It installs fixtures.yaml and the chart, signs people in by sealing their session cookies with the +chart's own session key (Entra ID is the one thing not in the loop), and walks every action +through the API: snapshots, a restore in place with the app scaled down, a restore into a copy, a +clone across environments, a production restore and its second person, a decline, a download, +the audit log and who may do what. Each step checks the database itself, not just the answers. +""" + +from __future__ import annotations + +import base64 +import hashlib +import hmac +import json +import secrets +import subprocess # nosec B404 - drives kubectl and helm for a test +import sys +import time +from contextlib import contextmanager +from pathlib import Path +from typing import Any +from urllib.parse import quote + +import httpx + +from databases_ui.session import Sealer + +HERE = Path(__file__).resolve().parent +CHART = HERE.parent / "charts" / "databases-ui" +ACCOUNT = "e2eaccount" +ORIGIN = "http://localhost:18080" # DevSkim: ignore DS162092 - the port-forwarded test server +PAYMENTS = "6f1c2b7e-3a44-4d0e-9a51-2b8e0c7d9f10" +OTHERS = "0b9d8e7c-6f5a-4b3c-8d2e-1f0a9b8c7d6e" +PEOPLE = { + "alice": {"groups": [PAYMENTS], "roles": []}, + "bob": {"groups": [PAYMENTS], "roles": []}, + "carol": {"groups": [OTHERS], "roles": []}, + "audrey": {"groups": [], "roles": ["Auditor"]}, +} +passed: list[str] = [] + + +def sh(*args: str, input: str | None = None, check: bool = True) -> str: + done = subprocess.run(args, input=input, capture_output=True, text=True, check=False) # nosec B603 - fixed test commands + if check and done.returncode != 0: + raise RuntimeError(f"{' '.join(args)}: {done.stderr.strip() or done.stdout.strip()}") + return done.stdout + + +def kubectl(*args: str, input: str | None = None, check: bool = True) -> str: + return sh("kubectl", *args, input=input, check=check) + + +def ok(what: str) -> None: + passed.append(what) + print(f" ok {what}", flush=True) + + +def psql(cluster: str, database: str, sql: str) -> str: + return kubectl("exec", "-n", "database", f"{cluster}-1", "-c", "postgres", "--", "psql", "-v", "ON_ERROR_STOP=1", "-Atq", "-d", database, "-c", sql).strip() + + +def wait_for(what: str, test, timeout: float = 300, every: float = 3) -> Any: + deadline = time.monotonic() + timeout + while True: + try: + found = test() + except (RuntimeError, httpx.HTTPError): + found = None + if found: + return found + if time.monotonic() > deadline: + raise SystemExit(f"timed out waiting for {what}") + time.sleep(every) + + +def account_sas(key: str) -> str: + """An account SAS for Azurite: blob service, every resource type, everything this app does.""" + fields = {"sv": "2022-11-02", "ss": "b", "srt": "sco", "sp": "rwdlac", "se": "2030-01-01T00:00:00Z", "spr": "https,http"} + to_sign = "\n".join([ACCOUNT, fields["sp"], fields["ss"], fields["srt"], "", fields["se"], "", fields["spr"], fields["sv"], "", ""]) + sig = base64.b64encode(hmac.new(base64.b64decode(key), to_sign.encode(), hashlib.sha256).digest()).decode() + return "&".join(f"{k}={quote(v, safe='')}" for k, v in {**fields, "sig": sig}.items()) + + +@contextmanager +def port_forward(namespace: str, target: str, ports: str): + proc = subprocess.Popen(["kubectl", "port-forward", "-n", namespace, target, ports], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) # nosec B603 B607 + try: + time.sleep(2) + yield + finally: + proc.terminate() + proc.wait() + + +def apply(*objects: dict[str, Any]) -> None: + kubectl("apply", "-f", "-", input="\n---\n".join(json.dumps(o) for o in objects)) + + +def setup() -> tuple[str, dict[str, str]]: + print("fixtures", flush=True) + apply(*({"apiVersion": "v1", "kind": "Namespace", "metadata": {"name": n}} for n in ("database", "storage", "dev-payments", "tst-payments", "databases-ui"))) + # Leftovers of an earlier run. + kubectl("delete", "jobs", "-n", "database", "-l", "app.kubernetes.io/managed-by=databases-ui", "--ignore-not-found", check=False) + kubectl("delete", "databases.postgresql.cnpg.io", "-n", "database", "-l", "databases-ui/copy-of", "--ignore-not-found", check=False) + key = base64.b64encode(secrets.token_bytes(64)).decode() + apply({"apiVersion": "v1", "kind": "Secret", "metadata": {"name": "azurite-account", "namespace": "storage"}, "stringData": {"AZURITE_ACCOUNTS": f"{ACCOUNT}:{key}"}}) + for env in ("dev", "tst"): + # Kept across runs: CloudNativePG sets a role's password when it creates the role. + kept = kubectl("get", "secret", f"payments-{env}-db", "-n", "database", "-o", "jsonpath={.data.password}", check=False) + password = base64.b64decode(kept).decode() if kept else secrets.token_urlsafe(24) + apply( + {"apiVersion": "v1", "kind": "Secret", "type": "kubernetes.io/basic-auth", "metadata": {"name": f"payments-{env}-db", "namespace": "database"}, "stringData": {"username": f"payments_{env}", "password": password}}, + {"apiVersion": "v1", "kind": "Secret", "metadata": {"name": "payments-db", "namespace": f"{env}-payments"}, "stringData": {"password": password}}, + ) + kubectl("apply", "-f", str(HERE / "fixtures.yaml")) + # A new key each run: Azurite starts empty with it. + kubectl("rollout", "restart", "deployment/azurite", "-n", "storage") + for env in ("dev", "tst"): + # The app: two replicas, each holding a session open the whole time. + kubectl("apply", "-f", "-", input=json.dumps({ + "apiVersion": "apps/v1", "kind": "Deployment", "metadata": {"name": "payments-api", "namespace": f"{env}-payments"}, + "spec": {"replicas": 2, "selector": {"matchLabels": {"app": "payments-api"}}, "template": { + "metadata": {"labels": {"app": "payments-api"}}, + "spec": {"terminationGracePeriodSeconds": 2, "securityContext": {"runAsNonRoot": True, "runAsUser": 10001}, "containers": [{ + "name": "api", "image": "databases-ui:dev", "imagePullPolicy": "IfNotPresent", "command": ["sh", "-c", "while true; do psql -Atqc 'select pg_sleep(600)'; sleep 1; done"], + "env": [{"name": "PGHOST", "value": f"{env}-rw.database.svc"}, {"name": "PGUSER", "value": f"payments_{env}"}, {"name": "PGDATABASE", "value": f"payments_{env}"}, + {"name": "PGSSLMODE", "value": "require"}, {"name": "HOME", "value": "/tmp"}, + {"name": "PGPASSWORD", "valueFrom": {"secretKeyRef": {"name": "payments-db", "key": "password"}}}], + }]}, + }}, + })) # fmt: skip + kubectl("rollout", "restart", "deployment/payments-api", "-n", f"{env}-payments") + for env in ("dev", "tst"): + kubectl("wait", "-n", "database", f"cluster/{env}", "--for=condition=Ready", "--timeout=600s") + wait_for(f"database payments_{env}", lambda env=env: kubectl("get", "-n", "database", f"database/payments-{env}", "-o", "jsonpath={.status.applied}") == "true") + wait_for(f"role payments_{env}", lambda env=env: psql(env, "postgres", f"select 1 from pg_roles where rolname = 'payments_{env}'") == "1") + password = base64.b64decode(kubectl("get", "secret", f"payments-{env}-db", "-n", "database", "-o", "jsonpath={.data.password}")).decode() + psql(env, "postgres", f"alter role payments_{env} password '{password}'") + psql(env, f"payments_{env}", f""" + set role payments_{env}; + drop table if exists orders, later; + create table orders (id int primary key, customer citext not null, total numeric(10,2) not null); + insert into orders values (1, '{env}-Ada', 12.50), (2, '{env}-Grace', 99.00), (3, '{env}-Katherine', 7.25); + """) # fmt: skip + kubectl("rollout", "status", "deployment/azurite", "-n", "storage", "--timeout=180s") + sas = account_sas(key) + with port_forward("storage", "svc/azurite", "10010:10000"): + for env in ("dev", "tst"): + response = httpx.put(f"http://127.0.0.1:10010/{ACCOUNT}/{env}?restype=container&{sas}", headers={"x-ms-version": "2022-11-02"}) # DevSkim: ignore DS137138 + assert response.status_code in (201, 409), response.text + for namespace in ("databases-ui", "database"): + kubectl("apply", "-f", "-", input=json.dumps({"apiVersion": "v1", "kind": "Secret", "metadata": {"name": "databases-ui-storage", "namespace": namespace}, "stringData": {"sas": sas}})) + kubectl("apply", "-f", "-", input=json.dumps({"apiVersion": "v1", "kind": "Secret", "metadata": {"name": "databases-ui-entra", "namespace": "databases-ui"}, "stringData": {"client-secret": "unused-here"}})) + + print("chart", flush=True) + values = { + "replicaCount": 1, + "image": {"repository": "databases-ui", "tag": "dev", "pullPolicy": "IfNotPresent"}, + "azure": {"tenantId": "11111111-2222-3333-4444-555555555555", "clientId": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee", "workloadIdentity": {"enabled": False}, "clientSecret": {"existingSecret": "databases-ui-entra"}}, + "config": {"publicOrigin": ORIGIN}, + "storage": {"sas": {"existingSecret": "databases-ui-storage"}}, + "rbac": {"namespaces": ["database"]}, + "jobs": {"scaleNamespaces": ["dev-payments", "tst-payments"]}, + "networkPolicy": {"databases": {"enabled": True}}, + "catalog": {"content": { + "environments": [ + {"name": "dev", "storage": {"url": f"http://azurite.storage.svc:10000/{ACCOUNT}/dev"}, "cloneFrom": ["tst"]}, # DevSkim: ignore DS137138 + {"name": "tst", "production": True, "storage": {"url": f"http://azurite.storage.svc:10000/{ACCOUNT}/tst"}, "cloneFrom": ["dev"]}, # DevSkim: ignore DS137138 + ], + "teams": [ + {"id": "payments", "name": "Payments", "groups": [PAYMENTS], "databases": [{"name": "payments_{env}", "workloads": ["deployment/{env}-payments/payments-api"]}]}, + {"id": "others", "name": "Others", "groups": [OTHERS], "databases": [{"name": "elsewhere"}]}, + ], + }}, + } # fmt: skip + sh("helm", "upgrade", "--install", "databases-ui", str(CHART), "-n", "databases-ui", "--values", "-", "--wait", "--timeout", "180s", input=json.dumps(values)) + kubectl("rollout", "restart", "deployment/databases-ui", "-n", "databases-ui") + kubectl("rollout", "status", "deployment/databases-ui", "-n", "databases-ui", "--timeout=180s") + session_key = base64.b64decode(kubectl("get", "secret", "databases-ui-session", "-n", "databases-ui", "-o", "jsonpath={.data.session-key}")) + sealer = Sealer(session_key) + cookies = {} + for person, who in PEOPLE.items(): + data = {"oid": hashlib.md5(person.encode()).hexdigest(), "upn": f"{person}@example.com", "name": person.title(), "csrf": f"csrf-{person}", **who} # nosec B324 - an id for a test person + cookies[person] = sealer.seal("session", data, 3600) + return sas, cookies + + +class Client: + def __init__(self, person: str, token: str): + self.person = person + self.http = httpx.Client(base_url=ORIGIN, cookies={"databases-ui.0": token}, timeout=60) + self.headers = {"Origin": ORIGIN, "X-CSRF-Token": f"csrf-{person}"} + + def get(self, path: str) -> httpx.Response: + return self.http.get(path) + + def post(self, path: str, body: dict[str, Any] | None = None, *, csrf: bool = True) -> httpx.Response: + return self.http.post(path, json=body or {}, headers=self.headers if csrf else {}) + + def delete(self, path: str) -> httpx.Response: + return self.http.delete(path, headers=self.headers) + + +def finished(c: Client, env: str, job: str) -> dict[str, Any]: + def done(): + found = next((j for j in c.get(f"/api/environments/{env}/jobs").json()["jobs"] if j["name"] == job), None) + return found if found and found["state"] in ("succeeded", "failed") else None + + found = wait_for(f"job {job}", done, timeout=300) + if found["state"] != "succeeded": + raise SystemExit(f"{job} failed: {found['result']}") + return found + + +def orders(env: str, database: str) -> list[str]: + return psql(env, database, "select customer from orders order by id").splitlines() + + +def replicas(env: str) -> str: + return kubectl("get", "deployment/payments-api", "-n", f"{env}-payments", "-o", "jsonpath={.spec.replicas}") + + +def scenarios(cookies: dict[str, str]) -> None: + alice, bob, carol, audrey = (Client(p, cookies[p]) for p in ("alice", "bob", "carol", "audrey")) + + print("who sees what", flush=True) + me = alice.get("/api/me").json() + assert [t["id"] for t in me["teams"]] == ["payments"] and [e["name"] for e in me["environments"]] == ["dev", "tst"], me + ok("me: alice is in payments, sees dev and tst") + assert [d["name"] for d in alice.get("/api/environments/dev/databases").json()["databases"]] == ["payments_dev"] + assert carol.get("/api/environments/dev/databases").json()["databases"] == [] + assert {d["name"] for d in audrey.get("/api/environments/tst/databases").json()["databases"]} == {"payments_tst"} + ok("databases: a member sees the team's, another team nothing, an auditor everything") + assert carol.post("/api/environments/dev/databases/payments_dev/snapshots").status_code == 403 + assert audrey.post("/api/environments/dev/databases/payments_dev/snapshots").status_code == 403 + assert alice.post("/api/environments/dev/databases/payments_dev/snapshots", csrf=False).status_code == 403 + ok("refused: another team, an auditor, and a write without the CSRF token") + + print("snapshot", flush=True) + job = alice.post("/api/environments/dev/databases/payments_dev/snapshots", {"note": "before the test"}).json() + snap = finished(alice, "dev", job["name"]) + assert snap["result"]["bytes"] > 0, snap + snapshots = alice.get("/api/environments/dev/databases/payments_dev/snapshots").json()["snapshots"] + assert len(snapshots) == 1 and snapshots[0]["note"] == "before the test" and snapshots[0]["created_by"] == "alice@example.com", snapshots + dev_snapshot = snapshots[0]["id"] + ok(f"snapshot of dev: {snapshots[0]['size']} bytes in blob storage, with who and why") + + print("restore in place", flush=True) + psql("dev", "payments_dev", "set role payments_dev; delete from orders where id > 1; update orders set total = 0; create table later (id int)") + assert orders("dev", "payments_dev") == ["dev-Ada"] + sessions = int(psql("dev", "payments_dev", "select count(*) from pg_stat_activity where usename = 'payments_dev'")) + assert sessions >= 2, sessions + body = {"source_environment": "dev", "source_database": "payments_dev", "snapshot": dev_snapshot, "into": "database", "reason": "undo the bad batch"} + job = alice.post("/api/environments/dev/databases/payments_dev/restore", body).json() + assert job["state"] in ("starting", "running"), job + assert alice.post("/api/environments/dev/databases/payments_dev/restore", body).status_code == 409 + ok("a second action on a busy database is refused") + seen_zero = wait_for("the app to scale down", lambda: replicas("dev") == "0", timeout=120, every=1) + finished(alice, "dev", job["name"]) + assert orders("dev", "payments_dev") == ["dev-Ada", "dev-Grace", "dev-Katherine"] + assert psql("dev", "payments_dev", "select sum(total) from orders") == "118.75" + assert psql("dev", "payments_dev", "select to_regclass('later') is not null") == "t" + assert seen_zero and replicas("dev") == "2" + assert kubectl("get", "deployment/payments-api", "-n", "dev-payments", "-o", "jsonpath={.metadata.annotations}").find("replicas-before-restore") == -1 + ok("restore in place: data back, the app went to 0 and back to 2, a table made later stays") + wait_for("the app's sessions to return", lambda: int(psql("dev", "payments_dev", "select count(*) from pg_stat_activity where usename = 'payments_dev'")) >= 2, timeout=120) + ok("the app reconnected") + + print("restore into a copy", flush=True) + psql("dev", "payments_dev", "set role payments_dev; delete from orders where id = 3") + job = alice.post("/api/environments/dev/databases/payments_dev/restore", {**body, "into": "copy", "reason": "look at last week's rows"}).json() + finished(alice, "dev", job["name"]) + assert orders("dev", "payments_dev_copy") == ["dev-Ada", "dev-Grace", "dev-Katherine"] + assert orders("dev", "payments_dev") == ["dev-Ada", "dev-Grace"] + assert psql("dev", "payments_dev_copy", "select extname from pg_extension where extname = 'citext'") == "citext" + db = alice.get("/api/environments/dev/databases").json()["databases"][0] + assert db["copy"]["name"] == "payments_dev_copy", db + ok("restore into a copy: payments_dev_copy holds the snapshot with its extension, payments_dev untouched") + + print("clone from production", flush=True) + job = alice.post("/api/environments/tst/databases/payments_tst/snapshots", {"note": "for dev"}).json() + finished(alice, "tst", job["name"]) + tst_snapshot = alice.get("/api/environments/tst/databases/payments_tst/snapshots").json()["snapshots"][0]["id"] + job = alice.post("/api/environments/dev/databases/payments_dev/restore", {"source_environment": "tst", "source_database": "payments_tst", "snapshot": tst_snapshot, "into": "database", "reason": "reproduce the tst bug"}).json() + assert job["source_environment"] == "tst", job + finished(alice, "dev", job["name"]) + assert orders("dev", "payments_dev") == ["tst-Ada", "tst-Grace", "tst-Katherine"] + ok("clone: tst's snapshot restored into dev") + + print("production restore needs a second person", flush=True) + psql("tst", "payments_tst", "set role payments_tst; truncate orders") + body = {"source_environment": "tst", "source_database": "payments_tst", "snapshot": tst_snapshot, "into": "database", "reason": "restore after the truncate"} + job = alice.post("/api/environments/tst/databases/payments_tst/restore", body).json() + assert job["state"] == "waiting" and job["approval"] == "required", job + time.sleep(5) + assert replicas("tst") == "2" and orders("tst", "payments_tst") == [] + ok("production restore waits: nothing ran, the app untouched") + assert alice.post(f"/api/environments/tst/jobs/{job['name']}/approve").status_code == 403 + assert carol.post(f"/api/environments/tst/jobs/{job['name']}/approve").status_code == 403 + listed = next(j for j in bob.get("/api/environments/tst/jobs").json()["jobs"] if j["name"] == job["name"]) + assert listed["can_approve"] and not next(j for j in alice.get("/api/environments/tst/jobs").json()["jobs"] if j["name"] == job["name"])["can_approve"] + ok("refused: approving your own request, or another team's") + approved = bob.post(f"/api/environments/tst/jobs/{job['name']}/approve").json() + assert approved["approved_by"] == "bob@example.com", approved + finished(bob, "tst", job["name"]) + assert orders("tst", "payments_tst") == ["tst-Ada", "tst-Grace", "tst-Katherine"] and replicas("tst") == "2" + ok("bob approved; the restore ran") + job = alice.post("/api/environments/tst/databases/payments_tst/restore", body).json() + assert bob.post(f"/api/environments/tst/jobs/{job['name']}/decline", {"reason": "not now"}).status_code == 204 + assert kubectl("get", "job", job["name"], "-n", "database", "--ignore-not-found", "-o", "name") == "" + ok("bob declined another; its Job is gone") + + print("downloads", flush=True) + response = alice.get(f"/api/environments/dev/databases/payments_dev/snapshots/{dev_snapshot}/download") + assert response.status_code == 200 and response.content[:5] == b"PGDMP", response.status_code + assert alice.get(f"/api/environments/tst/databases/payments_tst/snapshots/{tst_snapshot}/download").status_code == 403 + assert carol.get(f"/api/environments/dev/databases/payments_dev/snapshots/{dev_snapshot}/download").status_code == 403 + ok(f"download from dev ({len(response.content)} bytes, a pg_dump archive); none from production or for another team") + + print("drop the copy", flush=True) + assert alice.delete("/api/environments/dev/databases/payments_dev/copy").status_code == 204 + wait_for("the copy to go", lambda: psql("dev", "postgres", "select count(*) from pg_database where datname = 'payments_dev_copy'") == "0", timeout=120) + ok("dropped the copy: CloudNativePG dropped payments_dev_copy") + + print("audit log", flush=True) + dev_log = [(e["action"], e["actor"]) for e in alice.get("/api/environments/dev/audit").json()["entries"]] + tst_log = [(e["action"], e["actor"]) for e in bob.get("/api/environments/tst/audit").json()["entries"]] + for entry in [("snapshot.requested", "alice@example.com"), ("snapshot.succeeded", "alice@example.com"), ("restore.requested", "alice@example.com"), ("restore.succeeded", "alice@example.com"), ("snapshot.downloaded", "alice@example.com"), ("copy.dropped", "alice@example.com")]: + assert entry in dev_log, (entry, dev_log) + for entry in [("restore.approved", "bob@example.com"), ("restore.declined", "bob@example.com"), ("restore.succeeded", "alice@example.com")]: + assert entry in tst_log, (entry, tst_log) + assert carol.get("/api/environments/dev/audit").json()["entries"] == [] + ok(f"audit log: {len(dev_log)} entries in dev, {len(tst_log)} in tst, who and what; none shown to another team") + + +def forged(base: dict[str, Any], change) -> str: + """Create a changed copy of a Job as this app's own service account; what Kubernetes said.""" + job = json.loads(json.dumps(base)) + job["metadata"] = {"name": f"forged-{secrets.token_hex(3)}", "namespace": "database", "labels": job["metadata"]["labels"], "annotations": job["metadata"].get("annotations", {})} + job.pop("status", None) + job["spec"].pop("selector", None) + job["spec"]["template"]["metadata"]["labels"] = {k: v for k, v in job["spec"]["template"]["metadata"]["labels"].items() if "controller-uid" not in k and "job-name" not in k} + job["spec"]["suspend"] = True + change(job["spec"]["template"]["spec"]) + done = subprocess.run(["kubectl", "--as=system:serviceaccount:databases-ui:databases-ui", "create", "-f", "-"], input=json.dumps(job), capture_output=True, text=True, check=False) # nosec B603 B607 + if done.returncode == 0: + kubectl("delete", "job", job["metadata"]["name"], "-n", "database", "--wait=false") + return "created" + return done.stderr + + +def policy() -> None: + print("what the server's own account may do", flush=True) + name = kubectl("get", "jobs", "-n", "database", "-l", "databases-ui/action=snapshot", "-o", "jsonpath={.items[0].metadata.name}") + base = json.loads(kubectl("get", "job", name, "-n", "database", "-o", "json")) + + def env(var: str, value: Any): + def change(pod: dict[str, Any]) -> None: + for e in pod["containers"][0]["env"]: + if e["name"] == var: + e.clear() + e.update({"name": var, **value}) + return change + + assert forged(base, lambda pod: None) == "created" + for what, change, said in [ + ("the superuser's password", env("PGPASSWORD", {"valueFrom": {"secretKeyRef": {"name": "dev-superuser", "key": "password"}}}), "never a superuser's"), + ("another image", lambda pod: pod["containers"][0].update(image="busybox:1.36"), "only this app's own image"), + ("a shell", lambda pod: pod["containers"][0].update(command=["sh", "-c", "cat /etc/databases-ui/ca/*"]), "only this app's own image"), + ("the CA's key", lambda pod: next(v for v in pod["volumes"] if v["name"] == "ca")["secret"].update(items=[{"key": "ca.key", "path": "ca.key"}]), "a CA certificate, nothing else"), + ("someone else's storage", env("DBUI_BLOB_URL", {"value": "https://attacker.blob.core.windows.net/loot"}), "only the catalog's storage"), + ("a database elsewhere", env("PGHOST", {"value": "postgres.attacker.example"}), "in their own namespace"), + ("TLS without checks", env("PGSSLMODE", {"value": "disable"}), "verified TLS"), + ]: + answer = forged(base, change) + assert said in answer, (what, answer) + ok("admission policy: a Job as built passes; with a superuser's password, another image or command, the CA key, other storage, another host or no TLS checks it is refused") + for verb, resource in (("get", "secrets"), ("create", "pods"), ("delete", "clusters.postgresql.cnpg.io")): + assert kubectl("auth", "can-i", verb, resource, "-n", "database", "--as=system:serviceaccount:databases-ui:databases-ui", check=False).strip() == "no" + ok("RBAC: the server's account reads no Secret, creates no pod and deletes no Cluster") + + +def main() -> None: + _, cookies = setup() + with port_forward("databases-ui", "svc/databases-ui", "18080:80"): + wait_for("the server", lambda: httpx.get(f"{ORIGIN}/healthz").status_code == 200, timeout=60, every=1) + scenarios(cookies) + policy() + print(f"\n{len(passed)} checks passed") + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/examples/catalog.yaml b/examples/catalog.yaml new file mode 100644 index 0000000..544d38d --- /dev/null +++ b/examples/catalog.yaml @@ -0,0 +1,44 @@ +# Four environments, each with its own cluster and storage, and two teams. Check it with +# python -m databases_ui check examples/catalog.yaml +environments: + - name: dev + storage: + url: https://examplesnapshots.blob.core.windows.net/dev + cloneFrom: [tst, acc] + - name: tst + storage: + url: https://examplesnapshots.blob.core.windows.net/tst + cloneFrom: [acc] + - name: acc + storage: + url: https://examplesnapshots.blob.core.windows.net/acc + - name: prd + production: true + # The Cluster's own name, when it differs from the environment's. + cluster: prod + storage: + url: https://exampleprdsnapshots.blob.core.windows.net/prd + +teams: + - id: payments + name: Payments + description: Builds and runs the payments service. + groups: [6f1c2b7e-3a44-4d0e-9a51-2b8e0c7d9f10] + databases: + - name: payments_{env} + # {env} is the environment; a block list, since YAML reads braces in [ ] as a mapping. + workloads: + - deployment/{env}-payments/payments-api + - deployment/{env}-payments/payments-worker + - id: identity + name: Identity + description: Runs single sign-on for every app. + groups: [0b9d8e7c-6f5a-4b3c-8d2e-1f0a9b8c7d6e] + databases: + - name: keycloak + environments: [dev, tst, acc] + workloads: + - statefulset/{env}-keycloak/keycloak + - name: keycloak_prd + environments: [prd] + workloads: [statefulset/prd-keycloak/keycloak] diff --git a/frontend/index.html b/frontend/index.html new file mode 100644 index 0000000..50d2f1e --- /dev/null +++ b/frontend/index.html @@ -0,0 +1,15 @@ + + + + + + + + + Databases UI + + +
+ + + diff --git a/frontend/package-lock.json b/frontend/package-lock.json new file mode 100644 index 0000000..e4510e1 --- /dev/null +++ b/frontend/package-lock.json @@ -0,0 +1,1295 @@ +{ + "name": "databases-ui-frontend", + "version": "0.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "databases-ui-frontend", + "version": "0.0.0", + "dependencies": { + "react": "19.3.0", + "react-dom": "19.3.0" + }, + "devDependencies": { + "@types/react": "19.3.0", + "@types/react-dom": "19.3.0", + "@vitejs/plugin-react": "6.1.2", + "typescript": "7.0.2", + "vite": "8.3.4" + } + }, + "node_modules/@oxc-project/types": { + "version": "0.154.0", + "resolved": "https://registry.npmjs.org/@oxc-project/types/-/types-0.154.0.tgz", + "integrity": "sha512-KYOUGQFlLWR+s4QMV2Q9ko38TZm7EdO87Qm7rvZLqk/webse/cDjtyxKhg/47l0byCbs/k46LT8qc4PKjAikzA==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/oxc-project" + } + }, + "node_modules/@rolldown/binding-android-arm-eabi": { + "version": "1.2.14", + "resolved": "https://registry.npmjs.org/@rolldown/binding-android-arm-eabi/-/binding-android-arm-eabi-1.2.14.tgz", + "integrity": "sha512-aWR+XKH9+rW7m5fWq/5360J3mHycrx/o6xZM2DQFdJnTMdyP7/WzxPjhtLbVWdKo2y612/4U1bWqb3HQhiF7vg==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-android-arm64": { + "version": "1.2.14", + "resolved": "https://registry.npmjs.org/@rolldown/binding-android-arm64/-/binding-android-arm64-1.2.14.tgz", + "integrity": "sha512-QiVxHofl6A8lQU7WAtOUY4QMVZXohxwz7WJJoeh8NBEUyKfIkMRKhYyq8az/1RypNiIXzNTtiS6KwHz0erxYRQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-darwin-arm64": { + "version": "1.2.14", + "resolved": "https://registry.npmjs.org/@rolldown/binding-darwin-arm64/-/binding-darwin-arm64-1.2.14.tgz", + "integrity": "sha512-lTQOzHuBIooh3jIr5XINQkjPGEuGy+Dsy0meXDr6Sjty0b99kYgGh4uBC/8mJX1T0kC8d6S0aPP1Y+bHkh6aBw==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-darwin-x64": { + "version": "1.2.14", + "resolved": "https://registry.npmjs.org/@rolldown/binding-darwin-x64/-/binding-darwin-x64-1.2.14.tgz", + "integrity": "sha512-hyMKEGatjmBYCs/Q4sbIcL/GqpFEqsX3wc+HYVQ/85A4rxc1o7rPm4DUI4GV4k/h0ITddwFSGpqQunI14GXjTA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-freebsd-x64": { + "version": "1.2.14", + "resolved": "https://registry.npmjs.org/@rolldown/binding-freebsd-x64/-/binding-freebsd-x64-1.2.14.tgz", + "integrity": "sha512-u371GbXoVXrEgP20PwzoGNOdAOqAMhzo19JzzY+V4YmmnC+DTOoqdbMu+O+54emM59Mik/UdrtWgcuEDKWRPKA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-arm-gnueabihf": { + "version": "1.2.14", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-arm-gnueabihf/-/binding-linux-arm-gnueabihf-1.2.14.tgz", + "integrity": "sha512-BqwKsdZQf6EqVWr8fv2MrDYzAvOZ7+NYFSJESRGs87fkseEhs0TU9TXgRJTkZoRRkxTizyEg1LKUXfU3/78uqg==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-arm64-gnu": { + "version": "1.2.14", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-arm64-gnu/-/binding-linux-arm64-gnu-1.2.14.tgz", + "integrity": "sha512-SD9kY8M009x/7s57Z1dgUVlP5+uYBgKQK0Tkr1WIWngrtUJmRCW1RJFMY7QDla2khXhmg2i5Io7MUjcmZNZ/KQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-arm64-musl": { + "version": "1.2.14", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-arm64-musl/-/binding-linux-arm64-musl-1.2.14.tgz", + "integrity": "sha512-BJ2CL19M6uuWesMgnqJzgxoI+N+eV7b0A9O9vLV42y+gitC41fNa8KElau1tHVzuLWX5GzEuxMPhAO0tQXQMkg==", + "cpu": [ + "arm64" + ], + "dev": true, + "libc": [ + "musl" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-ppc64-gnu": { + "version": "1.2.14", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-ppc64-gnu/-/binding-linux-ppc64-gnu-1.2.14.tgz", + "integrity": "sha512-4+Kl8daPV8NDHaD7mfCcc1pRM+Qg7ab8DyMm5FG5WoZgv4h2i3KFN1CybYBNbQqmuYm7ftJLvmMI1eHYJ22S/Q==", + "cpu": [ + "ppc64" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-s390x-gnu": { + "version": "1.2.14", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-s390x-gnu/-/binding-linux-s390x-gnu-1.2.14.tgz", + "integrity": "sha512-V/h8ePq1fKDrmtFMz6xcCN3DKvuvMRrwwD1q0PkBeeo4DpK64biaKvqWGVxqCeYKqeRk7gE7/iKPxLCn08O97A==", + "cpu": [ + "s390x" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-x64-gnu": { + "version": "1.2.14", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-x64-gnu/-/binding-linux-x64-gnu-1.2.14.tgz", + "integrity": "sha512-WxalXzgrLVpKC93xfpaJ3gCXUWzeCr+FRCbDVD2mUAy4L6Vo3lNVz0epUEUpxPWJkLNYUwM4OSIikv36OJ9mLg==", + "cpu": [ + "x64" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-x64-musl": { + "version": "1.2.14", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-x64-musl/-/binding-linux-x64-musl-1.2.14.tgz", + "integrity": "sha512-3G3tnAmTpdk9jO3GQtyHXqeFD2SlecfTws/Y3M2mmj9nMBwwuLT4kur8sZKeu7ENUHSpVO3cIsm5A52LEWWwlg==", + "cpu": [ + "x64" + ], + "dev": true, + "libc": [ + "musl" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-openharmony-arm64": { + "version": "1.2.14", + "resolved": "https://registry.npmjs.org/@rolldown/binding-openharmony-arm64/-/binding-openharmony-arm64-1.2.14.tgz", + "integrity": "sha512-qyr5XiNGxm2ytx17vvtcJ9nXn6v1gENETi503bJx3OGwZ1tSonj7BosxbMa/xeAfSl5iS9X6KjEWYXLu6v1L7Q==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openharmony" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-win32-arm64-msvc": { + "version": "1.2.14", + "resolved": "https://registry.npmjs.org/@rolldown/binding-win32-arm64-msvc/-/binding-win32-arm64-msvc-1.2.14.tgz", + "integrity": "sha512-oA4o5o0S2yB199YyYXDzKUv1Z56Rc+mgOjwm7Z/vJ9Z8igiDPYvoOuDyo6g7AK/ZaF09nPhDKVnGBcYHO11GXA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-win32-x64-msvc": { + "version": "1.2.14", + "resolved": "https://registry.npmjs.org/@rolldown/binding-win32-x64-msvc/-/binding-win32-x64-msvc-1.2.14.tgz", + "integrity": "sha512-9mE94bf2GZUaR/fUSXCMpBoWkctu421Mi0ORpm4zqfbkjKep7RxzPFa5etcGs5h+2KApoWBOA/hAJa/7saGgEQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/pluginutils": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@rolldown/pluginutils/-/pluginutils-1.0.1.tgz", + "integrity": "sha512-2j9bGt5Jh8hj+vPtgzPtl72j0yRxHAyumoo6TNfAjsLB04UtpSvPbPcDcBMxz7n+9CYB0c1GxQFxYRg2jimqGw==", + "dev": true, + "license": "MIT" + }, + "node_modules/@types/react": { + "version": "19.3.0", + "resolved": "https://registry.npmjs.org/@types/react/-/react-19.3.0.tgz", + "integrity": "sha512-N0rFCuH9YoxG9/m61l9MfpJKfmLOVU0em7ipIz6TRgSSkvReLB9vL85GB+yr8Bs5leqpvg96JSwF4ZS1s4viQg==", + "dev": true, + "license": "MIT", + "dependencies": { + "csstype": "^3.2.2" + } + }, + "node_modules/@types/react-dom": { + "version": "19.3.0", + "resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-19.3.0.tgz", + "integrity": "sha512-ZI7bU42mZXXKHn/qNLEw2IrbiINU7X5+vfgdixBHkCNpYWXjKgfQ/P+uyGb5CjOLB9UcnTeg3rylQtV2hym44Q==", + "dev": true, + "license": "MIT", + "peerDependencies": { + "@types/react": "^19.3.0" + } + }, + "node_modules/@typescript/typescript-aix-ppc64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-aix-ppc64/-/typescript-aix-ppc64-7.0.2.tgz", + "integrity": "sha512-MTKKkWB7p/0E9xi1d1tHtZ5PiLkGEMIq88pK2CubZjOsLtYTLqhgIgi6zepFa+9GHZ6h05NMCkQxGKiPXMxXtQ==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "aix" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-darwin-arm64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-darwin-arm64/-/typescript-darwin-arm64-7.0.2.tgz", + "integrity": "sha512-gowzar9MwS/aRWp6f3a4KUqzRjAZjOsmGNCM6LcTgXum+dBfgsBVMN+AgvOCCbguXyick6LJhpBszxMebJ8syA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-darwin-x64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-darwin-x64/-/typescript-darwin-x64-7.0.2.tgz", + "integrity": "sha512-SZ9xZInqApNlNGc9s0W1VSsktYSOe9cFqNOIqmN1Gs8SmkjKZYFt017G4VwPxASInODuAdbTW7sXiFUf893RgA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-freebsd-arm64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-freebsd-arm64/-/typescript-freebsd-arm64-7.0.2.tgz", + "integrity": "sha512-W5NH4y/J0plIIS5b2xvTEkU7JFxyqdMAOgf+Ilhl0vHQXKO5dZoxd+C/jEtq56c4F3wk71RB4BMRQ2XdI+bwYQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-freebsd-x64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-freebsd-x64/-/typescript-freebsd-x64-7.0.2.tgz", + "integrity": "sha512-UMGDx5sTpzNw3WiPebH7l90IWfJggEd+egHt/q6p7/Cm3zqoV7VxkGXt+3DxPIw8CcmvAB0j3sVVfbhX+M4Tpw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-linux-arm": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-linux-arm/-/typescript-linux-arm-7.0.2.tgz", + "integrity": "sha512-gffT3xPz9sR7j/YJExkyPntrI0P2EP9XbOyWzth2/Gs0RstK+90RBcO0ncXoXy/beYll1SXw846Nf2zdnEz0QQ==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-linux-arm64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-linux-arm64/-/typescript-linux-arm64-7.0.2.tgz", + "integrity": "sha512-Qh4eU4/y3yDjnfjjyPYihMj5/ODIlmt+Bzu17OI+fiSRDW57QmU5SiN63exPRNJPKUzcc1INa1NXdrJ+MqHjUQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-linux-loong64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-linux-loong64/-/typescript-linux-loong64-7.0.2.tgz", + "integrity": "sha512-uEHck9i8hoAzXPiYRib1O7miOnz23SxIeVl6F4LXox+qov1K35jHcEW6VHKvZI+pyvl7fZEP4MCU5LYvIq1GuQ==", + "cpu": [ + "loong64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-linux-mips64el": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-linux-mips64el/-/typescript-linux-mips64el-7.0.2.tgz", + "integrity": "sha512-R4KvAMnE43W5Qeqb0Ly56O3mWMWIAgsMyz36DCaycd5nbg/9kzm0liw3JocfRqyJY0KPmzFjbswozXyW0DnIYA==", + "cpu": [ + "mips64el" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-linux-ppc64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-linux-ppc64/-/typescript-linux-ppc64-7.0.2.tgz", + "integrity": "sha512-DORx5b3sd/4S7eayxm4FQv+A7CrkUIGRaHiwI8oiHTAI1fAPWhF4J0vAlkC8biAlHSVVwxMQ3tjZ2/DVbnQiiA==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-linux-riscv64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-linux-riscv64/-/typescript-linux-riscv64-7.0.2.tgz", + "integrity": "sha512-wf0jqEDOjrPRnKwYRyyJDRo11KMbvMFrU+q4zqKyChODBzvlkbhNQfKvLxQCcwTpdDaXSHZTVuh0JoCrKCUMHQ==", + "cpu": [ + "riscv64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-linux-s390x": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-linux-s390x/-/typescript-linux-s390x-7.0.2.tgz", + "integrity": "sha512-IkwJc3L7yhytWd/ewjyxNDfOmswCm9GWMJT/ue/dU4aZNbwZeYAetq42VyLmsmSjvoX7z74X6ZaYCtzAr0EuGw==", + "cpu": [ + "s390x" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-linux-x64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-linux-x64/-/typescript-linux-x64-7.0.2.tgz", + "integrity": "sha512-EYdf2cNg7rgCWJnxCdJ+F3V39O8ihb37eHAu1LK8oAFizgTQbPOK7zHHXbPt8rX24COqODXeI3sIf0fCXG7H/A==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-netbsd-arm64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-netbsd-arm64/-/typescript-netbsd-arm64-7.0.2.tgz", + "integrity": "sha512-+polYF4MF04aPpO5FTkHran9yUQDSXqy5GiSDKpsll5jy3l3+g9QLhpf39T+ePtefhXLOGrLl0QIjkQP6VnelA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-netbsd-x64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-netbsd-x64/-/typescript-netbsd-x64-7.0.2.tgz", + "integrity": "sha512-8YIT0EHM/3dq10ZOVF/A7pc/YSMtbcecct4rWtexrnSCHOPcpC2KTLXfTCR6vDpnSiY12heNb1GiN/wu+T/FyA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-openbsd-arm64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-openbsd-arm64/-/typescript-openbsd-arm64-7.0.2.tgz", + "integrity": "sha512-APT8+ClYnuYm1u9+kgGXoMj2VzWzcymwh2gNSQVySHfkRDGOTVkoWLjCmOQSaO+PoqQ57B0flRp9SA+7GnnkzQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-openbsd-x64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-openbsd-x64/-/typescript-openbsd-x64-7.0.2.tgz", + "integrity": "sha512-yX7s+Q0Dln0Dt9tEzZsAjXXR/+ytBM7AlglaqyeMPxQszJ1JhlJdZ6jLA+IzldHtflX81em7lDao1xXu+aRRkg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-sunos-x64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-sunos-x64/-/typescript-sunos-x64-7.0.2.tgz", + "integrity": "sha512-dLJDGaLZ1D4HPQn62u1n8mBDkJREwMsAkCdkwd4Ieqw+x3TUyTsqY0YiBCtE6H6OzzgGk3iuZ3vFWRS+E8/d1g==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "sunos" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-win32-arm64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-win32-arm64/-/typescript-win32-arm64-7.0.2.tgz", + "integrity": "sha512-Gyl1Vy6OsWesLzmq+EP0Fb7b4Nid5232AvcA2SFcdYreldpNtYFFofPjnt62y9hQy7VTaZp65ICJjuAQRaVcIQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-win32-x64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-win32-x64/-/typescript-win32-x64-7.0.2.tgz", + "integrity": "sha512-0BQ3HkAHHlKLSp1qRvf3SUhGpGsDuhB/jgFw75guyqbxJqEaS0Cw/VFO8i2nHglJUzQCRtMMR/IBAKE3ETMC4g==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@vitejs/plugin-react": { + "version": "6.1.2", + "resolved": "https://registry.npmjs.org/@vitejs/plugin-react/-/plugin-react-6.1.2.tgz", + "integrity": "sha512-fhJNGUdscQa4HkI0xFxwonWyhnVReCPDbXI7FH7jmzpnVCrFQI7PRrhWecO263610vOrs9tr2Y4xcf8uAdFxbw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@rolldown/pluginutils": "^1.0.1" + }, + "engines": { + "node": "^20.19.0 || >=22.12.0" + }, + "peerDependencies": { + "@rolldown/plugin-babel": "^0.1.7 || ^0.2.0", + "babel-plugin-react-compiler": "^1.0.0", + "oxc-transform-react": "^0.152.0", + "vite": "^8.0.0" + }, + "peerDependenciesMeta": { + "@rolldown/plugin-babel": { + "optional": true + }, + "babel-plugin-react-compiler": { + "optional": true + }, + "oxc-transform-react": { + "optional": true + } + } + }, + "node_modules/csstype": { + "version": "3.2.3", + "resolved": "https://registry.npmjs.org/csstype/-/csstype-3.2.3.tgz", + "integrity": "sha512-z1HGKcYy2xA8AGQfwrn0PAy+PB7X/GSj3UVJW9qKyn43xWa+gl5nXmU4qqLMRzWVLFC8KusUX8T/0kCiOYpAIQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/detect-libc": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.1.2.tgz", + "integrity": "sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": ">=8" + } + }, + "node_modules/fdir": { + "version": "6.5.0", + "resolved": "https://registry.npmjs.org/fdir/-/fdir-6.5.0.tgz", + "integrity": "sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12.0.0" + }, + "peerDependencies": { + "picomatch": "^3 || ^4" + }, + "peerDependenciesMeta": { + "picomatch": { + "optional": true + } + } + }, + "node_modules/fsevents": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, + "node_modules/lightningcss": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss/-/lightningcss-1.33.0.tgz", + "integrity": "sha512-WkUDrojuJs0xkgGf2udWxa3yGBRxPtxUkB79i6aCZLRgc7PM8fZe9TosfPDcvEpQZbuFASnHYmRLBLUbmLOIIA==", + "dev": true, + "license": "MPL-2.0", + "dependencies": { + "detect-libc": "^2.0.3" + }, + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + }, + "optionalDependencies": { + "lightningcss-android-arm64": "1.33.0", + "lightningcss-darwin-arm64": "1.33.0", + "lightningcss-darwin-x64": "1.33.0", + "lightningcss-freebsd-x64": "1.33.0", + "lightningcss-linux-arm-gnueabihf": "1.33.0", + "lightningcss-linux-arm64-gnu": "1.33.0", + "lightningcss-linux-arm64-musl": "1.33.0", + "lightningcss-linux-x64-gnu": "1.33.0", + "lightningcss-linux-x64-musl": "1.33.0", + "lightningcss-win32-arm64-msvc": "1.33.0", + "lightningcss-win32-x64-msvc": "1.33.0" + } + }, + "node_modules/lightningcss-android-arm64": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-android-arm64/-/lightningcss-android-arm64-1.33.0.tgz", + "integrity": "sha512-gEpRTalKdosp4Bb8qWtc2iOgE5SeIHlpS1up9bFq2wAyYhl1UdTObYiHe98zEM9SQvSoqQZ1IQD0JNpg3Ml5pg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-darwin-arm64": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-darwin-arm64/-/lightningcss-darwin-arm64-1.33.0.tgz", + "integrity": "sha512-Sciaz8eenNTKn9b3t7+xr0ipTp9YxKQY4npwQ3mrRuL0BAVHBLyZxofhaKBAVtzmtRZ/zTyo0/to4B1uWG/Djg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-darwin-x64": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-darwin-x64/-/lightningcss-darwin-x64-1.33.0.tgz", + "integrity": "sha512-Z5UPAxzrjlWNNyGy6i65cJzzvgJ5D3T6wMvs+gWpY9d7qRhANrxqAp6LhxIgZhWEw18RfJTGcRxjuLIBr+m8XQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-freebsd-x64": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-freebsd-x64/-/lightningcss-freebsd-x64-1.33.0.tgz", + "integrity": "sha512-QQM/Ti/hQajJwCY+RiWuCZ9sdtI/XQk7nDK5vC8kkdwixezOlDgvDx7+RT+QjK6FcFT4MpsuoBnHIo/O3StRRg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-linux-arm-gnueabihf": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-linux-arm-gnueabihf/-/lightningcss-linux-arm-gnueabihf-1.33.0.tgz", + "integrity": "sha512-N7FVBe6iS24MlM6R/4RBTxGhQheZGs7tiQ9U32UtF75NzP5Q7xWPRqLBCKxlRQRk3rY1jCIPLzx7WzOhuUIRLQ==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-linux-arm64-gnu": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-linux-arm64-gnu/-/lightningcss-linux-arm64-gnu-1.33.0.tgz", + "integrity": "sha512-j2v/itmy4HlNxlc6voKXYgBqNi0Ng2LShg4z7GufpEgs05P+2suBVyi9I6YHq5uoVFx9ETin3eCEhLVyXGQnKg==", + "cpu": [ + "arm64" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-linux-arm64-musl": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-linux-arm64-musl/-/lightningcss-linux-arm64-musl-1.33.0.tgz", + "integrity": "sha512-yiO5ROMuYQgXbC60yjZU5CYSFZGKXL0HFATXt9mHJn1+zW55oCtMI9NfcVhYLMFDL7gV7oBPon/EmMMGg2OvtQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "libc": [ + "musl" + ], + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-linux-x64-gnu": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-linux-x64-gnu/-/lightningcss-linux-x64-gnu-1.33.0.tgz", + "integrity": "sha512-ar+Ju7LmcN0Jo4FpL4hpFybwNG9/3A/Br5KW2n2jyODg3MEZXaDYADdemoNS+BDNfMgKvylJLj4S5tyRActuAg==", + "cpu": [ + "x64" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-linux-x64-musl": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-linux-x64-musl/-/lightningcss-linux-x64-musl-1.33.0.tgz", + "integrity": "sha512-RYiYbkokw0trfKqqzfF55lginwEPrD3OJDfTuJzFs1MK6iFnDenaz1fqLLtX4ITG3OktJQXOeTaw1awrBAlZPw==", + "cpu": [ + "x64" + ], + "dev": true, + "libc": [ + "musl" + ], + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-win32-arm64-msvc": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-win32-arm64-msvc/-/lightningcss-win32-arm64-msvc-1.33.0.tgz", + "integrity": "sha512-1K+MPfLSFVpphzpdbfkhlWk6wBrTObBzS2T6db10PNOZgR9GoVsAWzwNyuhUYYbTp23j+4RrncfujZ4uAzXvwA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-win32-x64-msvc": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-win32-x64-msvc/-/lightningcss-win32-x64-msvc-1.33.0.tgz", + "integrity": "sha512-OlEICDx/Xl0FqSp4bry8zFnCvGpig3Gl4gCquvYwHuqJKEC1+n9NgDniFvqHGmMv1ZkqDJrDqKKSykTDX+ehuA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/nanoid": { + "version": "3.3.20", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.20.tgz", + "integrity": "sha512-uKdg2G3GNCKQn9byYOpxbGqrT2fGO5KRt5J/8b3pok8rT6qxGWF6hxMyJiEYtAf+FVyYuD9hRaDqX5uPFYJ4ZQ==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "license": "MIT", + "bin": { + "nanoid": "bin/nanoid.cjs" + }, + "engines": { + "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1" + } + }, + "node_modules/picocolors": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz", + "integrity": "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==", + "dev": true, + "license": "ISC" + }, + "node_modules/picomatch": { + "version": "4.0.7", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.7.tgz", + "integrity": "sha512-qcJu88Q2IWqJsDD529JKMdwGm/dvInW4HvQnRwiH9JtihJvzGOscDtHE3x1pBKeUOTysQ8kVmLnJ2kJu7yhcGA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/jonschlinkert" + } + }, + "node_modules/postcss": { + "version": "8.5.30", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.30.tgz", + "integrity": "sha512-zkd+e9S1AQHhmaBKye9zlFHWjOwVgqXl1q3ECYy8561K7qxR2cREf/STLskulBFd78k6AOFeA+ff1TtEzk9bAA==", + "dev": true, + "funding": [ + { + "type": "opencollective", + "url": "https://opencollective.com/postcss/" + }, + { + "type": "tidelift", + "url": "https://tidelift.com/funding/github/npm/postcss" + }, + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "license": "MIT", + "dependencies": { + "nanoid": "^3.3.20", + "picocolors": "^1.1.1", + "source-map-js": "^1.2.2" + }, + "engines": { + "node": "^10 || ^12 || >=14" + } + }, + "node_modules/react": { + "version": "19.3.0", + "resolved": "https://registry.npmjs.org/react/-/react-19.3.0.tgz", + "integrity": "sha512-E8LUcbtBWt20bbl2YoHfx4ZDBdxVTfOKtCZn9cDSJ4l6/nuoApcpIBcj47t2wZoVX8g2ZHuMHbiShgCR1T5Sog==", + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/react-dom": { + "version": "19.3.0", + "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-19.3.0.tgz", + "integrity": "sha512-JDk8dgif51OjFoDE70+OT9ICyYr+69HlmihNwp1+Nsfbna3t5sIiCa9ZJktDmQ4/1b/rn26hIAR2uYXDMr5r0Q==", + "license": "MIT", + "dependencies": { + "scheduler": "^0.28.0" + }, + "peerDependencies": { + "react": "^19.3.0" + } + }, + "node_modules/rolldown": { + "version": "1.2.14", + "resolved": "https://registry.npmjs.org/rolldown/-/rolldown-1.2.14.tgz", + "integrity": "sha512-eTBTTqMR6uHKLgcUqpJP8ntzDI6V4LYA8negAMBEI7gkgVvOdrx6VsvS2Ym+83KhOPdLCHWJu0w7UQFJZhHKNw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@oxc-project/types": "=0.154.0", + "@rolldown/pluginutils": "^1.0.0" + }, + "bin": { + "rolldown": "bin/cli.mjs" + }, + "engines": { + "node": "^20.19.0 || >=22.12.0" + }, + "optionalDependencies": { + "@rolldown/binding-android-arm-eabi": "1.2.14", + "@rolldown/binding-android-arm64": "1.2.14", + "@rolldown/binding-darwin-arm64": "1.2.14", + "@rolldown/binding-darwin-x64": "1.2.14", + "@rolldown/binding-freebsd-x64": "1.2.14", + "@rolldown/binding-linux-arm-gnueabihf": "1.2.14", + "@rolldown/binding-linux-arm64-gnu": "1.2.14", + "@rolldown/binding-linux-arm64-musl": "1.2.14", + "@rolldown/binding-linux-ppc64-gnu": "1.2.14", + "@rolldown/binding-linux-s390x-gnu": "1.2.14", + "@rolldown/binding-linux-x64-gnu": "1.2.14", + "@rolldown/binding-linux-x64-musl": "1.2.14", + "@rolldown/binding-openharmony-arm64": "1.2.14", + "@rolldown/binding-win32-arm64-msvc": "1.2.14", + "@rolldown/binding-win32-x64-msvc": "1.2.14" + } + }, + "node_modules/scheduler": { + "version": "0.28.0", + "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.28.0.tgz", + "integrity": "sha512-juorfCmIkIw8tT+p5BXSm6PJjQF/ycEYmKyzURCIt/RaZIhL+PulbQ9Yu2z1HdOJDdqDTlxA1+xKBmHXJsczAw==", + "license": "MIT" + }, + "node_modules/source-map-js": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.2.tgz", + "integrity": "sha512-KGj/8Y43x35aZVDtt+J4mK1hoLGHULMYfSkODJNQjNDC3oW1PqPoxMwo0pLUsWM/UEGzON/NxeHywEfNXNP3Vw==", + "dev": true, + "license": "BSD-3-Clause", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/tinyglobby": { + "version": "0.2.17", + "resolved": "https://registry.npmjs.org/tinyglobby/-/tinyglobby-0.2.17.tgz", + "integrity": "sha512-wXR/dYpcqKmfWpEdZjiKJOwCNFndD0DMnrW/cYjVGttEkBfVgcLFHoNrlj47mjOVic9yyNu65alsgF4NQyTa2g==", + "dev": true, + "license": "MIT", + "dependencies": { + "fdir": "^6.5.0", + "picomatch": "^4.0.4" + }, + "engines": { + "node": ">=12.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/SuperchupuDev" + } + }, + "node_modules/typescript": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-7.0.2.tgz", + "integrity": "sha512-8FYau96o3NKOhbjKi/qNvG/W5jhzxkbdm5sj9AbZ/5T5sWqn3hJgLfGx27sRKZWTvyzCP8dLRBTf5tBTSRVUNA==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "tsc": "bin/tsc" + }, + "engines": { + "node": ">=16.20.0" + }, + "optionalDependencies": { + "@typescript/typescript-aix-ppc64": "7.0.2", + "@typescript/typescript-darwin-arm64": "7.0.2", + "@typescript/typescript-darwin-x64": "7.0.2", + "@typescript/typescript-freebsd-arm64": "7.0.2", + "@typescript/typescript-freebsd-x64": "7.0.2", + "@typescript/typescript-linux-arm": "7.0.2", + "@typescript/typescript-linux-arm64": "7.0.2", + "@typescript/typescript-linux-loong64": "7.0.2", + "@typescript/typescript-linux-mips64el": "7.0.2", + "@typescript/typescript-linux-ppc64": "7.0.2", + "@typescript/typescript-linux-riscv64": "7.0.2", + "@typescript/typescript-linux-s390x": "7.0.2", + "@typescript/typescript-linux-x64": "7.0.2", + "@typescript/typescript-netbsd-arm64": "7.0.2", + "@typescript/typescript-netbsd-x64": "7.0.2", + "@typescript/typescript-openbsd-arm64": "7.0.2", + "@typescript/typescript-openbsd-x64": "7.0.2", + "@typescript/typescript-sunos-x64": "7.0.2", + "@typescript/typescript-win32-arm64": "7.0.2", + "@typescript/typescript-win32-x64": "7.0.2" + } + }, + "node_modules/vite": { + "version": "8.3.4", + "resolved": "https://registry.npmjs.org/vite/-/vite-8.3.4.tgz", + "integrity": "sha512-IftLE8phJhdNRIGNEV4JCCvfNScoZQVfcXaN8TQropWGJtOHcu+iAB9pHcuGvmEb/kddw0LBe/jS8ztdC6xdiQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "lightningcss": "^1.33.0", + "picomatch": "^4.0.7", + "postcss": "^8.5.29", + "rolldown": "~1.2.12", + "tinyglobby": "^0.2.17" + }, + "bin": { + "vite": "bin/vite.js" + }, + "engines": { + "node": "^20.19.0 || >=22.12.0" + }, + "funding": { + "url": "https://github.com/vitejs/vite?sponsor=1" + }, + "optionalDependencies": { + "fsevents": "~2.3.3" + }, + "peerDependencies": { + "@types/node": "^20.19.0 || >=22.12.0", + "@vitejs/devtools": "^0.7.1", + "esbuild": "^0.27.0 || ^0.28.0", + "jiti": ">=1.21.0", + "less": "^4.0.0", + "sass": "^1.70.0", + "sass-embedded": "^1.70.0", + "stylus": ">=0.54.8", + "sugarss": "^5.0.0", + "terser": "^5.16.0", + "tsx": "^4.8.1", + "yaml": "^2.4.2" + }, + "peerDependenciesMeta": { + "@types/node": { + "optional": true + }, + "@vitejs/devtools": { + "optional": true + }, + "esbuild": { + "optional": true + }, + "jiti": { + "optional": true + }, + "less": { + "optional": true + }, + "sass": { + "optional": true + }, + "sass-embedded": { + "optional": true + }, + "stylus": { + "optional": true + }, + "sugarss": { + "optional": true + }, + "terser": { + "optional": true + }, + "tsx": { + "optional": true + }, + "yaml": { + "optional": true + } + } + } + } +} diff --git a/frontend/package.json b/frontend/package.json new file mode 100644 index 0000000..6ac37c6 --- /dev/null +++ b/frontend/package.json @@ -0,0 +1,22 @@ +{ + "name": "databases-ui-frontend", + "private": true, + "version": "0.0.0", + "type": "module", + "scripts": { + "dev": "vite", + "build": "tsc --noEmit && vite build", + "typecheck": "tsc --noEmit" + }, + "dependencies": { + "react": "19.3.0", + "react-dom": "19.3.0" + }, + "devDependencies": { + "@types/react": "19.3.0", + "@types/react-dom": "19.3.0", + "@vitejs/plugin-react": "6.1.2", + "typescript": "7.0.2", + "vite": "8.3.4" + } +} diff --git a/frontend/public/favicon.svg b/frontend/public/favicon.svg new file mode 100644 index 0000000..cba0722 --- /dev/null +++ b/frontend/public/favicon.svg @@ -0,0 +1 @@ + diff --git a/frontend/public/theme.css b/frontend/public/theme.css new file mode 100644 index 0000000..30a5906 --- /dev/null +++ b/frontend/public/theme.css @@ -0,0 +1 @@ +/* The operator's colours, served by the backend at /theme.css; empty here for `npm run dev`. */ diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx new file mode 100644 index 0000000..dbe4057 --- /dev/null +++ b/frontend/src/App.tsx @@ -0,0 +1,229 @@ +import { createContext, useCallback, useContext, useEffect, useRef, useState, type ReactNode } from "react"; +import { api, ApiError, configure, type Environment, type Me } from "./api"; +import { Activity } from "./views/Activity"; +import { Audit } from "./views/Audit"; +import { DatabaseView } from "./views/DatabaseView"; +import { Databases } from "./views/Databases"; + +type Toast = { id: number; message: string; kind: "info" | "error" }; + +type Session = { + me: Me; + notify: (message: string, kind?: "info" | "error") => void; +}; + +const SessionContext = createContext(null); + +export function useSession(): Session { + const session = useContext(SessionContext); + if (!session) throw new Error("useSession outside the signed-in shell"); + return session; +} + +// The page in view lives in the hash: #/dev, #/dev/databases/payments, #/prd/activity +type Route = { path: string[] }; + +function routeFromHash(): Route { + const raw = window.location.hash.replace(/^#\/?/, ""); + return { path: raw.split("?")[0].split("/").filter(Boolean).map(decodeURIComponent) }; +} + +export function go(path: string) { + window.location.hash = path.startsWith("/") ? path : `/${path}`; +} + +// The callback sends a sign-in error back as ?auth_error=; show it once and drop it from the URL. +function takeAuthError(): string { + const params = new URLSearchParams(window.location.search); + const error = params.get("auth_error") ?? ""; + if (params.has("auth_error")) window.history.replaceState(null, "", window.location.pathname + window.location.hash); + return error; +} + +export function App() { + const [me, setMe] = useState(null); + const [state, setState] = useState<"loading" | "signed-out" | "ready" | "ended">("loading"); + const [authError] = useState(takeAuthError); + const [route, setRoute] = useState(routeFromHash); + const [toasts, setToasts] = useState([]); + const nextToast = useRef(0); + + const notify = useCallback((message: string, kind: "info" | "error" = "info") => { + const id = ++nextToast.current; + setToasts((t) => [...t, { id, message, kind }]); + if (kind === "info") window.setTimeout(() => setToasts((t) => t.filter((x) => x.id !== id)), 5000); + }, []); + + useEffect(() => { + api + .me() + .then((data) => { + configure(data.csrf, () => setState("ended")); + setMe(data); + setState("ready"); + }) + .catch((err) => setState(err instanceof ApiError && err.status === 401 ? "signed-out" : "ended")); + }, []); + + useEffect(() => { + const onHash = () => setRoute(routeFromHash()); + window.addEventListener("hashchange", onHash); + return () => window.removeEventListener("hashchange", onHash); + }, []); + + async function signOut() { + try { + await api.logout(); + } finally { + setMe(null); + setState("signed-out"); + } + } + + if (state === "loading") return
Loading…
; + + if (state === "signed-out" || state === "ended" || !me) { + return ( +
+
+ +

Databases UI

+

{state === "ended" ? "Your session has ended." : "Sign in with your work account to snapshot, restore and clone your team's databases."}

+ {authError && ( +

+ {authError} +

+ )} + + Sign in with Microsoft + +
+
+ ); + } + + const [envName, page = "", id] = route.path; + const env = me.environments.find((e) => e.name === envName) ?? me.environments.find((e) => e.runs_jobs) ?? me.environments[0]; + const pages = [ + { match: "", label: "Databases" }, + { match: "activity", label: "Activity" }, + { match: "audit", label: "Audit log" }, + ]; + + return ( + +
+
+ + + Databases UI + +
+ {me.name || me.upn} + +
+
+
+ +
+ +
+
+
+ {toasts.map((t) => ( +
+ {t.message} + +
+ ))} +
+
+
+ ); +} + +function Page({ env, page, id }: { env: Environment; page: string; id?: string }) { + if (page === "databases" && id) return ; + if (page === "activity") return ; + if (page === "audit") return ; + if (page === "" || page === "databases") return ; + return ( +
+

Nothing here

+

+ That page does not exist. Back to the databases. +

+
+ ); +} + +export function Section({ title, children, actions }: { title: string; children: ReactNode; actions?: ReactNode }) { + return ( +
+
+

{title}

+ {actions} +
+ {children} +
+ ); +} + +function Logo() { + return ( + + ); +} diff --git a/frontend/src/api.ts b/frontend/src/api.ts new file mode 100644 index 0000000..4f171ff --- /dev/null +++ b/frontend/src/api.ts @@ -0,0 +1,123 @@ +// The backend's JSON API. Same origin, the session cookie rides along, and every write carries +// the session's CSRF token. Who may see and do what is decided by the server; these types only +// say what comes back. + +export type Environment = { name: string; production: boolean; runs_jobs: boolean; clone_from: string[]; downloads: boolean }; + +export type Me = { + name: string; + upn: string; + csrf: string; + expires: number; + version: string; + release_notes: string | null; + admin: boolean; + auditor: boolean; + teams: { id: string; name: string }[]; + environments: Environment[]; +}; + +export type Database = { + name: string; + owner: string; + ready: boolean | null; + message: string; + teams: string[]; + workloads: string[]; + copy: { name: string; ready: boolean } | null; + can_act: boolean; +}; + +export type Snapshot = { id: string; created: string; size: number; created_by: string; note: string; sha256: string }; + +export type JobState = "waiting" | "starting" | "running" | "succeeded" | "failed" | "expired"; + +export type Job = { + name: string; + action: "snapshot" | "restore"; + database: string; + state: JobState; + requested_by: string; + requested_at: string; + approved_by: string; + approved_at: string; + reason: string; + note: string; + snapshot: string; + source_environment: string; + source_database: string; + into: "" | "database" | "copy"; + target_database: string; + approval: string; + started: string; + finished: string; + result: { result?: string; bytes?: number; seconds?: number; reason?: string }; + can_approve: boolean; + can_decline: boolean; +}; + +export type AuditEntry = { at: string; environment: string; actor: string; action: string; database?: string; job?: string; snapshot?: string; target?: string; detail?: string }; + +export type RestoreRequest = { source_environment: string; source_database: string; snapshot: string; into: "database" | "copy"; reason: string }; + +export class ApiError extends Error { + constructor( + readonly status: number, + readonly code: string, + message: string, + ) { + super(message); + } +} + +const MESSAGES: Record = { + signed_out: "Your session has ended. Sign in again.", + csrf: "This page is out of date. Reload it and try again.", + not_allowed: "You may not do that with this database.", + invalid_request: "Some fields are not valid.", +}; + +let csrf = ""; +let onSignedOut: () => void = () => {}; + +export function configure(token: string, signedOut: () => void) { + csrf = token; + onSignedOut = signedOut; +} + +async function request(method: string, path: string, body?: unknown): Promise { + const headers: Record = { Accept: "application/json" }; + if (method !== "GET") headers["X-CSRF-Token"] = csrf; + if (body !== undefined) headers["Content-Type"] = "application/json"; + let response: Response; + try { + response = await fetch(path, { method, headers, body: body === undefined ? undefined : JSON.stringify(body), credentials: "same-origin", cache: "no-store" }); + } catch { + throw new ApiError(0, "network", "The server could not be reached."); + } + const data = response.status === 204 ? {} : await response.json().catch(() => ({})); + if (!response.ok) { + const code = String(data.error ?? response.status); + if (response.status === 401) onSignedOut(); + throw new ApiError(response.status, code, data.message ?? MESSAGES[code] ?? `Request failed (${response.status}).`); + } + return data as T; +} + +const env = (name: string) => `/api/environments/${encodeURIComponent(name)}`; +const db = (name: string, database: string) => `${env(name)}/databases/${encodeURIComponent(database)}`; + +export const api = { + me: () => request("GET", "/api/me"), + logout: () => request("POST", "/auth/logout"), + databases: (e: string) => request<{ databases: Database[] }>("GET", `${env(e)}/databases`).then((r) => r.databases), + snapshots: (e: string, d: string) => request<{ snapshots: Snapshot[] }>("GET", `${db(e, d)}/snapshots`).then((r) => r.snapshots), + snapshot: (e: string, d: string, note: string) => request("POST", `${db(e, d)}/snapshots`, { note }), + restore: (e: string, d: string, body: RestoreRequest) => request("POST", `${db(e, d)}/restore`, body), + dropCopy: (e: string, d: string) => request("DELETE", `${db(e, d)}/copy`), + downloadUrl: (e: string, d: string, id: string) => `${db(e, d)}/snapshots/${encodeURIComponent(id)}/download`, + jobs: (e: string) => request<{ jobs: Job[] }>("GET", `${env(e)}/jobs`).then((r) => r.jobs), + approve: (e: string, name: string) => request("POST", `${env(e)}/jobs/${encodeURIComponent(name)}/approve`), + decline: (e: string, name: string, reason: string) => request("POST", `${env(e)}/jobs/${encodeURIComponent(name)}/decline`, { reason }), + audit: (e: string) => request<{ entries: AuditEntry[] }>("GET", `${env(e)}/audit`).then((r) => r.entries), +}; diff --git a/frontend/src/components/Dialog.tsx b/frontend/src/components/Dialog.tsx new file mode 100644 index 0000000..48ea6fc --- /dev/null +++ b/frontend/src/components/Dialog.tsx @@ -0,0 +1,60 @@ +import { useEffect, useRef, type ReactNode } from "react"; + +// The native : focus trap, Escape and the backdrop come with it. +export function Dialog({ title, wide, onClose, children }: { title: string; wide?: boolean; onClose: () => void; children: ReactNode }) { + const ref = useRef(null); + + // No close() on unmount: React removing the element takes it out of the top layer, and a + // close() there would queue a `close` event that fires onClose for the next dialog. + // showModal() focuses the first focusable element, which is the close button; a field marked + // data-autofocus takes it instead. + useEffect(() => { + const dialog = ref.current; + if (dialog && !dialog.open) dialog.showModal(); + dialog?.querySelector("[data-autofocus]")?.focus(); + }, []); + + return ( + +
+

{title}

+ +
+ {children} +
+ ); +} + +export function Confirm({ + title, + children, + action, + danger, + busy, + onConfirm, + onClose, +}: { + title: string; + children: ReactNode; + action: string; + danger?: boolean; + busy?: boolean; + onConfirm: () => void; + onClose: () => void; +}) { + return ( + +
{children}
+
+ + +
+
+ ); +} diff --git a/frontend/src/components/Menu.tsx b/frontend/src/components/Menu.tsx new file mode 100644 index 0000000..fd86a7f --- /dev/null +++ b/frontend/src/components/Menu.tsx @@ -0,0 +1,52 @@ +import { useEffect, useRef, useState } from "react"; + +export type MenuItem = { label: string; onSelect: () => void; danger?: boolean; disabled?: boolean }; + +// A small action menu: opens under its button, closes on a pick, Escape or a click elsewhere. +export function Menu({ label, items, disabled }: { label: string; items: MenuItem[]; disabled?: boolean }) { + const [open, setOpen] = useState(false); + const root = useRef(null); + + useEffect(() => { + if (!open) return; + const onPointer = (e: PointerEvent) => { + if (!root.current?.contains(e.target as Node)) setOpen(false); + }; + const onKey = (e: KeyboardEvent) => { + if (e.key === "Escape") setOpen(false); + }; + document.addEventListener("pointerdown", onPointer); + document.addEventListener("keydown", onKey); + return () => { + document.removeEventListener("pointerdown", onPointer); + document.removeEventListener("keydown", onKey); + }; + }, [open]); + + return ( +
+ + {open && ( +
+ {items.map((item) => ( + + ))} +
+ )} +
+ ); +} diff --git a/frontend/src/components/ui.tsx b/frontend/src/components/ui.tsx new file mode 100644 index 0000000..e82a78c --- /dev/null +++ b/frontend/src/components/ui.tsx @@ -0,0 +1,52 @@ +import { useCallback, useEffect, useState, type ReactNode } from "react"; +import { ApiError, type Job } from "../api"; + +// A loader for one view's data: the value, its error, and a reload. +export function useLoad(load: () => Promise, deps: unknown[]): { data: T | null; error: string; reload: () => void } { + const [data, setData] = useState(null); + const [error, setError] = useState(""); + const [tick, setTick] = useState(0); + // eslint-disable-next-line react-hooks/exhaustive-deps + const run = useCallback(load, deps); + useEffect(() => { + let live = true; + setError(""); + run().then( + (value) => live && setData(value), + (err) => live && setError(err instanceof ApiError ? err.message : String(err)), + ); + return () => { + live = false; + }; + }, [run, tick]); + const reload = useCallback(() => setTick((t) => t + 1), []); + return { data, error, reload }; +} + +export function Loading({ error, children }: { error: string; children?: ReactNode }) { + if (error) + return ( +

+ {error} +

+ ); + return

{children ?? "Loading…"}

; +} + +const STATES: Record = { + waiting: ["Waiting for approval", "state-open"], + starting: ["Starting", "state-open"], + running: ["Running", "state-open"], + succeeded: ["Done", "state-granted"], + failed: ["Failed", "state-declined"], + expired: ["Expired", "state-declined"], +}; + +export function StateBadge({ state }: { state: Job["state"] }) { + const [label, cls] = STATES[state]; + return {label}; +} + +export function message(err: unknown): string { + return err instanceof ApiError ? err.message : String(err); +} diff --git a/frontend/src/format.ts b/frontend/src/format.ts new file mode 100644 index 0000000..edaea74 --- /dev/null +++ b/frontend/src/format.ts @@ -0,0 +1,34 @@ +const dateTime = new Intl.DateTimeFormat(undefined, { dateStyle: "medium", timeStyle: "short" }); + +// An ISO 8601 time from the API, in the reader's own zone. +export function when(iso: string | null | undefined): string { + if (!iso) return "—"; + const parsed = new Date(iso); + return Number.isNaN(parsed.getTime()) ? iso : dateTime.format(parsed); +} + +// "20261023T141502Z-3fa9c1", a snapshot's id, as the time it was taken. +export function snapshotTime(id: string): string { + const m = /^(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})(\d{2})Z/.exec(id); + return m ? when(`${m[1]}-${m[2]}-${m[3]}T${m[4]}:${m[5]}:${m[6]}Z`) : id; +} + +const UNITS = ["B", "KB", "MB", "GB", "TB"]; + +export function bytes(n: number | undefined): string { + if (n === undefined || n === null) return "—"; + let value = n; + let unit = 0; + while (value >= 1024 && unit < UNITS.length - 1) { + value /= 1024; + unit++; + } + return `${value < 10 && unit > 0 ? value.toFixed(1) : Math.round(value)} ${UNITS[unit]}`; +} + +export function duration(seconds: number | undefined): string { + if (seconds === undefined) return ""; + if (seconds < 60) return `${seconds}s`; + const minutes = Math.floor(seconds / 60); + return minutes < 60 ? `${minutes}m ${seconds % 60}s` : `${Math.floor(minutes / 60)}h ${minutes % 60}m`; +} diff --git a/frontend/src/main.tsx b/frontend/src/main.tsx new file mode 100644 index 0000000..9891129 --- /dev/null +++ b/frontend/src/main.tsx @@ -0,0 +1,10 @@ +import { StrictMode } from "react"; +import { createRoot } from "react-dom/client"; +import { App } from "./App"; +import "./styles.css"; + +createRoot(document.getElementById("root")!).render( + + + , +); diff --git a/frontend/src/styles.css b/frontend/src/styles.css new file mode 100644 index 0000000..19ce240 --- /dev/null +++ b/frontend/src/styles.css @@ -0,0 +1,863 @@ +:root { + --bg: #f6f7f9; + --surface: #ffffff; + --surface-2: #f1f3f6; + --border: #dfe3e8; + --text: #1c2430; + --muted: #5f6b7a; + --accent: #0f766e; + --accent-text: #ffffff; + --accent-soft: #e6f4f2; + --danger: #c8283c; + --danger-soft: #fdecee; + --ok: #1a7f4b; + --ok-soft: #e7f6ee; + --warn: #9a5b00; + --warn-soft: #fff4e0; + --radius: 8px; + --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 1px 3px rgb(16 24 40 / 10%); + --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; + --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; + color-scheme: light; +} + +@media (prefers-color-scheme: dark) { + :root { + --bg: #0f1218; + --surface: #171b23; + --surface-2: #1e2430; + --border: #2b3240; + --text: #e6e9ef; + --muted: #98a2b3; + --accent: #2dd4bf; + --accent-text: #0f1218; + --accent-soft: #123532; + --danger: #f2707f; + --danger-soft: #3a1d23; + --ok: #5fd39a; + --ok-soft: #173326; + --warn: #f0b660; + --warn-soft: #3a2b12; + --shadow: 0 1px 2px rgb(0 0 0 / 40%); + color-scheme: dark; + } +} + +* { + box-sizing: border-box; +} + +html, +body { + margin: 0; + background: var(--bg); + color: var(--text); + font: 14px/1.5 var(--font); +} + +::selection { + background: var(--accent); + color: var(--accent-text); +} + +h1 { + font-size: 20px; + margin: 0; + overflow-wrap: anywhere; +} + +h2 { + font-size: 16px; + margin: 0; +} + +a { + color: var(--accent); +} + +.mono { + font-family: var(--mono); + font-size: 13px; +} + +.muted { + color: var(--muted); +} + +.nowrap { + white-space: nowrap; +} + +.small { + font-size: 12px; +} + +.logo { + width: 28px; + height: 28px; + flex: none; +} + +.logo rect { + fill: var(--accent); +} + +.logo ellipse, +.logo path { + fill: none; + stroke: var(--accent-text); + stroke-width: 2.5; + stroke-linecap: round; +} + +/* Buttons */ +.button { + display: inline-flex; + align-items: center; + justify-content: center; + gap: 6px; + min-height: 34px; + padding: 0 14px; + border: 1px solid var(--border); + border-radius: var(--radius); + background: var(--surface); + color: var(--text); + font: inherit; + font-weight: 500; + text-decoration: none; + cursor: pointer; + white-space: nowrap; +} + +.button:hover:not(:disabled) { + background: var(--surface-2); +} + +.button:focus-visible, +.icon-button:focus-visible, +input:focus-visible, +textarea:focus-visible, +select:focus-visible, +.vaults a:focus-visible { + outline: 2px solid var(--accent); + outline-offset: 2px; +} + +.button:disabled { + opacity: 0.5; + cursor: not-allowed; +} + +.button.primary { + background: var(--accent); + border-color: var(--accent); + color: var(--accent-text); +} + +.button.primary:hover:not(:disabled) { + background: var(--accent); + filter: brightness(1.08); +} + +.button.danger { + background: var(--danger); + border-color: var(--danger); + color: #fff; +} + +.button.danger-text { + color: var(--danger); +} + +.button.small { + min-height: 28px; + padding: 0 10px; + font-size: 13px; +} + +.button.wide { + width: 100%; +} + +.icon-button { + border: 0; + background: none; + color: var(--muted); + font-size: 20px; + line-height: 1; + padding: 4px 8px; + border-radius: 6px; + cursor: pointer; +} + +.icon-button:hover { + background: var(--surface-2); + color: var(--text); +} + +/* Sign-in and empty states */ +.center { + min-height: calc(100vh - 56px); + display: grid; + place-items: center; + padding: 24px 16px; +} + +.card { + width: 100%; + max-width: 420px; + padding: 32px; + background: var(--surface); + border: 1px solid var(--border); + border-radius: 12px; + box-shadow: var(--shadow); + display: grid; + gap: 14px; +} + +.sign-in { + text-align: center; + justify-items: center; +} + +.sign-in .logo { + width: 44px; + height: 44px; +} + +.notice { + margin: 0; + padding: 10px 12px; + border-radius: var(--radius); + text-align: left; + overflow-wrap: anywhere; +} + +.notice.error { + background: var(--danger-soft); + color: var(--danger); +} + +/* Shell */ +.topbar { + position: sticky; + top: 0; + z-index: 2; + height: 56px; + display: flex; + align-items: center; + justify-content: space-between; + gap: 12px; + padding: 0 20px; + background: var(--surface); + border-bottom: 1px solid var(--border); +} + +.brand { + display: flex; + align-items: center; + gap: 10px; + color: var(--text); + font-weight: 600; + text-decoration: none; +} + +.who { + display: flex; + align-items: center; + gap: 12px; + min-width: 0; +} + +.who > span { + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; + color: var(--muted); +} + +.layout { + display: grid; + grid-template-columns: 260px minmax(0, 1fr); + min-height: calc(100vh - 56px); +} + +/* Sticky and as tall as the window, so the version sits at the bottom left however long the page. */ +.vaults { + position: sticky; + top: 56px; + align-self: start; + height: calc(100vh - 56px); + overflow-y: auto; + display: flex; + flex-direction: column; + padding: 20px 12px; + border-right: 1px solid var(--border); + background: var(--surface); +} + +.nav-title { + font-size: 11px; + font-weight: 600; + letter-spacing: 0.06em; + text-transform: uppercase; + color: var(--muted); + padding: 0 10px 8px; +} + +.vaults ul { + list-style: none; + margin: 0; + padding: 0; + display: grid; + gap: 2px; +} + +.vaults a { + display: block; + padding: 7px 10px; + border-radius: 6px; + color: var(--text); + font-family: var(--mono); + font-size: 13px; + text-decoration: none; + overflow-wrap: anywhere; +} + +.vaults a:hover { + background: var(--surface-2); +} + +.vaults a[aria-current="page"] { + background: var(--accent-soft); + color: var(--accent); + font-weight: 600; +} + +.vault-select { + display: none; +} + +.nav-group + .nav-group { + margin-top: 18px; +} + +.version { + margin: auto 0 0; + padding: 16px 10px 0; +} + +.vaults .version a { + display: inline; + padding: 0; + color: inherit; + font-family: var(--font); + font-size: inherit; + text-decoration: underline; +} + +.content { + padding: 24px 28px 64px; +} + +input, +textarea, +select { + width: 100%; + min-height: 34px; + padding: 6px 10px; + border: 1px solid var(--border); + border-radius: var(--radius); + background: var(--surface); + color: var(--text); + font: inherit; +} + +textarea { + resize: vertical; +} + +input[aria-invalid="true"] { + border-color: var(--danger); +} + +.empty { + padding: 40px 16px; + text-align: center; + color: var(--muted); + background: var(--surface); + border: 1px dashed var(--border); + border-radius: var(--radius); +} + +.table { + width: 100%; + border-collapse: separate; + border-spacing: 0; + background: var(--surface); + border: 1px solid var(--border); + border-radius: var(--radius); + box-shadow: var(--shadow); +} + +/* Rounded corners without overflow: hidden, which would clip the row menus. */ +.table thead th:first-child { + border-top-left-radius: var(--radius); +} + +.table thead th:last-child { + border-top-right-radius: var(--radius); +} + +.table th { + text-align: left; + font-size: 12px; + font-weight: 600; + color: var(--muted); + padding: 10px 14px; + background: var(--surface-2); + border-bottom: 1px solid var(--border); +} + +.table td { + padding: 10px 14px; + border-bottom: 1px solid var(--border); + vertical-align: middle; +} + +.table tbody tr:last-child td { + border-bottom: 0; +} + +.name { + min-width: 160px; + overflow-wrap: break-word; + word-break: break-word; +} + +.actions-cell { + width: 1%; + text-align: right; + white-space: nowrap; +} + +.actions { + display: flex; + justify-content: flex-end; + gap: 6px; +} + +.row-actions { + display: flex; + gap: 6px; + margin-top: 6px; +} + +.menu { + position: relative; +} + +.menu-list { + position: absolute; + right: 0; + top: calc(100% + 4px); + z-index: 5; + min-width: 160px; + padding: 4px; + display: grid; + background: var(--surface); + border: 1px solid var(--border); + border-radius: var(--radius); + box-shadow: 0 10px 30px rgb(0 0 0 / 18%); +} + +.menu-item { + padding: 7px 10px; + border: 0; + border-radius: 6px; + background: none; + color: var(--text); + font: inherit; + text-align: left; + cursor: pointer; +} + +.menu-item:hover:not(:disabled), +.menu-item:focus-visible { + background: var(--surface-2); + outline: none; +} + +.menu-item.danger-text { + color: var(--danger); +} + +.badge { + white-space: nowrap; + margin-left: 8px; + padding: 1px 6px; + border-radius: 999px; + background: var(--surface-2); + color: var(--muted); + font-family: var(--font); + font-size: 11px; +} + +.status { + display: inline-flex; + align-items: center; + gap: 6px; + font-size: 13px; +} + +.status::before { + content: ""; + width: 7px; + height: 7px; + border-radius: 50%; + background: currentcolor; +} + +.status.on { + color: var(--ok); +} + +.status.off { + color: var(--muted); +} + +/* Dialogs */ +.dialog { + width: min(560px, calc(100vw - 32px)); + padding: 0; + border: 1px solid var(--border); + border-radius: 12px; + background: var(--surface); + color: var(--text); + box-shadow: 0 20px 50px rgb(0 0 0 / 25%); +} + +.dialog.wide { + width: min(780px, calc(100vw - 32px)); +} + +.dialog::backdrop { + background: rgb(15 18 24 / 50%); +} + +.dialog-header { + display: flex; + align-items: center; + justify-content: space-between; + gap: 12px; + padding: 16px 20px; + border-bottom: 1px solid var(--border); +} + +.dialog-header h2 { + overflow-wrap: anywhere; +} + +.dialog-body { + padding: 18px 20px; +} + +.dialog-body p { + margin: 0; +} + +.dialog-footer { + display: flex; + justify-content: flex-end; + gap: 10px; + padding: 14px 20px; + border-top: 1px solid var(--border); +} + +.form .dialog-footer { + margin: 4px -20px -18px; +} + +.form { + display: grid; + gap: 14px; +} + +.field { + display: grid; + gap: 5px; +} + +fieldset.field { + border: 0; + margin: 0; + padding: 0; + min-width: 0; +} + +.field > label, +.field > legend { + font-weight: 500; +} + +.field > legend { + padding: 0 0 5px; +} + +.form-row { + display: grid; + grid-template-columns: 1fr 1fr; + gap: 12px; +} + +.hint { + color: var(--muted); + font-size: 12px; +} + +.hint.error { + color: var(--danger); +} + +/* Toasts */ +.toasts { + position: fixed; + right: 16px; + bottom: 16px; + z-index: 10; + display: grid; + gap: 8px; + width: min(380px, calc(100vw - 32px)); +} + +.toast { + display: flex; + align-items: center; + justify-content: space-between; + gap: 10px; + padding: 10px 10px 10px 14px; + background: var(--surface); + border: 1px solid var(--border); + border-left: 4px solid var(--ok); + border-radius: var(--radius); + box-shadow: var(--shadow); + overflow-wrap: anywhere; +} + +.toast.error { + border-left-color: var(--danger); +} + +/* Phones: the vault list becomes a select, table rows become cards. */ +@media (max-width: 800px) { + .topbar { + padding: 0 16px; + } + + .brand span { + display: none; + } + + .layout { + grid-template-columns: 1fr; + } + + .vaults { + position: static; + height: auto; + border-right: 0; + border-bottom: 1px solid var(--border); + padding: 12px 16px; + } + + .nav-group, + .version { + display: none; + } + + .vault-select { + display: block; + font-family: var(--mono); + } + + .content { + padding: 16px 16px 64px; + } + + .table, + .table tbody, + .table tr, + .table td { + display: block; + width: 100%; + } + + .table thead { + display: none; + } + + .table tr { + padding: 8px 0; + border-bottom: 1px solid var(--border); + } + + .table td { + border: 0; + padding: 4px 14px; + } + + .table td[data-label]::before { + content: attr(data-label); + display: block; + font-size: 11px; + color: var(--muted); + } + + .actions-cell { + text-align: left; + } + + .actions { + justify-content: flex-start; + } + + .menu-list { + left: 0; + right: auto; + } + + .form-row { + grid-template-columns: 1fr; + } +} + +/* ── Permissions UI ─────────────────────────────────────────────────────────── */ + +.notice { + background: var(--accent-soft); + margin-bottom: 12px; +} + +.notice.warn { + background: var(--warn-soft); + color: var(--warn); +} + +.notice p { + margin: 0 0 4px; +} + +.danger-text { + color: var(--danger); +} + +.badge.state-open { + background: var(--warn-soft); + color: var(--warn); +} + +.badge.state-granted { + background: var(--ok-soft); + color: var(--ok); +} + +.badge.state-declined { + background: var(--danger-soft); + color: var(--danger); +} + +.section { + margin-top: 28px; +} + +.section-head { + display: flex; + align-items: baseline; + justify-content: space-between; + gap: 12px; + margin-bottom: 8px; +} + +.section-head h2 { + margin: 0; +} + +.list { + margin: 0; + padding-left: 18px; +} + +.list li { + margin: 3px 0; +} + +.choices { + margin: 8px 0 0; + padding: 0; + list-style: none; + max-height: 420px; + overflow: auto; + border: 1px solid var(--border); + border-radius: var(--radius); +} + +.choice { + display: flex; + gap: 10px; + align-items: flex-start; + padding: 8px 12px; + border-bottom: 1px solid var(--border); + cursor: pointer; +} + +.choices li:last-child .choice { + border-bottom: 0; +} + +.choice.chosen { + background: var(--accent-soft); +} + +.choice input { + margin-top: 4px; +} + +tr.muted td { + color: var(--muted); +} + +.vaults a { + font-family: var(--font); +} + +.page-head { + margin-bottom: 16px; +} + +.page-head h1 { + margin: 0 0 4px; +} + +.page-head p { + margin: 0; +} + +.page-head .actions { + display: flex; + flex-wrap: wrap; + align-items: center; + gap: 8px; + margin-top: 10px; +} + +.choice input[type="checkbox"], +.choice input[type="radio"] { + width: auto; + flex: none; + margin-top: 4px; +} + +.choice > span { + flex: 1; + text-align: left; +} diff --git a/frontend/src/views/Activity.tsx b/frontend/src/views/Activity.tsx new file mode 100644 index 0000000..7cb44f3 --- /dev/null +++ b/frontend/src/views/Activity.tsx @@ -0,0 +1,132 @@ +import { useEffect, useState } from "react"; +import { api, type Environment, type Job } from "../api"; +import { useSession } from "../App"; +import { Confirm } from "../components/Dialog"; +import { Loading, message, StateBadge, useLoad } from "../components/ui"; +import { bytes, duration, when } from "../format"; + +function what(job: Job, env: string): string { + if (job.action === "snapshot") return "Snapshot"; + const from = job.source_environment && job.source_environment !== env ? `Clone from ${job.source_environment}/${job.source_database}` : "Restore"; + return job.into === "copy" ? `${from} into ${job.target_database}` : from; +} + +export function Activity({ env }: { env: Environment }) { + const { notify } = useSession(); + const { data, error, reload } = useLoad(() => api.jobs(env.name), [env.name]); + const [declining, setDeclining] = useState(null); + const [busy, setBusy] = useState(""); + + // While something runs, look again every few seconds. + const moving = data?.some((j) => j.state === "starting" || j.state === "running"); + useEffect(() => { + if (!moving) return; + const timer = window.setInterval(reload, 4000); + return () => window.clearInterval(timer); + }, [moving, reload]); + + async function act(job: Job, run: () => Promise, done: string) { + setBusy(job.name); + try { + await run(); + notify(done); + setDeclining(null); + reload(); + } catch (err) { + notify(message(err), "error"); + } finally { + setBusy(""); + } + } + + return ( + <> +
+

Activity in {env.name}

+

Snapshots and restores of the last week. {env.production && "A restore here starts once a second person approves it."}

+
+ +
+
+ {!data ? ( + + ) : data.length === 0 ? ( +
+

Nothing has run here this week.

+
+ ) : ( + + + + + + + + + + + + {data.map((j) => ( + + + + + + + + ))} + +
AskedWhatDatabaseStateResult
+ {when(j.requested_at)} + + {what(j, env.name)} + {(j.reason || j.note) &&
{j.reason || j.note}
} +
+ by {j.requested_by} + {j.approved_by && `, approved by ${j.approved_by}`} +
+
{j.database} + + {(j.can_approve || j.can_decline) && ( +
+ {j.can_approve && ( + + )} + {j.can_decline && ( + + )} +
+ )} +
+ {j.result.result === "succeeded" ? ( + <> + {bytes(j.result.bytes)} in {duration(j.result.seconds)} + + ) : ( + j.result.reason && {j.result.reason} + )} +
+ )} + {declining && ( + void act(declining, () => api.decline(env.name, declining.name, ""), "The request is gone.")} + onClose={() => setDeclining(null)} + > +

+ {what(declining, env.name)} of {declining.database}, asked by {declining.requested_by}, will not run. +

+
+ )} + + ); +} diff --git a/frontend/src/views/Audit.tsx b/frontend/src/views/Audit.tsx new file mode 100644 index 0000000..0992e45 --- /dev/null +++ b/frontend/src/views/Audit.tsx @@ -0,0 +1,70 @@ +import { api, type AuditEntry, type Environment } from "../api"; +import { Loading, useLoad } from "../components/ui"; +import { snapshotTime, when } from "../format"; + +const ACTIONS: Record = { + "snapshot.requested": "asked for a snapshot", + "snapshot.succeeded": "snapshot taken", + "snapshot.failed": "snapshot failed", + "snapshot.downloaded": "downloaded a snapshot", + "restore.requested": "asked for a restore", + "restore.approved": "approved a restore", + "restore.declined": "declined a restore", + "restore.expired": "restore request expired", + "restore.succeeded": "restore done", + "restore.failed": "restore failed", + "copy.dropped": "dropped a copy", +}; + +// "acc/snapshots/payments_acc/.dump" reads as "acc/payments_acc, snapshot of ". +function detail(e: AuditEntry, env: string): string { + const parts: string[] = []; + const snap = /^(?:([a-z0-9-]+)\/)?snapshots\/([^/]+)\/([^/]+)\.dump$/.exec(e.snapshot ?? ""); + if (snap) parts.push(`${snap[1] && snap[1] !== env ? `${snap[1]}/${snap[2]}, ` : ""}snapshot of ${snapshotTime(snap[3])}`); + if (e.target) parts.push(e.action === "copy.dropped" ? e.target : `into ${e.target}`); + if (e.detail) parts.push(e.detail); + return parts.join(" · "); +} + +export function Audit({ env }: { env: Environment }) { + const { data, error } = useLoad(() => api.audit(env.name), [env.name]); + + return ( + <> +
+

Audit log of {env.name}

+

Who asked for what, who approved it and how it ended, over the last two months.

+
+ {!data ? ( + + ) : data.length === 0 ? ( +
+

Nothing recorded yet.

+
+ ) : ( + + + + + + + + + + + + {data.map((e, i) => ( + + + + + + + + ))} + +
WhenWhoWhatDatabaseDetail
{when(e.at)}{e.actor}{ACTIONS[e.action] ?? e.action}{e.database ?? ""}{detail(e, env.name)}
+ )} + + ); +} diff --git a/frontend/src/views/DatabaseView.tsx b/frontend/src/views/DatabaseView.tsx new file mode 100644 index 0000000..9ba0630 --- /dev/null +++ b/frontend/src/views/DatabaseView.tsx @@ -0,0 +1,364 @@ +import { useEffect, useState, type FormEvent } from "react"; +import { api, type Database, type Environment, type Snapshot } from "../api"; +import { go, Section, useSession } from "../App"; +import { Confirm, Dialog } from "../components/Dialog"; +import { Menu } from "../components/Menu"; +import { Loading, message, useLoad } from "../components/ui"; +import { bytes, snapshotTime } from "../format"; + +export function DatabaseView({ env, name }: { env: Environment; name: string }) { + const { notify } = useSession(); + const databases = useLoad(() => api.databases(env.name), [env.name]); + const snapshots = useLoad(() => api.snapshots(env.name, name), [env.name, name]); + const [dialog, setDialog] = useState(null); + const [busy, setBusy] = useState(false); + const db = databases.data?.find((d) => d.name === name); + + if (!databases.data) return ; + if (!db) + return ( +
+

{name}

+

+ {env.name} has no database {name} of yours. Back to the databases. +

+
+ ); + + const act = db.can_act; + + async function dropCopy() { + setBusy(true); + try { + await api.dropCopy(env.name, name); + notify(`${db?.copy?.name} is being dropped.`); + setDialog(null); + databases.reload(); + } catch (err) { + notify(message(err), "error"); + } finally { + setBusy(false); + } + } + + return ( + <> +
+

{db.name}

+

+ {env.name} + {db.owner && <> · owned by {db.owner}} + {db.teams.length > 0 && <> · {db.teams.join(", ")}} +

+ {act && ( +
+ + +
+ )} +
+ {db.ready === false &&

CloudNativePG has not applied this database: {db.message || "no reason given"}.

} + {db.copy && ( +

+ A copy, {db.copy.name}, holds a restored snapshot{db.copy.ready ? "" : " (being created)"}.{" "} + {act && ( + + )} +

+ )} +
+ {!snapshots.data ? ( + + ) : snapshots.data.length === 0 ? ( +
+

No snapshots of {name} yet.

+
+ ) : ( + + + + + + + + + + + {snapshots.data.map((s) => ( + + + + + + + + ))} + +
TakenBySizeNote +
{snapshotTime(s.id)}{s.created_by || "—"}{bytes(s.size)}{s.note || —} + {act && ( + setDialog({ kind: "restore", snapshot: s.id }) }, + ...(env.downloads ? [{ label: "Download", onSelect: () => (window.location.href = api.downloadUrl(env.name, name, s.id)) }] : []), + ]} + /> + )} +
+ )} +
+ {db.workloads.length > 0 && ( +
+

A restore in place scales these to 0 replicas, and back to what they had afterwards.

+
    + {db.workloads.map((w) => ( +
  • {w}
  • + ))} +
+
+ )} + {dialog?.kind === "snapshot" && ( + setDialog(null)} + onDone={() => { + setDialog(null); + notify(`Taking a snapshot of ${name}; it shows here when it is done.`); + go(`/${env.name}/activity`); + }} + /> + )} + {dialog?.kind === "restore" && ( + setDialog(null)} + onDone={(waiting) => { + setDialog(null); + notify(waiting ? "The restore waits for a second person to approve it." : "The restore has started."); + go(`/${env.name}/activity`); + }} + /> + )} + {dialog?.kind === "drop" && db.copy && ( + void dropCopy()} onClose={() => setDialog(null)}> +

CloudNativePG drops the database and everything in it. Snapshots are not affected.

+
+ )} + + ); +} + +function SnapshotDialog({ env, db, onClose, onDone }: { env: Environment; db: Database; onClose: () => void; onDone: () => void }) { + const [note, setNote] = useState(""); + const [busy, setBusy] = useState(false); + const [error, setError] = useState(""); + + async function submit(e: FormEvent) { + e.preventDefault(); + setBusy(true); + setError(""); + try { + await api.snapshot(env.name, db.name, note); + onDone(); + } catch (err) { + setError(message(err)); + setBusy(false); + } + } + + return ( + +
void submit(e)}> +
+

pg_dump writes the whole database to {env.name}'s storage. The database stays online.

+
+ + setNote(e.target.value)} placeholder="before the 2.4 migration" /> +
+ {error && ( +

+ {error} +

+ )} +
+
+ + +
+
+
+ ); +} + +function RestoreDialog({ env, db, snapshot, onClose, onDone }: { env: Environment; db: Database; snapshot?: string; onClose: () => void; onDone: (waiting: boolean) => void }) { + const [source, setSource] = useState(env.name); + // The databases of the source environment, and the one picked there: the same name if it has one. + const [sources, setSources] = useState<{ env: string; databases: Database[]; picked: string } | null>({ env: env.name, databases: [db], picked: db.name }); + const [list, setList] = useState(null); + const [chosen, setChosen] = useState(snapshot ?? ""); + const [into, setInto] = useState<"database" | "copy">("database"); + const [reason, setReason] = useState(""); + const [typed, setTyped] = useState(""); + const [busy, setBusy] = useState(false); + const [error, setError] = useState(""); + const sourceDb = sources?.env === source ? sources.picked : ""; + + useEffect(() => { + if (source === env.name) { + setSources({ env: env.name, databases: [db], picked: db.name }); + return; + } + let live = true; + setSources(null); + setError(""); + api.databases(source).then( + (found) => live && setSources({ env: source, databases: found, picked: found.some((d) => d.name === db.name) ? db.name : (found[0]?.name ?? "") }), + (err) => live && setError(message(err)), + ); + return () => { + live = false; + }; + }, [source, env.name, db]); + + useEffect(() => { + setList(null); + if (!sourceDb) return; + let live = true; + setError(""); + api.snapshots(source, sourceDb).then( + (found) => { + if (!live) return; + setList(found); + setChosen((c) => (found.some((s) => s.id === c) ? c : (found[0]?.id ?? ""))); + }, + (err) => live && setError(message(err)), + ); + return () => { + live = false; + }; + }, [source, sourceDb]); + + const inPlace = into === "database"; + const ready = chosen && reason.trim().length >= 3 && (!inPlace || typed === db.name); + + async function submit(e: FormEvent) { + e.preventDefault(); + setBusy(true); + setError(""); + try { + const job = await api.restore(env.name, db.name, { source_environment: source, source_database: sourceDb, snapshot: chosen, into, reason: reason.trim() }); + onDone(job.state === "waiting"); + } catch (err) { + setError(message(err)); + setBusy(false); + } + } + + return ( + +
void submit(e)}> +
+
+
+ + +
+
+ + +
+
+
+ + +
+
+ Into +
    +
  • + +
  • +
  • + +
  • +
+
+
+ + setReason(e.target.value)} placeholder="roll back the failed 2.4 migration" /> +
+ {inPlace && ( +
+ + setTyped(e.target.value)} aria-invalid={typed !== "" && typed !== db.name} /> +
+ )} +

+ pg_restore runs in one transaction: if anything fails, nothing changes. Tables made after the snapshot was taken stay as they are. + {env.production && " In production a second person approves it before it starts."} +

+ {error && ( +

+ {error} +

+ )} +
+
+ + +
+
+
+ ); +} diff --git a/frontend/src/views/Databases.tsx b/frontend/src/views/Databases.tsx new file mode 100644 index 0000000..cc881a6 --- /dev/null +++ b/frontend/src/views/Databases.tsx @@ -0,0 +1,63 @@ +import { api, type Environment } from "../api"; +import { useSession } from "../App"; +import { Loading, useLoad } from "../components/ui"; + +export function Databases({ env }: { env: Environment }) { + const { me } = useSession(); + const { data, error } = useLoad(() => api.databases(env.name), [env.name]); + const cloners = me.environments.filter((e) => e.clone_from.includes(env.name)).map((e) => e.name); + + return ( + <> +
+

+ {env.name} {env.production && production} +

+

+ {env.runs_jobs + ? env.production + ? "Take a snapshot at any time. A restore waits for a second person, and snapshots stay here." + : "Take a snapshot, restore one, or clone one from another environment." + : `Only this environment's snapshots are read here${cloners.length ? `, to clone into ${cloners.join(", ")}` : ""}. Nothing runs in ${env.name} from this app.`} +

+
+ {!data ? ( + + ) : data.length === 0 ? ( +
+

No databases of yours here.

+

The catalog says which team acts on which database; ask the platform team to add yours.

+
+ ) : ( + + + + + + + + + + + + {data.map((d) => ( + + + + + + + + ))} + +
DatabaseOwnerTeamsStatusCopy
+ + {d.name} + + {d.owner || "—"}{d.teams.join(", ") || —} + {d.ready === null ? snapshots only : d.ready ? ready : not ready} + {d.copy ? d.copy.name : —}
+ )} + + ); +} diff --git a/frontend/tsconfig.json b/frontend/tsconfig.json new file mode 100644 index 0000000..59bc3bb --- /dev/null +++ b/frontend/tsconfig.json @@ -0,0 +1,17 @@ +{ + "compilerOptions": { + "target": "ES2022", + "lib": ["ES2022", "DOM", "DOM.Iterable"], + "module": "ESNext", + "moduleResolution": "bundler", + "jsx": "react-jsx", + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true, + "isolatedModules": true, + "skipLibCheck": true, + "types": ["vite/client"] + }, + "include": ["src", "vite.config.ts"] +} diff --git a/frontend/vite.config.ts b/frontend/vite.config.ts new file mode 100644 index 0000000..ae3d604 --- /dev/null +++ b/frontend/vite.config.ts @@ -0,0 +1,14 @@ +import react from "@vitejs/plugin-react"; +import { defineConfig } from "vite"; + +// `npm run dev` serves the UI on 5173 and hands /api and /auth to the backend on 8080. +export default defineConfig({ + plugins: [react()], + build: { outDir: "dist", sourcemap: false }, + server: { + proxy: { + "/api": "http://localhost:8080", // DevSkim: ignore DS162092 - the dev server's proxy to the local backend + "/auth": "http://localhost:8080", // DevSkim: ignore DS162092 + }, + }, +}); diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..66acd9c --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,30 @@ +[project] +name = "databases-ui" +# The release version lives in the git tag and reaches the image as APP_VERSION. +version = "0.0.0" +description = "Let app teams snapshot, restore and clone their own PostgreSQL databases on CloudNativePG, without platform help" +readme = "README.md" +license = "Apache-2.0" +requires-python = ">=3.12" +dependencies = [ + "fastapi>=0.140", + "uvicorn>=0.50", + "httpx>=0.28", + "pyjwt[crypto]>=2.10", + "cryptography>=45", + "pyyaml>=6.0.2", +] + +[project.scripts] +databases-ui = "databases_ui.__main__:main" + +[dependency-groups] +dev = ["pytest>=8", "pytest-cov>=6"] + +[build-system] +requires = ["uv_build>=0.11,<0.13"] +build-backend = "uv_build" + +[tool.pytest.ini_options] +testpaths = ["tests"] +filterwarnings = ["error::DeprecationWarning:databases_ui.*"] diff --git a/src/databases_ui/__init__.py b/src/databases_ui/__init__.py new file mode 100644 index 0000000..6c8e6b9 --- /dev/null +++ b/src/databases_ui/__init__.py @@ -0,0 +1 @@ +__version__ = "0.0.0" diff --git a/src/databases_ui/__main__.py b/src/databases_ui/__main__.py new file mode 100644 index 0000000..6c5a4d4 --- /dev/null +++ b/src/databases_ui/__main__.py @@ -0,0 +1,90 @@ +"""`python -m databases_ui [serve | check | job]`. + +serve load the config, build the app, serve it with uvicorn (the default) +check validate a catalog file and print every problem: for the catalog's own CI +job do one Job's work, as the server wrote it into the Job (runner.py) + +TLS ends at the ingress in front of it; this listens on plain http inside the pod. +""" + +import json +import logging +import sys +from pathlib import Path + +import uvicorn + +from .app import create_app +from .catalog import CatalogError, load_catalog +from .config import ConfigError, load_config + + +def check(path: Path) -> int: + try: + catalog = load_catalog(path.read_text(), path.name) + except OSError as err: + print(f"cannot read {path}: {err.__class__.__name__}", file=sys.stderr) + return 1 + except CatalogError as err: + for problem in err.problems: + print(problem, file=sys.stderr) + return 1 + print(f"{len(catalog.environments)} environments, {len(catalog.teams)} teams, {len(catalog.grants)} databases granted: the catalog holds together.") + return 0 + + +def serve() -> None: + try: + cfg = load_config() + except ConfigError as err: + print(json.dumps({"msg": "configuration refused", "reason": str(err)}), file=sys.stderr) + sys.exit(1) + logging.getLogger("databases_ui").info( + json.dumps( + { + "msg": "starting", + "version": cfg.version, + "origin": cfg.origin, + "tenant": cfg.tenant_id, + "client": cfg.client_id, + "credential": "workload identity" if cfg.federated_token_file else "client secret", + "storage": "sas" if cfg.storage_sas else "entra", + "environments": sorted(cfg.catalog.environments), + "teams": len(cfg.catalog.teams), + "job_image": cfg.job_image, + } + ) + ) + uvicorn.run( + create_app(cfg), + # All interfaces: a container port, reached only through the ingress in front of it. + host="0.0.0.0", # noqa: S104 # nosec B104 + port=cfg.port, + # Longer than common ingress idle timeouts, so this side never closes a keep-alive + # connection the proxy is about to reuse (a 502). + timeout_keep_alive=95, + access_log=False, + server_header=False, + log_level="info", + ) + + +def main() -> None: + logging.basicConfig(level=logging.INFO, format="%(message)s", stream=sys.stdout) + # httpx logs every request at INFO, and its URLs carry SAS tokens. + logging.getLogger("httpx").setLevel(logging.WARNING) + command = sys.argv[1] if len(sys.argv) > 1 else "serve" + if command == "check" and len(sys.argv) == 3: + sys.exit(check(Path(sys.argv[2]))) + if command == "job": + from .runner import main as job + + sys.exit(job()) + if command != "serve": + print("usage: python -m databases_ui [serve | check | job]", file=sys.stderr) + sys.exit(2) + serve() + + +if __name__ == "__main__": + main() diff --git a/src/databases_ui/app.py b/src/databases_ui/app.py new file mode 100644 index 0000000..a88eec4 --- /dev/null +++ b/src/databases_ui/app.py @@ -0,0 +1,352 @@ +"""The web app: sign-in routes, the JSON API the frontend calls, and the built frontend itself. + +Writes need the session's CSRF token in X-CSRF-Token and this origin in Origin, on top of the +SameSite=Strict session cookie. What a person may see and do is decided in service.py. +""" + +import hmac +import json +import logging +import re +import secrets +from collections.abc import AsyncIterator +from contextlib import asynccontextmanager +from datetime import UTC, datetime +from typing import Annotated, Any, Literal +from urllib.parse import urlencode + +import httpx +from fastapi import Depends, FastAPI, HTTPException, Path, Request +from fastapi.exceptions import RequestValidationError +from fastapi.responses import ( + JSONResponse, + RedirectResponse, + Response, + StreamingResponse, +) +from fastapi.staticfiles import StaticFiles +from pydantic import BaseModel, Field + +from .blob import BlobError, Container +from .catalog import DATABASE, Kubernetes +from .config import Branding, Config +from .entra import AppToken, Entra, app_credential +from .kube import Kube, KubeError +from .oidc import SignInError +from .service import SNAPSHOT_ID, Actor, Console, ConsoleError +from .session import Cookies, Sealer + +log = logging.getLogger("databases_ui") + +LOGIN_SECONDS = 600 +SOURCE = "https://github.com/MagmaMoose/databases-ui" + +CSP = "; ".join( + [ + "default-src 'none'", + "script-src 'self'", + "style-src 'self'", + "img-src 'self' data:", + "font-src 'self'", + "connect-src 'self'", + "manifest-src 'self'", + "base-uri 'none'", + "form-action 'self'", + "frame-ancestors 'none'", + ] +) + + +def release_notes(version: str) -> str | None: + """Where a version's changes are written up: its GitHub release, or the pull request it was built from.""" + if re.fullmatch(r"v[0-9]+\.[0-9]+\.[0-9]+(?:-[0-9A-Za-z.-]+)?", version): + return f"{SOURCE}/releases/tag/{version}" + if found := re.fullmatch(r"pr-([0-9]+)", version): + return f"{SOURCE}/pull/{found.group(1)}" + return None + + +def theme_css(brand: Branding) -> str: + """The operator's colours over styles.css, whose `:root` loses to `html:root` in any order.""" + + def rules(accent: str, text: str, soft: int) -> str: + found = [f"--accent:{accent}", f"--accent-soft:color-mix(in srgb,{accent} {soft}%,var(--surface))"] if accent else [] + return ";".join(found + ([f"--accent-text:{text}"] if text else [])) + + light = rules(brand.accent, brand.accent_text, 10) + dark = rules(brand.accent_dark or brand.accent, brand.accent_text_dark or brand.accent_text, 14) + return (f"html:root{{{light}}}\n" if light else "") + (f"@media (prefers-color-scheme: dark){{html:root{{{dark}}}}}\n" if dark else "") + + +def favicon_svg(brand: Branding) -> str: + """The tab icon in the operator's accent. Unbranded, it is frontend/public/favicon.svg.""" + tile, glyph = brand.accent or "#0f766e", brand.accent_text or "#fff" + return ( + f'' + f'' + '' + ) + + +EnvName = Annotated[str, Path(pattern=r"^[a-z0-9-]{1,32}$")] +DbName = Annotated[str, Path(pattern=DATABASE)] +JobName = Annotated[str, Path(pattern=r"^dbui-(snapshot|restore)-[0-9a-f]{8}$")] +SnapshotId = Annotated[str, Path(pattern=SNAPSHOT_ID)] + + +class Note(BaseModel): + note: str = Field(default="", max_length=300) + + +class Restore(BaseModel): + source_environment: str = Field(pattern=r"^[a-z0-9-]{1,32}$") + source_database: str = Field(pattern=DATABASE) + snapshot: str = Field(pattern=SNAPSHOT_ID) + into: Literal["database", "copy"] + reason: str = Field(min_length=3, max_length=300) + + +class Reason(BaseModel): + reason: str = Field(default="", max_length=300) + + +def _log(event: str, **fields: Any) -> None: + log.info(json.dumps({"msg": event, **fields})) + + +def build_console(cfg: Config, http: httpx.AsyncClient, *, kube_transport: httpx.AsyncBaseTransport | None = None, now=lambda: datetime.now(UTC)) -> Console: + """One Kubernetes client per environment that runs Jobs, and one container per environment.""" + token = None if cfg.storage_sas else AppToken(http, token_url=cfg.token_url, client_id=cfg.client_id, credential=lambda: app_credential(cfg)) + kube: dict[str, Kube] = {} + storage: dict[str, Container] = {} + for env in cfg.catalog.environments.values(): + storage[env.name] = Container(http, env.storage.url, token=token, sas=cfg.storage_sas) + if isinstance(env.kubernetes, Kubernetes): + kube[env.name] = Kube(server=env.kubernetes.server, token_file=env.kubernetes.token_file, ca_file=env.kubernetes.ca_file, transport=kube_transport) + elif env.kubernetes == "in-cluster": + kube[env.name] = Kube.in_cluster(transport=kube_transport) + return Console(cfg, kube, storage, now=now) + + +def create_app(cfg: Config, transport: httpx.AsyncBaseTransport | None = None, *, kube_transport: httpx.AsyncBaseTransport | None = None, now=lambda: datetime.now(UTC)) -> FastAPI: + http = httpx.AsyncClient(transport=transport, follow_redirects=False) + idp = Entra(cfg, http) + cookies = Cookies(Sealer(cfg.session_key), secure=cfg.secure_cookies) + console = build_console(cfg, http, kube_transport=kube_transport, now=now) + + @asynccontextmanager + async def lifespan(_: FastAPI): + yield + await http.aclose() + + app = FastAPI(lifespan=lifespan, docs_url=None, redoc_url=None, openapi_url=None) + app.state.console = console + + @app.middleware("http") + async def headers(request: Request, call_next): + response = await call_next(request) + path = request.url.path + response.headers["Content-Security-Policy"] = CSP + response.headers["X-Content-Type-Options"] = "nosniff" + response.headers["Referrer-Policy"] = "no-referrer" + response.headers["X-Frame-Options"] = "DENY" + response.headers["Cross-Origin-Opener-Policy"] = "same-origin" + response.headers["Cross-Origin-Resource-Policy"] = "same-origin" + response.headers["Permissions-Policy"] = "camera=(), microphone=(), geolocation=(), payment=(), usb=()" + if cfg.secure_cookies: + response.headers["Strict-Transport-Security"] = "max-age=31536000" + if path.startswith("/assets/"): + # Vite names every asset by its content hash. + response.headers["Cache-Control"] = "public, max-age=31536000, immutable" + elif path.startswith(("/api/", "/auth/")): + response.headers["Cache-Control"] = "no-store" + else: + response.headers["Cache-Control"] = "no-cache" + return response + + @app.exception_handler(RequestValidationError) + async def invalid(_: Request, exc: RequestValidationError) -> JSONResponse: + fields = [{"field": ".".join(str(p) for p in e.get("loc", ())[1:]), "message": e.get("msg", "")} for e in exc.errors()] + return JSONResponse({"error": "invalid_request", "message": "The request is not valid.", "fields": fields}, 422) + + @app.exception_handler(ConsoleError) + async def console_error(_: Request, exc: ConsoleError) -> JSONResponse: + return JSONResponse({"error": exc.code, "message": str(exc)}, exc.status) + + @app.exception_handler(KubeError) + async def kube_error(_: Request, exc: KubeError) -> JSONResponse: + _log("kubernetes failed", status=exc.status, reason=str(exc)) + return JSONResponse({"error": "kubernetes_unavailable", "message": f"Kubernetes refused: {exc}"}, 502) + + @app.exception_handler(BlobError) + async def blob_error(_: Request, exc: BlobError) -> JSONResponse: + _log("storage failed", status=exc.status, reason=str(exc)) + return JSONResponse({"error": "storage_unavailable", "message": f"Storage refused: {exc}"}, 502) + + @app.exception_handler(SignInError) + async def token_error(_: Request, exc: SignInError) -> JSONResponse: + _log("app token failed", status=exc.status, reason=str(exc)) + return JSONResponse({"error": "storage_unavailable", "message": str(exc)}, 502) + + @app.exception_handler(HTTPException) + async def http_error(_: Request, exc: HTTPException) -> JSONResponse: + return JSONResponse({"error": exc.detail}, exc.status_code) + + # ── Sessions ────────────────────────────────────────────────────────────────────── + + def session(request: Request) -> dict[str, Any]: + data = cookies.read_session(request) + if data is None: + raise HTTPException(401, "signed_out") + return data + + Session = Annotated[dict[str, Any], Depends(session)] + + def writable(request: Request, data: Session) -> dict[str, Any]: + origin = request.headers.get("origin", "").encode() + token = request.headers.get("x-csrf-token", "").encode() + if not hmac.compare_digest(origin, cfg.origin.encode()) or not hmac.compare_digest(token, str(data.get("csrf", "")).encode()): + raise HTTPException(403, "csrf") + return data + + Writable = Annotated[dict[str, Any], Depends(writable)] + + def actor(data: dict[str, Any]) -> Actor: + roles = data.get("roles") or [] + return Actor( + oid=str(data["oid"]), upn=str(data.get("upn", "")), name=str(data.get("name", "")), groups=frozenset(data.get("groups") or []), + admin=cfg.admin_role in roles, auditor=cfg.auditor_role in roles, + ) # fmt: skip + + # ── Sign-in ─────────────────────────────────────────────────────────────────────── + + @app.get("/healthz") + async def healthz() -> dict[str, str]: + return {"status": "ok"} + + theme = theme_css(cfg.branding) + favicon = favicon_svg(cfg.branding) + + @app.get("/theme.css") + async def theme_stylesheet() -> Response: + return Response(theme, media_type="text/css") + + @app.get("/favicon.svg") + async def favicon_image() -> Response: + return Response(favicon, media_type="image/svg+xml") + + @app.get("/auth/login") + async def login() -> Response: + state, nonce, verifier = secrets.token_urlsafe(32), secrets.token_urlsafe(32), secrets.token_urlsafe(64) + response = RedirectResponse(idp.authorize_url(state=state, nonce=nonce, verifier=verifier), 302) + cookies.write_login(response, {"state": state, "nonce": nonce, "verifier": verifier}, LOGIN_SECONDS) + return response + + def _back(**query: str) -> Response: + response = RedirectResponse("/" + (f"?{urlencode(query)}" if query else ""), 303) + cookies.clear(response, cookies.login) + return response + + @app.get("/auth/callback") + async def callback(request: Request) -> Response: + params = request.query_params + if params.get("error"): + reason = (params.get("error_description") or params["error"]).splitlines()[0][:300] + _log("sign-in refused", reason=reason) + return _back(auth_error=reason) + flow = cookies.read_login(request) + if flow is None or not hmac.compare_digest(params.get("state", "").encode(), str(flow.get("state", "")).encode()): + return _back(auth_error="This sign-in expired or was not started here. Sign in again.") + try: + signed = await idp.redeem_code(code=params.get("code", ""), verifier=str(flow["verifier"]), nonce=str(flow["nonce"])) + except SignInError as err: + _log("sign-in failed", status=err.status, reason=str(err)) + return _back(auth_error=str(err)) + data = {"oid": signed.oid, "upn": signed.upn, "name": signed.name, "roles": signed.roles, "groups": signed.groups, "csrf": secrets.token_urlsafe(32)} + response = _back() + cookies.write_session(request, response, data, cfg.session_seconds) + _log("signed in", user=signed.oid, upn=signed.upn, roles=signed.roles, groups=len(signed.groups)) + return response + + @app.post("/auth/logout") + async def logout(request: Request, data: Writable) -> Response: + response = JSONResponse({"signed_out": True}) + cookies.clear_session(request, response) + return response + + # ── API ─────────────────────────────────────────────────────────────────────────── + + @app.get("/api/me") + async def me(data: Session) -> dict[str, Any]: + who = actor(data) + return { + "name": who.name, + "upn": who.upn, + "csrf": data.get("csrf", ""), + "expires": data.get("exp"), + "version": cfg.version, + "release_notes": release_notes(cfg.version), + "admin": who.admin, + "auditor": who.auditor, + "teams": [{"id": t.id, "name": t.name} for t in cfg.catalog.teams_of(who.groups)], + "environments": [ + {"name": e.name, "production": e.production, "runs_jobs": e.runs_jobs, "clone_from": e.clone_from, "downloads": not e.production} + for e in cfg.catalog.environments.values() + ], + } + + @app.get("/api/environments/{env}/databases") + async def databases(env: EnvName, data: Session) -> dict[str, Any]: + return {"databases": await console.databases(actor(data), env)} + + @app.get("/api/environments/{env}/databases/{db}/snapshots") + async def snapshots(env: EnvName, db: DbName, data: Session) -> dict[str, Any]: + return {"snapshots": await console.snapshots(actor(data), env, db)} + + @app.post("/api/environments/{env}/databases/{db}/snapshots", status_code=201) + async def take_snapshot(env: EnvName, db: DbName, body: Note, data: Writable) -> dict[str, Any]: + return await console.take_snapshot(actor(data), env, db, body.note.strip()) + + @app.post("/api/environments/{env}/databases/{db}/restore", status_code=201) + async def restore(env: EnvName, db: DbName, body: Restore, data: Writable) -> dict[str, Any]: + return await console.restore( + actor(data), env, db, source_environment=body.source_environment, source_database=body.source_database, snapshot=body.snapshot, into=body.into, reason=body.reason.strip(), + ) # fmt: skip + + @app.delete("/api/environments/{env}/databases/{db}/copy", status_code=204) + async def drop_copy(env: EnvName, db: DbName, data: Writable) -> Response: + await console.drop_copy(actor(data), env, db) + return Response(status_code=204) + + @app.get("/api/environments/{env}/databases/{db}/snapshots/{sid}/download") + async def download(env: EnvName, db: DbName, sid: SnapshotId, data: Session) -> Response: + container, blob, filename = await console.download(actor(data), env, db, sid) + + async def body() -> AsyncIterator[bytes]: + async with container.download(blob) as (_, chunks): + async for chunk in chunks: + yield chunk + + return StreamingResponse(body(), media_type="application/octet-stream", headers={"Content-Disposition": f'attachment; filename="{filename}"'}) + + @app.get("/api/environments/{env}/jobs") + async def list_jobs(env: EnvName, data: Session) -> dict[str, Any]: + return {"jobs": await console.jobs(actor(data), env)} + + @app.post("/api/environments/{env}/jobs/{name}/approve") + async def approve(env: EnvName, name: JobName, data: Writable) -> dict[str, Any]: + return await console.approve(actor(data), env, name) + + @app.post("/api/environments/{env}/jobs/{name}/decline", status_code=204) + async def decline(env: EnvName, name: JobName, body: Reason, data: Writable) -> Response: + await console.decline(actor(data), env, name, body.reason.strip()) + return Response(status_code=204) + + @app.get("/api/environments/{env}/audit") + async def audit_log(env: EnvName, data: Session) -> dict[str, Any]: + return {"entries": await console.audit_log(actor(data), env)} + + if cfg.static_dir is not None: + app.mount("/", StaticFiles(directory=cfg.static_dir, html=True), name="frontend") + + return app diff --git a/src/databases_ui/audit.py b/src/databases_ui/audit.py new file mode 100644 index 0000000..a87d790 --- /dev/null +++ b/src/databases_ui/audit.py @@ -0,0 +1,43 @@ +"""The audit log: one JSON line per action, in an append blob per month in the environment's +container. The server writes what people ask for and decide; each Job writes how it ended. +""" + +from __future__ import annotations + +import json +import logging +from datetime import UTC, datetime +from typing import Any + +from .blob import BlobError, Container + +log = logging.getLogger("databases_ui") +PREFIX = "audit/" + + +def blob_name(at: datetime) -> str: + return f"{PREFIX}{at:%Y-%m}.jsonl" + + +async def record(container: Container, *, environment: str, actor: str, action: str, at: datetime | None = None, **detail: Any) -> dict[str, Any]: + """Append one entry, and log it; a storage error is logged, not raised, after the action happened.""" + at = at or datetime.now(UTC) + entry = {"at": at.strftime("%Y-%m-%dT%H:%M:%SZ"), "environment": environment, "actor": actor, "action": action, **{k: v for k, v in detail.items() if v not in (None, "")}} + log.info(json.dumps({"msg": "audit", **entry})) + try: + await container.append(blob_name(at), (json.dumps(entry, separators=(",", ":")) + "\n").encode()) + except BlobError as err: + log.error(json.dumps({"msg": "audit write failed", "status": err.status, "reason": str(err), "entry": entry})) + return entry + + +def parse(text: bytes) -> list[dict[str, Any]]: + entries = [] + for line in text.decode(errors="replace").splitlines(): + try: + item = json.loads(line) + except ValueError: + continue + if isinstance(item, dict): + entries.append(item) + return entries diff --git a/src/databases_ui/blob.py b/src/databases_ui/blob.py new file mode 100644 index 0000000..edbe62b --- /dev/null +++ b/src/databases_ui/blob.py @@ -0,0 +1,168 @@ +"""Azure Blob Storage through its REST API: one container per environment, holding its snapshots +and its audit log. + +An Entra ID token (workload identity) or a SAS authorises every call. A snapshot is uploaded in +blocks as pg_dump writes it, so nothing touches a disk; an upload that fails commits nothing, and +Azure drops the uncommitted blocks after a week. +""" + +from __future__ import annotations + +import asyncio +import base64 +import hashlib +import xml.etree.ElementTree as ET # nosec B405 - parses Azure Storage's own listings, nothing a person writes +from collections.abc import AsyncIterator, Awaitable, Callable +from contextlib import asynccontextmanager +from dataclasses import dataclass +from email.utils import formatdate +from urllib.parse import parse_qsl, quote, unquote + +import httpx + +API_VERSION = "2024-08-04" +BLOCK = 8 * 1024 * 1024 +_RETRIES = 3 + + +class BlobError(Exception): + def __init__(self, status: int, message: str): + super().__init__(message) + self.status = status + + +@dataclass(frozen=True) +class Blob: + name: str + size: int + created: str + metadata: dict[str, str] + + +class Container: + def __init__(self, http: httpx.AsyncClient, url: str, *, token: Callable[[], Awaitable[str]] | None = None, sas: str = ""): + self._http = http + self.url = url.rstrip("/") + self._token = token + self._sas = dict(parse_qsl(sas.lstrip("?"))) + + async def _headers(self, **extra: str) -> dict[str, str]: + headers = {"x-ms-version": API_VERSION, "x-ms-date": formatdate(usegmt=True), **extra} + if self._token is not None and not self._sas: + headers["Authorization"] = f"Bearer {await self._token()}" + return headers + + def _target(self, name: str = "", **query: str) -> tuple[str, dict[str, str]]: + url = f"{self.url}/{quote(name)}" if name else self.url + return url, {**query, **self._sas} + + async def _send(self, method: str, name: str = "", *, query: dict[str, str] | None = None, headers: dict[str, str] | None = None, content: bytes | None = None, ok: tuple[int, ...] = (200, 201)) -> httpx.Response: + url, params = self._target(name, **(query or {})) + for attempt in range(_RETRIES): + try: + response = await self._http.request(method, url, params=params, headers=await self._headers(**(headers or {})), content=content, timeout=120) + except httpx.HTTPError as err: + if attempt + 1 == _RETRIES: + raise BlobError(502, f"cannot reach storage: {err.__class__.__name__}") from err + else: + if response.status_code in ok or response.status_code < 500 or attempt + 1 == _RETRIES: + break + await asyncio.sleep(2**attempt) + if response.status_code not in ok: + raise BlobError(response.status_code, f"storage answered {response.status_code} {response.headers.get('x-ms-error-code', '')}".strip()) + return response + + async def list(self, prefix: str) -> list[Blob]: + found: list[Blob] = [] + marker = "" + while True: + query = {"restype": "container", "comp": "list", "prefix": prefix, "include": "metadata"} + if marker: + query["marker"] = marker + response = await self._send("GET", query=query) + root = ET.fromstring(response.content) # nosec B314 - Azure Storage's own XML; expat limits entity expansion + for item in root.iter("Blob"): + props = item.find("Properties") + meta = item.find("Metadata") + found.append( + Blob( + name=item.findtext("Name", ""), + size=int(props.findtext("Content-Length", "0") if props is not None else 0), + created=(props.findtext("Creation-Time", "") or props.findtext("Last-Modified", "")) if props is not None else "", + metadata={child.tag.lower(): unquote(child.text or "") for child in meta} if meta is not None else {}, + ) + ) + marker = root.findtext("NextMarker", "") + if not marker: + return found + + async def properties(self, name: str) -> Blob | None: + try: + response = await self._send("HEAD", name) + except BlobError as err: + if err.status == 404: + return None + raise + meta = {k[len("x-ms-meta-") :].lower(): unquote(v) for k, v in response.headers.items() if k.lower().startswith("x-ms-meta-")} + return Blob(name=name, size=int(response.headers.get("content-length", "0")), created=response.headers.get("x-ms-creation-time", ""), metadata=meta) + + async def upload(self, name: str, chunks: AsyncIterator[bytes], metadata: dict[str, str], before_commit: Callable[[], Awaitable[None]] | None = None) -> tuple[int, str]: + """Write `chunks` to a block blob, committed with `metadata` once all are in and + `before_commit` has not raised: its size and sha256.""" + ids: list[str] = [] + digest = hashlib.sha256() + size = 0 + buffer = bytearray() + + async def put(data: bytes) -> None: + block = base64.b64encode(f"{len(ids):08d}".encode()).decode() + await self._send("PUT", name, query={"comp": "block", "blockid": block}, content=data) + ids.append(block) + + async for chunk in chunks: + digest.update(chunk) + size += len(chunk) + buffer += chunk + while len(buffer) >= BLOCK: + await put(bytes(buffer[:BLOCK])) + del buffer[:BLOCK] + if buffer: + await put(bytes(buffer)) + if before_commit is not None: + await before_commit() + body = "" + "".join(f"{i}" for i in ids) + "" + meta = {f"x-ms-meta-{k}": quote(v, safe="") for k, v in {**metadata, "size": str(size), "sha256": digest.hexdigest()}.items()} + await self._send("PUT", name, query={"comp": "blocklist"}, headers={"x-ms-blob-content-type": "application/octet-stream", **meta}, content=body.encode()) + return size, digest.hexdigest() + + @asynccontextmanager + async def download(self, name: str) -> AsyncIterator[tuple[int, AsyncIterator[bytes]]]: + """The blob's size and its bytes, streamed.""" + url, params = self._target(name) + try: + async with self._http.stream("GET", url, params=params, headers=await self._headers(), timeout=httpx.Timeout(60, read=300)) as response: + if response.status_code != 200: + raise BlobError(response.status_code, f"storage answered {response.status_code} {response.headers.get('x-ms-error-code', '')}".strip()) + yield int(response.headers.get("content-length", "0")), response.aiter_bytes(1024 * 1024) + except httpx.HTTPError as err: + raise BlobError(502, f"the download broke off: {err.__class__.__name__}") from err + + async def read(self, name: str) -> bytes | None: + try: + return (await self._send("GET", name)).content + except BlobError as err: + if err.status == 404: + return None + raise + + async def append(self, name: str, data: bytes) -> None: + """Add `data` to an append blob, created on first use.""" + try: + await self._send("PUT", name, query={"comp": "appendblock"}, content=data) + return + except BlobError as err: + if err.status != 404: + raise + # 409: someone else created it in the meantime, which is as good. + await self._send("PUT", name, headers={"x-ms-blob-type": "AppendBlob", "If-None-Match": "*"}, content=b"", ok=(201, 409)) + await self._send("PUT", name, query={"comp": "appendblock"}, content=data) diff --git a/src/databases_ui/catalog.py b/src/databases_ui/catalog.py new file mode 100644 index 0000000..63efc6a --- /dev/null +++ b/src/databases_ui/catalog.py @@ -0,0 +1,224 @@ +"""The catalog: the environments this app reaches, and which team acts on which database. One +YAML file. + + environments: + - name: dev + cluster: dev # the CloudNativePG Cluster (default: the name) + namespace: database # its namespace: Database resources, Secrets and Jobs + storage: + url: https://.blob.core.windows.net/dev-snapshots + cloneFrom: [acc] # environments whose snapshots may be restored here + - name: prd + production: true # a restore waits for a second person; no downloads + ... + teams: + - id: payments + name: Payments + groups: [] + databases: + - name: payments # the Database resource's spec.name; {env} is the environment + workloads: [deployment/{env}-payments/api] # scaled to 0 for a restore in place + +Everything here is plain data with no I/O, so `check` validates the same file the server reads. +""" + +from __future__ import annotations + +import re +from dataclasses import dataclass +from typing import Literal +from urllib.parse import urlsplit + +import yaml +from pydantic import ( + BaseModel, + ConfigDict, + Field, + ValidationError, + field_validator, + model_validator, +) + +NAME = r"^[a-z0-9]([a-z0-9-]{0,30}[a-z0-9])?$" +# A database name that is also a valid label value; `_copy` must still fit in PostgreSQL's 63. +DATABASE = r"^[a-z0-9]([a-z0-9_-]{0,56}[a-z0-9])?$" +_GUID = re.compile(r"^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$") +_WORKLOAD = re.compile(r"^(deployment|statefulset)/([a-z0-9{}][a-z0-9{}-]{0,62})/([a-z0-9{}][a-z0-9.{}-]{0,252})$") +# Plain http only for an emulator inside the cluster or on this machine. +_LOCAL = re.compile(r"^(localhost|127\.0\.0\.1|\[::1\]|[a-z0-9.-]+\.svc(\.cluster\.local)?)$") # DevSkim: ignore DS162092 - plain http is allowed only for a local emulator + + +class CatalogError(ValueError): + """The catalog does not hold together; `problems` lists every reason.""" + + def __init__(self, problems: list[str]): + super().__init__("; ".join(problems)) + self.problems = problems + + +class _Model(BaseModel): + model_config = ConfigDict(extra="forbid", frozen=True, populate_by_name=True) + + +class Storage(_Model): + # The container that holds the environment's snapshots and its audit log. + url: str = Field(max_length=300) + + @field_validator("url") + @classmethod + def _url(cls, value: str) -> str: + parts = urlsplit(value) + host = (parts.hostname or "").lower() + if parts.query or parts.fragment or parts.username or not host or len(parts.path.strip("/")) == 0: + raise ValueError("storage.url is the container's URL: https://.blob.core.windows.net/") + if parts.scheme != "https" and not (parts.scheme == "http" and _LOCAL.match(host)): + raise ValueError("storage.url must be https (plain http only for a local emulator)") + return value.rstrip("/") + + +class Kubernetes(_Model): + """Another cluster's API server, with a CA and a token file read on every call.""" + + server: str = Field(pattern=r"^https://\S+$") + ca_file: str = Field(alias="caFile", min_length=1) + token_file: str = Field(alias="tokenFile", min_length=1) + + +class Environment(_Model): + name: str = Field(pattern=NAME) + production: bool = False + cluster: str = Field(default="", pattern=r"^$|^[a-z0-9]([a-z0-9-]{0,48}[a-z0-9])?$") + namespace: str = Field(default="database", pattern=r"^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$") + # in-cluster: this app's own cluster. none: snapshots only, to clone from; nothing runs there. + kubernetes: Literal["in-cluster", "none"] | Kubernetes = "in-cluster" + storage: Storage + clone_from: list[str] = Field(default_factory=list, alias="cloneFrom") + + @property + def cnpg_cluster(self) -> str: + return self.cluster or self.name + + @property + def runs_jobs(self) -> bool: + return self.kubernetes != "none" + + +class DatabaseRef(_Model): + name: str = Field(min_length=1, max_length=63) + # Empty: every environment. + environments: list[str] = Field(default_factory=list) + workloads: list[str] = Field(default_factory=list) + + @field_validator("workloads") + @classmethod + def _workloads(cls, values: list[str]) -> list[str]: + for value in values: + if not _WORKLOAD.match(value): + raise ValueError(f"{value!r} is not deployment// or statefulset//") + return values + + +class Team(_Model): + id: str = Field(pattern=NAME) + name: str = Field(min_length=1, max_length=120) + description: str = Field(default="", max_length=2000) + # Entra ID group object ids; their members act on the team's databases. + groups: list[str] = Field(min_length=1) + databases: list[DatabaseRef] = Field(default_factory=list) + + @field_validator("groups") + @classmethod + def _groups(cls, values: list[str]) -> list[str]: + for value in values: + if not _GUID.match(value.lower()): + raise ValueError(f"{value!r} is not a group object id (a GUID)") + return [v.lower() for v in values] + + +class _File(_Model): + environments: list[Environment] = Field(min_length=1) + teams: list[Team] = Field(default_factory=list) + + @model_validator(mode="after") + def _references(self) -> _File: + names = [e.name for e in self.environments] + problems = [f"environment {n!r} is listed twice" for n in sorted({n for n in names if names.count(n) > 1})] + for env in self.environments: + problems += [f"environment {env.name!r} clones from unknown environment {s!r}" for s in env.clone_from if s not in names] + if env.name in env.clone_from: + problems.append(f"environment {env.name!r} lists itself in cloneFrom") + ids = [t.id for t in self.teams] + problems += [f"team {i!r} is listed twice" for i in sorted({i for i in ids if ids.count(i) > 1})] + for team in self.teams: + for ref in team.databases: + problems += [f"team {team.id!r} names unknown environment {e!r}" for e in ref.environments if e not in names] + for env in ref.environments or names: + if not re.match(DATABASE, ref.name.replace("{env}", env)): + problems.append(f"team {team.id!r}: {ref.name.replace('{env}', env)!r} is not a database name this app takes (a-z, 0-9, _ and -, at most 58)") + if problems: + raise ValueError("; ".join(problems)) + return self + + +@dataclass(frozen=True) +class Grant: + """A database a team acts on in one environment.""" + + team: str + environment: str + database: str + workloads: tuple[tuple[str, str, str], ...] + + +@dataclass(frozen=True) +class Catalog: + environments: dict[str, Environment] + teams: dict[str, Team] + grants: tuple[Grant, ...] + + @property + def groups(self) -> frozenset[str]: + """Every group the catalog names: the only ones a session needs to carry.""" + return frozenset(g for t in self.teams.values() for g in t.groups) + + def teams_of(self, groups: frozenset[str]) -> list[Team]: + return [t for t in self.teams.values() if groups & set(t.groups)] + + def grant(self, team_ids: set[str], environment: str, database: str) -> Grant | None: + return next((g for g in self.grants if g.team in team_ids and g.environment == environment and g.database == database), None) + + def databases(self, environment: str, team_ids: set[str] | None = None) -> dict[str, Grant]: + """The databases of `environment` the catalog names, for these teams or for any.""" + found: dict[str, Grant] = {} + for g in self.grants: + if g.environment == environment and (team_ids is None or g.team in team_ids): + found.setdefault(g.database, g) + return found + + +def _workload(value: str, env: str) -> tuple[str, str, str]: + kind, namespace, name = value.replace("{env}", env).split("/") + return kind, namespace, name + + +def load_catalog(text: str, source: str = "catalog") -> Catalog: + try: + data = yaml.safe_load(text) + except yaml.YAMLError as err: + raise CatalogError([f"{source}: not YAML: {err}"]) from err + try: + parsed = _File.model_validate(data if isinstance(data, dict) else {}) + except ValidationError as err: + problems = [] + for e in err.errors(): + where = ".".join(str(p) for p in e.get("loc", ())) + problems.append(f"{source}: {where + ': ' if where else ''}{e.get('msg', '')}".replace("Value error, ", "")) + raise CatalogError(problems) from err + names = [e.name for e in parsed.environments] + grants = tuple( + Grant(team.id, env, ref.name.replace("{env}", env), tuple(_workload(w, env) for w in ref.workloads)) + for team in parsed.teams + for ref in team.databases + for env in (ref.environments or names) + ) + return Catalog(environments={e.name: e for e in parsed.environments}, teams={t.id: t for t in parsed.teams}, grants=grants) diff --git a/src/databases_ui/config.py b/src/databases_ui/config.py new file mode 100644 index 0000000..2ce602d --- /dev/null +++ b/src/databases_ui/config.py @@ -0,0 +1,204 @@ +"""Everything the server reads from its environment, parsed and checked once at startup. + +A value that would make the server unsafe or useless fails startup rather than the first +request: a pod in CrashLoopBackOff with the reason in its log is found in minutes. +""" + +from __future__ import annotations + +import os +import re +from dataclasses import dataclass, field +from pathlib import Path +from urllib.parse import urlsplit + +from .catalog import Catalog, CatalogError, load_catalog + +_GUID = re.compile(r"^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$") +_HOST = re.compile(r"^[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)+$") +_COLOUR = re.compile(r"^#[0-9a-fA-F]{6}$") +_ROLE = re.compile(r"^[A-Za-z0-9._-]{1,120}$") +_K8S_NAME = re.compile(r"^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$") +_SECRET_REF = re.compile(r"^[a-z0-9]([a-z0-9.-]{0,251}[a-z0-9])?/[A-Za-z0-9._-]{1,253}$") +_LOOPBACK = {"localhost", "127.0.0.1", "::1"} # DevSkim: ignore DS162092 - plain http is allowed on loopback, for local development + + +class ConfigError(ValueError): + """A configuration value the server refuses to start with.""" + + +@dataclass(frozen=True) +class Branding: + """Colours as #rrggbb; empty keeps the default. The dark ones fall back to the light ones.""" + + accent: str = "" + accent_text: str = "" + accent_dark: str = "" + accent_text_dark: str = "" + + +@dataclass(frozen=True) +class Config: + tenant_id: str + client_id: str + origin: str + authority: str + session_key: bytes + session_seconds: int + catalog: Catalog + # The image every Job runs: this app's own, which carries the PostgreSQL client. + job_image: str + job_service_account: str = "databases-ui-job" + federated_token_file: Path | None = None + client_secret: str | None = None + # Storage through a SAS instead of Entra ID: the token for this server, and / of + # the Secret that holds the same token in each environment's namespace, for the Jobs. + storage_sas: str = "" + storage_sas_secret: str = "" + admin_role: str = "Admin" + auditor_role: str = "Auditor" + static_dir: Path | None = None + port: int = 8080 + version: str = "dev" + branding: Branding = field(default_factory=Branding) + + @property + def redirect_uri(self) -> str: + return f"{self.origin}/auth/callback" + + @property + def secure_cookies(self) -> bool: + return self.origin.startswith("https://") + + @property + def token_url(self) -> str: + return f"{self.authority}/{self.tenant_id}/oauth2/v2.0/token" + + +def _guid(env: dict[str, str], name: str) -> str: + value = env.get(name, "").strip().lower() + if not _GUID.match(value): + raise ConfigError(f"{name} must be a GUID") + return value + + +def _origin(value: str, name: str) -> str: + parts = urlsplit(value.strip()) + host = (parts.hostname or "").lower() + if parts.path not in ("", "/") or parts.query or parts.fragment or parts.username or not host: + raise ConfigError(f"{name} must be scheme://host[:port], with no path") + if parts.scheme != "https" and not (parts.scheme == "http" and host in _LOOPBACK): + raise ConfigError(f"{name} must be https (plain http only on a loopback address)") + return f"{parts.scheme}://{parts.netloc.lower()}" + + +def _authority(value: str) -> str: + parts = urlsplit(value.strip() or "https://login.microsoftonline.com") + if parts.scheme != "https" or not _HOST.match((parts.hostname or "").lower()) or parts.path not in ("", "/"): + raise ConfigError("AZURE_AUTHORITY_HOST must be an https host, such as https://login.microsoftonline.com") + return f"https://{parts.netloc.lower()}" + + +def _secret(env: dict[str, str], name: str) -> str: + """NAME, or the contents of the file NAME_FILE points at.""" + value = env.get(name, "") + if not value and env.get(f"{name}_FILE"): + try: + value = Path(env[f"{name}_FILE"]).read_text().strip() + except OSError as err: + raise ConfigError(f"cannot read {name}_FILE: {err.__class__.__name__}") from err + return value + + +def read_catalog(path: str) -> Catalog: + try: + text = Path(path).read_text() + except OSError as err: + raise ConfigError(f"cannot read the catalog {path}: {err.__class__.__name__}") from err + try: + return load_catalog(text, Path(path).name) + except CatalogError as err: + raise ConfigError(f"the catalog does not hold together: {err}") from err + + +def load_config(env: dict[str, str] | None = None) -> Config: + env = dict(os.environ if env is None else env) + + token_file = env.get("AZURE_FEDERATED_TOKEN_FILE", "").strip() + secret = _secret(env, "AZURE_CLIENT_SECRET") + if not token_file and not secret: + raise ConfigError("set AZURE_FEDERATED_TOKEN_FILE (workload identity), AZURE_CLIENT_SECRET or AZURE_CLIENT_SECRET_FILE") + + session_key = _secret(env, "DATABASES_UI_SESSION_KEY") + if len(session_key) < 32: + raise ConfigError("DATABASES_UI_SESSION_KEY (or DATABASES_UI_SESSION_KEY_FILE) must hold at least 32 characters") + + if not env.get("DATABASES_UI_CATALOG", "").strip(): + raise ConfigError("DATABASES_UI_CATALOG is required: the path of the catalog file") + catalog = read_catalog(env["DATABASES_UI_CATALOG"].strip()) + + job_image = env.get("DATABASES_UI_JOB_IMAGE", "").strip() + if not job_image or any(c.isspace() for c in job_image): + raise ConfigError("DATABASES_UI_JOB_IMAGE is required: the image the Jobs run, this app's own") + job_sa = env.get("DATABASES_UI_JOB_SERVICE_ACCOUNT", "databases-ui-job").strip() + if not _K8S_NAME.match(job_sa): + raise ConfigError("DATABASES_UI_JOB_SERVICE_ACCOUNT must be a service account name") + + sas = _secret(env, "DATABASES_UI_STORAGE_SAS").strip().lstrip("?") + sas_secret = env.get("DATABASES_UI_STORAGE_SAS_SECRET", "").strip() + if bool(sas) != bool(sas_secret): + raise ConfigError("a storage SAS needs both DATABASES_UI_STORAGE_SAS (or _FILE) and DATABASES_UI_STORAGE_SAS_SECRET (/ for the Jobs)") + if sas_secret and not _SECRET_REF.match(sas_secret): + raise ConfigError("DATABASES_UI_STORAGE_SAS_SECRET is /") + if sas and "sig=" not in sas: + raise ConfigError("DATABASES_UI_STORAGE_SAS is a SAS token: sv=…&sig=…") + if not sas and not token_file and any(e.runs_jobs for e in catalog.environments.values()): + # A Job can't use the client secret: workload identity is how it reaches storage. + raise ConfigError("the Jobs reach storage through workload identity (AZURE_FEDERATED_TOKEN_FILE) or a SAS (DATABASES_UI_STORAGE_SAS)") + + roles = {} + for key, default in (("admin", "Admin"), ("auditor", "Auditor")): + name = f"DATABASES_UI_{key.upper()}_ROLE" + roles[f"{key}_role"] = env.get(name, default).strip() + if not _ROLE.match(roles[f"{key}_role"]): + raise ConfigError(f"{name} must be an app role value, such as {default}") + + try: + hours = int(env.get("DATABASES_UI_SESSION_HOURS", "8")) + port = int(env.get("PORT", "8080")) + except ValueError as err: + raise ConfigError("DATABASES_UI_SESSION_HOURS and PORT must be whole numbers") from err + if not 1 <= hours <= 24: + raise ConfigError("DATABASES_UI_SESSION_HOURS must be between 1 and 24") + + if "DATABASES_UI_PUBLIC_ORIGIN" not in env: + raise ConfigError("DATABASES_UI_PUBLIC_ORIGIN is required, such as https://databases.example.com") + static = env.get("DATABASES_UI_STATIC_DIR", "/app/static") + + colours = {} + for key in ("accent", "accent_text", "accent_dark", "accent_text_dark"): + name = f"DATABASES_UI_BRAND_{key.upper()}" + colours[key] = env.get(name, "").strip().lower() + if colours[key] and not _COLOUR.match(colours[key]): + raise ConfigError(f"{name} must be a colour as #rrggbb, such as #0f766e") + + return Config( + tenant_id=_guid(env, "AZURE_TENANT_ID"), + client_id=_guid(env, "AZURE_CLIENT_ID"), + authority=_authority(env.get("AZURE_AUTHORITY_HOST", "")), + federated_token_file=Path(token_file) if token_file else None, + client_secret=secret or None, + origin=_origin(env["DATABASES_UI_PUBLIC_ORIGIN"], "DATABASES_UI_PUBLIC_ORIGIN"), + session_key=session_key.encode(), + session_seconds=hours * 3600, + catalog=catalog, + job_image=job_image, + job_service_account=job_sa, + storage_sas=sas, + storage_sas_secret=sas_secret, + static_dir=Path(static) if static and Path(static).is_dir() else None, + port=port, + version=env.get("APP_VERSION", "dev"), + branding=Branding(**colours), + **roles, + ) diff --git a/src/databases_ui/entra.py b/src/databases_ui/entra.py new file mode 100644 index 0000000..b5acfb4 --- /dev/null +++ b/src/databases_ui/entra.py @@ -0,0 +1,107 @@ +"""Signing in with Entra ID, as a confidential client (the flow itself is in oidc.py), and the +app's own token for Azure Storage. + +The credential is a workload identity token (AZURE_FEDERATED_TOKEN_FILE, which Entra trusts +through a federated credential on the app registration) or a client secret. The sign-in asks +only who the person is: their app roles (Admin, Auditor) and their groups come in the ID token. +""" + +from __future__ import annotations + +import asyncio +import time +from collections.abc import Callable +from typing import Any + +import httpx + +from .config import Config +from .oidc import OIDC, SignIn, SignInError + +_ASSERTION_TYPE = "urn:ietf:params:oauth:client-assertion-type:jwt-bearer" +STORAGE_SCOPE = "https://storage.azure.com/.default" + + +def federated_credential(token_file: str) -> dict[str, str]: + try: + # The kubelet rotates the projected token in place. + with open(token_file) as f: + assertion = f.read().strip() + except OSError as err: + raise SignInError(f"cannot read the workload identity token: {err.__class__.__name__}", status=500) from err + return {"client_assertion_type": _ASSERTION_TYPE, "client_assertion": assertion} + + +def app_credential(cfg: Config) -> dict[str, str]: + """The app's credential on Entra ID's token endpoint, read fresh each time.""" + if cfg.federated_token_file is None: + return {"client_secret": cfg.client_secret or ""} + return federated_credential(str(cfg.federated_token_file)) + + +class AppToken: + """The app's own access token for one scope, kept until shortly before it expires.""" + + def __init__(self, http: httpx.AsyncClient, *, token_url: str, client_id: str, credential: Callable[[], dict[str, str]], scope: str = STORAGE_SCOPE): + self._http = http + self._url = token_url + self._client_id = client_id + self._credential = credential + self._scope = scope + self._token = "" + self._expires = 0.0 + self._lock = asyncio.Lock() + + async def __call__(self) -> str: + async with self._lock: + if self._token and self._expires - 120 > time.time(): + return self._token + data = {"grant_type": "client_credentials", "client_id": self._client_id, "scope": self._scope, **self._credential()} + try: + response = await self._http.post(self._url, data=data, headers={"Accept": "application/json"}, timeout=15) + body = response.json() + except (httpx.HTTPError, ValueError) as err: + raise SignInError(f"cannot get the app's storage token: {err.__class__.__name__}") from err + if response.status_code != 200 or not isinstance(body, dict) or not body.get("access_token"): + reason = str(body.get("error_description") or body.get("error") or response.status_code) if isinstance(body, dict) else response.status_code + raise SignInError(f"Entra ID refused the app's storage token: {str(reason).splitlines()[0][:300]}") + self._token = str(body["access_token"]) + self._expires = time.time() + int(body.get("expires_in") or 3600) + return self._token + + +class Entra(OIDC): + name = "Microsoft" + + def __init__(self, cfg: Config, http: httpx.AsyncClient): + base = f"{cfg.authority}/{cfg.tenant_id}" + super().__init__( + http, + client_id=cfg.client_id, + redirect_uri=cfg.redirect_uri, + scope="openid profile", + endpoints={"authorize": f"{base}/oauth2/v2.0/authorize", "token": f"{base}/oauth2/v2.0/token", "jwks": f"{base}/discovery/v2.0/keys"}, + issuers=(f"{base}/v2.0",), + ) + self._cfg = cfg + + def _credential(self) -> dict[str, str]: + return app_credential(self._cfg) + + def _check_claims(self, claims: dict[str, Any]) -> None: + if str(claims.get("tid", "")).lower() != self._cfg.tenant_id or not claims.get("oid"): + raise SignInError("that account belongs to another tenant", status=401) + # Over 200 groups, Entra leaves them out and points at Graph instead. + if "groups" in (claims.get("_claim_names") or {}) or claims.get("hasgroups"): + raise SignInError("your groups do not fit in the ID token; the app registration should emit only the groups assigned to the application", status=401) + + async def _sign_in(self, body: dict[str, Any], claims: dict[str, Any]) -> SignIn: + named = self._cfg.catalog.groups + return SignIn( + oid=str(claims["oid"]).lower(), + upn=str(claims.get("preferred_username") or claims.get("upn") or claims["oid"]).lower()[:120], + name=str(claims.get("name") or "")[:120], + roles=[r for r in claims.get("roles") or [] if isinstance(r, str)], + # Only the groups the catalog names, so the session cookie stays small. + groups=sorted({g.lower() for g in claims.get("groups") or [] if isinstance(g, str)} & named), + ) diff --git a/src/databases_ui/jobs.py b/src/databases_ui/jobs.py new file mode 100644 index 0000000..650e6ba --- /dev/null +++ b/src/databases_ui/jobs.py @@ -0,0 +1,188 @@ +"""The Kubernetes Jobs that do the work, and what their state means. + +Every action is a Job in the environment's namespace, running this app's own image as +`python -m databases_ui job` (runner.py). Its pod connects as the database's owner role with the +password from that managed role's Secret, mounted by the kubelet: neither this server nor its +Kubernetes role ever reads a password. A restore that needs a second person is created +suspended; approving it lets it start, and a Job's pod template can't change after creation, so +what runs is exactly what was asked for. +""" + +from __future__ import annotations + +import json +import secrets +from dataclasses import dataclass +from typing import Any + +from .catalog import Environment +from .config import Config + +PREFIX = "databases-ui/" +MANAGED_BY = "app.kubernetes.io/managed-by" +APP = "databases-ui" +TOKEN_DIR = "/var/run/secrets/azure/tokens" +DEADLINE_SECONDS = 6 * 3600 +KEEP_SECONDS = 7 * 86400 + + +@dataclass(frozen=True) +class Target: + """A database as its owner role reaches it.""" + + environment: str + database: str + owner: str + password_secret: str + ca_secret: str + host: str + + +def name_for(action: str) -> str: + return f"dbui-{action}-{secrets.token_hex(4)}" + + +def selector(env: str, database: str = "") -> str: + return f"{MANAGED_BY}={APP},{PREFIX}environment={env}" + (f",{PREFIX}database={database}" if database else "") + + +def _storage_env(cfg: Config) -> list[dict[str, Any]]: + if cfg.storage_sas_secret: + secret, key = cfg.storage_sas_secret.split("/", 1) + return [{"name": "DBUI_STORAGE_SAS", "valueFrom": {"secretKeyRef": {"name": secret, "key": key}}}] + return [ + {"name": "AZURE_TENANT_ID", "value": cfg.tenant_id}, + {"name": "AZURE_CLIENT_ID", "value": cfg.client_id}, + {"name": "AZURE_AUTHORITY_HOST", "value": cfg.authority}, + {"name": "AZURE_FEDERATED_TOKEN_FILE", "value": f"{TOKEN_DIR}/azure-identity-token"}, + ] + + +def build( + cfg: Config, + env: Environment, + *, + name: str, + action: str, + target: Target, + database: str, + blob_url: str, + blob: str, + requested_by: str, + annotations: dict[str, str], + suspend: bool = False, + metadata: dict[str, str] | None = None, + workloads: tuple[tuple[str, str, str], ...] = (), + wait_for_database: bool = False, +) -> dict[str, Any]: + """The Job for one action. `database` is the catalog's name, `target.database` the one written to.""" + labels = {MANAGED_BY: APP, f"{PREFIX}environment": env.name, f"{PREFIX}database": database, f"{PREFIX}action": action} + variables: list[dict[str, Any]] = [ + {"name": "DBUI_ACTION", "value": action}, + {"name": "DBUI_JOB", "value": name}, + {"name": "DBUI_ENVIRONMENT", "value": env.name}, + {"name": "DBUI_DATABASE", "value": database}, + {"name": "DBUI_REQUESTED_BY", "value": requested_by}, + {"name": "DBUI_BLOB_URL", "value": blob_url}, + {"name": "DBUI_BLOB", "value": blob}, + {"name": "DBUI_AUDIT_URL", "value": env.storage.url}, + {"name": "PGHOST", "value": target.host}, + {"name": "PGPORT", "value": "5432"}, + {"name": "PGDATABASE", "value": target.database}, + {"name": "PGUSER", "value": target.owner}, + {"name": "PGPASSWORD", "valueFrom": {"secretKeyRef": {"name": target.password_secret, "key": "password"}}}, + {"name": "PGSSLMODE", "value": "verify-full"}, + {"name": "PGSSLROOTCERT", "value": "/etc/databases-ui/ca/ca.crt"}, + {"name": "PGAPPNAME", "value": "databases-ui"}, + {"name": "PGCONNECT_TIMEOUT", "value": "15"}, + {"name": "HOME", "value": "/tmp"}, + *_storage_env(cfg), + ] + if metadata: + variables.append({"name": "DBUI_METADATA", "value": json.dumps(metadata)}) + if workloads: + variables.append({"name": "DBUI_SCALE", "value": json.dumps([list(w) for w in workloads])}) + if wait_for_database: + variables.append({"name": "DBUI_WAIT_FOR_DATABASE", "value": "1"}) + volumes: list[dict[str, Any]] = [ + {"name": "tmp", "emptyDir": {"sizeLimit": "64Mi"}}, + # The server's CA certificate only: the Secret also holds the CA's key. + {"name": "ca", "secret": {"secretName": target.ca_secret, "defaultMode": 0o440, "items": [{"key": "ca.crt", "path": "ca.crt"}]}}, + ] + mounts = [{"name": "tmp", "mountPath": "/tmp"}, {"name": "ca", "mountPath": "/etc/databases-ui/ca", "readOnly": True}] + if not cfg.storage_sas_secret: + volumes.append( + { + "name": "azure-identity-token", + "projected": {"defaultMode": 0o440, "sources": [{"serviceAccountToken": {"path": "azure-identity-token", "audience": "api://AzureADTokenExchange", "expirationSeconds": 3600}}]}, + } + ) + mounts.append({"name": "azure-identity-token", "mountPath": TOKEN_DIR, "readOnly": True}) + return { + "apiVersion": "batch/v1", + "kind": "Job", + "metadata": {"name": name, "namespace": env.namespace, "labels": labels, "annotations": {f"{PREFIX}{k}": v for k, v in annotations.items() if v}}, + "spec": { + "suspend": suspend, + "backoffLimit": 0, + "activeDeadlineSeconds": DEADLINE_SECONDS, + "ttlSecondsAfterFinished": KEEP_SECONDS, + "template": { + "metadata": {"labels": {**labels, "app.kubernetes.io/name": APP, "app.kubernetes.io/component": "job"}}, + "spec": { + "restartPolicy": "Never", + "serviceAccountName": cfg.job_service_account, + # Only a restore in place talks to the Kubernetes API, to scale the workloads. + "automountServiceAccountToken": bool(workloads), + "securityContext": {"runAsNonRoot": True, "runAsUser": 10001, "runAsGroup": 10001, "fsGroup": 10001, "seccompProfile": {"type": "RuntimeDefault"}}, + "containers": [ + { + "name": "job", + "image": cfg.job_image, + "imagePullPolicy": "IfNotPresent", + "args": ["job"], + "env": variables, + "securityContext": {"allowPrivilegeEscalation": False, "readOnlyRootFilesystem": True, "capabilities": {"drop": ["ALL"]}}, + "resources": {"requests": {"cpu": "100m", "memory": "256Mi"}, "limits": {"memory": "1Gi"}}, + "terminationMessagePolicy": "FallbackToLogsOnError", + "volumeMounts": mounts, + } + ], + "volumes": volumes, + }, + }, + }, + } + + +def state(job: dict[str, Any]) -> str: + """waiting (for approval), starting, running, succeeded or failed.""" + status = job.get("status") or {} + conditions = {c.get("type"): c.get("status") for c in status.get("conditions") or []} + if conditions.get("Complete") == "True" or conditions.get("SuccessCriteriaMet") == "True": + return "succeeded" + if conditions.get("Failed") == "True" or conditions.get("FailureTarget") == "True": + return "failed" + if (job.get("spec") or {}).get("suspend"): + return "waiting" + return "running" if status.get("active") else "starting" + + +def result(pod: dict[str, Any] | None) -> dict[str, Any]: + """What the pod reported in its termination message, or the reason it never ran.""" + if pod is None: + return {} + for c in (pod.get("status") or {}).get("containerStatuses") or []: + terminated = (c.get("state") or {}).get("terminated") + if terminated: + try: + found = json.loads(terminated.get("message") or "") + if isinstance(found, dict): + return found + except ValueError: + pass + return {"reason": (terminated.get("message") or terminated.get("reason") or "").strip()[-1000:]} + waiting = (c.get("state") or {}).get("waiting") + if waiting and waiting.get("reason") not in (None, "ContainerCreating", "PodInitializing"): + return {"reason": f"{waiting.get('reason')}: {waiting.get('message', '')}".strip(": ")[:500]} + return {} diff --git a/src/databases_ui/kube.py b/src/databases_ui/kube.py new file mode 100644 index 0000000..ed450d8 --- /dev/null +++ b/src/databases_ui/kube.py @@ -0,0 +1,91 @@ +"""A small Kubernetes API client: the handful of calls this app and its Jobs make, over httpx. + +In a pod it uses the pod's service-account token and CA; for another cluster, the server, CA file +and token file from the catalog. The token is read from its file on every call, because the +kubelet rotates a projected token in place. +""" + +from __future__ import annotations + +import os +import ssl +from pathlib import Path +from typing import Any + +import httpx + +IN_CLUSTER = Path("/var/run/secrets/kubernetes.io/serviceaccount") +CNPG = "/apis/postgresql.cnpg.io/v1" + + +class KubeError(Exception): + def __init__(self, status: int, message: str): + super().__init__(message) + self.status = status + + +class Kube: + def __init__(self, *, server: str, token_file: str, ca_file: str | None = None, transport: httpx.AsyncBaseTransport | None = None): + verify: ssl.SSLContext | bool = True + if transport is None and ca_file and Path(ca_file).exists(): + verify = ssl.create_default_context(cafile=ca_file) + self._http = httpx.AsyncClient(base_url=server.rstrip("/"), verify=verify, transport=transport, timeout=20, follow_redirects=False) + self._token_file = Path(token_file) + + @classmethod + def in_cluster(cls, transport: httpx.AsyncBaseTransport | None = None) -> Kube: + host, port = os.environ.get("KUBERNETES_SERVICE_HOST", "kubernetes.default.svc"), os.environ.get("KUBERNETES_SERVICE_PORT", "443") + host = f"[{host}]" if ":" in host else host + return cls(server=f"https://{host}:{port}", token_file=str(IN_CLUSTER / "token"), ca_file=str(IN_CLUSTER / "ca.crt"), transport=transport) + + def _headers(self, content_type: str | None) -> dict[str, str]: + headers = {"Accept": "application/json"} + if content_type: + headers["Content-Type"] = content_type + try: + headers["Authorization"] = f"Bearer {self._token_file.read_text().strip()}" + except OSError: + pass # no token: the API server says so (401), which names the problem better than this could + return headers + + async def request(self, method: str, path: str, *, params: dict[str, str] | None = None, body: Any = None, content_type: str | None = None) -> Any: + try: + response = await self._http.request(method, path, params=params, json=body, headers=self._headers(content_type if body is not None else None)) + except httpx.HTTPError as err: + raise KubeError(502, f"cannot reach the Kubernetes API: {err.__class__.__name__}") from err + if response.status_code >= 400: + try: + message = str(response.json().get("message") or response.status_code) + except ValueError: + message = f"HTTP {response.status_code}" + raise KubeError(response.status_code, message[:500]) + return response.json() if response.content else None + + async def get(self, path: str) -> dict[str, Any] | None: + try: + return await self.request("GET", path) + except KubeError as err: + if err.status == 404: + return None + raise + + async def list(self, path: str, selector: str = "") -> list[dict[str, Any]]: + found = await self.request("GET", path, params={"labelSelector": selector} if selector else None) + return list((found or {}).get("items") or []) + + async def create(self, path: str, body: dict[str, Any]) -> dict[str, Any]: + return await self.request("POST", path, body=body, content_type="application/json") + + async def patch(self, path: str, body: dict[str, Any]) -> dict[str, Any]: + return await self.request("PATCH", path, body=body, content_type="application/merge-patch+json") + + async def delete(self, path: str) -> None: + try: + # Background: the Job's pods go with it. + await self.request("DELETE", path, params={"propagationPolicy": "Background"}) + except KubeError as err: + if err.status != 404: + raise + + async def aclose(self) -> None: + await self._http.aclose() diff --git a/src/databases_ui/oidc.py b/src/databases_ui/oidc.py new file mode 100644 index 0000000..3369cff --- /dev/null +++ b/src/databases_ui/oidc.py @@ -0,0 +1,167 @@ +"""Signing in with OpenID Connect: authorization code flow with PKCE, as a confidential client. + +What differs between identity providers lives in a subclass: the endpoints, the app's own +credential, which claims have to hold, and where a person's roles and groups come from. Entra ID +is in entra.py. Signing in needs only the ID token. + +The ID token is verified against the provider's published keys although it arrives straight +from the token endpoint over TLS (OIDC Core 3.1.3.7 would allow skipping that): issuer, +audience, expiry and nonce, plus the subclass's own claims, all have to hold. +""" + +from __future__ import annotations + +import base64 +import hashlib +import hmac +import time +from dataclasses import dataclass +from typing import Any +from urllib.parse import urlencode + +import httpx +import jwt + +_JWKS_TTL = 3600.0 +_JWKS_COOLDOWN = 30.0 + + +class SignInError(Exception): + def __init__(self, message: str, *, status: int = 502): + super().__init__(message) + self.status = status + + +@dataclass(frozen=True) +class SignIn: + oid: str + upn: str + name: str + roles: list[str] + groups: list[str] + + +def pkce_challenge(verifier: str) -> str: + return base64.urlsafe_b64encode(hashlib.sha256(verifier.encode()).digest()).rstrip(b"=").decode() + + +def _reason(body: Any) -> str: + """The provider's own reason, trimmed to the line a person can search for (AADSTS…).""" + if not isinstance(body, dict): + return "unknown error" + return str(body.get("error_description") or body.get("error") or "unknown error").splitlines()[0][:300] + + +class OIDC: + # Who people sign in with, for messages and the sign-in button: "Microsoft". + name = "" + + def __init__(self, http: httpx.AsyncClient, *, client_id: str, redirect_uri: str, scope: str, endpoints: dict[str, str], issuers: tuple[str, ...]): + self._http = http + self.client_id = client_id + self._redirect_uri = redirect_uri + self._scope = scope + self._authorize = endpoints["authorize"] + self._token = endpoints["token"] + self._jwks_url = endpoints["jwks"] + self._issuers = issuers + self._keys: dict[str, jwt.PyJWK] = {} + self._keys_at = float("-inf") + + def _authorize_extra(self) -> dict[str, str]: + return {} + + def _credential(self) -> dict[str, str]: + """The app's own credential on the token endpoint.""" + raise NotImplementedError + + def _check_claims(self, claims: dict[str, Any]) -> None: + """Claims of a verified ID token that also have to hold; raise SignInError if not.""" + + async def _sign_in(self, body: dict[str, Any], claims: dict[str, Any]) -> SignIn: + """The signed-in person, from a redeemed code's tokens and its verified ID token's claims.""" + raise NotImplementedError + + def authorize_url(self, *, state: str, nonce: str, verifier: str) -> str: + query = { + "client_id": self.client_id, + "response_type": "code", + "response_mode": "query", + "redirect_uri": self._redirect_uri, + "scope": self._scope, + "state": state, + "nonce": nonce, + "code_challenge": pkce_challenge(verifier), + "code_challenge_method": "S256", + **self._authorize_extra(), + } + return f"{self._authorize}?{urlencode(query)}" + + async def _redeem(self, fields: dict[str, str]) -> dict[str, Any]: + data = {**fields, "client_id": self.client_id, **self._credential()} + try: + response = await self._http.post(self._token, data=data, headers={"Accept": "application/json"}, timeout=15) + except httpx.HTTPError as err: + raise SignInError(f"cannot reach {self.name} sign-in: {err.__class__.__name__}") from err + try: + body = response.json() + except ValueError as err: + raise SignInError(f"{self.name} sign-in answered HTTP {response.status_code} without JSON") from err + if response.status_code != 200 or not isinstance(body, dict): + grant = isinstance(body, dict) and body.get("error") in ("invalid_grant", "interaction_required") + raise SignInError(f"{self.name} refused the sign-in: {_reason(body)}", status=401 if grant else 502) + return body + + async def redeem_code(self, *, code: str, verifier: str, nonce: str) -> SignIn: + body = await self._redeem( + { + "grant_type": "authorization_code", + "code": code, + "redirect_uri": self._redirect_uri, + "code_verifier": verifier, + "scope": self._scope, + } + ) + claims = await self.verify_id_token(str(body.get("id_token") or ""), nonce=nonce) + return await self._sign_in(body, claims) + + async def _signing_key(self, kid: str) -> jwt.PyJWK: + now = time.monotonic() + stale = now - self._keys_at > _JWKS_TTL + unknown = kid not in self._keys and now - self._keys_at > _JWKS_COOLDOWN + if stale or unknown: + try: + response = await self._http.get(self._jwks_url, timeout=15) + response.raise_for_status() + keys = {} + for data in response.json().get("keys", []): + try: + keys[str(data.get("kid"))] = jwt.PyJWK(data) + except jwt.PyJWKError: + continue + self._keys, self._keys_at = keys, now + except (httpx.HTTPError, ValueError, AttributeError) as err: + raise SignInError(f"cannot read {self.name}'s signing keys: {err.__class__.__name__}") from err + if kid not in self._keys: + raise SignInError(f"the ID token is signed with a key {self.name} does not publish", status=401) + return self._keys[kid] + + async def verify_id_token(self, id_token: str, *, nonce: str) -> dict[str, Any]: + try: + kid = str(jwt.get_unverified_header(id_token).get("kid") or "") + key = await self._signing_key(kid) + claims = jwt.decode( + id_token, + key=key, + algorithms=["RS256"], + audience=self.client_id, + issuer=self._issuers, + leeway=60, + options={"require": ["exp", "iat", "iss", "aud", "nonce"]}, + ) + except jwt.PyJWTError as err: + raise SignInError(f"the ID token did not verify: {err.__class__.__name__}", status=401) from err + if not hmac.compare_digest(str(claims.get("nonce")).encode(), nonce.encode()): + raise SignInError("the ID token belongs to another sign-in", status=401) + self._check_claims(claims) + return claims diff --git a/src/databases_ui/runner.py b/src/databases_ui/runner.py new file mode 100644 index 0000000..4a63958 --- /dev/null +++ b/src/databases_ui/runner.py @@ -0,0 +1,228 @@ +"""What a Job's pod does: `python -m databases_ui job`, configured by the variables the server put +in the Job (jobs.py). + +snapshot pg_dump in the custom format, streamed into a block blob that is committed, with who + asked and why as its metadata, only once pg_dump has succeeded. +restore the snapshot streamed into pg_restore in one transaction, so on any error nothing + changes. In place, the workloads that use the database go to 0 replicas first and back + to what they had afterwards; for a copy, it first waits for the database to exist. + +Nothing goes through `kubectl exec` or a disk. The outcome goes to the pod's termination +message, which the server shows, and to the environment's audit log. +""" + +from __future__ import annotations + +import asyncio +import json +import logging +import os +import subprocess # nosec B404 - runs pg_dump, pg_restore and psql with fixed arguments, no shell +import time +from collections.abc import AsyncIterator, Mapping +from pathlib import Path +from typing import Any + +import httpx + +from . import audit +from .blob import BlobError, Container +from .entra import AppToken, federated_credential +from .kube import Kube, KubeError +from .oidc import SignInError + +log = logging.getLogger("databases_ui") +TERMINATION_LOG = Path("/dev/termination-log") +SCALED = "databases-ui/replicas-before-restore" +READ = 1024 * 1024 +WAIT_SECONDS = 300 +REACH_SECONDS = 60 + + +class JobFailed(Exception): + pass + + +def _say(msg: str, **fields: Any) -> None: + log.info(json.dumps({"msg": msg, **fields})) + + +def _tail(text: bytes) -> str: + lines = [line for line in text.decode(errors="replace").splitlines() if line.strip()] + return " | ".join(lines[-6:])[-900:] + + +async def _exec(*args: str, stdin: int | None = None) -> asyncio.subprocess.Process: + # The arguments are fixed here; the connection comes from the PG* variables. + return await asyncio.create_subprocess_exec(*args, stdin=stdin, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + + +async def psql(sql: str) -> str: + proc = await _exec("psql", "--no-password", "--no-psqlrc", "-v", "ON_ERROR_STOP=1", "-Atqc", sql) + out, err = await proc.communicate() + if proc.returncode != 0: + raise JobFailed(f"psql: {_tail(err)}") + return out.decode().strip() + + +def _container(env: Mapping[str, str], url: str, http: httpx.AsyncClient) -> Container: + if env.get("DBUI_STORAGE_SAS"): + return Container(http, url, sas=env["DBUI_STORAGE_SAS"]) + authority = env.get("AZURE_AUTHORITY_HOST", "https://login.microsoftonline.com").rstrip("/") + token = AppToken( + http, + token_url=f"{authority}/{env['AZURE_TENANT_ID']}/oauth2/v2.0/token", + client_id=env["AZURE_CLIENT_ID"], + credential=lambda: federated_credential(env["AZURE_FEDERATED_TOKEN_FILE"]), + ) + return Container(http, url, token=token) + + +async def snapshot(env: Mapping[str, str], container: Container) -> dict[str, Any]: + await wait_for_database(REACH_SECONDS) + proc = await _exec("pg_dump", "--format=custom", "--no-password", "--exclude-extension=*") + stdout, stderr = proc.stdout, proc.stderr + if stdout is None or stderr is None: + raise JobFailed("pg_dump started without its pipes") + errors = asyncio.create_task(stderr.read()) + + async def chunks() -> AsyncIterator[bytes]: + while data := await stdout.read(READ): + yield data + + async def finished() -> None: + if await proc.wait() != 0: + raise JobFailed(f"pg_dump exited {proc.returncode}: {_tail(await errors)}") + + metadata = json.loads(env.get("DBUI_METADATA") or "{}") + try: + size, digest = await container.upload(env["DBUI_BLOB"], chunks(), metadata, before_commit=finished) + finally: + if proc.returncode is None: + proc.kill() + await proc.wait() + return {"bytes": size, "sha256": digest} + + +async def wait_for_database(seconds: float) -> None: + """Until the database answers: a new pod's network rules, a failover or a new copy take a moment.""" + deadline = time.monotonic() + seconds + while True: + try: + await psql("select 1") + return + except JobFailed as err: + if time.monotonic() > deadline: + raise JobFailed(f"the database never became reachable: {err}") from err + await asyncio.sleep(3) + + +async def scale_down(kube: Kube, workloads: list[list[str]], scaled: list[tuple[str, int]]) -> None: + """Each workload to 0, its count kept in an annotation and in `scaled` as it goes, so a failure + halfway still scales back what was scaled; then wait for its pods to go.""" + pods: list[tuple[str, str]] = [] + for kind, namespace, name in workloads: + path = f"/apis/apps/v1/namespaces/{namespace}/{kind}s/{name}" + found = await kube.get(path) + if found is None: + _say("workload not found, left alone", workload=f"{kind}/{namespace}/{name}") + continue + # A restore that died before scaling back left the real count here. + kept = ((found.get("metadata") or {}).get("annotations") or {}).get(SCALED) + replicas = int(kept) if kept and kept.isdigit() else int((found.get("spec") or {}).get("replicas", 1)) + await kube.patch(path, {"metadata": {"annotations": {SCALED: str(replicas)}}, "spec": {"replicas": 0}}) + scaled.append((path, replicas)) + labels = ((found.get("spec") or {}).get("selector") or {}).get("matchLabels") or {} + pods.append((f"/api/v1/namespaces/{namespace}/pods", ",".join(f"{k}={v}" for k, v in sorted(labels.items())))) + _say("scaled down", workload=f"{kind}/{namespace}/{name}", replicas=replicas) + deadline = time.monotonic() + WAIT_SECONDS + for path, labels in pods: + while labels and await kube.list(path, labels): + if time.monotonic() > deadline: + raise JobFailed(f"pods matching {labels} were still running after {WAIT_SECONDS}s") + await asyncio.sleep(3) + + +async def scale_up(kube: Kube, scaled: list[tuple[str, int]]) -> None: + for path, replicas in scaled: + try: + await kube.patch(path, {"metadata": {"annotations": {SCALED: None}}, "spec": {"replicas": replicas}}) + _say("scaled back", workload=path, replicas=replicas) + except KubeError as err: + _say("could not scale back", workload=path, replicas=replicas, reason=str(err)) + + +async def restore(env: Mapping[str, str], container: Container, kube: Kube | None) -> dict[str, Any]: + await wait_for_database(WAIT_SECONDS if env.get("DBUI_WAIT_FOR_DATABASE") else REACH_SECONDS) + scaled: list[tuple[str, int]] = [] + try: + if kube is not None: + await scale_down(kube, json.loads(env["DBUI_SCALE"]), scaled) + ended = await psql("select count(pg_terminate_backend(pid)) from pg_stat_activity where datname = current_database() and pid <> pg_backend_pid() and usename = current_user") + _say("sessions ended", count=ended) + async with container.download(env["DBUI_BLOB"]) as (size, chunks): + proc = await _exec( + "pg_restore", "--format=custom", "--clean", "--if-exists", "--no-owner", "--no-acl", "--single-transaction", "--no-password", + f"--dbname={env['PGDATABASE']}", stdin=subprocess.PIPE, + ) # fmt: skip + stdin, stderr = proc.stdin, proc.stderr + if stdin is None or stderr is None: + raise JobFailed("pg_restore started without its pipes") + errors = asyncio.create_task(stderr.read()) + fed = 0 + try: + async for chunk in chunks: + stdin.write(chunk) + await stdin.drain() + fed += len(chunk) + stdin.close() + except (BrokenPipeError, ConnectionResetError): + pass # pg_restore stopped reading; its exit status says why + if await proc.wait() != 0: + raise JobFailed(f"pg_restore exited {proc.returncode}, nothing changed: {_tail(await errors)}") + if fed != size: + raise JobFailed(f"read {fed} of {size} bytes of the snapshot") + finally: + if kube is not None: + await scale_up(kube, scaled) + return {"bytes": size} + + +async def run(env: Mapping[str, str], *, transport: httpx.AsyncBaseTransport | None = None, kube_transport: httpx.AsyncBaseTransport | None = None) -> int: + action = env.get("DBUI_ACTION", "") + started = time.monotonic() + async with httpx.AsyncClient(transport=transport, follow_redirects=False) as http: + try: + source = _container(env, env.get("DBUI_BLOB_URL", ""), http) + if action == "snapshot": + outcome = {"result": "succeeded", **await snapshot(env, source)} + elif action == "restore": + kube = Kube.in_cluster(transport=kube_transport) if env.get("DBUI_SCALE") else None + try: + outcome = {"result": "succeeded", **await restore(env, source, kube)} + finally: + if kube is not None: + await kube.aclose() + else: + raise JobFailed(f"unknown action {action!r}") + except (JobFailed, BlobError, KubeError, SignInError, KeyError, ValueError, OSError) as err: + outcome = {"result": "failed", "reason": str(err)[:1500] or err.__class__.__name__} + outcome["seconds"] = round(time.monotonic() - started) + try: + # The environment's own container, which for a clone is not the snapshot's. + await audit.record( + _container(env, env["DBUI_AUDIT_URL"], http), environment=env.get("DBUI_ENVIRONMENT", ""), actor=env.get("DBUI_REQUESTED_BY", ""), action=f"{action}.{outcome['result']}", + database=env.get("DBUI_DATABASE", ""), job=env.get("DBUI_JOB", ""), snapshot=env.get("DBUI_BLOB", ""), detail=outcome.get("reason", ""), + ) # fmt: skip + except (SignInError, KeyError) as err: + _say("audit write failed", reason=str(err)) + _say("finished", action=action, **outcome) + try: + TERMINATION_LOG.write_text(json.dumps(outcome)[:4000]) + except OSError: + pass # outside a pod + return 0 if outcome["result"] == "succeeded" else 1 + + +def main() -> int: + return asyncio.run(run(dict(os.environ))) diff --git a/src/databases_ui/service.py b/src/databases_ui/service.py new file mode 100644 index 0000000..5731658 --- /dev/null +++ b/src/databases_ui/service.py @@ -0,0 +1,393 @@ +"""What people may do, and doing it: an environment's databases, their snapshots, and the Jobs +that take, restore and clone them. + +Who acts on which database comes from the catalog's teams and the person's groups, checked here +on every call; the browser only shows what this server decided. App role Admin acts on every +database, Auditor reads everything and changes nothing. In a production environment a restore +waits for a second person, and nobody downloads a snapshot. +""" + +from __future__ import annotations + +import re +import secrets +from collections.abc import Callable +from dataclasses import dataclass +from datetime import UTC, datetime, timedelta +from typing import Any + +from . import audit, jobs +from .blob import Container +from .catalog import DATABASE, Environment, Grant +from .config import Config +from .kube import CNPG, Kube + +APPROVAL_HOURS = 24 +SNAPSHOT_ID = r"^[0-9]{8}T[0-9]{6}Z-[0-9a-f]{6}$" +_ACTIVE = ("waiting", "starting", "running") +_COPY = "_copy" + + +class ConsoleError(Exception): + def __init__(self, status: int, code: str, message: str): + super().__init__(message) + self.status = status + self.code = code + + +@dataclass(frozen=True) +class Actor: + oid: str + upn: str + name: str + groups: frozenset[str] + admin: bool = False + auditor: bool = False + + +def snapshot_blob(database: str, snapshot: str) -> str: + return f"snapshots/{database}/{snapshot}.dump" + + +def _iso(at: datetime) -> str: + return at.strftime("%Y-%m-%dT%H:%M:%SZ") + + +def _when(value: str) -> datetime | None: + try: + return datetime.strptime(value, "%Y-%m-%dT%H:%M:%SZ").replace(tzinfo=UTC) + except (TypeError, ValueError): + return None + + +class Console: + def __init__(self, cfg: Config, kube: dict[str, Kube], storage: dict[str, Container], now: Callable[[], datetime] = lambda: datetime.now(UTC)): + self.cfg = cfg + self.catalog = cfg.catalog + self._kube = kube + self._storage = storage + self._now = now + + # ── Who may do what ───────────────────────────────────────────────────────────── + + def environment(self, name: str) -> Environment: + env = self.catalog.environments.get(name) + if env is None: + raise ConsoleError(404, "unknown_environment", f"There is no environment {name!r}.") + return env + + def teams(self, actor: Actor) -> set[str]: + return {t.id for t in self.catalog.teams_of(actor.groups)} + + def grant(self, actor: Actor, env: str, database: str) -> Grant | None: + return self.catalog.grant(self.teams(actor), env, database) + + def may_read(self, actor: Actor, env: str, database: str) -> bool: + return actor.admin or actor.auditor or self.grant(actor, env, database) is not None + + def may_act(self, actor: Actor, env: str, database: str) -> bool: + return actor.admin or self.grant(actor, env, database) is not None + + def _require(self, allowed: bool) -> None: + if not allowed: + raise ConsoleError(403, "not_allowed", "You may not do that with this database.") + + def _kube_for(self, env: Environment) -> Kube: + kube = self._kube.get(env.name) + if kube is None: + raise ConsoleError(409, "no_jobs_here", f"This app only reads {env.name}'s snapshots; nothing runs there.") + return kube + + # ── Databases ─────────────────────────────────────────────────────────────────── + + async def _resources(self, env: Environment) -> list[dict[str, Any]]: + found = await self._kube_for(env).list(f"{CNPG}/namespaces/{env.namespace}/databases") + return [d for d in found if ((d.get("spec") or {}).get("cluster") or {}).get("name") == env.cnpg_cluster and (d.get("spec") or {}).get("ensure") != "absent"] + + async def _resource(self, env: Environment, database: str) -> dict[str, Any]: + found = next((d for d in await self._resources(env) if d["spec"].get("name") == database), None) + if found is None: + raise ConsoleError(404, "unknown_database", f"{env.name} has no database {database!r}.") + return found + + async def databases(self, actor: Actor, name: str) -> list[dict[str, Any]]: + env = self.environment(name) + granted = self.catalog.databases(env.name, self.teams(actor)) + everything = actor.admin or actor.auditor + if not env.runs_jobs: + listed = self.catalog.databases(env.name) if everything else granted + return [self._database_json(actor, env, db, None, None) for db in sorted(listed)] + resources = await self._resources(env) + copies = {(d.get("metadata") or {}).get("labels", {}).get(f"{jobs.PREFIX}copy-of"): d for d in resources} + out = [] + for d in sorted(resources, key=lambda d: d["spec"].get("name", "")): + db = d["spec"].get("name", "") + if d["metadata"].get("labels", {}).get(f"{jobs.PREFIX}copy-of") or not (everything or db in granted): + continue + out.append(self._database_json(actor, env, db, d, copies.get(db))) + return out + + def _database_json(self, actor: Actor, env: Environment, db: str, resource: dict[str, Any] | None, copy: dict[str, Any] | None) -> dict[str, Any]: + grants = [g for g in self.catalog.grants if g.environment == env.name and g.database == db] + status = (resource or {}).get("status") or {} + return { + "name": db, + "owner": ((resource or {}).get("spec") or {}).get("owner", ""), + "ready": bool(status.get("applied")) if resource else None, + "message": status.get("message", ""), + "teams": sorted({g.team for g in grants}), + "workloads": sorted({"/".join(w) for g in grants for w in g.workloads}), + "copy": None if copy is None else {"name": copy["spec"].get("name", ""), "ready": bool((copy.get("status") or {}).get("applied"))}, + "can_act": self.may_act(actor, env.name, db) and env.runs_jobs, + } + + async def _target(self, env: Environment, resource: dict[str, Any], database: str) -> jobs.Target: + owner = resource["spec"].get("owner", "") + cluster = await self._kube_for(env).get(f"{CNPG}/namespaces/{env.namespace}/clusters/{env.cnpg_cluster}") + if cluster is None: + raise ConsoleError(409, "no_cluster", f"There is no Cluster {env.cnpg_cluster} in {env.namespace}.") + roles = ((cluster.get("spec") or {}).get("managed") or {}).get("roles") or [] + secret = next((((r.get("passwordSecret") or {}).get("name")) for r in roles if r.get("name") == owner), None) + if not secret: + raise ConsoleError(409, "no_credential", f"The owner role {owner!r} has no password Secret among the Cluster's managed roles, so this app can't connect as it.") + ca = ((cluster.get("status") or {}).get("certificates") or {}).get("serverCASecret") or f"{env.cnpg_cluster}-ca" + return jobs.Target(environment=env.name, database=database, owner=owner, password_secret=secret, ca_secret=ca, host=f"{env.cnpg_cluster}-rw.{env.namespace}.svc") + + # ── Snapshots ─────────────────────────────────────────────────────────────────── + + def _check_name(self, database: str) -> None: + if not re.match(DATABASE, database): + raise ConsoleError(404, "unknown_database", "That is not a database name this app takes.") + + async def snapshots(self, actor: Actor, name: str, database: str) -> list[dict[str, Any]]: + env = self.environment(name) + self._check_name(database) + self._require(self.may_read(actor, env.name, database)) + found = await self._storage[env.name].list(f"snapshots/{database}/") + out = [] + for blob in found: + sid = blob.name.rsplit("/", 1)[-1].removesuffix(".dump") + if re.match(SNAPSHOT_ID, sid) and blob.name == snapshot_blob(database, sid): + m = blob.metadata + out.append({"id": sid, "created": m.get("created") or blob.created, "size": blob.size, "created_by": m.get("createdby", ""), "note": m.get("note", ""), "sha256": m.get("sha256", "")}) + return sorted(out, key=lambda s: s["id"], reverse=True) + + async def _busy(self, env: Environment, database: str) -> None: + for job in await self._kube_for(env).list(f"/apis/batch/v1/namespaces/{env.namespace}/jobs", jobs.selector(env.name, database)): + if jobs.state(job) in _ACTIVE and not self._expired(job): + raise ConsoleError(409, "busy", f"{database} has an action running or waiting for approval ({job['metadata']['name']}).") + + async def take_snapshot(self, actor: Actor, name: str, database: str, note: str) -> dict[str, Any]: + env = self.environment(name) + self._check_name(database) + self._require(self.may_act(actor, env.name, database)) + await self._busy(env, database) + target = await self._target(env, await self._resource(env, database), database) + now = self._now() + sid = f"{now:%Y%m%dT%H%M%SZ}-{secrets.token_hex(3)}" + job_name = jobs.name_for("snapshot") + blob = snapshot_blob(database, sid) + manifest = jobs.build( + self.cfg, env, name=job_name, action="snapshot", target=target, database=database, blob_url=env.storage.url, blob=blob, requested_by=actor.upn, + annotations={"requested-by": actor.upn, "requested-at": _iso(now), "note": note, "snapshot": sid}, + metadata={"createdby": actor.upn, "created": _iso(now), "note": note, "environment": env.name, "database": database, "job": job_name}, + ) # fmt: skip + job = await self._kube_for(env).create(f"/apis/batch/v1/namespaces/{env.namespace}/jobs", manifest) + await audit.record(self._storage[env.name], environment=env.name, actor=actor.upn, action="snapshot.requested", at=now, database=database, job=job_name, snapshot=blob, detail=note) + return self._job_json(actor, env, job, None) + + async def restore(self, actor: Actor, name: str, database: str, *, source_environment: str, source_database: str, snapshot: str, into: str, reason: str) -> dict[str, Any]: + env = self.environment(name) + source = self.environment(source_environment) + self._check_name(database) + self._check_name(source_database) + if not re.match(SNAPSHOT_ID, snapshot): + raise ConsoleError(404, "unknown_snapshot", "That is not a snapshot.") + self._require(self.may_act(actor, env.name, database) and self.may_read(actor, source.name, source_database)) + if source.name != env.name and source.name not in env.clone_from: + raise ConsoleError(403, "no_clone", f"{env.name} takes no snapshots from {source.name}.") + blob = snapshot_blob(source_database, snapshot) + if await self._storage[source.name].properties(blob) is None: + raise ConsoleError(404, "unknown_snapshot", f"{source.name} has no snapshot {snapshot} of {source_database}.") + await self._busy(env, database) + resource = await self._resource(env, database) + workloads: tuple[tuple[str, str, str], ...] = () + if into == "copy": + target = await self._target(env, await self._ensure_copy(env, resource, database), database + _COPY) + else: + target = await self._target(env, resource, database) + workloads = tuple(sorted({w for g in self.catalog.grants if g.environment == env.name and g.database == database for w in g.workloads})) + now = self._now() + job_name = jobs.name_for("restore") + manifest = jobs.build( + self.cfg, env, name=job_name, action="restore", target=target, database=database, blob_url=source.storage.url, blob=blob, requested_by=actor.upn, + annotations={ + "requested-by": actor.upn, "requested-at": _iso(now), "reason": reason, "snapshot": snapshot, "source-environment": source.name, + "source-database": source_database, "into": into, "target-database": target.database, "approval": "required" if env.production else "", + }, + suspend=env.production, workloads=workloads, wait_for_database=into == "copy", + ) # fmt: skip + job = await self._kube_for(env).create(f"/apis/batch/v1/namespaces/{env.namespace}/jobs", manifest) + await audit.record( + self._storage[env.name], environment=env.name, actor=actor.upn, action="restore.requested", at=now, database=database, job=job_name, + snapshot=f"{source.name}/{blob}", target=target.database, detail=reason, + ) # fmt: skip + return self._job_json(actor, env, job, None) + + async def _ensure_copy(self, env: Environment, resource: dict[str, Any], database: str) -> dict[str, Any]: + """The Database resource for `_copy`: CloudNativePG creates the database, and drops it with the resource.""" + name = f"{resource['metadata']['name']}-copy"[:253] + path = f"{CNPG}/namespaces/{env.namespace}/databases" + existing = await self._kube_for(env).get(f"{path}/{name}") + if existing is not None: + if existing["metadata"].get("labels", {}).get(f"{jobs.PREFIX}copy-of") != database: + raise ConsoleError(409, "copy_taken", f"A Database resource {name} exists that this app did not create.") + return existing + extensions = [{k: v for k, v in e.items() if k in ("name", "version", "schema")} for e in resource["spec"].get("extensions") or [] if e.get("ensure") != "absent"] + body = { + "apiVersion": "postgresql.cnpg.io/v1", + "kind": "Database", + "metadata": {"name": name, "namespace": env.namespace, "labels": {jobs.MANAGED_BY: jobs.APP, f"{jobs.PREFIX}environment": env.name, f"{jobs.PREFIX}copy-of": database}}, + "spec": { + "name": database + _COPY, + "owner": resource["spec"]["owner"], + "cluster": {"name": env.cnpg_cluster}, + "ensure": "present", + "databaseReclaimPolicy": "delete", + **({"extensions": extensions} if extensions else {}), + }, + } + return await self._kube_for(env).create(path, body) + + async def drop_copy(self, actor: Actor, name: str, database: str) -> None: + env = self.environment(name) + self._check_name(database) + self._require(self.may_act(actor, env.name, database)) + await self._busy(env, database) + path = f"{CNPG}/namespaces/{env.namespace}/databases" + copy = next((d for d in await self._kube_for(env).list(path, f"{jobs.MANAGED_BY}={jobs.APP},{jobs.PREFIX}copy-of={database}")), None) + if copy is None: + raise ConsoleError(404, "no_copy", f"{database} has no copy.") + await self._kube_for(env).delete(f"{path}/{copy['metadata']['name']}") + await audit.record(self._storage[env.name], environment=env.name, actor=actor.upn, action="copy.dropped", database=database, target=copy["spec"].get("name", "")) + + async def download(self, actor: Actor, name: str, database: str, snapshot: str) -> tuple[Container, str, str]: + """The container and blob to stream, and a file name, once the download is recorded.""" + env = self.environment(name) + self._check_name(database) + if env.production: + raise ConsoleError(403, "no_downloads", f"Snapshots of {env.name} stay in {env.name}.") + self._require(self.may_act(actor, env.name, database)) + if not re.match(SNAPSHOT_ID, snapshot): + raise ConsoleError(404, "unknown_snapshot", "That is not a snapshot.") + blob = snapshot_blob(database, snapshot) + if await self._storage[env.name].properties(blob) is None: + raise ConsoleError(404, "unknown_snapshot", f"{env.name} has no snapshot {snapshot} of {database}.") + await audit.record(self._storage[env.name], environment=env.name, actor=actor.upn, action="snapshot.downloaded", database=database, snapshot=blob) + return self._storage[env.name], blob, f"{env.name}-{database}-{snapshot}.dump" + + # ── Jobs ──────────────────────────────────────────────────────────────────────── + + def _expired(self, job: dict[str, Any]) -> bool: + if jobs.state(job) != "waiting": + return False + at = _when((job["metadata"].get("annotations") or {}).get(f"{jobs.PREFIX}requested-at", "")) + return at is None or self._now() - at > timedelta(hours=APPROVAL_HOURS) + + def _job_json(self, actor: Actor, env: Environment, job: dict[str, Any], pod: dict[str, Any] | None) -> dict[str, Any]: + meta = job.get("metadata") or {} + a = {k.removeprefix(jobs.PREFIX): v for k, v in (meta.get("annotations") or {}).items() if k.startswith(jobs.PREFIX)} + labels = meta.get("labels") or {} + database = labels.get(f"{jobs.PREFIX}database", "") + state = "expired" if self._expired(job) else jobs.state(job) + status = job.get("status") or {} + waiting = state == "waiting" + return { + "name": meta.get("name", ""), + "action": labels.get(f"{jobs.PREFIX}action", ""), + "database": database, + "state": state, + "requested_by": a.get("requested-by", ""), + "requested_at": a.get("requested-at", ""), + "approved_by": a.get("approved-by", ""), + "approved_at": a.get("approved-at", ""), + "reason": a.get("reason", ""), + "note": a.get("note", ""), + "snapshot": a.get("snapshot", ""), + "source_environment": a.get("source-environment", ""), + "source_database": a.get("source-database", ""), + "into": a.get("into", ""), + "target_database": a.get("target-database", ""), + "approval": a.get("approval", ""), + "started": status.get("startTime", ""), + "finished": status.get("completionTime", "") or next((c.get("lastTransitionTime", "") for c in status.get("conditions") or [] if c.get("type") == "Failed"), ""), + "result": jobs.result(pod), + "can_approve": waiting and actor.upn != a.get("requested-by") and self.may_act(actor, env.name, database), + "can_decline": waiting and (actor.upn == a.get("requested-by") or self.may_act(actor, env.name, database)), + } + + async def jobs(self, actor: Actor, name: str) -> list[dict[str, Any]]: + env = self.environment(name) + if not env.runs_jobs: + return [] + kube = self._kube_for(env) + found = await kube.list(f"/apis/batch/v1/namespaces/{env.namespace}/jobs", jobs.selector(env.name)) + pods = {} + for pod in await kube.list(f"/api/v1/namespaces/{env.namespace}/pods", jobs.selector(env.name)): + pods[(pod.get("metadata") or {}).get("labels", {}).get("job-name", "")] = pod + out = [] + for job in found: + if self._expired(job): + await self._drop(env, job, actor="databases-ui", action="restore.expired") + continue + if self.may_read(actor, env.name, (job["metadata"].get("labels") or {}).get(f"{jobs.PREFIX}database", "")): + out.append(self._job_json(actor, env, job, pods.get(job["metadata"]["name"]))) + return sorted(out, key=lambda j: j["requested_at"], reverse=True) + + async def _waiting(self, actor: Actor, env: Environment, job_name: str) -> dict[str, Any]: + job = await self._kube_for(env).get(f"/apis/batch/v1/namespaces/{env.namespace}/jobs/{job_name}") + labels = (job or {}).get("metadata", {}).get("labels") or {} + if job is None or labels.get(jobs.MANAGED_BY) != jobs.APP or labels.get(f"{jobs.PREFIX}environment") != env.name: + raise ConsoleError(404, "unknown_job", "There is no such request.") + self._require(self.may_read(actor, env.name, labels.get(f"{jobs.PREFIX}database", ""))) + if self._expired(job): + raise ConsoleError(409, "expired", f"Requests wait {APPROVAL_HOURS} hours for approval; ask again.") + if jobs.state(job) != "waiting": + raise ConsoleError(409, "not_waiting", "This request is not waiting for approval.") + return job + + async def approve(self, actor: Actor, name: str, job_name: str) -> dict[str, Any]: + env = self.environment(name) + job = await self._waiting(actor, env, job_name) + view = self._job_json(actor, env, job, None) + if actor.upn == view["requested_by"]: + raise ConsoleError(403, "own_request", "A second person approves this, not the one who asked.") + self._require(view["can_approve"]) + now = self._now() + patch = {"metadata": {"annotations": {f"{jobs.PREFIX}approved-by": actor.upn, f"{jobs.PREFIX}approved-at": _iso(now)}}, "spec": {"suspend": False}} + job = await self._kube_for(env).patch(f"/apis/batch/v1/namespaces/{env.namespace}/jobs/{job_name}", patch) + await audit.record(self._storage[env.name], environment=env.name, actor=actor.upn, action="restore.approved", at=now, database=view["database"], job=job_name, detail=f"asked by {view['requested_by']}") + return self._job_json(actor, env, job, None) + + async def decline(self, actor: Actor, name: str, job_name: str, reason: str) -> None: + env = self.environment(name) + job = await self._waiting(actor, env, job_name) + self._require(self._job_json(actor, env, job, None)["can_decline"]) + await self._drop(env, job, actor=actor.upn, action="restore.declined", detail=reason) + + async def _drop(self, env: Environment, job: dict[str, Any], *, actor: str, action: str, detail: str = "") -> None: + meta = job["metadata"] + await self._kube_for(env).delete(f"/apis/batch/v1/namespaces/{env.namespace}/jobs/{meta['name']}") + await audit.record(self._storage[env.name], environment=env.name, actor=actor, action=action, database=(meta.get("labels") or {}).get(f"{jobs.PREFIX}database", ""), job=meta["name"], detail=detail) + + # ── Audit ─────────────────────────────────────────────────────────────────────── + + async def audit_log(self, actor: Actor, name: str, limit: int = 500) -> list[dict[str, Any]]: + env = self.environment(name) + container = self._storage[env.name] + months = sorted((b.name for b in await container.list(audit.PREFIX)), reverse=True)[:2] + entries = [] + for month in months: + entries += audit.parse(await container.read(month) or b"") + visible = [e for e in entries if actor.admin or actor.auditor or (e.get("database") and self.may_read(actor, env.name, str(e["database"])))] + return sorted(visible, key=lambda e: str(e.get("at", "")), reverse=True)[:limit] diff --git a/src/databases_ui/session.py b/src/databases_ui/session.py new file mode 100644 index 0000000..6270d59 --- /dev/null +++ b/src/databases_ui/session.py @@ -0,0 +1,99 @@ +"""Signed-in state, sealed into cookies with AES-256-GCM. The server keeps no session store. + +Any replica can serve any request and a restart signs nobody out. The cookie holds who the +person is, their app roles and those of their groups the catalog names. It carries no token: +every call to Kubernetes and to storage runs as the app. +""" + +from __future__ import annotations + +import base64 +import json +import os +import time +from typing import Any + +from cryptography.exceptions import InvalidTag +from cryptography.hazmat.primitives import hashes +from cryptography.hazmat.primitives.ciphers.aead import AESGCM +from cryptography.hazmat.primitives.kdf.hkdf import HKDF +from starlette.requests import Request +from starlette.responses import Response + +# Browsers drop a cookie over 4096 bytes without a word, which shows up as a sign-in loop. +_CHUNK = 3800 +_MAX_CHUNKS = 6 + + +class Sealer: + def __init__(self, key: bytes): + derived = HKDF(algorithm=hashes.SHA256(), length=32, salt=None, info=b"databases-ui cookie v1").derive(key) + self._aead = AESGCM(derived) + + def seal(self, purpose: str, data: dict[str, Any], ttl: int) -> str: + body = json.dumps({**data, "exp": int(time.time()) + ttl}, separators=(",", ":")).encode() + nonce = os.urandom(12) + sealed = nonce + self._aead.encrypt(nonce, body, purpose.encode()) + return base64.urlsafe_b64encode(sealed).rstrip(b"=").decode() + + def open(self, purpose: str, token: str) -> dict[str, Any] | None: + """The data, or None for anything forged, altered, sealed for another purpose or expired.""" + try: + raw = base64.urlsafe_b64decode(token + "=" * (-len(token) % 4)) + body = json.loads(self._aead.decrypt(raw[:12], raw[12:], purpose.encode())) + except (ValueError, TypeError, InvalidTag): + return None + if not isinstance(body, dict) or not isinstance(body.get("exp"), int) or body["exp"] <= time.time(): + return None + return body + + +class Cookies: + """Cookie names and attributes. `__Host-` pins a cookie to this exact host, https and path /.""" + + def __init__(self, sealer: Sealer, secure: bool): + self._sealer = sealer + self._secure = secure + prefix = "__Host-" if secure else "" + self.session = f"{prefix}databases-ui" + self.login = f"{prefix}databases-ui-login" + + def _set(self, response: Response, name: str, value: str, max_age: int, samesite: str) -> None: + response.set_cookie(name, value, max_age=max_age, path="/", secure=self._secure, httponly=True, samesite=samesite) # type: ignore[arg-type] + + def read_session(self, request: Request) -> dict[str, Any] | None: + parts = [] + for i in range(_MAX_CHUNKS): + part = request.cookies.get(f"{self.session}.{i}") + if part is None: + break + parts.append(part) + return self._sealer.open("session", "".join(parts)) if parts else None + + def write_session(self, request: Request, response: Response, data: dict[str, Any], ttl: int) -> None: + token = self._sealer.seal("session", data, ttl) + chunks = [token[i : i + _CHUNK] for i in range(0, len(token), _CHUNK)] + if len(chunks) > _MAX_CHUNKS: + raise ValueError("the session does not fit in cookies") + for i, chunk in enumerate(chunks): + # Strict: no other site can make the browser send it, which is half the CSRF defence. + self._set(response, f"{self.session}.{i}", chunk, ttl, "strict") + for i in range(len(chunks), _MAX_CHUNKS): + if f"{self.session}.{i}" in request.cookies: + self.clear(response, f"{self.session}.{i}") + + def clear_session(self, request: Request, response: Response) -> None: + for i in range(_MAX_CHUNKS): + if f"{self.session}.{i}" in request.cookies: + self.clear(response, f"{self.session}.{i}") + + def read_login(self, request: Request) -> dict[str, Any] | None: + return self._sealer.open("login", request.cookies.get(self.login, "")) + + def write_login(self, response: Response, data: dict[str, Any], ttl: int) -> None: + # Lax, not strict: it has to come back on the top-level redirect from Microsoft. + self._set(response, self.login, self._sealer.seal("login", data, ttl), ttl, "lax") + + def clear(self, response: Response, name: str) -> None: + response.delete_cookie(name, path="/", secure=self._secure, httponly=True, samesite="lax") + diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..9407a2b --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,366 @@ +"""Fake Entra ID, Kubernetes API and Blob Storage behind httpx MockTransports, and an app wired to them. + +The Kubernetes fake keeps objects by API path and answers list, get, create, merge-patch and +delete the way the API server does; the storage fake keeps block, block-list and append blobs. +""" + +from __future__ import annotations + +import base64 +import copy +import hashlib +import json +import re +import time +import uuid +from dataclasses import dataclass, field +from datetime import UTC, datetime +from email.utils import formatdate +from pathlib import Path +from typing import Any +from urllib.parse import parse_qs, unquote, urlsplit +from xml.sax.saxutils import escape + +import httpx +import jwt +import pytest +from cryptography.hazmat.primitives.asymmetric import rsa +from fastapi.testclient import TestClient + +from databases_ui.app import create_app +from databases_ui.config import load_config + +TENANT = "11111111-2222-3333-4444-555555555555" +CLIENT = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee" +ORIGIN = "https://databases.example.test" +AUTHORITY = "https://login.example.test" +STORAGE = "https://snapshots.blob.example.test" +KUBE = "https://kubernetes.example.test" +NOW = datetime(2026, 10, 23, 14, 0, 0, tzinfo=UTC) +KEY = rsa.generate_private_key(public_exponent=65537, key_size=2048) +PAYMENTS = "6f1c2b7e-3a44-4d0e-9a51-2b8e0c7d9f10" +IDENTITY = "0b9d8e7c-6f5a-4b3c-8d2e-1f0a9b8c7d6e" +UNRELATED = "99999999-9999-4999-8999-999999999999" + +CATALOG = f""" +environments: + - name: dev + storage: + url: {STORAGE}/dev + cloneFrom: [acc, prd] + - name: acc + kubernetes: none + storage: + url: {STORAGE}/acc + - name: prd + production: true + cluster: prod + storage: + url: {STORAGE}/prd +teams: + - id: payments + name: Payments + groups: [{PAYMENTS}] + databases: + - name: payments_{{env}} + workloads: + - deployment/{{env}}-payments/api + - id: identity + name: Identity + groups: [{IDENTITY}] + databases: + - name: keycloak + environments: [dev] +""" + + +def oid(upn: str) -> str: + return str(uuid.uuid5(uuid.NAMESPACE_URL, upn)) + + +@dataclass +class FakeEntra: + user: str = "alice@example.com" + roles: list[str] = field(default_factory=list) + groups: list[str] = field(default_factory=list) + overage: bool = False + tenant: str = TENANT + challenge: str = "" + nonce: str = "" + token_requests: list[dict[str, list[str]]] = field(default_factory=list) + + def jwks(self) -> dict[str, Any]: + jwk = json.loads(jwt.algorithms.RSAAlgorithm.to_jwk(KEY.public_key())) + return {"keys": [{**jwk, "kid": "test-key", "use": "sig", "alg": "RS256"}]} + + def id_token(self) -> str: + now = int(time.time()) + claims = { + "iss": f"{AUTHORITY}/{TENANT}/v2.0", + "aud": CLIENT, + "iat": now, + "nbf": now, + "exp": now + 3600, + "nonce": self.nonce, + "tid": self.tenant, + "oid": oid(self.user), + "name": self.user.split("@")[0].title(), + "preferred_username": self.user, + "roles": self.roles, + "groups": self.groups, + } + if self.overage: + claims.pop("groups") + claims["_claim_names"] = {"groups": "src1"} + return jwt.encode(claims, KEY, algorithm="RS256", headers={"kid": "test-key"}) + + def token(self, request: httpx.Request) -> httpx.Response: + form = parse_qs(request.content.decode()) + self.token_requests.append(form) + grant = form["grant_type"][0] + if grant == "client_credentials": + return httpx.Response(200, json={"access_token": "storage-token", "expires_in": 3600}) + if grant == "authorization_code": + verifier = form["code_verifier"][0] + digest = base64.urlsafe_b64encode(hashlib.sha256(verifier.encode()).digest()).rstrip(b"=").decode() + if form["code"][0] != "good-code" or digest != self.challenge: + return httpx.Response(400, json={"error": "invalid_grant", "error_description": "AADSTS70008: bad code"}) + return httpx.Response(200, json={"token_type": "Bearer", "expires_in": 3600, "id_token": self.id_token()}) + return httpx.Response(400, json={"error": "unsupported_grant_type"}) + + +@dataclass +class StoredBlob: + data: bytes + metadata: dict[str, str] + created: str + kind: str = "BlockBlob" + + +@dataclass +class FakeStorage: + blobs: dict[str, StoredBlob] = field(default_factory=dict) + blocks: dict[tuple[str, str], bytes] = field(default_factory=dict) + calls: list[tuple[str, str]] = field(default_factory=list) + # Answers to fail with, by (method, comp): a status code each time. + fail: dict[tuple[str, str], int] = field(default_factory=dict) + page: int = 1000 + + def handle(self, request: httpx.Request) -> httpx.Response: + if request.headers.get("authorization") != "Bearer storage-token" and "sig" not in request.url.params: + return httpx.Response(403, headers={"x-ms-error-code": "AuthenticationFailed"}) + path = unquote(request.url.path).lstrip("/") + container, _, name = path.partition("/") + key = f"{container}/{name}" + comp = request.url.params.get("comp", "") + self.calls.append((request.method, f"{key}?{comp}" if comp else key)) + if (request.method, comp) in self.fail: + return httpx.Response(self.fail[(request.method, comp)], headers={"x-ms-error-code": "ServerBusy"}) + if request.method == "GET" and comp == "list": + prefix = f"{container}/{request.url.params.get('prefix', '')}" + names = sorted(k for k in self.blobs if k.startswith(prefix)) + start = int(request.url.params.get("marker") or 0) + chunk = names[start : start + self.page] + items = "".join( + f"{escape(n.split('/', 1)[1])}{self.blobs[n].created}" + f"{len(self.blobs[n].data)}" + f"{''.join(f'<{k}>{escape(v)}' for k, v in self.blobs[n].metadata.items())}" + for n in chunk + ) + marker = str(start + self.page) if start + self.page < len(names) else "" + return httpx.Response(200, content=f"{items}{marker}".encode()) + if request.method == "PUT" and comp == "block": + self.blocks[(key, request.url.params["blockid"])] = request.content + return httpx.Response(201) + if request.method == "PUT" and comp == "blocklist": + ids = re.findall(r"([^<]+)", request.content.decode()) + meta = {k[len("x-ms-meta-") :]: v for k, v in request.headers.items() if k.startswith("x-ms-meta-")} + self.blobs[key] = StoredBlob(b"".join(self.blocks.pop((key, i)) for i in ids), meta, formatdate(usegmt=True)) + return httpx.Response(201) + if request.method == "PUT" and comp == "appendblock": + if key not in self.blobs: + return httpx.Response(404, headers={"x-ms-error-code": "BlobNotFound"}) + self.blobs[key].data += request.content + return httpx.Response(201) + if request.method == "PUT" and request.headers.get("x-ms-blob-type") == "AppendBlob": + if key in self.blobs: + return httpx.Response(409, headers={"x-ms-error-code": "BlobAlreadyExists"}) + self.blobs[key] = StoredBlob(b"", {}, formatdate(usegmt=True), "AppendBlob") + return httpx.Response(201) + blob = self.blobs.get(key) + if request.method in ("GET", "HEAD"): + if blob is None: + return httpx.Response(404, headers={"x-ms-error-code": "BlobNotFound"}) + headers = {"content-length": str(len(blob.data)), "x-ms-creation-time": blob.created, **{f"x-ms-meta-{k}": v for k, v in blob.metadata.items()}} + return httpx.Response(200, headers=headers, content=blob.data if request.method == "GET" else b"") + return httpx.Response(400, headers={"x-ms-error-code": "Unhandled"}) + + def text(self, key: str) -> str: + return self.blobs[key].data.decode() + + def audit(self, env: str) -> list[dict[str, Any]]: + found = [b for k, b in self.blobs.items() if k.startswith(f"{env}/audit/")] + return [json.loads(line) for b in found for line in b.data.decode().splitlines()] + + +def _merge(target: dict[str, Any], patch: dict[str, Any]) -> None: + for k, v in patch.items(): + if v is None: + target.pop(k, None) + elif isinstance(v, dict) and isinstance(target.get(k), dict): + _merge(target[k], v) + else: + target[k] = copy.deepcopy(v) + + +def _matches(obj: dict[str, Any], selector: str) -> bool: + labels = obj.get("metadata", {}).get("labels") or {} + for term in filter(None, selector.split(",")): + k, _, v = term.partition("=") + if ("=" in term and labels.get(k) != v) or ("=" not in term and k not in labels): + return False + return True + + +@dataclass +class FakeKube: + # Collections by path, items by name. + objects: dict[str, dict[str, dict[str, Any]]] = field(default_factory=dict) + calls: list[tuple[str, str]] = field(default_factory=list) + # Answer every call with this status, as an API server that refuses this app would. + refuse: int = 0 + + def put(self, collection: str, obj: dict[str, Any]) -> dict[str, Any]: + obj.setdefault("metadata", {}).setdefault("labels", {}) + self.objects.setdefault(collection, {})[obj["metadata"]["name"]] = obj + return obj + + def get(self, collection: str, name: str) -> dict[str, Any] | None: + return self.objects.get(collection, {}).get(name) + + def handle(self, request: httpx.Request) -> httpx.Response: + path = request.url.path + self.calls.append((request.method, path)) + if self.refuse: + return httpx.Response(self.refuse, json={"message": "jobs.batch is forbidden"}) + collection, _, name = path.rpartition("/") + if name in ("databases", "clusters", "jobs", "pods", "deployments", "statefulsets"): + collection, name = path, "" + items = self.objects.setdefault(collection, {}) + if request.method == "GET" and not name: + selector = request.url.params.get("labelSelector", "") + return httpx.Response(200, json={"items": [copy.deepcopy(o) for o in items.values() if _matches(o, selector)]}) + if request.method == "GET": + found = items.get(name) + return httpx.Response(200, json=copy.deepcopy(found)) if found else httpx.Response(404, json={"message": f"{name} not found"}) + if request.method == "POST": + body = json.loads(request.content) + if body["metadata"]["name"] in items: + return httpx.Response(409, json={"message": "already exists"}) + body["metadata"].setdefault("creationTimestamp", "2026-10-23T14:00:00Z") + return httpx.Response(201, json=copy.deepcopy(self.put(collection, body))) + if request.method == "PATCH": + found = items.get(name) + if found is None: + return httpx.Response(404, json={"message": "not found"}) + assert request.headers["content-type"] == "application/merge-patch+json" + _merge(found, json.loads(request.content)) + return httpx.Response(200, json=copy.deepcopy(found)) + if request.method == "DELETE": + return httpx.Response(200, json={}) if items.pop(name, None) else httpx.Response(404, json={"message": "not found"}) + return httpx.Response(405, json={"message": "unhandled"}) + + +CNPG = "/apis/postgresql.cnpg.io/v1/namespaces/database" +JOBS = "/apis/batch/v1/namespaces/database/jobs" +PODS = "/api/v1/namespaces/database/pods" + + +def database(name: str, owner: str, cluster: str, **spec: Any) -> dict[str, Any]: + return {"metadata": {"name": name.replace("_", "-"), "labels": {}}, "spec": {"name": name, "owner": owner, "cluster": {"name": cluster}, **spec}, "status": {"applied": True}} + + +@dataclass +class World: + entra: FakeEntra = field(default_factory=FakeEntra) + storage: FakeStorage = field(default_factory=FakeStorage) + kube: FakeKube = field(default_factory=FakeKube) + + def handler(self, request: httpx.Request) -> httpx.Response: + url = str(request.url) + if url.startswith(f"{AUTHORITY}/{TENANT}/oauth2/v2.0/token"): + return self.entra.token(request) + if url.startswith(f"{AUTHORITY}/{TENANT}/discovery/v2.0/keys"): + return httpx.Response(200, json=self.entra.jwks()) + if url.startswith(STORAGE): + return self.storage.handle(request) + return httpx.Response(404, json={"error": "unhandled", "url": url}) + + def seed(self) -> None: + for name, cluster, roles in (("dev", "dev", ["payments_dev", "keycloak"]), ("prod", "prod", ["payments_prd"])): + self.kube.put( + f"{CNPG}/clusters", + {"metadata": {"name": name}, "spec": {"managed": {"roles": [{"name": r, "passwordSecret": {"name": f"{r}-db"}} for r in roles] + [{"name": "nopass"}]}}, "status": {"certificates": {"serverCASecret": f"{cluster}-ca"}}}, + ) + for d in ( + database("payments_dev", "payments_dev", "dev", extensions=[{"name": "citext", "ensure": "present"}, {"name": "old", "ensure": "absent"}]), + database("keycloak", "keycloak", "dev"), + database("platform_only", "nopass", "dev"), + database("payments_prd", "payments_prd", "prod"), + database("gone", "payments_dev", "dev", ensure="absent"), + ): + self.kube.put(f"{CNPG}/databases", d) + + def snapshot(self, env: str, database: str, sid: str, data: bytes = b"PGDMP-test", **meta: str) -> None: + self.storage.blobs[f"{env}/snapshots/{database}/{sid}.dump"] = StoredBlob(data, {"createdby": "alice@example.com", "note": "kept", **meta}, "Fri, 23 Oct 2026 12:00:00 GMT") + + +@pytest.fixture +def world() -> World: + w = World() + w.seed() + return w + + +@pytest.fixture +def env(tmp_path: Path) -> dict[str, str]: + catalog = tmp_path / "catalog.yaml" + catalog.write_text(CATALOG) + token = tmp_path / "token" + token.write_text("federated-token") + return { + "AZURE_TENANT_ID": TENANT, + "AZURE_CLIENT_ID": CLIENT, + "AZURE_AUTHORITY_HOST": AUTHORITY, + "AZURE_FEDERATED_TOKEN_FILE": str(token), + "DATABASES_UI_PUBLIC_ORIGIN": ORIGIN, + "DATABASES_UI_SESSION_KEY": "k" * 40, + "DATABASES_UI_CATALOG": str(catalog), + "DATABASES_UI_JOB_IMAGE": "ghcr.io/magmamoose/databases-ui:v0.1.0", + "DATABASES_UI_STATIC_DIR": str(tmp_path / "none"), + } + + +def make_client(world: World, env: dict[str, str]) -> TestClient: + app = create_app(load_config(env), transport=httpx.MockTransport(world.handler), kube_transport=httpx.MockTransport(world.kube.handle), now=lambda: NOW) + return TestClient(app, base_url=ORIGIN, follow_redirects=False) + + +@pytest.fixture +def client(world: World, env: dict[str, str]) -> TestClient: + return make_client(world, env) + + +def sign_in(client: TestClient, world: World, upn: str = "alice@example.com", groups: list[str] | tuple[str, ...] = (PAYMENTS,), roles: list[str] | tuple[str, ...] = ()) -> dict[str, Any]: + client.cookies.clear() + world.entra.user, world.entra.groups, world.entra.roles = upn, list(groups), list(roles) + response = client.get("/auth/login") + query = parse_qs(urlsplit(response.headers["location"]).query) + world.entra.challenge, world.entra.nonce = query["code_challenge"][0], query["nonce"][0] + done = client.get(f"/auth/callback?code=good-code&state={query['state'][0]}") + assert done.status_code == 303 and "auth_error" not in done.headers["location"], done.headers["location"] + return client.get("/api/me").json() + + +def write_headers(me: dict[str, Any], origin: str = ORIGIN) -> dict[str, str]: + return {"X-CSRF-Token": me["csrf"], "Origin": origin} diff --git a/tests/test_api.py b/tests/test_api.py new file mode 100644 index 0000000..d569216 --- /dev/null +++ b/tests/test_api.py @@ -0,0 +1,327 @@ +from __future__ import annotations + +import json +from typing import Any + +from conftest import ( + CNPG, + IDENTITY, + JOBS, + PAYMENTS, + PODS, + STORAGE, + UNRELATED, + World, + make_client, + sign_in, + write_headers, +) + + +def env_of(job: dict[str, Any]) -> dict[str, Any]: + container = job["spec"]["template"]["spec"]["containers"][0] + return {e["name"]: e.get("value", e.get("valueFrom")) for e in container["env"]} + + +def only_job(world: World) -> dict[str, Any]: + jobs = list(world.kube.objects.get(JOBS, {}).values()) + assert len(jobs) == 1, [j["metadata"]["name"] for j in jobs] + return jobs[0] + + +def finish(world: World, name: str, *, ok: bool = True, message: dict[str, Any] | None = None) -> None: + job = world.kube.get(JOBS, name) + job["status"] = {"conditions": [{"type": "Complete" if ok else "Failed", "status": "True", "lastTransitionTime": "2026-10-23T14:05:00Z"}], "startTime": "2026-10-23T14:00:01Z", "completionTime": "2026-10-23T14:05:00Z" if ok else None} + world.kube.put(PODS, {"metadata": {"name": f"{name}-x", "labels": {**job["spec"]["template"]["metadata"]["labels"], "job-name": name}}, + "status": {"containerStatuses": [{"state": {"terminated": {"message": json.dumps(message or {"result": "succeeded", "bytes": 1234, "seconds": 9})}}}]}}) # fmt: skip + + +def test_me_lists_teams_and_environments(client, world): + me = sign_in(client, world, groups=[PAYMENTS, UNRELATED]) + assert me["upn"] == "alice@example.com" and me["teams"] == [{"id": "payments", "name": "Payments"}] + assert [(e["name"], e["production"], e["runs_jobs"], e["downloads"]) for e in me["environments"]] == [("dev", False, True, True), ("acc", False, False, True), ("prd", True, True, False)] + + +def test_databases_follow_the_teams(client, world): + sign_in(client, world) + found = client.get("/api/environments/dev/databases").json()["databases"] + assert [d["name"] for d in found] == ["payments_dev"] + assert found[0] | {"teams": found[0]["teams"]} == { + "name": "payments_dev", "owner": "payments_dev", "ready": True, "message": "", "teams": ["payments"], + "workloads": ["deployment/dev-payments/api"], "copy": None, "can_act": True, + } # fmt: skip + # prd's Cluster is called prod; acc runs nothing here, so the catalog says what it holds. + assert [d["name"] for d in client.get("/api/environments/prd/databases").json()["databases"]] == ["payments_prd"] + assert client.get("/api/environments/acc/databases").json()["databases"] == [ + {"name": "payments_acc", "owner": "", "ready": None, "message": "", "teams": ["payments"], "workloads": ["deployment/acc-payments/api"], "copy": None, "can_act": False} + ] + sign_in(client, world, upn="nobody@example.com", groups=[UNRELATED]) + assert client.get("/api/environments/dev/databases").json()["databases"] == [] + sign_in(client, world, upn="audrey@example.com", groups=[], roles=["Auditor"]) + found = client.get("/api/environments/dev/databases").json()["databases"] + assert [(d["name"], d["can_act"]) for d in found] == [("keycloak", False), ("payments_dev", False), ("platform_only", False)] + assert client.get("/api/environments/nowhere/databases").status_code == 404 + + +def test_a_snapshot_is_a_job_that_reads_the_owners_password_itself(client, world): + me = sign_in(client, world) + response = client.post("/api/environments/dev/databases/payments_dev/snapshots", json={"note": " before the 2.4 migration "}, headers=write_headers(me)) + assert response.status_code == 201, response.text + job = only_job(world) + meta, spec = job["metadata"], job["spec"] + assert meta["name"].startswith("dbui-snapshot-") and meta["namespace"] == "database" + assert meta["labels"] == {"app.kubernetes.io/managed-by": "databases-ui", "databases-ui/environment": "dev", "databases-ui/database": "payments_dev", "databases-ui/action": "snapshot"} + assert meta["annotations"]["databases-ui/note"] == "before the 2.4 migration" and meta["annotations"]["databases-ui/requested-by"] == "alice@example.com" + assert spec["suspend"] is False and spec["backoffLimit"] == 0 + pod = spec["template"]["spec"] + assert pod["serviceAccountName"] == "databases-ui-job" and pod["automountServiceAccountToken"] is False + assert pod["containers"][0]["image"] == "ghcr.io/magmamoose/databases-ui:v0.1.0" and pod["containers"][0]["args"] == ["job"] + env = env_of(job) + assert env["PGHOST"] == "dev-rw.database.svc" and env["PGDATABASE"] == "payments_dev" and env["PGUSER"] == "payments_dev" + assert env["PGPASSWORD"] == {"secretKeyRef": {"name": "payments_dev-db", "key": "password"}} + assert env["PGSSLMODE"] == "verify-full" + assert env["DBUI_BLOB_URL"] == f"{STORAGE}/dev" and env["DBUI_BLOB"].startswith("snapshots/payments_dev/20261023T140000Z-") + assert json.loads(env["DBUI_METADATA"])["createdby"] == "alice@example.com" + # Workload identity: the Job exchanges its own projected token, nothing stored. + assert env["AZURE_CLIENT_ID"] == "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee" and env["AZURE_FEDERATED_TOKEN_FILE"].endswith("/azure-identity-token") + volumes = {v["name"]: v for v in pod["volumes"]} + assert volumes["ca"]["secret"] == {"secretName": "dev-ca", "defaultMode": 0o440, "items": [{"key": "ca.crt", "path": "ca.crt"}]} + assert volumes["azure-identity-token"]["projected"]["sources"][0]["serviceAccountToken"]["audience"] == "api://AzureADTokenExchange" + assert [(e["action"], e["actor"], e["database"]) for e in world.storage.audit("dev")] == [("snapshot.requested", "alice@example.com", "payments_dev")] + body = response.json() + assert body["state"] == "starting" and body["note"] == "before the 2.4 migration" + + +def test_a_database_with_a_job_in_flight_is_busy(client, world): + me = sign_in(client, world) + assert client.post("/api/environments/dev/databases/payments_dev/snapshots", json={}, headers=write_headers(me)).status_code == 201 + busy = client.post("/api/environments/dev/databases/payments_dev/snapshots", json={}, headers=write_headers(me)) + assert busy.status_code == 409 and busy.json()["error"] == "busy" + finish(world, only_job(world)["metadata"]["name"]) + assert client.post("/api/environments/dev/databases/payments_dev/snapshots", json={}, headers=write_headers(me)).status_code == 201 + + +def test_who_may_act(client, world): + me = sign_in(client, world, upn="carol@example.com", groups=[IDENTITY]) + assert client.post("/api/environments/dev/databases/payments_dev/snapshots", json={}, headers=write_headers(me)).status_code == 403 + assert client.post("/api/environments/dev/databases/keycloak/snapshots", json={}, headers=write_headers(me)).status_code == 201 + me = sign_in(client, world, upn="audrey@example.com", groups=[], roles=["Auditor"]) + assert client.post("/api/environments/dev/databases/payments_dev/snapshots", json={}, headers=write_headers(me)).status_code == 403 + me = sign_in(client, world, upn="root@example.com", groups=[], roles=["Admin"]) + response = client.post("/api/environments/dev/databases/platform_only/snapshots", json={}, headers=write_headers(me)) + assert response.status_code == 409 and response.json()["error"] == "no_credential" + assert client.post("/api/environments/dev/databases/gone/snapshots", json={}, headers=write_headers(me)).status_code == 404 + assert client.post("/api/environments/acc/databases/payments_acc/snapshots", json={}, headers=write_headers(me)).json()["error"] == "no_jobs_here" + + +def test_writes_need_the_csrf_token_and_this_origin(client, world): + me = sign_in(client, world) + path = "/api/environments/dev/databases/payments_dev/snapshots" + assert client.post(path, json={}).status_code == 403 + assert client.post(path, json={}, headers={"X-CSRF-Token": me["csrf"], "Origin": "https://evil.example.test"}).status_code == 403 + assert client.post(path, json={}, headers={"X-CSRF-Token": "forged", "Origin": "https://databases.example.test"}).status_code == 403 + assert world.kube.objects.get(JOBS, {}) == {} + + +def test_snapshots_list_newest_first_and_only_well_formed(client, world): + world.snapshot("dev", "payments_dev", "20261020T080000Z-aaaaaa") + world.snapshot("dev", "payments_dev", "20261022T080000Z-bbbbbb", note="na%C3%AFve") + world.storage.blobs["dev/snapshots/payments_dev/stray.txt"] = world.storage.blobs["dev/snapshots/payments_dev/20261020T080000Z-aaaaaa.dump"] + world.storage.page = 1 # every blob on its own page + sign_in(client, world) + found = client.get("/api/environments/dev/databases/payments_dev/snapshots").json()["snapshots"] + assert [s["id"] for s in found] == ["20261022T080000Z-bbbbbb", "20261020T080000Z-aaaaaa"] + assert found[0]["note"] == "naïve" and found[0]["size"] == len(b"PGDMP-test") and found[0]["created_by"] == "alice@example.com" + assert client.get("/api/environments/dev/databases/keycloak/snapshots").status_code == 403 + + +def test_restore_in_place_scales_the_catalogs_workloads(client, world): + world.snapshot("dev", "payments_dev", "20261022T080000Z-bbbbbb") + me = sign_in(client, world) + body = {"source_environment": "dev", "source_database": "payments_dev", "snapshot": "20261022T080000Z-bbbbbb", "into": "database", "reason": "undo the bad batch"} + response = client.post("/api/environments/dev/databases/payments_dev/restore", json=body, headers=write_headers(me)) + assert response.status_code == 201, response.text + job = only_job(world) + env = env_of(job) + assert job["spec"]["suspend"] is False and job["spec"]["template"]["spec"]["automountServiceAccountToken"] is True + assert json.loads(env["DBUI_SCALE"]) == [["deployment", "dev-payments", "api"]] + assert env["DBUI_BLOB"] == "snapshots/payments_dev/20261022T080000Z-bbbbbb.dump" and env["PGDATABASE"] == "payments_dev" + assert "DBUI_WAIT_FOR_DATABASE" not in env + assert job["metadata"]["annotations"]["databases-ui/reason"] == "undo the bad batch" + assert world.storage.audit("dev")[-1]["action"] == "restore.requested" + + +def test_restore_into_a_copy_makes_a_database_resource(client, world): + world.snapshot("dev", "payments_dev", "20261022T080000Z-bbbbbb") + me = sign_in(client, world) + body = {"source_environment": "dev", "source_database": "payments_dev", "snapshot": "20261022T080000Z-bbbbbb", "into": "copy", "reason": "look at old rows"} + assert client.post("/api/environments/dev/databases/payments_dev/restore", json=body, headers=write_headers(me)).status_code == 201 + copy = world.kube.get(f"{CNPG}/databases", "payments-dev-copy") + assert copy["metadata"]["labels"] == {"app.kubernetes.io/managed-by": "databases-ui", "databases-ui/environment": "dev", "databases-ui/copy-of": "payments_dev"} + assert copy["spec"] == {"name": "payments_dev_copy", "owner": "payments_dev", "cluster": {"name": "dev"}, "ensure": "present", "databaseReclaimPolicy": "delete", "extensions": [{"name": "citext"}]} + env = env_of(only_job(world)) + assert env["PGDATABASE"] == "payments_dev_copy" and env["DBUI_WAIT_FOR_DATABASE"] == "1" and "DBUI_SCALE" not in env + finish(world, only_job(world)["metadata"]["name"]) + listed = client.get("/api/environments/dev/databases").json()["databases"] + assert [d["name"] for d in listed] == ["payments_dev"] and listed[0]["copy"] == {"name": "payments_dev_copy", "ready": False} + # Again: the same copy is reused. + assert client.post("/api/environments/dev/databases/payments_dev/restore", json=body, headers=write_headers(me)).status_code == 201 + assert len([d for d in world.kube.objects[f"{CNPG}/databases"] if d.endswith("-copy")]) == 1 + # Dropping it waits for the restore, then deletes the resource, which drops the database. + assert client.delete("/api/environments/dev/databases/payments_dev/copy", headers=write_headers(me)).status_code == 409 + for name in list(world.kube.objects[JOBS]): + finish(world, name) + assert client.delete("/api/environments/dev/databases/payments_dev/copy", headers=write_headers(me)).status_code == 204 + assert world.kube.get(f"{CNPG}/databases", "payments-dev-copy") is None + assert client.delete("/api/environments/dev/databases/payments_dev/copy", headers=write_headers(me)).status_code == 404 + assert world.storage.audit("dev")[-1]["action"] == "copy.dropped" + + +def test_a_copy_name_this_app_did_not_make_is_left_alone(client, world): + world.snapshot("dev", "payments_dev", "20261022T080000Z-bbbbbb") + world.kube.put(f"{CNPG}/databases", {"metadata": {"name": "payments-dev-copy", "labels": {}}, "spec": {"name": "someone_elses", "owner": "x", "cluster": {"name": "dev"}}}) + me = sign_in(client, world) + body = {"source_environment": "dev", "source_database": "payments_dev", "snapshot": "20261022T080000Z-bbbbbb", "into": "copy", "reason": "look at old rows"} + response = client.post("/api/environments/dev/databases/payments_dev/restore", json=body, headers=write_headers(me)) + assert response.status_code == 409 and response.json()["error"] == "copy_taken" + + +def test_clone_only_from_listed_environments_and_existing_snapshots(client, world): + world.snapshot("acc", "payments_acc", "20261021T080000Z-cccccc") + world.snapshot("prd", "payments_prd", "20261021T080000Z-dddddd") + me = sign_in(client, world) + body = {"source_environment": "acc", "source_database": "payments_acc", "snapshot": "20261021T080000Z-cccccc", "into": "database", "reason": "reproduce the acc bug"} + response = client.post("/api/environments/dev/databases/payments_dev/restore", json=body, headers=write_headers(me)) + assert response.status_code == 201, response.text + env = env_of(only_job(world)) + # The snapshot is read from acc's container; the outcome is written to dev's audit log. + assert env["DBUI_BLOB_URL"] == f"{STORAGE}/acc" and env["DBUI_AUDIT_URL"] == f"{STORAGE}/dev" + assert response.json()["source_environment"] == "acc" + finish(world, only_job(world)["metadata"]["name"]) + # prd does not take dev's snapshots. + body = {"source_environment": "dev", "source_database": "payments_dev", "snapshot": "20261021T080000Z-cccccc", "into": "database", "reason": "nope nope"} + assert client.post("/api/environments/prd/databases/payments_prd/restore", json=body, headers=write_headers(me)).json()["error"] == "no_clone" + missing = {**body, "source_environment": "acc", "source_database": "payments_acc", "snapshot": "20261021T080000Z-ffffff"} + assert client.post("/api/environments/dev/databases/payments_dev/restore", json=missing, headers=write_headers(me)).status_code == 404 + carol = sign_in(client, world, upn="carol@example.com", groups=[IDENTITY]) + theirs = {**body, "source_environment": "acc", "source_database": "payments_acc", "snapshot": "20261021T080000Z-cccccc"} + assert client.post("/api/environments/dev/databases/keycloak/restore", json=theirs, headers=write_headers(carol)).status_code == 403 + assert client.post("/api/environments/dev/databases/keycloak/restore", json={**theirs, "into": "everywhere"}, headers=write_headers(carol)).status_code == 422 + + +def test_a_production_restore_waits_for_a_second_person(world, env): + world.snapshot("prd", "payments_prd", "20261021T080000Z-dddddd") + alice, bob, carol = (make_client(world, env) for _ in range(3)) + a = sign_in(alice, world) + b = sign_in(bob, world, upn="bob@example.com") + c = sign_in(carol, world, upn="carol@example.com", groups=[IDENTITY]) + body = {"source_environment": "prd", "source_database": "payments_prd", "snapshot": "20261021T080000Z-dddddd", "into": "database", "reason": "after the bad deploy"} + asked = alice.post("/api/environments/prd/databases/payments_prd/restore", json=body, headers=write_headers(a)).json() + job = only_job(world) + assert job["spec"]["suspend"] is True and asked["state"] == "waiting" and asked["approval"] == "required" + name = job["metadata"]["name"] + seen = {j["name"]: j for j in alice.get("/api/environments/prd/jobs").json()["jobs"]} + assert seen[name]["can_approve"] is False and seen[name]["can_decline"] is True + assert bob.get("/api/environments/prd/jobs").json()["jobs"][0]["can_approve"] is True + assert carol.get("/api/environments/prd/jobs").json()["jobs"] == [] + assert alice.post(f"/api/environments/prd/jobs/{name}/approve", headers=write_headers(a)).json()["error"] == "own_request" + assert carol.post(f"/api/environments/prd/jobs/{name}/approve", headers=write_headers(c)).status_code == 403 + approved = bob.post(f"/api/environments/prd/jobs/{name}/approve", headers=write_headers(b)) + assert approved.status_code == 200 and approved.json()["approved_by"] == "bob@example.com" + assert world.kube.get(JOBS, name)["spec"]["suspend"] is False + assert bob.post(f"/api/environments/prd/jobs/{name}/approve", headers=write_headers(b)).json()["error"] == "not_waiting" + assert [e["action"] for e in world.storage.audit("prd")] == ["restore.requested", "restore.approved"] + + +def test_a_waiting_restore_can_be_declined_or_withdrawn(world, env): + world.snapshot("prd", "payments_prd", "20261021T080000Z-dddddd") + alice, bob = make_client(world, env), make_client(world, env) + a, b = sign_in(alice, world), sign_in(bob, world, upn="bob@example.com") + body = {"source_environment": "prd", "source_database": "payments_prd", "snapshot": "20261021T080000Z-dddddd", "into": "database", "reason": "after the bad deploy"} + alice.post("/api/environments/prd/databases/payments_prd/restore", json=body, headers=write_headers(a)) + name = only_job(world)["metadata"]["name"] + assert bob.post(f"/api/environments/prd/jobs/{name}/decline", json={"reason": "not during the release"}, headers=write_headers(b)).status_code == 204 + assert world.kube.objects[JOBS] == {} + assert world.storage.audit("prd")[-1] | {"at": ""} == {"at": "", "environment": "prd", "actor": "bob@example.com", "action": "restore.declined", "database": "payments_prd", "job": name, "detail": "not during the release"} + alice.post("/api/environments/prd/databases/payments_prd/restore", json=body, headers=write_headers(a)) + name = only_job(world)["metadata"]["name"] + assert alice.post(f"/api/environments/prd/jobs/{name}/decline", json={}, headers=write_headers(a)).status_code == 204 + assert bob.post(f"/api/environments/prd/jobs/{name}/decline", json={}, headers=write_headers(b)).status_code == 404 + + +def test_requests_expire_after_a_day(world, env): + world.snapshot("prd", "payments_prd", "20261021T080000Z-dddddd") + alice, bob = make_client(world, env), make_client(world, env) + a, b = sign_in(alice, world), sign_in(bob, world, upn="bob@example.com") + body = {"source_environment": "prd", "source_database": "payments_prd", "snapshot": "20261021T080000Z-dddddd", "into": "database", "reason": "after the bad deploy"} + alice.post("/api/environments/prd/databases/payments_prd/restore", json=body, headers=write_headers(a)) + job = only_job(world) + job["metadata"]["annotations"]["databases-ui/requested-at"] = "2026-10-22T13:00:00Z" + assert bob.post(f"/api/environments/prd/jobs/{job['metadata']['name']}/approve", headers=write_headers(b)).json()["error"] == "expired" + # Expired, it no longer blocks the database, and the next listing clears it away. + assert alice.post("/api/environments/prd/databases/payments_prd/restore", json=body, headers=write_headers(a)).status_code == 201 + assert len(alice.get("/api/environments/prd/jobs").json()["jobs"]) == 1 + assert job["metadata"]["name"] not in world.kube.objects[JOBS] + assert "restore.expired" in [e["action"] for e in world.storage.audit("prd")] + + +def test_jobs_show_what_their_pods_reported(client, world): + me = sign_in(client, world) + client.post("/api/environments/dev/databases/payments_dev/snapshots", json={"note": "n"}, headers=write_headers(me)) + name = only_job(world)["metadata"]["name"] + world.kube.get(JOBS, name)["status"] = {"active": 1} + assert client.get("/api/environments/dev/jobs").json()["jobs"][0]["state"] == "running" + finish(world, name, ok=False, message={"result": "failed", "reason": "pg_dump exited 1: permission denied for table x"}) + job = client.get("/api/environments/dev/jobs").json()["jobs"][0] + assert job["state"] == "failed" and job["result"]["reason"].endswith("permission denied for table x") and job["finished"] == "2026-10-23T14:05:00Z" + sign_in(client, world, upn="carol@example.com", groups=[IDENTITY]) + assert client.get("/api/environments/dev/jobs").json()["jobs"] == [] + assert client.get("/api/environments/acc/jobs").json()["jobs"] == [] + + +def test_downloads_stream_outside_production_only(client, world): + world.snapshot("dev", "payments_dev", "20261022T080000Z-bbbbbb", data=b"PGDMP" + bytes(range(256)) * 9000) + world.snapshot("prd", "payments_prd", "20261021T080000Z-dddddd") + sign_in(client, world) + response = client.get("/api/environments/dev/databases/payments_dev/snapshots/20261022T080000Z-bbbbbb/download") + assert response.status_code == 200 and response.content == b"PGDMP" + bytes(range(256)) * 9000 + assert response.headers["content-disposition"] == 'attachment; filename="dev-payments_dev-20261022T080000Z-bbbbbb.dump"' + assert world.storage.audit("dev")[-1]["action"] == "snapshot.downloaded" + assert client.get("/api/environments/prd/databases/payments_prd/snapshots/20261021T080000Z-dddddd/download").json()["error"] == "no_downloads" + assert client.get("/api/environments/dev/databases/payments_dev/snapshots/20261022T080000Z-ffffff/download").status_code == 404 + sign_in(client, world, upn="audrey@example.com", groups=[], roles=["Auditor"]) + assert client.get("/api/environments/dev/databases/payments_dev/snapshots/20261022T080000Z-bbbbbb/download").status_code == 403 + + +def test_the_audit_log_shows_your_databases(client, world): + me = sign_in(client, world) + client.post("/api/environments/dev/databases/payments_dev/snapshots", json={"note": "one"}, headers=write_headers(me)) + finish(world, only_job(world)["metadata"]["name"]) + carol = sign_in(client, world, upn="carol@example.com", groups=[IDENTITY]) + client.post("/api/environments/dev/databases/keycloak/snapshots", json={}, headers=write_headers(carol)) + world.storage.blobs["dev/audit/2026-09.jsonl"] = type(world.storage.blobs["dev/audit/2026-10.jsonl"])(b'{"at":"2026-09-01T00:00:00Z","action":"old","database":"keycloak"}\nnot json\n', {}, "") + assert [e["action"] for e in client.get("/api/environments/dev/audit").json()["entries"]] == ["snapshot.requested", "old"] + sign_in(client, world) + assert [(e["action"], e["database"]) for e in client.get("/api/environments/dev/audit").json()["entries"]] == [("snapshot.requested", "payments_dev")] + sign_in(client, world, upn="audrey@example.com", groups=[], roles=["Auditor"]) + assert len(client.get("/api/environments/dev/audit").json()["entries"]) == 3 + + +def test_storage_and_kubernetes_errors_answer_502(client, world): + me = sign_in(client, world) + world.storage.fail[("GET", "list")] = 503 + response = client.get("/api/environments/dev/databases/payments_dev/snapshots") + assert response.status_code == 502 and response.json()["error"] == "storage_unavailable" + world.kube.objects[f"{CNPG}/clusters"].clear() + response = client.post("/api/environments/dev/databases/payments_dev/snapshots", json={}, headers=write_headers(me)) + assert response.status_code == 409 and response.json()["error"] == "no_cluster" + world.kube.refuse = 403 + response = client.get("/api/environments/dev/jobs") + assert response.status_code == 502 and response.json() == {"error": "kubernetes_unavailable", "message": "Kubernetes refused: jobs.batch is forbidden"} + + +def test_validation_errors_name_the_field(client, world): + me = sign_in(client, world) + response = client.post("/api/environments/dev/databases/payments_dev/restore", json={"into": "copy"}, headers=write_headers(me)) + assert response.status_code == 422 and {f["field"] for f in response.json()["fields"]} >= {"source_environment", "snapshot", "reason"} + assert client.get("/api/environments/dev/databases/Not-A-Name!/snapshots").status_code == 422 diff --git a/tests/test_auth.py b/tests/test_auth.py new file mode 100644 index 0000000..9157a12 --- /dev/null +++ b/tests/test_auth.py @@ -0,0 +1,73 @@ +from __future__ import annotations + +from urllib.parse import parse_qs, urlsplit + +from conftest import ( + CLIENT, + IDENTITY, + PAYMENTS, + UNRELATED, + make_client, + sign_in, + write_headers, +) + +from databases_ui.app import favicon_svg, release_notes, theme_css +from databases_ui.config import Branding + + +def test_signed_out_until_signed_in(client): + assert client.get("/api/me").json() == {"error": "signed_out"} + assert client.get("/api/environments/dev/databases").status_code == 401 + + +def test_sign_in_keeps_only_the_catalogs_groups(client, world): + me = sign_in(client, world, groups=[PAYMENTS, IDENTITY, UNRELATED], roles=["Admin"]) + assert [t["id"] for t in me["teams"]] == ["payments", "identity"] and me["admin"] and not me["auditor"] + login = world.entra.token_requests[-1] + assert login["grant_type"] == ["authorization_code"] and login["client_assertion"] == ["federated-token"] and login["client_id"] == [CLIENT] + cookie = next(c for c in client.cookies.jar if c.name.startswith("__Host-databases-ui")) + assert cookie.secure and cookie.path == "/" + + +def test_a_sign_in_with_too_many_groups_is_refused(client, world): + world.entra.overage = True + response = client.get("/auth/login") + query = parse_qs(urlsplit(response.headers["location"]).query) + world.entra.challenge, world.entra.nonce = query["code_challenge"][0], query["nonce"][0] + done = client.get(f"/auth/callback?code=good-code&state={query['state'][0]}") + assert "auth_error=" in done.headers["location"] and "groups+do+not+fit" in done.headers["location"] + + +def test_another_tenant_a_bad_state_and_a_refusal(client, world): + world.entra.tenant = "99999999-2222-3333-4444-555555555555" + response = client.get("/auth/login") + query = parse_qs(urlsplit(response.headers["location"]).query) + world.entra.challenge, world.entra.nonce = query["code_challenge"][0], query["nonce"][0] + assert "another+tenant" in client.get(f"/auth/callback?code=good-code&state={query['state'][0]}").headers["location"] + assert "expired" in client.get("/auth/callback?code=good-code&state=forged").headers["location"] + assert "AADSTS50105" in client.get("/auth/callback?error=access_denied&error_description=AADSTS50105:+not+assigned").headers["location"] + + +def test_logout_needs_the_csrf_token(client, world): + me = sign_in(client, world) + assert client.post("/auth/logout").status_code == 403 + assert client.post("/auth/logout", headers=write_headers(me)).json() == {"signed_out": True} + assert client.get("/api/me").status_code == 401 + + +def test_headers_and_theme(world, env): + client = make_client(world, {**env, "DATABASES_UI_BRAND_ACCENT": "#0b6e4f", "APP_VERSION": "v0.1.0"}) + response = client.get("/healthz") + assert response.json() == {"status": "ok"} + assert "default-src 'none'" in response.headers["content-security-policy"] and response.headers["x-frame-options"] == "DENY" + assert response.headers["strict-transport-security"] == "max-age=31536000" + assert "html:root{--accent:#0b6e4f" in client.get("/theme.css").text + assert 'fill="#0b6e4f"' in client.get("/favicon.svg").text + assert sign_in(client, world)["release_notes"] == "https://github.com/MagmaMoose/databases-ui/releases/tag/v0.1.0" + + +def test_release_notes_and_branding_helpers(): + assert release_notes("pr-12") == "https://github.com/MagmaMoose/databases-ui/pull/12" and release_notes("dev") is None + assert theme_css(Branding()) == "" and "@media (prefers-color-scheme: dark)" in theme_css(Branding(accent="#000000", accent_dark="#ffffff")) + assert 'fill="#0f766e"' in favicon_svg(Branding()) diff --git a/tests/test_catalog.py b/tests/test_catalog.py new file mode 100644 index 0000000..1a4c978 --- /dev/null +++ b/tests/test_catalog.py @@ -0,0 +1,68 @@ +from __future__ import annotations + +from pathlib import Path + +import pytest + +from databases_ui.__main__ import check +from databases_ui.catalog import CatalogError, load_catalog + +EXAMPLE = Path(__file__).resolve().parents[1] / "examples" / "catalog.yaml" +GROUP = "6f1c2b7e-3a44-4d0e-9a51-2b8e0c7d9f10" +ENVS = "environments:\n - {name: dev, storage: {url: 'https://a.blob.core.windows.net/dev'}}\n - {name: prd, production: true, cluster: prod, storage: {url: 'https://a.blob.core.windows.net/prd'}}\n" + + +def test_the_example_holds_together(capsys): + assert check(EXAMPLE) == 0 + assert "4 environments, 2 teams, 8 databases granted" in capsys.readouterr().out + catalog = load_catalog(EXAMPLE.read_text()) + assert catalog.environments["prd"].cnpg_cluster == "prod" and catalog.environments["dev"].cnpg_cluster == "dev" + grant = catalog.grant({"payments"}, "acc", "payments_acc") + assert grant is not None and grant.workloads == (("deployment", "acc-payments", "payments-api"), ("deployment", "acc-payments", "payments-worker")) + assert sorted(catalog.databases("prd")) == ["keycloak_prd", "payments_prd"] + assert catalog.grant({"identity"}, "prd", "keycloak") is None + + +def test_groups_select_teams(): + catalog = load_catalog(ENVS + f"teams:\n - {{id: a, name: A, groups: ['{GROUP.upper()}']}}\n") + assert catalog.groups == {GROUP} and [t.id for t in catalog.teams_of(frozenset({GROUP}))] == ["a"] + + +@pytest.mark.parametrize( + ("text", "problem"), + [ + ("environments: []\n", "environments"), + ("- not a mapping\n", "environments"), + ("environments: [\n", "not YAML"), + ("environments:\n - {name: dev, storage: {url: 'ftp://a/b'}}\n", "must be https"), + ("environments:\n - {name: dev, storage: {url: 'https://a.blob.core.windows.net'}}\n", "the container's URL"), + ("environments:\n - {name: dev, storage: {url: 'http://azurite.storage.svc:10000/acct/dev'}, kubernetes: elsewhere}\n", "kubernetes"), # DevSkim: ignore DS137138 - a local emulator's address + ("environments:\n - {name: Dev, storage: {url: 'https://a.blob.core.windows.net/x'}}\n", "name"), + (ENVS + " - {name: dev, storage: {url: 'https://a.blob.core.windows.net/x'}}\n", "'dev' is listed twice"), + ("environments:\n - {name: dev, cloneFrom: [acc], storage: {url: 'https://a.blob.core.windows.net/x'}}\n", "unknown environment 'acc'"), + ("environments:\n - {name: dev, cloneFrom: [dev], storage: {url: 'https://a.blob.core.windows.net/x'}}\n", "lists itself"), + (ENVS + "teams:\n - {id: a, name: A, groups: [not-a-guid]}\n", "not a group object id"), + (ENVS + f"teams:\n - {{id: a, name: A, groups: ['{GROUP}']}}\n - {{id: a, name: B, groups: ['{GROUP}']}}\n", "team 'a' is listed twice"), + (ENVS + f"teams:\n - {{id: a, name: A, groups: ['{GROUP}'], databases: [{{name: x, environments: [qa]}}]}}\n", "unknown environment 'qa'"), + (ENVS + f"teams:\n - {{id: a, name: A, groups: ['{GROUP}'], databases: [{{name: 'Bad Name'}}]}}\n", "not a database name"), + (ENVS + f"teams:\n - {{id: a, name: A, groups: ['{GROUP}'], databases: [{{name: x, workloads: [pod/a/b]}}]}}\n", "deployment//"), + (ENVS + f"teams:\n - {{id: a, name: A, groups: ['{GROUP}'], extra: 1}}\n", "extra"), + ], +) +def test_problems_are_named(text, problem): + with pytest.raises(CatalogError) as err: + load_catalog(text) + assert any(problem in p for p in err.value.problems), err.value.problems + + +def test_another_cluster_is_reached_with_its_own_token(): + catalog = load_catalog("environments:\n - name: dev\n storage: {url: 'https://a.blob.core.windows.net/dev'}\n kubernetes: {server: 'https://dev.example.test:6443', caFile: /ca.crt, tokenFile: /token}\n") + kube = catalog.environments["dev"].kubernetes + assert kube.server == "https://dev.example.test:6443" and kube.token_file == "/token" and catalog.environments["dev"].runs_jobs + + +def test_check_reports_every_problem(tmp_path, capsys): + (tmp_path / "bad.yaml").write_text(ENVS + "teams:\n - {id: a, name: A, groups: [x]}\n") + assert check(tmp_path / "bad.yaml") == 1 + assert "not a group object id" in capsys.readouterr().err + assert check(tmp_path / "missing.yaml") == 1 diff --git a/tests/test_config.py b/tests/test_config.py new file mode 100644 index 0000000..b6f6966 --- /dev/null +++ b/tests/test_config.py @@ -0,0 +1,69 @@ +from __future__ import annotations + +import pytest + +from databases_ui.config import ConfigError, load_config + + +def test_a_complete_environment_loads(env): + cfg = load_config(env) + assert cfg.redirect_uri == "https://databases.example.test/auth/callback" and cfg.secure_cookies + assert sorted(cfg.catalog.environments) == ["acc", "dev", "prd"] and cfg.job_service_account == "databases-ui-job" + assert cfg.storage_sas == "" and cfg.static_dir is None and cfg.session_seconds == 8 * 3600 + + +@pytest.mark.parametrize( + ("change", "message"), + [ + ({"AZURE_TENANT_ID": "nope"}, "AZURE_TENANT_ID must be a GUID"), + ({"AZURE_FEDERATED_TOKEN_FILE": ""}, "set AZURE_FEDERATED_TOKEN_FILE"), + ({"DATABASES_UI_SESSION_KEY": "short"}, "at least 32 characters"), + ({"DATABASES_UI_PUBLIC_ORIGIN": "http://databases.example.test"}, "must be https"), # DevSkim: ignore DS137138 - deliberately invalid input; the test asserts config rejects it + ({"DATABASES_UI_PUBLIC_ORIGIN": "https://databases.example.test/ui"}, "with no path"), + ({"AZURE_AUTHORITY_HOST": "http://login.example.test"}, "AZURE_AUTHORITY_HOST must be an https host"), # DevSkim: ignore DS137138 - deliberately invalid input + ({"DATABASES_UI_CATALOG": ""}, "DATABASES_UI_CATALOG is required"), + ({"DATABASES_UI_CATALOG": "/nowhere/catalog.yaml"}, "cannot read the catalog"), + ({"DATABASES_UI_JOB_IMAGE": ""}, "DATABASES_UI_JOB_IMAGE is required"), + ({"DATABASES_UI_JOB_SERVICE_ACCOUNT": "Not_A_Name"}, "service account name"), + ({"DATABASES_UI_STORAGE_SAS": "sv=2022-11-02&sig=x"}, "needs both"), + ({"DATABASES_UI_STORAGE_SAS": "sv=2022-11-02", "DATABASES_UI_STORAGE_SAS_SECRET": "sas/token"}, "a SAS token"), + ({"DATABASES_UI_STORAGE_SAS": "sv=2022-11-02&sig=x", "DATABASES_UI_STORAGE_SAS_SECRET": "no-key"}, "/"), + ({"AZURE_FEDERATED_TOKEN_FILE": "", "AZURE_CLIENT_SECRET": "s"}, "the Jobs reach storage through workload identity"), + ({"DATABASES_UI_ADMIN_ROLE": "has spaces"}, "DATABASES_UI_ADMIN_ROLE must be an app role value"), + ({"DATABASES_UI_SESSION_HOURS": "48"}, "between 1 and 24"), + ({"PORT": "eighty"}, "whole numbers"), + ({"DATABASES_UI_BRAND_ACCENT": "teal"}, "#rrggbb"), + ], +) +def test_refused(env, change, message): + with pytest.raises(ConfigError, match=message): + load_config({**env, **change}) + + +def test_refused_without_an_origin(env): + del env["DATABASES_UI_PUBLIC_ORIGIN"] + with pytest.raises(ConfigError, match="DATABASES_UI_PUBLIC_ORIGIN is required"): + load_config(env) + + +def test_a_broken_catalog_stops_startup(env, tmp_path): + (tmp_path / "bad.yaml").write_text("environments: []\n") + with pytest.raises(ConfigError, match="does not hold together"): + load_config({**env, "DATABASES_UI_CATALOG": str(tmp_path / "bad.yaml")}) + + +def test_secrets_from_files_and_a_sas_with_a_client_secret(env, tmp_path): + (tmp_path / "sas").write_text("?sv=2022-11-02&sig=abc\n") + (tmp_path / "key").write_text("s" * 40) + cfg = load_config({ + **env, "AZURE_FEDERATED_TOKEN_FILE": "", "AZURE_CLIENT_SECRET": "secret", "DATABASES_UI_SESSION_KEY": "", "DATABASES_UI_SESSION_KEY_FILE": str(tmp_path / "key"), + "DATABASES_UI_STORAGE_SAS_FILE": str(tmp_path / "sas"), "DATABASES_UI_STORAGE_SAS_SECRET": "databases-ui-storage/sas", "DATABASES_UI_BRAND_ACCENT": "#0B6E4F", + }) # fmt: skip + assert cfg.storage_sas == "sv=2022-11-02&sig=abc" and cfg.session_key == b"s" * 40 and cfg.client_secret == "secret" + assert cfg.branding.accent == "#0b6e4f" + with pytest.raises(ConfigError, match="cannot read DATABASES_UI_SESSION_KEY_FILE"): + load_config({**env, "DATABASES_UI_SESSION_KEY": "", "DATABASES_UI_SESSION_KEY_FILE": str(tmp_path / "missing")}) + + +def test_plain_http_only_on_loopback(env): + assert load_config({**env, "DATABASES_UI_PUBLIC_ORIGIN": "http://localhost:8080"}).secure_cookies is False # DevSkim: ignore DS162092 - loopback is allowed for local development diff --git a/tests/test_runner.py b/tests/test_runner.py new file mode 100644 index 0000000..33ecd9a --- /dev/null +++ b/tests/test_runner.py @@ -0,0 +1,149 @@ +"""The Job's own work, with stand-ins for pg_dump, pg_restore and psql on PATH.""" + +from __future__ import annotations + +import asyncio +import hashlib +import json +import os +from pathlib import Path +from typing import Any + +import httpx +import pytest +from conftest import AUTHORITY, STORAGE, TENANT, FakeKube, World + +from databases_ui import runner + +APPS = "/apis/apps/v1/namespaces/dev-payments/deployments" +SNAPSHOT = "snapshots/payments_dev/20261023T140000Z-abcdef.dump" + + +@pytest.fixture +def tools(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> Path: + """pg_dump writes DUMP_BYTES bytes (or fails with DUMP_FAIL), pg_restore keeps what it read and + its arguments, psql answers 2 and keeps its SQL.""" + bin_dir = tmp_path / "bin" + bin_dir.mkdir() + scripts = { + "pg_dump": '#!/bin/sh\nprintf PGDMP\nhead -c "${DUMP_BYTES:-100}" /dev/zero | tr "\\000" x\nif [ -n "$DUMP_FAIL" ]; then echo "pg_dump: error: $DUMP_FAIL" >&2; exit 1; fi\n', + "pg_restore": '#!/bin/sh\necho "$@" > "$OUT/restore-args"\ncat > "$OUT/restored"\nif [ -n "$RESTORE_FAIL" ]; then echo "pg_restore: error: $RESTORE_FAIL" >&2; exit 1; fi\n', + "psql": '#!/bin/sh\nfor last; do :; done\necho "$last" >> "$OUT/psql"\nif [ -n "$PSQL_FAIL" ]; then echo "psql: error: $PSQL_FAIL" >&2; exit 2; fi\necho 2\n', + } + for name, body in scripts.items(): + (bin_dir / name).write_text(body) + (bin_dir / name).chmod(0o755) + out = tmp_path / "out" + out.mkdir() + monkeypatch.setenv("PATH", f"{bin_dir}{os.pathsep}{os.environ['PATH']}") + monkeypatch.setenv("OUT", str(out)) + monkeypatch.setattr(runner, "TERMINATION_LOG", tmp_path / "termination-log") + monkeypatch.setattr(runner, "WAIT_SECONDS", 2) + monkeypatch.setattr(runner, "REACH_SECONDS", 1) + return out + + +def job_env(tmp_path: Path, action: str, **extra: str) -> dict[str, str]: + return { + "DBUI_ACTION": action, + "DBUI_JOB": f"dbui-{action}-12345678", + "DBUI_ENVIRONMENT": "dev", + "DBUI_DATABASE": "payments_dev", + "DBUI_REQUESTED_BY": "alice@example.com", + "DBUI_BLOB_URL": f"{STORAGE}/dev", + "DBUI_BLOB": SNAPSHOT, + "DBUI_AUDIT_URL": f"{STORAGE}/dev", + "DBUI_STORAGE_SAS": "sv=2022-11-02&sig=test", + "PGDATABASE": "payments_dev", + **extra, + } + + +def run(world: World, env: dict[str, str], kube: FakeKube | None = None) -> tuple[int, dict[str, Any]]: + code = asyncio.run(runner.run(env, transport=httpx.MockTransport(world.handler), kube_transport=httpx.MockTransport((kube or world.kube).handle))) + return code, json.loads(runner.TERMINATION_LOG.read_text()) + + +def test_a_snapshot_streams_pg_dump_into_blocks_and_commits_once_it_succeeded(world, tools, tmp_path, monkeypatch): + monkeypatch.setenv("DUMP_BYTES", str(20 * 1024 * 1024)) + env = job_env(tmp_path, "snapshot", DBUI_METADATA=json.dumps({"createdby": "alice@example.com", "note": "naïve note"})) + code, outcome = run(world, env) + assert code == 0 and outcome["result"] == "succeeded" and outcome["bytes"] == 5 + 20 * 1024 * 1024 + blob = world.storage.blobs[f"dev/{SNAPSHOT}"] + assert blob.data.startswith(b"PGDMP") and len(blob.data) == outcome["bytes"] + assert blob.metadata["sha256"] == hashlib.sha256(blob.data).hexdigest() == outcome["sha256"] + assert blob.metadata["note"] == "na%C3%AFve%20note" and blob.metadata["size"] == str(outcome["bytes"]) + # Three blocks of at most 8 MiB, then the block list. + assert [c for c in world.storage.calls if c[1].startswith("dev/snapshots")] == [("PUT", f"dev/{SNAPSHOT}?block")] * 3 + [("PUT", f"dev/{SNAPSHOT}?blocklist")] + assert [(e["action"], e["actor"], e["job"]) for e in world.storage.audit("dev")] == [("snapshot.succeeded", "alice@example.com", "dbui-snapshot-12345678")] + + +def test_a_failed_pg_dump_commits_nothing(world, tools, tmp_path, monkeypatch): + monkeypatch.setenv("DUMP_FAIL", "permission denied for table secrets") + code, outcome = run(world, job_env(tmp_path, "snapshot")) + assert code == 1 and outcome["result"] == "failed" and "permission denied for table secrets" in outcome["reason"] + assert f"dev/{SNAPSHOT}" not in world.storage.blobs + assert world.storage.audit("dev")[0]["action"] == "snapshot.failed" and "permission denied" in world.storage.audit("dev")[0]["detail"] + + +def test_storage_through_workload_identity(world, tools, tmp_path): + token = tmp_path / "azure-token" + token.write_text("projected-token") + env = job_env(tmp_path, "snapshot", AZURE_TENANT_ID=TENANT, AZURE_CLIENT_ID="aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee", AZURE_AUTHORITY_HOST=AUTHORITY, AZURE_FEDERATED_TOKEN_FILE=str(token)) + del env["DBUI_STORAGE_SAS"] + code, _ = run(world, env) + assert code == 0 and f"dev/{SNAPSHOT}" in world.storage.blobs + sent = world.entra.token_requests[0] + assert sent["client_assertion"] == ["projected-token"] and sent["scope"] == ["https://storage.azure.com/.default"] + + +def test_restore_in_place_scales_the_workloads_down_and_back(world, tools, tmp_path): + world.snapshot("dev", "payments_dev", "20261023T140000Z-abcdef", data=b"PGDMP" + b"y" * 3_000_000) + world.kube.put(APPS, {"metadata": {"name": "api"}, "spec": {"replicas": 3, "selector": {"matchLabels": {"app": "api"}}}}) + env = job_env(tmp_path, "restore", DBUI_SCALE=json.dumps([["deployment", "dev-payments", "api"], ["statefulset", "dev-payments", "gone"]])) + code, outcome = run(world, env) + assert code == 0 and outcome == {"result": "succeeded", "bytes": 3_000_005, "seconds": outcome["seconds"]} + assert (tools / "restored").read_bytes() == b"PGDMP" + b"y" * 3_000_000 + assert (tools / "restore-args").read_text().split() == ["--format=custom", "--clean", "--if-exists", "--no-owner", "--no-acl", "--single-transaction", "--no-password", "--dbname=payments_dev"] + assert "pg_terminate_backend" in (tools / "psql").read_text() + patches = [json.loads(json.dumps(c)) for c in world.kube.calls if c[0] == "PATCH"] + assert patches == [["PATCH", f"{APPS}/api"], ["PATCH", f"{APPS}/api"]] + api = world.kube.get(APPS, "api") + assert api["spec"]["replicas"] == 3 and "databases-ui/replicas-before-restore" not in (api["metadata"].get("annotations") or {}) + assert world.storage.audit("dev")[0]["action"] == "restore.succeeded" + + +def test_a_failed_restore_still_scales_back(world, tools, tmp_path, monkeypatch): + monkeypatch.setenv("RESTORE_FAIL", "must be owner of table orders") + world.snapshot("dev", "payments_dev", "20261023T140000Z-abcdef") + # An earlier restore died before scaling back: the annotation has the real count. + world.kube.put(APPS, {"metadata": {"name": "api", "annotations": {"databases-ui/replicas-before-restore": "4"}}, "spec": {"replicas": 0, "selector": {"matchLabels": {"app": "api"}}}}) + code, outcome = run(world, job_env(tmp_path, "restore", DBUI_SCALE=json.dumps([["deployment", "dev-payments", "api"]]))) + assert code == 1 and "nothing changed" in outcome["reason"] and "must be owner of table orders" in outcome["reason"] + assert world.kube.get(APPS, "api")["spec"]["replicas"] == 4 + + +def test_restore_waits_for_pods_to_go_and_gives_up(world, tools, tmp_path): + world.snapshot("dev", "payments_dev", "20261023T140000Z-abcdef") + world.kube.put(APPS, {"metadata": {"name": "api"}, "spec": {"replicas": 2, "selector": {"matchLabels": {"app": "api"}}}}) + world.kube.put("/api/v1/namespaces/dev-payments/pods", {"metadata": {"name": "api-1", "labels": {"app": "api"}}}) + code, outcome = run(world, job_env(tmp_path, "restore", DBUI_SCALE=json.dumps([["deployment", "dev-payments", "api"]]))) + assert code == 1 and "still running" in outcome["reason"] + assert not (tools / "restored").exists() and world.kube.get(APPS, "api")["spec"]["replicas"] == 2 + + +def test_restore_into_a_copy_waits_for_the_database(world, tools, tmp_path, monkeypatch): + world.snapshot("dev", "payments_dev", "20261023T140000Z-abcdef") + code, _ = run(world, job_env(tmp_path, "restore", DBUI_WAIT_FOR_DATABASE="1", PGDATABASE="payments_dev_copy")) + assert code == 0 and (tools / "psql").read_text().splitlines()[0] == "select 1" + assert (tools / "restore-args").read_text().split()[-1] == "--dbname=payments_dev_copy" + monkeypatch.setenv("PSQL_FAIL", "database does not exist") + code, outcome = run(world, job_env(tmp_path, "restore", DBUI_WAIT_FOR_DATABASE="1", PGDATABASE="payments_dev_copy")) + assert code == 1 and "never became reachable" in outcome["reason"] + + +def test_a_missing_snapshot_or_action_fails_cleanly(world, tools, tmp_path): + code, outcome = run(world, job_env(tmp_path, "restore")) + assert code == 1 and "404" in outcome["reason"] + code, outcome = run(world, job_env(tmp_path, "vacuum")) + assert code == 1 and outcome["reason"] == "unknown action 'vacuum'" diff --git a/uv.lock b/uv.lock new file mode 100644 index 0000000..483506c --- /dev/null +++ b/uv.lock @@ -0,0 +1,733 @@ +version = 1 +revision = 3 +requires-python = ">=3.12" + +[[package]] +name = "annotated-doc" +version = "0.0.5" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/5a/8e/38aa427ed5402449e226975b649c5dc73ccadfefeb95e6aecb8f8ea4b6b6/annotated_doc-0.0.5.tar.gz", hash = "sha256:c7e58ce09192557605d8bbd92836d7e1d520ac9580096042c0bfd197efacf1bb", size = 10758, upload-time = "2026-07-28T13:50:58.129Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/3e/30/e900b21425a860e195f32e37657aa1f7c7f2b1bfb26f03ca209b90933c06/annotated_doc-0.0.5-py3-none-any.whl", hash = "sha256:117bac03a25ede5df5440e855b32d556049ca169ead221505badf432fed4b101", size = 5302, upload-time = "2026-07-28T13:50:57.239Z" }, +] + +[[package]] +name = "annotated-types" +version = "0.8.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/5f/56/a8120250d128bed162cd73c76d45f6ef9991f3e068f62a8ee060afa3104a/annotated_types-0.8.0.tar.gz", hash = "sha256:13b2beaad985e05e2d6407ee4c4f35590b11f8d693a258a561055cac8f64cab7", size = 15893, upload-time = "2026-07-23T20:16:13.995Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/99/91/8acff4f5e50511b911bbccb72b8628a49c68ce14148cd9f6431094859a90/annotated_types-0.8.0-py3-none-any.whl", hash = "sha256:f072f4d804ea359e4eaf198b1af7a8b0943881a87f31bb764f8bf219bb9419e0", size = 13427, upload-time = "2026-07-23T20:16:12.938Z" }, +] + +[[package]] +name = "anyio" +version = "4.15.1" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "idna" }, + { name = "typing-extensions", marker = "python_full_version < '3.15'" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/a9/d2/f4d173e22df740bc37b1db102b386ba719b66e95b0f0d751f556b387e6d2/anyio-4.15.1.tar.gz", hash = "sha256:9f28306018cbd6d329e64a36d58256edff76dd996fe423bc957326e578b82a94", size = 276966, upload-time = "2026-09-05T10:42:39.44Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/12/b8/4bd346e22b28902df4d651910f5242c28d84e4a5c2435ca5c3f797ed7e2e/anyio-4.15.1-py3-none-any.whl", hash = "sha256:6152fdbbf9a77fdec97731721bebf7c4c44f7c29b424b0065826173efc7ed101", size = 132079, upload-time = "2026-09-05T10:42:37.923Z" }, +] + +[[package]] +name = "certifi" +version = "2026.10.23" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/fd/11/b524cbd9bbdaca58608e4cf4053fd463417549e1959fa8d3aa18319f9555/certifi-2026.10.23.tar.gz", hash = "sha256:a9895e6e2758b371e0545e321a3a8fd1fcfd9829ada8824a936dfb16aaaf36cd", size = 136225, upload-time = "2026-10-23T11:36:16.478Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/32/d1/a3652fe2c19134d0d15922177821d863cbd7e842d53a21bbe7e8e3a1b5ac/certifi-2026.10.23-py3-none-any.whl", hash = "sha256:e9b54de76e530bb6cf0ccd036787103acb58fd42ba930ea8bf948ddbaa2f61d1", size = 135082, upload-time = "2026-10-23T11:36:14.763Z" }, +] + +[[package]] +name = "cffi" +version = "2.1.1" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "pycparser", marker = "implementation_name != 'PyPy'" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/9e/ef/008a1939e372c06329a3fce4279c02f328488f3526744906eeec3da7ad5f/cffi-2.1.1.tar.gz", hash = "sha256:dd31f52ea1086513bb9df30f8fcee9b8918323ae067a3d5b78bc826a000712be", size = 530807, upload-time = "2026-08-03T21:21:18.939Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/10/69/43965eccfdead3b9220015fd1320e117be8c6ed01a62ffab76eeb752f5d5/cffi-2.1.1-cp312-cp312-macosx_10_15_x86_64.whl", hash = "sha256:c8c69575568085ba0b1b10c0249d779a214aea6f6522e949a0fc9fb0fcb449d0", size = 184821, upload-time = "2026-08-03T21:19:44.887Z" }, + { url = "https://files.pythonhosted.org/packages/54/7d/16e5a096677b5e313ca80cd5e5170efa3ea44624a82bb111925522da64b1/cffi-2.1.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:f81b3b8f3d4e343550fa4baa0e479bba9f2d29ce9c2e9b51d1ce1718d7442fcf", size = 184719, upload-time = "2026-08-03T21:19:46.129Z" }, + { url = "https://files.pythonhosted.org/packages/56/e6/8941622732edec876dd17d0453dce07317ae96db34f2ec1436c9d3785986/cffi-2.1.1-cp312-cp312-manylinux1_i686.manylinux2014_i686.manylinux_2_17_i686.manylinux_2_5_i686.whl", hash = "sha256:811bd1e21d32de12efca32393a0ab3f5133b54fce9bd44b8bd77ab07da14bf6a", size = 214799, upload-time = "2026-08-03T21:19:47.218Z" }, + { url = "https://files.pythonhosted.org/packages/44/de/f98430906df1545ffde0d543dd124a7a439bc2cd32b36b9c53f805df7333/cffi-2.1.1-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:68e62fe11f30d5ca8289242866f0a5291402d8529ca2178ab8afc5c9694ae890", size = 222389, upload-time = "2026-08-03T21:19:48.331Z" }, + { url = "https://files.pythonhosted.org/packages/6a/5b/717f1526b9957b34456313c31645c5b82b8fb5c3fe9e4752999be7128bfc/cffi-2.1.1-cp312-cp312-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl", hash = "sha256:4a7c934f7360e8cd64fe9efadcbd10c7c6364f531e432b9a4bf5ccbc9e0e8b50", size = 210249, upload-time = "2026-08-03T21:19:49.543Z" }, + { url = "https://files.pythonhosted.org/packages/64/b3/f8aa4f3e34986c7e4ec45072d1b1b9dd295b6b18007b45518d79726dd725/cffi-2.1.1-cp312-cp312-manylinux2014_s390x.manylinux_2_17_s390x.whl", hash = "sha256:3143d81e29e1e20a9ce10901ec369012947876596f75a222235965f2b7ae832e", size = 208775, upload-time = "2026-08-03T21:19:50.918Z" }, + { url = "https://files.pythonhosted.org/packages/b1/db/dceb9dd5b231e1da801793f8acc9f3c52a7e1afe40bb1aae37e02b0faad5/cffi-2.1.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:c1453022f490d2459a11819d83ad1d586e9ff65a12ac3e705ffebd46d3685dcf", size = 221822, upload-time = "2026-08-03T21:19:52.054Z" }, + { url = "https://files.pythonhosted.org/packages/a0/d2/6cd24ae3be000a634109c247d1475d62e5616d0dc78c82770942ec384248/cffi-2.1.1-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:208f941bb9d18e768138677f0a6d2ce01f590df56043dda1df1535ac57c88517", size = 225232, upload-time = "2026-08-03T21:19:53.109Z" }, + { url = "https://files.pythonhosted.org/packages/cb/52/3fa190537004dd7f0ab860a6dc7c0175b8667f68d1e618a46f5498d30250/cffi-2.1.1-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:210019b6c7cf07f081b4c54635c8cf744377001350e29cc0f81c4377b4797735", size = 223597, upload-time = "2026-08-03T21:19:54.515Z" }, + { url = "https://files.pythonhosted.org/packages/80/fb/0bb75b7039588c074b37ae99f40d9bfddf990ecb2fbc346ebccd2e56b9be/cffi-2.1.1-cp312-cp312-win32.whl", hash = "sha256:046bfc24911b37851ee1b51aab8bffe713d89c68c6a057b09484ce9fd5f69b4e", size = 175292, upload-time = "2026-08-03T21:19:55.566Z" }, + { url = "https://files.pythonhosted.org/packages/d9/79/615cc094e2fb508cade7de88d3b4f6c4ec2bab695c97bce9153dc65aadf5/cffi-2.1.1-cp312-cp312-win_amd64.whl", hash = "sha256:f53e442b08449d42821fa4a4fba000095af9f62742a500f978a9f557ec44339a", size = 185919, upload-time = "2026-08-03T21:19:56.89Z" }, + { url = "https://files.pythonhosted.org/packages/70/c6/d0ea84713fe46b243a436a18fcd47d639732747e21635c8a27191b06dc30/cffi-2.1.1-cp312-cp312-win_arm64.whl", hash = "sha256:7bde5e4cc5c10140859842b9d383af292b22639a4dffb725314baf45968cef80", size = 180093, upload-time = "2026-08-03T21:19:58.155Z" }, + { url = "https://files.pythonhosted.org/packages/9d/f4/035513d4117049066b4779dc3b7c0c0fdad175fa13731c9f4003f1cd1478/cffi-2.1.1-cp313-cp313-ios_13_0_arm64_iphoneos.whl", hash = "sha256:b5bdfd1c873d4e093aabc0ca84c4ca6dbc4f752afb5c86f146d9742580c9da2e", size = 194248, upload-time = "2026-08-03T21:19:59.399Z" }, + { url = "https://files.pythonhosted.org/packages/76/af/2aeb4dbb5fc41a04161ae9ff1518de7cec08e164f44a8ce6a4cf7fd2cd1d/cffi-2.1.1-cp313-cp313-ios_13_0_arm64_iphonesimulator.whl", hash = "sha256:31348097ff5bbe827ccc41795d4dd099d9f0625e7def00ee653c137a490c2a6c", size = 196908, upload-time = "2026-08-03T21:20:00.746Z" }, + { url = "https://files.pythonhosted.org/packages/a7/46/2e5fdde8555706dd98139a910ca11be02809f3f605ce956f655d0214e100/cffi-2.1.1-cp313-cp313-macosx_10_15_x86_64.whl", hash = "sha256:9d2055050ea716bd38b7f7f1579c275386646b4894c155a3e2f3cd62ed41b7c6", size = 184805, upload-time = "2026-08-03T21:20:02.02Z" }, + { url = "https://files.pythonhosted.org/packages/55/41/4c7042f317b9217502988f0873af87e16ad606dc20f84e546e3e6ce9764c/cffi-2.1.1-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:19ee6127ee34de7d83ce3d371ebc5ed91addbdcc39f9ab15ce4eb35a4e534971", size = 184764, upload-time = "2026-08-03T21:20:03.141Z" }, + { url = "https://files.pythonhosted.org/packages/43/1f/1c3d90d91811c8f86ced9ed637956c54bfe5b79ca98fe976d7f8c8979f6b/cffi-2.1.1-cp313-cp313-manylinux1_i686.manylinux2014_i686.manylinux_2_17_i686.manylinux_2_5_i686.whl", hash = "sha256:6a8dddef476fab96d066d578fc88526767b836ab5ab21754e1d5bf3879c31c7c", size = 214722, upload-time = "2026-08-03T21:20:04.377Z" }, + { url = "https://files.pythonhosted.org/packages/37/6f/3b5ce4c3b2192d250f04908f2bfd91ef34552ec8f7716a5d4abdb8d67bb2/cffi-2.1.1-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:f16c709686a78c727bbbf059f92b0bf41c6fc60deec706d2dc19f529175a6125", size = 222369, upload-time = "2026-08-03T21:20:05.544Z" }, + { url = "https://files.pythonhosted.org/packages/02/10/4b3c75dde3d9663c9e02ba05c2668b954f671d4bbe346413ca8c696b295a/cffi-2.1.1-cp313-cp313-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl", hash = "sha256:fcd22650c908d7b7da162bbfaab594a1227a15d1643a98c68b122ac642fa2264", size = 210175, upload-time = "2026-08-03T21:20:06.75Z" }, + { url = "https://files.pythonhosted.org/packages/df/62/14f74b9543e605d17701dc797b815958b8bb70b7624ce1b832ddad48ed6c/cffi-2.1.1-cp313-cp313-manylinux2014_s390x.manylinux_2_17_s390x.whl", hash = "sha256:aa9511c62d14da7aacc9b4bf51f3f697a621e83b2d6919008243c3aad168eea3", size = 208670, upload-time = "2026-08-03T21:20:08.04Z" }, + { url = "https://files.pythonhosted.org/packages/95/95/86342356ff5953b3fb06f7ef7c5bee212d45e770abc7218d451b9148313c/cffi-2.1.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:a931079504ecc49efed7744c476a5c343a92fabf66dec2db95edb1b2fdc770e2", size = 221824, upload-time = "2026-08-03T21:20:09.274Z" }, + { url = "https://files.pythonhosted.org/packages/eb/ff/7b3429ff53aafe931ed8a5fc69f481bbef7ba6de87ddcbb63d08f483f613/cffi-2.1.1-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:a2d7755bef5a12ed488f4ef1f1b69ee9191d7396083b755a5d2295f6edb4768b", size = 225148, upload-time = "2026-08-03T21:20:10.7Z" }, + { url = "https://files.pythonhosted.org/packages/34/34/a95870b9221e09cf4f2ce3178b1a210abdfe63a1bd357da940418d7b8d15/cffi-2.1.1-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:e0bcb7e0f677f543555d2adff3bf19c05f66cdb4796e5ff602442ab2fe3c4ef7", size = 223564, upload-time = "2026-08-03T21:20:12.165Z" }, + { url = "https://files.pythonhosted.org/packages/70/ea/839b50531021a647fb5e929f72cf97bc1ff702b5472166164b5b6e76b851/cffi-2.1.1-cp313-cp313-win32.whl", hash = "sha256:334644fbac4eff73d985a17a91226df55d0f394160c4cfb880e084c8f7161cac", size = 175263, upload-time = "2026-08-03T21:20:13.559Z" }, + { url = "https://files.pythonhosted.org/packages/60/a6/8b149b2c3f2e11aaa1618ef64500b45f50f22c57a977a4dff1aff1f91042/cffi-2.1.1-cp313-cp313-win_amd64.whl", hash = "sha256:1aa5645c30469b09530c4ebca77ebf8f17618293c58f8549cb1a543a50236e7d", size = 185688, upload-time = "2026-08-03T21:20:14.69Z" }, + { url = "https://files.pythonhosted.org/packages/01/9a/11f687cb39d6a3504060d5242f04f48c735afb4d3d533958a20594890cb2/cffi-2.1.1-cp313-cp313-win_arm64.whl", hash = "sha256:63bbfd5ded17c4840ac07cd8f1c21ba9d9708141f840b324f422f41b207e3973", size = 180078, upload-time = "2026-08-03T21:20:15.917Z" }, + { url = "https://files.pythonhosted.org/packages/d3/7b/d6bbf82b8b96e7391438898c42f5bd96dd02030fd5b64937d248220003e2/cffi-2.1.1-cp314-cp314-ios_13_0_arm64_iphoneos.whl", hash = "sha256:7dbb61fe3a7699468030f71bbe5f8a0e326a151daa91beb11a6fc1f980c55e1c", size = 194064, upload-time = "2026-08-03T21:20:17.148Z" }, + { url = "https://files.pythonhosted.org/packages/94/e6/bcc91b283be94735e268487a054004f0aa19947b6348fa367db53230abc8/cffi-2.1.1-cp314-cp314-ios_13_0_arm64_iphonesimulator.whl", hash = "sha256:f24fb43132a4c6b4cb4eb029492919b2db645be6808d738f244fd146c03c32cb", size = 196720, upload-time = "2026-08-03T21:20:18.268Z" }, + { url = "https://files.pythonhosted.org/packages/d9/99/c4b0c17cacdc9c3b8f280026286a9826d6a208c0f047591a3c3ce99b91fd/cffi-2.1.1-cp314-cp314-macosx_10_15_x86_64.whl", hash = "sha256:d28630f5854ab07ab1fd4aba756de52326c82e6be15d414b12793f1975048b54", size = 184964, upload-time = "2026-08-03T21:20:19.708Z" }, + { url = "https://files.pythonhosted.org/packages/b3/a9/9db617d05d7367c1ad0ab00b3aa6e6f9281edd689b4ee9ea0e5a84e89c97/cffi-2.1.1-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:661c298b4821edebead0c91edd2b00374d67ad7c5a1f7a91d4442633b79d6a72", size = 184962, upload-time = "2026-08-03T21:20:20.833Z" }, + { url = "https://files.pythonhosted.org/packages/67/b8/b42132ca113dc567d37684437b46ca1dafc885902b02a110a02d5b511857/cffi-2.1.1-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:58acb8ab8e295e6c5ea12f888cbb13cf21511ef2a3303a23f4325c29d17fe5c1", size = 222328, upload-time = "2026-08-03T21:20:22.118Z" }, + { url = "https://files.pythonhosted.org/packages/80/10/c5c0cbf0a657aecf59ef511409734230bf556f05a0d6c9eed7aa5c0a0166/cffi-2.1.1-cp314-cp314-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl", hash = "sha256:456a61fa52d579ebf9df2e9552ead5129855dbaff6c1e5a9b1bc408809bdc062", size = 209985, upload-time = "2026-08-03T21:20:23.401Z" }, + { url = "https://files.pythonhosted.org/packages/d5/6c/bfa0b87b03b9238148beca990292843c9396ba069b54496596594173de7b/cffi-2.1.1-cp314-cp314-manylinux2014_s390x.manylinux_2_17_s390x.whl", hash = "sha256:a4f00aa42f75d6e4595e8866e748cc1705adc0cddfeb2ca86d0d03993d63ba03", size = 208530, upload-time = "2026-08-03T21:20:24.628Z" }, + { url = "https://files.pythonhosted.org/packages/e9/02/4e7d553a7ac4b4238b38b3c1b80d486e9d4436f8d2acbf87a0997fe3f402/cffi-2.1.1-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:b0431303acaea1089ad4b3e9ce4e6518193def1118d4073ca848635ee4ea2e96", size = 221525, upload-time = "2026-08-03T21:20:25.758Z" }, + { url = "https://files.pythonhosted.org/packages/82/1d/a4aaf9babd75acb4d5f223bff71533bee748dd770a382619a798960ee9ba/cffi-2.1.1-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:64faea20f4e2613363a1a9b9c7dd73058f3ecd00133a511e72ad7c511658f527", size = 225053, upload-time = "2026-08-03T21:20:26.985Z" }, + { url = "https://files.pythonhosted.org/packages/81/10/5dc0e7bdd18e22107054288283380fc97a06ae3f1656a106908d666a3c88/cffi-2.1.1-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:5c58fe613dc5e5336357eff555824a314d8e43282600435c8d1cb6a7a2fedd13", size = 223213, upload-time = "2026-08-03T21:20:28.277Z" }, + { url = "https://files.pythonhosted.org/packages/0b/e9/d0061c364cde06ee43168a0d076ac1da512cbc380d44767b844ba34fe2b6/cffi-2.1.1-cp314-cp314-win32.whl", hash = "sha256:1a18a57b58cfb21fc28d72e876acf10eaed67a1ed96226f92af4df681d571c4c", size = 177682, upload-time = "2026-08-03T21:20:44.288Z" }, + { url = "https://files.pythonhosted.org/packages/a7/06/1c3e01e3ba14c39f6d10bfbac52753b7e22259e38088e5cfe1d704918690/cffi-2.1.1-cp314-cp314-win_amd64.whl", hash = "sha256:3222ba5d678f80a030e6afbcc33dc1ae5cb45facabb61cee2c7016b8432fde48", size = 187949, upload-time = "2026-08-03T21:20:45.623Z" }, + { url = "https://files.pythonhosted.org/packages/87/5b/da4e39efe18eeb89cf580ea9cfc66b6a7c3eadb808fc0cc1d3a295cb5a5d/cffi-2.1.1-cp314-cp314-win_arm64.whl", hash = "sha256:ab36d55f9ed2d067327667c2fea18dda018eb628dd6347aa01dda6cf1f5d3836", size = 182947, upload-time = "2026-08-03T21:20:46.955Z" }, + { url = "https://files.pythonhosted.org/packages/23/59/40338bf421c5accea1d45158170c87006ef1cd371b05c077e76476949728/cffi-2.1.1-cp314-cp314t-macosx_10_15_x86_64.whl", hash = "sha256:7750c6449dff7864bb9bb27ddfb0267756189201a3afc911d82b3caacd70dfc3", size = 188504, upload-time = "2026-08-03T21:20:29.495Z" }, + { url = "https://files.pythonhosted.org/packages/7d/47/5ecf1023850036e674c77ec4de86182d309ae344e39e7cba984b7df5d647/cffi-2.1.1-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:0beceaabe56af686895136a2de78db54ecd8e4046b236b8fd6d6cb61389e9bf2", size = 188259, upload-time = "2026-08-03T21:20:31.291Z" }, + { url = "https://files.pythonhosted.org/packages/2a/9c/92934c3bea9f785b23eba304538c0b4d37a2a96d2431eb3a1bc87a11aa19/cffi-2.1.1-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:49cbc70e6542d4ccccb936558d1064a8012541e78f821f955cff24e357776c94", size = 223864, upload-time = "2026-08-03T21:20:32.571Z" }, + { url = "https://files.pythonhosted.org/packages/4d/45/ba4c93527bc38616a8bd36488acb69a2212d60486794f0c1f318949bbb76/cffi-2.1.1-cp314-cp314t-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl", hash = "sha256:e2d65b31f36619cda3999b78b2aa9632e76b78448e7a56fc4240824200e7c4fc", size = 211538, upload-time = "2026-08-03T21:20:33.808Z" }, + { url = "https://files.pythonhosted.org/packages/80/e9/b6ef565e452acb932fb0cb5443f44a78efbd1233e566f02b5a83855e9115/cffi-2.1.1-cp314-cp314t-manylinux2014_s390x.manylinux_2_17_s390x.whl", hash = "sha256:28907ab9bfb6aa13184cfc17c6b8e1023c5ab6fd7076d8c20a35e59fe04f8f29", size = 210688, upload-time = "2026-08-03T21:20:34.974Z" }, + { url = "https://files.pythonhosted.org/packages/9a/95/eff5f0cee78d2eabc7eebffec40d3fc1876b5f3c95582e018bb4b99601f2/cffi-2.1.1-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:51b31d1c98274844cfd7838ce00bfc27c7423a4dc00fc0772fc3331c2cc90676", size = 223803, upload-time = "2026-08-03T21:20:36.564Z" }, + { url = "https://files.pythonhosted.org/packages/fa/01/579d39fb8bef00a335a23d83757b44feb24cd6345a2c451b64cb67b9c362/cffi-2.1.1-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:5e7cecbaadb83884793e05828cee59b210b24583b9c7425d0ba6a754fe22eb4e", size = 226763, upload-time = "2026-08-03T21:20:37.816Z" }, + { url = "https://files.pythonhosted.org/packages/8d/b0/0b44f47c60b01b57b6e2bbd92343f13a85a1d93bc46ccf6e47e244acd99c/cffi-2.1.1-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:25792eac27877609e7bb06d42ff88278a6624fff2ba9bbb523c09616b117e80f", size = 225688, upload-time = "2026-08-03T21:20:38.959Z" }, + { url = "https://files.pythonhosted.org/packages/eb/d2/3b7176cb570a1d3e27faf67b72f591af508036e0d8b2be2ef9af9e8c84bb/cffi-2.1.1-cp314-cp314t-win32.whl", hash = "sha256:8ef53b2de9bcb9197d31854256575d59dbac0cba72ac627bb291ef5eceb74be4", size = 182868, upload-time = "2026-08-03T21:20:40.388Z" }, + { url = "https://files.pythonhosted.org/packages/56/78/31f00c1bcd97c9bbf55f1bfdf5bc809a5de8887473e90bb9960dca825e80/cffi-2.1.1-cp314-cp314t-win_amd64.whl", hash = "sha256:616f097f2fe415bc92a247f02e11f634e1f9e9a83d327e3c915c15089c87869e", size = 194104, upload-time = "2026-08-03T21:20:41.725Z" }, + { url = "https://files.pythonhosted.org/packages/7b/1b/58496f2ed0a35de575250c02a43ab3cc2c04d494a88fed31c1cabc0fd176/cffi-2.1.1-cp314-cp314t-win_arm64.whl", hash = "sha256:ad2c86c495b899d862ea0f4b42891b8713a3bd45dd4105c7fd51c2a72f39f3a5", size = 186402, upload-time = "2026-08-03T21:20:43.042Z" }, + { url = "https://files.pythonhosted.org/packages/c1/8f/9ebe220eab48a093d1a5a5e339ab0dc7316eef3bb04d63c42f0251b61f50/cffi-2.1.1-cp315-cp315-ios_13_0_arm64_iphoneos.whl", hash = "sha256:dddad92b554513a31f272570678ba307fb9f618f05e3d4a5eacafff9eae03e1d", size = 194043, upload-time = "2026-08-03T21:20:48.179Z" }, + { url = "https://files.pythonhosted.org/packages/ff/69/844bad3ece306c4782c2ecb93597035b6690d48704b803914c199da1e8b3/cffi-2.1.1-cp315-cp315-ios_13_0_arm64_iphonesimulator.whl", hash = "sha256:da0e573f9f97159390c89d9f1a9e41908b66d408cc5b58d08cf3847d844c531b", size = 196737, upload-time = "2026-08-03T21:20:49.457Z" }, + { url = "https://files.pythonhosted.org/packages/1b/8a/af668013284634733f02d683458a0728739c7d6ddb5e14cb0c20832266fe/cffi-2.1.1-cp315-cp315-macosx_10_15_x86_64.whl", hash = "sha256:fb92203a88b3d3053034db775110081c49d28be6551923805e039924093761e4", size = 184933, upload-time = "2026-08-03T21:20:50.639Z" }, + { url = "https://files.pythonhosted.org/packages/0c/75/2f5207ff6d1a613133b23a5203cc0c2a628313b5eb3974d7956ae3c57950/cffi-2.1.1-cp315-cp315-macosx_11_0_arm64.whl", hash = "sha256:2ae64be792b8966f2c69538199728b290e34726562896df1e5dc8ffd8d8188e8", size = 185002, upload-time = "2026-08-03T21:20:52.173Z" }, + { url = "https://files.pythonhosted.org/packages/e2/31/9e1313b0a6e30e91b3b3d3fff51ae99c857c07738e3afcce1f7334e1b7ab/cffi-2.1.1-cp315-cp315-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:507a24c282e0f42f8ed737cf048572cbf580468da5555764a8331735e9c736b6", size = 222271, upload-time = "2026-08-03T21:20:53.462Z" }, + { url = "https://files.pythonhosted.org/packages/50/e3/f6234a833e6e08c7007003074723c406559eecf9b48dfc97471e5a8eb7a0/cffi-2.1.1-cp315-cp315-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl", hash = "sha256:246fa40ce8645a614ff682e0b70f37134e460eaf93a775e0cbe3cca585a67a80", size = 209919, upload-time = "2026-08-03T21:20:54.783Z" }, + { url = "https://files.pythonhosted.org/packages/0d/fc/5f74e293fced6edb51af3a46c4ccf6c23c9943774ecb375ddbd522c76add/cffi-2.1.1-cp315-cp315-manylinux2014_s390x.manylinux_2_17_s390x.whl", hash = "sha256:471cee653ae88de62096552e6d24ccb4a5adb8c8c9f10b5054d0122c15bf2779", size = 208529, upload-time = "2026-08-03T21:20:56.066Z" }, + { url = "https://files.pythonhosted.org/packages/44/16/29e6d01b388bef055ecd6ca8244b3f4d336bd09e92d5d892187b9601084e/cffi-2.1.1-cp315-cp315-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:aeae0e330c9f6acd681f647d46cefd30c29f93e3392882e792e82080c9691399", size = 221630, upload-time = "2026-08-03T21:20:57.336Z" }, + { url = "https://files.pythonhosted.org/packages/a4/18/fa7f1f6857d5eb88a4ca99ffcbfb7c387a287ccc154c64a73e86314745d7/cffi-2.1.1-cp315-cp315-musllinux_1_2_aarch64.whl", hash = "sha256:42a494cee34437f05546455144f2b5d9ac09b1face62bcfce597d2e521066688", size = 225134, upload-time = "2026-08-03T21:20:58.675Z" }, + { url = "https://files.pythonhosted.org/packages/e0/9f/e8e3dfa04a1b4c241f8c91faacad872b4d4efd051d49764ad4e2fd4b9fea/cffi-2.1.1-cp315-cp315-musllinux_1_2_x86_64.whl", hash = "sha256:cc572dace3f60ef98d7b12ff411d20f5362feb31a0439eab0085bbfd349982d7", size = 223197, upload-time = "2026-08-03T21:20:59.968Z" }, + { url = "https://files.pythonhosted.org/packages/f8/7e/8debeb04f1ab9fe2a6963964cd6f1aaf7192627b83926586a6a4e089c9fa/cffi-2.1.1-cp315-cp315-win32.whl", hash = "sha256:4f42141fc14250de6dde5ee7ea4432be017252d91f19c5ad043c084cea629cac", size = 177683, upload-time = "2026-08-03T21:21:14.901Z" }, + { url = "https://files.pythonhosted.org/packages/e0/31/5158704cc474ab65c1647932e88be78dc0873f47130e253be38bcaf13d01/cffi-2.1.1-cp315-cp315-win_amd64.whl", hash = "sha256:e6e8cff14d6fb0be70a09c0bdc58096f501952d04624ebf867e0e56da2df8960", size = 187897, upload-time = "2026-08-03T21:21:16.108Z" }, + { url = "https://files.pythonhosted.org/packages/cc/4b/b3a2da8570c704ffc0f9762cdc3ec0f02c8573798e0b5cf7f11c82bbb70f/cffi-2.1.1-cp315-cp315-win_arm64.whl", hash = "sha256:27350daa11d4f10c540e6e89dada4c54feb7256ad03e9a4dc075ebad7ba360d1", size = 182935, upload-time = "2026-08-03T21:21:17.271Z" }, + { url = "https://files.pythonhosted.org/packages/d0/ef/5443574510a1207e6f6bc38ba6e1f1de36cb48fef07b2728bb896a21f430/cffi-2.1.1-cp315-cp315t-macosx_10_15_x86_64.whl", hash = "sha256:c26608d2222fb1e94487e4a387d85f13eb55d5ed725cb25a0c589ac4ee60e7bc", size = 188464, upload-time = "2026-08-03T21:21:01.163Z" }, + { url = "https://files.pythonhosted.org/packages/7e/ae/a56fa8c4686ad50e148fcbc8d3ae0d03915ff5c30d795058988c24118cef/cffi-2.1.1-cp315-cp315t-macosx_11_0_arm64.whl", hash = "sha256:4be96343e422f2dfcd12ab5c9f5aebe03f82f737c6bffeca6830b3875cb44aab", size = 188262, upload-time = "2026-08-03T21:21:02.382Z" }, + { url = "https://files.pythonhosted.org/packages/53/b2/6187f46f2912276a3ae284076109cc5c8680482f11f766ccf26db4a86427/cffi-2.1.1-cp315-cp315t-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:937c0052c05a31ca1daf18de3158eed4dbfcb9cc107adbea227728d647be701e", size = 223779, upload-time = "2026-08-03T21:21:03.553Z" }, + { url = "https://files.pythonhosted.org/packages/8a/f6/c3ad28bd19f77047a03084424fbd4cbe997303267c14423737324be0385d/cffi-2.1.1-cp315-cp315t-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl", hash = "sha256:df423d40ee8654634421812bc3b196da3f9bd7d32929da813f8394c4348a5358", size = 211520, upload-time = "2026-08-03T21:21:04.863Z" }, + { url = "https://files.pythonhosted.org/packages/a0/cd/ccac9013a5bd9fd764de118674ab9c805b5ca10c19270d90ee273f8b2240/cffi-2.1.1-cp315-cp315t-manylinux2014_s390x.manylinux_2_17_s390x.whl", hash = "sha256:a730a083190634c65cca36ba5f489531576ebd79bcd5c8e172130f6453127231", size = 210673, upload-time = "2026-08-03T21:21:06.223Z" }, + { url = "https://files.pythonhosted.org/packages/52/86/2976131c639aead931c5bee5aba67e4b09fbeb8018b6f282f70803f923a7/cffi-2.1.1-cp315-cp315t-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:363e05fa78e15116c3c32c210ee36884fd6b9afa6d440e47112c3bd511d64cb6", size = 223835, upload-time = "2026-08-03T21:21:07.539Z" }, + { url = "https://files.pythonhosted.org/packages/ac/0c/33a7aeab2f9c76918c52e084beb39c570db3588133412929e8ec06fab90b/cffi-2.1.1-cp315-cp315t-musllinux_1_2_aarch64.whl", hash = "sha256:770de9db11e84213beec501cfcaa013b019820ca881e03344dea5844f7876d94", size = 226705, upload-time = "2026-08-03T21:21:08.774Z" }, + { url = "https://files.pythonhosted.org/packages/e3/26/2cde30fdde421130bfc18f70395731a6e6b2053c6a1978a5258ff04e72fa/cffi-2.1.1-cp315-cp315t-musllinux_1_2_x86_64.whl", hash = "sha256:7da0c5eff80f0197f3b3d1232ec5a682a9325f4ae9016a78f5f5ca35f9ced1f5", size = 225539, upload-time = "2026-08-03T21:21:09.911Z" }, + { url = "https://files.pythonhosted.org/packages/6d/cd/a361394c94b2129d604bb846f624a8e88255a3ee33129c434a00d715e64f/cffi-2.1.1-cp315-cp315t-win32.whl", hash = "sha256:06c72bb76605a4b0cd0aad6930b69d4baf7dd5d806cfc409b824191099700e66", size = 182707, upload-time = "2026-08-03T21:21:11.226Z" }, + { url = "https://files.pythonhosted.org/packages/9b/b5/ba2b299993c26577d529b6ae29841f9e15b9fcf004d65f423f4fcf94ade9/cffi-2.1.1-cp315-cp315t-win_amd64.whl", hash = "sha256:d9c275eaacd24aa73f94ffd6de08fc3f932424d8b6c376f4bed7cde376fe7bc3", size = 193772, upload-time = "2026-08-03T21:21:12.39Z" }, + { url = "https://files.pythonhosted.org/packages/aa/29/35e016098c814cd93de9cd320c66b5bfba14dc6ecedd3cb518fa7c408c69/cffi-2.1.1-cp315-cp315t-win_arm64.whl", hash = "sha256:d18e5ac0f2f03f4f518d3e23db0f0cad7faa1da8620e9c09461d443bbf6e6692", size = 186360, upload-time = "2026-08-03T21:21:13.636Z" }, +] + +[[package]] +name = "click" +version = "8.5.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/c7/0e/7fa0ef50764b67090eca4114772a2abf8b6148198475e54c660b97caeee6/click-8.5.0.tar.gz", hash = "sha256:ba0d2089de75ea0310e2dde03160e6ca10009947fb95a182f9b54021bb272e34", size = 382235, upload-time = "2026-08-26T13:33:14.56Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/58/50/6c0d534c5f134586a8e1ba4e330569e32f057e33372ae556463212fb4cd3/click-8.5.0-py3-none-any.whl", hash = "sha256:255bc9599cf7748b4b1a446ccc735421bd08a2ae529a8b88597d3de5664ee360", size = 125251, upload-time = "2026-08-26T13:33:12.928Z" }, +] + +[[package]] +name = "colorama" +version = "0.4.6" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/d8/53/6f443c9a4a8358a93a6792e2acffb9d9d5cb0a5cfd8802644b7b1c9a02e4/colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44", size = 27697, upload-time = "2022-10-25T02:36:22.414Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/d1/d6/3965ed04c63042e047cb6a3e6ed1a63a35087b6a609aa3a15ed8ac56c221/colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6", size = 25335, upload-time = "2022-10-25T02:36:20.889Z" }, +] + +[[package]] +name = "coverage" +version = "7.17.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/d2/79/e78bd8f75a9b8e32233ce92d4607f0a21ce88a9156cace2884e7175a82f5/coverage-7.17.0.tar.gz", hash = "sha256:cc010a0a7fbdd9bb8bdfd0d3f04a5151275860213cbd7e2b876b29778489c712", size = 991021, upload-time = "2026-10-22T16:06:50.009Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/0a/25/989fd3b495c4274ac0cf54cb6664326415e60183a7f8a73dd9bbb0b11e34/coverage-7.17.0-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:0cfdc938ca3319d873d1f1252e60620a39aee4ebf9dbd7cc58238109ebda9c51", size = 225938, upload-time = "2026-10-22T16:04:18.113Z" }, + { url = "https://files.pythonhosted.org/packages/db/cb/14726426bf3241657facbf0f7df7babd8f7d3fcf8e4609b7929f9dceecbc/coverage-7.17.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:d523da3c2e4bca49417768bcdb1a443c5b359dc44b8b93a3102e118fce912c40", size = 226166, upload-time = "2026-10-22T16:04:19.524Z" }, + { url = "https://files.pythonhosted.org/packages/8e/97/f95ed32cd3cfbe261a3598e694cb770cefc7b2d13ff013418d6f70a44dde/coverage-7.17.0-cp312-cp312-manylinux1_i686.manylinux_2_28_i686.manylinux_2_5_i686.whl", hash = "sha256:adbf3450c0f3f2b2854e282a8758f2b3eddf787eeff24ec9c9bc2cbc38328cc1", size = 258462, upload-time = "2026-10-22T16:04:21.079Z" }, + { url = "https://files.pythonhosted.org/packages/91/ac/eb4c31f741509a9ef48cf6f28385e98e9de0785599282252eee252ff8af7/coverage-7.17.0-cp312-cp312-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl", hash = "sha256:85932227e9dd38e62cd29c17fefdfecfb919eead6af1e3259522d03cf85de983", size = 261789, upload-time = "2026-10-22T16:04:23.037Z" }, + { url = "https://files.pythonhosted.org/packages/e8/3e/d9cd006d1a3cc5deab07beb29b86cb4a10dd84d66b330820363fb8d310d6/coverage-7.17.0-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:30f5477aac9c9e4a0a641c55f8f8fddd7f3bd91176c912c50f40ffced96b4034", size = 262322, upload-time = "2026-10-22T16:04:24.94Z" }, + { url = "https://files.pythonhosted.org/packages/c0/3a/4c872c6ae0762b09cdb8e856891bb3f584848cb60b6dda2bacb85fe2f3f0/coverage-7.17.0-cp312-cp312-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:0b8bb651a4406fb6a983a905309fec1783443c65e1771b41e92740a0f4a1176b", size = 264600, upload-time = "2026-10-22T16:04:26.444Z" }, + { url = "https://files.pythonhosted.org/packages/df/98/1d41a2373fa98b423bcd70adb91d75e38eafb417955426dbb920b10016f3/coverage-7.17.0-cp312-cp312-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:0edeb6594f080c8de1263cccb239cb316ef77aeb959e2e0f38f2953fcc72a49e", size = 258678, upload-time = "2026-10-22T16:04:27.832Z" }, + { url = "https://files.pythonhosted.org/packages/92/6a/fe04b5e63e76506daa63d90bdfb00a53767fe5df18546b437d6226918d6b/coverage-7.17.0-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:da94ec0484e84fce5c7bf8d0f54b97767a90d992653a129b35634699d516e0a5", size = 260210, upload-time = "2026-10-22T16:04:29.275Z" }, + { url = "https://files.pythonhosted.org/packages/4f/c3/5c5a78dc19dd4799be9c6ec022316fb25ababaeacfaf0f52f24c56a57b43/coverage-7.17.0-cp312-cp312-musllinux_1_2_i686.whl", hash = "sha256:a25cc5e8c23a590815c6a7aa43624234d25cb23b21b484adb8a0daed59860db5", size = 258375, upload-time = "2026-10-22T16:04:30.647Z" }, + { url = "https://files.pythonhosted.org/packages/ed/e7/4c1d8eaff4d756fefd15d58c4953a78ab656782fd0e32c5a3465dba61aa0/coverage-7.17.0-cp312-cp312-musllinux_1_2_ppc64le.whl", hash = "sha256:db645c81cf4d6bcb392ea1894aad65d55d1588a8472c834b25ca575da3029a56", size = 262422, upload-time = "2026-10-22T16:04:32.053Z" }, + { url = "https://files.pythonhosted.org/packages/a6/2a/0b17c3e2e7b6ff1a5d92eb58915c0d1026668928f961d14dac73cf1b6096/coverage-7.17.0-cp312-cp312-musllinux_1_2_riscv64.whl", hash = "sha256:6a80a11b90c4a03df1502304cf24ff953255b6b5d076ef79066ecf88baaff31f", size = 257875, upload-time = "2026-10-22T16:04:33.824Z" }, + { url = "https://files.pythonhosted.org/packages/d3/2d/eb0cbde0535342df0d17a667163030a3afb67e5eb9e3ad94af9540041584/coverage-7.17.0-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:e4eaf11d6b0f2147f46cfbf06fe7edcca6f095d0120da00ddc2458995ee869fc", size = 260361, upload-time = "2026-10-22T16:04:35.661Z" }, + { url = "https://files.pythonhosted.org/packages/2e/47/1be2a6db7eb655d0a1d899217c3f2469f9121cbbeddac35c1c8173b1482e/coverage-7.17.0-cp312-cp312-win32.whl", hash = "sha256:912a29f338798541d795e2e25903c6fe7a99dee70a40fe4706a9a124649b523e", size = 227747, upload-time = "2026-10-22T16:04:37.102Z" }, + { url = "https://files.pythonhosted.org/packages/11/c5/201c894c57de81875d8b8cc527ba222aa350e8cfb183eb3f6df45d06ad8e/coverage-7.17.0-cp312-cp312-win_amd64.whl", hash = "sha256:88a1a9fb0075b83389dd9b403bb3fce976031b3c2aa0e05e3e57143cf639de69", size = 228325, upload-time = "2026-10-22T16:04:38.989Z" }, + { url = "https://files.pythonhosted.org/packages/0b/5d/196095339b19758cf83f507fb598bc42820ae124745feb3084662729e17a/coverage-7.17.0-cp312-cp312-win_arm64.whl", hash = "sha256:2c680e838ff9e68d491158625ca2c1ddb17d78d791bba96a31f8b839b4990438", size = 228131, upload-time = "2026-10-22T16:04:40.654Z" }, + { url = "https://files.pythonhosted.org/packages/54/e6/1f01afbc9f4fa8ca5e1fa6fdf537a5c58b5765d1b4167ee284cddb9acc72/coverage-7.17.0-cp313-cp313-android_24_arm64_v8a.whl", hash = "sha256:84538c040f4e6214f663459d89372ce4e6b2bbdd9d397ef0dca7b3ecd56b8eb2", size = 227080, upload-time = "2026-10-22T16:04:42.325Z" }, + { url = "https://files.pythonhosted.org/packages/92/7a/bdb7e6260c4a211389aeac9b89dc31662ebe122153ad0ecfd156897912df/coverage-7.17.0-cp313-cp313-android_24_x86_64.whl", hash = "sha256:6abfb6a4cf1cb1b67bc8fccdde177e2d2b781d0d34449e7078156547025140e5", size = 227152, upload-time = "2026-10-22T16:04:43.737Z" }, + { url = "https://files.pythonhosted.org/packages/37/4e/276e7d5b3cfb124871bdb544c27b004a8b4e270e6bf8e7414149c54b5e5b/coverage-7.17.0-cp313-cp313-ios_13_0_arm64_iphoneos.whl", hash = "sha256:ef65e96f0fc1a7c8b7644c7011d47a8228555e7888ac4d6246f715a7f3d7c398", size = 225397, upload-time = "2026-10-22T16:04:45.292Z" }, + { url = "https://files.pythonhosted.org/packages/b3/7d/dac073db12f3c131598a6693253aded581e4d7d622a89864f11bfb0ca2f5/coverage-7.17.0-cp313-cp313-ios_13_0_arm64_iphonesimulator.whl", hash = "sha256:55939ea4c097fda2edabf80fac5e49bef15597b950a9f29fc56292a895245feb", size = 225705, upload-time = "2026-10-22T16:04:46.603Z" }, + { url = "https://files.pythonhosted.org/packages/00/45/877b0a9248e921080ae91d115c13192d17e308f5aee86bcc7f7bc2a54ed1/coverage-7.17.0-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:bfb6f868af552c0ceb2d19220b8cbcc2be096ca26163ac30e682a13041433429", size = 225828, upload-time = "2026-10-22T16:04:48.065Z" }, + { url = "https://files.pythonhosted.org/packages/4f/f5/2c48d47abec0e4590b302920334be5ee3854f96bbd22524feabb8d92b220/coverage-7.17.0-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:8d823d66afd59566030539c49c7a6acaf3083996682be2dda760c63555842094", size = 226088, upload-time = "2026-10-22T16:04:49.513Z" }, + { url = "https://files.pythonhosted.org/packages/a8/a0/ec0442f3f372c7fd742f49b3022edd392f79e37a0048e1fa333f56d01ec3/coverage-7.17.0-cp313-cp313-manylinux1_i686.manylinux_2_28_i686.manylinux_2_5_i686.whl", hash = "sha256:50678474e714c684b82c108e63fbb8f1bcf1266d8293a49980f1d08526f093b5", size = 257257, upload-time = "2026-10-22T16:04:50.982Z" }, + { url = "https://files.pythonhosted.org/packages/92/e2/eb0927ba93809f76eee69fa1e47999825fc7dbbabc3e0e1a2744f2677acb/coverage-7.17.0-cp313-cp313-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl", hash = "sha256:045c1eeb19fb4eae949850a761102fffb3a5f638b97f977912f95843e54f6669", size = 260165, upload-time = "2026-10-22T16:04:52.409Z" }, + { url = "https://files.pythonhosted.org/packages/9a/a2/8d4c6055efb32099b15c9cc33d007b8aabebc4832f372a3274de5ba0afc5/coverage-7.17.0-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:dfb12891a773cbc2132349c77c690a045a882fe3f98b4bda50dfabb01893f9bd", size = 261098, upload-time = "2026-10-22T16:04:53.763Z" }, + { url = "https://files.pythonhosted.org/packages/2c/1e/93412288688a7b03f152a734c8ef086e395108a0a6a746985d3967e220f2/coverage-7.17.0-cp313-cp313-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:3067608b4429629f640c1b23d2f69b05d2fd45e00ebb6ee9e8fad220a6c11722", size = 263164, upload-time = "2026-10-22T16:04:55.386Z" }, + { url = "https://files.pythonhosted.org/packages/3c/20/7eb8d805c4f1a212245cef20181dfbf39535357985073d49730ee9cf08d4/coverage-7.17.0-cp313-cp313-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:a1762e85cbbe3b5ff9c6dcbcc1b89d5c72320094292b7b9572bf882c85e428b7", size = 257287, upload-time = "2026-10-22T16:04:56.976Z" }, + { url = "https://files.pythonhosted.org/packages/1a/c1/1df29630b4ed17e135c76390afcc6bd273c3dc5ba2a21a76813a600fe98c/coverage-7.17.0-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:62bb77987d3f72a0aaa77c567ee7f9806bc2e748c8f46fafbe1fdb90dd148398", size = 259256, upload-time = "2026-10-22T16:04:58.545Z" }, + { url = "https://files.pythonhosted.org/packages/a1/79/2365d1008d28aafe468a450a24c6c63363de794b5140223d67685cd0e205/coverage-7.17.0-cp313-cp313-musllinux_1_2_i686.whl", hash = "sha256:6cc31f27240d4e080437e3b8229d92f1d809c9a4f233607385373b73974e183e", size = 257178, upload-time = "2026-10-22T16:05:00.103Z" }, + { url = "https://files.pythonhosted.org/packages/c0/9f/f002952d295d772688dffce0d991e3822795b1e3aad158073712a5a5e86e/coverage-7.17.0-cp313-cp313-musllinux_1_2_ppc64le.whl", hash = "sha256:61cde5222f1933d476647c5a25ed1a8678b7703098cb5a15f4a0aa39967d8c28", size = 261275, upload-time = "2026-10-22T16:05:01.462Z" }, + { url = "https://files.pythonhosted.org/packages/40/fe/f9e15fbb426be97cd679ee5d359151e046f103bcd76b5092c318c26ed596/coverage-7.17.0-cp313-cp313-musllinux_1_2_riscv64.whl", hash = "sha256:11f5f7fb2d97a0fe865f5e7bad4eb0619b957637f676bc088d13844adf26ba95", size = 257029, upload-time = "2026-10-22T16:05:02.8Z" }, + { url = "https://files.pythonhosted.org/packages/c2/4a/3c398f38694387334ff4c9f71afc8e15b4fa7db7bc0bea4d5b6032eb0df0/coverage-7.17.0-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:6e09612b1b82c9df1d2b6c85dee88d5aad3e73d77a8ec0b16ac6a7322cbdf5d9", size = 259109, upload-time = "2026-10-22T16:05:04.241Z" }, + { url = "https://files.pythonhosted.org/packages/bd/a9/908a3cf1a2335aec1c788682a06c2f742a62a4f987033f080de1c5fd1997/coverage-7.17.0-cp313-cp313-win32.whl", hash = "sha256:bd3e9eb493631ff1ca34bf5efac25b5c66724f837bf6182c4fc771c55946423d", size = 227691, upload-time = "2026-10-22T16:05:05.636Z" }, + { url = "https://files.pythonhosted.org/packages/13/f7/8cdd7bfd8a63b3e6b133fc395ecfc7b1cb6f561926e7e2ad050de85b83e7/coverage-7.17.0-cp313-cp313-win_amd64.whl", hash = "sha256:f1fc9a7cea899c51d8a53e66c2f082a3d9e461ece32418d3ef0a0b90c32bfd3d", size = 228418, upload-time = "2026-10-22T16:05:07.057Z" }, + { url = "https://files.pythonhosted.org/packages/09/cf/0b3fc57f735cd3831ca13d0be5312a5477d5934066683c5d34018cab7541/coverage-7.17.0-cp313-cp313-win_arm64.whl", hash = "sha256:e65a1e61a68493fbfbe44d8bec71b3231d81b9917f62d3dafe0e105072147e83", size = 228142, upload-time = "2026-10-22T16:05:08.435Z" }, + { url = "https://files.pythonhosted.org/packages/4d/e1/722462fe79912ebebc101497bd16c42413cde2dbae771017f1ec0acb84c2/coverage-7.17.0-cp314-cp314-android_24_arm64_v8a.whl", hash = "sha256:dc5936491e306f2f6f095bd5fba593de11eb0375cee787ca1f245c3a333a523a", size = 227197, upload-time = "2026-10-22T16:05:09.846Z" }, + { url = "https://files.pythonhosted.org/packages/b7/74/826b9c09f2ebfea803bccb391d935688a25309bff8e819fc446bc629c108/coverage-7.17.0-cp314-cp314-android_24_x86_64.whl", hash = "sha256:968c5fb6e0c83cab752d79a70209648ce4d90cae815c60fa229b59e264601062", size = 227314, upload-time = "2026-10-22T16:05:11.422Z" }, + { url = "https://files.pythonhosted.org/packages/6d/19/c8514d7f5e0659a96ff2bc7377119dca6d420e2761c5fc69ae37618734f8/coverage-7.17.0-cp314-cp314-ios_13_0_arm64_iphoneos.whl", hash = "sha256:12cb8a20ad904a5811e6660d829a586b216e5254b9b34b76dde8a4d65d827dc6", size = 225477, upload-time = "2026-10-22T16:05:12.761Z" }, + { url = "https://files.pythonhosted.org/packages/81/74/ef9433ce599f07d8633b4ce6e6d6921505c4ef3f7f9006f8eb66e2c278cf/coverage-7.17.0-cp314-cp314-ios_13_0_arm64_iphonesimulator.whl", hash = "sha256:bb5ca66937c55bc85d1a5e9c5900a3e4693a8edf2280a9b3672b7b2661a84b95", size = 225787, upload-time = "2026-10-22T16:05:14.394Z" }, + { url = "https://files.pythonhosted.org/packages/d8/66/26e58981940e8b3944c6a9941bec5c7f50840e7009a046712e3f3bcd9e6a/coverage-7.17.0-cp314-cp314-macosx_10_15_x86_64.whl", hash = "sha256:5cc15faaf318ee5040d835a62c75bc6f122d837274f3b5efd47bf9fbd4ac5b85", size = 226019, upload-time = "2026-10-22T16:05:15.798Z" }, + { url = "https://files.pythonhosted.org/packages/e9/63/fe175310815cc8357b83b773c9b4c20943c269f217dd825a37c4b4bfe324/coverage-7.17.0-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:7d6d9d396c8b7bcaf76d774a10140b218111484e54c73a5f2a1b75655381748e", size = 226169, upload-time = "2026-10-22T16:05:17.188Z" }, + { url = "https://files.pythonhosted.org/packages/2c/b0/ac84761f5b4bd226696b0ec4606903d2ef7208abda0aec06c14a4218def4/coverage-7.17.0-cp314-cp314-manylinux1_i686.manylinux_2_28_i686.manylinux_2_5_i686.whl", hash = "sha256:42e6f170d1ac04b7eb3363310a6c41cdfd82c1fe6bf9ffbc4a86f380bdf091c7", size = 258092, upload-time = "2026-10-22T16:05:18.691Z" }, + { url = "https://files.pythonhosted.org/packages/e9/58/d8bdd65a661913bc12eaaa3e59742b2cb8b94f2e7f78e62184f0a58ca493/coverage-7.17.0-cp314-cp314-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl", hash = "sha256:acdb5f3c96046efff9dc6c572a6acb2b8d0da09372d7b9a9ed7249cf7d17434f", size = 261096, upload-time = "2026-10-22T16:05:20.089Z" }, + { url = "https://files.pythonhosted.org/packages/7b/15/5d82e2f0a75ea149e0a6412e137e1d610538772fdfd7199737db7fe234da/coverage-7.17.0-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:3393209f6894713161ee82a9b0e673e58237e0f9733c6638e7a6c0c620ef0b33", size = 262080, upload-time = "2026-10-22T16:05:21.568Z" }, + { url = "https://files.pythonhosted.org/packages/0f/cc/e3ebfd295d1dd47c7bc84a17d73f150465a37ab388dd68fe82b495dc79a0/coverage-7.17.0-cp314-cp314-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:e9494d9e99389d39e6a96227749af898d8924ff591cb63944f8a98e68582bf0e", size = 264558, upload-time = "2026-10-22T16:05:22.906Z" }, + { url = "https://files.pythonhosted.org/packages/e0/9d/e2adff76d6544bbc6df7366d74967923c2de37ba889a006bfb875bf5857b/coverage-7.17.0-cp314-cp314-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:032d4c2db4c677eb71d43f2f8b80bf64e9346f7a3f7b6ebb13f1782f3cc6c274", size = 257855, upload-time = "2026-10-22T16:05:24.343Z" }, + { url = "https://files.pythonhosted.org/packages/d9/fd/ecd1e9cddf1c36b5d03c438568b1f53e63db84bb3656539d71b454484c7d/coverage-7.17.0-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:4343a9378b964eb3cb80fa90406385de91c7e982a769ca9314d848f93bc0d3f2", size = 259933, upload-time = "2026-10-22T16:05:25.79Z" }, + { url = "https://files.pythonhosted.org/packages/40/b6/e17a19dccdbcad494c64691f71c1dba3e55c30625bc29ffbb88ac5a0aa8b/coverage-7.17.0-cp314-cp314-musllinux_1_2_i686.whl", hash = "sha256:b609df3d6d900464207532c5170a65c6ede8d2e0b91f151f90008a866395cd76", size = 257972, upload-time = "2026-10-22T16:05:27.185Z" }, + { url = "https://files.pythonhosted.org/packages/6a/0d/37dac534709a3fa43a937c8b0604839bb44b8670b83d143a4b78fec20d1e/coverage-7.17.0-cp314-cp314-musllinux_1_2_ppc64le.whl", hash = "sha256:a01ef92caeedfa4f2ad171a3a8e6fece4565de871d8bca428151bf9929f41048", size = 262271, upload-time = "2026-10-22T16:05:28.619Z" }, + { url = "https://files.pythonhosted.org/packages/cb/17/7c05186925b4d64a46c271dfd944e3f0c1ad89db9095c31a6df157a75df2/coverage-7.17.0-cp314-cp314-musllinux_1_2_riscv64.whl", hash = "sha256:a3914e2c98c34b94c26d2add3d2a61ccfd3534fc4eaa879ee290bdbb5184ba6c", size = 257604, upload-time = "2026-10-22T16:05:30.07Z" }, + { url = "https://files.pythonhosted.org/packages/95/65/c241cdee66a0ff86c68f6d37328e735d10e3d30cd6ff66f356039eb688d2/coverage-7.17.0-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:e8a72b26dc5c9a9422e45472b1d67ba5caf273c524c8668cc04b23062663755e", size = 259714, upload-time = "2026-10-22T16:05:31.402Z" }, + { url = "https://files.pythonhosted.org/packages/db/09/e93233fe2405574ce0a31ed201c0cba3a860e085db5d2828bf12b7dc0790/coverage-7.17.0-cp314-cp314-win32.whl", hash = "sha256:03baf0688e14a5a44ffd1eefa8928dfc92b14565e521174e072b31b971aa1657", size = 227914, upload-time = "2026-10-22T16:05:32.78Z" }, + { url = "https://files.pythonhosted.org/packages/d7/77/04979eb217edb94b94afabb4bcc179f60c746f68d3fd0b12688ba9195730/coverage-7.17.0-cp314-cp314-win_amd64.whl", hash = "sha256:3a4459b0f389dd1e51aac3dbfc4ca35b30cae7dc99caa3c0a086d1997a985709", size = 228543, upload-time = "2026-10-22T16:05:34.118Z" }, + { url = "https://files.pythonhosted.org/packages/a0/38/155f2f2c6769f8c43eca8a5e581443faa0908828650090b97103b4a41376/coverage-7.17.0-cp314-cp314-win_arm64.whl", hash = "sha256:a32ee5831b15ba239bef5d272ae586ca8acea4a661b5f2941f5a0d380e518b23", size = 228396, upload-time = "2026-10-22T16:05:35.951Z" }, + { url = "https://files.pythonhosted.org/packages/52/55/d6751572d9445485c4c5a51ec6ae11caa5c11b7ef2448cdccc884f7f54d9/coverage-7.17.0-cp314-cp314t-macosx_10_15_x86_64.whl", hash = "sha256:9c083e253e96fdeeaf48133fe836cac86ace2db215d235700e7f7532420a200c", size = 226486, upload-time = "2026-10-22T16:05:37.363Z" }, + { url = "https://files.pythonhosted.org/packages/2f/a8/82d37760e537bfdb9fdee285fa1e1b45bc153293d23e2331c7befedd1990/coverage-7.17.0-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:b88fb4d4d7608cbcebdc7ff7dbffc2115e3b81d6c33a79147cd79d54fcb080f4", size = 226861, upload-time = "2026-10-22T16:05:38.777Z" }, + { url = "https://files.pythonhosted.org/packages/24/96/70ec00a9db6d7bdd3f914eba12057360769f5cb78a98456e71fe1937deb5/coverage-7.17.0-cp314-cp314t-manylinux1_i686.manylinux_2_28_i686.manylinux_2_5_i686.whl", hash = "sha256:2bf3ee38a40c0570c316b9e7507c472469586906a20f289705898528c31aaea8", size = 266849, upload-time = "2026-10-22T16:05:40.285Z" }, + { url = "https://files.pythonhosted.org/packages/77/d8/d99be3bfbb208512f039c80b31e404138a86678fc929a17acd5b7135a6ae/coverage-7.17.0-cp314-cp314t-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl", hash = "sha256:7c570293f001ea91598b90e90cb9b98fddee833e90bbede432cbd218331ccd8e", size = 269402, upload-time = "2026-10-22T16:05:41.585Z" }, + { url = "https://files.pythonhosted.org/packages/82/50/6cbe8b5a5060edbd21ce8109c4e900f8b7656e8b72ede6dc4d82dc0b8bfb/coverage-7.17.0-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:791f9ee09814dd30d9562b4f4eb037a371485ec1c830b53999d2320d20c4e764", size = 272025, upload-time = "2026-10-22T16:05:42.921Z" }, + { url = "https://files.pythonhosted.org/packages/bd/05/d3633add01e5518dfdacfdbd1be41cb5c581412dd8bccd663edf6ef7fec8/coverage-7.17.0-cp314-cp314t-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:c7c5672ecf1b497de7a0b37743bef40e3b58e3207e9fe2ed6682cb0420836a88", size = 273515, upload-time = "2026-10-22T16:05:44.324Z" }, + { url = "https://files.pythonhosted.org/packages/57/d9/b83387780271bf9ea9f96a3aeb01c1c302c4494a927923c4fa70cd170a3f/coverage-7.17.0-cp314-cp314t-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:337f87e62e1c5f43c8198d879f677c342d152f84d3f157add12558853cbb8eaf", size = 266725, upload-time = "2026-10-22T16:05:45.713Z" }, + { url = "https://files.pythonhosted.org/packages/e4/be/8e80b29764ae3f4d70d44952eee3f3927eb36897490fe799e400adb7f5da/coverage-7.17.0-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:c8a58baa8eb6154c6645eadcc19b6c089deab78c24a612a83206f2a8a5992a7c", size = 269312, upload-time = "2026-10-22T16:05:47.054Z" }, + { url = "https://files.pythonhosted.org/packages/b8/c9/e702f588fe8d83ca844f133270ad0a49bf650c8cf260551ff6f11a6b6bbf/coverage-7.17.0-cp314-cp314t-musllinux_1_2_i686.whl", hash = "sha256:fb5745048ee20f796b0e3ab61831049e749acff188563e2af32f58ede957ac1b", size = 266740, upload-time = "2026-10-22T16:05:48.343Z" }, + { url = "https://files.pythonhosted.org/packages/8a/11/ee13ad14b714d75ef07c490b6e43969574a8b8b8c6d67bc741fcbacbf9c3/coverage-7.17.0-cp314-cp314t-musllinux_1_2_ppc64le.whl", hash = "sha256:7b5abcae74750302ac4bc77351eaee87c450e4abd3b6225eacde3858e260f8b2", size = 271036, upload-time = "2026-10-22T16:05:49.727Z" }, + { url = "https://files.pythonhosted.org/packages/e2/bc/854e8912c11c54aaf416e74602000589c6efbbe1f251dc90202fdabddcb6/coverage-7.17.0-cp314-cp314t-musllinux_1_2_riscv64.whl", hash = "sha256:4e153f0bd6509dbf837fd585f489b3328bfd98f2a718a0b15ae63032148b285c", size = 266158, upload-time = "2026-10-22T16:05:51.141Z" }, + { url = "https://files.pythonhosted.org/packages/a8/dd/96432830ddf63bc42654de54eee77a0cd6949cc65769bda06f353323f23a/coverage-7.17.0-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:e42a835271922fe7bf98c7a05c78d4032f4e52bf5b07fafa1eadfdfc2f0ad22f", size = 268088, upload-time = "2026-10-22T16:05:52.92Z" }, + { url = "https://files.pythonhosted.org/packages/ce/ee/230c6ec065a6629d41cc89323ceb54d37e2650c104f70fc108f4ee7c5051/coverage-7.17.0-cp314-cp314t-win32.whl", hash = "sha256:5900055351ec89fdffb34b27898815106529ded29a9496464c1ebd6313fd40fa", size = 228229, upload-time = "2026-10-22T16:05:54.255Z" }, + { url = "https://files.pythonhosted.org/packages/f0/1d/23eb6aadcb3c00764ff2961c0ff55f5dfa2543856d932b949bbc04fa68e9/coverage-7.17.0-cp314-cp314t-win_amd64.whl", hash = "sha256:5ee9c8bd13a59e301dc2aefe7aa8384633406808de051b1982775667094eb673", size = 229154, upload-time = "2026-10-22T16:05:55.682Z" }, + { url = "https://files.pythonhosted.org/packages/3e/f1/7df117e8e016b7a3ee459e833b3456f3610505afefd071f8727702d98439/coverage-7.17.0-cp314-cp314t-win_arm64.whl", hash = "sha256:0a9cb9a0fb58e6fff5442969af36094ecd6976f4907f179e33b27e15355d8f74", size = 228726, upload-time = "2026-10-22T16:05:57.179Z" }, + { url = "https://files.pythonhosted.org/packages/9f/a1/f9c24911755f91e6f451ca2e2c1804fbcbe9fecbc3310e341bbbbfa1d85b/coverage-7.17.0-cp315-cp315-android_24_arm64_v8a.whl", hash = "sha256:adabc1079ba844b096799ba8638d8df434aca1613f95bb7d5791af320cf05559", size = 227196, upload-time = "2026-10-22T16:05:58.543Z" }, + { url = "https://files.pythonhosted.org/packages/b0/a5/2b665b40c626e6bb40e5e8e23d91170b48b5f2f57186f46b07f2fac42386/coverage-7.17.0-cp315-cp315-android_24_x86_64.whl", hash = "sha256:6b4593d2871c4c801656dd5861e759f8f5156febd6b6061b02f6a72d64618b7b", size = 227315, upload-time = "2026-10-22T16:06:00.409Z" }, + { url = "https://files.pythonhosted.org/packages/3d/8c/22b518d61b930b8a4d62905d046c76a03675ef19b466462011dfb16439a3/coverage-7.17.0-cp315-cp315-ios_13_0_arm64_iphoneos.whl", hash = "sha256:c2c48a36bb970b7265b196032bfd4237c0b373f2b25ef7012d7e905b5b35c19c", size = 225490, upload-time = "2026-10-22T16:06:01.743Z" }, + { url = "https://files.pythonhosted.org/packages/08/5b/d3b141455944e030cd4987f055f8c84a44a1a0b28d81ae93389f44051691/coverage-7.17.0-cp315-cp315-ios_13_0_arm64_iphonesimulator.whl", hash = "sha256:f8bc2cd4c6aa58be1ca243fb8cddb6c3c42031fe4403991ad9cf2b3baed03d9f", size = 225797, upload-time = "2026-10-22T16:06:03.423Z" }, + { url = "https://files.pythonhosted.org/packages/03/24/aab2156983f7022361352640c583d08f0238e4cd7463eb921172001b4cfe/coverage-7.17.0-cp315-cp315-macosx_10_15_x86_64.whl", hash = "sha256:cbf0b83ce927de6053279ba61342d9f8892afde1385fcba9144cd05d4023d109", size = 226025, upload-time = "2026-10-22T16:06:04.76Z" }, + { url = "https://files.pythonhosted.org/packages/87/db/94697b9ccf4ec94cdad07bf94e2a21b9702247cb212d2d5f18d2b9c3d0de/coverage-7.17.0-cp315-cp315-macosx_11_0_arm64.whl", hash = "sha256:66efc0fb99cee34626fc17d3adac9c3cd816bfdad563bb1e983c3ef432f566d4", size = 226193, upload-time = "2026-10-22T16:06:06.167Z" }, + { url = "https://files.pythonhosted.org/packages/a0/fd/db1c4ade4219831d590fff5aa5b7d9ceaf84586e8e60da6fff71b6182251/coverage-7.17.0-cp315-cp315-manylinux1_i686.manylinux_2_28_i686.manylinux_2_5_i686.whl", hash = "sha256:58a304efdf2253fb2ea03d45d0a04cc174a92a0cd5279c28c5bb893ce7410968", size = 258046, upload-time = "2026-10-22T16:06:07.51Z" }, + { url = "https://files.pythonhosted.org/packages/95/ee/84ed138990ed752abd73db4adffc1842d6152017d8e21809cc109a413fda/coverage-7.17.0-cp315-cp315-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl", hash = "sha256:aed06129a9f530a948928260d7d2d81c47261355b0127e3c782251b38958463c", size = 261735, upload-time = "2026-10-22T16:06:08.861Z" }, + { url = "https://files.pythonhosted.org/packages/64/ad/c1e4367bbd1e7d562d6bc979c82b542f2040544e95a8cd995b694caf0e1a/coverage-7.17.0-cp315-cp315-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:f6cdb47a9be2d3313829bed1d296086287682a3ee901ff987b3432b45705b771", size = 262819, upload-time = "2026-10-22T16:06:10.49Z" }, + { url = "https://files.pythonhosted.org/packages/b5/3a/e8e8509b0940403eab15d86f70022790a01fce3e971a161919c544953f7a/coverage-7.17.0-cp315-cp315-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:804fbaf81d09b34e2f8b1159d01e211a50713d743d32fd9b2ca6cf0ae507a66f", size = 265194, upload-time = "2026-10-22T16:06:11.847Z" }, + { url = "https://files.pythonhosted.org/packages/1f/77/d64bbdbb734b1059ebcde2b5df567f142a9948079e51af9b0abf8c9ec17b/coverage-7.17.0-cp315-cp315-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:b2afebb96da9a1bbca142f8cc12320c14e5c215e0a49cded4f191f5a31506a28", size = 258410, upload-time = "2026-10-22T16:06:13.234Z" }, + { url = "https://files.pythonhosted.org/packages/e2/29/7cf81f08a254532c074eb52cfe6b12bb753d08f2997269c9fac8de359541/coverage-7.17.0-cp315-cp315-musllinux_1_2_aarch64.whl", hash = "sha256:bd04fd23206be9ad3de13b0b39313094fafa66a1f6baf70f5471c004a9fac47d", size = 260697, upload-time = "2026-10-22T16:06:14.595Z" }, + { url = "https://files.pythonhosted.org/packages/7f/56/bacea6dee2d5ccb31ab0cfffcee87ca7efa80ff048840209c8013aeaf02e/coverage-7.17.0-cp315-cp315-musllinux_1_2_i686.whl", hash = "sha256:5ebfbc87836529a31d25c2dec1262c38eea852ec1c46c0f690a515a7339d9c5b", size = 258649, upload-time = "2026-10-22T16:06:16.265Z" }, + { url = "https://files.pythonhosted.org/packages/a4/97/fd8a6a63740f9ee177c53b59e2f4d0752369bb0fd154086a1e69aa1fb255/coverage-7.17.0-cp315-cp315-musllinux_1_2_ppc64le.whl", hash = "sha256:a59c3b470ac3b2432af3598a996affbeb10236cd899a005c1c4e517fcff8b592", size = 262989, upload-time = "2026-10-22T16:06:17.85Z" }, + { url = "https://files.pythonhosted.org/packages/c1/37/7cd3d3520d45db3788456452b65446182c08f2a7c276f40c9dd11966be02/coverage-7.17.0-cp315-cp315-musllinux_1_2_riscv64.whl", hash = "sha256:7fef12cec4b96f59e09761cbd4fc9bdf4788062d1ae435b920241fc16c8a9549", size = 257955, upload-time = "2026-10-22T16:06:19.563Z" }, + { url = "https://files.pythonhosted.org/packages/c1/b9/80343a55e07d854927a915cc21a52e350ae1db9ead33f0248507b960785f/coverage-7.17.0-cp315-cp315-musllinux_1_2_x86_64.whl", hash = "sha256:a14e8d69464da9cbe1dc29e7116dbd37296d1d51a695327c478e250349085089", size = 260512, upload-time = "2026-10-22T16:06:21.055Z" }, + { url = "https://files.pythonhosted.org/packages/f3/32/e4c816f0cb3efdc6392bb276ff88359729f9dec605bdd3c1c7a44776f759/coverage-7.17.0-cp315-cp315-win32.whl", hash = "sha256:9a66074231799d8884d267234d49f60c90b43a945dfe069646b72f3058cd4e67", size = 227913, upload-time = "2026-10-22T16:06:22.407Z" }, + { url = "https://files.pythonhosted.org/packages/43/14/283120142ac281834808584249b89957de997c28573ddd65ae106b622121/coverage-7.17.0-cp315-cp315-win_amd64.whl", hash = "sha256:79cf71e5f9a48877ccfed5baa2c72f45af4feeaa596249e23eb15b473134830e", size = 228532, upload-time = "2026-10-22T16:06:23.756Z" }, + { url = "https://files.pythonhosted.org/packages/b9/bc/83dbc6c3bd58042afaefcb0cfd7d7a2e3076989a2f3d9bc6e6edac819784/coverage-7.17.0-cp315-cp315-win_arm64.whl", hash = "sha256:09e563b49c81cd0a33734e926d7a4a6ef1778d74304cde2dcc3aff8b30ea1036", size = 228393, upload-time = "2026-10-22T16:06:25.163Z" }, + { url = "https://files.pythonhosted.org/packages/00/ed/9463d1cb1766a2570343a372c2871c7fb4d561e5051f029399f4d57ce947/coverage-7.17.0-cp315-cp315t-macosx_10_15_x86_64.whl", hash = "sha256:a5e2e0625dfc789af0b2e10acfc106b352f314fffbd19e6392a7961c8cbe5d9a", size = 226481, upload-time = "2026-10-22T16:06:26.563Z" }, + { url = "https://files.pythonhosted.org/packages/ae/59/6536c7fa87be13236b4184fc395f14d18f622a5b8ef7448a6bfdf5f24ec0/coverage-7.17.0-cp315-cp315t-macosx_11_0_arm64.whl", hash = "sha256:194562ab1eff0d85aee8a17ce4c5c0bc1ebf70a629a7145257123156ad100fd6", size = 226876, upload-time = "2026-10-22T16:06:27.921Z" }, + { url = "https://files.pythonhosted.org/packages/b0/bc/4ffae6038f78382c9ab6a4969cb5fc01d50b083d119851085807629abe88/coverage-7.17.0-cp315-cp315t-manylinux1_i686.manylinux_2_28_i686.manylinux_2_5_i686.whl", hash = "sha256:85682ca89bc4601125dcdff23fa70e6274e13c9ad502fba845e6c274ab2c6569", size = 267241, upload-time = "2026-10-22T16:06:29.356Z" }, + { url = "https://files.pythonhosted.org/packages/c0/60/cae4b708b4217d33ebf66b9c57f8910a257346b3eaf054a78d73605ddc4c/coverage-7.17.0-cp315-cp315t-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl", hash = "sha256:0d0fac604a962ff546beb038cba9a5a09d88e6e3f01612fb46f7bd4fe5dc8dca", size = 270079, upload-time = "2026-10-22T16:06:30.736Z" }, + { url = "https://files.pythonhosted.org/packages/a9/84/1225ab04e55a6a2e483e903a5eb0f8f081cb5325df833594534aa288d91c/coverage-7.17.0-cp315-cp315t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:72edd4f9483ae30cd1ba4f230687840ef7b58a16afb1c9e81131fd6d64655f36", size = 272775, upload-time = "2026-10-22T16:06:32.247Z" }, + { url = "https://files.pythonhosted.org/packages/94/ad/567f8dd9246a553aa8753732c41f0e0654e98e9a617d6282e64eae0e6aa8/coverage-7.17.0-cp315-cp315t-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:91e487ad07c511da77b574820141a7c2da09bc2a4b4090b5be2424295d100697", size = 274110, upload-time = "2026-10-22T16:06:33.859Z" }, + { url = "https://files.pythonhosted.org/packages/66/5f/e0ee76895df40601e4aedffb6b8e71ea48e276a629fb4488b92cffffca14/coverage-7.17.0-cp315-cp315t-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:1cabb31531002fef5197de5df3c84730aef01e750e25154b9813a2583435aba2", size = 267775, upload-time = "2026-10-22T16:06:35.193Z" }, + { url = "https://files.pythonhosted.org/packages/19/6d/d19c6e45e940e5b9ba697b7be9a8e63cef73d90bdea45b670a59df466717/coverage-7.17.0-cp315-cp315t-musllinux_1_2_aarch64.whl", hash = "sha256:c9ac886242bbd50fb35a2242ba79555a99891e657da33f98b7ca968e3488a350", size = 270268, upload-time = "2026-10-22T16:06:36.597Z" }, + { url = "https://files.pythonhosted.org/packages/27/a3/b2731bb7aef2db800b330603675c3fa58a6497a05d5b5f8625f3b6285f68/coverage-7.17.0-cp315-cp315t-musllinux_1_2_i686.whl", hash = "sha256:d45cdc495671fc99268ff3653e0da4244972e9fc0e1fc3ea9de18781ad28963a", size = 267298, upload-time = "2026-10-22T16:06:37.973Z" }, + { url = "https://files.pythonhosted.org/packages/50/75/d0c90a81b6b6607933109914dc8b0ef0a5f4cacf9482ca868ae773ee5d0b/coverage-7.17.0-cp315-cp315t-musllinux_1_2_ppc64le.whl", hash = "sha256:12961f738d717a046d4bf3f8d1727eb3ebe2ed5478ff96cd6233d4dfc39323d3", size = 271899, upload-time = "2026-10-22T16:06:39.389Z" }, + { url = "https://files.pythonhosted.org/packages/64/1e/f038f3a2614e9ef839a40a184713aca40b8ed79e626ab5cdc388771045df/coverage-7.17.0-cp315-cp315t-musllinux_1_2_riscv64.whl", hash = "sha256:1ee0a982b0e1230b3edf768a7dd022bd2377303763895327ac62deb5efacee03", size = 267380, upload-time = "2026-10-22T16:06:40.97Z" }, + { url = "https://files.pythonhosted.org/packages/c9/30/8d636e639b2d8b1934128573402a7caf66c8cfbc794fa02061d84f115c34/coverage-7.17.0-cp315-cp315t-musllinux_1_2_x86_64.whl", hash = "sha256:460679f53893081edb94eeed011d26be37228ba649b853fd2aed7e4394fb1f35", size = 268993, upload-time = "2026-10-22T16:06:42.361Z" }, + { url = "https://files.pythonhosted.org/packages/73/7a/219f6b391cb0636242d06c390a8add5af91afa3e92afd0380dbedd34f487/coverage-7.17.0-cp315-cp315t-win32.whl", hash = "sha256:600e121e412cd6bdb52ec105b95c6a04da0c9710d1534f6e64a42db667907802", size = 228216, upload-time = "2026-10-22T16:06:43.714Z" }, + { url = "https://files.pythonhosted.org/packages/f0/3f/514d294319c5eac11494394545de209079f33993e14526c220eab29b2a96/coverage-7.17.0-cp315-cp315t-win_amd64.whl", hash = "sha256:c3e11b81faafb1f063248735c3e2c5c4183fc1db2c7f46782170dd7760dffcbc", size = 229146, upload-time = "2026-10-22T16:06:45.262Z" }, + { url = "https://files.pythonhosted.org/packages/f6/82/c0d8bb0a67df838fc7bc6f4060ffc404fd1154fd18e624d83e6abc41aeef/coverage-7.17.0-cp315-cp315t-win_arm64.whl", hash = "sha256:d472ee1c64868a917a47f02ffb4ac8c22b477f7589d57a3eb0c58b1ad4f0137c", size = 228716, upload-time = "2026-10-22T16:06:47.097Z" }, + { url = "https://files.pythonhosted.org/packages/c9/17/48032919343afa2906112d458aceda2043afdb24a2ee8eb4c60904d8ddf1/coverage-7.17.0-py3-none-any.whl", hash = "sha256:bac487dce0d2aff28ddf1a533a916f771416eee0e493960f611e49037b878e9d", size = 217383, upload-time = "2026-10-22T16:06:48.471Z" }, +] + +[[package]] +name = "cryptography" +version = "50.0.2" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "cffi", marker = "platform_python_implementation != 'PyPy'" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/9d/af/182eb91b0df3fe75c4d9f26fe70684569566745f6ba7e5c9c73a862c5252/cryptography-50.0.2.tar.gz", hash = "sha256:7b46165bb56eb4704e2eaaf86f3c940d19154535d9b0ca7d6d590b04060e00d5", size = 880623, upload-time = "2026-09-30T15:30:04.884Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/e5/56/d194340cc4a57535e82e1bee9e89667ac4b7c13b5d3f59686deae3094dd5/cryptography-50.0.2-cp311-abi3-macosx_11_0_arm64.whl", hash = "sha256:fa8f5efb344d6908a1ce62f4a24e2e5780f825d6f53f5f50ec5ffacac72936cb", size = 3914904, upload-time = "2026-09-30T14:43:44.339Z" }, + { url = "https://files.pythonhosted.org/packages/d9/69/c9bd862c3bf43d6399c433caf002df16e2dffd4be49bdf515cda38038711/cryptography-50.0.2-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:79def8d059362e7831389ed3be0ecdf58a89386e1271e35dd9f5af84e81bffd0", size = 4731146, upload-time = "2026-09-30T14:43:47.113Z" }, + { url = "https://files.pythonhosted.org/packages/21/69/64cef1f702bf6657e0cc186ed1a2891d50d29fb41586b254e1c07adea261/cryptography-50.0.2-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:630ebfea3bf689d075f82316324ff7433dc447fe6bc1bfc76524b74b4a9567d2", size = 4719841, upload-time = "2026-09-30T14:43:49.01Z" }, + { url = "https://files.pythonhosted.org/packages/38/6b/61a3f8d8c5e1e49a6cddccafc4015cc1c0021360ab0acb4080e7a423644a/cryptography-50.0.2-cp311-abi3-manylinux_2_28_aarch64.whl", hash = "sha256:f9f6143a8c75945eb960d9eb98905a441394abfa24afaae239d514ffb2586480", size = 4738340, upload-time = "2026-09-30T14:43:50.932Z" }, + { url = "https://files.pythonhosted.org/packages/7b/2e/7212ca32fd43dc91f2f41db20160b268098874b4c9a0e7be94d6835f5b2e/cryptography-50.0.2-cp311-abi3-manylinux_2_28_ppc64le.whl", hash = "sha256:a582ab2ae1d34f67112cadc86702774c9ea4374df6bca6afe672817203c99134", size = 5367029, upload-time = "2026-09-30T14:43:52.911Z" }, + { url = "https://files.pythonhosted.org/packages/1a/f1/b474e930c4d910328780e3940da76f5aa5cbc48ce1fc14e44d239d9ea9db/cryptography-50.0.2-cp311-abi3-manylinux_2_28_x86_64.whl", hash = "sha256:4061c0079120205fb760c58acab6443e217307dcf05e3702cf970e0689972856", size = 4753050, upload-time = "2026-09-30T14:43:55.272Z" }, + { url = "https://files.pythonhosted.org/packages/7c/52/9af10e80ac16b0fcc2123f9cbd5e7afbd0fd5075bb7a607c592258a39cda/cryptography-50.0.2-cp311-abi3-manylinux_2_31_armv7l.whl", hash = "sha256:ac9ed99d81760c62fe89d5f0815cdfa1ba9a35141cf30f1c2d044f04b4803d2e", size = 4376724, upload-time = "2026-09-30T14:43:57.24Z" }, + { url = "https://files.pythonhosted.org/packages/71/37/6202e488cc1eb625ea110c292c6bda92823176e023f427d8d5660ce8d632/cryptography-50.0.2-cp311-abi3-manylinux_2_34_aarch64.whl", hash = "sha256:87e9ce85beb6b328ba370cc6e6aea483c92617b4c95b1d33a49297eb662bfb04", size = 4737859, upload-time = "2026-09-30T14:43:59.541Z" }, + { url = "https://files.pythonhosted.org/packages/8f/30/e86d7d518489b0ae2497091a35287abcb1a2ce4037837a34afbe9b1d6964/cryptography-50.0.2-cp311-abi3-manylinux_2_34_ppc64le.whl", hash = "sha256:f265528741e048bce55c3463ed721fb0aa45a5888d8add8cfeccb3035451bbdc", size = 5324103, upload-time = "2026-09-30T14:44:01.901Z" }, + { url = "https://files.pythonhosted.org/packages/d3/69/2c833a049475e0a3444e94c7d0aca0aa51d166374a449b09e92ac98138de/cryptography-50.0.2-cp311-abi3-manylinux_2_34_x86_64.whl", hash = "sha256:9dab55f57c74c3cad24c323bacbbd04be4705ba6eb0d92e920b1fc4837ed5079", size = 4752576, upload-time = "2026-09-30T14:44:04.545Z" }, + { url = "https://files.pythonhosted.org/packages/6c/5d/906970b83bbfc1f5bbfb677a143c181f2801f23b6a7204a3b47c42c97e65/cryptography-50.0.2-cp311-abi3-musllinux_1_2_aarch64.whl", hash = "sha256:25784ce8b9621c90c643efb9e1e2162ab3b0224cae446ad5e70e7fcb1ce18b51", size = 4870819, upload-time = "2026-09-30T14:44:06.884Z" }, + { url = "https://files.pythonhosted.org/packages/68/e3/f2298d3bb55e0c4a91841ec4d01b3f020ba8c5fbf15ccdcc6dcf03f97025/cryptography-50.0.2-cp311-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:85d0d9a31b9098e98534226d5686b47264b95e62ce459dc2e62fdfc809f9fe93", size = 5030152, upload-time = "2026-09-30T14:44:09.443Z" }, + { url = "https://files.pythonhosted.org/packages/9a/4f/adfc442765721292fff86d314ce385d3249d22db42295c0dd057727b60f3/cryptography-50.0.2-cp311-abi3-win_amd64.whl", hash = "sha256:7afa5a6602a9f29af1f3a2965f831bae7c9d5d597b7cbb716d41ab3b7d89879c", size = 3824692, upload-time = "2026-09-30T14:44:11.671Z" }, + { url = "https://files.pythonhosted.org/packages/ce/cb/52eb3770c0d0be2702a98c6e96065ddc0a2877cf0845aa9c23397c142cd4/cryptography-50.0.2-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:f785f6161f202ab04d8ca194158968798e480ca058943907972da5f12e2881e8", size = 3892731, upload-time = "2026-09-30T14:44:13.485Z" }, + { url = "https://files.pythonhosted.org/packages/19/8e/aa1fc533d4546b127b45de8aa024eb5933d23eff9debfe25931e56861095/cryptography-50.0.2-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:0ecbc5652bdb6fc9eaf89a7d196e20941adfe812f43bc4ca05d9150496821047", size = 4710431, upload-time = "2026-09-30T14:44:15.427Z" }, + { url = "https://files.pythonhosted.org/packages/6a/64/72bc3f75176e7e406b748a3e3830432b8c51297b38368713df04dc04898a/cryptography-50.0.2-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:ab50ee449bf968271e820086f10a33d101dd060370abc10bcd22279be2656539", size = 4694824, upload-time = "2026-09-30T14:44:17.69Z" }, + { url = "https://files.pythonhosted.org/packages/4e/c6/62c77550edfa5ca3f14bf44a1e6739b9fa09d6e998a11d97ed8213bccc98/cryptography-50.0.2-cp314-cp314t-manylinux_2_28_aarch64.whl", hash = "sha256:a9f7355e6fab51f6c369b86fb7571cffa05edee2c2121e0380a37fb9ac1cd5c1", size = 4716967, upload-time = "2026-09-30T14:44:19.661Z" }, + { url = "https://files.pythonhosted.org/packages/f4/37/cce70f150c432914460157a6ecc161752e053aa5ec0ef3b3f7dc6e31039a/cryptography-50.0.2-cp314-cp314t-manylinux_2_28_ppc64le.whl", hash = "sha256:94e5e9f108ee10471288214d3d233fbfbb492840a8457eb85178d643ddeb32c7", size = 5328676, upload-time = "2026-09-30T14:44:21.744Z" }, + { url = "https://files.pythonhosted.org/packages/aa/9a/6f2f0304d634ceafdeaf23e84537336664ac419b5d07611675c2ad3f6b7a/cryptography-50.0.2-cp314-cp314t-manylinux_2_28_x86_64.whl", hash = "sha256:241449bf940a5d27309bd317e6f9a2af6932113818bb2b8f5c59ddc7ef16da18", size = 4727698, upload-time = "2026-09-30T14:44:24.178Z" }, + { url = "https://files.pythonhosted.org/packages/1d/de/66bcf9244d118663b2e1aaded8990f4640e3d7b7411870a5765f252074d2/cryptography-50.0.2-cp314-cp314t-manylinux_2_31_armv7l.whl", hash = "sha256:d8947001be83df1394050758ce0e745dd74fb134eef0a4b5124208dfc3a68c37", size = 4354821, upload-time = "2026-09-30T14:44:26.263Z" }, + { url = "https://files.pythonhosted.org/packages/bd/e6/db28a28c7b6c676addce89136de3d8db49ea825a8c863472e36e42ead4ad/cryptography-50.0.2-cp314-cp314t-manylinux_2_34_aarch64.whl", hash = "sha256:4a20ce1e5cb4284a86692fdcba7cb8754185c6b2e5c56fcef3751cf451d3cdc2", size = 4716748, upload-time = "2026-09-30T14:44:28.447Z" }, + { url = "https://files.pythonhosted.org/packages/30/96/01546c7f69ea0e2ab790a2e4f0934a4052fb9b388147fbf83c2fd72f1e57/cryptography-50.0.2-cp314-cp314t-manylinux_2_34_ppc64le.whl", hash = "sha256:84f964e537f916e2cc85199e5a88742e964939b575ac8598b3f9d6cc416cdaf1", size = 5285085, upload-time = "2026-09-30T14:44:30.704Z" }, + { url = "https://files.pythonhosted.org/packages/6c/01/03263395f74d50b071e9e66daace3f8bef80493e5d410726f2ba8554736b/cryptography-50.0.2-cp314-cp314t-manylinux_2_34_x86_64.whl", hash = "sha256:828d49b0ff5a0e3975865571c5d91dbbdd0d38d8289b249a163e9425413a5e05", size = 4727268, upload-time = "2026-09-30T14:44:32.92Z" }, + { url = "https://files.pythonhosted.org/packages/eb/94/2bfe8f29ec0cc9c0d99359c4161adf32858e4934b72c6d100d2ac0bbe962/cryptography-50.0.2-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:deb9fde5c60e437ee4821bc9bc39ff31b42135c27e1dc61ef0a629389c1de62e", size = 4849503, upload-time = "2026-09-30T14:44:34.969Z" }, + { url = "https://files.pythonhosted.org/packages/54/44/e80651ecbf0e42b62e2bb5f5768916e07eea72e1297338956a61df361f88/cryptography-50.0.2-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:8c71ba2cd31fc93748c38e1b613200ff1c2665cbfd5341fe3a61cfde35a1430e", size = 5004057, upload-time = "2026-09-30T14:44:37.064Z" }, + { url = "https://files.pythonhosted.org/packages/f8/cc/1d33befb3cd7ea7e77d2d73f43f2066471da1b21f24a6156efcaabf6d2e8/cryptography-50.0.2-cp314-cp314t-win_amd64.whl", hash = "sha256:78198641e5be9521beea5aa782bb551a58068d10e6eb04c9c680c1b69f2e7d45", size = 3795868, upload-time = "2026-09-30T14:44:39.71Z" }, + { url = "https://files.pythonhosted.org/packages/2d/49/93f6a6e7a87c9aa68d44d3e1cdb5fe8f60c90d5d2f46acae9a56892816b8/cryptography-50.0.2-cp315-abi3.abi3t-macosx_11_0_arm64.whl", hash = "sha256:edc3342adf8f697fc5f59c887a304356f147b397809440ed64e2fa6af2f50f37", size = 4133708, upload-time = "2026-09-30T14:44:41.807Z" }, + { url = "https://files.pythonhosted.org/packages/8c/75/32ac2a56243d778805c16ca6a32b8f74fb757df7e28d7ecb560afafb59cf/cryptography-50.0.2-cp315-abi3.abi3t-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:d370b8d1dfcdf7130178137f6fbee6140774a1acc6cacefc4b42643ec11d0a3a", size = 4956267, upload-time = "2026-09-30T14:44:43.693Z" }, + { url = "https://files.pythonhosted.org/packages/aa/a4/2c8d734e43d97f0842ee9f1b7b4bfb3d0cf5e19edebf43c2afe6675c2320/cryptography-50.0.2-cp315-abi3.abi3t-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:f2f9bd7f90c64fe89253f0a2c05e3c4856072660429ce8831b4235bf29403a67", size = 4966465, upload-time = "2026-09-30T14:44:45.769Z" }, + { url = "https://files.pythonhosted.org/packages/c2/58/ee288c829a6f41f6235ae9dd33d82fd19b45442b65b4c8a3da36963d9f7a/cryptography-50.0.2-cp315-abi3.abi3t-manylinux_2_28_aarch64.whl", hash = "sha256:e275096ea1e60cc595cda2836fd4a6c725d1125108b868be17f53684d164e2cc", size = 4959356, upload-time = "2026-09-30T14:44:48.211Z" }, + { url = "https://files.pythonhosted.org/packages/92/20/9ded6d51ddd9897f6b6e81fb9ebea7951d7cc5d6c890b0ed8abf77a51a80/cryptography-50.0.2-cp315-abi3.abi3t-manylinux_2_28_ppc64le.whl", hash = "sha256:b13478603dcd0a2479ff8e87e2c19a7d525734686fe3c49542472293a204212d", size = 5548822, upload-time = "2026-09-30T14:44:50.86Z" }, + { url = "https://files.pythonhosted.org/packages/02/a8/8df951850d6b31d2a00218f19e2b3f999523437ed7a819df7fa427942fca/cryptography-50.0.2-cp315-abi3.abi3t-manylinux_2_28_x86_64.whl", hash = "sha256:58a0c478eeca76fe5e07993c5a0703def34a6dc6a0cda4f5564639b33112ffe7", size = 5001199, upload-time = "2026-09-30T14:44:53.379Z" }, + { url = "https://files.pythonhosted.org/packages/8b/f9/36b3022218ce75b7cdf068fb95f809f9bd0d820e4955ef43b90c255cc7ac/cryptography-50.0.2-cp315-abi3.abi3t-manylinux_2_31_armv7l.whl", hash = "sha256:d38cdff612d06fa6a32840d5e1b1f7a27cee4a349aa9085d94a67789d6bfd408", size = 4629333, upload-time = "2026-09-30T14:44:55.635Z" }, + { url = "https://files.pythonhosted.org/packages/8c/72/20f99a219f6af47cdd1cbd978c243b92d71496e168a746138af44ded4f29/cryptography-50.0.2-cp315-abi3.abi3t-manylinux_2_34_aarch64.whl", hash = "sha256:fdd28f912fccfec1846a94e2e1e8f9b0012f557f0c46fe4f3eb0d7a87afcf90b", size = 4958822, upload-time = "2026-09-30T14:44:59.639Z" }, + { url = "https://files.pythonhosted.org/packages/f2/20/196f112617fb08eb4d608a2a6c422373d46f9cc2857f38fc0667033c0899/cryptography-50.0.2-cp315-abi3.abi3t-manylinux_2_34_ppc64le.whl", hash = "sha256:cbc8738fd8526d80f35cb3a40d41f41a2e7030bb3b18b09a6778ef63d291c2fd", size = 5506351, upload-time = "2026-09-30T14:45:02.267Z" }, + { url = "https://files.pythonhosted.org/packages/24/95/83378121ef3eaaaf71d4b781577ff794acb39b9e1b87a3f156898c8497ed/cryptography-50.0.2-cp315-abi3.abi3t-manylinux_2_34_x86_64.whl", hash = "sha256:e105ab60406787da31fccc883fc0f733af1efd78f0136a4599692c4083a73d0c", size = 5000859, upload-time = "2026-09-30T14:45:05.009Z" }, + { url = "https://files.pythonhosted.org/packages/22/f7/70fd7ae4d1dbfa7ba29b02e1b9068771519a86027756510b700ce81086a8/cryptography-50.0.2-cp315-abi3.abi3t-musllinux_1_2_aarch64.whl", hash = "sha256:6f8700550aa1474a91e5dc07049c46f98b423b5b1ddd0483e0b51362eeeaf5be", size = 5092151, upload-time = "2026-09-30T15:29:15.932Z" }, + { url = "https://files.pythonhosted.org/packages/d4/be/688367b74de86984bd58d8efacfc7c9e68b89a6a22ced0fb4f38db50254a/cryptography-50.0.2-cp315-abi3.abi3t-musllinux_1_2_x86_64.whl", hash = "sha256:c71be1cbfa5cd9a41ee452acf1eccd82b2c05950358b106ec8ceb83411d1a020", size = 5286120, upload-time = "2026-09-30T15:29:18.309Z" }, + { url = "https://files.pythonhosted.org/packages/39/d1/55f8a3f2ef5d1529e16835ef10cf0fe3d559ce237b46dddc440c0bba3649/cryptography-50.0.2-cp315-abi3.abi3t-win_amd64.whl", hash = "sha256:c423ab384a46c4dff7217b2ea5ba2e11cffdeab6441acd04cf65a369caf0366c", size = 4111557, upload-time = "2026-09-30T15:29:20.155Z" }, + { url = "https://files.pythonhosted.org/packages/23/ad/ac987755d00e1e64273760228d2635ae38dae2be83e3c6e0d3289d91dec3/cryptography-50.0.2-cp39-abi3-macosx_11_0_arm64.whl", hash = "sha256:0ec5f09541743261e66e291b4a0cbf0fb2997aeaab6d9e9c740b9dba1b58d1c2", size = 3943588, upload-time = "2026-09-30T15:29:22.265Z" }, + { url = "https://files.pythonhosted.org/packages/d5/8d/6d585339bedf85d45044c85d8412dac53f2bb6f918e8b7777efba1787844/cryptography-50.0.2-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:c5e67125c7dca78d199ec4e116aa93dbb83494808ecbb8211a2cb09b1bf41dbd", size = 4756166, upload-time = "2026-09-30T15:29:24.58Z" }, + { url = "https://files.pythonhosted.org/packages/bf/f1/1c1f6874e8550cfddd4b688ceb38cefb6ed15ceed224d56f133f3d88c214/cryptography-50.0.2-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:ee247f5c245c9a2fe7c8e2214e295918838e44e00a45a6718451e4004219e767", size = 4749145, upload-time = "2026-09-30T15:29:26.807Z" }, + { url = "https://files.pythonhosted.org/packages/c1/63/61b15dc1a8de03fe0adbe3fd7608b3ad5c73bf50993bbcb1faaa930afe33/cryptography-50.0.2-cp39-abi3-manylinux_2_28_aarch64.whl", hash = "sha256:dfe9763530994147d9af1def057a5b9658b00e8f8fe8743d144d1e0911c2e454", size = 4763638, upload-time = "2026-09-30T15:29:28.588Z" }, + { url = "https://files.pythonhosted.org/packages/fc/35/b345bdfa40c9126df1a9d33236aa98418367931b8725f84fc3ae2b98dc59/cryptography-50.0.2-cp39-abi3-manylinux_2_28_ppc64le.whl", hash = "sha256:58ddb5a8e3179d12f19e4ea34d2d32e9d63a4baa142c875c1eb59f41b7243acd", size = 5382217, upload-time = "2026-09-30T15:29:30.589Z" }, + { url = "https://files.pythonhosted.org/packages/4f/87/ef344a9e616871f2519c22d6afcda79ddd5d35e9592d95eb6e677608d055/cryptography-50.0.2-cp39-abi3-manylinux_2_28_x86_64.whl", hash = "sha256:f21e8a22c8605750c7af886bab299a363721264061b4ac0a30efb73cfd58efc5", size = 4781387, upload-time = "2026-09-30T15:29:32.605Z" }, + { url = "https://files.pythonhosted.org/packages/90/5b/f2fdb13cd0b96f6f932c8627bb292a45f11c64d21620a8e120aee9a3b848/cryptography-50.0.2-cp39-abi3-manylinux_2_31_armv7l.whl", hash = "sha256:9c8402a82ea0dc4ceeab793db05f0fafa8ca139ca34fcde5df0f596103c74107", size = 4403790, upload-time = "2026-09-30T15:29:34.374Z" }, + { url = "https://files.pythonhosted.org/packages/bc/ce/7e4f662b1e3c393513569e402cfc85ac7da0bd3d5435e122a3140219eb2d/cryptography-50.0.2-cp39-abi3-manylinux_2_34_aarch64.whl", hash = "sha256:0ddc924c04591c2811ca024d62ecad4f7f6f08af8939c211438f48a16bd23602", size = 4764319, upload-time = "2026-09-30T15:29:36.149Z" }, + { url = "https://files.pythonhosted.org/packages/3c/3f/86ff33ce34cc0de6847fb96e035a1a760d81652e38643f617c02ad32ef7a/cryptography-50.0.2-cp39-abi3-manylinux_2_34_ppc64le.whl", hash = "sha256:a6557e5f38e065ca9fbdaf7cfc7435ecb1d113aa81a022d1b51921ee7432e227", size = 5338560, upload-time = "2026-09-30T15:29:39.053Z" }, + { url = "https://files.pythonhosted.org/packages/40/cf/6b5c8e2fd9202d98988ab7cb5cc5c991704c4ad55f492ff408e4969f83f1/cryptography-50.0.2-cp39-abi3-manylinux_2_34_x86_64.whl", hash = "sha256:1981f1db4630889b9ef7803fadef12b056f428cb6b85c27ba57b774793b6093c", size = 4780973, upload-time = "2026-09-30T15:29:41.251Z" }, + { url = "https://files.pythonhosted.org/packages/10/bf/8d6ebc7dded797bd0f0160d52188021211f011a2b164ef0ae1dac4587465/cryptography-50.0.2-cp39-abi3-musllinux_1_2_aarch64.whl", hash = "sha256:7a8701d6b584d76e909e3d305b7d126b41439876a5aaf76cddc67fc230eafa2e", size = 4897738, upload-time = "2026-09-30T15:29:43.106Z" }, + { url = "https://files.pythonhosted.org/packages/d4/aa/f3f6e0de7e6253b8baa8b2d8fb9d50924fa75cee3d4624bd4bc1208ee923/cryptography-50.0.2-cp39-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:ce47f66801c20ec6c6632453bb5960fe38939e9306970b48b3a5a26de7745d94", size = 5058280, upload-time = "2026-09-30T15:29:44.827Z" }, + { url = "https://files.pythonhosted.org/packages/f6/b6/a1faf3a27ae9405fb34b1713cc73b2d8a26b04d5c561578fa2e6ef3e5bb9/cryptography-50.0.2-cp39-abi3-win_amd64.whl", hash = "sha256:4e81d95e5bafc2d6e34e4bed780e53e4d5b9a2f928573428aa4d35fbec1eb0de", size = 3854095, upload-time = "2026-09-30T15:29:46.782Z" }, +] + +[[package]] +name = "databases-ui" +version = "0.0.0" +source = { editable = "." } +dependencies = [ + { name = "cryptography" }, + { name = "fastapi" }, + { name = "httpx" }, + { name = "pyjwt", extra = ["crypto"] }, + { name = "pyyaml" }, + { name = "uvicorn" }, +] + +[package.dev-dependencies] +dev = [ + { name = "pytest" }, + { name = "pytest-cov" }, +] + +[package.metadata] +requires-dist = [ + { name = "cryptography", specifier = ">=45" }, + { name = "fastapi", specifier = ">=0.140" }, + { name = "httpx", specifier = ">=0.28" }, + { name = "pyjwt", extras = ["crypto"], specifier = ">=2.10" }, + { name = "pyyaml", specifier = ">=6.0.2" }, + { name = "uvicorn", specifier = ">=0.50" }, +] + +[package.metadata.requires-dev] +dev = [ + { name = "pytest", specifier = ">=8" }, + { name = "pytest-cov", specifier = ">=6" }, +] + +[[package]] +name = "fastapi" +version = "0.161.1" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "annotated-doc" }, + { name = "opentelemetry-api" }, + { name = "pydantic" }, + { name = "starlette" }, + { name = "typing-extensions" }, + { name = "typing-inspection" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/ed/3d/2cc1a0dbc2dac6e157b4ef12bac063e1016cb7c6d7395f76665e439cf1aa/fastapi-0.161.1.tar.gz", hash = "sha256:4076b88434452e20289379068e976c4a04c65ffc8e6be31510106e150a422f0f", size = 527406, upload-time = "2026-10-22T22:22:07.757Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/45/2a/101012d82931d9de3855384e1667e49c0e07a0048e3868f9fec1697293a9/fastapi-0.161.1-py3-none-any.whl", hash = "sha256:a1363080cf9aeedecd99f4e1a23669d7e77542227f6536f4d7bbd59f07ecaa94", size = 149049, upload-time = "2026-10-22T22:22:06.139Z" }, +] + +[[package]] +name = "h11" +version = "0.16.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/01/ee/02a2c011bdab74c6fb3c75474d40b3052059d95df7e73351460c8588d963/h11-0.16.0.tar.gz", hash = "sha256:4e35b956cf45792e4caa5885e69fba00bdbc6ffafbfa020300e549b208ee5ff1", size = 101250, upload-time = "2025-04-24T03:35:25.427Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/04/4b/29cac41a4d98d144bf5f6d33995617b185d14b22401f75ca86f384e87ff1/h11-0.16.0-py3-none-any.whl", hash = "sha256:63cf8bbe7522de3bf65932fda1d9c2772064ffb3dae62d55932da54b31cb6c86", size = 37515, upload-time = "2025-04-24T03:35:24.344Z" }, +] + +[[package]] +name = "httpcore" +version = "1.0.9" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "certifi" }, + { name = "h11" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/06/94/82699a10bca87a5556c9c59b5963f2d039dbd239f25bc2a63907a05a14cb/httpcore-1.0.9.tar.gz", hash = "sha256:6e34463af53fd2ab5d807f399a9b45ea31c3dfa2276f15a2c3f00afff6e176e8", size = 85484, upload-time = "2025-04-24T22:06:22.219Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/7e/f5/f66802a942d491edb555dd61e3a9961140fd64c90bce1eafd741609d334d/httpcore-1.0.9-py3-none-any.whl", hash = "sha256:2d400746a40668fc9dec9810239072b40b4484b640a8c38fd654a024c7a1bf55", size = 78784, upload-time = "2025-04-24T22:06:20.566Z" }, +] + +[[package]] +name = "httpx" +version = "0.28.1" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "anyio" }, + { name = "certifi" }, + { name = "httpcore" }, + { name = "idna" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/b1/df/48c586a5fe32a0f01324ee087459e112ebb7224f646c0b5023f5e79e9956/httpx-0.28.1.tar.gz", hash = "sha256:75e98c5f16b0f35b567856f597f06ff2270a374470a5c2392242528e3e3e42fc", size = 141406, upload-time = "2024-12-06T15:37:23.222Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/2a/39/e50c7c3a983047577ee07d2a9e53faf5a69493943ec3f6a384bdc792deb2/httpx-0.28.1-py3-none-any.whl", hash = "sha256:d909fcccc110f8c7faf814ca82a9a4d816bc5a6dbfea25d6591d6985b8ba59ad", size = 73517, upload-time = "2024-12-06T15:37:21.509Z" }, +] + +[[package]] +name = "idna" +version = "3.20" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/f5/08/8eea9d4b8302028f3abb2c0813953f7aec26d33b7a8960ed760e65ff29fa/idna-3.20.tar.gz", hash = "sha256:a7db850025b95ded1eae8a46181a1a6c56c92c96f0e2b005d9ff8dc0210cab44", size = 216463, upload-time = "2026-09-17T14:11:04.752Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/58/a2/bb081bab032533a855d44de1d56f8e8426114ff1ba5d1f07a438a0a654f8/idna-3.20-py3-none-any.whl", hash = "sha256:ab7ae7122974553370f0bdb919e1a960b2cd1bc1ef0276416d896db81c14582c", size = 69583, upload-time = "2026-09-17T14:11:03.168Z" }, +] + +[[package]] +name = "iniconfig" +version = "2.3.1" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/01/e1/2069291243c926a2ff1cd706c7f3eeb9b62144bf60f77c9fb9ff2fb26bd3/iniconfig-2.3.1.tar.gz", hash = "sha256:67f4b9c50da0dedf52af349e7749a80a9057a5031199791b906c3bb3ae878960", size = 21209, upload-time = "2026-10-06T22:48:38.076Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/56/43/4ca9e49d27a1fcf6bece6f6aec0ea46bb9112489b93d4b688fb415457bdb/iniconfig-2.3.1-py3-none-any.whl", hash = "sha256:9121e2c1fdb355232495be3194c8dfe87ccc2d5dee45947b78e68f499790d7a7", size = 7552, upload-time = "2026-10-06T22:48:36.959Z" }, +] + +[[package]] +name = "opentelemetry-api" +version = "1.45.1" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "typing-extensions" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/2e/02/6e0ae9cc61bd3169d401077b507b3ebc344745171e1051ab430be012dcd9/opentelemetry_api-1.45.1.tar.gz", hash = "sha256:aa38ed19bcc084ba42782a73255b3582283eced7ad6dddbd6695189e69adfb75", size = 72804, upload-time = "2026-10-06T17:32:58.133Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/1e/41/f7dcf80b81ee8e71c1a2b59f14208bc723edbd89ed027a73b175abf6348e/opentelemetry_api-1.45.1-py3-none-any.whl", hash = "sha256:b31553efa588ae44bc306f863c785c5333a9ecc091248c6ee68b4b6c87fdedfb", size = 60256, upload-time = "2026-10-06T17:32:33.506Z" }, +] + +[[package]] +name = "packaging" +version = "26.3" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/7d/fa/3944b40b07da9ce895c0e6303a5ab7d53da063554f534556b134a54d6093/packaging-26.3.tar.gz", hash = "sha256:94edc256424af38762eb31306eed28beb9f0efc50a8837492c9d6fd6004aed79", size = 313412, upload-time = "2026-08-04T18:15:28.737Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/63/34/ba1c580383c9eada3711951fef0795c80b829a078d72188184bcab9dd527/packaging-26.3-py3-none-any.whl", hash = "sha256:d7193f7c8e4e93f444fde0262bf90af30e16fa0ad0ad44cb553c87339b23cd1c", size = 129956, upload-time = "2026-08-04T18:15:27.159Z" }, +] + +[[package]] +name = "pluggy" +version = "1.7.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/bf/db/7fc19e6f2dc92a966727031389fc2e08b558f0f25eb7403c1119ad4713cd/pluggy-1.7.0.tar.gz", hash = "sha256:d1eaa46ebb595891b860ab086b4d09c8588af65ebd4361b8e8f4bb8920b90ba8", size = 123304, upload-time = "2026-10-15T09:50:58.343Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/40/9e/2b38731e0fc536806f16490e1a12d7f0dc2a1235aa8cc07bcc75416a7daa/pluggy-1.7.0-py3-none-any.whl", hash = "sha256:7dd7b0d8832ba3cb632c306926ded123429211b83641b35dc5c41ad2d34f9bec", size = 27082, upload-time = "2026-10-15T09:50:56.808Z" }, +] + +[[package]] +name = "pycparser" +version = "3.12" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/cb/27/eeb9f307bf07060f3d9f9aa0fb8c15b01bdfded0a941e4b2719c7f94cacd/pycparser-3.12.tar.gz", hash = "sha256:f03387877eab82ce01bbdfd0ba7252ee55a90b1c708d5129e2ce915475cf1db6", size = 158785, upload-time = "2026-10-22T13:40:03.56Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/b6/ae/315bbeee126a769cbde43cf4908acb4b40408d8bf8bbf334dd7368d8dadf/pycparser-3.12-py3-none-any.whl", hash = "sha256:a076f3f489b39b43ed13563a1dafe42447445bec2e294154ec5c57fcdda4c85e", size = 62600, upload-time = "2026-10-22T13:40:02.021Z" }, +] + +[[package]] +name = "pydantic" +version = "2.14.1" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "annotated-types" }, + { name = "pydantic-core" }, + { name = "typing-extensions" }, + { name = "typing-inspection" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/7c/0b/8e10b2e693af8ec54346a14caf36221334775975a747c9ceaa3f8371d96d/pydantic-2.14.1.tar.gz", hash = "sha256:94f478203dd03404682a1ada216965651dd74b1d2d5ffd62e00e0837caab5c26", size = 900362, upload-time = "2026-10-11T18:37:55.396Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/35/ea/a56b9fe5066f3537b7882f77e9c5dfb26d8c2eefdaed9b5fc73d57b4dc22/pydantic-2.14.1-py3-none-any.whl", hash = "sha256:9195d967ec791692a04438115466764fb8b9a27b31f14a760437694f40d6b454", size = 488106, upload-time = "2026-10-11T18:37:53.437Z" }, +] + +[[package]] +name = "pydantic-core" +version = "2.50.1" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "typing-extensions" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/a6/24/af4ec4be49fbc810f35b0bdcacc3d433b56bbfa469fd3bfd4ae116cd9bf1/pydantic_core-2.50.1.tar.gz", hash = "sha256:e50d7b94baac6c7d09927fa5ca5800a0c7ee5015c7fcff65beb3a1931b5a6e09", size = 513515, upload-time = "2026-10-11T18:35:44.82Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/ee/94/101b49a6c63f99586755690696eae14532772587d9e39e93f7b8d28a49da/pydantic_core-2.50.1-cp312-cp312-macosx_10_12_x86_64.whl", hash = "sha256:704075d10b74f2f3c6e15407c696d88701df35fc8953f434a431add0d0074db0", size = 2222428, upload-time = "2026-10-11T18:32:20.228Z" }, + { url = "https://files.pythonhosted.org/packages/db/a3/f8b1b39349c33037c73d7a1b794c9c29d8f07d5bd2b74399c1375a529cc6/pydantic_core-2.50.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:e8e1d6ce820aa23317e8209a86bd65a540973c12dc7552b48a4f6c8e9926815e", size = 2025779, upload-time = "2026-10-11T18:32:21.723Z" }, + { url = "https://files.pythonhosted.org/packages/d2/2d/862a7d115305cc621358e51ba13f296e0ffdf4fbd984be9f63bc7862730b/pydantic_core-2.50.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:c18db21573bd2c6489f9a544b7499f0df2853958c568e5e783536ee1f690af41", size = 2048429, upload-time = "2026-10-11T18:32:23.3Z" }, + { url = "https://files.pythonhosted.org/packages/c0/7d/fed95d18bf2b5abe2d5ab2bbec4184bfc22b6805994a33ccdae8edffd25a/pydantic_core-2.50.1-cp312-cp312-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:cb57f304525a5e3c13333b772bf9a473f36326e9c821b2e8e1b2fd36f80ae2c3", size = 2173274, upload-time = "2026-10-11T18:32:24.697Z" }, + { url = "https://files.pythonhosted.org/packages/93/1e/c6f22ceac65dc3d291ff79bea0eb74cbd1de8b128f01fee48af03bcea1e1/pydantic_core-2.50.1-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:a27c09d86600f1bf2fe3f37e1ae697faf3143931c09322cd799da94deee923b5", size = 2360403, upload-time = "2026-10-11T18:32:26.281Z" }, + { url = "https://files.pythonhosted.org/packages/2c/97/190b5b6bfe4c72f265feb657913eb30749193927a5ad7b83cfa7866a25a2/pydantic_core-2.50.1-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:46b3301d3b5c886f77de7546e47274a5842c622ea2020b8c6524c6b66913b4a6", size = 2439799, upload-time = "2026-10-11T18:32:27.844Z" }, + { url = "https://files.pythonhosted.org/packages/90/24/48cd98388e4ac2c08d0800af36d15413db15e20387f1038123a2c86cb2f6/pydantic_core-2.50.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:93ba4e9d8210d941c200431a56b2c0400b131865947903937ed3ec5404307d2e", size = 2160157, upload-time = "2026-10-11T18:32:29.553Z" }, + { url = "https://files.pythonhosted.org/packages/00/86/d909133d0b9979ed14c20f110f21124a0e346caf071bd66ac5af3009062b/pydantic_core-2.50.1-cp312-cp312-manylinux_2_31_riscv64.whl", hash = "sha256:e5faeaee74a57d32b3ab3aebad2e348f06d3ba946fc5d28c1728455f00a3d13a", size = 2229523, upload-time = "2026-10-11T18:32:31.027Z" }, + { url = "https://files.pythonhosted.org/packages/90/31/4b43f08131b2098e73a852fd932063385f3103b33839fd9d1abdb89e673d/pydantic_core-2.50.1-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:a3cda0e538208e5d722bbf3698b24f19c0a7d05bc8d5f8a7f9b121ea7fa243d9", size = 2242700, upload-time = "2026-10-11T18:32:32.622Z" }, + { url = "https://files.pythonhosted.org/packages/88/77/de39658569dc7a4c293d110a89629f61145e7538f00d1e4280c28debefd3/pydantic_core-2.50.1-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:57f51b31ff826e2859120cf4737c5a758a48d96f3e97da40ccee1796d58078ff", size = 2278452, upload-time = "2026-10-11T18:32:34.165Z" }, + { url = "https://files.pythonhosted.org/packages/46/bd/1eeb9e4e791e81210ef9096f58080b32ba15b5b13c108d50aaa3f8ce9f73/pydantic_core-2.50.1-cp312-cp312-musllinux_1_1_armv7l.whl", hash = "sha256:8daa7ee75245d43ad7d747e5c9ecc1b1d06552f72b14887e9276f787d57375f4", size = 2450098, upload-time = "2026-10-11T18:32:35.547Z" }, + { url = "https://files.pythonhosted.org/packages/1c/e6/b2accfdff17e5a88d6358536702146de00f9339adaa4d5bbe1ee93cb4832/pydantic_core-2.50.1-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:acbf31f37c53a5ac0c34706c80b4f5107ba20b05fdd3816124bf236ef0c57dd2", size = 2476839, upload-time = "2026-10-11T18:32:37.119Z" }, + { url = "https://files.pythonhosted.org/packages/3b/7e/c8a83eb5d2cd42c2e13507150fb777b1edea5a018adc9cbf2858a1d08285/pydantic_core-2.50.1-cp312-cp312-win32.whl", hash = "sha256:45b11cac094aa25725581d9304eee93c9028516b9ea80dd9e175e13a5a2c840e", size = 2101425, upload-time = "2026-10-11T18:32:38.593Z" }, + { url = "https://files.pythonhosted.org/packages/c5/17/8bbd530b8659e9d963f5b16f6cb8e159f4cd174b4d6304e48969ab12dba8/pydantic_core-2.50.1-cp312-cp312-win_amd64.whl", hash = "sha256:132529c83901437ff642f585216831bf5fd7a91df66829907e155192ead62498", size = 2172522, upload-time = "2026-10-11T18:32:40.112Z" }, + { url = "https://files.pythonhosted.org/packages/af/9f/a79d690b127e4e3cff143d031538ab9aa715f6b2fbeecbd07cd6f2bf9fb7/pydantic_core-2.50.1-cp312-cp312-win_arm64.whl", hash = "sha256:4e834f6a8e4ff772dcc34f58ef5504147a3ea5b0f4eeb13b0f8eb2ca75ac57f1", size = 2161366, upload-time = "2026-10-11T18:32:41.606Z" }, + { url = "https://files.pythonhosted.org/packages/ae/57/0e237d7091d2cd44a35d243b7344227f90440166860469cd036afc23a04d/pydantic_core-2.50.1-cp313-cp313-macosx_10_12_x86_64.whl", hash = "sha256:d5e062c01286d861fd6a1c4ff6e063547b3e713067f2df033c0ff97ac2ca006b", size = 2222774, upload-time = "2026-10-11T18:32:43.103Z" }, + { url = "https://files.pythonhosted.org/packages/f7/b9/c720e56858d4e1539503297ed37063e0c08e0f3541c41b777f6a800f75fa/pydantic_core-2.50.1-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:0c003c3b7f49debb893d2d85ae099ac5959c9839e2f330fadb1fcdf7a6594482", size = 2024738, upload-time = "2026-10-11T18:32:44.587Z" }, + { url = "https://files.pythonhosted.org/packages/4d/b8/fbfc25875219cc060e613170ff10e850c6d8924beb4910da57c2ee3ba1d2/pydantic_core-2.50.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:409e0ea40ec30d9158f33574fd758e689f6045a0f2596701828c27816ca9687d", size = 2047049, upload-time = "2026-10-11T18:32:46.164Z" }, + { url = "https://files.pythonhosted.org/packages/d7/43/34210124d504c553688f2f04b48500b131237528ac545b445e0d6d30e0d5/pydantic_core-2.50.1-cp313-cp313-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:131059670f1d2444269b8585cb888963994871932447c08b39ac6a51fcfef658", size = 2173415, upload-time = "2026-10-11T18:32:47.722Z" }, + { url = "https://files.pythonhosted.org/packages/65/cf/6e178e8fdc11da5965bef980983bf46326a42f436871dd51ba0a57f39df1/pydantic_core-2.50.1-cp313-cp313-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:6dbcbee53bf17196a7f745aa9bf5a9603953a1e365b1f020be3207c676a3e7c4", size = 2361719, upload-time = "2026-10-11T18:32:49.217Z" }, + { url = "https://files.pythonhosted.org/packages/11/14/bd5169d356aa91bf777e28ba0b281c192d286d03c2812c9c9db023a2f00e/pydantic_core-2.50.1-cp313-cp313-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:325c23f3e35cfbf0fe3486fa5f7260d1e45885173002d30a28ca019994124255", size = 2439803, upload-time = "2026-10-11T18:32:51.025Z" }, + { url = "https://files.pythonhosted.org/packages/1c/bc/d79d000e5203ebef39af839f2ce77a777fcad6e08ad26af9a2fcd114ffc8/pydantic_core-2.50.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:17e722e156d0444ecaefbe640bdb60928752bf2013e2b7a11cdb099aaae19bec", size = 2158402, upload-time = "2026-10-11T18:32:52.714Z" }, + { url = "https://files.pythonhosted.org/packages/1b/a5/4902cb5fd599422c130bd3124ab31ee8b771199bd56662702eed07d3fec7/pydantic_core-2.50.1-cp313-cp313-manylinux_2_31_riscv64.whl", hash = "sha256:aa8224f10880d9bf1b5993988ba153d42a8b4f3f4f511f93b1f09c93ff613c72", size = 2229755, upload-time = "2026-10-11T18:32:54.126Z" }, + { url = "https://files.pythonhosted.org/packages/1a/f5/c1481f8669f6060d89110c9b1374173fc8767ca276b84f4870bd8acd5e3f/pydantic_core-2.50.1-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:41bc8237121bd8dc8d888dfd6279fc166ffc88c1f1bf3a8bf00869680533ca4c", size = 2242303, upload-time = "2026-10-11T18:32:55.641Z" }, + { url = "https://files.pythonhosted.org/packages/04/f9/77fc3c7653ba9b6e42049e17e96b25388187d4a7c274ab1cb07f58ac8419/pydantic_core-2.50.1-cp313-cp313-musllinux_1_1_aarch64.whl", hash = "sha256:45c6266d071c241f2a168d45bf8c54344f0effce35e7e6b73afdec11f3687568", size = 2278345, upload-time = "2026-10-11T18:32:57.38Z" }, + { url = "https://files.pythonhosted.org/packages/95/9b/0579c5d12e7f2b16b27e6782427987341fcce07b0725e02ddb0b74add0c4/pydantic_core-2.50.1-cp313-cp313-musllinux_1_1_armv7l.whl", hash = "sha256:1deeacb112d14d3f4fcb16b165f7dbaf76c70ba6e82f37ba042bdab51970a0b8", size = 2449947, upload-time = "2026-10-11T18:32:58.896Z" }, + { url = "https://files.pythonhosted.org/packages/a8/ac/1b677db91eba54cc5922f4de6edc46ba45c2bd712dfdc0130382d158e214/pydantic_core-2.50.1-cp313-cp313-musllinux_1_1_x86_64.whl", hash = "sha256:1c96fd793b73d1b92e65570132505498fe7b21eaef73cdf74e67e5dfba7ac9e4", size = 2476889, upload-time = "2026-10-11T18:33:00.665Z" }, + { url = "https://files.pythonhosted.org/packages/4d/2a/3a9f6624ee3ea9ccba5249dde11418bb4c35780a7a92608f8768bd3fea39/pydantic_core-2.50.1-cp313-cp313-win32.whl", hash = "sha256:06ead20d39ffd6f2f6f2a8f8a6de67ff8bb1b4f14a8a30e058502514ee2ac685", size = 2101118, upload-time = "2026-10-11T18:33:02.329Z" }, + { url = "https://files.pythonhosted.org/packages/2d/1f/323f78ddd9d9938aac420c1abb4e8ba799fc8bdab0acc67c0593b837c979/pydantic_core-2.50.1-cp313-cp313-win_amd64.whl", hash = "sha256:7816e98acc08119dc0f340ab167048ecc54126316330c1f0caf7c6756c88e28f", size = 2170840, upload-time = "2026-10-11T18:33:03.919Z" }, + { url = "https://files.pythonhosted.org/packages/cb/09/8497c52a739ae425c3ac2f7f56414cbc711c67d374346174f40fe2062644/pydantic_core-2.50.1-cp313-cp313-win_arm64.whl", hash = "sha256:c17799a62c142d61b8a3c51752a7cbc87fe2ad4ccfab10e628a77b405075c662", size = 2161633, upload-time = "2026-10-11T18:33:05.518Z" }, + { url = "https://files.pythonhosted.org/packages/49/33/28b96e81677153715e3eafb9f26663a80841e859fde282a380359b0d3fa1/pydantic_core-2.50.1-cp314-cp314-macosx_10_12_x86_64.whl", hash = "sha256:1cf41f1ae3fa155cf167a72689ad044bcc1e3c97e064123677149bdfb5dafc4a", size = 2224428, upload-time = "2026-10-11T18:33:07.153Z" }, + { url = "https://files.pythonhosted.org/packages/94/40/15c06410c9b7b8da5805d27b64e09bd3f900e986728106db2689dbc51513/pydantic_core-2.50.1-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:4df197990c15b5a37c5a277d131d9f2c67de6133f2e5dafd80d9bba4b99f46f9", size = 2023740, upload-time = "2026-10-11T18:33:08.763Z" }, + { url = "https://files.pythonhosted.org/packages/a1/4e/5eb629f6efc2a27e421d789dd4bfacbb5f6d09c80c28b13d1e87d73163d5/pydantic_core-2.50.1-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:0036473f5583e6a60e50b8b21651511564277a3f05cc5dab8cf579f552cd5f6c", size = 2049435, upload-time = "2026-10-11T18:33:10.366Z" }, + { url = "https://files.pythonhosted.org/packages/ba/8e/f195aebec49ad12318876ac2368c197a7939f5d52f8e156d2238ef8a4588/pydantic_core-2.50.1-cp314-cp314-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:992c3514ec891fa7858099183e4d64e6bd5a5d4ff452fae29df22faa77a006bb", size = 2172975, upload-time = "2026-10-11T18:33:12.368Z" }, + { url = "https://files.pythonhosted.org/packages/e0/f5/7ad9fb83010cd5ea0948409db105676ed779c4e709e2d3d89b9fe2558794/pydantic_core-2.50.1-cp314-cp314-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:739dc730e6be3bd5ec2f4ab5cfc7eb047cc45fc1497b3bafec74ff2ed07df597", size = 2364197, upload-time = "2026-10-11T18:33:14.244Z" }, + { url = "https://files.pythonhosted.org/packages/ca/fb/bf0aab3e78301d202b82a0322ec968cd703b11fc0623fde9a28708936f62/pydantic_core-2.50.1-cp314-cp314-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:32fad3a91e51b6d2039c572db04a5a873260b399f6bd62c3552671fa7a4a2899", size = 2444259, upload-time = "2026-10-11T18:33:15.79Z" }, + { url = "https://files.pythonhosted.org/packages/45/35/38f6d6564fae57d9b12e5676dfa947e0e7d5c46dbeaa7eb3352261d6d299/pydantic_core-2.50.1-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:42b54c2c90ad348b5e3a85e03e715d572c1fde357ef104cdfe3b03b697a404ea", size = 2159857, upload-time = "2026-10-11T18:33:17.51Z" }, + { url = "https://files.pythonhosted.org/packages/65/a0/fb0a3ca10f139dcf765b2d312d10cf0f65c57c59993229d00ad12b14ceff/pydantic_core-2.50.1-cp314-cp314-manylinux_2_31_riscv64.whl", hash = "sha256:2df1ff41884de2bc4b307bafd7c40a691094fad2ff8e767e5b45a319257bcf4e", size = 2233954, upload-time = "2026-10-11T18:33:19.591Z" }, + { url = "https://files.pythonhosted.org/packages/8c/6a/e63842252702aa4ec6e6b7178ca85e541a77459076592c23ebe2d9840b33/pydantic_core-2.50.1-cp314-cp314-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:fe90228920fd8ff2be62622b6bb8a2b11acd65046d50c6b130614b5879605a20", size = 2243876, upload-time = "2026-10-11T18:33:21.393Z" }, + { url = "https://files.pythonhosted.org/packages/39/25/5991cf8318b37e0dfab47b87541619a1df8501a793cba0d978846cba37a7/pydantic_core-2.50.1-cp314-cp314-musllinux_1_1_aarch64.whl", hash = "sha256:844b869f118e22a41a091bdcedda8a71bc1b0f62c38d1a0c3211cece47e1d8fc", size = 2277908, upload-time = "2026-10-11T18:33:23.324Z" }, + { url = "https://files.pythonhosted.org/packages/a7/3e/3ee8baaa6cc25a6961c69168cf9ff0f002d56f4e0d541ad6724c18fb61f3/pydantic_core-2.50.1-cp314-cp314-musllinux_1_1_armv7l.whl", hash = "sha256:2eb75304506894a281d346220a4f7481a1b8729577c5ed2a05395991966a8396", size = 2449285, upload-time = "2026-10-11T18:33:24.942Z" }, + { url = "https://files.pythonhosted.org/packages/c0/c7/acbec6deac13fe697a80c275a9b6661db62c4d323bac8a47347b1f39c7cd/pydantic_core-2.50.1-cp314-cp314-musllinux_1_1_x86_64.whl", hash = "sha256:6b20a4bffabdad0db2927ac034ae3b8a681b1f7a0182f3e60b479ad2fde21ebb", size = 2479013, upload-time = "2026-10-11T18:33:26.925Z" }, + { url = "https://files.pythonhosted.org/packages/10/08/21a3f237b264389f6219d053ee78fc1b5c2fd402c1b1cb2b6cb8b85f9834/pydantic_core-2.50.1-cp314-cp314-pyemscripten_2026_0_wasm32.whl", hash = "sha256:99ba9bc2b8062ea0c326a990f7f00e6530c23579de66dd246e72c4cafef950a5", size = 1484400, upload-time = "2026-10-11T18:33:28.693Z" }, + { url = "https://files.pythonhosted.org/packages/09/ce/077a6d262d12ef09108377ac0717f029f420d773ace63cafd6143af75568/pydantic_core-2.50.1-cp314-cp314-win32.whl", hash = "sha256:cf356f70551d40374eaffb1aa63f1eb6d2006681cbd7a9faea173ce0f4dd7cd2", size = 2103222, upload-time = "2026-10-11T18:33:30.326Z" }, + { url = "https://files.pythonhosted.org/packages/14/4c/350a2415209c43d670eb71d3c040f332c04a30583d39e311b05c7ac15762/pydantic_core-2.50.1-cp314-cp314-win_amd64.whl", hash = "sha256:d32f3acc081cc3923386d88f422cde8892335e95f034e0104bb4cf9310d9915f", size = 2171586, upload-time = "2026-10-11T18:33:32.139Z" }, + { url = "https://files.pythonhosted.org/packages/bf/92/9bea6ca96580a0902fed366f064f0829e404f41889b34543279a1162b888/pydantic_core-2.50.1-cp314-cp314-win_arm64.whl", hash = "sha256:bed5163e03b98bc1fa2eb05d74c63d9c5c95d8ed6254985481640fbf5e237dea", size = 2155773, upload-time = "2026-10-11T18:33:33.896Z" }, + { url = "https://files.pythonhosted.org/packages/86/8c/f121f073cf32bdd5cba7e6230b1ce0ac845b0cf43e44dd597d95af272db2/pydantic_core-2.50.1-cp314-cp314t-macosx_10_12_x86_64.whl", hash = "sha256:9572c1369e9c9da2d64a7b7992c786d90ff295abc93964cfe3125e4290768070", size = 2234017, upload-time = "2026-10-11T18:33:35.588Z" }, + { url = "https://files.pythonhosted.org/packages/a4/69/2bb2bcd6146cffe98d760a46c42ae71efd5151d9b2f9c9bf6619a3b32083/pydantic_core-2.50.1-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:2005207aafe1231315718bf6ed5d064a7300fb4772754af35ee72fc68159492e", size = 2001016, upload-time = "2026-10-11T18:33:37.57Z" }, + { url = "https://files.pythonhosted.org/packages/20/b3/fbf854c7d07ec114260c26e9e2071a4381740f9ae09641dbfcbdf2a18c45/pydantic_core-2.50.1-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:64f6047f62a6c5ae08d0a6afb035667aa2d97c3d20d69762e034c5ea144d92a5", size = 2023015, upload-time = "2026-10-11T18:33:39.433Z" }, + { url = "https://files.pythonhosted.org/packages/65/20/6de55b2f92cdb614b745c6e9ced639fc4fd7e1e77604825a88bdece6fcbd/pydantic_core-2.50.1-cp314-cp314t-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:1ef800dd7d85bcdadf4c3076e4c94e43939493558a3b69a1ea830c706d4617bb", size = 2192543, upload-time = "2026-10-11T18:33:41.381Z" }, + { url = "https://files.pythonhosted.org/packages/0c/d9/19e91c94bd5c405945ce2f15526808aea37e162c253160de8ed7bf70b406/pydantic_core-2.50.1-cp314-cp314t-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:b0135bcdcaa0f23573f286e4cb5e0fd2962700964ed13df085b85f2b97aeab9e", size = 2388704, upload-time = "2026-10-11T18:33:43.167Z" }, + { url = "https://files.pythonhosted.org/packages/b6/bc/2e24c8415eae1a25ee5a5484946a917123bad2e9d01689a759236928175a/pydantic_core-2.50.1-cp314-cp314t-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:0b3a6f334c6a2345ca15318ff894502a90012536404b37c844a976c76c846e0b", size = 2464118, upload-time = "2026-10-11T18:33:44.856Z" }, + { url = "https://files.pythonhosted.org/packages/bd/1f/945b8053cb061c64e102bcaf7bfb9ed740c0bd4349f9bb978a7d4ddff4ab/pydantic_core-2.50.1-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:06e01fbbfdb9be777b316a71b6c49efaf4a08b615d0a98d678cda3023f79d019", size = 2150142, upload-time = "2026-10-11T18:33:46.661Z" }, + { url = "https://files.pythonhosted.org/packages/2b/78/96a3e50bf0d64aaae781107eb9335b7529d05a85793ed6e7241c4cd1d931/pydantic_core-2.50.1-cp314-cp314t-manylinux_2_31_riscv64.whl", hash = "sha256:a29a061fec0b4e2d714f277e70a3a18125ecff803f2fea6eade2f2e53711d112", size = 2245577, upload-time = "2026-10-11T18:33:48.574Z" }, + { url = "https://files.pythonhosted.org/packages/7a/5d/a6038a0322232758a6ebfa709f4ca14a60bf5b93940cd0b345056a557da4/pydantic_core-2.50.1-cp314-cp314t-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:f5187624823423e1d1b82b1072ac41dc837389e18d3d0572cc19bbee46cd550a", size = 2263728, upload-time = "2026-10-11T18:33:50.527Z" }, + { url = "https://files.pythonhosted.org/packages/0d/4b/76ded3333a457a9344c4f2d63f2d82d0101654b05178fa4ddfe7d3627674/pydantic_core-2.50.1-cp314-cp314t-musllinux_1_1_aarch64.whl", hash = "sha256:3e46a9eb0a0901dd6275e6b06ac3a464885ef350ec4121fe486869de8053e4bb", size = 2293630, upload-time = "2026-10-11T18:33:52.362Z" }, + { url = "https://files.pythonhosted.org/packages/a9/00/9eca378335c9c1b72bc779bf6e4c2a82ce784f14ec48a0e87102c9870e05/pydantic_core-2.50.1-cp314-cp314t-musllinux_1_1_armv7l.whl", hash = "sha256:756d669f04e62ec4148ecfe22be6a4484d9b1181a6ef32e205ebfd200540858b", size = 2468048, upload-time = "2026-10-11T18:33:54.118Z" }, + { url = "https://files.pythonhosted.org/packages/35/ca/e3832e9cf93651251de43c8c5c029ed680a3c1a0a1b17ee26c81bed08cbd/pydantic_core-2.50.1-cp314-cp314t-musllinux_1_1_x86_64.whl", hash = "sha256:c516cc5367ca3448995d42cb994bf3f4c9002d2a7c22eac9622551269ad1b807", size = 2512159, upload-time = "2026-10-11T18:33:55.99Z" }, + { url = "https://files.pythonhosted.org/packages/4b/f2/773469b5a10a39116a2cb17edaf6d722f017dd8da07161b371465311c542/pydantic_core-2.50.1-cp314-cp314t-win32.whl", hash = "sha256:9d1bed94af6a63835461f3cf7502058eb166c58c4778e11d0f433cfb1bd69e19", size = 2098406, upload-time = "2026-10-11T18:33:58.043Z" }, + { url = "https://files.pythonhosted.org/packages/ee/42/0bb74f8f25204b259b11ab7c12dc7f180893b6bd706118b385147fb6efd5/pydantic_core-2.50.1-cp314-cp314t-win_amd64.whl", hash = "sha256:c8dce1f1e0e5358b682a6ad3fa5e31b31d4560997b8e61417e9217c8d60f8a0c", size = 2148481, upload-time = "2026-10-11T18:33:59.913Z" }, + { url = "https://files.pythonhosted.org/packages/47/0d/d801646c9679a4e630e15cf521d4108b93854b42a6e6e02391bd4c6b1095/pydantic_core-2.50.1-cp314-cp314t-win_arm64.whl", hash = "sha256:ceff0acc940be2715bd6ad17b24c0e5304abf44f6efd0f81ee8499e640f9dc86", size = 2174972, upload-time = "2026-10-11T18:34:01.875Z" }, + { url = "https://files.pythonhosted.org/packages/b2/84/23984b763d8862a02a13d27a44b6e8169428fd85ecfed88f54c29108604d/pydantic_core-2.50.1-cp315-cp315-macosx_10_12_x86_64.whl", hash = "sha256:8a6791afa2245e6c6b180122d105941644f5bd410bb18623b408808cc41a3102", size = 2224599, upload-time = "2026-10-11T18:34:04.016Z" }, + { url = "https://files.pythonhosted.org/packages/4d/90/a63cf8586abc1d1a3f6d9b18f0224789ebf003851f092ebda3c7c863fd32/pydantic_core-2.50.1-cp315-cp315-macosx_11_0_arm64.whl", hash = "sha256:84f34323a61a365b4e9295de6028474754829aaddd59c7bf1a040e7487ef8f3c", size = 2024191, upload-time = "2026-10-11T18:34:05.901Z" }, + { url = "https://files.pythonhosted.org/packages/a6/6a/f34bff9808ffb4907fbf5f5040457d253cacf2da7fce9efbc99ca1b1a44d/pydantic_core-2.50.1-cp315-cp315-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:23edad659e8dbd8ca7e4e877fe6c81573abbdf215bd25a68b53e1272f58b80c7", size = 2048252, upload-time = "2026-10-11T18:34:07.757Z" }, + { url = "https://files.pythonhosted.org/packages/b2/54/13f419bf1eb59852003818e25935aaf175687d978f4c4bca70e08fe40a3b/pydantic_core-2.50.1-cp315-cp315-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:3a5fce22f1e87d181e924e12da7d81cfe031fb3881a5ddf26ad28f141756ca43", size = 2173376, upload-time = "2026-10-11T18:34:09.592Z" }, + { url = "https://files.pythonhosted.org/packages/6d/6c/b5a34d24cd0c81669d8f8339d74e6815abcf2f8fb48ab4b49b84c09be1d5/pydantic_core-2.50.1-cp315-cp315-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:c73622ef819328873b53109ee4f77ceb598bffedd02daf916102be3228866b78", size = 2364559, upload-time = "2026-10-11T18:34:11.534Z" }, + { url = "https://files.pythonhosted.org/packages/eb/8d/d64d6216a8df365082665927ff923f183056f9049fee08e9777c9ac05296/pydantic_core-2.50.1-cp315-cp315-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:ce8c25ca38cc0e3d7753ba180808de2c0c8cb24eae0df64491e40921454e9831", size = 2444697, upload-time = "2026-10-11T18:34:13.535Z" }, + { url = "https://files.pythonhosted.org/packages/b8/0d/1b1149f60a00ea21ba5f70e28acbd40feb4598af414f80f53c921fac07c9/pydantic_core-2.50.1-cp315-cp315-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:7689580e72a642ab5ec64d5f55b2e33636fa43b4ebe63c0c2c965ef307c7d1aa", size = 2159961, upload-time = "2026-10-11T18:34:15.56Z" }, + { url = "https://files.pythonhosted.org/packages/1e/35/f236549299dcc78e71e945495d7ec67e78d20844d0999c60601685003031/pydantic_core-2.50.1-cp315-cp315-manylinux_2_31_riscv64.whl", hash = "sha256:d5c0e32fdbce7f1e8ef4d11f655694bf5f4175c757a9f1dc2be09b8864e5bcf5", size = 2234581, upload-time = "2026-10-11T18:34:17.502Z" }, + { url = "https://files.pythonhosted.org/packages/6a/85/26901a490522b7f75ef9bb9a7afb73e5bb550f0e1cb5b99a0069183e2eb9/pydantic_core-2.50.1-cp315-cp315-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:40f523349960fa30f3ea51404308ff50f9997a90df639590f47a057c1f32b415", size = 2244090, upload-time = "2026-10-11T18:34:19.402Z" }, + { url = "https://files.pythonhosted.org/packages/ca/2c/481bcfc70ceeb77a778ca6e5b705fe592cb64735c108157f81b7dd9c280e/pydantic_core-2.50.1-cp315-cp315-musllinux_1_1_aarch64.whl", hash = "sha256:d4193206b6587047437f6f11d7e776df23e1c1e23af2a54d9347275614791e10", size = 2277948, upload-time = "2026-10-11T18:34:21.317Z" }, + { url = "https://files.pythonhosted.org/packages/24/eb/f1e09333faa7ba447cde967310f758430cc7c5e987bdab5228816c70030d/pydantic_core-2.50.1-cp315-cp315-musllinux_1_1_armv7l.whl", hash = "sha256:84bc765b282a9d5b7fe0348b8648904f25a6a04b2139da52b1dd30c8ac3a2c8f", size = 2449688, upload-time = "2026-10-11T18:34:23.321Z" }, + { url = "https://files.pythonhosted.org/packages/d1/b3/036bde636db8f76d92996e81aefc75678ab5cec4a07eea1ad0c72a893fc3/pydantic_core-2.50.1-cp315-cp315-musllinux_1_1_x86_64.whl", hash = "sha256:ed1e728b39a383c81035b2459cfcb35d99dfb01f7d6ebe3a913bc1cc5b81e459", size = 2479286, upload-time = "2026-10-11T18:34:25.214Z" }, + { url = "https://files.pythonhosted.org/packages/d0/a3/07f018294ee18d144afeb6df1a47d9e92960f014be45c5ed13519fa5af95/pydantic_core-2.50.1-cp315-cp315-win32.whl", hash = "sha256:bc94f474417604bd383d2cd445d071b07dd55fedceed3ce33407bf1fcc107290", size = 2103683, upload-time = "2026-10-11T18:34:27.42Z" }, + { url = "https://files.pythonhosted.org/packages/5f/98/f9bd7e1f9b6709f155acb9ef826d9c3884fe925f811fd8e55b9b52280bad/pydantic_core-2.50.1-cp315-cp315-win_amd64.whl", hash = "sha256:983a662de2571cb2502fc8ff47b6770b03d025d2eb314c92f77b3f07c74720ed", size = 2171681, upload-time = "2026-10-11T18:34:29.508Z" }, + { url = "https://files.pythonhosted.org/packages/10/87/4bb3e1e7f385c076ab5af4d6dd0571b22042cd8207eb810d5b9fef15ae31/pydantic_core-2.50.1-cp315-cp315-win_arm64.whl", hash = "sha256:94845ff54dc5193f228cab81b2662a04bfbb892e95bdc15edf7399000ce57d54", size = 2156251, upload-time = "2026-10-11T18:34:31.455Z" }, + { url = "https://files.pythonhosted.org/packages/47/47/83643225b08f2aef6c8cc4bbe6e3f79c5e139c4364a6e450d0f399d87774/pydantic_core-2.50.1-cp315-cp315t-macosx_10_12_x86_64.whl", hash = "sha256:4a53d13cdfbedbfa87f08b83c1a0a5efcc767d785a4b41934fa9cb672670493a", size = 2234363, upload-time = "2026-10-11T18:34:33.65Z" }, + { url = "https://files.pythonhosted.org/packages/5e/66/127ca649ba2f2462039dc1e694c6c01e00a3689f023a617364d3507e6d97/pydantic_core-2.50.1-cp315-cp315t-macosx_11_0_arm64.whl", hash = "sha256:efbecf43d321f7b9281441f1f213f7c21c66988b0e06c2730ba13ed47a46bb08", size = 2000972, upload-time = "2026-10-11T18:34:36.037Z" }, + { url = "https://files.pythonhosted.org/packages/5e/4f/e421e0a5d653b1203b090b2e48745976988d7338a647940704b5b9c2b399/pydantic_core-2.50.1-cp315-cp315t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:bc1f08f68dac9f9e83845a8039880aba2ab553eb9b2259c3243a313182c253fe", size = 2022925, upload-time = "2026-10-11T18:34:37.972Z" }, + { url = "https://files.pythonhosted.org/packages/d5/4e/ea5568e2491e1a71100f15ae8c2d01ef52db42a184a2d4e716bc79e5eb8f/pydantic_core-2.50.1-cp315-cp315t-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:5dfe41f232befddb9c4377f6cfc702b51595e2d78ed082672adf8758d2c4619f", size = 2192867, upload-time = "2026-10-11T18:34:39.921Z" }, + { url = "https://files.pythonhosted.org/packages/ae/5e/3b8c3a35acbe219909ada5defad5d7d9fed845fb2b37bd5ec518f453c119/pydantic_core-2.50.1-cp315-cp315t-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:adc06d218a1cadfd2ec4628424d7d79ce4eba69c2965e7e7b55106f0da5208c8", size = 2388687, upload-time = "2026-10-11T18:34:42.184Z" }, + { url = "https://files.pythonhosted.org/packages/b6/aa/7889b4e515f91a2e8c0ae6b5081fec0feb30c4398d1434e14793c60f173a/pydantic_core-2.50.1-cp315-cp315t-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:2cf91809d0721ab81592ba67bea7694821679c10b1a2e3c3460082b286c1918a", size = 2464415, upload-time = "2026-10-11T18:34:44.384Z" }, + { url = "https://files.pythonhosted.org/packages/08/78/93449e628eb8a6fdcce3eff9043081179d1bc7ce6f1bff32dc5006f41e00/pydantic_core-2.50.1-cp315-cp315t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:23923ab9292c40da026330b1ecf4dc2618c8e86e0422e5d1fbf50d94d64ca4f8", size = 2150823, upload-time = "2026-10-11T18:34:46.392Z" }, + { url = "https://files.pythonhosted.org/packages/f4/f1/72c5bc129fceb0d00f05dc1e67f518c1728de1928c55f81fc13d7690de39/pydantic_core-2.50.1-cp315-cp315t-manylinux_2_31_riscv64.whl", hash = "sha256:f3377c8c2b3ce898423c5e5dd94c7982e30aa7717a7e6ab2470b9de364963709", size = 2245806, upload-time = "2026-10-11T18:34:48.805Z" }, + { url = "https://files.pythonhosted.org/packages/28/2a/922a0e78f3aa6ab837b59f88190233fb8dad546c17995fde9bb3ed3b9b49/pydantic_core-2.50.1-cp315-cp315t-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:455a773617b5913bf5c20d0692e5787b119e52c4d40ea644ca31f5758fd31be2", size = 2264160, upload-time = "2026-10-11T18:34:50.876Z" }, + { url = "https://files.pythonhosted.org/packages/52/a8/0f1449e3e1b20941c9372faa18e7b6a092e30cdfa841902473f7989532ac/pydantic_core-2.50.1-cp315-cp315t-musllinux_1_1_aarch64.whl", hash = "sha256:1a9006395dece0e32e704c315eff8a00bede494f6108546cfc5539c89fef4f9a", size = 2294031, upload-time = "2026-10-11T18:34:52.876Z" }, + { url = "https://files.pythonhosted.org/packages/d1/d0/1031f492857de70355fb16524bbb03efce5fd34c93ed4a1ec60be07e0d4b/pydantic_core-2.50.1-cp315-cp315t-musllinux_1_1_armv7l.whl", hash = "sha256:d2d82aa62521c55ddfb000ae70f88cdd8de974078f6024e821dfe5addd0c818f", size = 2468423, upload-time = "2026-10-11T18:34:54.995Z" }, + { url = "https://files.pythonhosted.org/packages/46/52/269ffffa645b8e47906395a39cf9db1151ae9fa4bcd7f47b960bc31baf37/pydantic_core-2.50.1-cp315-cp315t-musllinux_1_1_x86_64.whl", hash = "sha256:009634b83993777ddcd69cad0ffcace43dabde692109528e35f0fde91e386a8b", size = 2512598, upload-time = "2026-10-11T18:34:57.149Z" }, + { url = "https://files.pythonhosted.org/packages/31/5c/e47e28281f20326ff6f3c31d626f0a83e615d2d94ba41bb0ad6ec237184a/pydantic_core-2.50.1-cp315-cp315t-win32.whl", hash = "sha256:3fde4fdc6487a58d944ca87cf5adc95d5f266e872c19599f5f4c0a8a1b1f9f9f", size = 2098535, upload-time = "2026-10-11T18:34:59.313Z" }, + { url = "https://files.pythonhosted.org/packages/03/ad/759e181e69c1b472c60b2049e5f61d5da1deefdd5ce1df4bb2ebcf771f25/pydantic_core-2.50.1-cp315-cp315t-win_amd64.whl", hash = "sha256:1c8632d4ac04e6f91128fca584b3a8a507d81604c24eeaaad00d4be42765c32b", size = 2148645, upload-time = "2026-10-11T18:35:01.571Z" }, + { url = "https://files.pythonhosted.org/packages/6d/56/8a702c27e5be9f47e5f19d8669227424290e4c024e7c370279cbaf244b4e/pydantic_core-2.50.1-cp315-cp315t-win_arm64.whl", hash = "sha256:c3ede305158e75510be50869b319550ab072008c13d64d4ab1e094fb286b6f44", size = 2175297, upload-time = "2026-10-11T18:35:04.079Z" }, + { url = "https://files.pythonhosted.org/packages/a5/09/1bcf160f3cd6333e2a76982fae5963e5032de0bcaaba38464223dc266bfe/pydantic_core-2.50.1-graalpy312-graalpy250_312_native-macosx_10_12_x86_64.whl", hash = "sha256:76e2e83fa6ec8cdc972d438dafc2522b3a47bee4ec0ae668b29cfb1977ab5242", size = 2217070, upload-time = "2026-10-11T18:35:15.688Z" }, + { url = "https://files.pythonhosted.org/packages/3d/81/f02de95eec7794dfc7a5bc69a834f0e834b31b3009014ce6de903855f775/pydantic_core-2.50.1-graalpy312-graalpy250_312_native-macosx_11_0_arm64.whl", hash = "sha256:a51eee75939cf811ac09b278745a6cee7dc873ccfbc8b9af3cc88fe4b7ce25b5", size = 2039027, upload-time = "2026-10-11T18:35:18.07Z" }, + { url = "https://files.pythonhosted.org/packages/4d/16/227746ed3771d9bf2304568b55134849ece34e13b38b1d76de763015c77f/pydantic_core-2.50.1-graalpy312-graalpy250_312_native-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ae28183297fb0d2b8dc46a1f01d51f5e45825fc5afe76a835a6cb7fb34821295", size = 2109009, upload-time = "2026-10-11T18:35:20.218Z" }, + { url = "https://files.pythonhosted.org/packages/e5/b9/7664d1592a0e5a74903f357cd5b28ceb7336f3473256c5a4e8c8432f1881/pydantic_core-2.50.1-graalpy312-graalpy250_312_native-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:88e492e8b9d0312e7dc13667c30222abf284dc3b79b5302b3607b41a5784ce61", size = 2269883, upload-time = "2026-10-11T18:35:22.48Z" }, +] + +[[package]] +name = "pygments" +version = "2.21.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/49/2e/ced460408999b33da6b31b0021b0f37d329e202d4169aeb164493778f25b/pygments-2.21.0.tar.gz", hash = "sha256:610ca751c9bc2492b38eb9a38a7fbc93edbbb2d7182edaf34e66ae493dee5c8c", size = 5005329, upload-time = "2026-08-17T08:02:48.824Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/71/46/17f022dd3e953bf20a04a028a21ec746d942f8d2af30fa0f124fa0e6a684/pygments-2.21.0-py3-none-any.whl", hash = "sha256:2363c69b61c4a97c838da3b130dcd6468f4848992b21a82f2a63ec34377137d9", size = 1250147, upload-time = "2026-08-17T08:02:44.912Z" }, +] + +[[package]] +name = "pyjwt" +version = "2.15.1" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/43/ea/5194e52748b0da83d71e082d75496eaec6e58f419f5e184786ded517e6a9/pyjwt-2.15.1.tar.gz", hash = "sha256:4f259e80cdfb6b3fc18a7de51fd1ef9ec79652f25019bae68975ca2468a34df8", size = 121252, upload-time = "2026-09-28T18:40:42.598Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/50/ca/44de4e75f8aadc457f0634be3b542815078ded46dca30efb960edeecad6e/pyjwt-2.15.1-py3-none-any.whl", hash = "sha256:42d59d631f7768a1028a64c7ff581a9bf7519804daf91fc5b6c56e30eec5e193", size = 33860, upload-time = "2026-09-28T18:40:41.429Z" }, +] + +[package.optional-dependencies] +crypto = [ + { name = "cryptography" }, +] + +[[package]] +name = "pytest" +version = "9.1.1" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "colorama", marker = "sys_platform == 'win32'" }, + { name = "iniconfig" }, + { name = "packaging" }, + { name = "pluggy" }, + { name = "pygments" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/e4/47/b9efed96c114afcfa3c9d3fe98a76a1d14c74a9e266d397cf6eb64be5e01/pytest-9.1.1.tar.gz", hash = "sha256:1088fbde8f2b49d95a549a195707afa7a76a3ce9bcadc26b6d71f0ffda5fe313", size = 1636369, upload-time = "2026-06-19T10:58:32.857Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/24/25/1de2678b631f5a49215c6c96fff41ba892b0a34df68d6d80292b1b48aa7f/pytest-9.1.1-py3-none-any.whl", hash = "sha256:37a86b45efb9a47a61a36449063e8e18d0cab3161329fc099eb21783169c4f0c", size = 386536, upload-time = "2026-06-19T10:58:31.347Z" }, +] + +[[package]] +name = "pytest-cov" +version = "7.1.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "coverage" }, + { name = "pluggy" }, + { name = "pytest" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/b1/51/a849f96e117386044471c8ec2bd6cfebacda285da9525c9106aeb28da671/pytest_cov-7.1.0.tar.gz", hash = "sha256:30674f2b5f6351aa09702a9c8c364f6a01c27aae0c1366ae8016160d1efc56b2", size = 55592, upload-time = "2026-03-21T20:11:16.284Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/9d/7a/d968e294073affff457b041c2be9868a40c1c71f4a35fcc1e45e5493067b/pytest_cov-7.1.0-py3-none-any.whl", hash = "sha256:a0461110b7865f9a271aa1b51e516c9a95de9d696734a2f71e3e78f46e1d4678", size = 22876, upload-time = "2026-03-21T20:11:14.438Z" }, +] + +[[package]] +name = "pyyaml" +version = "6.0.3" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/05/8e/961c0007c59b8dd7729d542c61a4d537767a59645b82a0b521206e1e25c2/pyyaml-6.0.3.tar.gz", hash = "sha256:d76623373421df22fb4cf8817020cbb7ef15c725b9d5e45f17e189bfc384190f", size = 130960, upload-time = "2025-09-25T21:33:16.546Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/d1/33/422b98d2195232ca1826284a76852ad5a86fe23e31b009c9886b2d0fb8b2/pyyaml-6.0.3-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:7f047e29dcae44602496db43be01ad42fc6f1cc0d8cd6c83d342306c32270196", size = 182063, upload-time = "2025-09-25T21:32:11.445Z" }, + { url = "https://files.pythonhosted.org/packages/89/a0/6cf41a19a1f2f3feab0e9c0b74134aa2ce6849093d5517a0c550fe37a648/pyyaml-6.0.3-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:fc09d0aa354569bc501d4e787133afc08552722d3ab34836a80547331bb5d4a0", size = 173973, upload-time = "2025-09-25T21:32:12.492Z" }, + { url = "https://files.pythonhosted.org/packages/ed/23/7a778b6bd0b9a8039df8b1b1d80e2e2ad78aa04171592c8a5c43a56a6af4/pyyaml-6.0.3-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:9149cad251584d5fb4981be1ecde53a1ca46c891a79788c0df828d2f166bda28", size = 775116, upload-time = "2025-09-25T21:32:13.652Z" }, + { url = "https://files.pythonhosted.org/packages/65/30/d7353c338e12baef4ecc1b09e877c1970bd3382789c159b4f89d6a70dc09/pyyaml-6.0.3-cp312-cp312-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:5fdec68f91a0c6739b380c83b951e2c72ac0197ace422360e6d5a959d8d97b2c", size = 844011, upload-time = "2025-09-25T21:32:15.21Z" }, + { url = "https://files.pythonhosted.org/packages/8b/9d/b3589d3877982d4f2329302ef98a8026e7f4443c765c46cfecc8858c6b4b/pyyaml-6.0.3-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:ba1cc08a7ccde2d2ec775841541641e4548226580ab850948cbfda66a1befcdc", size = 807870, upload-time = "2025-09-25T21:32:16.431Z" }, + { url = "https://files.pythonhosted.org/packages/05/c0/b3be26a015601b822b97d9149ff8cb5ead58c66f981e04fedf4e762f4bd4/pyyaml-6.0.3-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:8dc52c23056b9ddd46818a57b78404882310fb473d63f17b07d5c40421e47f8e", size = 761089, upload-time = "2025-09-25T21:32:17.56Z" }, + { url = "https://files.pythonhosted.org/packages/be/8e/98435a21d1d4b46590d5459a22d88128103f8da4c2d4cb8f14f2a96504e1/pyyaml-6.0.3-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:41715c910c881bc081f1e8872880d3c650acf13dfa8214bad49ed4cede7c34ea", size = 790181, upload-time = "2025-09-25T21:32:18.834Z" }, + { url = "https://files.pythonhosted.org/packages/74/93/7baea19427dcfbe1e5a372d81473250b379f04b1bd3c4c5ff825e2327202/pyyaml-6.0.3-cp312-cp312-win32.whl", hash = "sha256:96b533f0e99f6579b3d4d4995707cf36df9100d67e0c8303a0c55b27b5f99bc5", size = 137658, upload-time = "2025-09-25T21:32:20.209Z" }, + { url = "https://files.pythonhosted.org/packages/86/bf/899e81e4cce32febab4fb42bb97dcdf66bc135272882d1987881a4b519e9/pyyaml-6.0.3-cp312-cp312-win_amd64.whl", hash = "sha256:5fcd34e47f6e0b794d17de1b4ff496c00986e1c83f7ab2fb8fcfe9616ff7477b", size = 154003, upload-time = "2025-09-25T21:32:21.167Z" }, + { url = "https://files.pythonhosted.org/packages/1a/08/67bd04656199bbb51dbed1439b7f27601dfb576fb864099c7ef0c3e55531/pyyaml-6.0.3-cp312-cp312-win_arm64.whl", hash = "sha256:64386e5e707d03a7e172c0701abfb7e10f0fb753ee1d773128192742712a98fd", size = 140344, upload-time = "2025-09-25T21:32:22.617Z" }, + { url = "https://files.pythonhosted.org/packages/d1/11/0fd08f8192109f7169db964b5707a2f1e8b745d4e239b784a5a1dd80d1db/pyyaml-6.0.3-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:8da9669d359f02c0b91ccc01cac4a67f16afec0dac22c2ad09f46bee0697eba8", size = 181669, upload-time = "2025-09-25T21:32:23.673Z" }, + { url = "https://files.pythonhosted.org/packages/b1/16/95309993f1d3748cd644e02e38b75d50cbc0d9561d21f390a76242ce073f/pyyaml-6.0.3-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:2283a07e2c21a2aa78d9c4442724ec1eb15f5e42a723b99cb3d822d48f5f7ad1", size = 173252, upload-time = "2025-09-25T21:32:25.149Z" }, + { url = "https://files.pythonhosted.org/packages/50/31/b20f376d3f810b9b2371e72ef5adb33879b25edb7a6d072cb7ca0c486398/pyyaml-6.0.3-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:ee2922902c45ae8ccada2c5b501ab86c36525b883eff4255313a253a3160861c", size = 767081, upload-time = "2025-09-25T21:32:26.575Z" }, + { url = "https://files.pythonhosted.org/packages/49/1e/a55ca81e949270d5d4432fbbd19dfea5321eda7c41a849d443dc92fd1ff7/pyyaml-6.0.3-cp313-cp313-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:a33284e20b78bd4a18c8c2282d549d10bc8408a2a7ff57653c0cf0b9be0afce5", size = 841159, upload-time = "2025-09-25T21:32:27.727Z" }, + { url = "https://files.pythonhosted.org/packages/74/27/e5b8f34d02d9995b80abcef563ea1f8b56d20134d8f4e5e81733b1feceb2/pyyaml-6.0.3-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:0f29edc409a6392443abf94b9cf89ce99889a1dd5376d94316ae5145dfedd5d6", size = 801626, upload-time = "2025-09-25T21:32:28.878Z" }, + { url = "https://files.pythonhosted.org/packages/f9/11/ba845c23988798f40e52ba45f34849aa8a1f2d4af4b798588010792ebad6/pyyaml-6.0.3-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:f7057c9a337546edc7973c0d3ba84ddcdf0daa14533c2065749c9075001090e6", size = 753613, upload-time = "2025-09-25T21:32:30.178Z" }, + { url = "https://files.pythonhosted.org/packages/3d/e0/7966e1a7bfc0a45bf0a7fb6b98ea03fc9b8d84fa7f2229e9659680b69ee3/pyyaml-6.0.3-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:eda16858a3cab07b80edaf74336ece1f986ba330fdb8ee0d6c0d68fe82bc96be", size = 794115, upload-time = "2025-09-25T21:32:31.353Z" }, + { url = "https://files.pythonhosted.org/packages/de/94/980b50a6531b3019e45ddeada0626d45fa85cbe22300844a7983285bed3b/pyyaml-6.0.3-cp313-cp313-win32.whl", hash = "sha256:d0eae10f8159e8fdad514efdc92d74fd8d682c933a6dd088030f3834bc8e6b26", size = 137427, upload-time = "2025-09-25T21:32:32.58Z" }, + { url = "https://files.pythonhosted.org/packages/97/c9/39d5b874e8b28845e4ec2202b5da735d0199dbe5b8fb85f91398814a9a46/pyyaml-6.0.3-cp313-cp313-win_amd64.whl", hash = "sha256:79005a0d97d5ddabfeeea4cf676af11e647e41d81c9a7722a193022accdb6b7c", size = 154090, upload-time = "2025-09-25T21:32:33.659Z" }, + { url = "https://files.pythonhosted.org/packages/73/e8/2bdf3ca2090f68bb3d75b44da7bbc71843b19c9f2b9cb9b0f4ab7a5a4329/pyyaml-6.0.3-cp313-cp313-win_arm64.whl", hash = "sha256:5498cd1645aa724a7c71c8f378eb29ebe23da2fc0d7a08071d89469bf1d2defb", size = 140246, upload-time = "2025-09-25T21:32:34.663Z" }, + { url = "https://files.pythonhosted.org/packages/9d/8c/f4bd7f6465179953d3ac9bc44ac1a8a3e6122cf8ada906b4f96c60172d43/pyyaml-6.0.3-cp314-cp314-macosx_10_13_x86_64.whl", hash = "sha256:8d1fab6bb153a416f9aeb4b8763bc0f22a5586065f86f7664fc23339fc1c1fac", size = 181814, upload-time = "2025-09-25T21:32:35.712Z" }, + { url = "https://files.pythonhosted.org/packages/bd/9c/4d95bb87eb2063d20db7b60faa3840c1b18025517ae857371c4dd55a6b3a/pyyaml-6.0.3-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:34d5fcd24b8445fadc33f9cf348c1047101756fd760b4dacb5c3e99755703310", size = 173809, upload-time = "2025-09-25T21:32:36.789Z" }, + { url = "https://files.pythonhosted.org/packages/92/b5/47e807c2623074914e29dabd16cbbdd4bf5e9b2db9f8090fa64411fc5382/pyyaml-6.0.3-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:501a031947e3a9025ed4405a168e6ef5ae3126c59f90ce0cd6f2bfc477be31b7", size = 766454, upload-time = "2025-09-25T21:32:37.966Z" }, + { url = "https://files.pythonhosted.org/packages/02/9e/e5e9b168be58564121efb3de6859c452fccde0ab093d8438905899a3a483/pyyaml-6.0.3-cp314-cp314-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:b3bc83488de33889877a0f2543ade9f70c67d66d9ebb4ac959502e12de895788", size = 836355, upload-time = "2025-09-25T21:32:39.178Z" }, + { url = "https://files.pythonhosted.org/packages/88/f9/16491d7ed2a919954993e48aa941b200f38040928474c9e85ea9e64222c3/pyyaml-6.0.3-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:c458b6d084f9b935061bc36216e8a69a7e293a2f1e68bf956dcd9e6cbcd143f5", size = 794175, upload-time = "2025-09-25T21:32:40.865Z" }, + { url = "https://files.pythonhosted.org/packages/dd/3f/5989debef34dc6397317802b527dbbafb2b4760878a53d4166579111411e/pyyaml-6.0.3-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:7c6610def4f163542a622a73fb39f534f8c101d690126992300bf3207eab9764", size = 755228, upload-time = "2025-09-25T21:32:42.084Z" }, + { url = "https://files.pythonhosted.org/packages/d7/ce/af88a49043cd2e265be63d083fc75b27b6ed062f5f9fd6cdc223ad62f03e/pyyaml-6.0.3-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:5190d403f121660ce8d1d2c1bb2ef1bd05b5f68533fc5c2ea899bd15f4399b35", size = 789194, upload-time = "2025-09-25T21:32:43.362Z" }, + { url = "https://files.pythonhosted.org/packages/23/20/bb6982b26a40bb43951265ba29d4c246ef0ff59c9fdcdf0ed04e0687de4d/pyyaml-6.0.3-cp314-cp314-win_amd64.whl", hash = "sha256:4a2e8cebe2ff6ab7d1050ecd59c25d4c8bd7e6f400f5f82b96557ac0abafd0ac", size = 156429, upload-time = "2025-09-25T21:32:57.844Z" }, + { url = "https://files.pythonhosted.org/packages/f4/f4/a4541072bb9422c8a883ab55255f918fa378ecf083f5b85e87fc2b4eda1b/pyyaml-6.0.3-cp314-cp314-win_arm64.whl", hash = "sha256:93dda82c9c22deb0a405ea4dc5f2d0cda384168e466364dec6255b293923b2f3", size = 143912, upload-time = "2025-09-25T21:32:59.247Z" }, + { url = "https://files.pythonhosted.org/packages/7c/f9/07dd09ae774e4616edf6cda684ee78f97777bdd15847253637a6f052a62f/pyyaml-6.0.3-cp314-cp314t-macosx_10_13_x86_64.whl", hash = "sha256:02893d100e99e03eda1c8fd5c441d8c60103fd175728e23e431db1b589cf5ab3", size = 189108, upload-time = "2025-09-25T21:32:44.377Z" }, + { url = "https://files.pythonhosted.org/packages/4e/78/8d08c9fb7ce09ad8c38ad533c1191cf27f7ae1effe5bb9400a46d9437fcf/pyyaml-6.0.3-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:c1ff362665ae507275af2853520967820d9124984e0f7466736aea23d8611fba", size = 183641, upload-time = "2025-09-25T21:32:45.407Z" }, + { url = "https://files.pythonhosted.org/packages/7b/5b/3babb19104a46945cf816d047db2788bcaf8c94527a805610b0289a01c6b/pyyaml-6.0.3-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:6adc77889b628398debc7b65c073bcb99c4a0237b248cacaf3fe8a557563ef6c", size = 831901, upload-time = "2025-09-25T21:32:48.83Z" }, + { url = "https://files.pythonhosted.org/packages/8b/cc/dff0684d8dc44da4d22a13f35f073d558c268780ce3c6ba1b87055bb0b87/pyyaml-6.0.3-cp314-cp314t-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:a80cb027f6b349846a3bf6d73b5e95e782175e52f22108cfa17876aaeff93702", size = 861132, upload-time = "2025-09-25T21:32:50.149Z" }, + { url = "https://files.pythonhosted.org/packages/b1/5e/f77dc6b9036943e285ba76b49e118d9ea929885becb0a29ba8a7c75e29fe/pyyaml-6.0.3-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:00c4bdeba853cc34e7dd471f16b4114f4162dc03e6b7afcc2128711f0eca823c", size = 839261, upload-time = "2025-09-25T21:32:51.808Z" }, + { url = "https://files.pythonhosted.org/packages/ce/88/a9db1376aa2a228197c58b37302f284b5617f56a5d959fd1763fb1675ce6/pyyaml-6.0.3-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:66e1674c3ef6f541c35191caae2d429b967b99e02040f5ba928632d9a7f0f065", size = 805272, upload-time = "2025-09-25T21:32:52.941Z" }, + { url = "https://files.pythonhosted.org/packages/da/92/1446574745d74df0c92e6aa4a7b0b3130706a4142b2d1a5869f2eaa423c6/pyyaml-6.0.3-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:16249ee61e95f858e83976573de0f5b2893b3677ba71c9dd36b9cf8be9ac6d65", size = 829923, upload-time = "2025-09-25T21:32:54.537Z" }, + { url = "https://files.pythonhosted.org/packages/f0/7a/1c7270340330e575b92f397352af856a8c06f230aa3e76f86b39d01b416a/pyyaml-6.0.3-cp314-cp314t-win_amd64.whl", hash = "sha256:4ad1906908f2f5ae4e5a8ddfce73c320c2a1429ec52eafd27138b7f1cbe341c9", size = 174062, upload-time = "2025-09-25T21:32:55.767Z" }, + { url = "https://files.pythonhosted.org/packages/f1/12/de94a39c2ef588c7e6455cfbe7343d3b2dc9d6b6b2f40c4c6565744c873d/pyyaml-6.0.3-cp314-cp314t-win_arm64.whl", hash = "sha256:ebc55a14a21cb14062aa4162f906cd962b28e2e9ea38f9b4391244cd8de4ae0b", size = 149341, upload-time = "2025-09-25T21:32:56.828Z" }, +] + +[[package]] +name = "starlette" +version = "1.9.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "anyio" }, + { name = "typing-extensions", marker = "python_full_version < '3.13'" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/ad/eb/4e197bf26b023abafc5e9043ec8710d7de0fcb032d0969045236d72aa0b1/starlette-1.9.0.tar.gz", hash = "sha256:3d931de246ed870e35ce605974440816ef895e592f255d1396cfdf191d4c4318", size = 2732466, upload-time = "2026-10-18T15:50:33.189Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/f3/93/181df62699d9b5aca1d87e5cfda131dac87e3cdaebf668662f7206ca3470/starlette-1.9.0-py3-none-any.whl", hash = "sha256:fd3f159936e882d06c1108f84688f7cda2cf85fc6a592a50edbd175e882c2ddc", size = 80335, upload-time = "2026-10-18T15:50:31.526Z" }, +] + +[[package]] +name = "typing-extensions" +version = "4.16.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/f6/cc/6253133b5bb138fc3306cebfbda2c520f545d36b5be2c7255cc528bb45d6/typing_extensions-4.16.0.tar.gz", hash = "sha256:dc983d19a509c94dba722ee6abd33940f7c05a89e243c47e907eb4db6f1a43e5", size = 113555, upload-time = "2026-07-02T08:40:05.92Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/49/d3/b8441a820a491ddfc024b0b0cf0393375b75ea13866d9c66727e54c2fc80/typing_extensions-4.16.0-py3-none-any.whl", hash = "sha256:481caa481374e813c1b176ada14e97f1f67a4539ce9cfeb3f350d78d6370c2e8", size = 45571, upload-time = "2026-07-02T08:40:04.659Z" }, +] + +[[package]] +name = "typing-inspection" +version = "0.4.4" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "typing-extensions" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/a3/26/b09b8010994eccc3c09092e6b34058f36a460eea2d4c3e8b910c695975a0/typing_inspection-0.4.4.tar.gz", hash = "sha256:547274fa6b0a561ccf549cc9524b999a578e737d015d8709d021f9d0d13bea47", size = 76928, upload-time = "2026-08-12T12:37:25.997Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/67/81/4add07e5172b7ac40d8ed5ff580409a7801a4fe26d529bdd915401dabfbe/typing_inspection-0.4.4-py3-none-any.whl", hash = "sha256:65b8397ba37ccbce054456aaccddfc91e6e3083c92824df348d96ca832f3f147", size = 14750, upload-time = "2026-08-12T12:37:24.648Z" }, +] + +[[package]] +name = "uvicorn" +version = "0.54.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "click" }, + { name = "h11" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/da/34/30e9280707135d2cfc589dfff3cb796bd07a3aeb1a3e415ba09dd89d7bb4/uvicorn-0.54.0.tar.gz", hash = "sha256:a2e33cbfaa0306f8e6b0c13e0cb89d7d7a2da3e62b90c66e18c33d9807b28620", size = 112283, upload-time = "2026-09-25T06:52:37.601Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/38/0c/b54a4fdd7f90a3af8b02ebc9ce6712c2c208b7926a2f7bad95c33ebbe943/uvicorn-0.54.0-py3-none-any.whl", hash = "sha256:505bdb0f318731d45f1f712071fc781a8981f6847a31c902c9f5e652d4f67faf", size = 87427, upload-time = "2026-09-25T06:52:35.829Z" }, +] From 81f82527277d9cc6a830fa09f20bfa0f6b49ecf5 Mon Sep 17 00:00:00 2001 From: CalebSargeant <4991715+CalebSargeant@users.noreply.github.com> Date: Fri, 23 Oct 2026 17:10:32 +0200 Subject: [PATCH 2/8] feat: access follows Kubernetes RBAC in each database's namespace 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. --- CLAUDE.md | 17 +- README.md | 247 +++++++------ charts/databases-ui/ci/default-values.yaml | 20 +- charts/databases-ui/templates/NOTES.txt | 6 +- charts/databases-ui/templates/_helpers.tpl | 28 +- charts/databases-ui/templates/rbac.yaml | 27 ++ charts/databases-ui/values.yaml | 32 +- e2e/fixtures.yaml | 60 ++- e2e/run.py | 85 +++-- examples/catalog.yaml | 32 +- frontend/src/App.tsx | 40 +- frontend/src/api.ts | 38 +- frontend/src/views/Audit.tsx | 3 +- frontend/src/views/DatabaseView.tsx | 230 ++++++++---- frontend/src/views/Databases.tsx | 37 +- frontend/src/views/Users.tsx | 52 +++ src/databases_ui/__main__.py | 9 +- src/databases_ui/app.py | 66 ++-- src/databases_ui/blob.py | 4 + src/databases_ui/catalog.py | 155 +++----- src/databases_ui/config.py | 45 ++- src/databases_ui/entra.py | 25 +- src/databases_ui/jobs.py | 7 +- src/databases_ui/oidc.py | 8 +- src/databases_ui/runner.py | 91 +++-- src/databases_ui/service.py | 410 ++++++++++++++------- tests/conftest.py | 111 ++++-- tests/test_api.py | 281 +++++++++----- tests/test_auth.py | 34 +- tests/test_catalog.py | 48 ++- tests/test_config.py | 14 +- tests/test_runner.py | 48 ++- 32 files changed, 1508 insertions(+), 802 deletions(-) create mode 100644 frontend/src/views/Users.tsx diff --git a/CLAUDE.md b/CLAUDE.md index d1ceace..e3c57c3 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -2,13 +2,18 @@ FastAPI backend (`src/databases_ui`) serving a React/TypeScript console (`frontend/`), and the Jobs' runner (`runner.py`) in the same image, with a Helm chart (`charts/databases-ui`). State lives in -Kubernetes (Database resources, Jobs) and Blob Storage (snapshots, the audit log); the server -stores nothing. +Kubernetes (Database resources, Jobs, RBAC) and Blob Storage (snapshots and their shares, the audit +log); the server stores nothing. ## Things that fail silently -- **The session carries only the groups the catalog named at sign-in.** A team added to the - catalog reaches its members when they sign in again, not before. +- **The user and groups the access reviews ask about must be the API server's.** They come from + `DATABASES_UI_USERNAME_*` and `DATABASES_UI_GROUPS_*` and the ID token, as the session took them + at sign-in. A claim, a prefix or a lowercased name that differs from the cluster's authentication + configuration asks about someone RBAC doesn't know, and every database disappears. A change in + someone's groups reaches the app when they sign in again. +- **A database outside your namespaces answers 404, never 403.** Keep it that way in new routes + (`Console._database`), or a 403 tells who may not see a database that it exists. - **The admission policy (`templates/jobpolicy.yaml`) knows the Job's shape.** It checks the variables `PGPASSWORD`, `DBUI_STORAGE_SAS`, `PGHOST`, `PGSSLMODE`, `DBUI_BLOB_URL` and `DBUI_AUDIT_URL`, the volume kinds and the `job` argument that `jobs.py` writes. Renaming one or @@ -16,6 +21,9 @@ stores nothing. change makes Kubernetes refuse every Job. - **Job pods carry `app.kubernetes.io/component: job`, never `web`.** `web` is the Service and PodDisruptionBudget selector; the chart's database NetworkPolicy admits `job`. +- **COMMIT reaches psql only after pg_restore exited 0** (`runner.apply`). The restore drops what + the owner owns first, so a COMMIT after a partial script would leave the database half empty; + any new early exit there must close psql without it. - **A storage lifecycle rule must be scoped to `snapshots/`.** One on the whole container also deletes the audit log under `audit/`. - **Snapshots leave extensions out** (`--exclude-extension=*`): the owner role can't drop one the @@ -23,7 +31,6 @@ stores nothing. source's `spec.extensions`; a restore into a database without them fails, and changes nothing. - **No `from __future__ import annotations` in `app.py`.** The routes use `Annotated` path types; postponed annotations turn them into strings and FastAPI answers 422 everywhere. -- **`{env}` in the catalog needs block lists.** YAML reads braces inside `[ ]` as a mapping. - **The page may hold no inline script or style.** The CSP blocks it and the page renders blank; CI greps `frontend/dist/index.html` for it. - **The image name follows the repository name** (`ghcr.io/magmamoose/databases-ui`). The chart's diff --git a/README.md b/README.md index 3e6e2f2..3e22983 100644 --- a/README.md +++ b/README.md @@ -2,21 +2,29 @@ Let app teams snapshot, restore and clone their own PostgreSQL databases on [CloudNativePG](https://cloudnative-pg.io/), without asking the platform team. People sign in with -Entra ID, see the databases their team owns, and every action runs as a Kubernetes Job next to the -database. +Entra ID and see the databases of the namespaces Kubernetes lets them into; every action runs as a +Kubernetes Job next to the database. +- **Access is Kubernetes RBAC.** A `Database` resource names its app's namespace in a label. Who + may see it, snapshot it or restore it is what the API server says that person may do in that + namespace, asked with a SubjectAccessReview: `view` sees, `edit` snapshots and restores, `admin` + restores production. There is no second list of who may do what. - **Snapshots on demand.** `pg_dump` in the custom format, streamed straight into Azure Blob Storage with who took it and why. Nothing touches a disk, and nothing leaves the cluster. -- **Restore in place or into a copy.** `pg_restore` in a single transaction: if anything fails, - nothing changes. In place, the app's workloads are scaled to 0 first and back afterwards; into a - copy, a second database `_copy` appears next to it, created and dropped by CloudNativePG. -- **Clone across environments.** Restore a snapshot of acc into dev, for instance, where the - catalog allows it. -- **Production is careful.** A restore in a production environment waits for a second person to - approve it, and snapshots taken there can't be downloaded. +- **Restore in place or into a copy, exactly.** In one transaction, everything the database's owner + owns is dropped and the snapshot restored: the database ends up as the snapshot was, or, if + anything fails, as it was before. In place, the app's workloads are scaled to 0 first and back + afterwards; into a copy, a second database `_copy` appears next to it, created and dropped + by CloudNativePG. +- **Clone across environments, once shared.** Someone who may snapshot a database in acc shares a + snapshot with a namespace in dev; whoever may restore there can then clone it. +- **Production is careful.** A restore in a production environment waits for a second person, and + snapshots taken there can't be downloaded. +- **Database users**: the owner roles of the databases you see, and the Secrets with their + passwords. - **An audit log** of who asked for what, who approved it and how it ended, per environment. - **No superuser.** Each Job connects as the database's owner role, with the password from that - managed role's Secret. The server itself never reads a password. + managed role's Secret. The server itself reads no Secret. ## How it works @@ -28,8 +36,10 @@ sequenceDiagram participant J as Job (in the database namespace) participant D as PostgreSQL participant B as Blob Storage + P->>U: sign in (Entra ID: the app the API server trusts) P->>U: snapshot payments_dev - U->>K: read the Database resource and the Cluster's managed roles + U->>K: Database resource: namespace label, owner, Cluster's managed roles + U->>K: SubjectAccessReview: may oidc:ada get secrets in dev-payments? U->>K: create a Job (owner role, its password Secret, the CA certificate) K->>J: start the pod J->>D: pg_dump --format=custom @@ -38,20 +48,25 @@ sequenceDiagram P->>U: restore it U->>K: create a Job J->>K: scale the app's workloads to 0 - J->>B: stream the snapshot - J->>D: pg_restore --clean --if-exists --no-owner --no-acl --single-transaction + J->>B: stream the snapshot through pg_restore + J->>D: BEGIN; DROP OWNED BY CURRENT_USER; the snapshot; COMMIT J->>K: scale the workloads back ``` -The server reads `Database` resources (`postgresql.cnpg.io/v1`) and their `Cluster`, creates Jobs, -and lists snapshots and the audit log in storage. The Jobs run this app's own image, which carries -the PostgreSQL client, as `python -m databases_ui job`. A Job's pod reads the owner's password from -the kubelet, verifies the server's certificate against the cluster's CA (`verify-full`), and talks -to storage with its own workload identity. +People sign in to the app registration the cluster's API server trusts, so their ID token carries +the claims the API server builds a user from. The server builds the same user and groups (with the +same claims and prefixes) and asks the API server about them in a SubjectAccessReview; the answers +are kept for a minute. It needs no token of theirs at the API server, and stores none. + +The Jobs run this app's own image, which carries the PostgreSQL client, as +`python -m databases_ui job`. A Job's pod reads the owner's password from the kubelet, verifies the +server's certificate against the cluster's CA (`verify-full`), and talks to storage with its own +workload identity. ## The catalog -One YAML file says which environments the app reaches and which team acts on which database (see +One instance runs in each cluster. Its catalog lists the environments: the one in its own cluster +runs Jobs, the others are where shared snapshots come from or go to (see [`examples/catalog.yaml`](examples/catalog.yaml)): ```yaml @@ -63,62 +78,83 @@ environments: namespace: database storage: url: https://.blob.core.windows.net/dev-snapshots - cloneFrom: [acc] # environments whose snapshots may be restored here + cloneFrom: [acc] # environments whose shared snapshots may be restored here - name: acc - # in-cluster (default), none (only read its snapshots, to clone from), or another cluster's - # API server: {server, caFile, tokenFile}. - kubernetes: none + kubernetes: none # another cluster's storage: url: https://.blob.core.windows.net/acc-snapshots - name: prd + kubernetes: none production: true # restores wait for a second person; no downloads cluster: prod storage: url: https://.blob.core.windows.net/prd-snapshots +``` -teams: - - id: payments - name: Payments - groups: [6f1c2b7e-3a44-4d0e-9a51-2b8e0c7d9f10] # Entra ID group object ids - databases: - - name: payments_{env} # the Database resource's spec.name - environments: [dev, acc, prd] # default: every environment - workloads: # scaled to 0 for a restore in place - - deployment/{env}-payments/payments-api +What each action takes in the database's namespace, per environment, can be changed with +`access`; these are the defaults: + +```yaml + access: + read: {verb: list, resource: pods} # see a database, its snapshots, Jobs, audit + snapshot: {verb: get, resource: secrets} # snapshot, download, share + restore: {verb: get, resource: secrets} # restore, clone into, drop a copy + # in a production environment: + # restore: {verb: create, group: rbac.authorization.k8s.io, resource: rolebindings} ``` -`{env}` is the environment's name. Write lists that use it as block lists: YAML reads braces inside -`[ ]` as a mapping. Check the file in CI before it reaches the server, which refuses to start with -a catalog that does not hold together: +A snapshot holds all of a database's data, so taking one takes what reading the namespace's +Secrets takes. Check the file in CI before it reaches the server, which refuses to start with a +catalog that does not hold together: ```bash docker run --rm -v "$PWD/catalog.yaml:/catalog.yaml:ro" ghcr.io/magmamoose/databases-ui: check /catalog.yaml ``` -## Who does what +## The Database resources + +The server finds a database's namespace and workloads on its `Database` resource: + +```yaml +apiVersion: postgresql.cnpg.io/v1 +kind: Database +metadata: + name: payments-dev + namespace: database + labels: + databases-ui/namespace: dev-payments # the label key is config.namespaceLabel + annotations: + databases-ui/workloads: deployment/payments-api,statefulset/payments-worker +spec: + cluster: {name: dev} + name: payments_dev + owner: payments_dev # a managed role with a passwordSecret +``` -| | Sees | Can | -|---|---|---| -| A team's members | their databases, their snapshots, Jobs and audit entries | snapshot, restore, clone, download outside production, approve a teammate's production restore | -| App role `Admin` | every database in every environment | everything a member can | -| App role `Auditor` | everything | nothing: read-only | +Without the label, a database belongs to its own namespace (`database`): only who may act there, +usually the platform team, sees it. Without the annotation, a restore in place scales nothing; the +owner's other sessions are still ended first. ## What a restore does -- **One transaction.** `pg_restore --single-transaction`: on any error, the database is as it was. -- **Objects in the snapshot are replaced; others stay.** `--clean --if-exists` drops and recreates - what the snapshot holds. A table created after the snapshot was taken is left alone, so an app - whose migrations created it may find it already there. -- **No owners or grants from the snapshot.** `--no-owner --no-acl`: everything restored belongs to - the database's owner role, so a snapshot moves between environments whose roles differ. +- **One transaction, the snapshot exactly.** `psql` runs `BEGIN`, `DROP OWNED BY CURRENT_USER`, then + the script `pg_restore --clean --if-exists --no-owner --no-acl` makes of the snapshot, and + `COMMIT` only once `pg_restore` has finished without an error. Tables created after the snapshot + go too, so an app's migrations find the state they expect. On any error, or if the download + breaks off, nothing changes. +- **`DROP OWNED` also revokes privileges granted to the owner role**, on objects in this database + and on shared objects such as other databases. Owners that own their databases, as CloudNativePG + sets them up, lose nothing. +- **No owners or grants from the snapshot.** Everything restored belongs to the database's owner + role, so a snapshot moves between environments whose roles differ. - **Extensions stay as they are.** Snapshots leave extensions out (`--exclude-extension=*`): the owner role can't drop one the operator created. The target database needs the same extensions; a copy gets those its `Database` resource lists. -- **In place, the workloads go first.** Each listed Deployment or StatefulSet is scaled to 0, its - replica count kept in the annotation `databases-ui/replicas-before-restore`, and other sessions - of the owner role are ended. Afterwards it gets its count back, also when the restore failed. If - the Job itself dies halfway, the next restore restores the count from the annotation. A GitOps - tool that sets `replicas` may scale the app back up during the restore; the transaction keeps the +- **In place, the workloads go first.** Each workload in the annotation is scaled to 0, its replica + count kept in the annotation `databases-ui/replicas-before-restore`, and other sessions of the + owner role are ended. Afterwards it gets its count back, also when the restore failed; if the Job + itself dies halfway, the next restore restores the count from that annotation. A GitOps tool + that sets `replicas` may scale the app back up during the restore; the transaction keeps the data right either way. - **The owner must read everything.** `pg_dump` runs as the owner role, so objects in the database that belong to other roles and that it can't read stop the snapshot. @@ -133,76 +169,78 @@ A container per environment, for example in a storage account per environment, w live; the audit log is under `audit/`, one append blob per month; - network rules that admit the clusters' egress addresses: every transfer happens inside a cluster, the browser's downloads included, which the server streams; -- Storage Blob Data Contributor on the container for the app registration below. - -A Job that clones reads the source environment's container, so that container must admit the -target cluster and grant the same app reading rights. - -### 2. The Entra ID app registration - -- Platform **Web**, redirect URI `https:///auth/callback`. -- **Group claims** in the ID token, emitting group object ids, best restricted to *groups assigned - to the application*; assign each team's group to the app. A person in more groups than fit in a - token is refused with a message that says so. -- App roles `Admin` and `Auditor`, assigned to who needs them. -- Federated credentials, audience `api://AzureADTokenExchange`, issuer your cluster's - service-account issuer, for the server - (`system:serviceaccount::`) and for the Jobs in each namespace - (`system:serviceaccount::databases-ui-job`). No secret to rotate. The server can use a - client secret instead; the Jobs then reach storage through a SAS (`storage.sas`), which suits - Azurite and tests more than production. +- Storage Blob Data Contributor on it for the storage identity below, and, where an environment + clones from this one, for that environment's storage identity too: its server lists what was + shared with it and its Jobs read the snapshots. + +### 2. Entra ID + +- **Sign-in**: the app registration whose ID tokens the cluster's API server accepts (its client id + is the API server's audience). Platform **Web**, redirect URI `https:///auth/callback`. + The sign-in asks for `openid profile`; nothing else. Its credential is a federated credential, + audience `api://AzureADTokenExchange`, issuer the cluster's service-account issuer, subject + `system:serviceaccount::`; or a client secret. +- **The claims the API server uses** (`config.kubernetesUser`, `config.kubernetesGroups`): the + username and groups claims and their prefixes, exactly as in its authentication configuration. + A person in more groups than fit in the token is refused at sign-in, with the reason. +- **Storage** (`azure.storageClientId`, default the sign-in app): a managed identity or app with + federated credentials for the server and for the Jobs in each namespace of `rbac.namespaces` + (`system:serviceaccount::databases-ui-job`). ### 3. Kubernetes -The chart installs, in each namespace of `rbac.namespaces` (the namespaces of the in-cluster -environments): - -- a Role for the server: Database resources (get, list, create and delete, for copies), - Clusters (get), Jobs (get, list, create, patch, delete) and pods (list); no Secrets; -- the Jobs' service account, `databases-ui-job`; -- with `networkPolicy.databases.enabled`, a NetworkPolicy that lets the Jobs' pods reach - PostgreSQL on the CloudNativePG pods, for clusters that admit only listed clients. - -In each namespace of `jobs.scaleNamespaces`, the Jobs' service account may get and patch -Deployments and StatefulSets and list pods, to scale the workloads of a restore in place. - -Creating Jobs in a namespace lets a client mount any Secret there, so the chart also installs a -ValidatingAdmissionPolicy (`jobPolicy`, Kubernetes 1.30+) that holds the Jobs the server creates to -what it builds: this image, run as `job`; one owner's password and never a `*-superuser` Secret; the -CA certificate and no other Secret file; `verify-full` TLS to a `-rw` service in the Job's own -namespace; and only the catalog's storage. +The chart installs: + +- a ClusterRole that lets the server create SubjectAccessReviews; +- in each namespace of `rbac.namespaces` (where the environment's CloudNativePG Cluster is): a Role + for the server (Database resources: get, list, create and delete, for copies; Clusters: get; + Jobs: get, list, create, patch, delete; pods: list; no Secrets), the Jobs' service account + `databases-ui-job`, and with `networkPolicy.databases.enabled` a NetworkPolicy that lets the Jobs + reach PostgreSQL on the CloudNativePG pods; +- in each namespace of `jobs.scaleNamespaces`: the right for the Jobs to get and patch Deployments + and StatefulSets and list pods, for restores in place; +- a ValidatingAdmissionPolicy (`jobPolicy`, Kubernetes 1.30+) that holds the Jobs the server creates + to what it builds: this image, run as `job`; one owner's password and never a `*-superuser` + Secret; the CA certificate and no other Secret file; `verify-full` TLS to a `-rw` service in the + Job's own namespace; and only the catalog's storage. Creating Jobs in a namespace would otherwise + let a client mount any Secret there. ### 4. Install ```bash helm install databases-ui oci://ghcr.io/magmamoose/charts/databases-ui \ --namespace databases-ui --create-namespace \ - --set azure.tenantId= --set azure.clientId= \ + --set azure.tenantId= --set azure.clientId= \ + --set azure.storageClientId= \ --set config.publicOrigin=https://databases.example.com \ - --set-file catalog.content=catalog.yaml \ + --set-file catalog.text=catalog.yaml \ --set 'jobs.scaleNamespaces={dev-payments}' \ --set ingress.enabled=true ``` Every value is described in [`charts/databases-ui/values.yaml`](charts/databases-ui/values.yaml). -The catalog can also come from your own ConfigMap (`catalog.existingConfigMap`); the server reads -it at startup, and the chart rolls the pods when its own copy changes. +The catalog can also be a map in `catalog.content` or your own ConfigMap +(`catalog.existingConfigMap`); the server reads it at startup, and the chart rolls the pods when +its own copy changes. ## Configuration | Variable | | |---|---| -| `AZURE_TENANT_ID`, `AZURE_CLIENT_ID` | the app registration | +| `AZURE_TENANT_ID`, `AZURE_CLIENT_ID` | the sign-in app registration | | `AZURE_FEDERATED_TOKEN_FILE` or `AZURE_CLIENT_SECRET[_FILE]` | its credential | | `AZURE_AUTHORITY_HOST` | a sovereign cloud's login host; default `https://login.microsoftonline.com` | +| `DATABASES_UI_STORAGE_CLIENT_ID` | the storage identity; default the sign-in app | | `DATABASES_UI_PUBLIC_ORIGIN` | where people open it, `https://host` | | `DATABASES_UI_SESSION_KEY[_FILE]` | at least 32 characters, the same on every replica | | `DATABASES_UI_SESSION_HOURS` | 1 to 24, default 8 | | `DATABASES_UI_CATALOG` | the catalog file | +| `DATABASES_UI_NAMESPACE_LABEL` | the label that names a database's namespace; default `databases-ui/namespace` | +| `DATABASES_UI_USERNAME_CLAIM`, `DATABASES_UI_USERNAME_PREFIX` | as the API server builds the user; default `preferred_username`, `oidc:` | +| `DATABASES_UI_GROUPS_CLAIM`, `DATABASES_UI_GROUPS_PREFIX` | as it builds the groups; default `groups`, `oidc:` | | `DATABASES_UI_JOB_IMAGE` | the image the Jobs run: this app's own | | `DATABASES_UI_JOB_SERVICE_ACCOUNT` | the Jobs' service account; default `databases-ui-job` | -| `DATABASES_UI_STORAGE_SAS[_FILE]` and `DATABASES_UI_STORAGE_SAS_SECRET` | instead of Entra ID: a SAS for the server, and `/` of the same SAS in each Job namespace | -| `DATABASES_UI_ADMIN_ROLE`, `DATABASES_UI_AUDITOR_ROLE` | app role values; default `Admin`, `Auditor` | +| `DATABASES_UI_STORAGE_SAS[_FILE]` and `DATABASES_UI_STORAGE_SAS_SECRET` | instead of Entra ID: a SAS for the server, and `/` of the same SAS in each Job namespace (for Azurite and tests) | | `DATABASES_UI_BRAND_ACCENT`, `_ACCENT_TEXT`, `_ACCENT_DARK`, `_ACCENT_TEXT_DARK` | your colours as `#rrggbb` | `python -m databases_ui [serve | check | job]`: the server (default), the catalog check, @@ -213,15 +251,18 @@ and a Job's work. - **Backend for frontend.** The browser holds no token it can read: the session is an AES-GCM sealed, `__Host-`, `HttpOnly`, `Secure`, `SameSite=Strict` cookie, and every write also needs a CSRF token and this origin. No inline script or style, under a strict Content Security Policy. -- **Decided on the server.** Who may see and do what follows from the catalog and the groups in - the person's ID token, checked on every call. +- **Kubernetes decides.** Every call asks the API server whether the person may do what it takes in + the database's namespace. Outside the namespaces someone may see, a database does not exist to + them: not in a list, not in an answer. If the claims or prefixes differ from the API server's, + the reviews ask about nobody and refuse everything. - **No passwords in the server.** It reads no Secret; a Job's pod gets the owner's password from - the kubelet, and the admission policy above keeps the server's Jobs to what it builds. + the kubelet, and the admission policy keeps the server's Jobs to what it builds. - **A production restore takes two people.** It is created suspended and starts only when someone - else who may act on the database approves it; a Job's pod template can't change after - creation, so what runs is what was asked for. Unapproved requests expire after a day. -- **Snapshots stay in the cluster's storage.** Downloads, outside production only, stream through - the server and are recorded in the audit log. + else who may restore there approves it; a Job's pod template can't change after creation, so + what runs is what was asked for. Unapproved requests expire after a day. +- **Data leaves an environment only when someone who may snapshot it says so**: a share names one + namespace in one environment, and is in the audit log. Downloads, outside production only, + stream through the server and are recorded too. ## Development @@ -232,8 +273,8 @@ uv run python -m databases_ui check examples/catalog.yaml cd frontend && npm install && npm run dev # the UI on 5173, the API proxied to 8080 ``` -[`e2e/run.py`](e2e/run.py) runs every action against a real cluster with CloudNativePG and -Azurite; CI runs it on kind: +[`e2e/run.py`](e2e/run.py) runs every action against a real cluster with CloudNativePG, Azurite and +RBAC like an OIDC-backed API server's; CI runs it on kind: ```bash k3d cluster create dbui diff --git a/charts/databases-ui/ci/default-values.yaml b/charts/databases-ui/ci/default-values.yaml index 97b002d..c112995 100644 --- a/charts/databases-ui/ci/default-values.yaml +++ b/charts/databases-ui/ci/default-values.yaml @@ -2,26 +2,24 @@ azure: tenantId: 11111111-2222-3333-4444-555555555555 clientId: aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee + storageClientId: cccccccc-bbbb-cccc-dddd-eeeeeeeeeeee config: publicOrigin: https://databases.example.com + namespaceLabel: example.com/namespace + kubernetesGroups: + claim: roles + prefix: "oidc:" catalog: content: environments: - name: dev storage: url: https://examplesnapshots.blob.core.windows.net/dev - - name: prd - production: true + cloneFrom: [acc] + - name: acc + kubernetes: none storage: - url: https://examplesnapshots.blob.core.windows.net/prd - teams: - - id: payments - name: Payments - groups: [6f1c2b7e-3a44-4d0e-9a51-2b8e0c7d9f10] - databases: - - name: payments - workloads: - - deployment/{env}-payments/api + url: https://examplesnapshots.blob.core.windows.net/acc rbac: namespaces: [database] jobs: diff --git a/charts/databases-ui/templates/NOTES.txt b/charts/databases-ui/templates/NOTES.txt index b61e647..8a06ba2 100644 --- a/charts/databases-ui/templates/NOTES.txt +++ b/charts/databases-ui/templates/NOTES.txt @@ -6,7 +6,11 @@ registration ({{ .Values.azure.clientId }}): {{ .Values.config.publicOrigin }}/auth/callback {{- if .Values.azure.workloadIdentity.enabled }} -and federated credentials, audience {{ .Values.azure.workloadIdentity.audience }}, for these subjects: +and federated credentials, audience {{ .Values.azure.workloadIdentity.audience }}, on the app for the server: + + system:serviceaccount:{{ .Release.Namespace }}:{{ include "databases-ui.serviceAccountName" . }} + +and on the storage identity ({{ .Values.azure.storageClientId | default .Values.azure.clientId }}) for the server and the Jobs: system:serviceaccount:{{ .Release.Namespace }}:{{ include "databases-ui.serviceAccountName" . }} {{- range .Values.rbac.namespaces }} diff --git a/charts/databases-ui/templates/_helpers.tpl b/charts/databases-ui/templates/_helpers.tpl index 4188c91..c926fc8 100644 --- a/charts/databases-ui/templates/_helpers.tpl +++ b/charts/databases-ui/templates/_helpers.tpl @@ -52,10 +52,10 @@ helm.sh/chart: {{ printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | {{- default (printf "%s-catalog" (include "databases-ui.fullname" .)) .Values.catalog.existingConfigMap }} {{- end }} -{{- /* The catalog as YAML text: catalog.content is a map in values, or a string from --set-file. */}} +{{- /* The catalog as YAML text: catalog.text as it is, else catalog.content. */}} {{- define "databases-ui.catalogContent" -}} -{{- if kindIs "string" .Values.catalog.content }} -{{- .Values.catalog.content }} +{{- if .Values.catalog.text }} +{{- .Values.catalog.text }} {{- else }} {{- toYaml .Values.catalog.content }} {{- end }} @@ -70,8 +70,8 @@ helm.sh/chart: {{ printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | {{- $_ := required "config.publicOrigin is required, such as https://databases.example.com" .Values.config.publicOrigin }} {{- $_ := required "azure.tenantId is required" .Values.azure.tenantId }} {{- $_ := required "azure.clientId is required" .Values.azure.clientId }} -{{- if and (not .Values.catalog.existingConfigMap) (not .Values.catalog.content) }} -{{- fail "set catalog.content (environments and teams) or catalog.existingConfigMap" }} +{{- if not (or .Values.catalog.existingConfigMap .Values.catalog.content .Values.catalog.text) }} +{{- fail "set catalog.content or catalog.text (the environments), or catalog.existingConfigMap" }} {{- end }} {{- if and (not .Values.azure.workloadIdentity.enabled) (not .Values.azure.clientSecret.existingSecret) }} {{- fail "set azure.workloadIdentity.enabled, or azure.clientSecret.existingSecret" }} @@ -121,10 +121,20 @@ helm.sh/chart: {{ printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | - name: DATABASES_UI_STORAGE_SAS_SECRET value: {{ printf "%s/%s" .Values.storage.sas.existingSecret .Values.storage.sas.key | quote }} {{- end }} -- name: DATABASES_UI_ADMIN_ROLE - value: {{ .Values.config.adminRole | quote }} -- name: DATABASES_UI_AUDITOR_ROLE - value: {{ .Values.config.auditorRole | quote }} +{{- with .Values.azure.storageClientId }} +- name: DATABASES_UI_STORAGE_CLIENT_ID + value: {{ . | quote }} +{{- end }} +- name: DATABASES_UI_NAMESPACE_LABEL + value: {{ .Values.config.namespaceLabel | quote }} +- name: DATABASES_UI_USERNAME_CLAIM + value: {{ .Values.config.kubernetesUser.claim | quote }} +- name: DATABASES_UI_USERNAME_PREFIX + value: {{ .Values.config.kubernetesUser.prefix | quote }} +- name: DATABASES_UI_GROUPS_CLAIM + value: {{ .Values.config.kubernetesGroups.claim | quote }} +- name: DATABASES_UI_GROUPS_PREFIX + value: {{ .Values.config.kubernetesGroups.prefix | quote }} {{- range $key, $env := dict "accent" "ACCENT" "accentText" "ACCENT_TEXT" "accentDark" "ACCENT_DARK" "accentTextDark" "ACCENT_TEXT_DARK" }} {{- with index $.Values.branding $key }} - name: DATABASES_UI_BRAND_{{ $env }} diff --git a/charts/databases-ui/templates/rbac.yaml b/charts/databases-ui/templates/rbac.yaml index fa564f9..e983d3c 100644 --- a/charts/databases-ui/templates/rbac.yaml +++ b/charts/databases-ui/templates/rbac.yaml @@ -1,5 +1,32 @@ {{- $fullname := include "databases-ui.fullname" . }} {{- $labels := include "databases-ui.labels" . }} +# Who may act on a database is the API server's answer: the server asks it, with a +# SubjectAccessReview, about the user and groups a person's ID token gives them. +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: {{ $fullname }}-access-review + labels: + {{- $labels | nindent 4 }} +rules: + - apiGroups: [authorization.k8s.io] + resources: [subjectaccessreviews] + verbs: [create] +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: {{ $fullname }}-access-review + labels: + {{- $labels | nindent 4 }} +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: {{ $fullname }}-access-review +subjects: + - kind: ServiceAccount + name: {{ include "databases-ui.serviceAccountName" . }} + namespace: {{ .Release.Namespace }} {{- range $ns := .Values.rbac.namespaces }} --- # The server reads the Database resources and the Cluster's managed roles, creates and approves diff --git a/charts/databases-ui/values.yaml b/charts/databases-ui/values.yaml index f7e14f8..ba15569 100644 --- a/charts/databases-ui/values.yaml +++ b/charts/databases-ui/values.yaml @@ -16,10 +16,13 @@ nameOverride: "" fullnameOverride: "" azure: - # The Entra ID tenant (a GUID) and the app registration's client id. One app signs people in - # and, with workload identity, reaches storage for the server and the Jobs. + # The Entra ID tenant (a GUID) and the client id of the app registration people sign in to: the + # one the cluster's API server trusts, so the ID token names them as Kubernetes does. tenantId: "" clientId: "" + # The identity that reaches storage, for the server and the Jobs. Empty: the sign-in app. A + # managed identity or app of its own needs federated credentials for the same service accounts. + storageClientId: "" # Leave empty for the public cloud (https://login.microsoftonline.com). authorityHost: "" # The app authenticates with its own service-account token, which Entra ID accepts through a @@ -41,17 +44,26 @@ config: publicOrigin: "" # How long a sign-in lasts, 1 to 24. sessionHours: 8 - # The app roles that act on every database (Admin) or read everything (Auditor). - adminRole: Admin - auditorRole: Auditor - -# The environments and the teams (see the README). Rendered into a ConfigMap from `content`, a -# map here or the file's text with --set-file catalog.content=catalog.yaml, or read from your own -# ConfigMap in the release namespace. + # The label on a Database resource that names the namespace of the app it belongs to. Who may do + # what with it is Kubernetes RBAC in that namespace; without the label, in the Cluster's own. + namespaceLabel: databases-ui/namespace + # How the cluster's API server names people from their ID token, as in its authentication + # configuration: the access reviews ask about the same user and groups, so these must match. + kubernetesUser: + claim: preferred_username + prefix: "oidc:" + kubernetesGroups: + claim: groups + prefix: "oidc:" + +# The environments (see the README). Rendered into a ConfigMap from `content`, a map here, or from +# `text`, the file as it is (--set-file catalog.text=catalog.yaml); or read from your own ConfigMap +# in the release namespace. catalog: existingConfigMap: "" key: catalog.yaml - content: "" + content: {} + text: "" # Where the Jobs run: the namespace of every in-cluster environment in the catalog, usually the # one that holds the CloudNativePG Clusters. Each gets a Role for this app, the Jobs' service diff --git a/e2e/fixtures.yaml b/e2e/fixtures.yaml index 7b4a434..5970395 100644 --- a/e2e/fixtures.yaml +++ b/e2e/fixtures.yaml @@ -1,6 +1,7 @@ # The world the end-to-end test runs in: two CloudNativePG clusters standing in for two # environments (dev, and tst as production), an app in each that holds a connection open, Azurite -# for storage, and NetworkPolicies that let only listed clients reach PostgreSQL. +# for storage, NetworkPolicies that let only listed clients reach PostgreSQL, and RBAC that gives +# people's groups (as an OIDC API server would name them) view, edit or admin in the app namespaces. apiVersion: v1 kind: Namespace metadata: @@ -104,6 +105,10 @@ kind: Database metadata: name: payments-dev namespace: database + labels: + databases-ui/namespace: dev-payments + annotations: + databases-ui/workloads: deployment/payments-api spec: cluster: {name: dev} name: payments_dev @@ -119,6 +124,10 @@ kind: Database metadata: name: payments-tst namespace: database + labels: + databases-ui/namespace: tst-payments + annotations: + databases-ui/workloads: deployment/payments-api spec: cluster: {name: tst} name: payments_tst @@ -191,3 +200,52 @@ spec: ports: - {protocol: TCP, port: 443} - {protocol: TCP, port: 6443} +--- +apiVersion: v1 +kind: Namespace +metadata: + name: dev-other +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: k8s-dev-payments-write + namespace: dev-payments +roleRef: {apiGroup: rbac.authorization.k8s.io, kind: ClusterRole, name: edit} +subjects: + - {apiGroup: rbac.authorization.k8s.io, kind: Group, name: "oidc:k8s-dev-payments-write"} +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: k8s-tst-payments-admin + namespace: tst-payments +roleRef: {apiGroup: rbac.authorization.k8s.io, kind: ClusterRole, name: admin} +subjects: + - {apiGroup: rbac.authorization.k8s.io, kind: Group, name: "oidc:k8s-tst-payments-admin"} +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: k8s-tst-payments-write + namespace: tst-payments +roleRef: {apiGroup: rbac.authorization.k8s.io, kind: ClusterRole, name: edit} +subjects: + - {apiGroup: rbac.authorization.k8s.io, kind: Group, name: "oidc:k8s-tst-payments-write"} +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: k8s-dev-other-write + namespace: dev-other +roleRef: {apiGroup: rbac.authorization.k8s.io, kind: ClusterRole, name: edit} +subjects: + - {apiGroup: rbac.authorization.k8s.io, kind: Group, name: "oidc:k8s-dev-other-write"} +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: cloud-read +roleRef: {apiGroup: rbac.authorization.k8s.io, kind: ClusterRole, name: view} +subjects: + - {apiGroup: rbac.authorization.k8s.io, kind: Group, name: "oidc:cloud-read"} diff --git a/e2e/run.py b/e2e/run.py index bbc06ea..8eb0d0b 100644 --- a/e2e/run.py +++ b/e2e/run.py @@ -36,13 +36,13 @@ CHART = HERE.parent / "charts" / "databases-ui" ACCOUNT = "e2eaccount" ORIGIN = "http://localhost:18080" # DevSkim: ignore DS162092 - the port-forwarded test server -PAYMENTS = "6f1c2b7e-3a44-4d0e-9a51-2b8e0c7d9f10" -OTHERS = "0b9d8e7c-6f5a-4b3c-8d2e-1f0a9b8c7d6e" +# People and their groups, as the API server would name them from an ID token. PEOPLE = { - "alice": {"groups": [PAYMENTS], "roles": []}, - "bob": {"groups": [PAYMENTS], "roles": []}, - "carol": {"groups": [OTHERS], "roles": []}, - "audrey": {"groups": [], "roles": ["Auditor"]}, + "alice": ["k8s-dev-payments-write", "k8s-tst-payments-admin"], + "bob": ["k8s-dev-payments-write", "k8s-tst-payments-admin"], + "pat": ["k8s-tst-payments-write"], + "carol": ["k8s-dev-other-write"], + "audrey": ["cloud-read"], } passed: list[str] = [] @@ -175,10 +175,6 @@ def setup() -> tuple[str, dict[str, str]]: {"name": "dev", "storage": {"url": f"http://azurite.storage.svc:10000/{ACCOUNT}/dev"}, "cloneFrom": ["tst"]}, # DevSkim: ignore DS137138 {"name": "tst", "production": True, "storage": {"url": f"http://azurite.storage.svc:10000/{ACCOUNT}/tst"}, "cloneFrom": ["dev"]}, # DevSkim: ignore DS137138 ], - "teams": [ - {"id": "payments", "name": "Payments", "groups": [PAYMENTS], "databases": [{"name": "payments_{env}", "workloads": ["deployment/{env}-payments/payments-api"]}]}, - {"id": "others", "name": "Others", "groups": [OTHERS], "databases": [{"name": "elsewhere"}]}, - ], }}, } # fmt: skip sh("helm", "upgrade", "--install", "databases-ui", str(CHART), "-n", "databases-ui", "--values", "-", "--wait", "--timeout", "180s", input=json.dumps(values)) @@ -187,8 +183,11 @@ def setup() -> tuple[str, dict[str, str]]: session_key = base64.b64decode(kubectl("get", "secret", "databases-ui-session", "-n", "databases-ui", "-o", "jsonpath={.data.session-key}")) sealer = Sealer(session_key) cookies = {} - for person, who in PEOPLE.items(): - data = {"oid": hashlib.md5(person.encode()).hexdigest(), "upn": f"{person}@example.com", "name": person.title(), "csrf": f"csrf-{person}", **who} # nosec B324 - an id for a test person + for person, groups in PEOPLE.items(): + data = { + "oid": hashlib.md5(person.encode()).hexdigest(), "upn": f"{person}@example.com", "name": person.title(), "csrf": f"csrf-{person}", # nosec B324 - an id for a test person + "user": f"oidc:{person}@example.com", "groups": [f"oidc:{g}" for g in groups], + } # fmt: skip cookies[person] = sealer.seal("session", data, 3600) return sas, cookies @@ -229,29 +228,34 @@ def replicas(env: str) -> str: def scenarios(cookies: dict[str, str]) -> None: - alice, bob, carol, audrey = (Client(p, cookies[p]) for p in ("alice", "bob", "carol", "audrey")) + alice, bob, pat, carol, audrey = (Client(p, cookies[p]) for p in ("alice", "bob", "pat", "carol", "audrey")) - print("who sees what", flush=True) + print("who sees what: Kubernetes RBAC in each database's namespace", flush=True) me = alice.get("/api/me").json() - assert [t["id"] for t in me["teams"]] == ["payments"] and [e["name"] for e in me["environments"]] == ["dev", "tst"], me - ok("me: alice is in payments, sees dev and tst") - assert [d["name"] for d in alice.get("/api/environments/dev/databases").json()["databases"]] == ["payments_dev"] + assert me["kubernetes"]["user"] == "oidc:alice@example.com" and [e["name"] for e in me["environments"]] == ["dev", "tst"], me + dev = alice.get("/api/environments/dev/databases").json()["databases"] + assert [(d["name"], d["namespace"], d["can_snapshot"], d["can_restore"]) for d in dev] == [("payments_dev", "dev-payments", True, True)], dev assert carol.get("/api/environments/dev/databases").json()["databases"] == [] - assert {d["name"] for d in audrey.get("/api/environments/tst/databases").json()["databases"]} == {"payments_tst"} - ok("databases: a member sees the team's, another team nothing, an auditor everything") - assert carol.post("/api/environments/dev/databases/payments_dev/snapshots").status_code == 403 + assert [(d["name"], d["can_snapshot"]) for d in audrey.get("/api/environments/dev/databases").json()["databases"]] == [("payments_dev", False)] + assert [(d["name"], d["can_snapshot"], d["can_restore"]) for d in pat.get("/api/environments/tst/databases").json()["databases"]] == [("payments_tst", True, False)] + ok("databases: edit in the namespace acts, edit elsewhere sees nothing, cluster view only reads, production restore takes admin") + users = alice.get("/api/environments/dev/users").json()["users"] + assert [(u["name"], u["secret"]) for u in users] == [("payments_dev", "payments-dev-db")], users + assert carol.get("/api/environments/dev/users").json()["users"] == [] + ok("users: the owner role and its password Secret, only for databases you see") + assert carol.post("/api/environments/dev/databases/payments_dev/snapshots").status_code == 404 assert audrey.post("/api/environments/dev/databases/payments_dev/snapshots").status_code == 403 assert alice.post("/api/environments/dev/databases/payments_dev/snapshots", csrf=False).status_code == 403 - ok("refused: another team, an auditor, and a write without the CSRF token") + ok("refused: another namespace (to whom the database does not exist), a reader, and a write without the CSRF token") print("snapshot", flush=True) job = alice.post("/api/environments/dev/databases/payments_dev/snapshots", {"note": "before the test"}).json() snap = finished(alice, "dev", job["name"]) assert snap["result"]["bytes"] > 0, snap snapshots = alice.get("/api/environments/dev/databases/payments_dev/snapshots").json()["snapshots"] - assert len(snapshots) == 1 and snapshots[0]["note"] == "before the test" and snapshots[0]["created_by"] == "alice@example.com", snapshots + assert len(snapshots) == 1 and snapshots[0]["note"] == "before the test" and snapshots[0]["namespace"] == "dev-payments", snapshots dev_snapshot = snapshots[0]["id"] - ok(f"snapshot of dev: {snapshots[0]['size']} bytes in blob storage, with who and why") + ok(f"snapshot of dev: {snapshots[0]['size']} bytes in blob storage, with who, why and the namespace") print("restore in place", flush=True) psql("dev", "payments_dev", "set role payments_dev; delete from orders where id > 1; update orders set total = 0; create table later (id int)") @@ -267,10 +271,10 @@ def scenarios(cookies: dict[str, str]) -> None: finished(alice, "dev", job["name"]) assert orders("dev", "payments_dev") == ["dev-Ada", "dev-Grace", "dev-Katherine"] assert psql("dev", "payments_dev", "select sum(total) from orders") == "118.75" - assert psql("dev", "payments_dev", "select to_regclass('later') is not null") == "t" + assert psql("dev", "payments_dev", "select to_regclass('later') is null") == "t" assert seen_zero and replicas("dev") == "2" assert kubectl("get", "deployment/payments-api", "-n", "dev-payments", "-o", "jsonpath={.metadata.annotations}").find("replicas-before-restore") == -1 - ok("restore in place: data back, the app went to 0 and back to 2, a table made later stays") + ok("restore in place: exactly the snapshot (a table made later is gone), the app went to 0 and back to 2") wait_for("the app's sessions to return", lambda: int(psql("dev", "payments_dev", "select count(*) from pg_stat_activity where usename = 'payments_dev'")) >= 2, timeout=120) ok("the app reconnected") @@ -285,29 +289,37 @@ def scenarios(cookies: dict[str, str]) -> None: assert db["copy"]["name"] == "payments_dev_copy", db ok("restore into a copy: payments_dev_copy holds the snapshot with its extension, payments_dev untouched") - print("clone from production", flush=True) + print("clone from production, once shared", flush=True) job = alice.post("/api/environments/tst/databases/payments_tst/snapshots", {"note": "for dev"}).json() finished(alice, "tst", job["name"]) tst_snapshot = alice.get("/api/environments/tst/databases/payments_tst/snapshots").json()["snapshots"][0]["id"] - job = alice.post("/api/environments/dev/databases/payments_dev/restore", {"source_environment": "tst", "source_database": "payments_tst", "snapshot": tst_snapshot, "into": "database", "reason": "reproduce the tst bug"}).json() + clone = {"source_environment": "tst", "source_database": "payments_tst", "snapshot": tst_snapshot, "into": "database", "reason": "reproduce the tst bug"} + assert alice.post("/api/environments/dev/databases/payments_dev/restore", clone).json()["error"] == "not_shared" + assert alice.get("/api/environments/dev/databases/payments_dev/shared").json()["snapshots"] == [] + shared = alice.post(f"/api/environments/tst/databases/payments_tst/snapshots/{tst_snapshot}/share", {"environment": "dev", "namespace": "dev-payments"}).json() + assert shared["shared_with"] == ["dev/dev-payments"], shared + assert [s["id"] for s in alice.get("/api/environments/dev/databases/payments_dev/shared").json()["snapshots"]] == [tst_snapshot] + job = alice.post("/api/environments/dev/databases/payments_dev/restore", clone).json() assert job["source_environment"] == "tst", job finished(alice, "dev", job["name"]) assert orders("dev", "payments_dev") == ["tst-Ada", "tst-Grace", "tst-Katherine"] - ok("clone: tst's snapshot restored into dev") + ok("clone: refused until shared, then tst's snapshot restored into dev") - print("production restore needs a second person", flush=True) + print("production restore needs a second person with admin", flush=True) psql("tst", "payments_tst", "set role payments_tst; truncate orders") body = {"source_environment": "tst", "source_database": "payments_tst", "snapshot": tst_snapshot, "into": "database", "reason": "restore after the truncate"} + assert pat.post("/api/environments/tst/databases/payments_tst/restore", body).status_code == 403 job = alice.post("/api/environments/tst/databases/payments_tst/restore", body).json() assert job["state"] == "waiting" and job["approval"] == "required", job time.sleep(5) assert replicas("tst") == "2" and orders("tst", "payments_tst") == [] - ok("production restore waits: nothing ran, the app untouched") + ok("production restore waits: nothing ran, the app untouched; edit alone may not ask") assert alice.post(f"/api/environments/tst/jobs/{job['name']}/approve").status_code == 403 + assert pat.post(f"/api/environments/tst/jobs/{job['name']}/approve").status_code == 403 assert carol.post(f"/api/environments/tst/jobs/{job['name']}/approve").status_code == 403 listed = next(j for j in bob.get("/api/environments/tst/jobs").json()["jobs"] if j["name"] == job["name"]) assert listed["can_approve"] and not next(j for j in alice.get("/api/environments/tst/jobs").json()["jobs"] if j["name"] == job["name"])["can_approve"] - ok("refused: approving your own request, or another team's") + ok("refused: approving your own request, with edit only, or from another namespace") approved = bob.post(f"/api/environments/tst/jobs/{job['name']}/approve").json() assert approved["approved_by"] == "bob@example.com", approved finished(bob, "tst", job["name"]) @@ -322,8 +334,8 @@ def scenarios(cookies: dict[str, str]) -> None: response = alice.get(f"/api/environments/dev/databases/payments_dev/snapshots/{dev_snapshot}/download") assert response.status_code == 200 and response.content[:5] == b"PGDMP", response.status_code assert alice.get(f"/api/environments/tst/databases/payments_tst/snapshots/{tst_snapshot}/download").status_code == 403 - assert carol.get(f"/api/environments/dev/databases/payments_dev/snapshots/{dev_snapshot}/download").status_code == 403 - ok(f"download from dev ({len(response.content)} bytes, a pg_dump archive); none from production or for another team") + assert audrey.get(f"/api/environments/dev/databases/payments_dev/snapshots/{dev_snapshot}/download").status_code == 403 + ok(f"download from dev ({len(response.content)} bytes, a pg_dump archive); none from production or for a reader") print("drop the copy", flush=True) assert alice.delete("/api/environments/dev/databases/payments_dev/copy").status_code == 204 @@ -335,10 +347,10 @@ def scenarios(cookies: dict[str, str]) -> None: tst_log = [(e["action"], e["actor"]) for e in bob.get("/api/environments/tst/audit").json()["entries"]] for entry in [("snapshot.requested", "alice@example.com"), ("snapshot.succeeded", "alice@example.com"), ("restore.requested", "alice@example.com"), ("restore.succeeded", "alice@example.com"), ("snapshot.downloaded", "alice@example.com"), ("copy.dropped", "alice@example.com")]: assert entry in dev_log, (entry, dev_log) - for entry in [("restore.approved", "bob@example.com"), ("restore.declined", "bob@example.com"), ("restore.succeeded", "alice@example.com")]: + for entry in [("snapshot.shared", "alice@example.com"), ("restore.approved", "bob@example.com"), ("restore.declined", "bob@example.com"), ("restore.succeeded", "alice@example.com")]: assert entry in tst_log, (entry, tst_log) assert carol.get("/api/environments/dev/audit").json()["entries"] == [] - ok(f"audit log: {len(dev_log)} entries in dev, {len(tst_log)} in tst, who and what; none shown to another team") + ok(f"audit log: {len(dev_log)} entries in dev, {len(tst_log)} in tst, who and what; none shown outside the namespace") def forged(base: dict[str, Any], change) -> str: @@ -385,7 +397,8 @@ def change(pod: dict[str, Any]) -> None: ok("admission policy: a Job as built passes; with a superuser's password, another image or command, the CA key, other storage, another host or no TLS checks it is refused") for verb, resource in (("get", "secrets"), ("create", "pods"), ("delete", "clusters.postgresql.cnpg.io")): assert kubectl("auth", "can-i", verb, resource, "-n", "database", "--as=system:serviceaccount:databases-ui:databases-ui", check=False).strip() == "no" - ok("RBAC: the server's account reads no Secret, creates no pod and deletes no Cluster") + assert kubectl("auth", "can-i", "create", "subjectaccessreviews.authorization.k8s.io", "--as=system:serviceaccount:databases-ui:databases-ui", check=False).strip() == "yes" + ok("RBAC: the server's account reads no Secret, creates no pod and deletes no Cluster; it asks access reviews") def main() -> None: diff --git a/examples/catalog.yaml b/examples/catalog.yaml index 544d38d..5120930 100644 --- a/examples/catalog.yaml +++ b/examples/catalog.yaml @@ -1,44 +1,26 @@ -# Four environments, each with its own cluster and storage, and two teams. Check it with +# The catalog of the instance in the dev cluster. Every instance lists every environment; only the +# one in its own cluster runs Jobs, the others are where shared snapshots come from or go to. +# Check it with # python -m databases_ui check examples/catalog.yaml environments: - name: dev storage: url: https://examplesnapshots.blob.core.windows.net/dev + # Snapshots tst and acc share with a namespace here can be cloned into it. cloneFrom: [tst, acc] - name: tst + kubernetes: none storage: url: https://examplesnapshots.blob.core.windows.net/tst cloneFrom: [acc] - name: acc + kubernetes: none storage: url: https://examplesnapshots.blob.core.windows.net/acc - name: prd + kubernetes: none production: true # The Cluster's own name, when it differs from the environment's. cluster: prod storage: url: https://exampleprdsnapshots.blob.core.windows.net/prd - -teams: - - id: payments - name: Payments - description: Builds and runs the payments service. - groups: [6f1c2b7e-3a44-4d0e-9a51-2b8e0c7d9f10] - databases: - - name: payments_{env} - # {env} is the environment; a block list, since YAML reads braces in [ ] as a mapping. - workloads: - - deployment/{env}-payments/payments-api - - deployment/{env}-payments/payments-worker - - id: identity - name: Identity - description: Runs single sign-on for every app. - groups: [0b9d8e7c-6f5a-4b3c-8d2e-1f0a9b8c7d6e] - databases: - - name: keycloak - environments: [dev, tst, acc] - workloads: - - statefulset/{env}-keycloak/keycloak - - name: keycloak_prd - environments: [prd] - workloads: [statefulset/prd-keycloak/keycloak] diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index dbe4057..c15c2ce 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -4,6 +4,7 @@ import { Activity } from "./views/Activity"; import { Audit } from "./views/Audit"; import { DatabaseView } from "./views/DatabaseView"; import { Databases } from "./views/Databases"; +import { Users } from "./views/Users"; type Toast = { id: number; message: string; kind: "info" | "error" }; @@ -88,7 +89,7 @@ export function App() {

Databases UI

-

{state === "ended" ? "Your session has ended." : "Sign in with your work account to snapshot, restore and clone your team's databases."}

+

{state === "ended" ? "Your session has ended." : "Sign in with your work account to snapshot, restore and clone the databases of your namespaces."}

{authError && (

{authError} @@ -103,9 +104,12 @@ export function App() { } const [envName, page = "", id] = route.path; - const env = me.environments.find((e) => e.name === envName) ?? me.environments.find((e) => e.runs_jobs) ?? me.environments[0]; + // Only the environments of this cluster: the others are where shared snapshots come from. + const here = me.environments.filter((e) => e.runs_jobs); + const env = here.find((e) => e.name === envName) ?? here[0]; const pages = [ { match: "", label: "Databases" }, + { match: "users", label: "Users" }, { match: "activity", label: "Activity" }, { match: "audit", label: "Audit log" }, ]; @@ -128,7 +132,7 @@ export function App() {

+
+ + setNamespace(e.target.value)} /> +
+
+ {error && ( +

+ {error} +

+ )} + +
+ + +
+ +
+ ); +} + function RestoreDialog({ env, db, snapshot, onClose, onDone }: { env: Environment; db: Database; snapshot?: string; onClose: () => void; onDone: (waiting: boolean) => void }) { const [source, setSource] = useState(env.name); - // The databases of the source environment, and the one picked there: the same name if it has one. - const [sources, setSources] = useState<{ env: string; databases: Database[]; picked: string } | null>({ env: env.name, databases: [db], picked: db.name }); const [list, setList] = useState(null); const [chosen, setChosen] = useState(snapshot ?? ""); const [into, setInto] = useState<"database" | "copy">("database"); @@ -215,31 +307,14 @@ function RestoreDialog({ env, db, snapshot, onClose, onDone }: { env: Environmen const [typed, setTyped] = useState(""); const [busy, setBusy] = useState(false); const [error, setError] = useState(""); - const sourceDb = sources?.env === source ? sources.picked : ""; + // This database's own snapshots here, or what another environment shared with its namespace. useEffect(() => { - if (source === env.name) { - setSources({ env: env.name, databases: [db], picked: db.name }); - return; - } let live = true; - setSources(null); - setError(""); - api.databases(source).then( - (found) => live && setSources({ env: source, databases: found, picked: found.some((d) => d.name === db.name) ? db.name : (found[0]?.name ?? "") }), - (err) => live && setError(message(err)), - ); - return () => { - live = false; - }; - }, [source, env.name, db]); - - useEffect(() => { setList(null); - if (!sourceDb) return; - let live = true; setError(""); - api.snapshots(source, sourceDb).then( + const load = source === env.name ? api.snapshots(env.name, db.name) : api.shared(env.name, db.name).then((all) => all.filter((s) => s.environment === source)); + load.then( (found) => { if (!live) return; setList(found); @@ -250,17 +325,19 @@ function RestoreDialog({ env, db, snapshot, onClose, onDone }: { env: Environmen return () => { live = false; }; - }, [source, sourceDb]); + }, [source, env.name, db.name]); + const picked = list?.find((s) => s.id === chosen); const inPlace = into === "database"; - const ready = chosen && reason.trim().length >= 3 && (!inPlace || typed === db.name); + const ready = picked && reason.trim().length >= 3 && (!inPlace || typed === db.name); async function submit(e: FormEvent) { e.preventDefault(); + if (!picked) return; setBusy(true); setError(""); try { - const job = await api.restore(env.name, db.name, { source_environment: source, source_database: sourceDb, snapshot: chosen, into, reason: reason.trim() }); + const job = await api.restore(env.name, db.name, { source_environment: source, source_database: picked.database, snapshot: picked.id, into, reason: reason.trim() }); onDone(job.state === "waiting"); } catch (err) { setError(message(err)); @@ -278,34 +355,25 @@ function RestoreDialog({ env, db, snapshot, onClose, onDone }: { env: Environmen
- - setChosen(e.target.value)} disabled={!list || list.length === 0}> + {list?.length === 0 && } + {(list ?? []).map((s) => ( + ))}
-
- - -
Into
    @@ -313,7 +381,7 @@ function RestoreDialog({ env, db, snapshot, onClose, onDone }: { env: Environmen @@ -341,7 +409,7 @@ function RestoreDialog({ env, db, snapshot, onClose, onDone }: { env: Environmen )}

    - pg_restore runs in one transaction: if anything fails, nothing changes. Tables made after the snapshot was taken stay as they are. + One transaction: the database ends up as the snapshot was, or if anything fails, as it is now. {env.production && " In production a second person approves it before it starts."}

    {error && ( diff --git a/frontend/src/views/Databases.tsx b/frontend/src/views/Databases.tsx index cc881a6..69e32f4 100644 --- a/frontend/src/views/Databases.tsx +++ b/frontend/src/views/Databases.tsx @@ -5,7 +5,6 @@ import { Loading, useLoad } from "../components/ui"; export function Databases({ env }: { env: Environment }) { const { me } = useSession(); const { data, error } = useLoad(() => api.databases(env.name), [env.name]); - const cloners = me.environments.filter((e) => e.clone_from.includes(env.name)).map((e) => e.name); return ( <> @@ -14,27 +13,37 @@ export function Databases({ env }: { env: Environment }) { {env.name} {env.production && production}

    - {env.runs_jobs - ? env.production - ? "Take a snapshot at any time. A restore waits for a second person, and snapshots stay here." - : "Take a snapshot, restore one, or clone one from another environment." - : `Only this environment's snapshots are read here${cloners.length ? `, to clone into ${cloners.join(", ")}` : ""}. Nothing runs in ${env.name} from this app.`} + {env.production + ? "Take a snapshot at any time. A restore waits for a second person, and snapshots stay here." + : "Take a snapshot, restore one, or clone one another environment shared with you."}{" "} + You see the databases of the namespaces Kubernetes lets you into.

    {!data ? ( ) : data.length === 0 ? (
    -

    No databases of yours here.

    -

    The catalog says which team acts on which database; ask the platform team to add yours.

    +

    No databases in namespaces you can see.

    +

    + Kubernetes knows you as {me.kubernetes.user} + {me.kubernetes.groups.length > 0 ? ( + <> + {" "} + in {me.kubernetes.groups.join(", ")} + + ) : ( + " in no groups" + )} + . Ask for access to your app's namespace. +

    ) : ( + - @@ -47,10 +56,16 @@ export function Databases({ env }: { env: Environment }) { {d.name} + - diff --git a/frontend/src/views/Users.tsx b/frontend/src/views/Users.tsx new file mode 100644 index 0000000..e614785 --- /dev/null +++ b/frontend/src/views/Users.tsx @@ -0,0 +1,52 @@ +import { api, type Environment } from "../api"; +import { Loading, useLoad } from "../components/ui"; + +export function Users({ env }: { env: Environment }) { + const { data, error } = useLoad(() => api.users(env.name), [env.name]); + + return ( + <> +
    +

    Database users in {env.name}

    +

    The roles that own the databases you see. Each one's password is in its Secret, next to the database cluster.

    +
    + {!data ? ( + + ) : data.length === 0 ? ( +
    +

    No database users in namespaces you can see.

    +
    + ) : ( +
    DatabaseNamespace OwnerTeams Status Copy
    {d.namespace} {d.owner || "—"}{d.teams.join(", ") || —} - {d.ready === null ? snapshots only : d.ready ? ready : not ready} + {d.ready ? ( + ready + ) : ( + + not ready + + )} {d.copy ? d.copy.name : —}
    + + + + + + + + + + {data.map((u) => ( + + + + + + + ))} + +
    RoleOwnsNamespacePassword Secret
    + {u.name} + {!u.login && no login} + + {u.databases.map((d) => ( +
    + {d} +
    + ))} +
    {u.namespaces.join(", ")}{u.secret || {u.managed ? "none" : "not a managed role"}}
    + )} + + ); +} diff --git a/src/databases_ui/__main__.py b/src/databases_ui/__main__.py index 6c5a4d4..eb77016 100644 --- a/src/databases_ui/__main__.py +++ b/src/databases_ui/__main__.py @@ -29,7 +29,8 @@ def check(path: Path) -> int: for problem in err.problems: print(problem, file=sys.stderr) return 1 - print(f"{len(catalog.environments)} environments, {len(catalog.teams)} teams, {len(catalog.grants)} databases granted: the catalog holds together.") + here = sorted(e.name for e in catalog.environments.values() if e.runs_jobs) + print(f"{len(catalog.environments)} environments, {', '.join(here)} in this cluster: the catalog holds together.") return 0 @@ -50,7 +51,11 @@ def serve() -> None: "credential": "workload identity" if cfg.federated_token_file else "client secret", "storage": "sas" if cfg.storage_sas else "entra", "environments": sorted(cfg.catalog.environments), - "teams": len(cfg.catalog.teams), + "storage_client": cfg.storage_client_id, + "namespace_label": cfg.namespace_label, + # Who the access reviews ask about, as the API server derives it from a token. + "kubernetes_user": f"{cfg.username_prefix}<{cfg.username_claim}>", + "kubernetes_groups": f"{cfg.groups_prefix}<{cfg.groups_claim}>", "job_image": cfg.job_image, } ) diff --git a/src/databases_ui/app.py b/src/databases_ui/app.py index a88eec4..d482ba0 100644 --- a/src/databases_ui/app.py +++ b/src/databases_ui/app.py @@ -1,7 +1,8 @@ """The web app: sign-in routes, the JSON API the frontend calls, and the built frontend itself. Writes need the session's CSRF token in X-CSRF-Token and this origin in Origin, on top of the -SameSite=Strict session cookie. What a person may see and do is decided in service.py. +SameSite=Strict session cookie. What a person may see and do is Kubernetes' answer, asked in +service.py for the user and groups the session carries. """ import hmac @@ -28,9 +29,9 @@ from pydantic import BaseModel, Field from .blob import BlobError, Container -from .catalog import DATABASE, Kubernetes +from .catalog import DATABASE from .config import Branding, Config -from .entra import AppToken, Entra, app_credential +from .entra import AppToken, Entra, app_credential, federated_credential from .kube import Kube, KubeError from .oidc import SignInError from .service import SNAPSHOT_ID, Actor, Console, ConsoleError @@ -106,6 +107,11 @@ class Restore(BaseModel): reason: str = Field(min_length=3, max_length=300) +class Share(BaseModel): + environment: str = Field(pattern=r"^[a-z0-9-]{1,32}$") + namespace: str = Field(pattern=r"^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$") + + class Reason(BaseModel): reason: str = Field(default="", max_length=300) @@ -115,16 +121,16 @@ def _log(event: str, **fields: Any) -> None: def build_console(cfg: Config, http: httpx.AsyncClient, *, kube_transport: httpx.AsyncBaseTransport | None = None, now=lambda: datetime.now(UTC)) -> Console: - """One Kubernetes client per environment that runs Jobs, and one container per environment.""" - token = None if cfg.storage_sas else AppToken(http, token_url=cfg.token_url, client_id=cfg.client_id, credential=lambda: app_credential(cfg)) - kube: dict[str, Kube] = {} - storage: dict[str, Container] = {} - for env in cfg.catalog.environments.values(): - storage[env.name] = Container(http, env.storage.url, token=token, sas=cfg.storage_sas) - if isinstance(env.kubernetes, Kubernetes): - kube[env.name] = Kube(server=env.kubernetes.server, token_file=env.kubernetes.token_file, ca_file=env.kubernetes.ca_file, transport=kube_transport) - elif env.kubernetes == "in-cluster": - kube[env.name] = Kube.in_cluster(transport=kube_transport) + """This cluster's API server for the environments that run here, and a container per environment.""" + token = None + if not cfg.storage_sas: + # A storage identity of its own trusts the same service-account token as the sign-in app. + own = cfg.storage_client_id not in ("", cfg.client_id) + credential = (lambda: federated_credential(str(cfg.federated_token_file))) if own else (lambda: app_credential(cfg)) + token = AppToken(http, token_url=cfg.token_url, client_id=cfg.storage_client_id or cfg.client_id, credential=credential) + here = Kube.in_cluster(transport=kube_transport) + kube = {env.name: here for env in cfg.catalog.environments.values() if env.runs_jobs} + storage = {env.name: Container(http, env.storage.url, token=token, sas=cfg.storage_sas) for env in cfg.catalog.environments.values()} return Console(cfg, kube, storage, now=now) @@ -212,10 +218,9 @@ def writable(request: Request, data: Session) -> dict[str, Any]: Writable = Annotated[dict[str, Any], Depends(writable)] def actor(data: dict[str, Any]) -> Actor: - roles = data.get("roles") or [] return Actor( - oid=str(data["oid"]), upn=str(data.get("upn", "")), name=str(data.get("name", "")), groups=frozenset(data.get("groups") or []), - admin=cfg.admin_role in roles, auditor=cfg.auditor_role in roles, + oid=str(data["oid"]), upn=str(data.get("upn", "")), name=str(data.get("name", "")), + user=str(data.get("user", "")), groups=tuple(str(g) for g in data.get("groups") or []), ) # fmt: skip # ── Sign-in ─────────────────────────────────────────────────────────────────────── @@ -262,10 +267,10 @@ async def callback(request: Request) -> Response: except SignInError as err: _log("sign-in failed", status=err.status, reason=str(err)) return _back(auth_error=str(err)) - data = {"oid": signed.oid, "upn": signed.upn, "name": signed.name, "roles": signed.roles, "groups": signed.groups, "csrf": secrets.token_urlsafe(32)} + data = {"oid": signed.oid, "upn": signed.upn, "name": signed.name, "user": signed.user, "groups": signed.groups, "csrf": secrets.token_urlsafe(32)} response = _back() cookies.write_session(request, response, data, cfg.session_seconds) - _log("signed in", user=signed.oid, upn=signed.upn, roles=signed.roles, groups=len(signed.groups)) + _log("signed in", oid=signed.oid, user=signed.user, groups=len(signed.groups)) return response @app.post("/auth/logout") @@ -286,11 +291,16 @@ async def me(data: Session) -> dict[str, Any]: "expires": data.get("exp"), "version": cfg.version, "release_notes": release_notes(cfg.version), - "admin": who.admin, - "auditor": who.auditor, - "teams": [{"id": t.id, "name": t.name} for t in cfg.catalog.teams_of(who.groups)], + "kubernetes": {"user": who.user, "groups": list(who.groups)}, "environments": [ - {"name": e.name, "production": e.production, "runs_jobs": e.runs_jobs, "clone_from": e.clone_from, "downloads": not e.production} + { + "name": e.name, + "production": e.production, + "runs_jobs": e.runs_jobs, + "clone_from": e.clone_from, + "shares_to": cfg.catalog.cloning_from(e.name), + "downloads": not e.production, + } for e in cfg.catalog.environments.values() ], } @@ -307,6 +317,18 @@ async def snapshots(env: EnvName, db: DbName, data: Session) -> dict[str, Any]: async def take_snapshot(env: EnvName, db: DbName, body: Note, data: Writable) -> dict[str, Any]: return await console.take_snapshot(actor(data), env, db, body.note.strip()) + @app.get("/api/environments/{env}/users") + async def users(env: EnvName, data: Session) -> dict[str, Any]: + return {"users": await console.users(actor(data), env)} + + @app.post("/api/environments/{env}/databases/{db}/snapshots/{sid}/share") + async def share(env: EnvName, db: DbName, sid: SnapshotId, body: Share, data: Writable) -> dict[str, Any]: + return await console.share(actor(data), env, db, sid, environment=body.environment, namespace=body.namespace) + + @app.get("/api/environments/{env}/databases/{db}/shared") + async def shared(env: EnvName, db: DbName, data: Session) -> dict[str, Any]: + return {"snapshots": await console.shared(actor(data), env, db)} + @app.post("/api/environments/{env}/databases/{db}/restore", status_code=201) async def restore(env: EnvName, db: DbName, body: Restore, data: Writable) -> dict[str, Any]: return await console.restore( diff --git a/src/databases_ui/blob.py b/src/databases_ui/blob.py index edbe62b..b3cffa9 100644 --- a/src/databases_ui/blob.py +++ b/src/databases_ui/blob.py @@ -106,6 +106,10 @@ async def properties(self, name: str) -> Blob | None: meta = {k[len("x-ms-meta-") :].lower(): unquote(v) for k, v in response.headers.items() if k.lower().startswith("x-ms-meta-")} return Blob(name=name, size=int(response.headers.get("content-length", "0")), created=response.headers.get("x-ms-creation-time", ""), metadata=meta) + async def set_metadata(self, name: str, metadata: dict[str, str]) -> None: + """Replace a blob's metadata, all of it.""" + await self._send("PUT", name, query={"comp": "metadata"}, headers={f"x-ms-meta-{k}": quote(v, safe="") for k, v in metadata.items()}) + async def upload(self, name: str, chunks: AsyncIterator[bytes], metadata: dict[str, str], before_commit: Callable[[], Awaitable[None]] | None = None) -> tuple[int, str]: """Write `chunks` to a block blob, committed with `metadata` once all are in and `before_commit` has not raised: its size and sha256.""" diff --git a/src/databases_ui/catalog.py b/src/databases_ui/catalog.py index 63efc6a..808adef 100644 --- a/src/databases_ui/catalog.py +++ b/src/databases_ui/catalog.py @@ -1,25 +1,24 @@ -"""The catalog: the environments this app reaches, and which team acts on which database. One -YAML file. +"""The catalog: the environments this app reaches. One YAML file. environments: - - name: dev + - name: dev # an environment in this app's own cluster cluster: dev # the CloudNativePG Cluster (default: the name) - namespace: database # its namespace: Database resources, Secrets and Jobs + namespace: database # its namespace: Database resources, role Secrets and Jobs storage: url: https://.blob.core.windows.net/dev-snapshots cloneFrom: [acc] # environments whose snapshots may be restored here + - name: acc + kubernetes: none # another cluster's: only snapshots shared with this one + storage: + url: https://.blob.core.windows.net/acc-snapshots - name: prd production: true # a restore waits for a second person; no downloads - ... - teams: - - id: payments - name: Payments - groups: [] - databases: - - name: payments # the Database resource's spec.name; {env} is the environment - workloads: [deployment/{env}-payments/api] # scaled to 0 for a restore in place - -Everything here is plain data with no I/O, so `check` validates the same file the server reads. + access: # what each action takes in the database's namespace + restore: {verb: create, group: rbac.authorization.k8s.io, resource: rolebindings} + +Who may act on a database is not here: it follows from Kubernetes RBAC in the namespace the +Database resource names in a label. Everything here is plain data with no I/O, so `check` +validates the same file the server reads. """ from __future__ import annotations @@ -42,8 +41,7 @@ NAME = r"^[a-z0-9]([a-z0-9-]{0,30}[a-z0-9])?$" # A database name that is also a valid label value; `_copy` must still fit in PostgreSQL's 63. DATABASE = r"^[a-z0-9]([a-z0-9_-]{0,56}[a-z0-9])?$" -_GUID = re.compile(r"^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$") -_WORKLOAD = re.compile(r"^(deployment|statefulset)/([a-z0-9{}][a-z0-9{}-]{0,62})/([a-z0-9{}][a-z0-9.{}-]{0,252})$") +NAMESPACE = r"^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$" # Plain http only for an emulator inside the cluster or on this machine. _LOCAL = re.compile(r"^(localhost|127\.0\.0\.1|\[::1\]|[a-z0-9.-]+\.svc(\.cluster\.local)?)$") # DevSkim: ignore DS162092 - plain http is allowed only for a local emulator @@ -76,23 +74,38 @@ def _url(cls, value: str) -> str: return value.rstrip("/") -class Kubernetes(_Model): - """Another cluster's API server, with a CA and a token file read on every call.""" +class Check(_Model): + """A Kubernetes permission in the database's namespace, asked as a SubjectAccessReview.""" + + verb: str = Field(pattern=r"^[a-z]+$") + resource: str = Field(pattern=r"^[a-z0-9-]+(/[a-z]+)?$") + group: str = Field(default="", pattern=r"^$|^[a-z0-9.-]+$") + + +# See a namespace's databases with `view`; snapshot and restore with `edit`; restore production +# with `admin`. Snapshots carry all the data, so they take what reading Secrets takes. +READ = Check(verb="list", resource="pods") +SNAPSHOT = Check(verb="get", resource="secrets") +RESTORE = Check(verb="get", resource="secrets") +RESTORE_PRODUCTION = Check(verb="create", resource="rolebindings", group="rbac.authorization.k8s.io") - server: str = Field(pattern=r"^https://\S+$") - ca_file: str = Field(alias="caFile", min_length=1) - token_file: str = Field(alias="tokenFile", min_length=1) + +class Access(_Model): + read: Check | None = None + snapshot: Check | None = None + restore: Check | None = None class Environment(_Model): name: str = Field(pattern=NAME) production: bool = False cluster: str = Field(default="", pattern=r"^$|^[a-z0-9]([a-z0-9-]{0,48}[a-z0-9])?$") - namespace: str = Field(default="database", pattern=r"^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$") - # in-cluster: this app's own cluster. none: snapshots only, to clone from; nothing runs there. - kubernetes: Literal["in-cluster", "none"] | Kubernetes = "in-cluster" + namespace: str = Field(default="database", pattern=NAMESPACE) + # in-cluster: this app's own cluster. none: another cluster's, whose snapshots are shared here. + kubernetes: Literal["in-cluster", "none"] = "in-cluster" storage: Storage clone_from: list[str] = Field(default_factory=list, alias="cloneFrom") + access: Access = Field(default_factory=Access) @property def cnpg_cluster(self) -> str: @@ -102,42 +115,15 @@ def cnpg_cluster(self) -> str: def runs_jobs(self) -> bool: return self.kubernetes != "none" - -class DatabaseRef(_Model): - name: str = Field(min_length=1, max_length=63) - # Empty: every environment. - environments: list[str] = Field(default_factory=list) - workloads: list[str] = Field(default_factory=list) - - @field_validator("workloads") - @classmethod - def _workloads(cls, values: list[str]) -> list[str]: - for value in values: - if not _WORKLOAD.match(value): - raise ValueError(f"{value!r} is not deployment// or statefulset//") - return values - - -class Team(_Model): - id: str = Field(pattern=NAME) - name: str = Field(min_length=1, max_length=120) - description: str = Field(default="", max_length=2000) - # Entra ID group object ids; their members act on the team's databases. - groups: list[str] = Field(min_length=1) - databases: list[DatabaseRef] = Field(default_factory=list) - - @field_validator("groups") - @classmethod - def _groups(cls, values: list[str]) -> list[str]: - for value in values: - if not _GUID.match(value.lower()): - raise ValueError(f"{value!r} is not a group object id (a GUID)") - return [v.lower() for v in values] + def check(self, action: Literal["read", "snapshot", "restore"]) -> Check: + found = getattr(self.access, action) + if found is not None: + return found + return {"read": READ, "snapshot": SNAPSHOT, "restore": RESTORE_PRODUCTION if self.production else RESTORE}[action] class _File(_Model): environments: list[Environment] = Field(min_length=1) - teams: list[Team] = Field(default_factory=list) @model_validator(mode="after") def _references(self) -> _File: @@ -147,58 +133,20 @@ def _references(self) -> _File: problems += [f"environment {env.name!r} clones from unknown environment {s!r}" for s in env.clone_from if s not in names] if env.name in env.clone_from: problems.append(f"environment {env.name!r} lists itself in cloneFrom") - ids = [t.id for t in self.teams] - problems += [f"team {i!r} is listed twice" for i in sorted({i for i in ids if ids.count(i) > 1})] - for team in self.teams: - for ref in team.databases: - problems += [f"team {team.id!r} names unknown environment {e!r}" for e in ref.environments if e not in names] - for env in ref.environments or names: - if not re.match(DATABASE, ref.name.replace("{env}", env)): - problems.append(f"team {team.id!r}: {ref.name.replace('{env}', env)!r} is not a database name this app takes (a-z, 0-9, _ and -, at most 58)") + if not any(e.runs_jobs for e in self.environments): + problems.append("no environment runs here: at least one has kubernetes: in-cluster") if problems: raise ValueError("; ".join(problems)) return self -@dataclass(frozen=True) -class Grant: - """A database a team acts on in one environment.""" - - team: str - environment: str - database: str - workloads: tuple[tuple[str, str, str], ...] - - @dataclass(frozen=True) class Catalog: environments: dict[str, Environment] - teams: dict[str, Team] - grants: tuple[Grant, ...] - - @property - def groups(self) -> frozenset[str]: - """Every group the catalog names: the only ones a session needs to carry.""" - return frozenset(g for t in self.teams.values() for g in t.groups) - - def teams_of(self, groups: frozenset[str]) -> list[Team]: - return [t for t in self.teams.values() if groups & set(t.groups)] - - def grant(self, team_ids: set[str], environment: str, database: str) -> Grant | None: - return next((g for g in self.grants if g.team in team_ids and g.environment == environment and g.database == database), None) - - def databases(self, environment: str, team_ids: set[str] | None = None) -> dict[str, Grant]: - """The databases of `environment` the catalog names, for these teams or for any.""" - found: dict[str, Grant] = {} - for g in self.grants: - if g.environment == environment and (team_ids is None or g.team in team_ids): - found.setdefault(g.database, g) - return found - -def _workload(value: str, env: str) -> tuple[str, str, str]: - kind, namespace, name = value.replace("{env}", env).split("/") - return kind, namespace, name + def cloning_from(self, source: str) -> list[str]: + """The environments that take `source`'s snapshots.""" + return [e.name for e in self.environments.values() if source in e.clone_from] def load_catalog(text: str, source: str = "catalog") -> Catalog: @@ -214,11 +162,4 @@ def load_catalog(text: str, source: str = "catalog") -> Catalog: where = ".".join(str(p) for p in e.get("loc", ())) problems.append(f"{source}: {where + ': ' if where else ''}{e.get('msg', '')}".replace("Value error, ", "")) raise CatalogError(problems) from err - names = [e.name for e in parsed.environments] - grants = tuple( - Grant(team.id, env, ref.name.replace("{env}", env), tuple(_workload(w, env) for w in ref.workloads)) - for team in parsed.teams - for ref in team.databases - for env in (ref.environments or names) - ) - return Catalog(environments={e.name: e for e in parsed.environments}, teams={t.id: t for t in parsed.teams}, grants=grants) + return Catalog(environments={e.name: e for e in parsed.environments}) diff --git a/src/databases_ui/config.py b/src/databases_ui/config.py index 2ce602d..44dace1 100644 --- a/src/databases_ui/config.py +++ b/src/databases_ui/config.py @@ -17,7 +17,10 @@ _GUID = re.compile(r"^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$") _HOST = re.compile(r"^[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)+$") _COLOUR = re.compile(r"^#[0-9a-fA-F]{6}$") -_ROLE = re.compile(r"^[A-Za-z0-9._-]{1,120}$") +_CLAIM = re.compile(r"^[A-Za-z0-9_.:-]{1,64}$") +_PREFIX = re.compile(r"^[A-Za-z0-9_.:@/#-]{0,64}$") +# A label key: an optional DNS-subdomain prefix and a name, as Kubernetes takes them. +_LABEL_KEY = re.compile(r"^([a-z0-9]([a-z0-9.-]{0,251}[a-z0-9])?/)?[A-Za-z0-9]([A-Za-z0-9_.-]{0,61}[A-Za-z0-9])?$") _K8S_NAME = re.compile(r"^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$") _SECRET_REF = re.compile(r"^[a-z0-9]([a-z0-9.-]{0,251}[a-z0-9])?/[A-Za-z0-9._-]{1,253}$") _LOOPBACK = {"localhost", "127.0.0.1", "::1"} # DevSkim: ignore DS162092 - plain http is allowed on loopback, for local development @@ -55,8 +58,17 @@ class Config: # the Secret that holds the same token in each environment's namespace, for the Jobs. storage_sas: str = "" storage_sas_secret: str = "" - admin_role: str = "Admin" - auditor_role: str = "Auditor" + # The identity that reaches storage, for this server and the Jobs: the sign-in app's own, or a + # separate one that trusts the same service-account tokens. + storage_client_id: str = "" + # The label on a Database resource that names the namespace whose people may act on it. + namespace_label: str = "databases-ui/namespace" + # How the cluster's API server names a person from their Entra ID token: these must match its + # authentication configuration, or the access reviews ask about someone else. + username_claim: str = "preferred_username" + username_prefix: str = "oidc:" + groups_claim: str = "groups" + groups_prefix: str = "oidc:" static_dir: Path | None = None port: int = 8080 version: str = "dev" @@ -156,12 +168,21 @@ def load_config(env: dict[str, str] | None = None) -> Config: # A Job can't use the client secret: workload identity is how it reaches storage. raise ConfigError("the Jobs reach storage through workload identity (AZURE_FEDERATED_TOKEN_FILE) or a SAS (DATABASES_UI_STORAGE_SAS)") - roles = {} - for key, default in (("admin", "Admin"), ("auditor", "Auditor")): - name = f"DATABASES_UI_{key.upper()}_ROLE" - roles[f"{key}_role"] = env.get(name, default).strip() - if not _ROLE.match(roles[f"{key}_role"]): - raise ConfigError(f"{name} must be an app role value, such as {default}") + client_id = _guid(env, "AZURE_CLIENT_ID") + storage_client_id = _guid(env, "DATABASES_UI_STORAGE_CLIENT_ID") if env.get("DATABASES_UI_STORAGE_CLIENT_ID", "").strip() else client_id + + label = env.get("DATABASES_UI_NAMESPACE_LABEL", "databases-ui/namespace").strip() + if not _LABEL_KEY.match(label): + raise ConfigError("DATABASES_UI_NAMESPACE_LABEL must be a label key, such as databases-ui/namespace") + mapping = {} + for key, default in (("username_claim", "preferred_username"), ("groups_claim", "groups")): + mapping[key] = env.get(f"DATABASES_UI_{key.upper()}", default).strip() + if not _CLAIM.match(mapping[key]): + raise ConfigError(f"DATABASES_UI_{key.upper()} must be a claim name, such as {default}") + for key in ("username_prefix", "groups_prefix"): + mapping[key] = env.get(f"DATABASES_UI_{key.upper()}", "oidc:").strip() + if not _PREFIX.match(mapping[key]): + raise ConfigError(f"DATABASES_UI_{key.upper()} must be a prefix such as oidc:, or empty") try: hours = int(env.get("DATABASES_UI_SESSION_HOURS", "8")) @@ -184,7 +205,9 @@ def load_config(env: dict[str, str] | None = None) -> Config: return Config( tenant_id=_guid(env, "AZURE_TENANT_ID"), - client_id=_guid(env, "AZURE_CLIENT_ID"), + client_id=client_id, + storage_client_id=storage_client_id, + namespace_label=label, authority=_authority(env.get("AZURE_AUTHORITY_HOST", "")), federated_token_file=Path(token_file) if token_file else None, client_secret=secret or None, @@ -200,5 +223,5 @@ def load_config(env: dict[str, str] | None = None) -> Config: port=port, version=env.get("APP_VERSION", "dev"), branding=Branding(**colours), - **roles, + **mapping, ) diff --git a/src/databases_ui/entra.py b/src/databases_ui/entra.py index b5acfb4..a13ba6c 100644 --- a/src/databases_ui/entra.py +++ b/src/databases_ui/entra.py @@ -2,8 +2,9 @@ app's own token for Azure Storage. The credential is a workload identity token (AZURE_FEDERATED_TOKEN_FILE, which Entra trusts -through a federated credential on the app registration) or a client secret. The sign-in asks -only who the person is: their app roles (Admin, Auditor) and their groups come in the ID token. +through a federated credential on the app registration) or a client secret. People sign in to the +app registration the cluster's API server trusts, so their ID token names them the way Kubernetes +does: the user and groups claims, with the API server's prefixes, are what access reviews ask about. """ from __future__ import annotations @@ -89,19 +90,23 @@ def _credential(self) -> dict[str, str]: return app_credential(self._cfg) def _check_claims(self, claims: dict[str, Any]) -> None: - if str(claims.get("tid", "")).lower() != self._cfg.tenant_id or not claims.get("oid"): + cfg = self._cfg + if str(claims.get("tid", "")).lower() != cfg.tenant_id or not claims.get("oid"): raise SignInError("that account belongs to another tenant", status=401) + if not isinstance(claims.get(cfg.username_claim), str) or not claims[cfg.username_claim]: + raise SignInError(f"the ID token has no {cfg.username_claim}, which is how Kubernetes names you", status=401) # Over 200 groups, Entra leaves them out and points at Graph instead. - if "groups" in (claims.get("_claim_names") or {}) or claims.get("hasgroups"): - raise SignInError("your groups do not fit in the ID token; the app registration should emit only the groups assigned to the application", status=401) + if cfg.groups_claim in (claims.get("_claim_names") or {}): + raise SignInError(f"your {cfg.groups_claim} do not fit in the ID token, so Kubernetes would not know them either", status=401) async def _sign_in(self, body: dict[str, Any], claims: dict[str, Any]) -> SignIn: - named = self._cfg.catalog.groups + cfg = self._cfg + found = claims.get(cfg.groups_claim) or [] return SignIn( oid=str(claims["oid"]).lower(), - upn=str(claims.get("preferred_username") or claims.get("upn") or claims["oid"]).lower()[:120], + upn=str(claims.get("preferred_username") or claims.get("upn") or claims["oid"])[:120], name=str(claims.get("name") or "")[:120], - roles=[r for r in claims.get("roles") or [] if isinstance(r, str)], - # Only the groups the catalog names, so the session cookie stays small. - groups=sorted({g.lower() for g in claims.get("groups") or [] if isinstance(g, str)} & named), + # As the API server takes them: the claim as it is, with its prefix. + user=f"{cfg.username_prefix}{claims[cfg.username_claim]}", + groups=[f"{cfg.groups_prefix}{g}" for g in (found if isinstance(found, list) else [found]) if isinstance(g, str)][:200], ) diff --git a/src/databases_ui/jobs.py b/src/databases_ui/jobs.py index 650e6ba..ae53513 100644 --- a/src/databases_ui/jobs.py +++ b/src/databases_ui/jobs.py @@ -36,6 +36,8 @@ class Target: password_secret: str ca_secret: str host: str + # The app's namespace, whose people may act on the database. + namespace: str def name_for(action: str) -> str: @@ -52,7 +54,7 @@ def _storage_env(cfg: Config) -> list[dict[str, Any]]: return [{"name": "DBUI_STORAGE_SAS", "valueFrom": {"secretKeyRef": {"name": secret, "key": key}}}] return [ {"name": "AZURE_TENANT_ID", "value": cfg.tenant_id}, - {"name": "AZURE_CLIENT_ID", "value": cfg.client_id}, + {"name": "AZURE_CLIENT_ID", "value": cfg.storage_client_id or cfg.client_id}, {"name": "AZURE_AUTHORITY_HOST", "value": cfg.authority}, {"name": "AZURE_FEDERATED_TOKEN_FILE", "value": f"{TOKEN_DIR}/azure-identity-token"}, ] @@ -76,12 +78,13 @@ def build( wait_for_database: bool = False, ) -> dict[str, Any]: """The Job for one action. `database` is the catalog's name, `target.database` the one written to.""" - labels = {MANAGED_BY: APP, f"{PREFIX}environment": env.name, f"{PREFIX}database": database, f"{PREFIX}action": action} + labels = {MANAGED_BY: APP, f"{PREFIX}environment": env.name, f"{PREFIX}database": database, f"{PREFIX}namespace": target.namespace, f"{PREFIX}action": action} variables: list[dict[str, Any]] = [ {"name": "DBUI_ACTION", "value": action}, {"name": "DBUI_JOB", "value": name}, {"name": "DBUI_ENVIRONMENT", "value": env.name}, {"name": "DBUI_DATABASE", "value": database}, + {"name": "DBUI_NAMESPACE", "value": target.namespace}, {"name": "DBUI_REQUESTED_BY", "value": requested_by}, {"name": "DBUI_BLOB_URL", "value": blob_url}, {"name": "DBUI_BLOB", "value": blob}, diff --git a/src/databases_ui/oidc.py b/src/databases_ui/oidc.py index 3369cff..756d0ac 100644 --- a/src/databases_ui/oidc.py +++ b/src/databases_ui/oidc.py @@ -1,8 +1,8 @@ """Signing in with OpenID Connect: authorization code flow with PKCE, as a confidential client. What differs between identity providers lives in a subclass: the endpoints, the app's own -credential, which claims have to hold, and where a person's roles and groups come from. Entra ID -is in entra.py. Signing in needs only the ID token. +credential, which claims have to hold, and who the person is to Kubernetes. Entra ID is in +entra.py. Signing in needs only the ID token. The ID token is verified against the provider's published keys although it arrives straight from the token endpoint over TLS (OIDC Core 3.1.3.7 would allow skipping that): issuer, @@ -37,7 +37,9 @@ class SignIn: oid: str upn: str name: str - roles: list[str] + # Who Kubernetes takes this person for: the user and groups its API server derives from the + # same ID token. + user: str groups: list[str] diff --git a/src/databases_ui/runner.py b/src/databases_ui/runner.py index 4a63958..3830b15 100644 --- a/src/databases_ui/runner.py +++ b/src/databases_ui/runner.py @@ -3,9 +3,10 @@ snapshot pg_dump in the custom format, streamed into a block blob that is committed, with who asked and why as its metadata, only once pg_dump has succeeded. -restore the snapshot streamed into pg_restore in one transaction, so on any error nothing - changes. In place, the workloads that use the database go to 0 replicas first and back - to what they had afterwards; for a copy, it first waits for the database to exist. +restore in one transaction, everything the owner role owns is dropped and the snapshot's + script, from pg_restore, runs: the database ends up as it was when the snapshot was + taken, or on any error as it was before. In place, the workloads that use it go to 0 + replicas first and back afterwards; for a copy, it first waits for the database. Nothing goes through `kubectl exec` or a disk. The outcome goes to the pod's termination message, which the server shows, and to the environment's audit log. @@ -14,6 +15,7 @@ from __future__ import annotations import asyncio +import contextlib import json import logging import os @@ -152,6 +154,64 @@ async def scale_up(kube: Kube, scaled: list[tuple[str, int]]) -> None: _say("could not scale back", workload=path, replicas=replicas, reason=str(err)) +def _stop(*procs: asyncio.subprocess.Process) -> None: + for proc in procs: + with contextlib.suppress(ProcessLookupError): + proc.kill() + + +async def apply(chunks: AsyncIterator[bytes], database: str) -> None: + """The snapshot into `database` in one transaction: everything the owner role owns is dropped, + then pg_restore's script runs, and COMMIT follows only once pg_restore has succeeded. On any + error psql stops, its connection closes and PostgreSQL rolls the lot back.""" + run = await asyncio.create_subprocess_exec( + "psql", "--no-password", "--no-psqlrc", "--quiet", "-v", "ON_ERROR_STOP=1", f"--dbname={database}", "--file=-", + stdin=subprocess.PIPE, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE, + ) # fmt: skip + script = await asyncio.create_subprocess_exec( + "pg_restore", "--format=custom", "--clean", "--if-exists", "--no-owner", "--no-acl", "--file=-", + stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, + ) # fmt: skip + if run.stdin is None or run.stderr is None or script.stdin is None or script.stdout is None or script.stderr is None: + raise JobFailed("psql or pg_restore started without its pipes") + run_errors, script_errors = asyncio.create_task(run.stderr.read()), asyncio.create_task(script.stderr.read()) + to_psql, to_restore, from_restore = run.stdin, script.stdin, script.stdout + + async def feed() -> None: + try: + async for chunk in chunks: + to_restore.write(chunk) + await to_restore.drain() + to_restore.close() + except (BrokenPipeError, ConnectionResetError): + pass # pg_restore stopped reading; its exit status says why + except BaseException: + # The download broke off: psql goes before it sees COMMIT, so nothing changes. + _stop(run, script) + raise + + async def relay() -> None: + try: + to_psql.write(b"BEGIN;\nDROP OWNED BY CURRENT_USER;\n") + while data := await from_restore.read(READ): + to_psql.write(data) + await to_psql.drain() + if await script.wait() == 0: + to_psql.write(b"\nCOMMIT;\n") + await to_psql.drain() + to_psql.close() + except (BrokenPipeError, ConnectionResetError): + # psql stopped on an error: pg_restore must not block on a full pipe. + _stop(script) + + await asyncio.gather(feed(), relay()) + if await script.wait() != 0: + await run.wait() + raise JobFailed(f"pg_restore exited {script.returncode}, nothing changed: {_tail(await script_errors)}") + if await run.wait() != 0: + raise JobFailed(f"the restore failed, nothing changed: {_tail(await run_errors)}") + + async def restore(env: Mapping[str, str], container: Container, kube: Kube | None) -> dict[str, Any]: await wait_for_database(WAIT_SECONDS if env.get("DBUI_WAIT_FOR_DATABASE") else REACH_SECONDS) scaled: list[tuple[str, int]] = [] @@ -161,27 +221,7 @@ async def restore(env: Mapping[str, str], container: Container, kube: Kube | Non ended = await psql("select count(pg_terminate_backend(pid)) from pg_stat_activity where datname = current_database() and pid <> pg_backend_pid() and usename = current_user") _say("sessions ended", count=ended) async with container.download(env["DBUI_BLOB"]) as (size, chunks): - proc = await _exec( - "pg_restore", "--format=custom", "--clean", "--if-exists", "--no-owner", "--no-acl", "--single-transaction", "--no-password", - f"--dbname={env['PGDATABASE']}", stdin=subprocess.PIPE, - ) # fmt: skip - stdin, stderr = proc.stdin, proc.stderr - if stdin is None or stderr is None: - raise JobFailed("pg_restore started without its pipes") - errors = asyncio.create_task(stderr.read()) - fed = 0 - try: - async for chunk in chunks: - stdin.write(chunk) - await stdin.drain() - fed += len(chunk) - stdin.close() - except (BrokenPipeError, ConnectionResetError): - pass # pg_restore stopped reading; its exit status says why - if await proc.wait() != 0: - raise JobFailed(f"pg_restore exited {proc.returncode}, nothing changed: {_tail(await errors)}") - if fed != size: - raise JobFailed(f"read {fed} of {size} bytes of the snapshot") + await apply(chunks, env["PGDATABASE"]) finally: if kube is not None: await scale_up(kube, scaled) @@ -212,7 +252,8 @@ async def run(env: Mapping[str, str], *, transport: httpx.AsyncBaseTransport | N # The environment's own container, which for a clone is not the snapshot's. await audit.record( _container(env, env["DBUI_AUDIT_URL"], http), environment=env.get("DBUI_ENVIRONMENT", ""), actor=env.get("DBUI_REQUESTED_BY", ""), action=f"{action}.{outcome['result']}", - database=env.get("DBUI_DATABASE", ""), job=env.get("DBUI_JOB", ""), snapshot=env.get("DBUI_BLOB", ""), detail=outcome.get("reason", ""), + database=env.get("DBUI_DATABASE", ""), namespace=env.get("DBUI_NAMESPACE", ""), job=env.get("DBUI_JOB", ""), snapshot=env.get("DBUI_BLOB", ""), + detail=outcome.get("reason", ""), ) # fmt: skip except (SignInError, KeyError) as err: _say("audit write failed", reason=str(err)) diff --git a/src/databases_ui/service.py b/src/databases_ui/service.py index 5731658..f6070c3 100644 --- a/src/databases_ui/service.py +++ b/src/databases_ui/service.py @@ -1,31 +1,42 @@ -"""What people may do, and doing it: an environment's databases, their snapshots, and the Jobs -that take, restore and clone them. - -Who acts on which database comes from the catalog's teams and the person's groups, checked here -on every call; the browser only shows what this server decided. App role Admin acts on every -database, Auditor reads everything and changes nothing. In a production environment a restore -waits for a second person, and nobody downloads a snapshot. +"""What people may do, and doing it: an environment's databases and their owners, snapshots, and +the Jobs that take, restore and clone them. + +Who may act on a database is Kubernetes' answer. A Database resource names, in a label, the +namespace of the app it belongs to (without one, its own namespace: the platform's); the server +asks the API server, with a SubjectAccessReview, whether the signed-in person may do there what +the action takes (catalog.py: `view` to see, `edit` to snapshot and restore, `admin` to restore +production). Answers are kept for a minute. In a production environment a restore also waits for +a second person, and nobody downloads a snapshot. + +Another environment's snapshot reaches this one only when someone who may snapshot it there shares +it with a namespace here; whoever may restore in that namespace can then clone it. """ from __future__ import annotations +import asyncio import re import secrets -from collections.abc import Callable +import time +from collections.abc import Callable, Iterable from dataclasses import dataclass from datetime import UTC, datetime, timedelta -from typing import Any +from typing import Any, Literal from . import audit, jobs from .blob import Container -from .catalog import DATABASE, Environment, Grant +from .catalog import DATABASE, NAMESPACE, Environment from .config import Config from .kube import CNPG, Kube APPROVAL_HOURS = 24 +REVIEW_SECONDS = 60 SNAPSHOT_ID = r"^[0-9]{8}T[0-9]{6}Z-[0-9a-f]{6}$" +WORKLOADS = f"{jobs.PREFIX}workloads" +_WORKLOAD = re.compile(r"^(deployment|statefulset)/([a-z0-9]([a-z0-9.-]{0,251}[a-z0-9])?)$") _ACTIVE = ("waiting", "starting", "running") _COPY = "_copy" +Action = Literal["read", "snapshot", "restore"] class ConsoleError(Exception): @@ -40,9 +51,9 @@ class Actor: oid: str upn: str name: str - groups: frozenset[str] - admin: bool = False - auditor: bool = False + # Who Kubernetes takes them for. + user: str + groups: tuple[str, ...] def snapshot_blob(database: str, snapshot: str) -> str: @@ -60,6 +71,10 @@ def _when(value: str) -> datetime | None: return None +def _shares(metadata: dict[str, str]) -> list[str]: + return sorted(set(metadata.get("sharedwith", "").split())) + + class Console: def __init__(self, cfg: Config, kube: dict[str, Kube], storage: dict[str, Container], now: Callable[[], datetime] = lambda: datetime.now(UTC)): self.cfg = cfg @@ -67,6 +82,7 @@ def __init__(self, cfg: Config, kube: dict[str, Kube], storage: dict[str, Contai self._kube = kube self._storage = storage self._now = now + self._reviews: dict[tuple[Any, ...], tuple[bool, float]] = {} # ── Who may do what ───────────────────────────────────────────────────────────── @@ -76,100 +92,198 @@ def environment(self, name: str) -> Environment: raise ConsoleError(404, "unknown_environment", f"There is no environment {name!r}.") return env - def teams(self, actor: Actor) -> set[str]: - return {t.id for t in self.catalog.teams_of(actor.groups)} - - def grant(self, actor: Actor, env: str, database: str) -> Grant | None: - return self.catalog.grant(self.teams(actor), env, database) - - def may_read(self, actor: Actor, env: str, database: str) -> bool: - return actor.admin or actor.auditor or self.grant(actor, env, database) is not None - - def may_act(self, actor: Actor, env: str, database: str) -> bool: - return actor.admin or self.grant(actor, env, database) is not None - - def _require(self, allowed: bool) -> None: - if not allowed: - raise ConsoleError(403, "not_allowed", "You may not do that with this database.") - def _kube_for(self, env: Environment) -> Kube: kube = self._kube.get(env.name) if kube is None: - raise ConsoleError(409, "no_jobs_here", f"This app only reads {env.name}'s snapshots; nothing runs there.") + raise ConsoleError(409, "no_jobs_here", f"{env.name} is another cluster's: only snapshots shared from it are read here.") return kube - # ── Databases ─────────────────────────────────────────────────────────────────── + def namespace_of(self, env: Environment, resource: dict[str, Any]) -> str: + found = ((resource.get("metadata") or {}).get("labels") or {}).get(self.cfg.namespace_label, "") + return found if re.match(NAMESPACE, found) else env.namespace + + async def allowed(self, actor: Actor, env: Environment, namespace: str, action: Action) -> bool: + """Whether Kubernetes lets this person do what `action` takes in `namespace`.""" + check = env.check(action) + key = (env.name, actor.user, actor.groups, namespace, check) + now = time.monotonic() + if (hit := self._reviews.get(key)) is not None and hit[1] > now: + return hit[0] + resource, _, subresource = check.resource.partition("/") + review = await self._kube_for(env).create( + "/apis/authorization.k8s.io/v1/subjectaccessreviews", + { + "apiVersion": "authorization.k8s.io/v1", + "kind": "SubjectAccessReview", + "spec": { + "user": actor.user, + # As the API server would: every person it authenticates is in this group too. + "groups": [*actor.groups, "system:authenticated"], + "resourceAttributes": {"namespace": namespace, "verb": check.verb, "group": check.group, "resource": resource, "subresource": subresource}, + }, + }, + ) + answer = bool((review.get("status") or {}).get("allowed")) + if len(self._reviews) > 10_000: + self._reviews.clear() + self._reviews[key] = (answer, now + REVIEW_SECONDS) + return answer + + async def _answers(self, actor: Actor, env: Environment, namespaces: Iterable[str], action: Action) -> dict[str, bool]: + found = sorted(set(namespaces)) + return dict(zip(found, await asyncio.gather(*(self.allowed(actor, env, ns, action) for ns in found)), strict=True)) + + async def _require(self, actor: Actor, env: Environment, namespace: str, action: Action) -> None: + if not await self.allowed(actor, env, namespace, action): + check = env.check(action) + what = f"{check.verb} {check.resource}" + (f".{check.group}" if check.group else "") + raise ConsoleError(403, "not_allowed", f"That takes {what} in the namespace {namespace}, which Kubernetes does not give you.") + + # ── Databases and their owners ─────────────────────────────────────────────────── + + def _check_name(self, database: str) -> None: + if not re.match(DATABASE, database): + raise ConsoleError(404, "unknown_database", "That is not a database name this app takes.") async def _resources(self, env: Environment) -> list[dict[str, Any]]: found = await self._kube_for(env).list(f"{CNPG}/namespaces/{env.namespace}/databases") return [d for d in found if ((d.get("spec") or {}).get("cluster") or {}).get("name") == env.cnpg_cluster and (d.get("spec") or {}).get("ensure") != "absent"] + def _copy_of(self, resource: dict[str, Any]) -> str: + return ((resource.get("metadata") or {}).get("labels") or {}).get(f"{jobs.PREFIX}copy-of", "") + async def _resource(self, env: Environment, database: str) -> dict[str, Any]: - found = next((d for d in await self._resources(env) if d["spec"].get("name") == database), None) + self._check_name(database) + found = next((d for d in await self._resources(env) if d["spec"].get("name") == database and not self._copy_of(d)), None) if found is None: raise ConsoleError(404, "unknown_database", f"{env.name} has no database {database!r}.") return found + async def _database(self, actor: Actor, env: Environment, database: str) -> tuple[dict[str, Any], str]: + """A database and its namespace, if this person may see it: to anyone else it does not exist.""" + resource = await self._resource(env, database) + namespace = self.namespace_of(env, resource) + if not await self.allowed(actor, env, namespace, "read"): + raise ConsoleError(404, "unknown_database", f"{env.name} has no database {database!r}.") + return resource, namespace + + async def _cluster(self, env: Environment) -> dict[str, Any]: + cluster = await self._kube_for(env).get(f"{CNPG}/namespaces/{env.namespace}/clusters/{env.cnpg_cluster}") + if cluster is None: + raise ConsoleError(409, "no_cluster", f"There is no Cluster {env.cnpg_cluster} in {env.namespace}.") + return cluster + + def _roles(self, cluster: dict[str, Any]) -> dict[str, dict[str, Any]]: + return {r["name"]: r for r in ((cluster.get("spec") or {}).get("managed") or {}).get("roles") or [] if r.get("name")} + + def workloads(self, resource: dict[str, Any], namespace: str) -> tuple[tuple[str, str, str], ...]: + """What a restore in place scales to 0: the Database resource's databases-ui/workloads + annotation, `deployment/,statefulset/` in the app's namespace.""" + text = ((resource.get("metadata") or {}).get("annotations") or {}).get(WORKLOADS, "") + found = [] + for item in filter(None, (part.strip() for part in text.split(","))): + if not (m := _WORKLOAD.match(item)): + raise ConsoleError(409, "bad_workloads", f"The annotation {WORKLOADS} names {item!r}; it takes deployment/ or statefulset/.") + found.append((m.group(1), namespace, m.group(2))) + return tuple(found) + async def databases(self, actor: Actor, name: str) -> list[dict[str, Any]]: env = self.environment(name) - granted = self.catalog.databases(env.name, self.teams(actor)) - everything = actor.admin or actor.auditor if not env.runs_jobs: - listed = self.catalog.databases(env.name) if everything else granted - return [self._database_json(actor, env, db, None, None) for db in sorted(listed)] + return [] resources = await self._resources(env) - copies = {(d.get("metadata") or {}).get("labels", {}).get(f"{jobs.PREFIX}copy-of"): d for d in resources} + own = {d["spec"].get("name", ""): d for d in resources if not self._copy_of(d)} + copies = {self._copy_of(d): d for d in resources if self._copy_of(d)} + spaces = {db: self.namespace_of(env, d) for db, d in own.items()} + seen = await self._answers(actor, env, spaces.values(), "read") + visible = [db for db in sorted(own) if seen[spaces[db]]] + snapshot = await self._answers(actor, env, (spaces[db] for db in visible), "snapshot") + restore = await self._answers(actor, env, (spaces[db] for db in visible), "restore") + roles = self._roles(await self._cluster(env)) if visible else {} out = [] - for d in sorted(resources, key=lambda d: d["spec"].get("name", "")): - db = d["spec"].get("name", "") - if d["metadata"].get("labels", {}).get(f"{jobs.PREFIX}copy-of") or not (everything or db in granted): - continue - out.append(self._database_json(actor, env, db, d, copies.get(db))) + for db in visible: + d, ns = own[db], spaces[db] + copy = copies.get(db) + try: + workloads = [f"{kind}/{wname}" for kind, _, wname in self.workloads(d, ns)] + except ConsoleError: + workloads = [] + owner = d["spec"].get("owner", "") + out.append( + { + "name": db, + "namespace": ns, + "owner": owner, + "owner_secret": ((roles.get(owner) or {}).get("passwordSecret") or {}).get("name", ""), + "ready": bool((d.get("status") or {}).get("applied")), + "message": (d.get("status") or {}).get("message", ""), + "workloads": workloads, + "copy": None if copy is None else {"name": copy["spec"].get("name", ""), "ready": bool((copy.get("status") or {}).get("applied"))}, + "can_snapshot": snapshot[ns], + "can_restore": restore[ns], + } + ) return out - def _database_json(self, actor: Actor, env: Environment, db: str, resource: dict[str, Any] | None, copy: dict[str, Any] | None) -> dict[str, Any]: - grants = [g for g in self.catalog.grants if g.environment == env.name and g.database == db] - status = (resource or {}).get("status") or {} - return { - "name": db, - "owner": ((resource or {}).get("spec") or {}).get("owner", ""), - "ready": bool(status.get("applied")) if resource else None, - "message": status.get("message", ""), - "teams": sorted({g.team for g in grants}), - "workloads": sorted({"/".join(w) for g in grants for w in g.workloads}), - "copy": None if copy is None else {"name": copy["spec"].get("name", ""), "ready": bool((copy.get("status") or {}).get("applied"))}, - "can_act": self.may_act(actor, env.name, db) and env.runs_jobs, - } + async def users(self, actor: Actor, name: str) -> list[dict[str, Any]]: + """The owner roles of the databases this person sees, from the Cluster's managed roles.""" + found = await self.databases(actor, name) + if not found: + return [] + roles = self._roles(await self._cluster(self.environment(name))) + out = [] + for owner in sorted({d["owner"] for d in found}): + role = roles.get(owner) + out.append( + { + "name": owner, + "managed": role is not None, + "login": bool((role or {}).get("login")), + "secret": ((role or {}).get("passwordSecret") or {}).get("name", ""), + "databases": [d["name"] for d in found if d["owner"] == owner], + "namespaces": sorted({d["namespace"] for d in found if d["owner"] == owner}), + } + ) + return out - async def _target(self, env: Environment, resource: dict[str, Any], database: str) -> jobs.Target: + async def _target(self, env: Environment, resource: dict[str, Any], database: str, namespace: str) -> jobs.Target: owner = resource["spec"].get("owner", "") - cluster = await self._kube_for(env).get(f"{CNPG}/namespaces/{env.namespace}/clusters/{env.cnpg_cluster}") - if cluster is None: - raise ConsoleError(409, "no_cluster", f"There is no Cluster {env.cnpg_cluster} in {env.namespace}.") - roles = ((cluster.get("spec") or {}).get("managed") or {}).get("roles") or [] - secret = next((((r.get("passwordSecret") or {}).get("name")) for r in roles if r.get("name") == owner), None) + cluster = await self._cluster(env) + secret = ((self._roles(cluster).get(owner) or {}).get("passwordSecret") or {}).get("name") if not secret: raise ConsoleError(409, "no_credential", f"The owner role {owner!r} has no password Secret among the Cluster's managed roles, so this app can't connect as it.") ca = ((cluster.get("status") or {}).get("certificates") or {}).get("serverCASecret") or f"{env.cnpg_cluster}-ca" - return jobs.Target(environment=env.name, database=database, owner=owner, password_secret=secret, ca_secret=ca, host=f"{env.cnpg_cluster}-rw.{env.namespace}.svc") + return jobs.Target(environment=env.name, database=database, owner=owner, password_secret=secret, ca_secret=ca, host=f"{env.cnpg_cluster}-rw.{env.namespace}.svc", namespace=namespace) # ── Snapshots ─────────────────────────────────────────────────────────────────── - def _check_name(self, database: str) -> None: - if not re.match(DATABASE, database): - raise ConsoleError(404, "unknown_database", "That is not a database name this app takes.") + def _snapshot_json(self, environment: str, database: str, sid: str, size: int, created: str, metadata: dict[str, str]) -> dict[str, Any]: + return { + "environment": environment, "database": database, "id": sid, "created": metadata.get("created") or created, "size": size, + "created_by": metadata.get("createdby", ""), "note": metadata.get("note", ""), "namespace": metadata.get("namespace", ""), "shared_with": _shares(metadata), + } # fmt: skip async def snapshots(self, actor: Actor, name: str, database: str) -> list[dict[str, Any]]: env = self.environment(name) - self._check_name(database) - self._require(self.may_read(actor, env.name, database)) - found = await self._storage[env.name].list(f"snapshots/{database}/") + await self._database(actor, env, database) out = [] - for blob in found: + for blob in await self._storage[env.name].list(f"snapshots/{database}/"): sid = blob.name.rsplit("/", 1)[-1].removesuffix(".dump") if re.match(SNAPSHOT_ID, sid) and blob.name == snapshot_blob(database, sid): - m = blob.metadata - out.append({"id": sid, "created": m.get("created") or blob.created, "size": blob.size, "created_by": m.get("createdby", ""), "note": m.get("note", ""), "sha256": m.get("sha256", "")}) + out.append(self._snapshot_json(env.name, database, sid, blob.size, blob.created, blob.metadata)) + return sorted(out, key=lambda s: s["id"], reverse=True) + + async def shared(self, actor: Actor, name: str, database: str) -> list[dict[str, Any]]: + """Other environments' snapshots shared with this database's namespace.""" + env = self.environment(name) + _, namespace = await self._database(actor, env, database) + out = [] + for source in env.clone_from: + for blob in await self._storage[source].list("snapshots/"): + parts = blob.name.split("/") + sid = parts[-1].removesuffix(".dump") + if len(parts) == 3 and re.match(SNAPSHOT_ID, sid) and f"{env.name}/{namespace}" in _shares(blob.metadata): + out.append(self._snapshot_json(source, parts[1], sid, blob.size, blob.created, blob.metadata)) return sorted(out, key=lambda s: s["id"], reverse=True) async def _busy(self, env: Environment, database: str) -> None: @@ -179,10 +293,10 @@ async def _busy(self, env: Environment, database: str) -> None: async def take_snapshot(self, actor: Actor, name: str, database: str, note: str) -> dict[str, Any]: env = self.environment(name) - self._check_name(database) - self._require(self.may_act(actor, env.name, database)) + resource, namespace = await self._database(actor, env, database) + await self._require(actor, env, namespace, "snapshot") await self._busy(env, database) - target = await self._target(env, await self._resource(env, database), database) + target = await self._target(env, resource, database, namespace) now = self._now() sid = f"{now:%Y%m%dT%H%M%SZ}-{secrets.token_hex(3)}" job_name = jobs.name_for("snapshot") @@ -190,33 +304,61 @@ async def take_snapshot(self, actor: Actor, name: str, database: str, note: str) manifest = jobs.build( self.cfg, env, name=job_name, action="snapshot", target=target, database=database, blob_url=env.storage.url, blob=blob, requested_by=actor.upn, annotations={"requested-by": actor.upn, "requested-at": _iso(now), "note": note, "snapshot": sid}, - metadata={"createdby": actor.upn, "created": _iso(now), "note": note, "environment": env.name, "database": database, "job": job_name}, + metadata={"createdby": actor.upn, "created": _iso(now), "note": note, "environment": env.name, "database": database, "namespace": namespace, "job": job_name}, ) # fmt: skip job = await self._kube_for(env).create(f"/apis/batch/v1/namespaces/{env.namespace}/jobs", manifest) - await audit.record(self._storage[env.name], environment=env.name, actor=actor.upn, action="snapshot.requested", at=now, database=database, job=job_name, snapshot=blob, detail=note) - return self._job_json(actor, env, job, None) + await audit.record(self._storage[env.name], environment=env.name, actor=actor.upn, action="snapshot.requested", at=now, database=database, namespace=namespace, job=job_name, snapshot=blob, detail=note) + return self._job_json(env, job, None, can_approve=False, can_decline=False) + + async def share(self, actor: Actor, name: str, database: str, snapshot: str, *, environment: str, namespace: str) -> dict[str, Any]: + """Let `namespace` in `environment` clone this snapshot. Only someone who may snapshot the + database here may hand its data on, and only to an environment that takes this one's.""" + env = self.environment(name) + target = self.environment(environment) + if env.name not in target.clone_from: + raise ConsoleError(403, "no_clone", f"{target.name} takes no snapshots from {env.name}.") + if not re.match(NAMESPACE, namespace): + raise ConsoleError(422, "invalid_request", "That is not a namespace name.") + _, source = await self._database(actor, env, database) + await self._require(actor, env, source, "snapshot") + blob = snapshot_blob(database, self._snapshot_id(snapshot)) + found = await self._storage[env.name].properties(blob) + if found is None: + raise ConsoleError(404, "unknown_snapshot", f"{env.name} has no snapshot {snapshot} of {database}.") + shares = sorted(set(_shares(found.metadata)) | {f"{target.name}/{namespace}"}) + await self._storage[env.name].set_metadata(blob, {**found.metadata, "sharedwith": " ".join(shares)}) + await audit.record(self._storage[env.name], environment=env.name, actor=actor.upn, action="snapshot.shared", database=database, namespace=source, snapshot=blob, target=f"{target.name}/{namespace}") + return self._snapshot_json(env.name, database, snapshot, found.size, found.created, {**found.metadata, "sharedwith": " ".join(shares)}) + + def _snapshot_id(self, snapshot: str) -> str: + if not re.match(SNAPSHOT_ID, snapshot): + raise ConsoleError(404, "unknown_snapshot", "That is not a snapshot.") + return snapshot async def restore(self, actor: Actor, name: str, database: str, *, source_environment: str, source_database: str, snapshot: str, into: str, reason: str) -> dict[str, Any]: env = self.environment(name) source = self.environment(source_environment) - self._check_name(database) self._check_name(source_database) - if not re.match(SNAPSHOT_ID, snapshot): - raise ConsoleError(404, "unknown_snapshot", "That is not a snapshot.") - self._require(self.may_act(actor, env.name, database) and self.may_read(actor, source.name, source_database)) + blob = snapshot_blob(source_database, self._snapshot_id(snapshot)) + resource, namespace = await self._database(actor, env, database) + await self._require(actor, env, namespace, "restore") if source.name != env.name and source.name not in env.clone_from: raise ConsoleError(403, "no_clone", f"{env.name} takes no snapshots from {source.name}.") - blob = snapshot_blob(source_database, snapshot) - if await self._storage[source.name].properties(blob) is None: + if source.name == env.name and source_database != database: + # Another database's data: what snapshotting that one takes. + await self._require(actor, env, (await self._database(actor, env, source_database))[1], "snapshot") + found = await self._storage[source.name].properties(blob) + if found is None: raise ConsoleError(404, "unknown_snapshot", f"{source.name} has no snapshot {snapshot} of {source_database}.") + if source.name != env.name and f"{env.name}/{namespace}" not in _shares(found.metadata): + raise ConsoleError(403, "not_shared", f"That snapshot is not shared with {namespace} in {env.name}; someone who may snapshot it in {source.name} shares it.") await self._busy(env, database) - resource = await self._resource(env, database) workloads: tuple[tuple[str, str, str], ...] = () if into == "copy": - target = await self._target(env, await self._ensure_copy(env, resource, database), database + _COPY) + target = await self._target(env, await self._ensure_copy(env, resource, database), database + _COPY, namespace) else: - target = await self._target(env, resource, database) - workloads = tuple(sorted({w for g in self.catalog.grants if g.environment == env.name and g.database == database for w in g.workloads})) + workloads = self.workloads(resource, namespace) + target = await self._target(env, resource, database, namespace) now = self._now() job_name = jobs.name_for("restore") manifest = jobs.build( @@ -229,10 +371,10 @@ async def restore(self, actor: Actor, name: str, database: str, *, source_enviro ) # fmt: skip job = await self._kube_for(env).create(f"/apis/batch/v1/namespaces/{env.namespace}/jobs", manifest) await audit.record( - self._storage[env.name], environment=env.name, actor=actor.upn, action="restore.requested", at=now, database=database, job=job_name, + self._storage[env.name], environment=env.name, actor=actor.upn, action="restore.requested", at=now, database=database, namespace=namespace, job=job_name, snapshot=f"{source.name}/{blob}", target=target.database, detail=reason, ) # fmt: skip - return self._job_json(actor, env, job, None) + return self._job_json(env, job, None, can_approve=False, can_decline=env.production) async def _ensure_copy(self, env: Environment, resource: dict[str, Any], database: str) -> dict[str, Any]: """The Database resource for `_copy`: CloudNativePG creates the database, and drops it with the resource.""" @@ -240,14 +382,17 @@ async def _ensure_copy(self, env: Environment, resource: dict[str, Any], databas path = f"{CNPG}/namespaces/{env.namespace}/databases" existing = await self._kube_for(env).get(f"{path}/{name}") if existing is not None: - if existing["metadata"].get("labels", {}).get(f"{jobs.PREFIX}copy-of") != database: + if self._copy_of(existing) != database: raise ConsoleError(409, "copy_taken", f"A Database resource {name} exists that this app did not create.") return existing + labels = {jobs.MANAGED_BY: jobs.APP, f"{jobs.PREFIX}environment": env.name, f"{jobs.PREFIX}copy-of": database} + if label := ((resource.get("metadata") or {}).get("labels") or {}).get(self.cfg.namespace_label): + labels[self.cfg.namespace_label] = label extensions = [{k: v for k, v in e.items() if k in ("name", "version", "schema")} for e in resource["spec"].get("extensions") or [] if e.get("ensure") != "absent"] body = { "apiVersion": "postgresql.cnpg.io/v1", "kind": "Database", - "metadata": {"name": name, "namespace": env.namespace, "labels": {jobs.MANAGED_BY: jobs.APP, f"{jobs.PREFIX}environment": env.name, f"{jobs.PREFIX}copy-of": database}}, + "metadata": {"name": name, "namespace": env.namespace, "labels": labels}, "spec": { "name": database + _COPY, "owner": resource["spec"]["owner"], @@ -261,29 +406,27 @@ async def _ensure_copy(self, env: Environment, resource: dict[str, Any], databas async def drop_copy(self, actor: Actor, name: str, database: str) -> None: env = self.environment(name) - self._check_name(database) - self._require(self.may_act(actor, env.name, database)) + _, namespace = await self._database(actor, env, database) + await self._require(actor, env, namespace, "restore") await self._busy(env, database) path = f"{CNPG}/namespaces/{env.namespace}/databases" - copy = next((d for d in await self._kube_for(env).list(path, f"{jobs.MANAGED_BY}={jobs.APP},{jobs.PREFIX}copy-of={database}")), None) + copy = next(iter(await self._kube_for(env).list(path, f"{jobs.MANAGED_BY}={jobs.APP},{jobs.PREFIX}copy-of={database}")), None) if copy is None: raise ConsoleError(404, "no_copy", f"{database} has no copy.") await self._kube_for(env).delete(f"{path}/{copy['metadata']['name']}") - await audit.record(self._storage[env.name], environment=env.name, actor=actor.upn, action="copy.dropped", database=database, target=copy["spec"].get("name", "")) + await audit.record(self._storage[env.name], environment=env.name, actor=actor.upn, action="copy.dropped", database=database, namespace=namespace, target=copy["spec"].get("name", "")) async def download(self, actor: Actor, name: str, database: str, snapshot: str) -> tuple[Container, str, str]: """The container and blob to stream, and a file name, once the download is recorded.""" env = self.environment(name) - self._check_name(database) if env.production: raise ConsoleError(403, "no_downloads", f"Snapshots of {env.name} stay in {env.name}.") - self._require(self.may_act(actor, env.name, database)) - if not re.match(SNAPSHOT_ID, snapshot): - raise ConsoleError(404, "unknown_snapshot", "That is not a snapshot.") - blob = snapshot_blob(database, snapshot) + _, namespace = await self._database(actor, env, database) + await self._require(actor, env, namespace, "snapshot") + blob = snapshot_blob(database, self._snapshot_id(snapshot)) if await self._storage[env.name].properties(blob) is None: raise ConsoleError(404, "unknown_snapshot", f"{env.name} has no snapshot {snapshot} of {database}.") - await audit.record(self._storage[env.name], environment=env.name, actor=actor.upn, action="snapshot.downloaded", database=database, snapshot=blob) + await audit.record(self._storage[env.name], environment=env.name, actor=actor.upn, action="snapshot.downloaded", database=database, namespace=namespace, snapshot=blob) return self._storage[env.name], blob, f"{env.name}-{database}-{snapshot}.dump" # ── Jobs ──────────────────────────────────────────────────────────────────────── @@ -294,18 +437,17 @@ def _expired(self, job: dict[str, Any]) -> bool: at = _when((job["metadata"].get("annotations") or {}).get(f"{jobs.PREFIX}requested-at", "")) return at is None or self._now() - at > timedelta(hours=APPROVAL_HOURS) - def _job_json(self, actor: Actor, env: Environment, job: dict[str, Any], pod: dict[str, Any] | None) -> dict[str, Any]: + def _job_json(self, env: Environment, job: dict[str, Any], pod: dict[str, Any] | None, *, can_approve: bool, can_decline: bool) -> dict[str, Any]: meta = job.get("metadata") or {} a = {k.removeprefix(jobs.PREFIX): v for k, v in (meta.get("annotations") or {}).items() if k.startswith(jobs.PREFIX)} labels = meta.get("labels") or {} - database = labels.get(f"{jobs.PREFIX}database", "") state = "expired" if self._expired(job) else jobs.state(job) status = job.get("status") or {} - waiting = state == "waiting" return { "name": meta.get("name", ""), "action": labels.get(f"{jobs.PREFIX}action", ""), - "database": database, + "database": labels.get(f"{jobs.PREFIX}database", ""), + "namespace": labels.get(f"{jobs.PREFIX}namespace", ""), "state": state, "requested_by": a.get("requested-by", ""), "requested_at": a.get("requested-at", ""), @@ -322,10 +464,14 @@ def _job_json(self, actor: Actor, env: Environment, job: dict[str, Any], pod: di "started": status.get("startTime", ""), "finished": status.get("completionTime", "") or next((c.get("lastTransitionTime", "") for c in status.get("conditions") or [] if c.get("type") == "Failed"), ""), "result": jobs.result(pod), - "can_approve": waiting and actor.upn != a.get("requested-by") and self.may_act(actor, env.name, database), - "can_decline": waiting and (actor.upn == a.get("requested-by") or self.may_act(actor, env.name, database)), + "can_approve": state == "waiting" and can_approve, + "can_decline": state == "waiting" and can_decline, } + def _namespace_of_job(self, env: Environment, job: dict[str, Any]) -> str: + found = ((job.get("metadata") or {}).get("labels") or {}).get(f"{jobs.PREFIX}namespace", "") + return found if re.match(NAMESPACE, found) else env.namespace + async def jobs(self, actor: Actor, name: str) -> list[dict[str, Any]]: env = self.environment(name) if not env.runs_jobs: @@ -335,50 +481,64 @@ async def jobs(self, actor: Actor, name: str) -> list[dict[str, Any]]: pods = {} for pod in await kube.list(f"/api/v1/namespaces/{env.namespace}/pods", jobs.selector(env.name)): pods[(pod.get("metadata") or {}).get("labels", {}).get("job-name", "")] = pod - out = [] + live = [] for job in found: if self._expired(job): await self._drop(env, job, actor="databases-ui", action="restore.expired") - continue - if self.may_read(actor, env.name, (job["metadata"].get("labels") or {}).get(f"{jobs.PREFIX}database", "")): - out.append(self._job_json(actor, env, job, pods.get(job["metadata"]["name"]))) + else: + live.append(job) + spaces = [self._namespace_of_job(env, j) for j in live] + seen = await self._answers(actor, env, spaces, "read") + restore = await self._answers(actor, env, (ns for ns in spaces if seen[ns]), "restore") + out = [] + for job, ns in zip(live, spaces, strict=True): + if seen[ns]: + mine = (job["metadata"].get("annotations") or {}).get(f"{jobs.PREFIX}requested-by") == actor.upn + out.append(self._job_json(env, job, pods.get(job["metadata"]["name"]), can_approve=restore[ns] and not mine, can_decline=restore[ns] or mine)) return sorted(out, key=lambda j: j["requested_at"], reverse=True) - async def _waiting(self, actor: Actor, env: Environment, job_name: str) -> dict[str, Any]: + async def _waiting(self, actor: Actor, env: Environment, job_name: str) -> tuple[dict[str, Any], str]: job = await self._kube_for(env).get(f"/apis/batch/v1/namespaces/{env.namespace}/jobs/{job_name}") labels = (job or {}).get("metadata", {}).get("labels") or {} if job is None or labels.get(jobs.MANAGED_BY) != jobs.APP or labels.get(f"{jobs.PREFIX}environment") != env.name: raise ConsoleError(404, "unknown_job", "There is no such request.") - self._require(self.may_read(actor, env.name, labels.get(f"{jobs.PREFIX}database", ""))) + namespace = self._namespace_of_job(env, job) + await self._require(actor, env, namespace, "read") if self._expired(job): raise ConsoleError(409, "expired", f"Requests wait {APPROVAL_HOURS} hours for approval; ask again.") if jobs.state(job) != "waiting": raise ConsoleError(409, "not_waiting", "This request is not waiting for approval.") - return job + return job, namespace async def approve(self, actor: Actor, name: str, job_name: str) -> dict[str, Any]: env = self.environment(name) - job = await self._waiting(actor, env, job_name) - view = self._job_json(actor, env, job, None) - if actor.upn == view["requested_by"]: + job, namespace = await self._waiting(actor, env, job_name) + asked_by = (job["metadata"].get("annotations") or {}).get(f"{jobs.PREFIX}requested-by", "") + if actor.upn == asked_by: raise ConsoleError(403, "own_request", "A second person approves this, not the one who asked.") - self._require(view["can_approve"]) + await self._require(actor, env, namespace, "restore") now = self._now() patch = {"metadata": {"annotations": {f"{jobs.PREFIX}approved-by": actor.upn, f"{jobs.PREFIX}approved-at": _iso(now)}}, "spec": {"suspend": False}} job = await self._kube_for(env).patch(f"/apis/batch/v1/namespaces/{env.namespace}/jobs/{job_name}", patch) - await audit.record(self._storage[env.name], environment=env.name, actor=actor.upn, action="restore.approved", at=now, database=view["database"], job=job_name, detail=f"asked by {view['requested_by']}") - return self._job_json(actor, env, job, None) + database = (job["metadata"].get("labels") or {}).get(f"{jobs.PREFIX}database", "") + await audit.record(self._storage[env.name], environment=env.name, actor=actor.upn, action="restore.approved", at=now, database=database, namespace=namespace, job=job_name, detail=f"asked by {asked_by}") + return self._job_json(env, job, None, can_approve=False, can_decline=False) async def decline(self, actor: Actor, name: str, job_name: str, reason: str) -> None: env = self.environment(name) - job = await self._waiting(actor, env, job_name) - self._require(self._job_json(actor, env, job, None)["can_decline"]) + job, namespace = await self._waiting(actor, env, job_name) + if (job["metadata"].get("annotations") or {}).get(f"{jobs.PREFIX}requested-by") != actor.upn: + await self._require(actor, env, namespace, "restore") await self._drop(env, job, actor=actor.upn, action="restore.declined", detail=reason) async def _drop(self, env: Environment, job: dict[str, Any], *, actor: str, action: str, detail: str = "") -> None: meta = job["metadata"] + labels = meta.get("labels") or {} await self._kube_for(env).delete(f"/apis/batch/v1/namespaces/{env.namespace}/jobs/{meta['name']}") - await audit.record(self._storage[env.name], environment=env.name, actor=actor, action=action, database=(meta.get("labels") or {}).get(f"{jobs.PREFIX}database", ""), job=meta["name"], detail=detail) + await audit.record( + self._storage[env.name], environment=env.name, actor=actor, action=action, database=labels.get(f"{jobs.PREFIX}database", ""), + namespace=self._namespace_of_job(env, job), job=meta["name"], detail=detail, + ) # fmt: skip # ── Audit ─────────────────────────────────────────────────────────────────────── @@ -389,5 +549,7 @@ async def audit_log(self, actor: Actor, name: str, limit: int = 500) -> list[dic entries = [] for month in months: entries += audit.parse(await container.read(month) or b"") - visible = [e for e in entries if actor.admin or actor.auditor or (e.get("database") and self.may_read(actor, env.name, str(e["database"])))] + space = {id(e): str(e.get("namespace") or "") if re.match(NAMESPACE, str(e.get("namespace") or "")) else env.namespace for e in entries} + seen = await self._answers(actor, env, space.values(), "read") if env.runs_jobs else {} + visible = [e for e in entries if seen.get(space[id(e)])] return sorted(visible, key=lambda e: str(e.get("at", "")), reverse=True)[:limit] diff --git a/tests/conftest.py b/tests/conftest.py index 9407a2b..96d12bb 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -38,41 +38,52 @@ KUBE = "https://kubernetes.example.test" NOW = datetime(2026, 10, 23, 14, 0, 0, tzinfo=UTC) KEY = rsa.generate_private_key(public_exponent=65537, key_size=2048) -PAYMENTS = "6f1c2b7e-3a44-4d0e-9a51-2b8e0c7d9f10" -IDENTITY = "0b9d8e7c-6f5a-4b3c-8d2e-1f0a9b8c7d6e" -UNRELATED = "99999999-9999-4999-8999-999999999999" - CATALOG = f""" environments: - name: dev storage: url: {STORAGE}/dev - cloneFrom: [acc, prd] + cloneFrom: [acc] - name: acc kubernetes: none storage: url: {STORAGE}/acc + - name: tst + kubernetes: none + storage: + url: {STORAGE}/tst + cloneFrom: [dev] - name: prd production: true cluster: prod storage: url: {STORAGE}/prd -teams: - - id: payments - name: Payments - groups: [{PAYMENTS}] - databases: - - name: payments_{{env}} - workloads: - - deployment/{{env}}-payments/api - - id: identity - name: Identity - groups: [{IDENTITY}] - databases: - - name: keycloak - environments: [dev] """ +# What each Kubernetes tier lets someone do in a namespace, as the API server's RBAC would answer. +VIEW = {("list", "", "pods")} +EDIT = VIEW | {("get", "", "secrets")} +ADMIN = EDIT | {("create", "rbac.authorization.k8s.io", "rolebindings")} +# Groups (as in the ID token) and the namespaces they hold tiers in; "*" is every namespace. +RBAC = { + "k8s-dev-payments-read": {"dev-payments": VIEW}, + "k8s-dev-payments-write": {"dev-payments": EDIT}, + "k8s-prd-payments-write": {"prd-payments": EDIT}, + "k8s-prd-payments-admin": {"prd-payments": ADMIN}, + "k8s-dev-identity-write": {"dev-identity": EDIT}, + "cloud-read": {"*": VIEW}, + "cloud-admin": {"*": ADMIN}, +} +PEOPLE = { + "alice@example.com": ["k8s-dev-payments-write", "k8s-prd-payments-admin"], + "bob@example.com": ["k8s-dev-payments-write", "k8s-prd-payments-admin"], + "pat@example.com": ["k8s-prd-payments-write"], + "carol@example.com": ["k8s-dev-identity-write"], + "vera@example.com": ["k8s-dev-payments-read"], + "audrey@example.com": ["cloud-read"], + "root@example.com": ["cloud-admin"], +} + def oid(upn: str) -> str: return str(uuid.uuid5(uuid.NAMESPACE_URL, upn)) @@ -81,9 +92,10 @@ def oid(upn: str) -> str: @dataclass class FakeEntra: user: str = "alice@example.com" - roles: list[str] = field(default_factory=list) groups: list[str] = field(default_factory=list) overage: bool = False + # More claims in the next ID token. + extra: dict[str, Any] = field(default_factory=dict) tenant: str = TENANT challenge: str = "" nonce: str = "" @@ -106,8 +118,8 @@ def id_token(self) -> str: "oid": oid(self.user), "name": self.user.split("@")[0].title(), "preferred_username": self.user, - "roles": self.roles, "groups": self.groups, + **self.extra, } if self.overage: claims.pop("groups") @@ -137,6 +149,15 @@ class StoredBlob: kind: str = "BlockBlob" +class Broken(httpx.AsyncByteStream): + def __init__(self, head: bytes): + self.head = head + + async def __aiter__(self): + yield self.head + raise httpx.ReadError("connection reset") + + @dataclass class FakeStorage: blobs: dict[str, StoredBlob] = field(default_factory=dict) @@ -145,6 +166,8 @@ class FakeStorage: # Answers to fail with, by (method, comp): a status code each time. fail: dict[tuple[str, str], int] = field(default_factory=dict) page: int = 1000 + # Downloads break off after this many bytes, as a dropped connection would. + break_after: int | None = None def handle(self, request: httpx.Request) -> httpx.Response: if request.headers.get("authorization") != "Bearer storage-token" and "sig" not in request.url.params: @@ -177,6 +200,11 @@ def handle(self, request: httpx.Request) -> httpx.Response: meta = {k[len("x-ms-meta-") :]: v for k, v in request.headers.items() if k.startswith("x-ms-meta-")} self.blobs[key] = StoredBlob(b"".join(self.blocks.pop((key, i)) for i in ids), meta, formatdate(usegmt=True)) return httpx.Response(201) + if request.method == "PUT" and comp == "metadata": + if key not in self.blobs: + return httpx.Response(404, headers={"x-ms-error-code": "BlobNotFound"}) + self.blobs[key].metadata = {k[len("x-ms-meta-") :]: v for k, v in request.headers.items() if k.startswith("x-ms-meta-")} + return httpx.Response(200) if request.method == "PUT" and comp == "appendblock": if key not in self.blobs: return httpx.Response(404, headers={"x-ms-error-code": "BlobNotFound"}) @@ -192,6 +220,8 @@ def handle(self, request: httpx.Request) -> httpx.Response: if blob is None: return httpx.Response(404, headers={"x-ms-error-code": "BlobNotFound"}) headers = {"content-length": str(len(blob.data)), "x-ms-creation-time": blob.created, **{f"x-ms-meta-{k}": v for k, v in blob.metadata.items()}} + if request.method == "GET" and self.break_after is not None: + return httpx.Response(200, headers=headers, stream=Broken(blob.data[: self.break_after])) return httpx.Response(200, headers=headers, content=blob.data if request.method == "GET" else b"") return httpx.Response(400, headers={"x-ms-error-code": "Unhandled"}) @@ -229,6 +259,15 @@ class FakeKube: calls: list[tuple[str, str]] = field(default_factory=list) # Answer every call with this status, as an API server that refuses this app would. refuse: int = 0 + reviews: list[dict[str, Any]] = field(default_factory=list) + + def review(self, spec: dict[str, Any]) -> bool: + self.reviews.append(spec) + attrs = spec["resourceAttributes"] + want = (attrs["verb"], attrs.get("group", ""), attrs["resource"]) + groups = [g.removeprefix("oidc:") for g in spec.get("groups", [])] + assert "system:authenticated" in groups and spec["user"].startswith("oidc:") + return any(want in tiers.get(attrs["namespace"], set()) | tiers.get("*", set()) for g in groups for tiers in [RBAC.get(g, {})]) def put(self, collection: str, obj: dict[str, Any]) -> dict[str, Any]: obj.setdefault("metadata", {}).setdefault("labels", {}) @@ -253,6 +292,9 @@ def handle(self, request: httpx.Request) -> httpx.Response: if request.method == "GET": found = items.get(name) return httpx.Response(200, json=copy.deepcopy(found)) if found else httpx.Response(404, json={"message": f"{name} not found"}) + if request.method == "POST" and path == "/apis/authorization.k8s.io/v1/subjectaccessreviews": + body = json.loads(request.content) + return httpx.Response(201, json={**body, "status": {"allowed": self.review(body["spec"])}}) if request.method == "POST": body = json.loads(request.content) if body["metadata"]["name"] in items: @@ -276,8 +318,11 @@ def handle(self, request: httpx.Request) -> httpx.Response: PODS = "/api/v1/namespaces/database/pods" -def database(name: str, owner: str, cluster: str, **spec: Any) -> dict[str, Any]: - return {"metadata": {"name": name.replace("_", "-"), "labels": {}}, "spec": {"name": name, "owner": owner, "cluster": {"name": cluster}, **spec}, "status": {"applied": True}} +def database(name: str, owner: str, cluster: str, namespace: str = "", workloads: str = "", **spec: Any) -> dict[str, Any]: + meta: dict[str, Any] = {"name": name.replace("_", "-"), "labels": {"databases-ui/namespace": namespace} if namespace else {}} + if workloads: + meta["annotations"] = {"databases-ui/workloads": workloads} + return {"metadata": meta, "spec": {"name": name, "owner": owner, "cluster": {"name": cluster}, **spec}, "status": {"applied": True}} @dataclass @@ -297,17 +342,21 @@ def handler(self, request: httpx.Request) -> httpx.Response: return httpx.Response(404, json={"error": "unhandled", "url": url}) def seed(self) -> None: - for name, cluster, roles in (("dev", "dev", ["payments_dev", "keycloak"]), ("prod", "prod", ["payments_prd"])): + for name, roles in (("dev", ["payments_dev", "keycloak"]), ("prod", ["payments_prd"])): self.kube.put( f"{CNPG}/clusters", - {"metadata": {"name": name}, "spec": {"managed": {"roles": [{"name": r, "passwordSecret": {"name": f"{r}-db"}} for r in roles] + [{"name": "nopass"}]}}, "status": {"certificates": {"serverCASecret": f"{cluster}-ca"}}}, + { + "metadata": {"name": name}, + "spec": {"managed": {"roles": [{"name": r, "login": True, "passwordSecret": {"name": f"{r}-db"}} for r in roles] + [{"name": "nopass"}]}}, + "status": {"certificates": {"serverCASecret": f"{name}-ca"}}, + }, ) for d in ( - database("payments_dev", "payments_dev", "dev", extensions=[{"name": "citext", "ensure": "present"}, {"name": "old", "ensure": "absent"}]), - database("keycloak", "keycloak", "dev"), + database("payments_dev", "payments_dev", "dev", "dev-payments", "deployment/api, statefulset/worker", extensions=[{"name": "citext", "ensure": "present"}, {"name": "old", "ensure": "absent"}]), + database("keycloak", "keycloak", "dev", "dev-identity"), database("platform_only", "nopass", "dev"), - database("payments_prd", "payments_prd", "prod"), - database("gone", "payments_dev", "dev", ensure="absent"), + database("payments_prd", "payments_prd", "prod", "prd-payments", "deployment/api"), + database("gone", "payments_dev", "dev", "dev-payments", ensure="absent"), ): self.kube.put(f"{CNPG}/databases", d) @@ -351,9 +400,9 @@ def client(world: World, env: dict[str, str]) -> TestClient: return make_client(world, env) -def sign_in(client: TestClient, world: World, upn: str = "alice@example.com", groups: list[str] | tuple[str, ...] = (PAYMENTS,), roles: list[str] | tuple[str, ...] = ()) -> dict[str, Any]: +def sign_in(client: TestClient, world: World, upn: str = "alice@example.com", groups: list[str] | None = None) -> dict[str, Any]: client.cookies.clear() - world.entra.user, world.entra.groups, world.entra.roles = upn, list(groups), list(roles) + world.entra.user, world.entra.groups = upn, PEOPLE.get(upn, []) if groups is None else groups response = client.get("/auth/login") query = parse_qs(urlsplit(response.headers["location"]).query) world.entra.challenge, world.entra.nonce = query["code_challenge"][0], query["nonce"][0] diff --git a/tests/test_api.py b/tests/test_api.py index d569216..e0b60af 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -4,13 +4,11 @@ from typing import Any from conftest import ( + CATALOG, CNPG, - IDENTITY, JOBS, - PAYMENTS, PODS, STORAGE, - UNRELATED, World, make_client, sign_in, @@ -36,31 +34,72 @@ def finish(world: World, name: str, *, ok: bool = True, message: dict[str, Any] "status": {"containerStatuses": [{"state": {"terminated": {"message": json.dumps(message or {"result": "succeeded", "bytes": 1234, "seconds": 9})}}}]}}) # fmt: skip -def test_me_lists_teams_and_environments(client, world): - me = sign_in(client, world, groups=[PAYMENTS, UNRELATED]) - assert me["upn"] == "alice@example.com" and me["teams"] == [{"id": "payments", "name": "Payments"}] - assert [(e["name"], e["production"], e["runs_jobs"], e["downloads"]) for e in me["environments"]] == [("dev", False, True, True), ("acc", False, False, True), ("prd", True, True, False)] +RESTORE = {"source_environment": "dev", "source_database": "payments_dev", "snapshot": "20261022T080000Z-bbbbbb", "into": "database", "reason": "undo the bad batch"} +PRD = {"source_environment": "prd", "source_database": "payments_prd", "snapshot": "20261021T080000Z-dddddd", "into": "database", "reason": "after the bad deploy"} -def test_databases_follow_the_teams(client, world): +def test_me_names_the_person_as_kubernetes_does(client, world): + me = sign_in(client, world) + assert me["upn"] == "alice@example.com" and me["kubernetes"] == {"user": "oidc:alice@example.com", "groups": ["oidc:k8s-dev-payments-write", "oidc:k8s-prd-payments-admin"]} + envs = {e["name"]: e for e in me["environments"]} + assert envs["dev"] == {"name": "dev", "production": False, "runs_jobs": True, "clone_from": ["acc"], "shares_to": ["tst"], "downloads": True} + assert envs["acc"]["runs_jobs"] is False and envs["acc"]["shares_to"] == ["dev"] and envs["prd"]["downloads"] is False + + +def test_databases_follow_kubernetes_access_per_namespace(client, world): sign_in(client, world) found = client.get("/api/environments/dev/databases").json()["databases"] - assert [d["name"] for d in found] == ["payments_dev"] - assert found[0] | {"teams": found[0]["teams"]} == { - "name": "payments_dev", "owner": "payments_dev", "ready": True, "message": "", "teams": ["payments"], - "workloads": ["deployment/dev-payments/api"], "copy": None, "can_act": True, - } # fmt: skip - # prd's Cluster is called prod; acc runs nothing here, so the catalog says what it holds. - assert [d["name"] for d in client.get("/api/environments/prd/databases").json()["databases"]] == ["payments_prd"] - assert client.get("/api/environments/acc/databases").json()["databases"] == [ - {"name": "payments_acc", "owner": "", "ready": None, "message": "", "teams": ["payments"], "workloads": ["deployment/acc-payments/api"], "copy": None, "can_act": False} - ] - sign_in(client, world, upn="nobody@example.com", groups=[UNRELATED]) - assert client.get("/api/environments/dev/databases").json()["databases"] == [] - sign_in(client, world, upn="audrey@example.com", groups=[], roles=["Auditor"]) - found = client.get("/api/environments/dev/databases").json()["databases"] - assert [(d["name"], d["can_act"]) for d in found] == [("keycloak", False), ("payments_dev", False), ("platform_only", False)] + assert found == [ + { + "name": "payments_dev", "namespace": "dev-payments", "owner": "payments_dev", "owner_secret": "payments_dev-db", "ready": True, "message": "", + "workloads": ["deployment/api", "statefulset/worker"], "copy": None, "can_snapshot": True, "can_restore": True, + } + ] # fmt: skip + spec = world.kube.reviews[0] + assert spec["user"] == "oidc:alice@example.com" and spec["groups"][-1] == "system:authenticated" + # Every namespace once per tier, then answers come from the cache for a minute. + asked = len(world.kube.reviews) + client.get("/api/environments/dev/databases") + assert len(world.kube.reviews) == asked + assert client.get("/api/environments/acc/databases").json()["databases"] == [] assert client.get("/api/environments/nowhere/databases").status_code == 404 + sign_in(client, world, "vera@example.com") + assert [(d["name"], d["can_snapshot"], d["can_restore"]) for d in client.get("/api/environments/dev/databases").json()["databases"]] == [("payments_dev", False, False)] + sign_in(client, world, "carol@example.com") + assert [d["name"] for d in client.get("/api/environments/dev/databases").json()["databases"]] == ["keycloak"] + # Without the label a database is the platform's: its own namespace. + sign_in(client, world, "audrey@example.com") + found = client.get("/api/environments/dev/databases").json()["databases"] + assert [(d["name"], d["namespace"], d["can_snapshot"]) for d in found] == [("keycloak", "dev-identity", False), ("payments_dev", "dev-payments", False), ("platform_only", "database", False)] + sign_in(client, world, "nobody@example.com", groups=[]) + assert client.get("/api/environments/dev/databases").json()["databases"] == [] + + +def test_production_restores_take_admin_in_the_namespace(client, world): + sign_in(client, world, "pat@example.com") + found = client.get("/api/environments/prd/databases").json()["databases"] + assert [(d["name"], d["can_snapshot"], d["can_restore"]) for d in found] == [("payments_prd", True, False)] + restore = next(r for r in world.kube.reviews if r["resourceAttributes"]["resource"] == "rolebindings") + assert restore["resourceAttributes"] == {"namespace": "prd-payments", "verb": "create", "group": "rbac.authorization.k8s.io", "resource": "rolebindings", "subresource": ""} + + +def test_access_per_environment_comes_from_the_catalog(world, env, tmp_path): + (tmp_path / "catalog.yaml").write_text(CATALOG + " access:\n restore: {verb: get, resource: secrets}\n") + client = make_client(world, env) + sign_in(client, world, "pat@example.com") + assert client.get("/api/environments/prd/databases").json()["databases"][0]["can_restore"] is True + + +def test_users_are_the_owners_of_the_databases_you_see(client, world): + sign_in(client, world) + assert client.get("/api/environments/dev/users").json()["users"] == [ + {"name": "payments_dev", "managed": True, "login": True, "secret": "payments_dev-db", "databases": ["payments_dev"], "namespaces": ["dev-payments"]} + ] + sign_in(client, world, "root@example.com") + users = {u["name"]: u for u in client.get("/api/environments/dev/users").json()["users"]} + assert sorted(users) == ["keycloak", "nopass", "payments_dev"] and users["nopass"]["secret"] == "" and users["nopass"]["login"] is False + sign_in(client, world, "nobody@example.com", groups=[]) + assert client.get("/api/environments/dev/users").json()["users"] == [] def test_a_snapshot_is_a_job_that_reads_the_owners_password_itself(client, world): @@ -70,7 +109,10 @@ def test_a_snapshot_is_a_job_that_reads_the_owners_password_itself(client, world job = only_job(world) meta, spec = job["metadata"], job["spec"] assert meta["name"].startswith("dbui-snapshot-") and meta["namespace"] == "database" - assert meta["labels"] == {"app.kubernetes.io/managed-by": "databases-ui", "databases-ui/environment": "dev", "databases-ui/database": "payments_dev", "databases-ui/action": "snapshot"} + assert meta["labels"] == { + "app.kubernetes.io/managed-by": "databases-ui", "databases-ui/environment": "dev", "databases-ui/database": "payments_dev", + "databases-ui/namespace": "dev-payments", "databases-ui/action": "snapshot", + } # fmt: skip assert meta["annotations"]["databases-ui/note"] == "before the 2.4 migration" and meta["annotations"]["databases-ui/requested-by"] == "alice@example.com" assert spec["suspend"] is False and spec["backoffLimit"] == 0 pod = spec["template"]["spec"] @@ -78,18 +120,26 @@ def test_a_snapshot_is_a_job_that_reads_the_owners_password_itself(client, world assert pod["containers"][0]["image"] == "ghcr.io/magmamoose/databases-ui:v0.1.0" and pod["containers"][0]["args"] == ["job"] env = env_of(job) assert env["PGHOST"] == "dev-rw.database.svc" and env["PGDATABASE"] == "payments_dev" and env["PGUSER"] == "payments_dev" - assert env["PGPASSWORD"] == {"secretKeyRef": {"name": "payments_dev-db", "key": "password"}} - assert env["PGSSLMODE"] == "verify-full" - assert env["DBUI_BLOB_URL"] == f"{STORAGE}/dev" and env["DBUI_BLOB"].startswith("snapshots/payments_dev/20261023T140000Z-") - assert json.loads(env["DBUI_METADATA"])["createdby"] == "alice@example.com" + assert env["PGPASSWORD"] == {"secretKeyRef": {"name": "payments_dev-db", "key": "password"}} and env["PGSSLMODE"] == "verify-full" + assert env["DBUI_BLOB_URL"] == f"{STORAGE}/dev" and env["DBUI_BLOB"].startswith("snapshots/payments_dev/20261023T140000Z-") and env["DBUI_NAMESPACE"] == "dev-payments" + meta_out = json.loads(env["DBUI_METADATA"]) + assert meta_out["createdby"] == "alice@example.com" and meta_out["namespace"] == "dev-payments" # Workload identity: the Job exchanges its own projected token, nothing stored. assert env["AZURE_CLIENT_ID"] == "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee" and env["AZURE_FEDERATED_TOKEN_FILE"].endswith("/azure-identity-token") volumes = {v["name"]: v for v in pod["volumes"]} assert volumes["ca"]["secret"] == {"secretName": "dev-ca", "defaultMode": 0o440, "items": [{"key": "ca.crt", "path": "ca.crt"}]} assert volumes["azure-identity-token"]["projected"]["sources"][0]["serviceAccountToken"]["audience"] == "api://AzureADTokenExchange" - assert [(e["action"], e["actor"], e["database"]) for e in world.storage.audit("dev")] == [("snapshot.requested", "alice@example.com", "payments_dev")] - body = response.json() - assert body["state"] == "starting" and body["note"] == "before the 2.4 migration" + assert [(e["action"], e["actor"], e["database"], e["namespace"]) for e in world.storage.audit("dev")] == [("snapshot.requested", "alice@example.com", "payments_dev", "dev-payments")] + assert response.json()["state"] == "starting" and response.json()["namespace"] == "dev-payments" + + +def test_a_storage_identity_of_its_own(world, env): + client = make_client(world, {**env, "DATABASES_UI_STORAGE_CLIENT_ID": "cccccccc-bbbb-cccc-dddd-eeeeeeeeeeee"}) + me = sign_in(client, world) + client.post("/api/environments/dev/databases/payments_dev/snapshots", json={}, headers=write_headers(me)) + assert env_of(only_job(world))["AZURE_CLIENT_ID"] == "cccccccc-bbbb-cccc-dddd-eeeeeeeeeeee" + storage = [r for r in world.entra.token_requests if r["grant_type"] == ["client_credentials"]] + assert storage[0]["client_id"] == ["cccccccc-bbbb-cccc-dddd-eeeeeeeeeeee"] and storage[0]["client_assertion"] == ["federated-token"] def test_a_database_with_a_job_in_flight_is_busy(client, world): @@ -102,12 +152,16 @@ def test_a_database_with_a_job_in_flight_is_busy(client, world): def test_who_may_act(client, world): - me = sign_in(client, world, upn="carol@example.com", groups=[IDENTITY]) - assert client.post("/api/environments/dev/databases/payments_dev/snapshots", json={}, headers=write_headers(me)).status_code == 403 + me = sign_in(client, world, "vera@example.com") + refused = client.post("/api/environments/dev/databases/payments_dev/snapshots", json={}, headers=write_headers(me)) + assert refused.status_code == 403 and "get secrets in the namespace dev-payments" in refused.json()["message"] + # Outside your namespaces a database does not exist. + me = sign_in(client, world, "carol@example.com") + assert client.post("/api/environments/dev/databases/payments_dev/snapshots", json={}, headers=write_headers(me)).status_code == 404 assert client.post("/api/environments/dev/databases/keycloak/snapshots", json={}, headers=write_headers(me)).status_code == 201 - me = sign_in(client, world, upn="audrey@example.com", groups=[], roles=["Auditor"]) + me = sign_in(client, world, "audrey@example.com") assert client.post("/api/environments/dev/databases/payments_dev/snapshots", json={}, headers=write_headers(me)).status_code == 403 - me = sign_in(client, world, upn="root@example.com", groups=[], roles=["Admin"]) + me = sign_in(client, world, "root@example.com") response = client.post("/api/environments/dev/databases/platform_only/snapshots", json={}, headers=write_headers(me)) assert response.status_code == 409 and response.json()["error"] == "no_credential" assert client.post("/api/environments/dev/databases/gone/snapshots", json={}, headers=write_headers(me)).status_code == 404 @@ -124,53 +178,64 @@ def test_writes_need_the_csrf_token_and_this_origin(client, world): def test_snapshots_list_newest_first_and_only_well_formed(client, world): - world.snapshot("dev", "payments_dev", "20261020T080000Z-aaaaaa") - world.snapshot("dev", "payments_dev", "20261022T080000Z-bbbbbb", note="na%C3%AFve") + world.snapshot("dev", "payments_dev", "20261020T080000Z-aaaaaa", namespace="dev-payments") + world.snapshot("dev", "payments_dev", "20261022T080000Z-bbbbbb", note="na%C3%AFve", sharedwith="tst/tst-payments") world.storage.blobs["dev/snapshots/payments_dev/stray.txt"] = world.storage.blobs["dev/snapshots/payments_dev/20261020T080000Z-aaaaaa.dump"] world.storage.page = 1 # every blob on its own page - sign_in(client, world) + sign_in(client, world, "vera@example.com") found = client.get("/api/environments/dev/databases/payments_dev/snapshots").json()["snapshots"] assert [s["id"] for s in found] == ["20261022T080000Z-bbbbbb", "20261020T080000Z-aaaaaa"] - assert found[0]["note"] == "naïve" and found[0]["size"] == len(b"PGDMP-test") and found[0]["created_by"] == "alice@example.com" - assert client.get("/api/environments/dev/databases/keycloak/snapshots").status_code == 403 + assert found[0]["note"] == "naïve" and found[0]["shared_with"] == ["tst/tst-payments"] and found[1]["namespace"] == "dev-payments" + assert client.get("/api/environments/dev/databases/keycloak/snapshots").status_code == 404 -def test_restore_in_place_scales_the_catalogs_workloads(client, world): +def test_restore_in_place_scales_the_annotated_workloads(client, world): world.snapshot("dev", "payments_dev", "20261022T080000Z-bbbbbb") me = sign_in(client, world) - body = {"source_environment": "dev", "source_database": "payments_dev", "snapshot": "20261022T080000Z-bbbbbb", "into": "database", "reason": "undo the bad batch"} - response = client.post("/api/environments/dev/databases/payments_dev/restore", json=body, headers=write_headers(me)) + response = client.post("/api/environments/dev/databases/payments_dev/restore", json=RESTORE, headers=write_headers(me)) assert response.status_code == 201, response.text job = only_job(world) env = env_of(job) assert job["spec"]["suspend"] is False and job["spec"]["template"]["spec"]["automountServiceAccountToken"] is True - assert json.loads(env["DBUI_SCALE"]) == [["deployment", "dev-payments", "api"]] + assert json.loads(env["DBUI_SCALE"]) == [["deployment", "dev-payments", "api"], ["statefulset", "dev-payments", "worker"]] assert env["DBUI_BLOB"] == "snapshots/payments_dev/20261022T080000Z-bbbbbb.dump" and env["PGDATABASE"] == "payments_dev" - assert "DBUI_WAIT_FOR_DATABASE" not in env - assert job["metadata"]["annotations"]["databases-ui/reason"] == "undo the bad batch" + assert "DBUI_WAIT_FOR_DATABASE" not in env and job["metadata"]["annotations"]["databases-ui/reason"] == "undo the bad batch" assert world.storage.audit("dev")[-1]["action"] == "restore.requested" + me = sign_in(client, world, "vera@example.com") + assert client.post("/api/environments/dev/databases/payments_dev/restore", json=RESTORE, headers=write_headers(me)).status_code == 403 + + +def test_a_bad_workloads_annotation_stops_a_restore_in_place(client, world): + world.snapshot("dev", "payments_dev", "20261022T080000Z-bbbbbb") + world.kube.get(f"{CNPG}/databases", "payments-dev")["metadata"]["annotations"]["databases-ui/workloads"] = "deployment/api, pod/x" + me = sign_in(client, world) + assert client.get("/api/environments/dev/databases").json()["databases"][0]["workloads"] == [] + response = client.post("/api/environments/dev/databases/payments_dev/restore", json=RESTORE, headers=write_headers(me)) + assert response.status_code == 409 and response.json()["error"] == "bad_workloads" def test_restore_into_a_copy_makes_a_database_resource(client, world): world.snapshot("dev", "payments_dev", "20261022T080000Z-bbbbbb") me = sign_in(client, world) - body = {"source_environment": "dev", "source_database": "payments_dev", "snapshot": "20261022T080000Z-bbbbbb", "into": "copy", "reason": "look at old rows"} + body = {**RESTORE, "into": "copy", "reason": "look at old rows"} assert client.post("/api/environments/dev/databases/payments_dev/restore", json=body, headers=write_headers(me)).status_code == 201 copy = world.kube.get(f"{CNPG}/databases", "payments-dev-copy") - assert copy["metadata"]["labels"] == {"app.kubernetes.io/managed-by": "databases-ui", "databases-ui/environment": "dev", "databases-ui/copy-of": "payments_dev"} + assert copy["metadata"]["labels"] == {"app.kubernetes.io/managed-by": "databases-ui", "databases-ui/environment": "dev", "databases-ui/copy-of": "payments_dev", "databases-ui/namespace": "dev-payments"} assert copy["spec"] == {"name": "payments_dev_copy", "owner": "payments_dev", "cluster": {"name": "dev"}, "ensure": "present", "databaseReclaimPolicy": "delete", "extensions": [{"name": "citext"}]} env = env_of(only_job(world)) assert env["PGDATABASE"] == "payments_dev_copy" and env["DBUI_WAIT_FOR_DATABASE"] == "1" and "DBUI_SCALE" not in env finish(world, only_job(world)["metadata"]["name"]) listed = client.get("/api/environments/dev/databases").json()["databases"] assert [d["name"] for d in listed] == ["payments_dev"] and listed[0]["copy"] == {"name": "payments_dev_copy", "ready": False} - # Again: the same copy is reused. assert client.post("/api/environments/dev/databases/payments_dev/restore", json=body, headers=write_headers(me)).status_code == 201 assert len([d for d in world.kube.objects[f"{CNPG}/databases"] if d.endswith("-copy")]) == 1 # Dropping it waits for the restore, then deletes the resource, which drops the database. assert client.delete("/api/environments/dev/databases/payments_dev/copy", headers=write_headers(me)).status_code == 409 for name in list(world.kube.objects[JOBS]): finish(world, name) + vera = sign_in(client, world, "vera@example.com") + assert client.delete("/api/environments/dev/databases/payments_dev/copy", headers=write_headers(vera)).status_code == 403 + me = sign_in(client, world) assert client.delete("/api/environments/dev/databases/payments_dev/copy", headers=write_headers(me)).status_code == 204 assert world.kube.get(f"{CNPG}/databases", "payments-dev-copy") is None assert client.delete("/api/environments/dev/databases/payments_dev/copy", headers=write_headers(me)).status_code == 404 @@ -181,69 +246,103 @@ def test_a_copy_name_this_app_did_not_make_is_left_alone(client, world): world.snapshot("dev", "payments_dev", "20261022T080000Z-bbbbbb") world.kube.put(f"{CNPG}/databases", {"metadata": {"name": "payments-dev-copy", "labels": {}}, "spec": {"name": "someone_elses", "owner": "x", "cluster": {"name": "dev"}}}) me = sign_in(client, world) - body = {"source_environment": "dev", "source_database": "payments_dev", "snapshot": "20261022T080000Z-bbbbbb", "into": "copy", "reason": "look at old rows"} - response = client.post("/api/environments/dev/databases/payments_dev/restore", json=body, headers=write_headers(me)) + response = client.post("/api/environments/dev/databases/payments_dev/restore", json={**RESTORE, "into": "copy"}, headers=write_headers(me)) assert response.status_code == 409 and response.json()["error"] == "copy_taken" -def test_clone_only_from_listed_environments_and_existing_snapshots(client, world): - world.snapshot("acc", "payments_acc", "20261021T080000Z-cccccc") - world.snapshot("prd", "payments_prd", "20261021T080000Z-dddddd") +def test_sharing_hands_a_snapshot_to_a_namespace_in_another_environment(client, world): + world.snapshot("dev", "payments_dev", "20261022T080000Z-bbbbbb") me = sign_in(client, world) + path = "/api/environments/dev/databases/payments_dev/snapshots/20261022T080000Z-bbbbbb/share" + shared = client.post(path, json={"environment": "tst", "namespace": "tst-payments"}, headers=write_headers(me)) + assert shared.status_code == 200 and shared.json()["shared_with"] == ["tst/tst-payments"] + again = client.post(path, json={"environment": "tst", "namespace": "tst-other"}, headers=write_headers(me)).json() + assert again["shared_with"] == ["tst/tst-other", "tst/tst-payments"] + blob = world.storage.blobs["dev/snapshots/payments_dev/20261022T080000Z-bbbbbb.dump"] + assert blob.metadata["sharedwith"] == "tst%2Ftst-other%20tst%2Ftst-payments" and blob.metadata["createdby"] == "alice%40example.com" + assert world.storage.audit("dev")[-1] | {"at": ""} == { + "at": "", "environment": "dev", "actor": "alice@example.com", "action": "snapshot.shared", "database": "payments_dev", "namespace": "dev-payments", + "snapshot": "snapshots/payments_dev/20261022T080000Z-bbbbbb.dump", "target": "tst/tst-other", + } # fmt: skip + # prd takes nothing from dev; a namespace must be one; only who may snapshot shares. + assert client.post(path, json={"environment": "prd", "namespace": "prd-payments"}, headers=write_headers(me)).json()["error"] == "no_clone" + assert client.post(path, json={"environment": "tst", "namespace": "Not_A_Namespace"}, headers=write_headers(me)).status_code == 422 + assert client.post(path.replace("bbbbbb", "ffffff"), json={"environment": "tst", "namespace": "tst-payments"}, headers=write_headers(me)).status_code == 404 + vera = sign_in(client, world, "vera@example.com") + assert client.post(path, json={"environment": "tst", "namespace": "tst-payments"}, headers=write_headers(vera)).status_code == 403 + + +def test_clone_only_what_was_shared_with_the_namespace(client, world): + world.snapshot("acc", "payments_acc", "20261021T080000Z-cccccc", sharedwith="dev/dev-payments") + world.snapshot("acc", "payments_acc", "20261021T090000Z-eeeeee", sharedwith="dev/dev-identity") + world.snapshot("acc", "payments_acc", "20261021T100000Z-ffffff") + me = sign_in(client, world) + shared = client.get("/api/environments/dev/databases/payments_dev/shared").json()["snapshots"] + assert [(s["environment"], s["database"], s["id"]) for s in shared] == [("acc", "payments_acc", "20261021T080000Z-cccccc")] body = {"source_environment": "acc", "source_database": "payments_acc", "snapshot": "20261021T080000Z-cccccc", "into": "database", "reason": "reproduce the acc bug"} response = client.post("/api/environments/dev/databases/payments_dev/restore", json=body, headers=write_headers(me)) assert response.status_code == 201, response.text env = env_of(only_job(world)) # The snapshot is read from acc's container; the outcome is written to dev's audit log. - assert env["DBUI_BLOB_URL"] == f"{STORAGE}/acc" and env["DBUI_AUDIT_URL"] == f"{STORAGE}/dev" - assert response.json()["source_environment"] == "acc" + assert env["DBUI_BLOB_URL"] == f"{STORAGE}/acc" and env["DBUI_AUDIT_URL"] == f"{STORAGE}/dev" and response.json()["source_environment"] == "acc" finish(world, only_job(world)["metadata"]["name"]) - # prd does not take dev's snapshots. - body = {"source_environment": "dev", "source_database": "payments_dev", "snapshot": "20261021T080000Z-cccccc", "into": "database", "reason": "nope nope"} - assert client.post("/api/environments/prd/databases/payments_prd/restore", json=body, headers=write_headers(me)).json()["error"] == "no_clone" - missing = {**body, "source_environment": "acc", "source_database": "payments_acc", "snapshot": "20261021T080000Z-ffffff"} - assert client.post("/api/environments/dev/databases/payments_dev/restore", json=missing, headers=write_headers(me)).status_code == 404 - carol = sign_in(client, world, upn="carol@example.com", groups=[IDENTITY]) - theirs = {**body, "source_environment": "acc", "source_database": "payments_acc", "snapshot": "20261021T080000Z-cccccc"} - assert client.post("/api/environments/dev/databases/keycloak/restore", json=theirs, headers=write_headers(carol)).status_code == 403 - assert client.post("/api/environments/dev/databases/keycloak/restore", json={**theirs, "into": "everywhere"}, headers=write_headers(carol)).status_code == 422 + for sid in ("20261021T090000Z-eeeeee", "20261021T100000Z-ffffff"): + refused = client.post("/api/environments/dev/databases/payments_dev/restore", json={**body, "snapshot": sid}, headers=write_headers(me)) + assert refused.status_code == 403 and refused.json()["error"] == "not_shared" + missing = client.post("/api/environments/dev/databases/payments_dev/restore", json={**body, "snapshot": "20261021T080000Z-000000"}, headers=write_headers(me)) + assert missing.status_code == 404 + # prd takes no snapshots from dev; another of dev's own databases takes what snapshotting it takes. + world.snapshot("dev", "payments_dev", "20261022T080000Z-bbbbbb") + assert client.post("/api/environments/prd/databases/payments_prd/restore", json=RESTORE, headers=write_headers(me)).json()["error"] == "no_clone" + world.snapshot("dev", "keycloak", "20261022T080000Z-bbbbbb") + other = {**RESTORE, "source_database": "keycloak"} + assert client.post("/api/environments/dev/databases/payments_dev/restore", json=other, headers=write_headers(me)).status_code == 404 + carol = sign_in(client, world, "carol@example.com") + assert client.get("/api/environments/dev/databases/payments_dev/shared").status_code == 404 + assert client.post("/api/environments/dev/databases/keycloak/restore", json={**body, "into": "everywhere"}, headers=write_headers(carol)).status_code == 422 def test_a_production_restore_waits_for_a_second_person(world, env): world.snapshot("prd", "payments_prd", "20261021T080000Z-dddddd") - alice, bob, carol = (make_client(world, env) for _ in range(3)) + alice, bob, pat, carol = (make_client(world, env) for _ in range(4)) a = sign_in(alice, world) - b = sign_in(bob, world, upn="bob@example.com") - c = sign_in(carol, world, upn="carol@example.com", groups=[IDENTITY]) - body = {"source_environment": "prd", "source_database": "payments_prd", "snapshot": "20261021T080000Z-dddddd", "into": "database", "reason": "after the bad deploy"} - asked = alice.post("/api/environments/prd/databases/payments_prd/restore", json=body, headers=write_headers(a)).json() + b = sign_in(bob, world, "bob@example.com") + p = sign_in(pat, world, "pat@example.com") + c = sign_in(carol, world, "carol@example.com") + refused = pat.post("/api/environments/prd/databases/payments_prd/restore", json=PRD, headers=write_headers(p)) + assert refused.status_code == 403 and "create rolebindings.rbac.authorization.k8s.io" in refused.json()["message"] + asked = alice.post("/api/environments/prd/databases/payments_prd/restore", json=PRD, headers=write_headers(a)).json() job = only_job(world) - assert job["spec"]["suspend"] is True and asked["state"] == "waiting" and asked["approval"] == "required" + assert job["spec"]["suspend"] is True and asked["state"] == "waiting" and asked["approval"] == "required" and asked["can_decline"] is True name = job["metadata"]["name"] seen = {j["name"]: j for j in alice.get("/api/environments/prd/jobs").json()["jobs"]} assert seen[name]["can_approve"] is False and seen[name]["can_decline"] is True assert bob.get("/api/environments/prd/jobs").json()["jobs"][0]["can_approve"] is True + assert pat.get("/api/environments/prd/jobs").json()["jobs"][0]["can_approve"] is False assert carol.get("/api/environments/prd/jobs").json()["jobs"] == [] assert alice.post(f"/api/environments/prd/jobs/{name}/approve", headers=write_headers(a)).json()["error"] == "own_request" + assert pat.post(f"/api/environments/prd/jobs/{name}/approve", headers=write_headers(p)).status_code == 403 assert carol.post(f"/api/environments/prd/jobs/{name}/approve", headers=write_headers(c)).status_code == 403 approved = bob.post(f"/api/environments/prd/jobs/{name}/approve", headers=write_headers(b)) assert approved.status_code == 200 and approved.json()["approved_by"] == "bob@example.com" assert world.kube.get(JOBS, name)["spec"]["suspend"] is False assert bob.post(f"/api/environments/prd/jobs/{name}/approve", headers=write_headers(b)).json()["error"] == "not_waiting" - assert [e["action"] for e in world.storage.audit("prd")] == ["restore.requested", "restore.approved"] + assert [(e["action"], e["namespace"]) for e in world.storage.audit("prd")] == [("restore.requested", "prd-payments"), ("restore.approved", "prd-payments")] def test_a_waiting_restore_can_be_declined_or_withdrawn(world, env): world.snapshot("prd", "payments_prd", "20261021T080000Z-dddddd") - alice, bob = make_client(world, env), make_client(world, env) - a, b = sign_in(alice, world), sign_in(bob, world, upn="bob@example.com") - body = {"source_environment": "prd", "source_database": "payments_prd", "snapshot": "20261021T080000Z-dddddd", "into": "database", "reason": "after the bad deploy"} - alice.post("/api/environments/prd/databases/payments_prd/restore", json=body, headers=write_headers(a)) + alice, bob, pat = make_client(world, env), make_client(world, env), make_client(world, env) + a, b, p = sign_in(alice, world), sign_in(bob, world, "bob@example.com"), sign_in(pat, world, "pat@example.com") + alice.post("/api/environments/prd/databases/payments_prd/restore", json=PRD, headers=write_headers(a)) name = only_job(world)["metadata"]["name"] + assert pat.post(f"/api/environments/prd/jobs/{name}/decline", json={}, headers=write_headers(p)).status_code == 403 assert bob.post(f"/api/environments/prd/jobs/{name}/decline", json={"reason": "not during the release"}, headers=write_headers(b)).status_code == 204 assert world.kube.objects[JOBS] == {} - assert world.storage.audit("prd")[-1] | {"at": ""} == {"at": "", "environment": "prd", "actor": "bob@example.com", "action": "restore.declined", "database": "payments_prd", "job": name, "detail": "not during the release"} - alice.post("/api/environments/prd/databases/payments_prd/restore", json=body, headers=write_headers(a)) + assert world.storage.audit("prd")[-1] | {"at": ""} == { + "at": "", "environment": "prd", "actor": "bob@example.com", "action": "restore.declined", "database": "payments_prd", "namespace": "prd-payments", "job": name, "detail": "not during the release", + } # fmt: skip + alice.post("/api/environments/prd/databases/payments_prd/restore", json=PRD, headers=write_headers(a)) name = only_job(world)["metadata"]["name"] assert alice.post(f"/api/environments/prd/jobs/{name}/decline", json={}, headers=write_headers(a)).status_code == 204 assert bob.post(f"/api/environments/prd/jobs/{name}/decline", json={}, headers=write_headers(b)).status_code == 404 @@ -252,14 +351,13 @@ def test_a_waiting_restore_can_be_declined_or_withdrawn(world, env): def test_requests_expire_after_a_day(world, env): world.snapshot("prd", "payments_prd", "20261021T080000Z-dddddd") alice, bob = make_client(world, env), make_client(world, env) - a, b = sign_in(alice, world), sign_in(bob, world, upn="bob@example.com") - body = {"source_environment": "prd", "source_database": "payments_prd", "snapshot": "20261021T080000Z-dddddd", "into": "database", "reason": "after the bad deploy"} - alice.post("/api/environments/prd/databases/payments_prd/restore", json=body, headers=write_headers(a)) + a, b = sign_in(alice, world), sign_in(bob, world, "bob@example.com") + alice.post("/api/environments/prd/databases/payments_prd/restore", json=PRD, headers=write_headers(a)) job = only_job(world) job["metadata"]["annotations"]["databases-ui/requested-at"] = "2026-10-22T13:00:00Z" assert bob.post(f"/api/environments/prd/jobs/{job['metadata']['name']}/approve", headers=write_headers(b)).json()["error"] == "expired" # Expired, it no longer blocks the database, and the next listing clears it away. - assert alice.post("/api/environments/prd/databases/payments_prd/restore", json=body, headers=write_headers(a)).status_code == 201 + assert alice.post("/api/environments/prd/databases/payments_prd/restore", json=PRD, headers=write_headers(a)).status_code == 201 assert len(alice.get("/api/environments/prd/jobs").json()["jobs"]) == 1 assert job["metadata"]["name"] not in world.kube.objects[JOBS] assert "restore.expired" in [e["action"] for e in world.storage.audit("prd")] @@ -274,7 +372,7 @@ def test_jobs_show_what_their_pods_reported(client, world): finish(world, name, ok=False, message={"result": "failed", "reason": "pg_dump exited 1: permission denied for table x"}) job = client.get("/api/environments/dev/jobs").json()["jobs"][0] assert job["state"] == "failed" and job["result"]["reason"].endswith("permission denied for table x") and job["finished"] == "2026-10-23T14:05:00Z" - sign_in(client, world, upn="carol@example.com", groups=[IDENTITY]) + sign_in(client, world, "carol@example.com") assert client.get("/api/environments/dev/jobs").json()["jobs"] == [] assert client.get("/api/environments/acc/jobs").json()["jobs"] == [] @@ -289,22 +387,25 @@ def test_downloads_stream_outside_production_only(client, world): assert world.storage.audit("dev")[-1]["action"] == "snapshot.downloaded" assert client.get("/api/environments/prd/databases/payments_prd/snapshots/20261021T080000Z-dddddd/download").json()["error"] == "no_downloads" assert client.get("/api/environments/dev/databases/payments_dev/snapshots/20261022T080000Z-ffffff/download").status_code == 404 - sign_in(client, world, upn="audrey@example.com", groups=[], roles=["Auditor"]) - assert client.get("/api/environments/dev/databases/payments_dev/snapshots/20261022T080000Z-bbbbbb/download").status_code == 403 + for person in ("vera@example.com", "audrey@example.com"): + sign_in(client, world, person) + assert client.get("/api/environments/dev/databases/payments_dev/snapshots/20261022T080000Z-bbbbbb/download").status_code == 403 -def test_the_audit_log_shows_your_databases(client, world): +def test_the_audit_log_follows_the_namespaces(client, world): me = sign_in(client, world) client.post("/api/environments/dev/databases/payments_dev/snapshots", json={"note": "one"}, headers=write_headers(me)) finish(world, only_job(world)["metadata"]["name"]) - carol = sign_in(client, world, upn="carol@example.com", groups=[IDENTITY]) + carol = sign_in(client, world, "carol@example.com") client.post("/api/environments/dev/databases/keycloak/snapshots", json={}, headers=write_headers(carol)) - world.storage.blobs["dev/audit/2026-09.jsonl"] = type(world.storage.blobs["dev/audit/2026-10.jsonl"])(b'{"at":"2026-09-01T00:00:00Z","action":"old","database":"keycloak"}\nnot json\n', {}, "") - assert [e["action"] for e in client.get("/api/environments/dev/audit").json()["entries"]] == ["snapshot.requested", "old"] + world.storage.blobs["dev/audit/2026-09.jsonl"] = type(world.storage.blobs["dev/audit/2026-10.jsonl"])(b'{"at":"2026-09-01T00:00:00Z","action":"old","database":"x"}\nnot json\n', {}, "") + assert [e["action"] for e in client.get("/api/environments/dev/audit").json()["entries"]] == ["snapshot.requested"] sign_in(client, world) assert [(e["action"], e["database"]) for e in client.get("/api/environments/dev/audit").json()["entries"]] == [("snapshot.requested", "payments_dev")] - sign_in(client, world, upn="audrey@example.com", groups=[], roles=["Auditor"]) + # Entries without a namespace are the platform's. + sign_in(client, world, "audrey@example.com") assert len(client.get("/api/environments/dev/audit").json()["entries"]) == 3 + assert client.get("/api/environments/acc/audit").json()["entries"] == [] def test_storage_and_kubernetes_errors_answer_502(client, world): diff --git a/tests/test_auth.py b/tests/test_auth.py index 9157a12..32600f7 100644 --- a/tests/test_auth.py +++ b/tests/test_auth.py @@ -2,15 +2,7 @@ from urllib.parse import parse_qs, urlsplit -from conftest import ( - CLIENT, - IDENTITY, - PAYMENTS, - UNRELATED, - make_client, - sign_in, - write_headers, -) +from conftest import CLIENT, make_client, sign_in, write_headers from databases_ui.app import favicon_svg, release_notes, theme_css from databases_ui.config import Branding @@ -21,22 +13,38 @@ def test_signed_out_until_signed_in(client): assert client.get("/api/environments/dev/databases").status_code == 401 -def test_sign_in_keeps_only_the_catalogs_groups(client, world): - me = sign_in(client, world, groups=[PAYMENTS, IDENTITY, UNRELATED], roles=["Admin"]) - assert [t["id"] for t in me["teams"]] == ["payments", "identity"] and me["admin"] and not me["auditor"] +def test_sign_in_names_the_person_as_the_api_server_does(client, world): + me = sign_in(client, world, "Alice.Smith@Example.com", groups=["k8s-dev-payments-write", "k8s-prd-payments-admin"]) + # The claim as it is, prefixed: no lowercasing, or RBAC would know someone else. + assert me["kubernetes"] == {"user": "oidc:Alice.Smith@Example.com", "groups": ["oidc:k8s-dev-payments-write", "oidc:k8s-prd-payments-admin"]} login = world.entra.token_requests[-1] assert login["grant_type"] == ["authorization_code"] and login["client_assertion"] == ["federated-token"] and login["client_id"] == [CLIENT] + assert login["scope"] == ["openid profile"] cookie = next(c for c in client.cookies.jar if c.name.startswith("__Host-databases-ui")) assert cookie.secure and cookie.path == "/" +def test_the_claims_and_prefixes_follow_the_cluster(world, env): + client = make_client(world, {**env, "DATABASES_UI_GROUPS_CLAIM": "roles", "DATABASES_UI_GROUPS_PREFIX": "", "DATABASES_UI_USERNAME_PREFIX": "entra#"}) + world.entra.extra = {"roles": ["k8s-dev-payments-read"]} + assert sign_in(client, world, groups=[])["kubernetes"] == {"user": "entra#alice@example.com", "groups": ["k8s-dev-payments-read"]} + + +def test_a_token_without_the_username_claim_is_refused(world, env): + client = make_client(world, {**env, "DATABASES_UI_USERNAME_CLAIM": "upn"}) + response = client.get("/auth/login") + query = parse_qs(urlsplit(response.headers["location"]).query) + world.entra.challenge, world.entra.nonce = query["code_challenge"][0], query["nonce"][0] + assert "has+no+upn" in client.get(f"/auth/callback?code=good-code&state={query['state'][0]}").headers["location"] + + def test_a_sign_in_with_too_many_groups_is_refused(client, world): world.entra.overage = True response = client.get("/auth/login") query = parse_qs(urlsplit(response.headers["location"]).query) world.entra.challenge, world.entra.nonce = query["code_challenge"][0], query["nonce"][0] done = client.get(f"/auth/callback?code=good-code&state={query['state'][0]}") - assert "auth_error=" in done.headers["location"] and "groups+do+not+fit" in done.headers["location"] + assert "auth_error=" in done.headers["location"] and "do+not+fit+in+the+ID+token" in done.headers["location"] def test_another_tenant_a_bad_state_and_a_refusal(client, world): diff --git a/tests/test_catalog.py b/tests/test_catalog.py index 1a4c978..38fac3e 100644 --- a/tests/test_catalog.py +++ b/tests/test_catalog.py @@ -5,27 +5,32 @@ import pytest from databases_ui.__main__ import check -from databases_ui.catalog import CatalogError, load_catalog +from databases_ui.catalog import ( + RESTORE, + RESTORE_PRODUCTION, + CatalogError, + Check, + load_catalog, +) EXAMPLE = Path(__file__).resolve().parents[1] / "examples" / "catalog.yaml" -GROUP = "6f1c2b7e-3a44-4d0e-9a51-2b8e0c7d9f10" -ENVS = "environments:\n - {name: dev, storage: {url: 'https://a.blob.core.windows.net/dev'}}\n - {name: prd, production: true, cluster: prod, storage: {url: 'https://a.blob.core.windows.net/prd'}}\n" +DEV = " - {name: dev, storage: {url: 'https://a.blob.core.windows.net/dev'}}\n" def test_the_example_holds_together(capsys): assert check(EXAMPLE) == 0 - assert "4 environments, 2 teams, 8 databases granted" in capsys.readouterr().out + assert "4 environments, dev in this cluster" in capsys.readouterr().out catalog = load_catalog(EXAMPLE.read_text()) assert catalog.environments["prd"].cnpg_cluster == "prod" and catalog.environments["dev"].cnpg_cluster == "dev" - grant = catalog.grant({"payments"}, "acc", "payments_acc") - assert grant is not None and grant.workloads == (("deployment", "acc-payments", "payments-api"), ("deployment", "acc-payments", "payments-worker")) - assert sorted(catalog.databases("prd")) == ["keycloak_prd", "payments_prd"] - assert catalog.grant({"identity"}, "prd", "keycloak") is None + assert [e.name for e in catalog.environments.values() if e.runs_jobs] == ["dev"] + assert catalog.cloning_from("acc") == ["dev", "tst"] and catalog.cloning_from("prd") == [] -def test_groups_select_teams(): - catalog = load_catalog(ENVS + f"teams:\n - {{id: a, name: A, groups: ['{GROUP.upper()}']}}\n") - assert catalog.groups == {GROUP} and [t.id for t in catalog.teams_of(frozenset({GROUP}))] == ["a"] +def test_access_defaults_and_overrides(): + catalog = load_catalog("environments:\n" + DEV + " - name: prd\n production: true\n storage: {url: 'https://a.blob.core.windows.net/prd'}\n access:\n read: {verb: get, resource: deployments/scale, group: apps}\n") + dev, prd = catalog.environments["dev"], catalog.environments["prd"] + assert dev.check("restore") == RESTORE and prd.check("restore") == RESTORE_PRODUCTION + assert prd.check("read") == Check(verb="get", resource="deployments/scale", group="apps") @pytest.mark.parametrize( @@ -38,15 +43,12 @@ def test_groups_select_teams(): ("environments:\n - {name: dev, storage: {url: 'https://a.blob.core.windows.net'}}\n", "the container's URL"), ("environments:\n - {name: dev, storage: {url: 'http://azurite.storage.svc:10000/acct/dev'}, kubernetes: elsewhere}\n", "kubernetes"), # DevSkim: ignore DS137138 - a local emulator's address ("environments:\n - {name: Dev, storage: {url: 'https://a.blob.core.windows.net/x'}}\n", "name"), - (ENVS + " - {name: dev, storage: {url: 'https://a.blob.core.windows.net/x'}}\n", "'dev' is listed twice"), + ("environments:\n" + DEV + DEV, "'dev' is listed twice"), ("environments:\n - {name: dev, cloneFrom: [acc], storage: {url: 'https://a.blob.core.windows.net/x'}}\n", "unknown environment 'acc'"), ("environments:\n - {name: dev, cloneFrom: [dev], storage: {url: 'https://a.blob.core.windows.net/x'}}\n", "lists itself"), - (ENVS + "teams:\n - {id: a, name: A, groups: [not-a-guid]}\n", "not a group object id"), - (ENVS + f"teams:\n - {{id: a, name: A, groups: ['{GROUP}']}}\n - {{id: a, name: B, groups: ['{GROUP}']}}\n", "team 'a' is listed twice"), - (ENVS + f"teams:\n - {{id: a, name: A, groups: ['{GROUP}'], databases: [{{name: x, environments: [qa]}}]}}\n", "unknown environment 'qa'"), - (ENVS + f"teams:\n - {{id: a, name: A, groups: ['{GROUP}'], databases: [{{name: 'Bad Name'}}]}}\n", "not a database name"), - (ENVS + f"teams:\n - {{id: a, name: A, groups: ['{GROUP}'], databases: [{{name: x, workloads: [pod/a/b]}}]}}\n", "deployment//"), - (ENVS + f"teams:\n - {{id: a, name: A, groups: ['{GROUP}'], extra: 1}}\n", "extra"), + ("environments:\n - {name: dev, kubernetes: none, storage: {url: 'https://a.blob.core.windows.net/x'}}\n", "no environment runs here"), + ("environments:\n - {name: dev, storage: {url: 'https://a.blob.core.windows.net/x'}, access: {restore: {verb: 'Get', resource: secrets}}}\n", "verb"), + ("environments:\n - {name: dev, storage: {url: 'https://a.blob.core.windows.net/x'}, teams: []}\n", "teams"), ], ) def test_problems_are_named(text, problem): @@ -55,14 +57,8 @@ def test_problems_are_named(text, problem): assert any(problem in p for p in err.value.problems), err.value.problems -def test_another_cluster_is_reached_with_its_own_token(): - catalog = load_catalog("environments:\n - name: dev\n storage: {url: 'https://a.blob.core.windows.net/dev'}\n kubernetes: {server: 'https://dev.example.test:6443', caFile: /ca.crt, tokenFile: /token}\n") - kube = catalog.environments["dev"].kubernetes - assert kube.server == "https://dev.example.test:6443" and kube.token_file == "/token" and catalog.environments["dev"].runs_jobs - - def test_check_reports_every_problem(tmp_path, capsys): - (tmp_path / "bad.yaml").write_text(ENVS + "teams:\n - {id: a, name: A, groups: [x]}\n") + (tmp_path / "bad.yaml").write_text("environments:\n" + DEV + DEV) assert check(tmp_path / "bad.yaml") == 1 - assert "not a group object id" in capsys.readouterr().err + assert "listed twice" in capsys.readouterr().err assert check(tmp_path / "missing.yaml") == 1 diff --git a/tests/test_config.py b/tests/test_config.py index b6f6966..1ae638a 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -8,7 +8,8 @@ def test_a_complete_environment_loads(env): cfg = load_config(env) assert cfg.redirect_uri == "https://databases.example.test/auth/callback" and cfg.secure_cookies - assert sorted(cfg.catalog.environments) == ["acc", "dev", "prd"] and cfg.job_service_account == "databases-ui-job" + assert sorted(cfg.catalog.environments) == ["acc", "dev", "prd", "tst"] and cfg.job_service_account == "databases-ui-job" + assert (cfg.username_claim, cfg.username_prefix, cfg.groups_claim, cfg.groups_prefix) == ("preferred_username", "oidc:", "groups", "oidc:") assert cfg.storage_sas == "" and cfg.static_dir is None and cfg.session_seconds == 8 * 3600 @@ -29,7 +30,10 @@ def test_a_complete_environment_loads(env): ({"DATABASES_UI_STORAGE_SAS": "sv=2022-11-02", "DATABASES_UI_STORAGE_SAS_SECRET": "sas/token"}, "a SAS token"), ({"DATABASES_UI_STORAGE_SAS": "sv=2022-11-02&sig=x", "DATABASES_UI_STORAGE_SAS_SECRET": "no-key"}, "/"), ({"AZURE_FEDERATED_TOKEN_FILE": "", "AZURE_CLIENT_SECRET": "s"}, "the Jobs reach storage through workload identity"), - ({"DATABASES_UI_ADMIN_ROLE": "has spaces"}, "DATABASES_UI_ADMIN_ROLE must be an app role value"), + ({"DATABASES_UI_STORAGE_CLIENT_ID": "not-a-guid"}, "DATABASES_UI_STORAGE_CLIENT_ID must be a GUID"), + ({"DATABASES_UI_NAMESPACE_LABEL": "not a label"}, "DATABASES_UI_NAMESPACE_LABEL must be a label key"), + ({"DATABASES_UI_USERNAME_CLAIM": "has spaces"}, "DATABASES_UI_USERNAME_CLAIM must be a claim name"), + ({"DATABASES_UI_GROUPS_PREFIX": "no spaces"}, "DATABASES_UI_GROUPS_PREFIX must be a prefix"), ({"DATABASES_UI_SESSION_HOURS": "48"}, "between 1 and 24"), ({"PORT": "eighty"}, "whole numbers"), ({"DATABASES_UI_BRAND_ACCENT": "teal"}, "#rrggbb"), @@ -65,5 +69,11 @@ def test_secrets_from_files_and_a_sas_with_a_client_secret(env, tmp_path): load_config({**env, "DATABASES_UI_SESSION_KEY": "", "DATABASES_UI_SESSION_KEY_FILE": str(tmp_path / "missing")}) +def test_a_storage_identity_and_a_label_of_your_own(env): + cfg = load_config({**env, "DATABASES_UI_STORAGE_CLIENT_ID": "CCCCCCCC-bbbb-cccc-dddd-eeeeeeeeeeee", "DATABASES_UI_NAMESPACE_LABEL": "example.com/app-namespace"}) + assert cfg.storage_client_id == "cccccccc-bbbb-cccc-dddd-eeeeeeeeeeee" and cfg.namespace_label == "example.com/app-namespace" + assert load_config(env).storage_client_id == cfg.client_id + + def test_plain_http_only_on_loopback(env): assert load_config({**env, "DATABASES_UI_PUBLIC_ORIGIN": "http://localhost:8080"}).secure_cookies is False # DevSkim: ignore DS162092 - loopback is allowed for local development diff --git a/tests/test_runner.py b/tests/test_runner.py index 33ecd9a..bf019bc 100644 --- a/tests/test_runner.py +++ b/tests/test_runner.py @@ -27,8 +27,14 @@ def tools(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> Path: bin_dir.mkdir() scripts = { "pg_dump": '#!/bin/sh\nprintf PGDMP\nhead -c "${DUMP_BYTES:-100}" /dev/zero | tr "\\000" x\nif [ -n "$DUMP_FAIL" ]; then echo "pg_dump: error: $DUMP_FAIL" >&2; exit 1; fi\n', - "pg_restore": '#!/bin/sh\necho "$@" > "$OUT/restore-args"\ncat > "$OUT/restored"\nif [ -n "$RESTORE_FAIL" ]; then echo "pg_restore: error: $RESTORE_FAIL" >&2; exit 1; fi\n', - "psql": '#!/bin/sh\nfor last; do :; done\necho "$last" >> "$OUT/psql"\nif [ -n "$PSQL_FAIL" ]; then echo "psql: error: $PSQL_FAIL" >&2; exit 2; fi\necho 2\n', + # Its script is the archive itself, which is all psql needs to show here. + "pg_restore": '#!/bin/sh\necho "$@" > "$OUT/restore-args"\nif [ -n "$RESTORE_FAIL" ]; then head -c 3; echo "pg_restore: error: $RESTORE_FAIL" >&2; exit 1; fi\ncat\n', + "psql": ( + '#!/bin/sh\nfor last; do :; done\n' + 'if [ "$last" = "--file=-" ]; then echo "$@" > "$OUT/psql-args"; cat > "$OUT/script"; ' + 'if [ -n "$SCRIPT_FAIL" ]; then echo "psql::9: ERROR: $SCRIPT_FAIL" >&2; exit 3; fi; exit 0; fi\n' + 'echo "$last" >> "$OUT/psql"\nif [ -n "$PSQL_FAIL" ]; then echo "psql: error: $PSQL_FAIL" >&2; exit 2; fi\necho 2\n' + ), } for name, body in scripts.items(): (bin_dir / name).write_text(body) @@ -49,6 +55,7 @@ def job_env(tmp_path: Path, action: str, **extra: str) -> dict[str, str]: "DBUI_JOB": f"dbui-{action}-12345678", "DBUI_ENVIRONMENT": "dev", "DBUI_DATABASE": "payments_dev", + "DBUI_NAMESPACE": "dev-payments", "DBUI_REQUESTED_BY": "alice@example.com", "DBUI_BLOB_URL": f"{STORAGE}/dev", "DBUI_BLOB": SNAPSHOT, @@ -103,26 +110,45 @@ def test_restore_in_place_scales_the_workloads_down_and_back(world, tools, tmp_p env = job_env(tmp_path, "restore", DBUI_SCALE=json.dumps([["deployment", "dev-payments", "api"], ["statefulset", "dev-payments", "gone"]])) code, outcome = run(world, env) assert code == 0 and outcome == {"result": "succeeded", "bytes": 3_000_005, "seconds": outcome["seconds"]} - assert (tools / "restored").read_bytes() == b"PGDMP" + b"y" * 3_000_000 - assert (tools / "restore-args").read_text().split() == ["--format=custom", "--clean", "--if-exists", "--no-owner", "--no-acl", "--single-transaction", "--no-password", "--dbname=payments_dev"] + # One transaction: what the owner owns goes, the snapshot's script runs, then COMMIT. + assert (tools / "script").read_bytes() == b"BEGIN;\nDROP OWNED BY CURRENT_USER;\nPGDMP" + b"y" * 3_000_000 + b"\nCOMMIT;\n" + assert (tools / "restore-args").read_text().split() == ["--format=custom", "--clean", "--if-exists", "--no-owner", "--no-acl", "--file=-"] + assert (tools / "psql-args").read_text().split() == ["--no-password", "--no-psqlrc", "--quiet", "-v", "ON_ERROR_STOP=1", "--dbname=payments_dev", "--file=-"] assert "pg_terminate_backend" in (tools / "psql").read_text() - patches = [json.loads(json.dumps(c)) for c in world.kube.calls if c[0] == "PATCH"] - assert patches == [["PATCH", f"{APPS}/api"], ["PATCH", f"{APPS}/api"]] + patches = [c for c in world.kube.calls if c[0] == "PATCH"] + assert patches == [("PATCH", f"{APPS}/api"), ("PATCH", f"{APPS}/api")] api = world.kube.get(APPS, "api") assert api["spec"]["replicas"] == 3 and "databases-ui/replicas-before-restore" not in (api["metadata"].get("annotations") or {}) - assert world.storage.audit("dev")[0]["action"] == "restore.succeeded" + assert world.storage.audit("dev")[0]["action"] == "restore.succeeded" and world.storage.audit("dev")[0]["namespace"] == "dev-payments" -def test_a_failed_restore_still_scales_back(world, tools, tmp_path, monkeypatch): - monkeypatch.setenv("RESTORE_FAIL", "must be owner of table orders") +def test_a_failed_pg_restore_never_commits_and_still_scales_back(world, tools, tmp_path, monkeypatch): + monkeypatch.setenv("RESTORE_FAIL", "unsupported version (1.16) in file header") world.snapshot("dev", "payments_dev", "20261023T140000Z-abcdef") # An earlier restore died before scaling back: the annotation has the real count. world.kube.put(APPS, {"metadata": {"name": "api", "annotations": {"databases-ui/replicas-before-restore": "4"}}, "spec": {"replicas": 0, "selector": {"matchLabels": {"app": "api"}}}}) code, outcome = run(world, job_env(tmp_path, "restore", DBUI_SCALE=json.dumps([["deployment", "dev-payments", "api"]]))) - assert code == 1 and "nothing changed" in outcome["reason"] and "must be owner of table orders" in outcome["reason"] + assert code == 1 and "pg_restore exited 1, nothing changed" in outcome["reason"] and "unsupported version" in outcome["reason"] + assert b"COMMIT" not in (tools / "script").read_bytes() assert world.kube.get(APPS, "api")["spec"]["replicas"] == 4 +def test_a_failed_statement_rolls_the_restore_back(world, tools, tmp_path, monkeypatch): + monkeypatch.setenv("SCRIPT_FAIL", 'type "citext" does not exist') + world.snapshot("dev", "payments_dev", "20261023T140000Z-abcdef") + code, outcome = run(world, job_env(tmp_path, "restore")) + assert code == 1 and outcome["reason"].startswith("the restore failed, nothing changed") and "citext" in outcome["reason"] + + +def test_a_download_that_breaks_off_commits_nothing(world, tools, tmp_path): + world.snapshot("dev", "payments_dev", "20261023T140000Z-abcdef", data=b"PGDMP" + b"z" * 100_000) + world.storage.break_after = 50_000 + code, outcome = run(world, job_env(tmp_path, "restore")) + assert code == 1 and "broke off" in outcome["reason"] + # psql was stopped, maybe before it read a byte: either way it never saw COMMIT. + assert not (tools / "script").exists() or b"COMMIT" not in (tools / "script").read_bytes() + + def test_restore_waits_for_pods_to_go_and_gives_up(world, tools, tmp_path): world.snapshot("dev", "payments_dev", "20261023T140000Z-abcdef") world.kube.put(APPS, {"metadata": {"name": "api"}, "spec": {"replicas": 2, "selector": {"matchLabels": {"app": "api"}}}}) @@ -136,7 +162,7 @@ def test_restore_into_a_copy_waits_for_the_database(world, tools, tmp_path, monk world.snapshot("dev", "payments_dev", "20261023T140000Z-abcdef") code, _ = run(world, job_env(tmp_path, "restore", DBUI_WAIT_FOR_DATABASE="1", PGDATABASE="payments_dev_copy")) assert code == 0 and (tools / "psql").read_text().splitlines()[0] == "select 1" - assert (tools / "restore-args").read_text().split()[-1] == "--dbname=payments_dev_copy" + assert "--dbname=payments_dev_copy" in (tools / "psql-args").read_text().split() monkeypatch.setenv("PSQL_FAIL", "database does not exist") code, outcome = run(world, job_env(tmp_path, "restore", DBUI_WAIT_FOR_DATABASE="1", PGDATABASE="payments_dev_copy")) assert code == 1 and "never became reachable" in outcome["reason"] From 9da584ba9b0867c9721030f8aab28827d485fb14 Mon Sep 17 00:00:00 2001 From: CalebSargeant <4991715+CalebSargeant@users.noreply.github.com> Date: Fri, 23 Oct 2026 17:14:58 +0200 Subject: [PATCH 3/8] fix(ui): name the workloads' namespace once, in the sentence --- frontend/src/views/DatabaseView.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/frontend/src/views/DatabaseView.tsx b/frontend/src/views/DatabaseView.tsx index 6f08789..9637fc1 100644 --- a/frontend/src/views/DatabaseView.tsx +++ b/frontend/src/views/DatabaseView.tsx @@ -124,12 +124,12 @@ export function DatabaseView({ env, name }: { env: Environment; name: string }) {db.workloads.length > 0 && (
    -

    A restore in place scales these to 0 replicas, and back to what they had afterwards.

    +

    + A restore in place scales these, in {db.namespace}, to 0 replicas, and back to what they had afterwards. +

      {db.workloads.map((w) => ( -
    • - {db.namespace}/{w} -
    • +
    • {w}
    • ))}
    From 8b36519fef97b99312c1a0288aafe6925e4335e9 Mon Sep 17 00:00:00 2001 From: CalebSargeant <4991715+CalebSargeant@users.noreply.github.com> Date: Fri, 23 Oct 2026 17:37:03 +0200 Subject: [PATCH 4/8] test: move the e2e harness under tests/ and drop md5 from it 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. --- .dockerignore | 1 - .github/workflows/ci.yml | 4 ++-- README.md | 4 ++-- {e2e => tests/e2e}/fixtures.yaml | 0 {e2e => tests/e2e}/run.py | 8 ++++---- 5 files changed, 8 insertions(+), 9 deletions(-) rename {e2e => tests/e2e}/fixtures.yaml (100%) rename {e2e => tests/e2e}/run.py (98%) diff --git a/.dockerignore b/.dockerignore index 6238be4..df12dc4 100644 --- a/.dockerignore +++ b/.dockerignore @@ -5,7 +5,6 @@ .coverage **/__pycache__ tests -e2e examples charts docker-bake.hcl diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1a28f7d..df69e49 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -100,7 +100,7 @@ jobs: - run: uv run python -m databases_ui check examples/catalog.yaml # The image, the chart, CloudNativePG, Azurite and real PostgreSQL: every action through the - # API, checked in the databases themselves (e2e/run.py). + # API, checked in the databases themselves (tests/e2e/run.py). e2e: runs-on: ubuntu-latest timeout-minutes: 30 @@ -123,7 +123,7 @@ jobs: helm install cnpg cloudnative-pg --repo https://cloudnative-pg.github.io/charts --version 0.29.1 \ --namespace cnpg-system --create-namespace --wait --timeout 5m - run: uv sync --locked - - run: uv run python e2e/run.py + - run: uv run python tests/e2e/run.py - name: What the cluster looked like if: failure() run: | diff --git a/README.md b/README.md index 3e22983..2615457 100644 --- a/README.md +++ b/README.md @@ -273,7 +273,7 @@ uv run python -m databases_ui check examples/catalog.yaml cd frontend && npm install && npm run dev # the UI on 5173, the API proxied to 8080 ``` -[`e2e/run.py`](e2e/run.py) runs every action against a real cluster with CloudNativePG, Azurite and +[`tests/e2e/run.py`](tests/e2e/run.py) runs every action against a real cluster with CloudNativePG, Azurite and RBAC like an OIDC-backed API server's; CI runs it on kind: ```bash @@ -281,7 +281,7 @@ k3d cluster create dbui helm install cnpg cloudnative-pg --repo https://cloudnative-pg.github.io/charts --version 0.29.1 \ --namespace cnpg-system --create-namespace --wait docker buildx bake app-local && k3d image import databases-ui:dev -c dbui -uv run python e2e/run.py +uv run python tests/e2e/run.py ``` ## Licence diff --git a/e2e/fixtures.yaml b/tests/e2e/fixtures.yaml similarity index 100% rename from e2e/fixtures.yaml rename to tests/e2e/fixtures.yaml diff --git a/e2e/run.py b/tests/e2e/run.py similarity index 98% rename from e2e/run.py rename to tests/e2e/run.py index 8eb0d0b..0ba9ce7 100644 --- a/e2e/run.py +++ b/tests/e2e/run.py @@ -4,7 +4,7 @@ helm install cnpg cloudnative-pg --repo https://cloudnative-pg.github.io/charts \ --version 0.29.1 --namespace cnpg-system --create-namespace --wait docker buildx bake app-local && k3d image import databases-ui:dev -c dbui - uv run python e2e/run.py + uv run python tests/e2e/run.py It installs fixtures.yaml and the chart, signs people in by sealing their session cookies with the chart's own session key (Entra ID is the one thing not in the loop), and walks every action @@ -33,7 +33,7 @@ from databases_ui.session import Sealer HERE = Path(__file__).resolve().parent -CHART = HERE.parent / "charts" / "databases-ui" +CHART = HERE.parents[1] / "charts" / "databases-ui" ACCOUNT = "e2eaccount" ORIGIN = "http://localhost:18080" # DevSkim: ignore DS162092 - the port-forwarded test server # People and their groups, as the API server would name them from an ID token. @@ -154,7 +154,7 @@ def setup() -> tuple[str, dict[str, str]]: sas = account_sas(key) with port_forward("storage", "svc/azurite", "10010:10000"): for env in ("dev", "tst"): - response = httpx.put(f"http://127.0.0.1:10010/{ACCOUNT}/{env}?restype=container&{sas}", headers={"x-ms-version": "2022-11-02"}) # DevSkim: ignore DS137138 + response = httpx.put(f"http://127.0.0.1:10010/{ACCOUNT}/{env}?restype=container&{sas}", headers={"x-ms-version": "2022-11-02"}) # DevSkim: ignore DS137138,DS162092 - Azurite, port-forwarded to this machine assert response.status_code in (201, 409), response.text for namespace in ("databases-ui", "database"): kubectl("apply", "-f", "-", input=json.dumps({"apiVersion": "v1", "kind": "Secret", "metadata": {"name": "databases-ui-storage", "namespace": namespace}, "stringData": {"sas": sas}})) @@ -185,7 +185,7 @@ def setup() -> tuple[str, dict[str, str]]: cookies = {} for person, groups in PEOPLE.items(): data = { - "oid": hashlib.md5(person.encode()).hexdigest(), "upn": f"{person}@example.com", "name": person.title(), "csrf": f"csrf-{person}", # nosec B324 - an id for a test person + "oid": hashlib.sha256(person.encode()).hexdigest()[:32], "upn": f"{person}@example.com", "name": person.title(), "csrf": f"csrf-{person}", "user": f"oidc:{person}@example.com", "groups": [f"oidc:{g}" for g in groups], } # fmt: skip cookies[person] = sealer.seal("session", data, 3600) From cb53f98a1d8b2f489d038e478e32fe33310ff97b Mon Sep 17 00:00:00 2001 From: CalebSargeant <4991715+CalebSargeant@users.noreply.github.com> Date: Fri, 23 Oct 2026 17:37:09 +0200 Subject: [PATCH 5/8] fix: give the scanner false positives in src their reasons 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. --- src/databases_ui/blob.py | 4 +++- src/databases_ui/entra.py | 2 +- src/databases_ui/jobs.py | 6 +++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/databases_ui/blob.py b/src/databases_ui/blob.py index b3cffa9..5b2d927 100644 --- a/src/databases_ui/blob.py +++ b/src/databases_ui/blob.py @@ -11,7 +11,9 @@ import asyncio import base64 import hashlib -import xml.etree.ElementTree as ET # nosec B405 - parses Azure Storage's own listings, nothing a person writes +# Only Azure Storage's own List Blobs answers are parsed, from the operator's configured endpoint: +# ElementTree resolves no external entities, and expat (2.4.1 and later) caps entity expansion. +import xml.etree.ElementTree as ET # nosec B405 # nosemgrep: python.lang.security.use-defused-xml.use-defused-xml from collections.abc import AsyncIterator, Awaitable, Callable from contextlib import asynccontextmanager from dataclasses import dataclass diff --git a/src/databases_ui/entra.py b/src/databases_ui/entra.py index a13ba6c..9022a6d 100644 --- a/src/databases_ui/entra.py +++ b/src/databases_ui/entra.py @@ -49,7 +49,7 @@ def __init__(self, http: httpx.AsyncClient, *, token_url: str, client_id: str, c self._client_id = client_id self._credential = credential self._scope = scope - self._token = "" + self._token = "" # nosec B105 - no token fetched yet; this is the empty cache, not a credential self._expires = 0.0 self._lock = asyncio.Lock() diff --git a/src/databases_ui/jobs.py b/src/databases_ui/jobs.py index ae53513..d890295 100644 --- a/src/databases_ui/jobs.py +++ b/src/databases_ui/jobs.py @@ -21,7 +21,7 @@ PREFIX = "databases-ui/" MANAGED_BY = "app.kubernetes.io/managed-by" APP = "databases-ui" -TOKEN_DIR = "/var/run/secrets/azure/tokens" +TOKEN_DIR = "/var/run/secrets/azure/tokens" # nosec B105 - where the kubelet mounts the token, not a token DEADLINE_SECONDS = 6 * 3600 KEEP_SECONDS = 7 * 86400 @@ -98,7 +98,7 @@ def build( {"name": "PGSSLROOTCERT", "value": "/etc/databases-ui/ca/ca.crt"}, {"name": "PGAPPNAME", "value": "databases-ui"}, {"name": "PGCONNECT_TIMEOUT", "value": "15"}, - {"name": "HOME", "value": "/tmp"}, + {"name": "HOME", "value": "/tmp"}, # nosec B108 - the pod's own emptyDir, mounted below *_storage_env(cfg), ] if metadata: @@ -112,7 +112,7 @@ def build( # The server's CA certificate only: the Secret also holds the CA's key. {"name": "ca", "secret": {"secretName": target.ca_secret, "defaultMode": 0o440, "items": [{"key": "ca.crt", "path": "ca.crt"}]}}, ] - mounts = [{"name": "tmp", "mountPath": "/tmp"}, {"name": "ca", "mountPath": "/etc/databases-ui/ca", "readOnly": True}] + mounts = [{"name": "tmp", "mountPath": "/tmp"}, {"name": "ca", "mountPath": "/etc/databases-ui/ca", "readOnly": True}] # nosec B108 - an emptyDir no other pod shares if not cfg.storage_sas_secret: volumes.append( { From b64dcf362f6a1687ff345e19dff1f8c1504fe2a3 Mon Sep 17 00:00:00 2001 From: CalebSargeant <4991715+CalebSargeant@users.noreply.github.com> Date: Fri, 23 Oct 2026 17:37:10 +0200 Subject: [PATCH 6/8] build: copy the PostgreSQL apt key from the repo instead of fetching it with ADD --- Dockerfile | 7 ++-- docker/apt.postgresql.org.asc | 77 +++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+), 4 deletions(-) create mode 100644 docker/apt.postgresql.org.asc diff --git a/Dockerfile b/Dockerfile index d8a4973..87b8242 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,12 +24,11 @@ RUN uv sync --locked --no-dev --no-editable FROM python:3.14-slim@sha256:a2b82f3c48559aa0a8446d9af49826b6e2b2016f4cd2afabfe6013ec53729170 # pg_dump, pg_restore and psql from the PostgreSQL project's repository: pg_dump has to be at -# least the server's version, and Debian's own lags behind. The signing key is checked by hash. -ADD --checksum=sha256:0144068502a1eddd2a0280ede10ef607d1ec592ce819940991203941564e8e76 \ - https://www.postgresql.org/media/keys/ACCC4CF8.asc /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc +# least the server's version, and Debian's own lags behind. Its signing key is kept here +# (fingerprint B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8), so a rotation is a reviewed change. +COPY --chmod=0644 docker/apt.postgresql.org.asc /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc # hadolint ignore=DL3008 RUN set -eux; \ - chmod 0644 /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc; \ codename="$(. /etc/os-release && echo "$VERSION_CODENAME")"; \ echo "deb [signed-by=/usr/share/postgresql-common/pgdg/apt.postgresql.org.asc] https://apt.postgresql.org/pub/repos/apt ${codename}-pgdg main" > /etc/apt/sources.list.d/pgdg.list; \ apt-get update; \ diff --git a/docker/apt.postgresql.org.asc b/docker/apt.postgresql.org.asc new file mode 100644 index 0000000..8480576 --- /dev/null +++ b/docker/apt.postgresql.org.asc @@ -0,0 +1,77 @@ +-----BEGIN PGP PUBLIC KEY BLOCK----- + +mQINBE6XR8IBEACVdDKT2HEH1IyHzXkb4nIWAY7echjRxo7MTcj4vbXAyBKOfjja +UrBEJWHN6fjKJXOYWXHLIYg0hOGeW9qcSiaa1/rYIbOzjfGfhE4x0Y+NJHS1db0V +G6GUj3qXaeyqIJGS2z7m0Thy4Lgr/LpZlZ78Nf1fliSzBlMo1sV7PpP/7zUO+aA4 +bKa8Rio3weMXQOZgclzgeSdqtwKnyKTQdXY5MkH1QXyFIk1nTfWwyqpJjHlgtwMi +c2cxjqG5nnV9rIYlTTjYG6RBglq0SmzF/raBnF4Lwjxq4qRqvRllBXdFu5+2pMfC +IZ10HPRdqDCTN60DUix+BTzBUT30NzaLhZbOMT5RvQtvTVgWpeIn20i2NrPWNCUh +hj490dKDLpK/v+A5/i8zPvN4c6MkDHi1FZfaoz3863dylUBR3Ip26oM0hHXf4/2U +A/oA4pCl2W0hc4aNtozjKHkVjRx5Q8/hVYu+39csFWxo6YSB/KgIEw+0W8DiTII3 +RQj/OlD68ZDmGLyQPiJvaEtY9fDrcSpI0Esm0i4sjkNbuuh0Cvwwwqo5EF1zfkVj +Tqz2REYQGMJGc5LUbIpk5sMHo1HWV038TWxlDRwtOdzw08zQA6BeWe9FOokRPeR2 +AqhyaJJwOZJodKZ76S+LDwFkTLzEKnYPCzkoRwLrEdNt1M7wQBThnC5z6wARAQAB +tBxQb3N0Z3JlU1FMIERlYmlhbiBSZXBvc2l0b3J5iQJOBBMBCAA4AhsDBQsJCAcD +BRUKCQgLBRYCAwEAAh4BAheAFiEEuXsK/KoaR/BE8kSgf8x9RqzMTPgFAlhtCD8A +CgkQf8x9RqzMTPgECxAAk8uL+dwveTv6eH21tIHcltt8U3Ofajdo+D/ayO53LiYO +xi27kdHD0zvFMUWXLGxQtWyeqqDRvDagfWglHucIcaLxoxNwL8+e+9hVFIEskQAY +kVToBCKMXTQDLarz8/J030Pmcv3ihbwB+jhnykMuyyNmht4kq0CNgnlcMCdVz0d3 +z/09puryIHJrD+A8y3TD4RM74snQuwc9u5bsckvRtRJKbP3GX5JaFZAqUyZNRJRJ +Tn2OQRBhCpxhlZ2afkAPFIq2aVnEt/Ie6tmeRCzsW3lOxEH2K7MQSfSu/kRz7ELf +Cz3NJHj7rMzC+76Rhsas60t9CjmvMuGONEpctijDWONLCuch3Pdj6XpC+MVxpgBy +2VUdkunb48YhXNW0jgFGM/BFRj+dMQOUbY8PjJjsmVV0joDruWATQG/M4C7O8iU0 +B7o6yVv4m8LDEN9CiR6r7H17m4xZseT3f+0QpMe7iQjz6XxTUFRQxXqzmNnloA1T +7VjwPqIIzkj/u0V8nICG/ktLzp1OsCFatWXh7LbU+hwYl6gsFH/mFDqVxJ3+DKQi +vyf1NatzEwl62foVjGUSpvh3ymtmtUQ4JUkNDsXiRBWczaiGSuzD9Qi0ONdkAX3b +ewqmN4TfE+XIpCPxxHXwGq9Rv1IFjOdCX0iG436GHyTLC1tTUIKF5xV4Y0+cXIOI +RgQQEQgABgUCTpdI7gAKCRDFr3dKWFELWqaPAKD1TtT5c3sZz92Fj97KYmqbNQZP ++ACfSC6+hfvlj4GxmUjp1aepoVTo3weJAhwEEAEIAAYFAk6XSQsACgkQTFprqxLS +p64F8Q//cCcutwrH50UoRFejg0EIZav6LUKejC6kpLeubbEtuaIH3r2zMblPGc4i ++eMQKo/PqyQrceRXeNNlqO6/exHozYi2meudxa6IudhwJIOn1MQykJbNMSC2sGUp +1W5M1N5EYgt4hy+qhlfnD66LR4G+9t5FscTJSy84SdiOuqgCOpQmPkVRm1HX5X1+ +dmnzMOCk5LHHQuiacV0qeGO7JcBCVEIDr+uhU1H2u5GPFNHm5u15n25tOxVivb94 +xg6NDjouECBH7cCVuW79YcExH/0X3/9G45rjdHlKPH1OIUJiiX47OTxdG3dAbB4Q +fnViRJhjehFscFvYWSqXo3pgWqUsEvv9qJac2ZEMSz9x2mj0ekWxuM6/hGWxJdB+ ++985rIelPmc7VRAXOjIxWknrXnPCZAMlPlDLu6+vZ5BhFX0Be3y38f7GNCxFkJzl +hWZ4Cj3WojMj+0DaC1eKTj3rJ7OJlt9S9xnO7OOPEUTGyzgNIDAyCiu8F4huLPaT +ape6RupxOMHZeoCVlqx3ouWctelB2oNXcxxiQ/8y+21aHfD4n/CiIFwDvIQjl7dg +mT3u5Lr6yxuosR3QJx1P6rP5ZrDTP9khT30t+HZCbvs5Pq+v/9m6XDmi+NlU7Zuh +Ehy97tL3uBDgoL4b/5BpFL5U9nruPlQzGq1P9jj40dxAaDAX/WKJAj0EEwEIACcC +GwMFCwkIBwMFFQoJCAsFFgIDAQACHgECF4AFAlB5KywFCQPDFt8ACgkQf8x9RqzM +TPhuCQ//QAjRSAOCQ02qmUAikT+mTB6baOAakkYq6uHbEO7qPZkv4E/M+HPIJ4wd +nBNeSQjfvdNcZBA/x0hr5EMcBneKKPDj4hJ0panOIRQmNSTThQw9OU351gm3YQct +AMPRUu1fTJAL/AuZUQf9ESmhyVtWNlH/56HBfYjE4iVeaRkkNLJyX3vkWdJSMwC/ +LO3Lw/0M3R8itDsm74F8w4xOdSQ52nSRFRh7PunFtREl+QzQ3EA/WB4AIj3VohIG +kWDfPFCzV3cyZQiEnjAe9gG5pHsXHUWQsDFZ12t784JgkGyO5wT26pzTiuApWM3k +/9V+o3HJSgH5hn7wuTi3TelEFwP1fNzI5iUUtZdtxbFOfWMnZAypEhaLmXNkg4zD +kH44r0ss9fR0DAgUav1a25UnbOn4PgIEQy2fgHKHwRpCy20d6oCSlmgyWsR40EPP +YvtGq49A2aK6ibXmdvvFT+Ts8Z+q2SkFpoYFX20mR2nsF0fbt1lfH65P64dukxeR +GteWIeNakDD40bAAOH8+OaoTGVBJ2ACJfLVNM53PEoftavAwUYMrR910qvwYfd/4 +6rh46g1Frr9SFMKYE9uvIJIgDsQB3QBp71houU4H55M5GD8XURYs+bfiQpJG1p7e +B8e5jZx1SagNWc4XwL2FzQ9svrkbg1Y+359buUiP7T6QXX2zY++JAj0EEwEIACcC +GwMFCwkIBwMFFQoJCAsFFgIDAQACHgECF4AFAlEqbZUFCQg2wEEACgkQf8x9RqzM +TPhFMQ//WxAfKMdpSIA9oIC/yPD/dJpY/+DyouOljpE6MucMy/ArBECjFTBwi/j9 +NYM4ynAk34IkhuNexc1i9/05f5RM6+riLCLgAOsADDbHD4miZzoSxiVr6GQ3YXMb +OGld9kV9Sy6mGNjcUov7iFcf5Hy5w3AjPfKuR9zXswyfzIU1YXObiiZT38l55pp/ +BSgvGVQsvbNjsff5CbEKXS7q3xW+WzN0QWF6YsfNVhFjRGj8hKtHvwKcA02wwjLe +LXVTm6915ZUKhZXUFc0vM4Pj4EgNswH8Ojw9AJaKWJIZmLyW+aP+wpu6YwVCicxB +Y59CzBO2pPJDfKFQzUtrErk9irXeuCCLesDyirxJhv8o0JAvmnMAKOLhNFUrSQ2m ++3EnF7zhfz70gHW+EG8X8mL/EN3/dUM09j6TVrjtw43RLxBzwMDeariFF9yC+5bL +tnGgxjsB9Ik6GV5v34/NEEGf1qBiAzFmDVFRZlrNDkq6gmpvGnA5hUWNr+y0i01L +jGyaLSWHYjgw2UEQOqcUtTFK9MNzbZze4mVaHMEz9/aMfX25R6qbiNqCChveIm8m +Yr5Ds2zdZx+G5bAKdzX7nx2IUAxFQJEE94VLSp3npAaTWv3sHr7dR8tSyUJ9poDw +gw4W9BIcnAM7zvFYbLF5FNggg/26njHCCN70sHt8zGxKQINMc6SJAj0EEwEIACcC +GwMFCwkIBwMFFQoJCAsFFgIDAQACHgECF4AFAlLpFRkFCQ6EJy0ACgkQf8x9RqzM +TPjOZA//Zp0e25pcvle7cLc0YuFr9pBv2JIkLzPm83nkcwKmxaWayUIG4Sv6pH6h +m8+S/CHQij/yFCX+o3ngMw2J9HBUvafZ4bnbI0RGJ70GsAwraQ0VlkIfg7GUw3Tz +voGYO42rZTru9S0K/6nFP6D1HUu+U+AsJONLeb6oypQgInfXQExPZyliUnHdipei +4WR1YFW6sjSkZT/5C3J1wkAvPl5lvOVthI9Zs6bZlJLZwusKxU0UM4Btgu1Sf3nn +JcHmzisixwS9PMHE+AgPWIGSec/N27a0KmTTvImV6K6nEjXJey0K2+EYJuIBsYUN +orOGBwDFIhfRk9qGlpgt0KRyguV+AP5qvgry95IrYtrOuE7307SidEbSnvO5ezNe +mE7gT9Z1tM7IMPfmoKph4BfpNoH7aXiQh1Wo+ChdP92hZUtQrY2Nm13cmkxYjQ4Z +gMWfYMC+DA/GooSgZM5i6hYqyyfAuUD9kwRN6BqTbuAUAp+hCWYeN4D88sLYpFh3 +paDYNKJ+Gf7Yyi6gThcV956RUFDH3ys5Dk0vDL9NiWwdebWfRFbzoRM3dyGP889a +OyLzS3mh6nHzZrNGhW73kslSQek8tjKrB+56hXOnb4HaElTZGDvD5wmrrhN94kby +Gtz3cydIohvNO9d90+29h0eGEDYti7j7maHkBKUAwlcPvMg5m3Y= +=DA1T +-----END PGP PUBLIC KEY BLOCK----- From 8059b9cf99cdd19dae1fb2d21c42666e77b1346d Mon Sep 17 00:00:00 2001 From: CalebSargeant <4991715+CalebSargeant@users.noreply.github.com> Date: Fri, 23 Oct 2026 17:37:10 +0200 Subject: [PATCH 7/8] ci: keep the e2e fixtures out of the manifest scanners They build a throwaway test cluster, RoleBindings to edit and admin included, and are applied nowhere else; the secret scanners still read them. --- .mega-linter.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 .mega-linter.yml diff --git a/.mega-linter.yml b/.mega-linter.yml new file mode 100644 index 0000000..01cfcf1 --- /dev/null +++ b/.mega-linter.yml @@ -0,0 +1,16 @@ +--- +# Additive to the env Chargate injects (MagmaMoose/chargate, docs/setup.md). + +# tests/e2e/fixtures.yaml is the world the end-to-end test builds on a throwaway kind or k3d +# cluster and deletes with it: Azurite as Microsoft ships it, and RoleBindings that give test +# groups `edit` and `admin` in app namespaces, because that access is what the test exercises. +# It is applied nowhere else, so the hardening and RBAC rules these scanners hold manifests to +# (resource limits, seccomp, a read-only root, trusted registries, no binding to admin) are +# about deployments it is not. Trivy, Checkov and Semgrep still read every other file, the +# chart included, and the secret scanners still read this one. +# +# Per-linter ARGUMENTS rather than FILTER_REGEX_EXCLUDE: all three are project-scope linters, +# which MegaLinter's file filter never reaches. +REPOSITORY_TRIVY_ARGUMENTS: "--skip-files tests/e2e/fixtures.yaml" +REPOSITORY_CHECKOV_ARGUMENTS: "--skip-path tests/e2e/fixtures.yaml" +REPOSITORY_SEMGREP_ARGUMENTS: "--exclude tests/e2e/fixtures.yaml" From f6a7576be9f20f4e2cc234288c29ceb127cb82dd Mon Sep 17 00:00:00 2001 From: CalebSargeant <4991715+CalebSargeant@users.noreply.github.com> Date: Fri, 23 Oct 2026 17:53:21 +0200 Subject: [PATCH 8/8] fix(build): copy the apt key without --chmod, which locked apt out of 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. --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 87b8242..da8eba6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -26,7 +26,7 @@ FROM python:3.14-slim@sha256:a2b82f3c48559aa0a8446d9af49826b6e2b2016f4cd2afabfe6 # pg_dump, pg_restore and psql from the PostgreSQL project's repository: pg_dump has to be at # least the server's version, and Debian's own lags behind. Its signing key is kept here # (fingerprint B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8), so a rotation is a reviewed change. -COPY --chmod=0644 docker/apt.postgresql.org.asc /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc +COPY docker/apt.postgresql.org.asc /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc # hadolint ignore=DL3008 RUN set -eux; \ codename="$(. /etc/os-release && echo "$VERSION_CODENAME")"; \