84 lines
9.5 KiB
Markdown
84 lines
9.5 KiB
Markdown
# P05-CI-02 — Targeted Remediation & CI Acceptance
|
||
|
||
**Date:** 2026-11-22
|
||
**Baseline:** `42adaba0044ee5cb86e6e6bcfd4e00e5fe96ad00` (local `main` = Gitea `main`)
|
||
**State:** IMPLEMENTATION COMMITTED AND RUN #83 COMPLETED (3 PASS / 1 FAIL); post-run CI-only port fix pending acceptance
|
||
**Previous CI evidence:** Gitea Run [#81](https://dev.ivib.cc/vibtools/ZitPlane/actions/runs/81), tested `42b79362c13b9dbb07f85a58ad278742d91b1f5b`, overall FAILURE.
|
||
|
||
## Exact approved write scope
|
||
|
||
- `users/ui/src/auth.ts` — B01 narrow session callback typing only.
|
||
- `users/ui/src/types/next-auth.d.ts` — only if needed; avoid otherwise.
|
||
- `.gitea/workflows/p05-ci.yml` — CI isolation/verification/triage/cleanup.
|
||
- `tests/ci/**` — focused CI-only OIDC negative/discovery/production and audit scripts, plus README/MINIFEST.
|
||
- `notes/**`, `project/**`, relevant `docs/**`, associated `.gitea/**/README.md` and `MINIFEST.md`; root `README.md`, `MINIFEST.md` only as necessary.
|
||
|
||
READ ONLY: `core/backend/zitadel/dev.py`, `deployment/docker/compose.backend.dev.yaml`, all `auth/ui/v2/**` original source and lockfile, `users/ui/package.json` / `package-lock.json`, portal UI pages/feature logic and all other files. Preserve unrelated untracked `AI_INSTRUCTIONS.md`.
|
||
|
||
**No local builds, local tests, dev servers, Docker, real credentials/users, production deployments, tags or releases.** Source-level preflight/diff is permitted. Only ONE new manually dispatched Gitea CI acceptance cycle; no repeated reruns to chase green checks.
|
||
|
||
## Root-cause evidence (before edits)
|
||
|
||
- **B01 / TS2345**: Run #81 job 165, `users/ui/src/auth.ts(14,61)` generic NextAuth config callback rejected; downstream `callbacks.session` at lines 50–65 returns inferred `user.id: {}` instead of `string`. The current ternary uses `valid ? token.zitadelSubject! : ""`; the inferred `token.zitadelSubject!` type is not a reliable string despite the boolean `valid` expression. Correct by independently narrowing the JWT subject using `typeof ... === "string"` before constructing the session, and preserve expiry fail-closed. No `as any`, disabling strict mode or weakening route guards.
|
||
- **B02 / Docker checkout**: Run #81 job 168 failed in `node:22-alpine` `actions/checkout@v4`: Git missing, archive fallback `Not found`. Current Gitea `main` already has pre-checkout `apk add --no-cache git` at workflow lines 106–110, not yet executed by CI. Current Compose uses fixed local-only network/port; refuse collisions and cleanup ONLY owned disposable project volumes. Verify Postgres volume survives service restart, then readiness, OIDC issuer/discovery/JWKS on disposable network. No edits to Compose or backend helper.
|
||
- **B03 / Moderates**: Run #81 job 167 passed HIGH/CRITICAL threshold, but `pnpm audit --prod` reported **18 MODERATE findings**, without individual package/advisory IDs. Account `npm audit` also found **1 MODERATE Next.js issue** with multiple GHSA IDs. Generate structured advisory inventory in CI using registry data, record package/affected range/available fix; no blind dependency upgrades.
|
||
- **B04 / OIDC**: `tests/ci/oidc_discovery.py` currently checks ready/discovery/JWKS only, not authenticated user callback, session, MFA or admin login. Add robust negative/issuer/JWKS tests, while keeping real login E2E explicitly BLOCKED until separately approved disposable user/client provisioning.
|
||
|
||
## Implementation plan
|
||
|
||
1. Narrow `users/ui/src/auth.ts` TypeScript narrowing patch, no auth flow change. Add CI negative contract probes and source contract checks.
|
||
2. Strengthen Gitea job: auth typecheck/build, Login frozen build/unit regression, JSON advisory triage alongside existing HIGH+ gates, disposable Docker preflight plus Postgres persistence/ready/discovery/JWKS verification and always cleanup.
|
||
3. Ensure job isolation: no shared Docker network/port takeover, no existing project teardown; fail-closed if daemon/capability/isolation unavailable. No real secrets. One CI run, read job logs and exact conclusions.
|
||
4. Update `project/`, `docs/`, `notes/`, manifests. Exact scope/security diff audit, Git commit and authorized Gitea `main` push, verify final remote/local SHA. Phase acceptance remains BLOCKED if required gates fail; never claim unexecuted E2E PASS.
|
||
|
||
## Verification ledger
|
||
|
||
**NOT STARTED.** Record run ID/SHA, exact terminal job statuses, advisory IDs and severity, Docker persistence/cleanup, remaining blockers and final Git SHA only after real evidence is received.
|
||
|
||
|
||
## Actual Gitea CI acceptance cycle — Run #83
|
||
|
||
**Event:** `workflow_dispatch` on `main`
|
||
**Tested source SHA:** `c27fe3d3234d16375b962b88014cdd8733ab2fb4`
|
||
**Run:** https://dev.ivib.cc/vibtools/ZitPlane/actions/runs/83
|
||
**Terminal:** 2026-11-22 13:28:49 UTC, **overall FAILURE**, 3 jobs PASS / 1 FAIL.
|
||
**No second run was started.**
|
||
|
||
| Job | Job ID | Conclusion | Evidence |
|
||
| --- | ---: | --- | --- |
|
||
| Account Portal | 171 | **PASS** | Source/lock guards, npm ci, `tsc --noEmit`, Next production build, anonymous GET `/api/account/me` 401/no-store, protected route redirect |
|
||
| Login V2 | 172 | **PASS** | Pinned pnpm frozen install, Nx proto/client/Login V2 standalone build; Vitest **84/84 files, 1219/1219 tests PASS** |
|
||
| Dependency security | 173 | **PASS at HIGH/CRITICAL only** | Account npm audit 1 Moderate vulnerable `next`; Login pnpm 18 Moderate advisory records; neither has HIGH/CRITICAL at the reported audit date |
|
||
| Disposable Docker | 174 | **FAIL** | Git/checkout, Docker preflight, 3 Python P02 static tests, official image pulls, PostgreSQL, ZITADEL API and prebuilt Login V2 **HEALTHY**. Traefik proxy failed: `Bind for 0.0.0.0:8080 failed: port is already allocated`. Postgres marker write/restart/persistence and OIDC discovery/JWKS **NOT REACHED**. Always-cleanup **PASS**: job-owned containers, network, volumes removed |
|
||
|
||
**B01 disposition:** FIXED and CI typecheck/build **verified PASS**. No TypeScript config relaxation, unsafe cast, PKCE/nonce/state change, session expiration bypass or UI change.
|
||
|
||
**B02 disposition:** Git checkout fixed and verified; PostgreSQL, ZITADEL API, Login V2 reached healthy state. Port 8080 was occupied on shared Docker runner; scope did not permit editing P02 Compose. **After the terminal run**, added a narrow CI-only `tests/ci/compose.portless.override.yaml` with `proxy.ports: !reset []` and applied it consistently to all 9 workflow Compose commands; enforced effective config `proxy.ports` empty before startup. Official Docker Compose documented reset behavior: https://docs.docker.com/reference/compose-file/merge/#reset-value. **This source fix is NOT VERIFIED by CI**, and the remaining persistence/discovery gates are BLOCKED until a separately approved run. P02 developer Compose remains untouched.
|
||
|
||
### B03 — exact live registry advisory triage (2026-11-22)
|
||
|
||
**Account Portal npm audit:** 1 Moderate affected `next` package, pinned `16.4.3`, affected `16.0.0–16.4.4`, npm advises `16.4.6`:
|
||
`GHSA-mfr8-8qww-v76h`, `GHSA-vc7v-qv4w-wrv8`, `GHSA-7qx7-33qx-rqx2`, `GHSA-f3mh-rxg3-f5g2`, `GHSA-pc58-hwjq-p385`, `GHSA-rhh4-g77r-r9qj`, `GHSA-vvgp-ww4w-46vf`. Seven advisory IDs are grouped into **one affected npm package record**, not seven separate npm packages.
|
||
|
||
**Login V2 pnpm audit: 18 Moderate advisory records**, grouped as follows:
|
||
|
||
| Count | Package(s) | Advisory | Vulnerable range → patched version |
|
||
| ---: | --- | --- | --- |
|
||
| 8 | `@opentelemetry/instrumentation-pg`, `-mysql2`, `-knex`, `-mysql`, `-mongoose`, `-oracledb`, `-tedious`, `-cassandra-driver` | `GHSA-qqmp-wf37-98f9` | pg <0.73.0 → ≥0.73.0; mysql2/mysql/mongoose <0.67.0 → ≥0.67.0; knex <0.65.0 → ≥0.65.0; oracledb <0.46.0 → ≥0.46.0; tedious <0.40.0 → ≥0.40.0; cassandra-driver <0.66.0 → ≥0.66.0 |
|
||
| 1 | `@opentelemetry/instrumentation-http` | `GHSA-3v2p-hm54-8qcq` | >0.204.0 <0.222.0 → ≥0.222.0 |
|
||
| 1 | `glob` | `GHSA-3g3m-2fjr-6pw4` | ≥9.0.0 ≤14.0.1 → ≥14.0.2 |
|
||
| 1 | `minimatch` | `GHSA-g3hv-75wg-m249` | ≥7.0.0 <11.0.1 → ≥11.0.1 |
|
||
| 7 | `next` | Seven `GHSA` IDs listed above | Next.js 16.x ≤16.4.4 (ranges differ) → pnpm reports ≥16.4.5 |
|
||
|
||
**Disposition:** all 19 Moderate audit records (18 Login + 1 Account package record) remain OPEN; HIGH/CRITICAL gate passed. Fixed-version metadata is a candidate only, not proof of compatibility or runtime exploitability. No blind npm/pnpm dependency upgrades, upstream Login fork edits or lockfile changes in P05-CI-02. A separate dependency-only security phase must evaluate reachability, runtime vs tooling transitive paths, pin consistency with official upstream, package/lock changes and CI regression.
|
||
|
||
### Phase closure, outstanding blockers
|
||
|
||
- B01 **CLOSED**, account typecheck/build/anonymous access verified.
|
||
- B02 **PARTIALLY VERIFIED** (checkout + health), but fixed portless CI overlay, restart persistence and OIDC/JWKS smoke remain **UNVERIFIED**; full backend gate FAIL.
|
||
- B03 **TRIAGE COMPLETE**, 19 Moderate records remain open pending approved dependency remediation; High/Critical gates PASS.
|
||
- B04 **PARTIALLY VERIFIED** (anonymous Account checks + synthetic negative OIDC metadata contracts in source); live Docker OIDC discovery/keys NOT RUN; authenticated client/user callback, MFA, Admin Console and federated logout **DEFERRED**.
|
||
- No live user data, production network, production host, Coolify deployment, tags, releases or local application tests/builds used. **No Gitea run rerun**. Untracked `AI_INSTRUCTIONS.md` preserved.
|
||
|
||
**Post-run commit:** contains only approved CI overlay/workflow and accurate notes/project/docs, no core/Compose/manifest/lock changes. The new commit SHA is recorded in Git history; **Run #83 tested `c27fe3d`, not the later documentation/portless patch SHA.**
|