Files
Heimdall/skills/heimdall-identity/SKILL.md
T
arnaud.dartois 91816fbf29
Heimdall Gitea / Detect CI scope (push) Successful in 4s
Heimdall Gitea / Build and tests (push) Skipped
Heimdall Gitea / Build and scan server image (push) Skipped
Heimdall Gitea / Build and scan agent image (push) Skipped
Heimdall Gitea / Build and scan NVIDIA Agent image (push) Skipped
Heimdall Gitea / Publish versioned installer release (push) Skipped
Heimdall Gitea / CI policy (push) Successful in 1s
docs: align specification role summaries with identity (#396)
Co-authored-by: Arnaud Dartois <admin@tordais.cc>
2026-11-13 12:07:01 +01:00

9.7 KiB

name, description
name description
heimdall-identity Implement and review Heimdall account, password, session, email confirmation, lockout, and two-factor authentication flows built on ASP.NET Core Identity.

Heimdall Identity workflow

Read AGENTS.md, the focused Gitea issue and the Gitea ticket workflow, and the Identity wiring in Infrastructure/DependencyInjection.cs and Web/Program.cs before changing authentication.

When maintaining docs/auth-roles.md or identity summaries in docs/specs.md, verify their role names and default permission summaries against Infrastructure/Security/AppPermissions.cs and Domain/Enums/UserRole.cs. Heimdall has Admin, Supervisor, and Viewer; site/camera access is separately enforced through resource-access services, not represented by a generic User role. Keep the authentication summary in docs/README.md aligned with that guide and model.

Verify identity model examples against Infrastructure/Identity/IdentityAppUser.cs, Domain/Entities/UserSite.cs, and Infrastructure/Data/Configurations/UserSiteConfiguration.cs. Keep ASP.NET Identity in Infrastructure; UserSite stores the user ID without an Identity navigation, and Infrastructure maps that foreign key.

Before documenting UI/API authorization examples in docs/auth-roles.md, verify referenced pages, methods, policies, and routes against Components/Routes.razor, the page components, controllers, and ResourceAccess. Do not preserve generic authorization snippets that reference services or callbacks absent from the application; distinguish page authentication from API resource filtering.

  • Identity owns password hashing, normalized account lookup, role membership, lockout, authenticator tokens, and email/password tokens. Do not duplicate password or token cryptography in Heimdall.
  • Keep ASP.NET Core Identity packages and types inside Infrastructure. Domain must not reference Identity; Application uses IIdentityAccountService and IdentityAccount only. Put Identity EF entities (IdentityAppUser, IdentityAppRole) and UserManager/RoleManager adapters in Infrastructure. Keep user-related Domain relationships keyed by Guid UserId; configure their foreign keys to the Infrastructure user entity.
  • When creating an Identity user, copy the generated SecurityStamp back into the application account before building the first session/JWT. Cover bootstrap and regular user creation with a relational session validation test.
  • Moving Identity model classes without changing tables should produce an explicit empty EF migration and a snapshot containing the Infrastructure entity types. Verify migration compatibility against PostgreSQL before release.
  • Keep bootstrap one-time and PostgreSQL-serializable. Anonymous registration stays disabled after bootstrap; role and account creation failures must not be reported as success.
  • Keep public login/reset responses generic so they do not reveal account existence, lockout state, or Identity policy details. Logs must not contain emails, passwords, tokens, authenticator keys, recovery codes, or Identity error descriptions; log safe error codes only when needed.
  • Rotate SecurityStamp after password changes/resets, email or role changes, lock/unlock, and 2FA changes. Verify existing cookies, JWTs, and refresh tokens are rejected after the change.
  • Cookie principal validation runs on every authenticated HTTP request. Keep it asynchronous and use AccountSessionPolicy.IsValidLiveAsync with IIdentityAccountService.GetSessionRecordAsync plus an IApplicationDbContext projection; this bypasses Identity's tracked-user cache and avoids repeated UserManager database round trips while preserving fresh security-stamp, lockout, and email-confirmation checks. Do not replace it with claims-only validation.
  • The Blazor cookie bridge runs through heimdallAuth.signIn → POST /_auth/signin. Have JavaScript return only the HTTP status code (or 0 for a network failure); classify JSDisconnectedException separately from non-2xx responses. Log only the failure stage, HTTP status, or exception type—never exception messages, emails, user IDs, access tokens, cookies, or request bodies. Return generic public errors from the endpoint. Integration coverage should verify a successful 2FA response can create a usable cookie and that malformed tokens reveal no validation details.
  • For cookie failures reported after 2FA, inspect only sanitized event breadcrumbs around the JS bridge; distinguish a circuit/WebSocket disconnect from a /_auth/signin HTTP rejection, and do not infer cookie serialization failure when the event has no exception. Keep a Playwright E2E path that submits an authenticator code through /login, observes the real HttpOnly auth cookie, and proves that cookie authorizes /api/users/me; remove the temporary Identity account in finally.
  • Enroll an authenticator in two steps: create/show the setup key while 2FA remains disabled; renew the user's access token and cookie after Identity rotates the security stamp; verify a TOTP code before enabling 2FA and creating one-time recovery codes. Persist only hashes of recovery codes, redeem each atomically once, and clear them when 2FA is disabled.
  • Check every IdentityResult before proceeding. Avoid partial account creation; clean up the created user if role assignment fails.
  • Keep first-account provisioning on /setup → /api/auth/bootstrap-admin; later accounts and role assignment use /users → /api/users. Do not reintroduce a second Admin-registration endpoint.
  • Keep the three supported role names seeded by Identity. Seed their default permission claims once using a durable role-claim marker; the Admin permission set stays immutable. Manage Supervisor/Viewer permission claims from /admin/claims, then include those persisted claims in login, refresh, cookie, and 2FA auth responses.
  • When role membership or role permissions change, rotate every affected user's security stamp and record the acting administrator in the audit log. Protect last-admin demotion, deletion, and lockout based on unlocked Admin accounts.
  • Apply [Collection("E2E")] on each concrete Playwright test class deriving from E2ETestBase; xUnit does not reliably inherit the PostgreSQL fixture attribute from its abstract base.
  • Configure Identity options explicitly and review changes to password, unique email, confirmed email, lockout, cookie, token-provider, and Data Protection behavior.
  • CI installs Chromium through the Playwright CLI already copied beside the Release E2E test assembly (node tests/Heimdall.E2E.Tests/bin/Release/net10.0/.playwright/package/cli.js install --with-deps chromium). This keeps browser tooling on the test project's locked Playwright dependency graph and avoids an independently restored C# script project.
  • Keep PostgreSQL-specific transaction and concurrency guarantees in Infrastructure. Use relational integration tests for bootstrap races, recovery-code redemption, session revocation, and migration compatibility.
  • For cookie session validation changes, prove a freshly issued cookie succeeds before account mutation and fails afterward for lockout, role/security-stamp, email, and password changes. Treat GlitchTip blocking warnings as hypotheses: inspect the full async stack and do not claim a synchronous block solely from the warning title.
  • For behavior changes, update FR/EN resources and UI/API contracts, add focused tests, update the Gitea issue, and run the disposable Compose acceptance recipe with unique credentials, ports, volumes, project name, and network.
  • Acceptance must exercise bootstrap through the setup UI, user lifecycle and role editing through /users, permission editing through /admin/claims, and verify the resulting JWT/API allow and deny decisions. Check that stale sessions fail after a role/permission change and that the last usable Admin cannot be demoted, deleted, or locked.
  • For account-creation password regressions, cover the real /users dialog for Viewer and Supervisor with the role selected both before and after password entry. Confirm the new account's email through the admin row action, then authenticate through /api/auth/login using the exact synthetic password entered in the form; assert only the status/token presence and never log the password. Keep this as a Playwright E2E test under the E2E collection.
  • The disposable Compose recipe defaults to the account-creation path; HEIMDALL_ACCEPTANCE_FLOW=2fa-cookie runs the complete authenticator challenge → /_auth/signin → cookie-authorized /api/users/me path. Each invocation uses a unique project, generated PostgreSQL/JWT credentials, a free loopback port, and a project-specific Central image tag. Build from the checkout and wait for /healthz; the separate Playwright E2E test covers the real browser UI bridge. Teardown only that Compose project and verify its containers, volumes, and network are gone; remove and verify absence of the exact Central tag while retaining PostgreSQL and other shared base images.
  • Record a project-unique tag for each source-built Central acceptance image and install an EXIT cleanup trap before build/start. After scoped Compose teardown, verify zero containers/volumes/networks and remove/verify absence of each exact local tag even on failure. Keep shared upstream base images, preserve test exit status, report cleanup failures, and avoid --rmi all or broad image-prune commands.

Useful official references: ASP.NET Core Identity configuration, Two-factor authentication, and Data Protection.