feat: add administrator-owned SSO impersonation #11

Merged
exler merged 1 commit from feat/admin-impersonation into main 2026-11-08 19:58:02 +01:00
Collaborator

Summary

  • Add session-bound administrator impersonation from the user detail page, with an actor-visible banner and explicit stop/return action.
  • Keep the real administrator as the Thermopylae session owner; applications receive only the selected user's identity, access and roles.
  • Add an administrator-only audit of start, application sign-in and end events, without changing the target's own sessions or normal login history.

Security and lifecycle

  • Fully authenticated, enabled administrators only; CSRF-protected POST actions, rotated session credentials, no nesting, and eligible target checks.
  • Maximum 30 minutes, capped by the actor session. Provenance-bound authorization codes/access tokens are invalidated on stop, expiry and actor-session revocation; permissions and account state are rechecked on issuance/exchange/userinfo.
  • Real SQLite serialization and atomic auditing cover concurrent issuance/revocation. Other administrator/target sessions and ordinary tokens remain unaffected.
  • Ended contexts refuse SSO until the administrator explicitly returns; there is no silent administrator fallback within the affected session.

Agreed limitations

Only new SSO logins are affected. Existing application sessions are neither switched nor ended automatically: sign out/in in each application before impersonation and again after ending it. Already issued signed ID tokens cannot be recalled; their expiry is capped. Applications can send their own login notices. Thermopylae does not notify the impersonated user or expose the impersonation in their own account/history.

Migration

Additive SQLite migration 0006: impersonation context/audit tables, nullable credential/session provenance and transactional lifecycle triggers. Existing sessions/tokens retain null provenance. Back up the database before a future deployment; reverting to an older binary requires restoring a compatible backup. This PR does not deploy anything.

Verification

  • Parent: fresh go test -count=1 ./..., go vet ./..., normal build and git diff --check passed.
  • Parent: SQL regenerated with sqlc; generated-file hashes unchanged.
  • Parent: fresh final-code local browser/OIDC smoke 133 checks, 0 failures, including JWKS signature validation, target-only claims, ordinary-target privacy, other-session isolation, stop/timeout, redirect-chain identity safety and administrator-target audit privacy.
  • Parent visually inspected desktop/mobile start, active banner, ordinary target account, full audit and the changed sign-in-refusal/administrator-target views.
  • Independent Claude Code security review and targeted follow-up re-review both returned no blockers. Parent additionally required and verified two corrections: terminate stale-cookie authorization redirect chains across Start/Stop instead of silently changing subjects; hide an administrator target's own impersonation audit entries at SQL level before pagination. Regression tests cover both.
  • Audit visibility is intentionally privacy-filtered: a target administrator cannot see records about themselves; the actor and any other administrator can. With only two administrators, those records may therefore be visible only to the actor in the UI, while the durable database audit remains intact.
  • Local smoke uses synthetic applications over loopback HTTP, not real relying-party software or production TLS. Stale idle forms retain the existing reload-required CSRF behavior.
  • All final Go package tests pass locally; worker's JSON tally is 117 passing test/subtest events (not 117 top-level tests).
  • Final CI passed on commit 64e9640347b9b8b04a49758b3e9db085cbe4c5dc: run 24, test job successful, including go vet ./... and go test -race ./... (verified against the committed workflow and passing linux/amd64 package results in runner logs). The image-publish job is intentionally skipped for pull requests; nothing was deployed. Local Raspberry Pi race execution is unsupported due to ThreadSanitizer VMA47/48 incompatibility.

Screenshots

Synthetic local fixtures; no real account or credential data.

02 start desktop

Screenshot: 02-start-desktop.png

02 start phone

Screenshot: 02-start-phone.png

05 banner admin desktop

Screenshot: 05-banner-admin-desktop.png

05 banner admin phone

Screenshot: 05-banner-admin-phone.png

08 target account phone

Screenshot: 08-target-account-phone.png

14 audit full desktop

Screenshot: 14-audit-full-desktop.png

14 audit full phone

Screenshot: 14-audit-full-phone.png

15 inflight across start desktop

Screenshot: 15-inflight-across-start-desktop.png

15 inflight across start phone

Screenshot: 15-inflight-across-start-phone.png

17 audit as admin target desktop

Screenshot: 17-audit-as-admin-target-desktop.png

17 audit as admin target phone

Screenshot: 17-audit-as-admin-target-phone.png

## Summary - Add session-bound administrator impersonation from the user detail page, with an actor-visible banner and explicit stop/return action. - Keep the real administrator as the Thermopylae session owner; applications receive only the selected user's identity, access and roles. - Add an administrator-only audit of start, application sign-in and end events, without changing the target's own sessions or normal login history. ## Security and lifecycle - Fully authenticated, enabled administrators only; CSRF-protected POST actions, rotated session credentials, no nesting, and eligible target checks. - Maximum 30 minutes, capped by the actor session. Provenance-bound authorization codes/access tokens are invalidated on stop, expiry and actor-session revocation; permissions and account state are rechecked on issuance/exchange/userinfo. - Real SQLite serialization and atomic auditing cover concurrent issuance/revocation. Other administrator/target sessions and ordinary tokens remain unaffected. - Ended contexts refuse SSO until the administrator explicitly returns; there is no silent administrator fallback within the affected session. ## Agreed limitations Only **new SSO logins** are affected. Existing application sessions are neither switched nor ended automatically: sign out/in in each application before impersonation and again after ending it. Already issued signed ID tokens cannot be recalled; their expiry is capped. Applications can send their own login notices. Thermopylae does not notify the impersonated user or expose the impersonation in their own account/history. ## Migration Additive SQLite migration `0006`: impersonation context/audit tables, nullable credential/session provenance and transactional lifecycle triggers. Existing sessions/tokens retain null provenance. Back up the database before a future deployment; reverting to an older binary requires restoring a compatible backup. **This PR does not deploy anything.** ## Verification - Parent: fresh `go test -count=1 ./...`, `go vet ./...`, normal build and `git diff --check` passed. - Parent: SQL regenerated with `sqlc`; generated-file hashes unchanged. - Parent: fresh final-code local browser/OIDC smoke **133 checks, 0 failures**, including JWKS signature validation, target-only claims, ordinary-target privacy, other-session isolation, stop/timeout, redirect-chain identity safety and administrator-target audit privacy. - Parent visually inspected desktop/mobile start, active banner, ordinary target account, full audit and the changed sign-in-refusal/administrator-target views. - Independent Claude Code security review and targeted follow-up re-review both returned **no blockers**. Parent additionally required and verified two corrections: terminate stale-cookie authorization redirect chains across Start/Stop instead of silently changing subjects; hide an administrator target's own impersonation audit entries at SQL level before pagination. Regression tests cover both. - Audit visibility is intentionally privacy-filtered: a target administrator cannot see records about themselves; the actor and any other administrator can. With only two administrators, those records may therefore be visible only to the actor in the UI, while the durable database audit remains intact. - Local smoke uses synthetic applications over loopback HTTP, not real relying-party software or production TLS. Stale idle forms retain the existing reload-required CSRF behavior. - All final Go package tests pass locally; worker's JSON tally is 117 passing test/subtest events (not 117 top-level tests). - **Final CI passed** on commit `64e9640347b9b8b04a49758b3e9db085cbe4c5dc`: [run 24](https://git.marut.network/exler/thermopylae/actions/runs/24), `test` job successful, including `go vet ./...` and `go test -race ./...` (verified against the committed workflow and passing linux/amd64 package results in runner logs). The image-publish job is intentionally skipped for pull requests; nothing was deployed. Local Raspberry Pi race execution is unsupported due to ThreadSanitizer VMA47/48 incompatibility. ## Screenshots Synthetic local fixtures; no real account or credential data. ### 02 start desktop ![Screenshot: 02-start-desktop.png](https://git.marut.network/attachments/fd59af49-30ef-4854-88ed-e6387646e9ce) ### 02 start phone ![Screenshot: 02-start-phone.png](https://git.marut.network/attachments/75ed5cfa-8ce4-4596-bf2d-7274dd6ff9e7) ### 05 banner admin desktop ![Screenshot: 05-banner-admin-desktop.png](https://git.marut.network/attachments/5ba2a4d7-a2f1-4539-9fd9-a2130d747cf2) ### 05 banner admin phone ![Screenshot: 05-banner-admin-phone.png](https://git.marut.network/attachments/a77bccfb-fc0d-4b25-89da-5a92e00af92e) ### 08 target account phone ![Screenshot: 08-target-account-phone.png](https://git.marut.network/attachments/68beafb0-9f6a-4f84-9e0c-c20e2ae94c7f) ### 14 audit full desktop ![Screenshot: 14-audit-full-desktop.png](https://git.marut.network/attachments/a536c497-20d1-45f2-9d73-69a5598fdbc1) ### 14 audit full phone ![Screenshot: 14-audit-full-phone.png](https://git.marut.network/attachments/9ad2c8c6-5bb4-4cd6-9bc1-f31f11d6ee17) ### 15 inflight across start desktop ![Screenshot: 15-inflight-across-start-desktop.png](https://git.marut.network/attachments/676dedeb-91e3-4491-9596-d0732658d7ec) ### 15 inflight across start phone ![Screenshot: 15-inflight-across-start-phone.png](https://git.marut.network/attachments/3152ced3-04d2-47b3-ac4f-baec0f55edff) ### 17 audit as admin target desktop ![Screenshot: 17-audit-as-admin-target-desktop.png](https://git.marut.network/attachments/e646ca3f-ea0e-4902-ac41-55ebbbcd2a2e) ### 17 audit as admin target phone ![Screenshot: 17-audit-as-admin-target-phone.png](https://git.marut.network/attachments/42dbc2a5-08df-4002-99c6-c16437882022)
feat: add session-bound administrator impersonation
All checks were successful
Push Docker Image / test (pull_request) Successful in 2m9s
Push Docker Image / push (pull_request) Has been skipped
64e9640347
Owner
@fara
fara left a comment

Engineering review

  • Target: exler/thermopylae PR #11
  • Request: Exler's comment 625
  • Snapshot: e855460a9578c20bc649dfd49b8c9df6d02f96d7 → 64e9640347b9b8b04a49758b3e9db085cbe4c5dc
  • Scope: all 21 changed files, including generated SQL bindings, migration, tests, templates and CSS; neighboring session, CSRF, administrative mutation and OIDC/access-control paths.
  • Verdict: No blocking findings in reviewed scope.

Findings

No confirmed blocking correctness or security defect found.

[P3, non-blocking] Qualify the README's lifecycle guarantees

  • Location: README.md:59-60.
  • Trigger / consequence: an administrator authorization code issued before Start still exchanges as the administrator after Start; not every in-progress sign-in is refused. Separately, removing and restoring the target's application grant within the context's lifetime lets its unexpired credentials and new sign-ins work again without Stop/Return. This is a temporary live-access denial, not an ended context. The current wording can lead an operator to expect stronger refusal/revocation guarantees.
  • Evidence: independently reproduced both behaviors through actual handlers and SQLite using two external Go-overlay probes. The earlier-code behavior is also explicitly preserved by TestStopReturnsActorAndKillsOnlyItsCredentials. High confidence; this is documentation precision, not a demonstrated privilege escalation.
  • Minimal remedy: describe refusal for requests crossing a session rotation, distinguish already-issued ordinary codes, and reserve the explicit Return requirement for ended contexts (timeout/actor invalidation), rather than temporary target-access failures. No runtime redesign is requested.

Architecture and technical debt

The separation between the real session owner and the effective application subject is coherent. Context provenance on codes/tokens, fresh transactional authorization checks, credential rotation, and atomic audit/revocation triggers work together without introducing another service or competing application-access policy. Tests exercise real persistence, rollback, competing SQLite connections and loopback redirect chains, not only mocks.

The unpruned context/audit history is deliberate debt, not a merge blocker at the demonstrated scale. Because authorization also performs an expiry sweep, retention/indexing should be revisited when measured history size or write-lock latency warrants it; no repayment owner is established here. Migration 0006 is additive and preserves ordinary credential provenance as NULL; the older binary rejects the newer schema, so rollback requires a compatible database backup.

Verification and limitations

Independently executed in a clean detached worktree with Go 1.27.1, a credential-free test environment and cached dependencies/network package resolution disabled:

  • go test -count=1 -json ./... — exit 0; 59 top-level tests, 117 passing test/subtest events, three tested packages, no failures.
  • go vet ./... — exit 0.
  • go build -o ../thermopylae-review ./cmd/thermopylae — exit 0 (output outside source tree).
  • git diff --check e855460a9578c20bc649dfd49b8c9df6d02f96d7...HEAD — exit 0.
  • go test -overlay=../overlay.json -count=1 -v ./internal/server -run '^TestFaraReview' — exit 0; two review-only lifecycle probes passed; overlay files are outside the checkout and are not committed regression coverage.
  • go test -race ./... — exit 1 before tests could execute, due to ThreadSanitizer's unsupported VMA47/48 mapping on this ARM64 host; not a detected data race. Independently retrieved CI run 24, its exact SHA, workflow and test-job log: the linux/amd64 test job passed vet/race gates; image publication was intentionally skipped for this PR.

A subscription-backed Opus read-only source pass supplemented my independent inspection; consequential observations above were independently checked. The checkout remains clean. No source changes, commits, pushes, production access or deployment. No fresh visual/browser QA or real relying-party/production-TLS integration was performed. Existing application sessions and already-issued signed ID tokens remain subject to the documented revocation limitations. This verdict applies only to the reviewed snapshot and scope.

# Engineering review - Target: exler/thermopylae PR #11 - Request: [Exler's comment 625](https://git.marut.network/exler/thermopylae/pulls/11#issuecomment-625) - Snapshot: `e855460a9578c20bc649dfd49b8c9df6d02f96d7` → `64e9640347b9b8b04a49758b3e9db085cbe4c5dc` - Scope: all 21 changed files, including generated SQL bindings, migration, tests, templates and CSS; neighboring session, CSRF, administrative mutation and OIDC/access-control paths. - **Verdict: No blocking findings in reviewed scope.** ## Findings No confirmed blocking correctness or security defect found. ### [P3, non-blocking] Qualify the README's lifecycle guarantees - Location: `README.md:59-60`. - Trigger / consequence: an administrator authorization code issued **before** Start still exchanges as the administrator after Start; not every in-progress sign-in is refused. Separately, removing and restoring the target's application grant within the context's lifetime lets its unexpired credentials and new sign-ins work again without Stop/Return. This is a temporary live-access denial, not an ended context. The current wording can lead an operator to expect stronger refusal/revocation guarantees. - Evidence: independently reproduced both behaviors through actual handlers and SQLite using two external Go-overlay probes. The earlier-code behavior is also explicitly preserved by `TestStopReturnsActorAndKillsOnlyItsCredentials`. High confidence; this is documentation precision, not a demonstrated privilege escalation. - Minimal remedy: describe refusal for requests crossing a **session rotation**, distinguish already-issued ordinary codes, and reserve the explicit Return requirement for ended contexts (timeout/actor invalidation), rather than temporary target-access failures. No runtime redesign is requested. ## Architecture and technical debt The separation between the real session owner and the effective application subject is coherent. Context provenance on codes/tokens, fresh transactional authorization checks, credential rotation, and atomic audit/revocation triggers work together without introducing another service or competing application-access policy. Tests exercise real persistence, rollback, competing SQLite connections and loopback redirect chains, not only mocks. The unpruned context/audit history is deliberate debt, not a merge blocker at the demonstrated scale. Because authorization also performs an expiry sweep, retention/indexing should be revisited when measured history size or write-lock latency warrants it; no repayment owner is established here. Migration 0006 is additive and preserves ordinary credential provenance as NULL; the older binary rejects the newer schema, so rollback requires a compatible database backup. ## Verification and limitations Independently executed in a clean detached worktree with Go 1.27.1, a credential-free test environment and cached dependencies/network package resolution disabled: - `go test -count=1 -json ./...` — exit 0; **59 top-level tests, 117 passing test/subtest events**, three tested packages, no failures. - `go vet ./...` — exit 0. - `go build -o ../thermopylae-review ./cmd/thermopylae` — exit 0 (output outside source tree). - `git diff --check e855460a9578c20bc649dfd49b8c9df6d02f96d7...HEAD` — exit 0. - `go test -overlay=../overlay.json -count=1 -v ./internal/server -run '^TestFaraReview'` — exit 0; two review-only lifecycle probes passed; overlay files are outside the checkout and are not committed regression coverage. - `go test -race ./...` — exit 1 **before tests could execute**, due to ThreadSanitizer's unsupported VMA47/48 mapping on this ARM64 host; not a detected data race. Independently retrieved [CI run 24](https://git.marut.network/exler/thermopylae/actions/runs/24), its exact SHA, workflow and test-job log: the linux/amd64 test job passed vet/race gates; image publication was intentionally skipped for this PR. A subscription-backed Opus read-only source pass supplemented my independent inspection; consequential observations above were independently checked. The checkout remains clean. No source changes, commits, pushes, production access or deployment. No fresh visual/browser QA or real relying-party/production-TLS integration was performed. Existing application sessions and already-issued signed ID tokens remain subject to the documented revocation limitations. This verdict applies only to the reviewed snapshot and scope. <!-- fara-source-request: exler/thermopylae#11:comment:625:878eacdc42885c7f7d5fadb04e0eb0011cab43319790aaea6b3815cf9f2a92a2 -->
exler merged commit 907e8168b2 into main 2026-11-08 19:58:02 +01:00
exler deleted branch feat/admin-impersonation 2026-11-08 19:58:02 +01:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
exler/thermopylae!11
No description provided.