Files
ZitPlane/notes/P05-OIDC-08-A03.md
T

80 lines
13 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# P05-OIDC-08-A03 — Safe Extra Deploy Normalization RCA & Complete Static Security Contract Gate
**Date:** 2026-11-23 Asia/Dhaka.
**User-approved baseline:** `b3b1878e03b3d189ae97ce24a87d6d87c6151811` verified against Gitea `main` before changes.
**Prior real evidence:** [Gitea Run #103](https://dev.ivib.cc/vibtools/ZitPlane/actions/runs/103), job #219, terminal FAILURE, tested source `45a2edb854acd98546e60a68482075bc5f742bd2`. `docker compose config --quiet` PASS; all five source and normalized replicas numeric zero PASS; all five normalized `deploy` objects contained additional unnamed fields; strict `DEPLOY_DISABLED` failed before all 25+4+3 negative fixtures; `always()` workflow-safety PASS, CI-task cleanup reported.
**Earlier real OIDC:** [Run #99](https://dev.ivib.cc/vibtools/ZitPlane/actions/runs/99) imported custom Login V2 disposable HTTP localhost real browser OIDC SUCCESS, independent of this static production contract.
## EXACT PRE-SOURCE SCOPE LOCK (commit this note FIRST)
**SOURCE WRITE EXACT ONE FILE:** `tests/ci/production_contract/validate.py`.
**DOCUMENTATION WRITE:** `notes/**`, relevant `project/**`, `docs/**`, required associated `README.md` / `MINIFEST.md` only (including root README if useful). No other files.
**STRICT READ ONLY:** `auth/**`, `users/**`, `core/**`, **all `deployment/**`** (including synthetic `compose.ci.yaml` and `routing-policy.json`), **all existing `.gitea/workflows/**`**, `tests/**` except exact validator and necessary related existing README/MINIFEST, all package manifests/lockfiles, runner settings, DNS/VPS/Coolify/Cloudflare/SSL, production secrets and infrastructure, unrelated files and untracked `AI_INSTRUCTIONS.md`.
**NO:** local application build/test; any `docker compose up/run/build/pull`, container service startup or registry publishing; production DNS/HTTPS/certificate lookup, real credentials/users/MFA/login, deploy, tag/release; CI rerun loop; post-dispatch source patch. Allowed CI is only current manually dispatched workflow with static Compose config normalization, stdlib Python checks and runner-managed cleanup. No changes to existing CI workflow.
## Evidence-first A03 plan and fail-closed guardrails
1. **Read-only before changes:** verified source fixture has exactly five `deploy: replicas: 0` declarations and reserved `synthetic.invalid` images; policy has proposed `https://auth.vib.tools` issuer, `https://account.vib.tools` separate Account origin; existing job #219 shows each normalized `deploy.replicas` integer 0 and **unidentified extra `deploy` field(s)**. Exact field name, type, value and semantics are **UNKNOWN** before this A03 run. Do not infer specific keys from A02 logs.
2. Modify ONLY `validate.py` to report **predefined finite allowlisted** `deploy` field names (e.g. known Docker Compose metadata keys) and only **safe shape categories** (`NULL`, `EMPTY_OBJECT`, `EMPTY_LIST`, `NONEMPTY_OBJECT`, `NONEMPTY_LIST`, `STRING`, `OTHER`); any other keys reported **UNKNOWN_KEY_PRESENT** without printing input names or values. Source must never print secrets, raw Compose JSON, command text, arbitrary key names or actual values.
3. Gate acceptance of a specifically named **semantically inert default** using source zero-replica proof, normalized exact true integer-zero replicas in all five, and a narrow per-key allowlist for empty/null metadata *only*. Some known Compose keys may be normalization output, but **must be proven by the new one-shot CI**; if unexpected/unsafe populated keys appear, FAIL and stop. No broad relaxations. All deployment-capable populated `mode`, `placement`, `resources`, `restart_policy`, `update_config`, `rollback_config`, nonempty settings, unknown deploy fields and real images remain rejected.
4. Preserve original **25** security negatives + prior **4** runtime override negatives + existing **3** replica negatives. Add independent new tests that deliberate unsafe extra deployment metadata is rejected by the exact `DEPLOY_DISABLED` rule (distinct from code failing for some unrelated reason). Preserve OIDC/issuer/callback/routes/Host/headers/internal-only network/secrets/no public ports/no Docker socket/privileges fail-closed checks. No changes to `compose.ci.yaml` or JSON policy.
5. **One focused pre-CI source/security/diff audit**; commit/push exact tested source SHA to `main`, dispatch **exactly ONE** newly approved manual `p05-production-contract-dry-run.yml`. Check static Compose config, normalized deploy shape evidence, full positive and negative assertions, always-run workflow-safety/CI runner cleanup. **If failure** do not patch source or dispatch again; record PASS/FAIL/NOT EXECUTED and propose narrowly scoped next approval.
6. Sync exact notes/project/docs, manifests/README/source inventory; perform cumulative allowed-path/secret/diff check, commit/push docs and verify remote `main` SHA. Report clearly which SHA was CI-tested and which is later documentation-only.
**Production boundaries:** This is synthetic CI-only validation; **not real HTTPS, live DNS, deployed Login/Console, secrets/backup recovery, MFA/passkey or multi-app SSO acceptance**. No production work is authorized.
## Terminal single-run evidence and A03 acceptance verdict — 2026-11-23
**Scope-first note commit:** `756f3e134affcf908c3cce800cd177d78c192c78`. **Only modified source:** `tests/ci/production_contract/validate.py`; no `deployment/**`, `auth/**`, `users/**`, `core/**`, existing workflow, package lock, runner or production edit. Exact pre-dispatch tested source SHA `7954938fcee4d11c0b27751c7cf7abdcc64cd243`. One focused source/security/diff audit PASS: the 25 original, 4 runtime, 3 replica and 8 added deploy negative fixtures are present as source definitions; **CI execution had not yet occurred when audited**.
**One and only manual CI dispatch:** [Gitea Run #104](https://dev.ivib.cc/vibtools/ZitPlane/actions/runs/104) / Job #220, `completed/failure`, checkout at immutable source `7954938fcee4d11c0b27751c7cf7abdcc64cd243`, 2026-11-23T16:12:50Z–16:13:09Z. Step #0 install toolchain **PASS**; #1 checkout **PASS**; #2 Compose config + validator **FAIL**; #3 `always()` static manual-only/no-resource-actions check **PASS**. **No rerun, no post-run code patch**.
| Gate | Actual outcome / log marker |
| --- | --- |
| `docker compose -f deployment/production-contract/compose.ci.yaml config --quiet` | **PASS** — `ZITPLANE_P08_COMPOSE_STATIC_CONFIG_PASS` |
| Pinned unchanged fixture bytes and original five zero-replica declarations | **PASS** — `ZITPLANE_P08_SOURCE_ALL_FIVE_REPLICAS_ZERO_PASS`; immutable Git blob `930c0b0fbfb518555436acd6f0b4bb3bdd421937` read-only |
| Five normalized `command: null` / `entrypoint: null` defaults | **VERIFIED** — ten allowlisted `*_COMMAND_NULL` / `*_ENTRYPOINT_NULL` markers |
| Five normalized deploy mappings and integer `replicas: 0` | **VERIFIED** — `ZITPLANE_P08_NORMALIZED_DEPLOY_*_OBJECT` and `*_REPLICAS_INT_ZERO` |
| Extra normalized deploy fields | **EXACT RCA VERIFIED:** `resources: {}` and `placement: {}` on **each of five** synthetic services; `*_KNOWN_RESOURCES_EMPTY_OBJECT` + `*_KNOWN_PLACEMENT_EMPTY_OBJECT`. No `*_UNKNOWN_KEY_PRESENT` marker in recorded result |
| Previous A02 `DEPLOY_DISABLED` acceptance blocker | **RESOLVED for at least the checked service execution path:** validator progressed past this guard and failed at the **later service-secret-ref check**. Do not claim all five service paths completed. |
| Service secret-reference normalization/policy | **FAIL** — `ZITPLANE_P08_FAIL_CLOSED_SERVICE_SECRET_REFS` |
| Exact secret grant field/list entry/source-target mismatch | **UNKNOWN**; `service_secret_refs()` checks entry shape and `target == source` when represented as dict; actual normalized grants were not printed or classified. Do **not** assume a particular mismatch or reveal paths/credential values |
| Full positive issuer/callback, Login V2/Console/API h2c, Host/forwarded, secret/private-network aggregate success markers | **NOT REACHED** (early failure; individual policy sections may have executed without aggregate success markers) |
| Original 25 synthetic invalid fixtures | **NOT EXECUTED** |
| Four nonempty runtime override fixtures | **NOT EXECUTED** |
| Three malicious replica fixtures | **NOT EXECUTED** |
| Eight dangerous extra-deploy metadata fixtures | **NOT EXECUTED** |
| Inert metadata positive synthetic fixture | **NOT EXECUTED** |
| Static manual-only/no Docker lifecycle commands configured | **PASS** `ZITPLANE_P08_MANUAL_ONLY_NO_RESOURCE_ACTIONS_CONFIGURED_PASS` (initial check + `always()`) |
| Gitea-owned temporary task resource cleanup | **PASS as job evidence:** job container deleted, two task volumes removed and task network cleanup logged; no production Docker inventory |
| Real DNS, public HTTPS/certificates, actual ZITADEL/Account auth, Console/MFA/passkeys/SSO, secrets/DB backups or production deployment | **NOT EXECUTED / OUT OF SCOPE** |
### Proven root cause vs residual defect
Unlike Run #103, this run revealed **exactly the two known additional keys** on every synthetic `deploy` object: `resources` and `placement`, each an **empty mapping**. This is consistent with inert Docker Compose normalization; the validator's exact-key/empty-shape acceptance lets execution proceed to `SERVICE_SECRET_REFS` without accepting nonempty resources, placement, restart, update, rollback, mode, endpoints, unfamiliar keys or nonzero replicas. The newly added negative fixture **definitions** cover such hostile mutation but are **not CI-tested**, since `negative_cases()` never ran.
Next blocker `SERVICE_SECRET_REFS`: strict service secret grant structure does not match normalized `docker compose config --format json`. Its **precise** normalized entry representation is not in the safe logs. The code has `service_secret_refs(service)`, accepting string entries or restricted source/target dictionary where `target == source`, then exact expected references. It is possible normalized target paths or metadata differ, but no particular one can be concluded without new evidence.
**A03 FINAL VERDICT:** **partial RCA and prior-blocker PASS**, **full synthetic contract CI acceptance FAIL/BLOCKED**. All **40** negative security fixtures (25+4+3+8) **NOT EXECUTED**. Imported Login V2 [Run #99](https://dev.ivib.cc/vibtools/ZitPlane/actions/runs/99) remains real isolated disposable OIDC acceptance only. No live production evidence.
### Remaining blockers and separately approved next phase
**P0 static-contract blocker:** exact normalized service-level secret grant shape/source-to-target semantics, unknown; still need positive/negative synthetic security acceptance. Afterward, production image provenance, master-key/PAT client-secret custody and encrypted DB recoverability, real trusted HTTPS issuer/ingress, Console/MFA/SSO remain separate non-synthetic phases.
**PROPOSED P05-OIDC-08-A04 — Normalized Service-Secret Grants RCA & Full Static Contract Acceptance (NOT YET APPROVED).**
- **Approved baseline for next phase:** use final A03 documentation-closure Gitea main SHA, verify at closure; previous tested source `7954938fcee4d11c0b27751c7cf7abdcc64cd243`, Run #104/Job #220 terminal failure.
- **Pre-source Scope Lock note FIRST:** create and commit `notes/P05-OIDC-08-A04.md` before any source changes.
- **SOURCE WRITE ONLY:** `tests/ci/production_contract/validate.py`. **DOCUMENTATION WRITE:** `notes/**`, relevant `project/**`, `docs/**`, necessary associated existing README/MINIFEST. **STRICT READ-ONLY:** `auth/**`, `users/**`, `core/**`, **all `deployment/**`**, existing `.gitea/workflows/**`, other tests (apart from necessary README/MINIFEST), manifests/locks, runner, live DNS/VPS/Coolify/Cloudflare/SSL, production secrets/infrastructure and unrelated files; preserve untracked `AI_INSTRUCTIONS.md`.
- **Evidence-first diagnostics:** for known five services and six symbolic secret-reference names ONLY, log **fixed safe classes** for list entries (string vs dict vs other), whether source matches an allowlisted name, whether target is exact source/basename, canonical `/run/secrets/<source>` or other, whether unexpected grant keys or duplicates exist. No actual source/target strings, credential values, entire normalized JSON, arbitrary key names, environment/secret files, tokens or personal data logged. Read unchanged fixture source and policy **read-only**.
- **Narrow safety fix:** accept *only independently evidenced* harmless Compose-normalized representation of exactly original required grants and per-service expected order/sets with non-deployable external named placeholder secrets; reject missing, duplicated, extra, wrong-target, privileged/broad grant or unknown fields and plaintext credential exposure. Preserve full fail-closed issuer/routing, private ports, 0 replicas, inert metadata and Docker socket/command restrictions.
- **Tests:** preserve original **25**, runtime **4**, replica **3**, deploy **8** negatives; add focused missing/extra/mis-targeted secret grant rejections with exact error classes if relevant, maintain an inert normalized positive fixture. No false PASS before actual run.
- **One focused pre-run source/security/diff audit**, source commit/push, **exactly one newly approved manual Gitea CI dispatch** using unchanged workflow; record full positive markers, all negative fixture markers, manual workflow-safety and runner-owned cleanup. Failure -> stop, no rerun or post-CI code patch. Documentation sync, cumulative exact allowed-path/secret/source-inventory audit and final remote SHA.
- **Never** run Compose up/build/pull, real DNS/TLS, secrets/users, registry, production infrastructure, local app build/test, tag or release.
**No A04 execution without new explicit approval.**