Files
Heimdall/skills/heimdall-identity/SKILL.md
T
arnaud.dartois 89c4c43922
Heimdall Gitea / Detect CI scope (push) Successful in 7s
Heimdall Gitea / Build and tests (push) Successful in 14m48s
Heimdall Gitea / Publish versioned release (push) Skipped
Heimdall Gitea / Build and scan server image (push) Successful in 4m27s
Heimdall Gitea / Build and scan agent image (push) Successful in 15m42s
Heimdall Gitea / Publish Docker Hub latest tags (push) Successful in 1m27s
Heimdall Gitea / CI policy (push) Successful in 2s
fix(identity): harden user lifecycle and permissions (#136)
Co-authored-by: Arnaud Dartois <admin@tordais.cc>
2026-11-04 13:33:30 +01:00

5.1 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 AUTH-BOOTSTRAP entry in todo.md, and the Identity wiring in Infrastructure/DependencyInjection.cs and Web/Program.cs before changing authentication.

  • 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.
  • 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 behavior changes, update FR/EN resources and UI/API contracts, add focused tests, update todo.md, 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.

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