Management API HTTP Basic (CLI) still signs in users whose AD groups map to no role #145

Closed
opened 2026-11-17 11:37:14 -05:00 by dohertj2 · 1 comment
Owner

Follow-up from #144, part of the NAM AD LDAP cutover (scadaproj#6, plan scadaproj/docs/plans/2026-11-15-nam-ldap-cutover.md §2A / §3 "no role, no login").

Problem

#144 (merged in d48e1667) made /auth/login, /auth/token and the cookie-session refresh refuse a user whose AD groups map to zero ScadaBridge roles. The management surfaces were left out. Their HTTP Basic login still lets that user in.

ManagementAuthenticator.AuthenticateAsync (src/ZB.MOM.WW.ScadaBridge.ManagementService/ManagementAuthenticator.cs, around lines 149–160) binds against LDAP, calls RoleMapper.MapGroupsToRolesAsync, and builds an AuthenticatedUser even when the role set is empty. Per-command authorization in ManagementActor.HandleEnvelope / GetRequiredRoles denies role-gated commands. However, every command where GetRequiredRoles returns null (open to any authenticated user) still answers a zero-role caller.

The callers are ManagementEndpoints (/management, used by the CLI), AuditEndpoints and DebugStreamHub.

Why it matters

Once NAM AD is on, any NAM user with a valid password can query ScadaBridge's read-only management surface over Basic. This includes anyone in only unrelated UG_WW_* / Citrix / plant groups, or in no family group at all. That violates the family standard (no role, no login) and undercuts #144.

Fix

  • Basic path: if the mapping yields zero roles, return the same 401 AUTH_FAILED body as a bad password, and count it as a LoginThrottle failure (as in #144). If the mapper throws, refuse in the same way, with the same status policy #144 chose.
  • Log each refusal at Warning with the endpoint, the user and the reason.
  • Bearer path (AuthenticateBearer): refuse a token whose role claim set is empty. /auth/token can no longer mint one, but tokens minted before the deploy can still exist until they expire.
  • Check that DebugStreamHub and AuditEndpoints go through the same refusal, so none of them builds its own AuthenticatedUser without it.
  • The DisableLogin dev bypass is unchanged, since it uses Roles.All.
  • Docs: extend the "No role, no login" section in docs/requirements/Component-Security.md to cover the management/CLI surfaces.

Acceptance

  • The following are tested (Basic and Bearer each) for zero roles, mapper throws and one role:
    • a /management read-only (GetRequiredRoles == null) command;
    • an audit endpoint query;
    • a DebugStreamHub connect.
  • A test fails if a null-role command is reachable by a zero-role principal.
  • The new tests fail against the current code.
  • Deploy waits for the owner's deploy hold to lift. It ships with #144 before the ScadaBridge step of the cutover (plan §7.4).
Follow-up from #144, part of the NAM AD LDAP cutover (scadaproj#6, plan `scadaproj/docs/plans/2026-11-15-nam-ldap-cutover.md` §2A / §3 "no role, no login"). ## Problem #144 (merged in `d48e1667`) made `/auth/login`, `/auth/token` and the cookie-session refresh refuse a user whose AD groups map to **zero** ScadaBridge roles. The management surfaces were left out. Their HTTP Basic login still lets that user in. `ManagementAuthenticator.AuthenticateAsync` (`src/ZB.MOM.WW.ScadaBridge.ManagementService/ManagementAuthenticator.cs`, around lines 149–160) binds against LDAP, calls `RoleMapper.MapGroupsToRolesAsync`, and builds an `AuthenticatedUser` even when the role set is empty. Per-command authorization in `ManagementActor.HandleEnvelope` / `GetRequiredRoles` denies role-gated commands. However, every command where `GetRequiredRoles` returns `null` (open to any authenticated user) still answers a zero-role caller. The callers are `ManagementEndpoints` (`/management`, used by the CLI), `AuditEndpoints` and `DebugStreamHub`. ## Why it matters Once NAM AD is on, **any** NAM user with a valid password can query ScadaBridge's read-only management surface over Basic. This includes anyone in only unrelated `UG_WW_*` / Citrix / plant groups, or in no family group at all. That violates the family standard (no role, no login) and undercuts #144. ## Fix - Basic path: if the mapping yields zero roles, return the same 401 `AUTH_FAILED` body as a bad password, and count it as a `LoginThrottle` failure (as in #144). If the mapper throws, refuse in the same way, with the same status policy #144 chose. - Log each refusal at Warning with the endpoint, the user and the reason. - Bearer path (`AuthenticateBearer`): refuse a token whose role claim set is empty. `/auth/token` can no longer mint one, but tokens minted before the deploy can still exist until they expire. - Check that `DebugStreamHub` and `AuditEndpoints` go through the same refusal, so none of them builds its own `AuthenticatedUser` without it. - The `DisableLogin` dev bypass is unchanged, since it uses `Roles.All`. - Docs: extend the "No role, no login" section in `docs/requirements/Component-Security.md` to cover the management/CLI surfaces. ## Acceptance - The following are tested (Basic and Bearer each) for zero roles, mapper throws and one role: - a `/management` read-only (`GetRequiredRoles == null`) command; - an audit endpoint query; - a `DebugStreamHub` connect. - A test fails if a `null`-role command is reachable by a zero-role principal. - The new tests fail against the current code. - Deploy waits for the owner's deploy hold to lift. It ships with #144 before the ScadaBridge step of the cutover (plan §7.4).
dohertj2 added the type:followuppriority:p1 labels 2026-11-17 11:37:14 -05:00
Author
Owner

Fixed and merged to main in 2e0ce81e (branch fix/145-management-zero-role: 1d2170a1, a5243b1e). Not deployed. Deployment is on hold by owner decision and is tracked with the cutover in scadaproj#6.

Basic: zero roles, or a throwing mapper, gets the bad-password 401 { error: "Invalid username or password.", code: "AUTH_FAILED" }. This covers /management, /api/audit/* and the DebugStreamHub connect, which aborts the connection. Each refusal counts as a LoginThrottle failure and logs a Warning naming the path, the user and the reason.

Throttle ordering: RecordSuccess now runs only after the role mapping succeeds, so a refusal no longer clears earlier failures.

Bearer: a token with no role claim gets the existing invalid-token 401. Blank role values are ignored. As with every other bearer failure, it does not count toward the throttle.

DisableLogin: unchanged, and a test pins it.

Docs: Component-Security, Component-CLI, Component-ManagementService and CLAUDE.md are updated.

Tests:

  • 58 new cases, including a theory that sends every GetRequiredRoles == null command, over Basic and Bearer, as a zero-role principal and expects 401.
  • Against the old authenticator, 47 of the 58 fail. The 11 that pass are one-role and anchor checks.
Project Passed Failed
ManagementService.Tests 836 0
CentralUI.Tests 1608 0
Security.Tests 234 0
CLI.Tests 588 0
AuthFlowTests (live GLAuth) 7 0

Other paths checked; none admit a zero-role user:

  • gRPC (node-to-node PSK) and LocalDb sync (API key);
  • the inbound API (API keys);
  • DeploymentConfigEndpoints (per-deployment token);
  • health and metrics (anonymous by design);
  • all other UI, which uses the cookie covered by #144.

Note: a CLI run that makes several Basic calls as a zero-role user adds one throttle failure per call.

Fixed and merged to `main` in `2e0ce81e` (branch `fix/145-management-zero-role`: `1d2170a1`, `a5243b1e`). **Not deployed.** Deployment is on hold by owner decision and is tracked with the cutover in scadaproj#6. **Basic:** zero roles, or a throwing mapper, gets the bad-password 401 `{ error: "Invalid username or password.", code: "AUTH_FAILED" }`. This covers `/management`, `/api/audit/*` and the `DebugStreamHub` connect, which aborts the connection. Each refusal counts as a `LoginThrottle` failure and logs a Warning naming the path, the user and the reason. **Throttle ordering:** `RecordSuccess` now runs only after the role mapping succeeds, so a refusal no longer clears earlier failures. **Bearer:** a token with no role claim gets the existing invalid-token 401. Blank role values are ignored. As with every other bearer failure, it does not count toward the throttle. **`DisableLogin`:** unchanged, and a test pins it. **Docs:** Component-Security, Component-CLI, Component-ManagementService and CLAUDE.md are updated. **Tests:** - 58 new cases, including a theory that sends every `GetRequiredRoles == null` command, over Basic and Bearer, as a zero-role principal and expects 401. - Against the old authenticator, 47 of the 58 fail. The 11 that pass are one-role and anchor checks. | Project | Passed | Failed | |---|---|---| | ManagementService.Tests | 836 | 0 | | CentralUI.Tests | 1608 | 0 | | Security.Tests | 234 | 0 | | CLI.Tests | 588 | 0 | | AuthFlowTests (live GLAuth) | 7 | 0 | **Other paths checked; none admit a zero-role user:** - gRPC (node-to-node PSK) and LocalDb sync (API key); - the inbound API (API keys); - `DeploymentConfigEndpoints` (per-deployment token); - health and metrics (anonymous by design); - all other UI, which uses the cookie covered by #144. **Note:** a CLI run that makes several Basic calls as a zero-role user adds one throttle failure per call.
Sign in to join this conversation.