Files
ZitPlane/notes/P05-OIDC-10-A01.md
T

82 lines
14 KiB
Markdown

# P05-OIDC-10-A01 — Safe OCI Environment-Key Boundary RCA & Provenance Acceptance
**Date:** 2026-11-24 Asia/Dhaka.
**Approved baseline:** `195568a8be978304a686c826cdcbf0ab0d36c6a6`, independently verified current Gitea `main`.
**Previous source-tested SHA:** `6ba004808ef47c8856c1a7906faaf7ee807d15a6`.
**Previous [Run #106](https://dev.ivib.cc/vibtools/ZitPlane/actions/runs/106) / Job #222:** `COMPLETED FAILURE`: immutable source-tree/PNPM/base pins PASS; 12/12 provenance negatives PASS; pinned frozen Login standalone and temporary OCI build, 0755 entrypoint, linux/amd64 builder index PASS; final `ZITPLANE_P10_FAIL_CLOSED_IMAGE_SECRET_ENV_KEY` FAIL; partial SPDX/unsigned attestation NOT EXECUTED; unchanged owned builder/image/context cleanup PASS and Gitea task cleanup observed. Actual rejected image env key UNKNOWN (the unanchored `PAT` matcher could match common `PATH`, but this is NOT proven until new CI).
## EXACT APPROVED SCOPE LOCK — THIS NOTE MUST BE COMMITTED BEFORE SOURCE EDITS
**SOURCE WRITE ONLY:** `tests/ci/login_image/provenance.py`. Add fixed allowlisted environment-key diagnostics, precisely scoped fail-closed secret/credential-key handling and focused positive/negative in-memory tests. Retain original 12 source/OCI negative cases unchanged and their markers. Do not alter image pins or bypass real credential injection checks.
**DOCUMENTATION WRITE ONLY:** `notes/**`, relevant `project/**`, relevant `docs/**`, associated `tests/ci/login_image/{README.md,MINIFEST.md}`, `.gitea/workflows/{README.md,MINIFEST.md}`, necessary root README/MINIFEST and exact inventory documentation.
**STRICT READ ONLY:** `auth/**`, `users/**`, `core/**`, `deployment/**`, `tests/ci/login_image/{build.sh,cleanup.sh,provenance-lock.json}`, **ALL existing Gitea workflow YAMLs** including `.gitea/workflows/p05-login-provenance.yml`, **ALL other tests/**, package manifests/lockfiles, Gitea runner config, VPS/DNS/SSL/Coolify/Cloudflare/production credentials and infrastructure, unrelated paths. Untracked `AI_INSTRUCTIONS.md` is untouched/uninspected.
**NO:** local app build/test, production deployment, external live DNS/TLS, secrets/users, signing keys, registry push, release/tag, actual production app startup. **EXACTLY ONE** newly approved manual Gitea dispatch of the unchanged existing provenance workflow, after one focused pre-run source/security/diff audit. If failure: do **not** rerun, dispatch a second run, or edit source post-CI. Run-owned cleanup remains mandatory. Keep accepted prior Run #99 real disposable custom Login and Run #105 48/48 synthetic security CI unchanged.
## Read-only RCA and planned strict remediation
- Existing `validate_image()` parses image `Config.Env` list and currently uses **unanchored** `(SECRET|PASSWORD|TOKEN|PAT|MASTERKEY|DATABASE|AUTH_|PRIVATE_KEY)` search on environment *key names*; innocuous `PATH` contains `PAT`. This is a **code-proven collision candidate**, not a proven actual offending key in Run #106, because the original validator emitted only a fail-closed class.
- Restrict data exposure: in the new CI image scan print only **predefined known safe environment key names**, e.g. `PATH`, `NODE_VERSION`, `YARN_VERSION`, `NODE_ENV`, `HOSTNAME`, `PORT`, `NODE_OPTIONS`, `SSL_CERT_FILE`, `ZITADEL_TLS_ENABLED`, `OTEL_SERVICE_NAME`, `OTEL_EXPORTER_OTLP_PROTOCOL` and approved essential benign system keys if independently justified. For any unexpected key only a fixed marker `UNKNOWN_KEY_PRESENT` or `SENSITIVE_KEY_PRESENT`; **never** print arbitrary keys, raw OCI JSON, environment values, credentials, tokens, file paths from unknown inputs or secret contents.
- Key validation must remain **fail-closed**: accept an exact finite set of documented benign OCI image-config environment names and explicitly enforce credential-sensitive segments/boundaries; reject `AUTH_SECRET`, `ZITADEL_MASTERKEY`, `ZITADEL_SERVICE_USER_TOKEN`, `LOGIN_CLIENT_PAT`, DB passwords, private-key/credential-bearing keys, unknown/unexpected keys, duplicate/invalid environment entries, and unsafe image user, entrypoint, labels or platform. Do NOT broaden allowlisting based on unknown key data or allow env-sensitive prefixes. Require production `NODE_ENV=production`.
- Preserve original **12/12** source/OCI negative cases with exact classes and add PATH positive acceptance plus strict sensitive token/PAT/MASTERKEY/DB/PRIVATE_KEY, unknown/duplicate and malformed env rejection fixtures. New diagnostics must not run on arbitrary strings as dynamic marker suffixes.
- Source/lock/CI remain pinned and unaffected: original imported Git source/tree and Node22 Bookworm/Node24 Alpine OCI base indexes are fixed. Never edit upstream Login code or original image builder/workflow.
- After one focused source/security/cumulative diff review, commit tested source and dispatch one Gitea run. Confirm exact real OCI env key **only if an allowlisted safe diagnostic marker is emitted**, final image attestation/partial SPDX files, 12 original and new cases, standalone build, immutable source/images, 0755/nonroot, owned cleanup. Classify each PASS/FAIL/NOT EXECUTED and record exact source SHA. No second CI or source patch.
- Complete `notes/P05-OIDC-10-A01.md` and `docs/P05-OIDC-10-A01.md`, synchronize project/docs/README/MINIFEST and exact tracked inventory, commit and verify final Gitea main SHA. Distinguish CI-tested source SHA from documentation-only SHA.
**Production stop condition remains:** even if CI passes, partial source/base material SPDX and **UNSIGNED** provenance are not a full transitive/OS SBOM, signed registry release or production HTTPS/Console/MFA/SSO acceptance. Production go/no-go remains BLOCKED pending separate phases.
## A01 source implementation, focused audit and existing CI scheduling evidence
**Scope-first note SHA:** `46e2897380b736b970a0b1de15a161c3600abcb6`, committed before any change to `tests/ci/login_image/provenance.py`. **Exactly one source file** changed; tested source `4452a61b0f5a0892399060fd7569231a564bce02`. Baseline `195568a8be978304a686c826cdcbf0ab0d36c6a6`. Source change was committed to `main` before dispatch. Existing `auth/**`, `users/**`, `core/**`, `deployment/**`, all other tests, `build.sh`, `cleanup.sh`, `provenance-lock.json` and ALL existing workflow YAMLs were **strictly read-only**. Untracked `AI_INSTRUCTIONS.md` remains untouched.
### Verified source-level RCA and security boundary
- Historical [Run #106](https://dev.ivib.cc/vibtools/ZitPlane/actions/runs/106) failed `IMAGE_SECRET_ENV_KEY`, without logging the actual key. Old source used `(SECRET|PASSWORD|TOKEN|PAT|MASTERKEY|DATABASE|AUTH_|PRIVATE_KEY)` as **unanchored** substring over environment key names. Standard benign `PATH` **does contain `PAT`** as a prefix, so a false-positive mechanism is **SOURCE VERIFIED**. Whether that exact key caused Run #106 is still **CI NOT VERIFIED** until new run prints a fixed allowlisted PATH marker.
- `classify_oci_env_key()` recognizes complete underscore-separated credential-bearing segments (`AUTH`, `SECRET`, `PASSWORD`, `TOKEN`, `PAT`, `MASTERKEY`, `DATABASE`, `POSTGRES`, `PRIVATE`, `KEY`, `CREDENTIAL`, etc.), rather than accepting arbitrary names containing the string `PAT`. Exact safe allowed names are limited to frozen image's expected `PATH`, `NODE_VERSION`, `YARN_VERSION`, `NODE_ENV`, `HOSTNAME`, `PORT`, `NODE_OPTIONS`, `SSL_CERT_FILE`, `ZITADEL_TLS_ENABLED`, `OTEL_SERVICE_NAME`, `OTEL_EXPORTER_OTLP_PROTOCOL`. Unexpected keys FAIL CLOSED, even without a sensitive token segment.
- `validate_image()` rejects credential-bearing keys (`IMAGE_SECRET_ENV_KEY`), malformed names (`IMAGE_ENV_KEY_FORMAT`), unknown names (`IMAGE_UNEXPECTED_ENV_KEY`), duplicate names (`IMAGE_ENV_DUPLICATE_KEY`), untrusted `NODE_ENV` (`IMAGE_PRODUCTION_ENV`), unsafe image source labels/user/entrypoint/platform. It checks the variable **names only**, never prints or records their values.
- `diagnose_oci_image_env()` prints only **predefined allowed benign key names** such as `ZITPLANE_P10_OCI_ENV_KNOWN_PATH_PRESENT` and `ZITPLANE_P10_OCI_ENV_LEGACY_MATCH_PATH_VERIFIED` if actually present on the inspected OCI image, or **fixed generic classifications** `UNKNOWN_KEY_PRESENT`, `SENSITIVE_KEY_PRESENT`, `INVALID_ENTRY_PRESENT`, `DUPLICATE_KEY_PRESENT`; never arbitrary input keys or values, credentials, entire Docker image-inspect JSON. The old matcher is retained ONLY in this safe forensic classifier, not as a rejection rule.
- The original **12** provenance-security negative cases and `ZITPLANE_P10_ALL_12_PROVENANCE_NEGATIVES_PASS` marker remain defined unchanged. Source adds **14** targeted synthetic env negative cases (nine forbidden credential-bearing key classes, unexpected name, duplicate PATH, malformed entry, invalid name format, production-mode downgrade), plus one **positive harmless PATH acceptance**. **These new cases are SOURCE PRESENT but CI NOT EXECUTED at current queue state**. No local tests were run.
### One focused pre-run source/security/diff audit
**PASS:** Approved baseline→tested source `4452a61b0f5a0892399060fd7569231a564bce02` cumulative diff exactly **two** paths: `notes/P05-OIDC-10-A01.md` and `tests/ci/login_image/provenance.py`. First commit `46e2897380b736b970a0b1de15a161c3600abcb6` precedes source. All other source/workflow/runtime/production paths unchanged; original 12 negatives preserved; finite diagnostic markers, allowlisted only; no network/registry/prod actions added. Recursive tree returned >1000 total directory+file entries, so both pages were consulted; no missing file/path inferred from the first page's `truncated:true`. This is source/diff audit, **not CI test pass**.
### Single approved CI dispatch and latest observed status
**Dispatched exactly ONE new manual workflow**, the unchanged `.gitea/workflows/p05-login-provenance.yml`, on `main`: [Gitea Run #108](https://dev.ivib.cc/vibtools/ZitPlane/actions/runs/108) / Job #230, event `workflow_dispatch`, **tested source `4452a61b0f5a0892399060fd7569231a564bce02`**, created 2026-11-23T18:05:23Z (2026-11-24 00:05:23 Asia/Dhaka). **Last read-only inspection: Run #108 QUEUED, Job #230 QUEUED; `started_at` unset, job step list empty, no job log.** Workflow is **active**. Runner online/offline/label match/capacity/registration remains **UNKNOWN**; no runner-management interface or authorized change used. A queued run is not a CI success or failure. **NO SECOND DISPATCH, NO RERUN, NO POST-RUN SOURCE PATCH.**
| Exact gate | Actual observed A01 outcome |
| --- | --- |
| Scoped first commit, exact two-path pre-CI security audit, source change committed | **PASS — Git/source read-only evidence** |
| Correct single manual Run #108 dispatch on exact source `4452a61b0f5a0892399060fd7569231a564bce02` | **PASS — queued job recorded** |
| Required runner `ubuntu-latest` availability, capacity, registration, scheduled job | **UNKNOWN / QUEUED** |
| Check out source and immutable source/OCI pins | **NOT EXECUTED** |
| Original 12 negative fixtures | **NOT EXECUTED** |
| A01 14 extra credential/env negatives + harmless PATH positive | **NOT EXECUTED** |
| Real OCI allowlisted `PATH` legacy-collision diagnostic, exact offending previous key | **NOT EXECUTED / UNKNOWN** |
| Frozen PNPM/Next source-built Login, pinned runtime/builder, entrypoint and nonroot/label checks | **NOT EXECUTED** |
| Partial SPDX materials and unsigned attestation written to temporary owned context | **NOT EXECUTED** |
| Run #108 exact cleanup and Gitea runner owned task cleanup | **NOT EXECUTED** |
| No image publish/production access configured in unchanged workflow | **SOURCE-LEVEL PASS**; execution NOT STARTED |
| Historic Run #99 Login disposable OIDC, Run #105 static 48/48 security, Run #106 pinned local build/cleanup | **HISTORICAL CI ACCEPTANCE unchanged; not new A01 evidence** |
**A01 current acceptance verdict: SOURCE IMPLEMENTATION + SCOPE AUDIT PASS, CI ACCEPTANCE PENDING / BLOCKED BY QUEUED RUN #108.** No source fix is accepted as actually working against a real OCI image until the same run reaches terminal status with complete logs. If Run #108 later fails, preserve fail-closed policy: no post-run source patch or rerun under this approval. Do not describe production image provenance as certified.
### Next independently approvable Scope Lock — P05-OIDC-10-A02
**Title:** Runner Scheduling RCA & Existing Run #108 Terminal Provenance Acceptance, **read-only first**.
**Baseline:** exact verified A01 final Gitea main docs SHA after closure; A01 tested source `4452a61b0f5a0892399060fd7569231a564bce02`; **existing Run #108 / Job #230** must be checked, **not dispatched again**.
1. Commit `notes/P05-OIDC-10-A02.md` Scope Lock **before other documentation changes**; source tree, workflows and external infrastructure **strictly read-only**.
2. Use existing Gitea run/job/log + available **read-only** runner evidence to determine runner online/offline, `ubuntu-latest` label matching, registration and busy capacity; if unavailable record **UNKNOWN** and do not infer offline. Do not change runner or server settings.
3. If existing Run #108 executes, inspect exactly its terminal status, safe PATH classifier, original 12+extra 14 negative fixtures, frozen Login/OCI nonroot, image ID, partial SPDX/unsigned local attestation and `always()` run-owned + runner cleanup. Record every PASS/FAIL/NOT EXECUTED. If already completed, do not create a new run. If still queued, report QUEUED and leave untouched.
4. **No new CI dispatch/rerun**, no source/runner/workflow edits, no Docker build/manual execution, registry publishing, live DNS/TLS/secrets/users, deployment, tag or release. Existing `AI_INSTRUCTIONS.md` untouched.
5. **Documentation write only:** `notes/**`, relevant `project/**`, relevant `docs/**`, associated README/MINIFEST as required. Focused documentation/security/diff audit, reconcile exact tracked inventory, commit/push final Gitea main and report exact baseline/head. If runner action is truly necessary, propose a **separate** narrow permissioned approval—do not silently change runner state.
6. Production gate remains BLOCKED even after successful CI: partial unsigned SBOM is not full OS/dependency SBOM, signed release, public HTTPS/SSO/MFA/Console or backup recovery.
**P05-OIDC-10-A02 is PROPOSED only; not yet approved or executed.**