Aller au contenu

Super Admin console — deployment

Brouillon : cette page n'a pas encore été relue et peut être incomplète ou inexacte.

The Super Admin console is two apps, both submodules of this repo:

App (manifest key) Submodule / repo Default branch Image (DOCR) Type
super-admin-backend super-admin-backend/ (Django “orchestrator” API) master super-admin-backend backend: tag = <sha>
super-admin-frontend DWN-SUPER-ADMIN/ (Next.js) main super-admin-frontend frontend: tag = <sha>-<env>

They deploy through the same pipeline as GED/AFCM: app CI builds the image → bumps environments/dev/versions.yaml → deploy.yml helm-upgrades agbale-<env>. Staging/prod go through promote.yml. Before reviewing what the apps do, read notes/superadmin-audit/super-admin-console-review.md; it lists known security issues that are not fixed by this deployment work.

https://admin.<env host>/ → super-admin-frontend (Next.js server, :3000)
https://admin.<env host>/api/v1/* → super-admin-backend (gunicorn, :8000)
https://<platform host>/auth → Keycloak (existing), realm `agbale`
super-admin-backend → http://agbale-<env>-afcm-backend:80/internal/tenants (cluster DNS)
→ http://agbale-<env>-ged-backend:8000/internal/tenants
→ http://agbale-<env>-keycloak:8080/auth (JWKS, SA token, Admin API)
→ agbale-<env>-postgresql / super_admin_db
  • Own host, not a /path. The console hard-codes root paths and has /auth/* routes that would collide with Keycloak’s /auth on the platform host. A separate origin also keeps the platform-admin token away from any XSS in the tenant SPAs. global.superAdminDomain sets the host.
  • Only /api/v1 is routed to the backend. /health, /api/schema/ and /api/docs/ stay cluster-internal, as does /internal/* on AFCM/GED.
  • TLS is issued by cert-manager’s ingress-shim into <host>-tls. Don’t also add the host to certificate.yaml: two Certificates on one secret fight, which is why dev already has a stuck dev-dowonou-com-tls Certificate.
  • Database super_admin_db lives on the shared Postgres. Fresh volumes create it in initdb. On existing volumes the migration Job’s init container creates it (agbale_user has CREATEDB).
  • Migrations run in a post-install/upgrade Job, with SKIP_MIGRATE=1 on pods. Two CronJobs cover expire_subscriptions (daily 00:15 UTC) and process_licence_outbox (every 5 min, concurrencyPolicy: Forbid).
  • NetworkPolicies (prod): pods labelled dowonou.io/role=orchestrator (the API and the CronJobs) may reach backend pods on 80/8000, and nothing else is opened.
Env Console host Keycloak authority DNS
dev admin.dev.dowonou.com https://dev.dowonou.com/auth ✅ *.dev.dowonou.com wildcard
eph-N eph-N-admin.dev.dowonou.com https://eph-N.dev.dowonou.com/auth (isolated KC) ✅ wildcard
staging admin.staging.dowonou.com https://staging.dowonou.com/auth ❌ record needed
prod admin.dowonou.com https://app.dowonou.com/auth ❌ record needed

The hosts are defined in two places that must agree: DWN-SUPER-ADMIN/.github/workflows/build-env.yml, which bakes them into the image, and global.superAdminDomain in values-<env>.yaml.

The console needs three realm objects. The realm export (helm/agbale-platform/configs/keycloak-realm-export.json) carries them for fresh Keycloaks (eph envs, new installs):

  • Realm role platform-admin: grants console access. It is not a tenant admin.
  • Public client dowonou-admin:
    • PKCE S256, standard flow only, post.logout.redirect.uris=+.
    • Mappers: audience (aud=dowonou-admin), realm roles, username/email/full name.
  • Confidential client dowonou-orchestrator:
    • Service account holding realm-management roles manage-users, view-users, query-users, query-groups.
    • A realm-management client-role mapper.
  • Non-prod only: the test user platformadmin (secrets.keycloakPlatformAdminUserPassword), with no tenant group.

The explicit mappers are required. This realm’s export defines its own clientScopes, so a fresh import has no built-in roles/profile/email scopes. Without the mappers the service-account token carries no resource_access (the Admin API returns 403) and console tokens carry no email.

--import-realm never updates an existing realm. For dev/staging, run the idempotent script once, then again whenever a host changes:

Fenêtre de terminal
KC_PW=... # master admin (values-<env>.yaml keycloak.auth.adminPassword)
ORCH_SECRET=... # must equal super-admin-backend.django.keycloak.saClientSecret
GRANT_PLATFORM_ADMIN=<operator username> \
./deploy/scripts/apply-super-admin-keycloak.sh \
https://dev.dowonou.com/auth agbale "$KC_PW" "$ORCH_SECRET" admin.dev.dowonou.com --dry-run
# drop --dry-run to apply

Security note: manage-users is realm-wide, and the backend also forwards that token to AFCM/GED (review finding SA-C1). Treat dowonou-orchestrator’s secret like a realm admin credential.

  1. Merge the superrepo PR. It adds the submodules, subcharts, realm export, eph workflow and dev manifest entries. The manifest change triggers a dev helm upgrade that only updates the realm and init-scripts ConfigMaps; no pods restart, and both console apps stay disabled because they are unpinned.
  2. Before merging, give the shared GitHub App access to both new repos. Two workflows depend on it:
    • ephemeral-deploy.yml checks out all submodules recursively with the App token, so an App that can’t read super-admin-backend / DWN-SUPER-ADMIN breaks every eph deploy.
    • promote.yml dispatches build-env.yml in DWN-SUPER-ADMIN.
  3. Add Actions secrets to both app repos, as on ged_backend / agbale_frontend: DIGITALOCEAN_ACCESS_TOKEN (DOCR push), DEPLOY_APP_ID, DEPLOY_APP_PRIVATE_KEY.
  4. Run apply-super-admin-keycloak.sh against dev (above), granting platform-admin to at least one operator.
  5. Merge the app-repo PRs (Dockerfile + workflows). Each merge builds an image and auto-merges a deploy(dev): super-admin-* -> <tag> PR here, and deploy.yml enables the app on dev.
  6. Smoke test: https://admin.dev.dowonou.com/ → Keycloak login as the operator → dashboard. A tenant admin must land on /interdit (403).

The chart side is already in place: values-staging.yaml sets global.superAdminDomain: admin.staging.dowonou.com, the orchestrator client secret and both subchart blocks, and environments/staging/versions.yaml lists both apps with an empty tag, so they stay disabled until promoted. CI needs no new workflow: promote.yml rebuilds the frontend through DWN-SUPER-ADMIN’s build-env.yml (staging host + https://staging.dowonou.com/auth baked in) and copies the backend tag forward, and deploy.yml enables both apps when the promotion PR merges.

Before the first promotion:

  1. DNS: add an A record admin.staging.dowonou.com pointing to the ingress load balancer (the same IP as staging.dowonou.com), unless a *.staging.dowonou.com wildcard already exists. cert-manager issues admin-staging-dowonou-com-tls on the first deploy once the record resolves.
  2. Keycloak: run the script against the live staging realm. The secret must equal super-admin-backend.django.keycloak.saClientSecret in values-staging.yaml:
    Fenêtre de terminal
    KC_PW=... # values-staging.yaml keycloak.auth.adminPassword
    GRANT_PLATFORM_ADMIN=<operator username> \
    ./deploy/scripts/apply-super-admin-keycloak.sh \
    https://staging.dowonou.com/auth agbale "$KC_PW" dowonou-orchestrator-secret-staging \
    admin.staging.dowonou.com --dry-run
    # drop --dry-run to apply
  3. GitHub: build-env.yml runs in the staging GitHub Environment of DWN-SUPER-ADMIN. Make sure DIGITALOCEAN_ACCESS_TOKEN is visible there (repo secret or Environment secret) and add required reviewers if staging builds should be gated.
  4. Promote: Actions → Promote → dev → staging, apps super-admin-backend super-admin-frontend. Review and merge the PR; deploy.yml runs the staging helm upgrade, the migration Job creates super_admin_db, and the rollout is verified for both apps.
  5. Smoke test: https://admin.staging.dowonou.com/ → Keycloak login as the operator → dashboard. A tenant admin must land on /interdit (403).
  • Organisation create / suspend returns 503 until AFCM and GED implement PUT /internal/tenants (afcm-backend#130, ged_backend#53, both still open; see review findings RX-1…RX-6 before merging them). Each failed attempt still leaves a Keycloak group, and possibly a user, behind (review SA-H1). Don’t create real organisations on dev until that is resolved.
  • Module logos upload but are not served. The app has no /media route, and storage is a pod-local emptyDir (super-admin-backend.media.persistence).
  • Prod: add DNS, global.superAdminDomain, super-admin-backend secrets (django.secretKey, database.password, keycloak.saClientSecret) and secrets.orchestratorKeycloakClientSecret to values-prod.yaml before promoting. Otherwise the whole env’s helm upgrade fails on the subchart required checks. Staging already has them (see below).

Validation performed when this was added (2026-09-14)

Section intitulée « Validation performed when this was added (2026-09-14) »
  • Images:
    • Both built locally and run as non-root. The frontend runs on a read-only root filesystem with security headers set and /_next/image disabled.
    • Next upgraded 16.3.2 → 16.3.5; npm audit --omit=dev is clean.
  • Chart:
    • Rendered for dev (apps off and on), eph and prod.
    • With the apps off, dev differs from main only in the realm and init-scripts ConfigMaps.
    • All 14 new resources pass kubectl apply --dry-run=server on agbale-dev.
  • Keycloak 21.1 (the same version as dev), local:
    • A fresh import of the new export works.
    • The script applied to a main-era realm is idempotent (a third run is a no-op).
    • The orchestrator service account can list and create /tenants/* groups and users.
    • platform-admin tokens carry aud=dowonou-admin, typ=Bearer, email and roles.
  • End to end, local: the backend image with chart-shaped env against the fresh-import Keycloak and a stub adapter:
    • /api/v1/me: 401 with no token, 200 for platform-admin, 403 for a tenant admin.
    • POST /organisations created the Keycloak group and pushed to both adapter URLs.