fix(seed-job): content-validating idempotency + Keycloak redirectUris patcher (unblock SSO over LAN)#53
Merged
ciprianiacobescu merged 4 commits intoMay 17, 2026
Conversation
added 4 commits
May 17, 2026 09:19
Two related bootstrap-pipeline defects:
1. seed-job _ensure_* functions check existence not validity → stale
secrets persist after format changes (jaeger cookie bug on 2026-05-17).
2. SSO over LAN broken because: (a) .env missing 5 PUBLIC_URL settings,
(b) realm JSON has literal '${MINTKEY_*_PUBLIC_URL}' placeholders that
neither Keycloak nor seed-job substitute.
Owner-locked: seed-job patches redirectUris/webOrigins after realm
import using env-var values. Idempotent. Localhost preserved for
local dev.
…redirectUris patcher Two related defects in the bootstrap pipeline addressed in one commit because both touch seed-job/main.py. ## SF-1 — idempotency footgun Added `_ensure_secret_file()` helper that validates existing content (size + format), not just file existence. Regenerates on validation failure; preserves on success. Applied to: - `_ensure_jaeger_cookie_secret`: validates 44-char base64url - `_write_client_secrets`: validates non-empty + matches live Keycloak secret (catches operator rotation via Keycloak UI too) - `_ensure_admin_password_file` (new wrapper): validates 12-128 chars Catches the PR #50 64-byte hex format bug AND any future format change to any seed-managed secret. 10 offline unit tests pass. ## SSO-1 — Keycloak client redirectUris patcher `seed-job/realm-mintkey.json` previously stored literal placeholder strings like `${MINTKEY_ADMIN_API_PUBLIC_URL}/v1/auth/oidc/callback` in client redirectUris. Keycloak does NOT substitute env vars; seed-job did not patch them after import. Result: operator-facing login over LAN (e.g. http://10.243.1.200:8081/) was rejected with `invalid_redirect_uri` because no allow-listed URI matched. Added `_patch_keycloak_client_redirect_uris(client_id_name, callback_path, public_url_env)` called after realm import for: - mintkey-admin-api → /v1/auth/oidc/callback / MINTKEY_ADMIN_API_PUBLIC_URL - mintkey-grafana → /login/generic_oauth / MINTKEY_GRAFANA_PUBLIC_URL - mintkey-jaeger → /oauth2/callback / MINTKEY_JAEGER_PUBLIC_URL Algorithm: GET client → compute desired URIs (preserve localhost, drop `${...}` placeholders, add public URL if env var set) → PUT only if different. Idempotent (no-op if already correct). Logs "patched <client> redirectUris: ..." or "<client> redirectUris already current." realm-mintkey.json updated: `${...}` placeholders removed from all 3 clients (the patcher now adds the correct values dynamically). docker-compose.yml seed-job env extended to forward MINTKEY_{ADMIN_API,GRAFANA,JAEGER}_PUBLIC_URL. Verification (local): - Test 1: existing-valid jaeger cookie preserved across re-runs. - Test 2: 11-byte stale cookie → detected INVALID → regenerated 44 bytes. - Test 3: idempotent ("valid — skipping") on second run. - Test 4: jaeger-auth healthy after seed-job re-run. - Patcher: 3 clients get LAN-IP URIs added; re-run logs "already current". - Keycloak REST query confirms: no `${...}` literal remains; LAN IP + localhost both in redirectUris. CI regression: low — seed-job's patcher no-ops when env vars unset (CI integration test path). Idempotency helper is purely additive over existing logic. Out-of-scope follow-ups (documented in 99-report): - `webOrigins` left at `+` (Keycloak permissive default); explicit LAN origin patching deferred — covers same-origin already.
Keycloak realm enforces PKCE S256 on mintkey-jaeger client (per seed-job _enforce_pkce_on_clients), but oauth2-proxy v7.6.0 doesn't enable PKCE automatically. Without the flag, the auth flow reached Keycloak but returned: error=invalid_request&error_description=Missing+parameter%3A+code_challenge_method Added --code-challenge-method=S256 to the exec line. Verified via live curl chain: /oauth2/sign_in now lands on Keycloak login page with code_challenge=... in the URL. Same root-cause-family as PR #48 (otel-collector config drift) and PR #52 (oauth2-proxy cookie format): config-vs-runtime expectation mismatch surfaced once the upstream constraint became reachable.
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes two related bootstrap defects + one cascading mismatch. After this lands, an operator can SSO-login to admin-ui, Grafana, and Jaeger over LAN via Keycloak.
_ensure_secret_file)_patch_keycloak_client_redirect_uris)redirectUrisafter realm import, substituting env-var-derived public URLs. Literal${...}placeholders removed fromrealm-mintkey.json. Localhost preserved.--code-challenge-method=S256(Keycloak realm enforces PKCE S256 onmintkey-jaeger).Verification (end-to-end, live local stack at 10.243.1.200)
All 3 SSO chains:
curl -sL http://10.243.1.200:{8081,3003,16686}/→ 200, lands on Keycloak login page with correct LAN-IP redirect_uri.Idempotency: 4 stale-→-regen and valid-→-skip live tests pass.
Change Type
Provenance
team/remediation/2026-05-17-seed-job-idempotency-and-sso/_ensure_secret_filevalidatorsVerification
Agent/Automation Rules
--no-verifyCo-Authored-Bytrailer