Guarantee IAM ID on every authenticated effective-user principal

Open
#466 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
48/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
typescript

Research direction

Start by tracing UserProfileOrchestrator.EnsureUserProfileAsync and AuthenticationHelper.OnTokenValidated, then inspect SystemController.Emulate, the local login flow in AccountController, cookie validation, and WalterTargetingContextAccessor. Run the existing authentication and targeting tests to map coverage before making changes. Done means every authenticated path has one canonical effective-user IAM claim, cookies are repaired or authentication fails when it cannot be resolved, and targeting uses the claim without a database lookup; add the behavioral tests listed in the issue.

Written by the indexing model from the issue text.

Description

enhancement

Walter should guarantee that every authenticated application principal contains exactly one nonblank ucdPersonIAMID claim identifying the effective user. During emulation, that must be the emulated user's IAM ID.

Normal profile initialization already requires a resolvable IAM ID, but the resolved value is not consistently copied into the authentication cookie. Emulation and local development login also construct principals without this claim. This leaves consumers with inconsistent identity information and makes feature targeting perform a separate user lookup.

Follow-up to #465. Schedule this separately from the current feature-flag PR.

Current impact

  • UserProfileOrchestrator.EnsureUserProfileAsync resolves and persists IAM ID, while AuthenticationHelper.OnTokenValidated discards the returned profile instead of adding the resolved claim.
  • SystemController.Emulate and the local login flow in AccountController omit IAM ID when constructing their cookie principals.
  • /api/user/me reads IAM ID from the database, so the frontend and browser telemetry can still identify the user. Project access commonly uses the object ID to retrieve the stored Employee ID.
  • Backend request logging and tracing read IAM ID directly from the principal, so these sessions lose IAM attribution.
  • WalterTargetingContextAccessor compensates with a database lookup for missing claims and emulation.

Proposed change

  1. After normal profile initialization, stamp its resolved IAM ID onto the application's authenticated principal before issuing the cookie. Normalize the value and replace duplicate or conflicting IAM claims.
  2. Include the selected user's IAM ID when issuing emulation and local development cookies. Preserve the operator's separate audit identity during emulation.
  3. Extend existing cookie validation to repair missing or inconsistent IAM claims from the effective user's stored profile and renew the cookie, including when roles have not changed. Retrieve IAM alongside the existing user/role lookup rather than adding another database round trip.
  4. Simplify WalterTargetingContextAccessor to read the canonical claim. Remove its user-service dependency, database fallback, and special emulation branch. Retain a defensive missing-claim warning/off result for callers outside the authenticated application pipeline.
  5. Update authentication, telemetry, and feature-flag documentation to describe the guarantee.

Authentication behavior

A session whose IAM ID cannot be resolved must not continue as an authenticated Walter session. Return a clear authentication failure. Repair existing cookies when their stored user profile supplies the ID; a missing claim alone should not force users to sign in again.

This intentionally changes the feature-flag migration's behavior for an authenticated session without IAM: authentication will reject an unresolvable identity instead of permitting that session to use global flags. Normal profile initialization already rejects unresolved IAM IDs. Keep object IDs, Employee IDs, role-based access checks, and operator audit information distinct from IAM ID. Do not substitute another identifier or accept browser-supplied targeting identity.

Acceptance criteria

  • Normal sign-in produces one correct IAM claim whether it arrived in the validated token or was resolved through the existing profile fallback.
  • Emulation and local development login produce the effective user's IAM claim; the operator's IAM ID cannot leak into the emulated principal.
  • Existing cookies with missing, duplicate, or inconsistent IAM claims are corrected and renewed, including when roles are unchanged.
  • An unresolvable IAM ID fails authentication with a clear error; anonymous endpoints retain their existing behavior.
  • Backend logs and traces receive the effective user's IAM ID for normal, fallback, and emulated sessions, while retaining separate operator attribution.
  • Feature targeting reads only the principal and performs no identity lookup. Role and project authorization behavior remains intact.
  • Behavioral tests cover all sign-in paths, cookie migration, unresolved IAM, telemetry attribution, and IAM allowlist/exclusion evaluation after the accessor is simplified.
Dominant language
TypeScript
Stars
0
Forks
1
Avg merge
19h 34m
Merged PRs (30d)
22

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ucdavis/Walter

All issues in ucdavis/Walter

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.