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

79 lines
13 KiB
Markdown
Raw Normal View History

# P05-OIDC-06-A01 — CI-Only Entrypoint Executability RCA and Custom Login Runtime Acceptance
**Date:** 2026-11-23 (Asia/Dhaka)
**Approved baseline (verified main):** `c656b5fbe1f1c2c819a600bad9a6b04105499e85`
**Prior run:** [Gitea Run #98](https://dev.ivib.cc/vibtools/ZitPlane/actions/runs/98), Job #213, source `fcfa59e826c39b445faa1b5b26c47ce715d8c3d6`: COMPLETED FAILURE. Frozen build and local custom image PASS, `exec: "/app/entrypoint.sh": permission denied`, real custom browser NOT EXECUTED, both old/new owned cleanup PASS. Previously accepted official prebuilt [Run #96](https://dev.ivib.cc/vibtools/ZitPlane/actions/runs/96) remains SUCCESS.
## Exact pre-source-change Scope Lock — approved
**WRITE:** This note created and committed **before** the source edit. One CI-only source file: `tests/ci/login_image/build.sh`. At most one *new* narrow helper under `tests/ci/login_image/**` only if strictly needed (not presently justified). Documentation: relevant `notes/**`, `project/**`, `docs/**`, associated README/MINIFEST, root README only if necessary.
**STRICT READ-ONLY:** imported `auth/ui/v2/**` including untouched upstream `apps/login/Dockerfile`, original entrypoint/source/lock, `users/ui/**`, `core/**`, all existing workflows including `.gitea/workflows/p05-custom-login-acceptance.yml`, both Compose files, `tests/ci/oidc_e2e/**` (browser, provision, original cleanup and run.sh), `tests/ci/login_image/cleanup.sh`, package manifests/lockfiles, runner settings, production infrastructure/secrets, unrelated files; preserve untracked `AI_INSTRUCTIONS.md`. No local builds/tests, CI reruns, real humans, public host ports, registry push, production, tags or releases.
## Pre-source forensic observations
1. Gitea recursive tracked tree at immutable approved baseline records `auth/ui/v2/apps/login/scripts/entrypoint.sh` mode **`100644`** and SHA `2da2aca45348afeb7480323e02cf98902d479db3`: the original script is **NOT executable in Git**; it starts with `#!/bin/sh` and its content must remain unchanged.
2. The approved untouched upstream `auth/ui/v2/apps/login/Dockerfile` uses `COPY --chown=nextjs:nodejs .next/standalone ./`, `USER nextjs` and direct `ENTRYPOINT ["/app/entrypoint.sh","node","apps/login/server.js"]`. Its standalone build script copies `scripts/*` into `.next/standalone/` and does **not** chmod entrypoint. The existing `tests/ci/login_image/build.sh` copies generated `.next/standalone` into a **temporary** CI context and invokes the Dockerfile without changing the file mode.
3. Actual Run #98 successfully built the temporary image `zitplane-login-ci:98` then failed at OCI before process startup with `exec: "/app/entrypoint.sh": permission denied`. This is consistent with missing executable bit. **The exact copied context file mode and built image mode were NOT measured in Run #98**; next run will report only sanitized numeric modes and execute-status without secrets.
## Evidence-backed implementation design
- Immediately after `docker cp` to the disposable build context and **before** `docker build`, check **exact regular file, no symlink** for `$context/.next/standalone/entrypoint.sh`; verify its first two bytes are `#!` without printing source contents; collect only numeric mode/UID/GID (`stat`) and test `-x`. A non-executable regular shebang file is the only permitted temporary-artifact remediation case: `chmod 0755` on that **copied temporary file only**; verify exact mode `755` and `-x`. Fail closed on missing, symlink, invalid shebang or unexpected mode/permissions. No upstream or Dockerfile edits.
- After local image creation, before reporting image build PASS and before Compose, use `docker run --rm --network none --entrypoint /bin/sh "$image" -ec '...'` with **no secrets, mounts, published ports, or copied env** to verify `/app/entrypoint.sh` exists, is regular/not symlink, `-x` as default image user and has shebang; output only fixed PASS marker. Do not execute original entrypoint in the preflight or log file contents. Image label/ID still checked.
- One focused source/security/diff audit, commit/push exact tested SHA; dispatch **exactly one** authorized fresh disposable manual `p05-custom-login-acceptance.yml` run (no rerun). Verify frozen source build, temporary copy before/after mode, built image permission and ID, actual custom service health+image ID, exact private Host/issuer, official disposable project/client/user, real Chromium Login V2/PKCE/state/nonce/Auth.js callback/session, protected Account pages/API, negative cases/logout, exact old/new owned cleanup. Document PASS/FAIL/NOT EXECUTED and terminal Gitea outcome; no additional source patch or second run if blocked.
- Documentation synchronization, one exact cumulative path/manifest security audit, remote main SHA verification. Tested source SHA and later documentation SHA distinct. Next phase recommendation only after observed results.
**Pre-execution acceptance:** Source and documentation remain entirely under Scope Lock; privacy/isolation preserved. Actual image/context file mode and custom browser flow pending one CI run.
## Terminal A01 acceptance — VERIFIED COMPLETE
**Source preparation:** Scope Lock first committed at `adc02bd2c31469fa1b268bfb34d4dabc8185941c`; exactly one edited source file, `tests/ci/login_image/build.sh`, tested in source SHA `7d6b6d0704b9e39bcb6e74257dadf0b64a19fc0f`. Focused source/security diff confirmed only that file plus this pre-source Scope Lock note changed before dispatch; `auth/ui/v2/**`, upstream Dockerfile, original entrypoint bytes/mode, `users/ui/**`, `core/**`, existing workflow/Compose/OIDC/cleanup, package locks and infrastructure unchanged. No local build/test or registry publish.
**Single Gitea manual dispatch:** [Run #99](https://dev.ivib.cc/vibtools/ZitPlane/actions/runs/99) / Job #214 on `main`, source `7d6b6d0704b9e39bcb6e74257dadf0b64a19fc0f`, **COMPLETED SUCCESS**, job 2026-11-23T10:35:13Z–2026-11-23T10:43:43Z. All five job steps (#0 Git/CLI, #1 checkout, #2 frozen standalone + image, #3 genuine custom Login Chromium OIDC, #4 `always()` cleanup) **SUCCESS**. No retry/rerun or post-dispatch source edit.
| Gate | Exact outcome / primary evidence |
| --- | --- |
| Git checkout + Docker preflight | **PASS** Gitea job #214 steps #0–1 |
| Run-owned isolated builder and frozen PNPM | **PASS** `ZITPLANE_CUSTOM_LOGIN_ISOLATED_BUILD_PREFLIGHT_PASS`, `ZITPLANE_CUSTOM_LOGIN_FROZEN_INSTALL_PASS` |
| NX proto/client/Next standalone imported source | **PASS** `ZITPLANE_CUSTOM_LOGIN_STANDALONE_BUILD_PASS`; upstream Edge-runtime build warnings were nonfatal |
| Root cause: source-tracked imported entrypoint mode | **VERIFIED** `auth/ui/v2/apps/login/scripts/entrypoint.sh` Git `100644`, SHA `2da2aca45348afeb7480323e02cf98902d479db3` (read-only) |
| Actual copied temporary entrypoint mode/owner | **VERIFIED** `ZITPLANE_CUSTOM_LOGIN_ENTRYPOINT_COPY_MODE=644 OWNER=0:0` |
| Temporary artifact execute-bit correction only | **PASS** `ZITPLANE_CUSTOM_LOGIN_TEMP_ENTRYPOINT_MODE_FIXED_PASS`, `ZITPLANE_CUSTOM_LOGIN_ENTRYPOINT_COPY_EXECUTABLE_PASS` (mode `755`) |
| Built image `/app/entrypoint.sh` default-user executable/no-network check | **PASS** `ZITPLANE_CUSTOM_LOGIN_BUILT_IMAGE_ENTRYPOINT_EXECUTABLE_PASS` |
| Disposable local custom image packaging + label and ID | **PASS** `ZITPLANE_CUSTOM_LOGIN_LOCAL_IMAGE_BUILT_PASS`; `zitplane-login-ci:99`, image ID `sha256:42fba458e25d3186c504ae4532fece489986a18ab5fdcf97e87b052c4866207f`; **NOT published** |
| Docker/Compose four healthy official backend services, no host-published ports | **PASS** `ZITPLANE_OIDC_DOCKER_PREFLIGHT_PASS`, `ZITPLANE_OIDC_NO_PUBLISHED_PORT_AND_OWNER_CONFIG_PASS`, `ZITPLANE_OIDC_FOUR_SERVICES_READY_PASS` |
| Actual running Login container matches source-built image | **PASS** `ZITPLANE_CUSTOM_LOGIN_RUNNING_IMAGE_MATCH_PASS` |
| Private Traefik HTTP 200 / socket owner | **PASS** `ZITPLANE_OIDC_PRIVATE_PROXY_HOST_ROUTE_PASS`, TCP6:8080 `traefik` PID1 and `ZITPLANE_OIDC_PROXY_PREBIND_SOCKET_FORENSICS_PASS` |
| Immutable forwarder and private loopback/issuer discovery | **PASS** `ZITPLANE_OIDC_PINNED_FORWARDER_DIGEST_VERIFIED_PASS`, `ZITPLANE_OIDC_SOCAT_FORWARDER_READY_PASS`, `ZITPLANE_OIDC_PRIVATE_LOOPBACK_FORWARDER_READY_PASS`, `ZITPLANE_OIDC_LOCAL_ORIGIN_READY_PASS`, `ZITPLANE_OIDC_ISSUER_DISCOVERY_PASS` |
| Official disposable ZITADEL project/client/verified human | **PASS** `ZITPLANE_OIDC_PROJECT_CREATED_PASS`, `ZITPLANE_OIDC_REAL_CLIENT_CREATED_PASS`, `ZITPLANE_OIDC_REAL_TEST_HUMAN_CREATED_PASS`, `ZITPLANE_OIDC_TEST_CREDENTIALS_ISOLATED_PASS`, `ZITPLANE_OIDC_DISPOSABLE_PROVISIONING_PASS` |
| Account Portal dependencies and HTTP readiness | **PASS** `ZITPLANE_OIDC_DISPOSABLE_ACCOUNT_DEPENDENCIES_READY_PASS`, `ZITPLANE_OIDC_DISPOSABLE_ACCOUNT_HTTP_READY_PASS` |
| Anonymous API/page and tampered callback negative cases | **PASS** `ZITPLANE_OIDC_ANONYMOUS_API_AND_PAGE_REJECTED_PASS`, `ZITPLANE_OIDC_INVALID_CALLBACK_FAIL_CLOSED_PASS` |
| Chromium real authorize PKCE S256/state/nonce | **PASS** `ZITPLANE_OIDC_REAL_AUTHORIZE_PKCE_STATE_NONCE_PASS` |
| Imported custom Login V2 real password and Auth.js callback | **PASS** `ZITPLANE_OIDC_REAL_PASSWORD_AND_CALLBACK_PASS` |
| Matched Auth.js subject/session, protected Account API/page | **PASS** `ZITPLANE_OIDC_REAL_SESSION_PROTECTED_PAGE_AND_API_PASS` |
| Portal-local logout/session revocation | **PASS** `ZITPLANE_OIDC_PORTAL_LOGOUT_SESSION_REVOKED_PASS` |
| Full real Chromium browser acceptance | **PASS** `ZITPLANE_OIDC_REAL_BROWSER_COMPLETE_PASS`, `ZITPLANE_OIDC_REAL_BROWSER_ACCEPTANCE_PASS` |
| Existing backend/credentials/volumes/network exact-owned cleanup | **PASS** `ZITPLANE_BACKEND_CLEANUP_VERIFIED_PASS`, `ZITPLANE_OIDC_ALL_RESOURCES_CLEANED_PASS` |
| New run-owned image/builder/temp context cleanup | **PASS** `ZITPLANE_CUSTOM_LOGIN_ALL_BUILD_RESOURCES_CLEANED_PASS` |
| Optional Python forwarder fallback | **NOT EXECUTED / NOT REQUIRED** — Socat passed |
| Proxy transient retry negative branch / permission unexpected-mode branch | **NOT EXECUTED** — positive first-attempt paths passed |
| Production TLS, real domains/users, MFA/passkeys, Admin Console, multiple app SSO | **NOT EXECUTED / OUT OF SCOPE** |
### Root cause conclusively resolved
The tracked upstream shell entrypoint is `100644`; its actual generated temporary standalone copy was `644`, owned 0:0, and it was copied into a Docker image whose existing upstream `ENTRYPOINT` attempts direct execution. This explains Run #98's pre-process OCI `permission denied`. Under A01 the **only** permission mutation was `chmod 0755` on the run-owned disposable copied `.next/standalone/entrypoint.sh` build-context file, after regular-file/no-symlink/shebang/numeric checks. Image `/app/entrypoint.sh` passed no-network no-secret default-`nextjs` executable verification. In the real service (under existing CI Compose runtime policies), custom image started healthy, matched the immutable local image ID and completed real browser OIDC. The upstream source and Dockerfile **remain byte-for-byte unchanged**.
**P05-OIDC-06-A01 acceptance: COMPLETE / PASS for imported custom Login V2 development-origin disposable E2E**, not deployed production. Successful original prebuilt Run #96 remains an independent accepted baseline; Run #98 remains a historical **FAIL** (not rewritten).
### Next proposed exact Scope Lock — P05-OIDC-07 (not authorized yet)
**Title:** Production HTTPS, Issuer/Ingress and Secrets/Recovery Deployment Contract Forensic Design.
**Baseline:** Final documentation-only A01 Gitea SHA (verify at closure); accepted real custom-image E2E source `7d6b6d0704b9e39bcb6e74257dadf0b64a19fc0f`.
**WRITE ONLY:** `notes/P05-OIDC-07.md` (first), relevant `project/**`, `docs/**` and associated README/MINIFEST as necessary. **READ-ONLY:** all `auth/**`, `users/**`, `core/**`, `deployment/**`, `tests/**`, `.gitea/workflows/**`, manifests/locks, runner configuration, live DNS/VPS/Coolify/SSL/account infrastructure, production secrets and unrelated files. Preserve untracked `AI_INSTRUCTIONS.md`.
**Task:** Design and audit (no deploy) minimum production configuration for `auth.vib.tools` / `account.vib.tools` (proposed, not verified live): canonical HTTPS issuer and Login/Console routes, ZITADEL HTTP2/h2c + TLS proxy topology, secure Forwarded/Host/redirect/callback allowlists, Auth.js session and cookie security, zero public backend ports, secret/master-key/PAT issuance/rotation, least-privilege bootstrap/break-glass, SMTP, PostgreSQL backup/restore, immutable images/current advisory + rollout/rollback/monitoring. Distinguish existing source evidence from missing external state and produce one minimal scoped **CI-only production-config dry-run implementation plan** requiring separate approval. No new CI run, local build/tests, real human login, DNS/infra edit, production deploy, tag/release. Final documentation sync, one exact diff audit, remote Git SHA and copy-ready next approval.
**This phase contains no operator production acceptance**, and documentation commits after Run #99 are not new tested source commits.