feat(portal-bff): admin module + role guard + /api/admin/me self-test #127

Merged
julien merged 1 commits from feat/portal-bff-admin-module-role-guard into main 2026-05-14 01:17:31 +02:00

1 Commits

Author SHA1 Message Date
Julien Gautier c30b663c51 feat(portal-bff): admin module + role guard + /api/admin/me self-test
CI / commits (pull_request) Successful in 2m35s
CI / scan (pull_request) Successful in 2m46s
CI / check (pull_request) Successful in 3m10s
CI / a11y (pull_request) Successful in 1m29s
CI / perf (pull_request) Successful in 6m17s
Lays the foundation for the `/api/admin/*` surface per ADR-0020.
This PR ships the guard, the `@RequireAdmin()` decorator, and a
self-test endpoint — no business routes yet.

- `AdminRoleGuard` (apps/portal-bff/src/admin/admin-role.guard.ts):
  - No session → 401 (no audit; unauthenticated probes are noise).
  - Session but `roles` lacks `admin` → 403 + `admin.access_denied`
    audit row capturing actor hash, attempted route, and roles held.
  - Session with `admin` → pass through.
  - Audit-write failures propagate (no audit ⇒ no action,
    consistent with the existing call sites in AuthController).

- `@RequireAdmin()` decorator wraps `@UseGuards(AdminRoleGuard)`
  via `applyDecorators` so future composition (e.g. with the
  upcoming `@RequireMfa()` for the admin entry route) is mechanical.

- `GET /api/admin/me` returns the public user payload + `roles` for
  ops to verify the gate is wired correctly end-to-end. The handler
  intentionally has no logic beyond the projection — the value of
  the endpoint is the guard chain it forces traffic through.

- `AuditWriter.adminAccessDenied()` typed method keeps the salt
  inside the audit module and matches the pattern of the existing
  typed events. Uses the pre-existing `denied` outcome enum value.

Surface impact:
- No new env vars, no new dependencies.
- The shared portal-shell session is the auth source for this PR.
  The distinct `__Host-portal_admin_session` cookie + admin auth
  flow land in the next PR per the chantier sequence.

Tests: +11 specs (7 guard, 2 controller, 2 typed audit method).
2026-05-14 00:43:53 +02:00