test(ci): add disposable real ZITADEL browser OIDC acceptance

This commit is contained in:
Vib Tools committed 2026-11-22 09:16:53 -08:00
1 parent f423c69654
commit cbcd60e76e
32 files changed
+875 -22

No files matched your search

+1
View File
@@ -7,3 +7,4 @@
| [p05-ci.yml](p05-ci.yml) | Isolated account/login/backend CI verification on Gitea | P05-CI-01/P05-CI-02 |
| [p05-backend-acceptance.yml](p05-backend-acceptance.yml) | Manual backend-only disposable Compose, persistence and OIDC acceptance; no Account/Login build rerun | P05-CI-03 |
| [p05-security-acceptance.yml](p05-security-acceptance.yml) | Manual isolated Account/Login frozen builds, security advisory triage and strict Moderate+ gate | P05-SEC-01 |
| [p05-oidc-acceptance.yml](p05-oidc-acceptance.yml) | Manual-only disposable ZITADEL real user/client/Chromium OIDC and mandatory owned-only cleanup | P05-OIDC-01 |
+3
View File
@@ -24,3 +24,6 @@ See `notes/P05-CI-01.md` and `tests/ci/`.
**P05-SEC-02-A01 ACCEPTED:** Manual Login-only [Run #89](https://dev.ivib.cc/vibtools/ZitPlane/actions/runs/89), tested `ff4c58ed861474061c8f045be3a9f0752caf6ca0`, overall **SUCCESS**. Login frozen install/build/upstream 1219/1219 unit regressions job #194 PASS, Login production zero-Moderate/High/Critical audit job #196 PASS, Account jobs #193/#195 intentionally SKIPPED. Corrected `transitive_override_contract.py` verified exact seven parent overrides without false-positive `>=` parsing; no dependency lock/manifest/source change. Human OIDC/MFA remains unverified.
**P05-OIDC-01:** New `p05-oidc-acceptance.yml` is **manual-only** with one disposable Docker job and `always()` owned cleanup. New `tests/ci/oidc_e2e/**` uses a short-lived ZITADEL IAM_OWNER PAT for official project/real client/test human provisioning, private portless browser network, original Login V2 Chromium username/password and real Auth.js callback/positive protected identity/negative access, with strict run-labeled browser/secret/Compose teardown. No Account/Login source, package, P02 developer Compose, real user or production change. **Actual Gitea runtime result pending**, no false PASS. See `docs/P05-OIDC-01.md` and `project/OIDC-E2E-ARCHITECTURE.md`.
+37
View File
@@ -0,0 +1,37 @@
name: ZitPlane P05-OIDC-01 Disposable Real Browser Acceptance
# Dispatch by authorized operator only. No PR, push or schedule.
# Uses CI-owned Docker resources; never access production/real user data.
on:
workflow_dispatch:
permissions:
contents: read
jobs:
oidc:
name: Disposable ZITADEL Client User Browser OIDC and Cleanup
runs-on: ubuntu-latest
container: node:22-alpine
timeout-minutes: 55
steps:
- name: Install Git before isolated Gitea checkout
run: apk add --no-cache git
- uses: actions/checkout@v4
with:
github-server-url: https://dev.ivib.cc
- name: Disposable backend, real OIDC client/user, browser and negative tests
run: |
set -eu
apk add --no-cache python3 docker-cli docker-cli-compose
sh tests/ci/oidc_e2e/run.sh
- name: Always remove ONLY run-owned Docker containers, credentials and volumes
if: always()
run: |
set -eu
if [ ! -f tests/ci/oidc_e2e/cleanup.sh ]; then
echo '::error::CI-owned cleanup script missing; cannot claim teardown'
exit 1
fi
apk add --no-cache docker-cli docker-cli-compose
sh tests/ci/oidc_e2e/cleanup.sh
+1
View File
@@ -13,6 +13,7 @@ Compact, developer-friendly monorepo for a central identity service, a branded l
- **P05-SEC-01:** Gitea Run #87 **3 PASS / 1 FAIL**. Account and Login patched Next.js `16.4.6` builds PASS, Login 1219/1219 upstream unit tests PASS, Account audit 0. Login OpenTelemetry patched dependencies reduced prior 18 Moderate to **2 remaining** (glob/minimatch); strict Moderate security gate correctly FAILS. Current dependency patch retained; complete security acceptance requires a separate narrow transitive remediation phase. See `docs/P05-SEC-01.md`.
- **P05-SEC-02:** Seven parent-scoped PNPM overrides resolved `glob`/`minimatch` advisories. Gitea Run #88 Login production audit **0 Moderate/High/Critical PASS**, but Login frozen install/build/units **NOT RUN** because a new CI override validator misparsed existing `>=` version ranges; post-run regex correction **not CI-verified**. Full acceptance **BLOCKED** pending a separately approved focused CI run. Account jobs intentionally skipped. See `docs/P05-SEC-02.md`.
- **P05-SEC-02-A01:** **Gitea Run #89 SUCCESS** on `ff4c58e`: corrected exact override contract PASS, pinned PNPM frozen install PASS, official Login V2 standalone build PASS, upstream Vitest **1219/1219 PASS**, Login production audit **0 Moderate/High/Critical**; Account jobs skipped. **Dependency security/build unit acceptance complete; real user OIDC/MFA E2E and production integration NOT verified**. See `docs/P05-SEC-02-A01.md`.
- **P05-OIDC-01:** Approved manual disposable real ZITADEL OIDC client/user + Chromium original Login V2/Auth.js callback/session/negative test harness, cleanup enforced; **actual CI pending**, no live production or auth source changes. See `docs/P05-OIDC-01.md`.
- **Production / Coolify:** not configured or deployed.
## Documentation and project knowledge
+3
View File
@@ -27,3 +27,6 @@ Snapshot: 2026-11-22. **Run #86** accepted isolated ZITADEL backend; **Run #89**
Prior historical **P02 source-only Python static tests** passed 3/3 in earlier work, and P03 upstream imported Git blobs matched 638/638. These are **not equivalent** to a running authentication system.
Future feature additions need an evidence-backed status update here, an exact developer implementation record in `project/`, a pre-change scope entry in `notes/`, and corresponding user guide updates.
**P05-OIDC-01 source status (pre-run):** The new Gitea-only disposable IAM_OWNER → official OIDC project/client/human → real Chromium original Login V2/Auth.js positive callback/session/negative checks and strict cleanup harness is **IMPLEMENTED IN SOURCE**, **RUNTIME NOT YET VERIFIED**. Do not mark real login, production TLS, Admin Console or MFA as verified unless one actual CI run executes those exact assertions and succeeds.
+1
View File
@@ -13,6 +13,7 @@ Every file listed below is a direct child of `docs/`. Add/remove rows whenever t
| [P05-SEC-01.md](P05-SEC-01.md) | Source-grounded dependency security patches, advisory blockers and CI verification | P05-SEC-01 / Run #87 3 PASS/1 FAIL, 2 Moderate open |
| [P05-SEC-02.md](P05-SEC-02.md) | Seven scoped PNPM parent overrides, patched lock and manual Login-only security CI evidence | P05-SEC-02 / Run #88 partial: security zero, build unverified |
| [P05-SEC-02-A01.md](P05-SEC-02-A01.md) | Gitea-only Login V2 full frozen-install/build/units/zero-advisory acceptance and status | P05-SEC-02-A01 / Run #89 SUCCESS |
| [P05-OIDC-01.md](P05-OIDC-01.md) | How isolated real OIDC Login V2 browser/session checks work; real CI status/limitations | P05-OIDC-01 / run pending |
| [SETUP-GUIDE.md](SETUP-GUIDE.md) | Operator/developer prerequisites, configs, activation and safety | DOCS-01 / active; runtime pending |
| [FEATURES-STATUS.md](FEATURES-STATUS.md) | Exact implemented/unavailable/unverified feature matrix | DOCS-01 / active |
| [TROUBLESHOOTING.md](TROUBLESHOOTING.md) | Known blockers and safe diagnosis based on source status | DOCS-01 / active |
+26
View File
@@ -0,0 +1,26 @@
# P05-OIDC-01 — Disposable Real OIDC Browser Acceptance
**Approved baseline:** `f423c696544f28a42d6a5d1ad0acfd88a3b6f56d`
**Planned verification:** manual Gitea Actions `.gitea/workflows/p05-oidc-acceptance.yml`
**Status:** CI-only implementation prepared; **NO real browser login or cleanup accepted until the focused Gitea run completes**.
## What this phase actually tests
- A completely disposable instance of the existing official **ZITADEL v4.20.4**, PostgreSQL, prebuilt **Login V2** and Traefik, with *no published runner host port*.
- An IAM_OWNER PAT for CI-only official provisioning. The token expires quickly, is never printed and is never mounted into the Account Portal/browser. Separate login-client PAT from the unchanged P02 Compose remains limited to Login V2.
- An actual project, OIDC Web authorization-code client with redirect `http://localhost:3000/api/auth/callback/zitadel`, and an actual **new CI-only human account**, with a random password and verified `.invalid` email. All data are within the disposable PostgreSQL volumes.
- A real Chromium browser follows **Continue with ZITADEL** → unmodified ZITADEL Login V2 username/password → genuine Auth.js authorization-code callback. PKCE S256, state and nonce are checked from actual outgoing browser authorization navigation; no sessions are mocked or injected.
- Success requires authenticated `GET /api/account/me` returning the **exact** provisioned user's ID, HttpOnly Auth.js session cookie, allowed protected Account page; rejection of anonymous/invalid callback, and local Account Portal sign-out returning 401.
- `always()` resource cleanup removes only CI-owned containers, the temporary secret volume, the IAM_OWNER bootstrap and PostgreSQL data, with explicit absence verification. A cleanup failure blocks acceptance.
## CI network and security boundary
The existing P02 Compose external issuer is `http://localhost:8080`. Account Portal `users/ui/src/lib/env.ts` allows HTTP localhost only when **not** running as production, and correctly requires HTTPS for production. Rather than altering authentication source or falsely claiming a production TLS test, this phase runs the unchanged Account Portal with **`next dev` only within a disposable Gitea Chromium container**, co-located on the private Docker proxy network namespace. A run-scoped localhost:8080 → proxy:80 TCP forward preserves exact discovery issuer and browser redirects **without publishing any host port**. The official ZITADEL backend, existing development Compose, original Login V2, Auth.js, Account UI, package manifests and lockfiles remain READ ONLY.
The user test credentials, admin PAT, OAuth codes, cookies and browser URLs with query strings are never printed, committed or uploaded. No production or real human account is touched.
## Running / interpretation
Authorize and dispatch the **one** manual workflow under Gitea [ZitPlane Actions](https://dev.ivib.cc/vibtools/ZitPlane/actions). Do not trigger it outside a dedicated Docker runner. A full PASS needs **all** official client/user creation, real browser password/callback/positive and negative identity evidence and complete owned resource teardown, verified by named CI markers and final job SUCCESS. If the runner lacks Docker, a provisioning API is incompatible, real authorization cannot complete, or cleanup fails, the phase remains **BLOCKED** with the exact verified point of failure; it is not silently downgraded into metadata/JWKS smoke.
**Not covered:** human MFA/passkeys, Admin Console human E2E, production HTTPS/TLS issuer, source-built Login V2 runtime wiring, real global SSO logout and production Coolify deployment. These are separate explicit Scope Locks. The final actual Gitea results are recorded in `notes/P05-OIDC-01.md`.
+6
View File
@@ -70,6 +70,12 @@ Implement one explicitly approved phase at a time. Keep out-of-scope files, exis
- **Exact Scope Lock:** `tests/ci/transitive_override_contract.py` and `.gitea/workflows/p05-security-acceptance.yml` only if a NEW exact validator/CI defect is reproduced; `notes/**`, `project/**`, relevant `docs/**`, associated README/MINIFEST for evidence. All PNPM lock/config/manifests, original Login/UI/auth, Account Portal, ZITADEL backend, Compose, production and unrelated files read-only. Preserve untracked `AI_INSTRUCTIONS.md`.
- **Run #89 ACCEPTED/SUCCESS**: tested SHA `ff4c58ed861474061c8f045be3a9f0752caf6ca0`. Existing corrected override validator PASS, seven parent pins + patched lock contract PASS; PNPM `10.30.3` frozen install PASS; Nx proto/client/Login 16.4.6 standalone production build PASS; upstream Vitest **84/84 files and 1219/1219 tests PASS**. Live production `pnpm audit --prod`: **0 Moderate/High/Critical**. Login jobs #194/#196 SUCCESS; Account jobs #193/#195 SKIPPED intentionally. One CI run, no local app test/build, no source/lock/deploy changes. Interactive OIDC/MFA/Admin Console login still unverified. Exact evidence: `notes/P05-SEC-02-A01.md`, `docs/P05-SEC-02-A01.md`.
## P05-OIDC-01 — Disposable Real OIDC Login/Session Acceptance (APPROVED 2026-11-22)
- Baseline `f423c696544f28a42d6a5d1ad0acfd88a3b6f56d`, prior Run #86 disposable backend, Run #87 Account and Run #89 Login build/security PASS. **Real OIDC positive callback/session still unverified**.
- Exact Write Scope: new `.gitea/workflows/p05-oidc-acceptance.yml`, focused `tests/ci/oidc_e2e/**` and narrow CI-only helpers, `notes/**`, `project/**`, relevant `docs/**`, associated README/MINIFEST and root navigation. Original P02 Compose/backend, original Login V2/auth UI, Account Portal Auth.js/UI, all package manifests/locks, production and unrelated files READ ONLY. Preserve untracked `AI_INSTRUCTIONS.md`.
- Pre-change plan `notes/P05-OIDC-01.md` documents official IAM_OWNER bootstrap PAT (not the Login-client PAT), disposable project/real OIDC Web client and human, original Login V2 Chromium password flow, Auth.js PKCE/state/nonce, positive Account API/session and anonymous/invalid negatives, and mandatory run-owned secret/Compose cleanup. No public host ports. Existing HTTP localhost issuer requires development **only in the disposable CI container**, not a production TLS acceptance.
- One manual Gitea Actions CI cycle; **no local app installs/builds/tests/dev servers or production deployment**, no fake login/session or identity bypass. Exact real job results required for PASS. `docs/P05-OIDC-01.md`, `project/OIDC-E2E-ARCHITECTURE.md`.
## P05 - Full Integration (proposed, NOT approved)
Shared design system, production-safe Compose topology and verified Login/Account OIDC wiring. No live deployment; separate approval.
+1 -1
View File
@@ -26,4 +26,4 @@
Full update policy is in root [AGENTS.md](../AGENTS.md). A list of available docs is in [MINIFEST.md](MINIFEST.md).
For Gitea Run #89 final Login frozen build/unit/zero-advisory acceptance and the remaining interactive identity gaps see [P05-SEC-02-A01.md](P05-SEC-02-A01.md). For Run #88 historical blocker and corrected helper see [P05-SEC-02.md](P05-SEC-02.md). For Gitea Run #87 findings see [P05-SEC-01.md](P05-SEC-01.md). For backend-only isolated runtime verification see [P05-CI-03.md](P05-CI-03.md); for initial full workflow and its limitations see [P05-CI-01.md](P05-CI-01.md). A green backend discovery smoke is not an authenticated user-login result.
For the P05-OIDC-01 isolated real-user/Chromium login callback acceptance harness, actual CI outcome and safety boundaries see [P05-OIDC-01.md](P05-OIDC-01.md). For Gitea Run #89 final Login frozen build/unit/zero-advisory acceptance see [P05-SEC-02-A01.md](P05-SEC-02-A01.md). For Run #88 historical blocker and corrected helper see [P05-SEC-02.md](P05-SEC-02.md). For Gitea Run #87 findings see [P05-SEC-01.md](P05-SEC-01.md). For backend-only isolated runtime verification see [P05-CI-03.md](P05-CI-03.md); for initial full workflow and its limitations see [P05-CI-01.md](P05-CI-01.md). A green backend discovery smoke is not an authenticated user-login result.
+5
View File
@@ -100,3 +100,8 @@ Use Gitea Actions → **ZitPlane P05 Dependency Security Acceptance (SEC-01/02)*
**P05-SEC-02-A01 VERIFIED:** Gitea [Run #89](https://dev.ivib.cc/vibtools/ZitPlane/actions/runs/89) succeeded with manual `login_only=true`: patched seven-parent dependency contract, pinned frozen PNPM install, proto/client/Login standalone production build, **1219/1219** upstream tests and production registry audit **0 Moderate/High/Critical**. Account jobs were intentionally skipped. No user credential, interactive OIDC login, MFA, production TLS or deployment was tested; do not treat this as a deployed service.
## P05-OIDC-01 — isolated real-user OIDC verification, Gitea only
In Gitea `vibtools/ZitPlane` → Actions → **ZitPlane P05-OIDC-01 Disposable Real Browser Acceptance** → manual Run workflow on `main` only when explicitly approved. The workflow provisions its own short-lived IAM_OWNER PAT, isolated ZITADEL project/client/verified test human, then tests the actual ZITADEL Login V2 username/password and Auth.js Account callback in Chromium. It does **not** use your real users, public domain, production secrets or host-published HTTP ports. It removes its test credentials, browser and isolated database/volumes via an `always()` step; any cleanup failure prevents phase acceptance. See `docs/P05-OIDC-01.md` for the expected checks and current real run result. This test uses CI-only HTTP loopback (Account development mode), **not** the actual production HTTPS issuer.
+5
View File
@@ -50,3 +50,8 @@ Run #88 Login build job #190 stopped before `pnpm install --frozen-lockfile` whe
## P05-SEC-02-A01 — Run #88 validator false-positive closed in Run #89
The earlier Run #88 CI helper misread `axios@>=` and similar version-range keys as parent overrides. The already-committed suffix-only `>glob` / `>minimatch` correction **passed** in Gitea [Run #89](https://dev.ivib.cc/vibtools/ZitPlane/actions/runs/89), followed by successful frozen PNPM install, original Login Nx production build and **1219/1219** unit tests. The production registry vulnerability audit also passed with **0 Moderate/High/Critical**. The prior false-positive is now **CI-verified resolved**; no repeat local test or production deployment. If future login failures occur, distinguish CI build/unit success from still-untested authenticated OIDC/callback/MFA integration.
## P05-OIDC-01 — isolated real OIDC browser acceptance troubleshooting
The new manual Gitea `p05-oidc-acceptance.yml` is **not a production deployment**. If runner Docker ownership preflight fails, do not delete an existing network/volume or reuse secrets; use a clean runner. If IAM_OWNER PAT or API client/user creation fails, do not use P02's restricted `IAM_LOGIN_CLIENT` PAT as a substitute. If the original Login V2 browser or Auth.js callback fails, report only the safe blocker marker and do **not** mock tokens, disable PKCE/state/nonce or alter production auth source. If cleanup cannot prove empty run-owned Docker resources, the job must remain FAILED. The HTTP localhost issuer works only in the private Gitea CI development environment; production HTTPS requires a separate Scope Lock. Exact current evidence: `notes/P05-OIDC-01.md`.
+1
View File
@@ -15,5 +15,6 @@ This is the chronological **index**. Phase-specific scope/implementation evidenc
| 2026-11-22 | P05-SEC-01 | Next.js 16.4.6, compatible OTel instrumentation, frozen locks and strict advisory gates | Run #87: 3 PASS/1 FAIL; 17/19 prior findings no longer reported, 2 Moderate Login blockers. [Evidence](P05-SEC-01.md) |
| 2026-11-22 | P05-SEC-02 | Seven scoped parent overrides for glob/minimatch, pinned PNPM lock; one focused Gitea run | Run #88: Login security 0 findings PASS, build gate FAIL before frozen install on CI helper false-positive. Post-run regex fix unverified; [evidence](P05-SEC-02.md) |
| 2026-11-22 | P05-SEC-02-A01 | One-run final acceptance of corrected CI parser and unchanged Login lockfile/seven overrides | **Run #89 SUCCESS** on `ff4c58e`: frozen install, standalone build and upstream 1219/1219 tests PASS; audit 0 Moderate/High/Critical; Account jobs skipped. [Evidence](P05-SEC-02-A01.md) |
| 2026-11-22 | P05-OIDC-01 | Real disposable ZITADEL OIDC client/user, Chromium original Login V2/Auth.js callback/identity and owned-only cleanup | Source prepared; one focused Gitea run pending; [scope/evidence](P05-OIDC-01.md) |
Rules: Append new phases or fixes; never silently rewrite a past result. Separate **implemented**, **verified**, **blocked**, and **proposed**. Never log a user secret or personal data.
+1
View File
@@ -11,6 +11,7 @@
| [P05-SEC-01.md](P05-SEC-01.md) | Pre-change security scope, remediation, exact advisory evidence, one CI run and closure | P05-SEC-01 / Run #87 completed, 2 Moderate open |
| [P05-SEC-02.md](P05-SEC-02.md) | Exact root chain, seven PNPM parent overrides, one focused Gitea CI and closure evidence | P05-SEC-02 / Run #88 security PASS, build blocked; parser post-run patch unverified |
| [P05-SEC-02-A01.md](P05-SEC-02-A01.md) | Single-run Login-only final frozen/build/unit/security acceptance, scope lock and evidence | P05-SEC-02-A01 / Run #89 SUCCESS, accepted |
| [P05-OIDC-01.md](P05-OIDC-01.md) | Pre-change real browser OIDC Scope Lock, provision/redirect/session/negative tests and one CI run evidence | P05-OIDC-01 / implementation prepared, real CI pending |
| [CHANGELOG.md](CHANGELOG.md) | Short append-only chronological phase log and links to detailed reports | DOCS-01 / active |
Update this manifest whenever any direct child file or directory changes. Use **actual source state**; a planned file must be labeled planned, not present.
+43
View File
@@ -0,0 +1,43 @@
# P05-OIDC-01 — Real Disposable OIDC Login and Session Acceptance
**Date:** 2026-11-22
**User-approved baseline:** `f423c696544f28a42d6a5d1ad0acfd88a3b6f56d` on Gitea `vibtools/ZitPlane/main`.
**Pre-implementation state:** APPROVED / SCOPE LOCKED — this planning record is written before any CI implementation edits.
**Prior verified evidence:** Run #86 disposable backend/JWKS/DB persistence/teardown PASS; Run #87 Account build/security and negative authorization PASS; Run #89 Login V2 frozen standalone build/1219 tests and zero Moderate+ audit PASS. None proved a real authorization callback with a human user.
## Exact approved write scope and hard boundaries
Allowed: new `.gitea/workflows/p05-oidc-acceptance.yml`, new `tests/ci/oidc_e2e/**`, narrow CI-only helper files under `tests/ci/**`, `notes/**`, `project/**`, relevant `docs/**`, associated `README.md` and exact `MINIFEST.md` updates and root navigation only if necessary.
**Read-only:** `core/backend/zitadel/**`, `deployment/docker/**`, `auth/ui/v2/**` application/authentication code, `users/ui/**` application/authentication code, all package manifests and lockfiles, production infrastructure, third-party upstream source, secrets, and all unrelated files. Preserve unrelated untracked root `AI_INSTRUCTIONS.md` without staging.
No local application installs/builds/tests/dev servers/Docker. No production deployment, real credentials/accounts, tags or releases. **One focused Gitea Actions CI cycle ONLY**. A blocked test is documented honestly, not called PASS.
## Verified source and official API research (read-only, before implementation)
1. P02 Compose is the untouched official ZITADEL `ghcr.io/zitadel/zitadel:v4.20.4`, official prebuilt Login V2 `ghcr.io/zitadel/zitadel-login:v4.20.4`, PostgreSQL 17.10 and Traefik 3.7.7. Initial ZITADEL external origin is **`http://localhost:8080`**. Existing `tests/ci/compose.portless.override.yaml` removes the public/shared runner host 8080 mapping and connects through run-owned `zitplane-backend-dev-internal` Docker network. Existing `backend_cleanup.sh` removes only run-owned project containers/network/volumes with a marker and verifies cleanup.
2. `users/ui/src/lib/env.ts` rejects an HTTP issuer when `NODE_ENV=production`, but accepts HTTP loopback only in development. The Account Portal source must remain unchanged; running `next dev` **only inside a disposable Gitea Docker container** is necessary for the current HTTP localhost issuer. This can prove the real application Auth.js OIDC flow in CI development context, **NOT production-HTTPS topology**. For production-style TLS additional approval is required.
3. `users/ui/src/auth.ts` uses the genuine NextAuth ZITADEL provider with `checks: [pkce, state, nonce]`, JWT session, explicit subject and expiration validation and fail-closed no-user identity. Signin UI server action on `/signin` calls `signIn("zitadel", {redirectTo:"/account"})`; `/api/account/me` returns HTTP 401/no-store anonymously and authenticated user ID only for valid session.
4. Official ZITADEL docs `https://zitadel.com/docs/self-hosting/manage/configure/configure` and official `cmd/setup/steps.yaml` confirm FirstInstance machine credentials can create an ephemeral IAM_OWNER service account with `ZITADEL_FIRSTINSTANCE_PATPATH`, `ZITADEL_FIRSTINSTANCE_ORG_MACHINE_MACHINE_USERNAME`, `ZITADEL_FIRSTINSTANCE_ORG_MACHINE_PAT_EXPIRATIONDATE`. **DO NOT** confuse P02's dedicated `IAM_LOGIN_CLIENT` PAT with an administrator PAT. CI-only Compose override may add an IAM_OWNER machine PAT to a transient bootstrap volume, only at FIRST startup.
5. Official project/OIDC application creation: `POST /management/v1/projects`; `POST /management/v1/projects/{projectId}/apps/oidc` with redirect `http://localhost:3000/api/auth/callback/zitadel`, OIDC Web/Authorization Code/Basic client secret and `devMode:true`. Official v2 human API `POST /v2/users/human` can create a verified disposable user with a random password and `changeRequired:false`. Cite official refs: `https://zitadel.com/docs/reference/api/management/zitadel.management.v1.ManagementService.AddOIDCApp`, `https://zitadel.com/docs/guides/integrate/login-ui/username-password`. API permissions/response must be checked by the actual isolated runtime; do not invent client/user IDs.
6. Browser test should use pinned disposable Playwright Chromium, drive real original Login V2 `data-testid="username-text-input"` and `data-testid="password-text-input"`; no mocked identity provider, fake token, cookie injection, insecure TLS bypass or authentication shortcut. Test real browser state/PKCE/nonce, actual token exchange, callback, protected user identity positive, anonymous/invalid-flow negative and local sign-out if feasible.
7. **CI network design:** avoid publishing any host port. Launch P02 services with run-owned Compose project + portless override and an additional **CI-only first-instance owner PAT override**. Run a transient loopback port-8080 TCP forwarder in the isolated Traefik proxy **network namespace**, so `localhost:8080` issuer, `localhost:3000` Account Portal and real browser all share one disposable network namespace without host binds. Start a pinned Playwright image as a runner container sharing that namespace; copy only Account app and CI scripts, install project dependencies and Playwright only in ephemeral runner; no local Windows builds/tests. API provisioning uses separate Python runtime with IAM_OWNER PAT volume read-only and writes disposable client/user secrets only to a CI-owned volume, which is shared read-only with the browser runner. Never print or upload PAT, passwords, client secret, session tokens, screenshots or callback query values.
8. **Fail-closed preflight and cleanup:** refuse preexisting CI project, existing fixed network, unrelated credentials/markers/volumes; cleanup owns only exact run ID and project marker. Always remove owned Playwright and TCP forwarder containers, verify no leftover CI owned app browser containers/secret volume, call existing backend cleanup for ZITADEL stack, and fail job if cleanup incomplete. No production/user volumes or network touched.
## Focused implementation plan, in order
1. Implement the CI-only first-instance IAM_OWNER and no-host-port Compose override, root `run.sh` with strict run ID/project/network preflight and explicit cleanup scripts; IAM_OWNER PAT expires quickly.
2. Implement `provision.py` with bounded official management/user API calls, exact expected project/app/client/human response checks and no secret logs. Save generated secrets only inside disposable volume with `0600` permissions. Do not dump on API errors.
3. Implement original-app-only `browser.cjs` and ephemeral `browser.sh`: invoke real Next dev (CI ONLY) and real Playwright Chromium for positive OIDC browser flow, PKCE/state/nonce observation, account API/session positive and negative, bounded wait and safe error diagnostics. **No mock session or bypass**.
4. Add new manual-only `.gitea/workflows/p05-oidc-acceptance.yml` with one isolated job, Docker preflight, no real credentials, always-run cleanup after failure, finite timeout, no CI artifacts containing secrets.
5. Update `notes/project/docs` and exact manifests, inspect allowed-path diff and security integrity, then commit/push Gitea main.
6. Dispatch **ONE** focused isolated Gitea run; check exact actual steps/jobs/cleanup. Record complete PASS only on real positive browser login and proper teardown. If provisioning/browser/network can't complete, record the exact blocker and remaining P05-OIDC acceptance as **BLOCKED/DEFERRED**, without a second run or auth/source modification. Final notes/docs commit and remote SHA verify.
7. Automatically propose next narrow Scope Lock + compact plan and copy-ready approval, scoped to actual remaining blocker if any.
## Acceptance gates (all mandatory, NOT claimed in advance)
- Disposable ownership/pinned images/boot/readiness/client project and real test human creation PASS, with no real secrets used.
- Browser reaches original Login V2 via real ZITADEL authorize redirect with PKCE S256, state and nonce; real password verifies and callback exchanges code.
- `GET /api/account/me` returns actual newly created user ID with private/no-store; protected Account page accessible with session, anonymous denied; malicious callback/session/issuer state rejected.
- **Always-run** owned container/volume/network/credential cleanup verified.
- No unauthorized repo changes, local builds/tests, fake PASS or production deployment. MFA/passkeys and production TLS **out of scope** unless actually verified with real flows; must remain deferred.
+1
View File
@@ -15,6 +15,7 @@ This is the **developer-focused implementation history**. `notes/CHANGELOG.md` i
| 2026-11-22 | P05-SEC-01 | Next.js/OTel minimal security manifests, reproducible locks, dedicated CI and strict Moderate+ gates | Run #87: Account/Login build PASS, Login Vitest 1219/1219, Account audit 0, Login 2 Moderate open; `notes/P05-SEC-01.md` |
| 2026-11-22 | P05-SEC-02 | Seven parent-targeted glob/minimatch patched resolutions, PNPM lockfile metadata-only, manual Login-only CI and post-run validator fix | Run #88: strict Login audit 0 findings PASS, Login build job blocked before install by parser false-positive; post-run fix untested. `notes/P05-SEC-02.md` |
| 2026-11-22 | P05-SEC-02-A01 | Verify existing corrected helper, exact seven PNPM scoped overrides, frozen Login Nx build and upstream Vitest; no source/lock changes | **Gitea Run #89 SUCCESS** on `ff4c58e`, 84/84 files, 1219/1219 tests, Login audit 0 Moderate/High/Critical; `notes/P05-SEC-02-A01.md` |
| 2026-11-22 | P05-OIDC-01 | CI-only real OIDC IAM_OWNER bootstrap, project/client/user creation, Playwright password/callback/identity/negative tests and always cleanup | Source prepared; real CI outcome pending; `notes/P05-OIDC-01.md` |
## Required entry for each future change
+7
View File
@@ -124,3 +124,10 @@ One manual `p05-security-acceptance.yml` dispatch with `login_only=true` tests t
**One** manual Gitea [Run #89](https://dev.ivib.cc/vibtools/ZitPlane/actions/runs/89) tested SHA `ff4c58ed861474061c8f045be3a9f0752caf6ca0`, 2026-11-22 16:30:28–16:34:54 UTC, **overall SUCCESS**. `login_only=true` skipped Account build/security jobs #193/#195, previously accepted in Run #87. Login job #194 **SUCCESS**: corrected exact seven-parent override source contract/lock matched (`ZITPLANE_EXACT_SEVEN_PARENT_OVERRIDES_PASS`, `ZITPLANE_GLOB_MINIMATCH_PATCHED_LOCK_CONTRACT_PASS`), PNPM 10.30.3 frozen installation (`Lockfile is up to date`, 1121 packages) PASS, official Nx proto/client/Login 16.4.6 standalone build/artifact PASS, upstream Vitest **84/84 test files, 1219/1219 unit tests PASS**. Login security job #196 **SUCCESS**: fail-closed HIGH/CRITICAL gate PASS, production registry `pnpm audit --prod` **0 Moderate/High/Critical**, `ZITPLANE_PNPM_ZERO_MODERATE_HIGH_CRITICAL_PASS`.
No new CI/auth/application/manifest/lock changes in A01; all checks were against the existing corrected validator. This closes the dependency-security/frozen-build acceptance only, **not** human OIDC login/callback, real MFA or production integration. See `notes/P05-SEC-02-A01.md` for exact markers/timestamps.
## P05-OIDC-01 — Gitea-only real OIDC browser acceptance
New manual workflow `.gitea/workflows/p05-oidc-acceptance.yml` executes **one** isolated Docker runner job. `tests/ci/oidc_e2e/run.sh` creates the unchanged P02 stack under exact numeric run ownership and no host ports; a CI-only FirstInstance IAM_OWNER machine PAT and official API provision a disposable OIDC client/user. A pinned Chromium image runs the **unmodified** Account Portal in isolated CI development mode, driving official prebuilt Login V2 and real Auth.js PKCE/state/nonce, callback, authenticated Account API/page, negatives and local logout. An `always()` step calls `tests/ci/oidc_e2e/cleanup.sh` to remove only owned browser/forwarder/secrets and invokes audited backend owned-data cleanup. The run must fail if cleanup is incomplete; no browser secrets are logged/uploaded.
**Important:** The original backend external issuer is HTTP localhost, while Account Portal production mode correctly requires HTTPS. This **CI development-origin** browser acceptance does not certify production TLS, full self-hosted login source wiring, MFA or Admin Console human login. See `project/OIDC-E2E-ARCHITECTURE.md` for individual modules and `notes/P05-OIDC-01.md` for the actual run status.
+5
View File
@@ -163,3 +163,8 @@ P02 dev Compose, core backend helper, Login V2 source, Account Portal and all de
| `notes/P05-SEC-02.md`, `docs/P05-SEC-02.md` | Pre-edit parent-chain evidence, exact patch and actual run outcome |
Official Login V2 user/auth source, user Account Portal, backend Compose and production infrastructure remain unmodified.
## P05-OIDC-01 — disposable real OIDC acceptance source map
`.gitea/workflows/p05-oidc-acceptance.yml`: one manual Gitea isolated Docker job and mandatory `always()` cleanup. `tests/ci/oidc_e2e/compose.owner.override.yaml`: only ephemeral IAM_OWNER PAT bootstrap; original P02 Compose untouched. `tests/ci/oidc_e2e/run.sh`: ownership preflight, portless backend startup, private loopback routing and original-app browser harness. `tests/ci/oidc_e2e/provision.py`: official ZITADEL API client/project/verified human creation and 0600 temporary secret fixture. `tests/ci/oidc_e2e/browser.sh`: CI-only pinned Playwright/Account npm dependencies. `tests/ci/oidc_e2e/browser.cjs`: actual Chromium Auth.js/OIDC/password/callback/session and fail-closed checks. `tests/ci/oidc_e2e/cleanup.sh`: owned-only containers, volume, bootstrap/database data cleanup. New directory `README.md` and `MINIFEST.md` document all modules. Detailed boundaries: `project/OIDC-E2E-ARCHITECTURE.md`; actual test outcomes pending Gitea.
+8
View File
@@ -119,3 +119,11 @@ Existing `tests/ci/security_advisory_gate.py` remains the independent **live reg
**P05-SEC-02 post-run correction:** `overridden(data)` in `tests/ci/transitive_override_contract.py` originally matched every `>`, incorrectly interpreting `axios@>=...`, `brace-expansion@>=...` and `esbuild@>=...` existing PNPM version constraints as new parent-child override selectors. The matching expression now restricts the suffix to `>glob` or `>minimatch` only, preserving the seven exact patch-parent check without changing registry audit logic. Run #88 predates the fix; this parser has **not yet passed CI**. Auth/session flows untouched.
## P05-OIDC-01 — CI-only real browser identity helper functions
- `tests/ci/oidc_e2e/provision.py::request()` restricts official management/user API requests to fixed localhost and returns **bounded** JSON, without printing token/secret/error-body values; `wait_until_ready()` and `main()` verify issuer discovery and use ephemeral IAM_OWNER bootstrap to create real disposable project, OIDC client and verified human. The resulting secrets file is written only to a CI Docker volume with mode 0600.
- `tests/ci/oidc_e2e/browser.cjs::fixture()` checks fixture integrity; `waitForPortal()` checks the CI-only Account dev server; `assertAuthorization()` validates genuine browser authorization params (S256 PKCE, state, nonce, client and exact redirect); `verifyAnonymous()` asserts unauthenticated API 401/no-store and protected-page redirect; `verifyInvalidCallback()` asserts tampered state/code cannot establish a session; `main()` uses original Login V2 username/password, waits for a *real* Auth.js callback, verifies created user ID, cookie, protected page and local logout.
- `run.sh` owns startup and preflight; `cleanup.sh` owns exact run-labeled teardown and failure if anything remains. These are not user-facing endpoints and must never run against shared/production Docker.
- `users/ui/src/auth.ts`, Account/API source and all upstream Login V2 runtime functions remain unchanged.
+1
View File
@@ -6,6 +6,7 @@
| [MINIFEST.md](MINIFEST.md) | Exact direct-child file inventory | DOCS-01 / active |
| [ARCHITECTURE.md](ARCHITECTURE.md) | Verified component boundaries, identity flows, future integration boundary | DOCS-01 / active |
| [CI-ARCHITECTURE.md](CI-ARCHITECTURE.md) | Gitea runner jobs, dependency reconciliation, disposable infrastructure and remaining auth gates | P05-CI-01 / prepared |
| [OIDC-E2E-ARCHITECTURE.md](OIDC-E2E-ARCHITECTURE.md) | Real disposable OIDC client/user, browser/Auth.js session flow, CI isolation and owned cleanup | P05-OIDC-01 / source implemented, runtime pending |
| [DEPENDENCY-SECURITY.md](DEPENDENCY-SECURITY.md) | Exact GHSA inventory, transitive parents, minimal patch ranges and CI evidence | P05-SEC-01 / active |
| [FILE-MAP.md](FILE-MAP.md) | First-party file + module explanation; upstream source references | DOCS-01 / active |
| [FUNCTIONS.md](FUNCTIONS.md) | First-party function/route map, safeguards and responsibilities | DOCS-01 / active |
+43
View File
@@ -0,0 +1,43 @@
# P05-OIDC-01 — Disposable Real Browser Authentication Architecture
**Approved baseline:** `f423c696544f28a42d6a5d1ad0acfd88a3b6f56d`.
**Current status:** CI-only source implemented; **real user callback/session acceptance requires actual terminal Gitea evidence**.
## Source and trust boundaries
| Exact first-party file | Main function / why it exists |
| --- | --- |
| `.gitea/workflows/p05-oidc-acceptance.yml` | Only manual Gitea Docker job, installs Git before checkout, executes CI-only harness and always calls owned-only teardown; never auto-runs on untrusted PRs |
| `tests/ci/oidc_e2e/run.sh` | Numeric Gitea run-ID validation, refusal of existing fixed network/projects/volumes/.env, disposable P02 Compose startup with no host ports, CI-only loopback namespace and secret volume, invokes official API provisioning and Chromium test |
| `tests/ci/oidc_e2e/compose.owner.override.yaml` | Add first-instance ephemeral IAM_OWNER machine PAT **only to the CI-owned API service**; official P02 developer Compose unchanged |
| `tests/ci/oidc_e2e/provision.py` | `request()` restricted to localhost API + Host, validates issuer/discovery, creates real project/Account OIDC Web client and verified temporary human via official management/User v2 APIs, writes generated credentials to 0600 separate CI secret volume, suppresses secret/error-body logging |
| `tests/ci/oidc_e2e/browser.sh` | Disposable Playwright Chromium image installs committed Account npm dependencies and pinned Playwright v1.58.2 inside container, not local developer PC |
| `tests/ci/oidc_e2e/browser.cjs` | `main()` drives actual browser OIDC authorization, original Login V2 UI fields, Auth.js callback, authenticated ID/API/pages, anon/invalid callback negative checks and local session sign-out; no mock or injected sessions |
| `tests/ci/oidc_e2e/cleanup.sh` | Only owner-labeled browser/forwarder containers and secret volume are removed, then existing `backend_cleanup.sh` removes and verifies run-marked Compose/DB/bootstrap state; fail-closed on unverified cleanup |
| `tests/ci/oidc_e2e/{README.md,MINIFEST.md}` | Isolated harness guide, exact source ownership and constraints |
## Exact runtime topology
The P02 backend routes ZITADEL at `http://localhost:8080` and prebuilt official Login V2 at `/ui/v2/login`. The pre-existing CI `compose.portless.override.yaml` removes the developer's host loopback bind. This phase uses an isolated Docker proxy network namespace, with a run-owned TCP forward from **namespace-local** localhost:8080 to Traefik:80. Both the one-off provisioning container and the Chromium/Account runner share that *private* namespace; nothing listens on the Gitea host's port 8080 or 3000.
`users/ui/src/lib/env.ts` disallows HTTP issuer in production and permits only HTTP localhost when `NODE_ENV=development`. Running the unmodified Account Portal with `next dev` inside a disposable CI container is therefore intentionally a **development-origin functional acceptance**, not a claim of HTTPS/production security acceptance. `users/ui/src/auth.ts` has real NextAuth ZITADEL `checks: ["pkce","state","nonce"]`, nonempty subject and token expiry guards; this phase does not edit them.
## Identity/provisioning security
A first-instance IAM_OWNER service user is created only inside disposable ZITADEL during initial setup, with its PAT written to the run-owned bootstrap volume and a short expiry. This is **not** the existing IAM_LOGIN_CLIENT service token used by the official Login V2. The IAM_OWNER token is mounted read-only **only to the provisioning Python container**, not to Chromium. The test app/client secret and randomly generated password are transferred via a separate run-labeled volume read-only to Chromium, and neither logs nor Git contain sensitive values. The test user's email is a verified `.invalid` address, not a real recipient; owner token, identity client and user are destroyed along with owned Postgres/bootstrap volumes.
## Verification contract
- ZITADEL 4 services live, exact isolated portless config, authoritative issuer and OIDC discovery
- IAM_OWNER PAT exists, official project/app/client/user APIs return valid required fields
- Chromium's real authorization navigation contains response_type code, matching client/redirect, S256 challenge, state and nonce
- Original Login V2 form receives the ephemeral username/password; browser follows a genuine authorization code exchange to the protected Account Portal
- Actual `GET /api/account/me` returns created subject ID and no-store, HttpOnly session cookie; protected page valid
- Anonymous API + protected page rejected; tampered callback fails closed; portal sign-out returns unauthenticated API
- Always owned-only cleanup confirms browser, port forwarder, secret volume, Compose containers, network, DB and bootstrap credentials gone
**Never equate** a static source check, issuer/JWKS check or successful redirect with a successful interactive login/callback. MFA/passkey, Admin Console human sign-in, production TLS and custom source-built Login V2 runtime wiring are future explicitly approved phases.
## References
ZITADEL official endpoints and bootstrap specification: `https://github.com/zitadel/zitadel/blob/main/cmd/setup/steps.yaml`, `https://zitadel.com/docs/reference/api/management/zitadel.management.v1.ManagementService.AddOIDCApp` and `https://zitadel.com/docs/guides/integrate/login-ui/username-password`. Actual Gitea result: `notes/P05-OIDC-01.md`.
+5
View File
@@ -79,3 +79,8 @@ These are **major** dependency migrations underneath older parents, not an upstr
**Final A01 evidence:** Gitea Run #89 on `ff4c58e` verified exactly seven scoped patches and frozen PNPM 10.30.3 install (1121 packages), official Login proto/client/Next 16.4.6 standalone production build, upstream Vitest **84/84 files + 1219/1219 unit tests**, and zero live Moderate/High/Critical Login production advisory records. The Account and backend jobs were deliberately not rerun. This was CI-only, without local application dependency installation, local build/test or deployment. Product user authentication integration still requires separate live disposable OIDC acceptance.
## P05-OIDC-01 — isolated browser test tooling and why
CI only: official ZITADEL v4.20.4, official Login V2 v4.20.4, PostgreSQL 17.10/Traefik 3.7.7 from P02; existing portless Compose override; new `alpine:3.21` namespace-local `socat` loopback forwarder, `python:3.12-alpine` stdlib API provisioner, pinned `mcr.microsoft.com/playwright:v1.58.2-noble` (Chromium), pinned `playwright@1.58.2` and the Account Portal's existing `npm ci` lock inside an ephemeral browser container. No manifests or lockfiles changed, no local PC builds/tests, and no host HTTP port published. Dynamic IAM_OWNER bootstrap PAT expires in two hours and all token/password/client data are destroyed with owned volumes after the run. P02 issuer HTTP localhost requires Account `NODE_ENV=development` **inside CI only**; production HTTPS remains unverified. Detailed topology and cleanup: `project/OIDC-E2E-ARCHITECTURE.md`.
+33 -21
View File
@@ -1,27 +1,27 @@
# Git-tracked source inventory ? exact paths
# ZitPlane ? exact tracked source inventory
**Snapshot:** 2026-11-22, P05-SEC-02-A01 source accepted by **Gitea Run #89 SUCCESS** on `ff4c58ed861474061c8f045be3a9f0752caf6ca0`. Corrected validator, frozen Login build/1219 unit tests and zero Moderate/High/Critical audit PASS. Final docs-only follow-up commit does not change tested source.
**Snapshot:** 2026-11-22, P05-OIDC-01 source candidate on approved baseline `f423c69`. New browser OIDC integration is **NOT runtime-verified until actual Gitea CI**.
**Git-tracked paths: 734.** Untracked `AI_INSTRUCTIONS.md` and ignored secrets excluded.
**Git-tracked file paths: 746.** Untracked `AI_INSTRUCTIONS.md` and ignored local secrets excluded.
This file inventories actual Git-tracked file paths; it does not prove production/interactive OIDC or CI runtime. See `notes/P05-SEC-02-A01.md` and `project/DEPENDENCY-SECURITY.md`.
This is an exact Git file-path locator, not a claim of source-built Login runtime, browser authentication or deployment. See `notes/P05-OIDC-01.md` and `project/OIDC-E2E-ARCHITECTURE.md`.
| Group | Paths | Responsibility |
| --- | ---: | --- |
| `(repository root)` | 6 | Repository root |
| `.gitea` | 7 | Manual Gitea workflows |
| `auth` | 639 | Original official Login V2 plus verified security dependency metadata |
| `core` | 2 | Backend developer orchestration |
| `deployment` | 2 | Dev-only Compose |
| `docs` | 18 | User/operator guidance |
| `notes` | 10 | Exact pre-change scope/evidence |
| `(repository root)` | 6 | Tracked repository root |
| `.gitea` | 8 | Manual Gitea CI-only workflows |
| `auth` | 639 | Original official ZITADEL Login V2 source/locked dependencies |
| `core` | 2 | Local backend helper |
| `deployment` | 2 | Read-only developer Compose |
| `docs` | 19 | User/operator guides |
| `notes` | 11 | Prechange plans/evidence |
| `packages` | 1 | Placeholder |
| `project` | 11 | Development architecture/security/function maps |
| `scripts` | 1 | Script placeholder |
| `tests` | 13 | Focused CI-only contracts |
| `users` | 24 | Account Portal read-only |
| `project` | 12 | Developer architecture/source/security maps |
| `scripts` | 1 | Placeholder |
| `tests` | 21 | CI verification scripts and disposable OIDC browser harness |
| `users` | 24 | Read-only Account Portal |
## Exact tracked paths
## Exact Git-tracked paths
### (repository root) ? 6 files
@@ -32,7 +32,7 @@ This file inventories actual Git-tracked file paths; it does not prove productio
- `MINIFEST.md`
- `README.md`
### .gitea ? 7 files
### .gitea ? 8 files
- `.gitea/MINIFEST.md`
- `.gitea/README.md`
@@ -40,6 +40,7 @@ This file inventories actual Git-tracked file paths; it does not prove productio
- `.gitea/workflows/README.md`
- `.gitea/workflows/p05-backend-acceptance.yml`
- `.gitea/workflows/p05-ci.yml`
- `.gitea/workflows/p05-oidc-acceptance.yml`
- `.gitea/workflows/p05-security-acceptance.yml`
### auth ? 639 files
@@ -694,7 +695,7 @@ This file inventories actual Git-tracked file paths; it does not prove productio
- `deployment/README.md`
- `deployment/docker/compose.backend.dev.yaml`
### docs ? 18 files
### docs ? 19 files
- `docs/ARCHITECTURE.md`
- `docs/DEVELOPMENT.md`
@@ -706,6 +707,7 @@ This file inventories actual Git-tracked file paths; it does not prove productio
- `docs/P05-CI-01.md`
- `docs/P05-CI-02.md`
- `docs/P05-CI-03.md`
- `docs/P05-OIDC-01.md`
- `docs/P05-SEC-01.md`
- `docs/P05-SEC-02-A01.md`
- `docs/P05-SEC-02.md`
@@ -715,7 +717,7 @@ This file inventories actual Git-tracked file paths; it does not prove productio
- `docs/TROUBLESHOOTING.md`
- `docs/USER-GUIDE.md`
### notes ? 10 files
### notes ? 11 files
- `notes/CHANGELOG.md`
- `notes/DOCS-01.md`
@@ -723,6 +725,7 @@ This file inventories actual Git-tracked file paths; it does not prove productio
- `notes/P05-CI-01.md`
- `notes/P05-CI-02.md`
- `notes/P05-CI-03.md`
- `notes/P05-OIDC-01.md`
- `notes/P05-SEC-01.md`
- `notes/P05-SEC-02-A01.md`
- `notes/P05-SEC-02.md`
@@ -732,7 +735,7 @@ This file inventories actual Git-tracked file paths; it does not prove productio
- `packages/README.md`
### project ? 11 files
### project ? 12 files
- `project/ARCHITECTURE.md`
- `project/CHANGELOG.md`
@@ -742,6 +745,7 @@ This file inventories actual Git-tracked file paths; it does not prove productio
- `project/FILE-MAP.md`
- `project/FUNCTIONS.md`
- `project/MINIFEST.md`
- `project/OIDC-E2E-ARCHITECTURE.md`
- `project/README.md`
- `project/SETUP-AND-DEPENDENCIES.md`
- `project/SOURCE-INVENTORY.md`
@@ -750,7 +754,7 @@ This file inventories actual Git-tracked file paths; it does not prove productio
- `scripts/README.md`
### tests ? 13 files
### tests ? 21 files
- `tests/README.md`
- `tests/ci/MINIFEST.md`
@@ -761,6 +765,14 @@ This file inventories actual Git-tracked file paths; it does not prove productio
- `tests/ci/backend_cleanup.sh`
- `tests/ci/compose.portless.override.yaml`
- `tests/ci/oidc_discovery.py`
- `tests/ci/oidc_e2e/MINIFEST.md`
- `tests/ci/oidc_e2e/README.md`
- `tests/ci/oidc_e2e/browser.cjs`
- `tests/ci/oidc_e2e/browser.sh`
- `tests/ci/oidc_e2e/cleanup.sh`
- `tests/ci/oidc_e2e/compose.owner.override.yaml`
- `tests/ci/oidc_e2e/provision.py`
- `tests/ci/oidc_e2e/run.sh`
- `tests/ci/security_advisory_gate.py`
- `tests/ci/source_contract.py`
- `tests/ci/transitive_override_contract.py`
+1
View File
@@ -13,3 +13,4 @@
| [backend_cleanup.sh](backend_cleanup.sh) | Always-run cleanup of marked CI-owned Compose project/volumes, with leftover verification | P05-CI-03 |
| [security_advisory_gate.py](security_advisory_gate.py) | Strict CI registry JSON gate: rejects incomplete reports and any Moderate/High/Critical finding | P05-SEC-01 |
| [transitive_override_contract.py](transitive_override_contract.py) | Verify exact seven parent-scoped patched PNPM overrides and no known vulnerable resolved lock entries | P05-SEC-02 |
| [oidc_e2e/](oidc_e2e/) | Isolated real OIDC client/user/browser provisioning/negative checks, CI-only Compose owner PAT and resource cleanup | P05-OIDC-01 |
+3
View File
@@ -22,3 +22,6 @@ Add new CI checks and update `MINIFEST.md`, `project/`, `docs/`, and `notes/` in
**P05-SEC-02-A01 final acceptance:** Existing corrected `transitive_override_contract.py` successfully executed in **Gitea Run #89** (exact seven parent selector and patched lock markers). Frozen PNPM install, Next Login standalone build, and Vitest 84/84 files/1219/1219 cases PASS. Separate production `security_advisory_gate.py` reports **0 Moderate/High/Critical**, no suppressed findings. Two Account jobs intentionally skipped using `login_only=true`. No local test run; no real authenticated OIDC session/production deployment.
**P05-OIDC-01** is the new CI-only directory `tests/ci/oidc_e2e/`: exact files and first-party instructions in `README.md` and `MINIFEST.md` inside that folder. It is triggered **only** via new manual `.gitea/workflows/p05-oidc-acceptance.yml`. `run.sh` protects numeric run ownership, starts no-host-port official ZITADEL Compose, provisions a real disposable client/human via official IAM_OWNER PAT and runs pinned Chromium with the original Login V2 and unmodified Account Portal. It expects real PKCE/state/nonce/callback/session positive and negative results. `cleanup.sh` runs even on failure and must prove removal of **only** owned test containers, volumes, database/bootstrap credentials. **CI execution pending, not local tests or production proof.**
+14
View File
@@ -0,0 +1,14 @@
# tests/ci/oidc_e2e/ — exact file manifest
| File | Responsibility |
| --- | --- |
| [README.md](README.md) | CI-only architecture, prerequisites, safety and flow boundaries |
| [MINIFEST.md](MINIFEST.md) | Exact registered files in this new first-party directory |
| [compose.owner.override.yaml](compose.owner.override.yaml) | Disposable first-instance IAM_OWNER PAT bootstrap only; no developer/prod change |
| [run.sh](run.sh) | Run-ID Docker ownership preflight, portless stack startup, secret volume/provisioning, private browser launch |
| [provision.py](provision.py) | Official ZITADEL project/OIDC client/human creation via ephemeral owner PAT; no secret output |
| [browser.sh](browser.sh) | Pinned Playwright image CI-only npm installs, isolated Account app dependencies and browser harness |
| [browser.cjs](browser.cjs) | Real Chromium OIDC PKCE/state/nonce/username/password/callback/session and negative contracts |
| [cleanup.sh](cleanup.sh) | Always-run owned-only browser/forwarder/secret/Compose teardown and leftover checks |
Every child file is tracked in Git. Never add real credentials, screenshots, session recordings or user data.
+15
View File
@@ -0,0 +1,15 @@
# P05-OIDC-01 — disposable Gitea-only real browser OIDC verification
**Not for local development, production hosts, or real identities.** The new `.gitea/workflows/p05-oidc-acceptance.yml` manual workflow is the only approved entrypoint, and it runs on a disposable Gitea Docker runner.
The environment is a temporary `zitplane-p05-{GITHUB_RUN_ID}` Compose stack containing the **unchanged** P02 PostgreSQL/ZITADEL API/official prebuilt Login V2/Traefik. `compose.owner.override.yaml` adds **only** a first-instance ephemeral `IAM_OWNER` machine PAT for official API provisioning, with a short expiration; `compose.portless.override.yaml` clears inherited host ports. A tiny run-owned TCP loopback-forwarder exists only in the proxy Docker network namespace to preserve the official P02 `localhost:8080` issuer. No host port is published.
`run.sh` strictly refuses an existing fixed network, project, volume, credentials file or marker. `provision.py` uses the official API with a read-only temporary owner PAT to create an isolated project, OIDC Web authorization-code client and a verified disposable human with a strong random password; the app/user secrets are written with mode `0600` into **a separate disposable volume**. Admin PAT never reaches the browser runner. `browser.sh` installs the **unchanged** Account Portal using its committed npm lock and pinned Playwright 1.58.2 in a short-lived Chromium image, and invokes `browser.cjs` to launch the Account Portal with `next dev` **inside the isolated CI container only**. The HTTP loopback issuer is allowed in CI development mode but **not** in production. Do not claim HTTPS production topology was tested.
`browser.cjs` performs real native browser navigation, original ZITADEL Login V2 username/password, visible OIDC authorization code + PKCE S256/state/nonce request, Auth.js callback, nonempty matching subject in `GET /api/account/me`, protected Account page, anonymous/invalid-callback 401 negative tests and local Account Portal logout. No fake IdP, injected session cookies, mocked tokens or bypasses. It must reject failures rather than silently skip assertions.
`cleanup.sh` is mandatory `always()`: removes **only** run-labeled Playwright/forwarder containers and run-labeled secret volume, then invokes the pre-existing audited `tests/ci/backend_cleanup.sh` for the marked Compose project (including bootstrap PAT/Postgres), and verifies no owned resources remain. Failure of cleanup makes the CI job fail; never run it on a production host.
**Privacy:** never log user password, owner PAT, OIDC client secret, Auth.js cookies, codes, nonce, state, request query or screenshots. Browser diagnostics contain only safe stage IDs. No credentials/recordings uploaded as CI artifacts. The actual CI run and individual pass/blocked status are recorded in `notes/P05-OIDC-01.md` and `docs/P05-OIDC-01.md`; source existence alone is not runtime acceptance.
**Phase limitations:** MFA/passkeys, production HTTPS issuer, deployment, full Admin Console human login and global SSO logout are outside this phase. Only a real successful browser callback + verified teardown is enough for its narrower user/password OIDC acceptance.
+194
View File
@@ -0,0 +1,194 @@
"use strict";
// Real Chromium -> original Login V2 -> real ZITADEL -> unmodified Auth.js.
// No mock authorization, fabricated JWT, injected session, or token exfiltration.
const assert = require("node:assert/strict");
const fs = require("node:fs");
const { spawn } = require("node:child_process");
const { chromium } = require("playwright");
const ACCOUNT = "http://localhost:3000";
const ISSUER = "http://localhost:8080";
let stage = "BROWSER_PREFLIGHT";
let server;
let browser;
function pass(marker) {
process.stdout.write(marker + "\n");
}
function fixture() {
const data = JSON.parse(fs.readFileSync("/ci/secret/oidc.json", "utf8"));
for (const key of ["authSecret", "clientId", "clientSecret", "userId", "loginName", "password"]) {
assert.equal(typeof data[key], "string", "Missing temporary fixture field");
assert.ok(data[key].length > 0, "Empty temporary fixture field");
}
assert.equal(data.issuer, ISSUER);
return data;
}
async function waitForPortal(maxMs = 180000) {
const deadline = Date.now() + maxMs;
while (Date.now() < deadline) {
if (server.exitCode !== null) throw Error("Disposable Account Portal exited early");
try {
const controller = new AbortController();
const abort = setTimeout(() => controller.abort(), 3000);
try {
const res = await fetch(ACCOUNT + "/signin", { redirect: "manual", signal: controller.signal });
if (res.status === 200 || res.status === 303 || res.status === 307) return;
} finally {
clearTimeout(abort);
}
} catch (_) {}
await new Promise(resolve => setTimeout(resolve, 1500));
}
throw Error("Disposable Account Portal was not HTTP-ready");
}
function assertAuthorization(requestUrl, expectedId) {
assert.ok(requestUrl, "No genuine OIDC authorization navigation observed");
const u = new URL(requestUrl);
assert.equal(u.origin, ISSUER);
assert.equal(u.pathname, "/oauth/v2/authorize");
assert.equal(u.searchParams.get("client_id"), expectedId);
assert.equal(u.searchParams.get("response_type"), "code");
assert.equal(u.searchParams.get("code_challenge_method"), "S256");
assert.ok((u.searchParams.get("code_challenge") || "").length >= 43);
assert.ok((u.searchParams.get("state") || "").length >= 16);
assert.ok((u.searchParams.get("nonce") || "").length >= 16);
assert.equal(u.searchParams.get("redirect_uri"), ACCOUNT + "/api/auth/callback/zitadel");
}
async function verifyAnonymous(context) {
const reply = await context.request.get(ACCOUNT + "/api/account/me");
assert.equal(reply.status(), 401, "Anonymous Account API must be denied");
const cache = reply.headers()["cache-control"] || "";
assert.ok(cache.includes("no-store"), "Anonymous identity response may be cached");
const page = await context.newPage();
await page.goto(ACCOUNT + "/account", { waitUntil: "domcontentloaded", timeout: 90000 });
await page.waitForURL(url => url.pathname === "/signin", { timeout: 60000 });
await page.close();
pass("ZITPLANE_OIDC_ANONYMOUS_API_AND_PAGE_REJECTED_PASS");
}
async function verifyInvalidCallback(context) {
const page = await context.newPage();
await page.goto(ACCOUNT + "/api/auth/callback/zitadel?code=invalid&state=invalid", {
waitUntil: "domcontentloaded",
timeout: 60000
}).catch(() => {});
const reply = await context.request.get(ACCOUNT + "/api/account/me");
assert.equal(reply.status(), 401, "Tampered callback established an identity");
await page.close();
pass("ZITPLANE_OIDC_INVALID_CALLBACK_FAIL_CLOSED_PASS");
}
async function main() {
const data = fixture();
stage = "ACCOUNT_SERVER_START";
// Only this isolated CI namespace uses HTTP loopback; production Auth.js
// configuration (including its HTTPS requirement) stays untouched.
const outFd = fs.openSync("/tmp/oidc-portal-server.log", "w", 0o600);
server = spawn("npm", ["run", "dev", "--", "--hostname", "127.0.0.1", "--port", "3000"], {
cwd: "/tmp/ui",
detached: true,
stdio: ["ignore", outFd, outFd],
env: {
...process.env,
NODE_ENV: "development",
AUTH_URL: ACCOUNT,
AUTH_TRUST_HOST: "true",
AUTH_SECRET: data.authSecret,
ZITADEL_ISSUER: ISSUER,
ZITADEL_CLIENT_ID: data.clientId,
ZITADEL_CLIENT_SECRET: data.clientSecret,
NO_PROXY: "localhost,127.0.0.1"
}
});
fs.closeSync(outFd);
await waitForPortal();
pass("ZITPLANE_OIDC_DISPOSABLE_ACCOUNT_HTTP_READY_PASS");
stage = "PLAYWRIGHT_CHROMIUM_START";
browser = await chromium.launch({ headless: true, args: ["--no-sandbox"] });
const anonymous = await browser.newContext();
const signed = await browser.newContext();
anonymous.setDefaultTimeout(70000);
signed.setDefaultTimeout(70000);
stage = "ANONYMOUS_NEGATIVE";
await verifyAnonymous(anonymous);
stage = "INVALID_CALLBACK_NEGATIVE";
await verifyInvalidCallback(anonymous);
stage = "REAL_OIDC_AUTH_REDIRECT";
const page = await signed.newPage();
let authorizeUrl = null;
page.on("request", request => {
try {
const url = new URL(request.url());
if (url.origin === ISSUER && url.pathname === "/oauth/v2/authorize") {
// Captured in memory ONLY. Never print code challenge, state or nonce.
authorizeUrl = request.url();
}
} catch (_) {}
});
await page.goto(ACCOUNT + "/signin", { waitUntil: "domcontentloaded", timeout: 90000 });
await page.getByRole("button", { name: "Continue with ZITADEL" }).click();
await page.getByTestId("username-text-input").waitFor({ state: "visible", timeout: 110000 });
assertAuthorization(authorizeUrl, data.clientId);
pass("ZITPLANE_OIDC_REAL_AUTHORIZE_PKCE_STATE_NONCE_PASS");
stage = "ORIGINAL_LOGIN_USERNAME";
await page.getByTestId("username-text-input").fill(data.loginName);
await page.getByTestId("submit-button").click();
stage = "ORIGINAL_LOGIN_PASSWORD";
await page.getByTestId("password-text-input").waitFor({ state: "visible", timeout: 80000 });
await page.getByTestId("password-text-input").fill(data.password);
await page.getByTestId("submit-button").click();
stage = "OIDC_CODE_CALLBACK";
await page.waitForURL(url => url.origin === ACCOUNT && url.pathname === "/account", {
timeout: 105000
});
pass("ZITPLANE_OIDC_REAL_PASSWORD_AND_CALLBACK_PASS");
stage = "AUTHENTICATED_SESSION_IDENTITY";
const response = await signed.request.get(ACCOUNT + "/api/account/me");
assert.equal(response.status(), 200, "Authenticated API did not return HTTP 200");
assert.ok((response.headers()["cache-control"] || "").includes("no-store"));
const identity = await response.json();
assert.equal(identity?.user?.id, data.userId, "Authenticated subject mismatch");
const cookies = await signed.cookies(ACCOUNT);
assert.ok(cookies.some(c => c.name.includes("session-token") && c.httpOnly), "No HttpOnly Auth.js session cookie");
await page.goto(ACCOUNT + "/account/security", { waitUntil: "domcontentloaded" });
assert.equal(new URL(page.url()).pathname, "/account/security", "Protected Account page denied valid session");
pass("ZITPLANE_OIDC_REAL_SESSION_PROTECTED_PAGE_AND_API_PASS");
stage = "LOCAL_SESSION_LOGOUT";
await page.getByRole("button", { name: "Sign out of portal" }).click();
await page.waitForURL(url => url.pathname === "/signin", { timeout: 90000 });
const afterLogout = await signed.request.get(ACCOUNT + "/api/account/me");
assert.equal(afterLogout.status(), 401, "Local sign out left Account API authenticated");
pass("ZITPLANE_OIDC_PORTAL_LOGOUT_SESSION_REVOKED_PASS");
await anonymous.close();
await signed.close();
pass("ZITPLANE_OIDC_REAL_BROWSER_COMPLETE_PASS");
}
(async () => {
try {
await main();
} catch (_) {
// Never log browser URL/query, cookies, API bodies, passwords or client key.
process.stderr.write("ZITPLANE_OIDC_BROWSER_BLOCKED_AT=" + stage + "\n");
process.exitCode = 1;
} finally {
if (browser) await browser.close().catch(() => {});
if (server?.pid) {
try { process.kill(-server.pid, "SIGTERM"); } catch (_) {}
}
}
})();
+22
View File
@@ -0,0 +1,22 @@
#!/usr/bin/env bash
# Ephemeral CI-only Playwright image; NEVER use on the developer Windows PC.
set -euo pipefail
test -r /ci/secret/oidc.json || { echo OIDC_CI_SECRET_FIXTURE_MISSING >&2; exit 1; }
test -d /tmp/ui || { echo OIDC_CI_SOURCE_MISSING >&2; exit 1; }
# Account Portal is installed in a disposable browser container only. The
# previously verified production build/unit suites are NOT repeated here.
if ! (cd /tmp/ui && npm ci --no-audit --no-fund >/tmp/oidc-account-npm.log 2>&1); then
echo ZITPLANE_OIDC_ACCOUNT_CI_DEPENDENCIES_BLOCKED >&2
exit 1
fi
echo ZITPLANE_OIDC_DISPOSABLE_ACCOUNT_DEPENDENCIES_READY_PASS
# Match the pinned Chromium image, never install arbitrary latest browser code.
if ! npm install --prefix /tmp/oidc-playwright --no-save --ignore-scripts --no-audit --no-fund playwright@1.58.2 >/tmp/oidc-browser-npm.log 2>&1; then
echo ZITPLANE_OIDC_PINNED_PLAYWRIGHT_INSTALL_BLOCKED >&2
exit 1
fi
export NODE_PATH=/tmp/oidc-playwright/node_modules
# Issuer and Account are private IPv4 loopback sockets in the proxy namespace.
export NODE_OPTIONS=--dns-result-order=ipv4first
exec node /tmp/oidc_e2e/browser.cjs
+85
View File
@@ -0,0 +1,85 @@
#!/bin/sh
# Run only as the always() step for the matching Gitea run's disposable job.
set -eu
: "${GITHUB_RUN_ID:?Gitea numeric run ID required for safe cleanup}"
case "$GITHUB_RUN_ID" in *[!0-9]*|'') echo OIDC_CI_CLEANUP_INVALID_RUN_ID >&2; exit 1;; esac
project="zitplane-p05-$GITHUB_RUN_ID"
browser="zitplane-oidc-$GITHUB_RUN_ID-browser"
forwarder="zitplane-oidc-$GITHUB_RUN_ID-loopback"
secret_volume="zitplane-oidc-$GITHUB_RUN_ID-secrets"
owner_marker=".p05-oidc-owned"
rc=0
if [ -f "$owner_marker" ] && [ ! -f .p05-ci-owned ]; then
# Pre-Compose preparation failed; this run claimed a clean checkout before
# generating the disposable .env. No Docker resources were created yet.
rm -f .env "$owner_marker"
echo ZITPLANE_OIDC_PRECOMPOSE_CREDENTIAL_CLEANUP_PASS
exit 0
fi
if [ ! -f "$owner_marker" ] && [ ! -f .p05-ci-owned ]; then
# Preflight failed before claiming ownership; never touch Docker resources.
if [ -e .env ]; then
echo 'OIDC_CI_UNOWNED_ENV_PRESENT: cleanup refused' >&2
exit 1
fi
echo ZITPLANE_OIDC_CLEANUP_NOT_REQUIRED
exit 0
fi
# Stop only exact run-labeled, CI-created sibling containers, before Compose
# teardown, otherwise they could keep the fixed private network namespace alive.
for name in "$browser" "$forwarder"; do
if docker container inspect "$name" >/dev/null 2>&1; then
label="$(docker inspect -f '{{ index .Config.Labels "zitplane.oidc.run" }}' "$name" 2>/dev/null || true)"
if [ "$label" != "$GITHUB_RUN_ID" ]; then
echo 'OIDC_CI_UNOWNED_CONTAINER_BLOCKED' >&2
rc=1
continue
fi
if ! docker rm -f "$name" >/dev/null; then
echo 'OIDC_CI_BROWSER_OR_FORWARDER_CLEANUP_FAILED' >&2
rc=1
fi
fi
done
if docker volume inspect "$secret_volume" >/dev/null 2>&1; then
label="$(docker volume inspect -f '{{ index .Labels "zitplane.oidc.run" }}' "$secret_volume" 2>/dev/null || true)"
if [ "$label" != "$GITHUB_RUN_ID" ]; then
echo 'OIDC_CI_UNOWNED_SECRET_VOLUME_BLOCKED' >&2
rc=1
elif ! docker volume rm "$secret_volume" >/dev/null; then
echo 'OIDC_CI_DISPOSABLE_SECRETS_NOT_DESTROYED' >&2
rc=1
fi
fi
# Remove only the run-owned backend project using existing audited cleanup.
if [ -f .p05-ci-owned ]; then
if ! sh tests/ci/backend_cleanup.sh; then
echo OIDC_CI_BACKEND_CLEANUP_NOT_VERIFIED >&2
rc=1
fi
fi
for name in "$browser" "$forwarder"; do
if docker container inspect "$name" >/dev/null 2>&1; then
echo OIDC_CI_CONTAINER_LEFTOVER >&2
rc=1
fi
done
if docker volume inspect "$secret_volume" >/dev/null 2>&1; then
echo OIDC_CI_SECRET_VOLUME_LEFTOVER >&2
rc=1
fi
if [ -n "$(docker ps -a -q --filter "label=com.docker.compose.project=$project")" ] ||
[ -n "$(docker volume ls -q --filter "label=com.docker.compose.project=$project")" ] ||
docker network inspect zitplane-backend-dev-internal >/dev/null 2>&1; then
echo OIDC_CI_DISPOSABLE_BACKEND_RESOURCES_LEFTOVER >&2
rc=1
fi
if [ "$rc" -ne 0 ]; then
echo ZITPLANE_OIDC_CLEANUP_FAILED_MANUAL_REVIEW >&2
exit 1
fi
rm -f "$owner_marker"
echo ZITPLANE_OIDC_ALL_RESOURCES_CLEANED_PASS
@@ -0,0 +1,8 @@
# P05-OIDC-01 CI-only bootstrap. Never change P02 developer or production Compose.
services:
zitadel-api:
environment:
ZITADEL_FIRSTINSTANCE_PATPATH: /zitadel/bootstrap/oidc-ci-owner.pat
ZITADEL_FIRSTINSTANCE_ORG_MACHINE_MACHINE_USERNAME: oidc-ci-owner
ZITADEL_FIRSTINSTANCE_ORG_MACHINE_MACHINE_NAME: Disposable_OIDC_CI_IAM_OWNER
ZITADEL_FIRSTINSTANCE_ORG_MACHINE_PAT_EXPIRATIONDATE: ${OIDC_CI_PAT_EXPIRATION:?Missing ephemeral owner PAT expiration}
+178
View File
@@ -0,0 +1,178 @@
"""Official ZITADEL API provisioning for ONE disposable, isolated Gitea run.
Read-only IAM_OWNER PAT from the ephemeral ZITADEL bootstrap volume.
Only output state is a 0600 JSON fixture on a distinct CI-owned Docker volume.
NEVER log PAT, client secrets, passwords, tokens, API JSON/error bodies.
"""
from __future__ import annotations
import json
import os
from pathlib import Path
import secrets
import sys
import time
from urllib.error import HTTPError, URLError
from urllib.request import HTTPRedirectHandler, ProxyHandler, Request, build_opener
OWNER_PAT = Path("/zitadel/bootstrap/oidc-ci-owner.pat")
FIXTURE = Path("/ci/secret/oidc.json")
ISSUER = "http://localhost:8080"
ORIGIN = "http://127.0.0.1:8080"
TIMEOUT = 20
CLIENT_ID_KEYS = ("clientId",)
OPENER = build_opener(ProxyHandler({}))
class DenyRedirect(HTTPRedirectHandler):
def redirect_request(self, req, fp, code, msg, headers, newurl):
raise RuntimeError("Unexpected redirect while provisioning local ZITADEL")
OPENER.add_handler(DenyRedirect())
def request(method: str, path: str, token: str | None = None, payload: dict | None = None) -> dict:
if not path.startswith("/") or path.startswith("//") or "://" in path or "?" in path:
raise RuntimeError("Unsafe provisioning endpoint")
body = None if payload is None else json.dumps(payload, separators=(",", ":")).encode()
headers = {"Host": "localhost:8080", "Accept": "application/json"}
if body is not None:
headers["Content-Type"] = "application/json"
if token:
headers["Authorization"] = "Bearer " + token
try:
with OPENER.open(Request(ORIGIN + path, data=body, headers=headers, method=method), timeout=TIMEOUT) as reply:
if reply.status != 200:
raise RuntimeError(f"Provisioning endpoint returned HTTP {reply.status}")
data = reply.read(1_000_001)
if len(data) > 1_000_000:
raise RuntimeError("Oversized provisioning API response")
except HTTPError as exc:
# No error response payload (may include secrets, login names or details).
raise RuntimeError(f"Official ZITADEL API {method} {path} returned HTTP {exc.code}") from None
except URLError as exc:
raise RuntimeError(f"ZITADEL API unavailable for {method} {path}") from None
if not data:
return {}
result = json.loads(data)
if not isinstance(result, dict):
raise RuntimeError("Invalid API response shape")
return result
def wait_until_ready() -> None:
deadline = time.monotonic() + 70
while time.monotonic() < deadline:
try:
request("GET", "/debug/ready")
return
except RuntimeError:
time.sleep(2)
raise RuntimeError("Disposable localhost issuer port forwarding was not ready")
def required_string(data: dict, name: str) -> str:
value = data.get(name)
if not isinstance(value, str) or not value or len(value) > 4096:
raise RuntimeError(f"ZITADEL response missing required {name}")
return value
def main() -> None:
run = os.environ.get("OIDC_CI_RUN_ID", "")
if not run.isdecimal() or len(run) > 18:
raise RuntimeError("Invalid disposable Gitea run ID")
if not FIXTURE.parent.is_dir() or FIXTURE.exists():
raise RuntimeError("Secret fixture volume missing or already used")
wait_until_ready()
print("ZITPLANE_OIDC_LOCAL_ORIGIN_READY_PASS", flush=True)
discovery = request("GET", "/.well-known/openid-configuration")
if discovery.get("issuer") != ISSUER:
raise RuntimeError("Disposable OIDC issuer mismatch")
for field in ("authorization_endpoint", "token_endpoint", "jwks_uri"):
if not isinstance(discovery.get(field), str) or not discovery[field].startswith(ISSUER + "/"):
raise RuntimeError(f"Invalid discovery {field} origin")
print("ZITPLANE_OIDC_ISSUER_DISCOVERY_PASS", flush=True)
if not OWNER_PAT.is_file():
raise RuntimeError("Disposable first-instance IAM_OWNER PAT was not issued")
pat = OWNER_PAT.read_text(encoding="utf-8").strip()
if len(pat) < 20:
raise RuntimeError("Invalid disposable IAM_OWNER PAT length")
project = request(
"POST", "/management/v1/projects", pat,
{"name": f"zitplane-oidc-ci-{run}"},
)
project_id = required_string(project, "id")
print("ZITPLANE_OIDC_PROJECT_CREATED_PASS", flush=True)
app = request(
"POST", f"/management/v1/projects/{project_id}/apps/oidc", pat,
{
"name": "ZitPlane_Disposable_Account_OIDC",
"redirectUris": ["http://localhost:3000/api/auth/callback/zitadel"],
"postLogoutRedirectUris": ["http://localhost:3000"],
"responseTypes": ["OIDC_RESPONSE_TYPE_CODE"],
"grantTypes": ["OIDC_GRANT_TYPE_AUTHORIZATION_CODE"],
"appType": "OIDC_APP_TYPE_WEB",
"authMethodType": "OIDC_AUTH_METHOD_TYPE_BASIC",
"version": "OIDC_VERSION_1_0",
"devMode": True,
},
)
client_id = required_string(app, "clientId")
client_secret = required_string(app, "clientSecret")
required_string(app, "appId")
print("ZITPLANE_OIDC_REAL_CLIENT_CREATED_PASS", flush=True)
# Invalid TLD and verified email ensure no delivery to any real account.
login_name = f"oidc-ci-{run}@example.invalid"
password = "Zp!7" + secrets.token_urlsafe(38)
human = request(
"POST", "/v2/users/human", pat,
{
"username": login_name,
"profile": {
"givenName": "Disposable",
"familyName": "Acceptance",
"preferredLanguage": "en",
},
"email": {"email": login_name, "isVerified": True},
"password": {"password": password, "changeRequired": False},
},
)
user_id = required_string(human, "userId")
print("ZITPLANE_OIDC_REAL_TEST_HUMAN_CREATED_PASS", flush=True)
# Write secrets only inside an explicit CI-created, non-reused Docker volume;
# browser has this volume read-only, never the owner PAT. No stdout JSON.
fixture = {
"issuer": ISSUER,
"clientId": client_id,
"clientSecret": client_secret,
"authSecret": secrets.token_urlsafe(48),
"userId": user_id,
"loginName": login_name,
"password": password,
}
flags = os.O_WRONLY | os.O_CREAT | os.O_EXCL
fd = os.open(FIXTURE, flags, 0o600)
try:
with os.fdopen(fd, "w", encoding="utf-8") as handle:
json.dump(fixture, handle)
handle.write("\n")
except BaseException:
FIXTURE.unlink(missing_ok=True)
raise
print("ZITPLANE_OIDC_TEST_CREDENTIALS_ISOLATED_PASS", flush=True)
if __name__ == "__main__":
try:
main()
except Exception as exc:
# Only our intentionally redacted statuses, not raw traceback/request.
print(f"ZITPLANE_OIDC_PROVISION_BLOCKED: {str(exc)[:210]}", file=sys.stderr)
sys.exit(1)
+118
View File
@@ -0,0 +1,118 @@
#!/bin/sh
# One-shot isolated Gitea runner ONLY. No public host port; no real user data.
set -eu
: "${GITHUB_RUN_ID:?Gitea run ID required}"
case "$GITHUB_RUN_ID" in *[!0-9]*|'') echo 'OIDC_CI_INVALID_RUN_ID' >&2; exit 1;; esac
project="zitplane-p05-$GITHUB_RUN_ID"
network="zitplane-backend-dev-internal"
secret_volume="zitplane-oidc-$GITHUB_RUN_ID-secrets"
browser="zitplane-oidc-$GITHUB_RUN_ID-browser"
forwarder="zitplane-oidc-$GITHUB_RUN_ID-loopback"
marker=".p05-oidc-owned"
dc() {
docker compose --env-file .env -p "$project" \
-f deployment/docker/compose.backend.dev.yaml \
-f tests/ci/compose.portless.override.yaml \
-f tests/ci/oidc_e2e/compose.owner.override.yaml "$@"
}
docker --version
docker compose version
docker info --format '{{.Driver}}' >/dev/null
echo ZITPLANE_OIDC_DOCKER_PREFLIGHT_PASS
# Refuse to assume ownership of any preexisting name, fixed shared network,
# credential or prior project; cleanup must not delete unowned resources.
if [ -e .env ] || [ -e "$marker" ] || [ -e .p05-ci-owned ] ||
docker network inspect "$network" >/dev/null 2>&1 ||
docker volume inspect "$secret_volume" >/dev/null 2>&1 ||
docker container inspect "$browser" >/dev/null 2>&1 ||
docker container inspect "$forwarder" >/dev/null 2>&1 ||
[ -n "$(docker ps -a -q --filter "label=com.docker.compose.project=$project")" ] ||
[ -n "$(docker volume ls -q --filter "label=com.docker.compose.project=$project")" ]; then
echo 'OIDC_CI_OWNERSHIP_PREFLIGHT_BLOCKED: existing state' >&2
exit 1
fi
for v in "${project}_postgres-data" "${project}_zitadel-bootstrap"; do
if docker volume inspect "$v" >/dev/null 2>&1; then
echo OIDC_CI_PREEXISTING_VOLUME_BLOCKED >&2
exit 1
fi
done
# Mark only CI ownership after verifying a fresh checkout and NO Docker
# resources. If env/config generation fails, cleanup deletes only our env.
touch "$marker"
python3 core/backend/zitadel/dev.py init
python3 - <<'PY'
from datetime import datetime, timedelta, timezone
from pathlib import Path
p = Path('.env')
if not p.is_file():
raise SystemExit('Disposable env missing')
expiration = (datetime.now(timezone.utc) + timedelta(hours=2)).strftime('%Y-%m-%dT%H:%M:%SZ')
with p.open('a', encoding='utf-8') as out:
out.write('OIDC_CI_PAT_EXPIRATION=' + expiration + '\n')
p.chmod(0o600)
PY
dc config --quiet
dc config --format json |
python3 -c 'import json,sys; v=json.load(sys.stdin); assert set(v["services"])=={"postgres","zitadel-api","zitadel-login","proxy"}; assert not v["services"]["proxy"].get("ports"), "A public host port was configured"; assert v["services"]["zitadel-api"]["environment"]["ZITADEL_FIRSTINSTANCE_PATPATH"]=="/zitadel/bootstrap/oidc-ci-owner.pat"; print("ZITPLANE_OIDC_NO_PUBLISHED_PORT_AND_OWNER_CONFIG_PASS")'
# Mark ownership only AFTER all preflight/config checks; always() cleanup knows it.
touch .p05-ci-owned
dc up -d --wait
for name in postgres zitadel-api zitadel-login proxy; do
cid="$(dc ps -q "$name")"
[ -n "$cid" ] && [ "$(docker inspect -f '{{.State.Running}}' "$cid")" = true ] || {
echo "OIDC_CI_SERVICE_NOT_RUNNING=$name" >&2; exit 1;
}
if [ "$name" != proxy ]; then
[ "$(docker inspect -f '{{.State.Health.Status}}' "$cid")" = healthy ] || {
echo "OIDC_CI_SERVICE_NOT_HEALTHY=$name" >&2; exit 1;
}
fi
done
echo ZITPLANE_OIDC_FOUR_SERVICES_READY_PASS
proxy_id="$(dc ps -q proxy)"
test -n "$proxy_id"
bootstrap_volume="${project}_zitadel-bootstrap"
# Everything below shares the private proxy network namespace (not the host).
# Loopback-8080 preserves ZITADEL's P02 external issuer and Host routing.
docker run -d --name "$forwarder" \
--label "zitplane.oidc.run=$GITHUB_RUN_ID" \
--network "container:$proxy_id" alpine:3.21 \
sh -ec 'apk add --no-cache socat >/dev/null 2>&1; exec socat TCP-LISTEN:8080,bind=127.0.0.1,reuseaddr,fork TCP:127.0.0.1:80' >/dev/null
docker volume create --name "$secret_volume" \
--label "zitplane.oidc.run=$GITHUB_RUN_ID" >/dev/null
# Provisioning container only: holds ephemeral IAM_OWNER PAT READ-ONLY and
# writes a CI-only client/user credential file to a separate short-lived volume.
docker run --rm -i --network "container:$proxy_id" \
-e "OIDC_CI_RUN_ID=$GITHUB_RUN_ID" \
--volume "$bootstrap_volume:/zitadel/bootstrap:ro" \
--volume "$secret_volume:/ci/secret" \
python:3.12-alpine python - < tests/ci/oidc_e2e/provision.py
echo ZITPLANE_OIDC_DISPOSABLE_PROVISIONING_PASS
# Copy only nonsecret repository app/source and test harness files into a
# throwaway browser container. Docker cp does NOT depend on runner host paths.
docker create --name "$browser" \
--label "zitplane.oidc.run=$GITHUB_RUN_ID" \
--network "container:$proxy_id" \
--volume "$secret_volume:/ci/secret:ro" \
mcr.microsoft.com/playwright:v1.58.2-noble \
bash /tmp/oidc_e2e/browser.sh >/dev/null
docker cp users/ui "$browser:/tmp/ui"
docker cp tests/ci/oidc_e2e "$browser:/tmp/oidc_e2e"
# Logs only safe named PASS/BLOCKED markers, never passwords/tokens/query URLs.
docker start -a "$browser"
exit_code="$(docker inspect -f '{{.State.ExitCode}}' "$browser")"
if [ "$exit_code" != 0 ]; then
echo 'ZITPLANE_OIDC_BROWSER_ACCEPTANCE_BLOCKED' >&2
exit 1
fi
echo ZITPLANE_OIDC_REAL_BROWSER_ACCEPTANCE_PASS