↑↓ to navigate Enter to open "…" all these words ANDOR to combine

Architecture Decision Record

ADR-140: Machine Clients Through OAuth Client Credentials Backed by Service Accounts

Status

Accepted (2026-11-08). Ships in MMCA.Common v1.281.0. Off unless the host calls AddMachineClients, registers its own IServiceAccountProvisioner and sets MachineClients:Enabled (MMCA.Common/Source/Core/MMCA.Common.Application/Auth/MachineClients/MachineClientSettings.cs:35-36, default false). Amended 2026-11-12: MMCA.ADC is the first consumer to carry machine clients, switched off in its production configuration as passkeys are (ADR-139); MMCA.Common's [RefuseMachineClients] keeps machine clients off the endpoints where a person takes part, and ADC declares it on eight controllers (see Consequences). Revised 2026-11-23: the service-account refusal behind every interactive path now sits in the private IssueTokensCoreAsync, and the revocation marker is written for the longer of the machine token and the host's access-token lifetime plus the 5-minute bearer clock skew (20 minutes at least); anchors refreshed after v1.315.0.

Context

Only a person could obtain a token: every token-issuing path in the framework is an interactive sign-in. A program (a nightly sync, a partner's server, a server-side MCP client) had no way to call a host's APIs or its permissioned MCP tools, and access tokens last 15 minutes (ADR-138, point 7), so pasting a person's token into a program works for minutes.

Four forces shaped the decision:

  • Every service already validates the same tokens. Identity signs RS256 and every service validates through JWKS (ADR-004). A credential that ended in an ordinary access token would need no new validation path in any service or the gateway.
  • Audit, ownership and rate limiting key on an integer user id. Audit stamps and ownership rules read the token's sub, and the per-user rate-limit partition is the caller's user id (MMCA.Common/Source/Presentation/MMCA.Common.API/Startup/WebApplicationBuilderExtensions.RateLimiting.cs:183-186). A caller that is not a user id breaks all three.
  • Common has no user entity. The user row is the app's (ADR-116); IAuthUser is a narrow contract (MMCA.Common/Source/Core/MMCA.Common.Domain/Auth/IAuthUser.cs), so creating an account is the app's job.
  • Revocation already has a cross-service mechanism. Deleting an account writes a soft-deleted marker every service reads, so SoftDeletedUserMiddleware rejects that user's outstanding tokens (ADR-047; MMCA.Common/Source/Core/MMCA.Common.Application/Auth/SoftDeletedUserCache.cs:41, :73-74).

Decision

A program authenticates with the OAuth 2.0 client credentials grant and receives a short-lived access token for its own service-account user. Permissions come from that user's role, revocation writes the soft-deleted marker, and a role that could escalate can never back a client.

  1. Each client is backed one to one by its own service-account user. The consumer implements IServiceAccountProvisioner over its own user aggregate: CreateAsync(name, role) creates a user with that role and no password and returns its id, and FindAsync(userId) returns a ServiceAccount or null when the account is gone, locked or not a service account (MMCA.Common/Source/Core/MMCA.Common.Application/Auth/MachineClients/IServiceAccountProvisioner.cs:15-34), the ADR-116 consumer-supplied-store shape. IAuthUser.IsServiceAccount is a defaulted member (false), so an app that never adopts machine clients implements nothing (IAuthUser.cs:25-33).
  2. A service account never signs in interactively. Password login (MMCA.Common/Source/Core/MMCA.Common.Application/Auth/AuthenticationServiceBase.cs:197-209, through CanSignInWithPassword at :938-939), sign-in links (:564-570) and passkeys (:609-615) refuse it, and the private IssueTokensCoreAsync refuses it as the backstop behind every interactive path (:725-735): the framework's own sign-in paths mint through it directly, and the protected IssueTokensAsync that app-level flows such as external login call skips the second-factor challenge for a service account and delegates to it (:691-713). View-as refuses it as a target through ViewAsSubject.IsServiceAccount (MMCA.Common/Source/Core/MMCA.Common.Application/Auth/ViewAs/ViewAsService.cs:177-181).
  3. One call registers it, and two checks catch a half-configuration. services.AddMachineClients(configuration) binds the MachineClients section with ValidateOnStart and registers the EF client store and IMachineClientService (MMCA.Common/Source/Core/MMCA.Common.Infrastructure/DependencyInjection.MachineClients.cs:37-53). The settings validator fails an enabled host that has no IServiceAccountProvisioner (MMCA.Common/Source/Core/MMCA.Common.Infrastructure/Auth/MachineClients/MachineClientSettingsValidator.cs:37-40), and the startup tripwire fails MachineClients:Enabled true without the call (MMCA.Common/Source/Core/MMCA.Common.Infrastructure/Configuration/CloudAdapterTripwire.cs:44-49, :71-75).
  4. The token endpoint is its own controller base. MachineTokenControllerBase (the app's sealed subclass routes it at auth/token) serves one anonymous POST on the auth-ip policy, form encoded with grant_type=client_credentials, the client authenticating with HTTP Basic or with client_id and client_secret form fields, and answers RFC 6749 JSON (access_token, token_type, expires_in) or invalid_client (401) / unsupported_grant_type / invalid_request (400), both with Cache-Control: no-store; it answers 404 while machine clients are off (MMCA.Common/Source/Presentation/MMCA.Common.API/Controllers/MachineClients/MachineTokenControllerBase.cs:16-76, :115-131). It is a base of its own rather than an action on AuthControllerBase, which every consumer already inherits, so a consumer that does not adopt machine clients gets no new route and no change to its committed OpenAPI documents.
  5. The token is a person-shaped token for the service account. MachineClientService.IssueTokenAsync checks the secret, reads the account through the provisioner on every mint, and mints through the raw ITokenService.GenerateShortLivedAccessToken, the view-as precedent, with client_id and token_use=machine added (MMCA.Common/Source/Core/MMCA.Common.Application/Auth/MachineClients/MachineClientService.cs:66-120; MMCA.Common/Source/Core/MMCA.Common.Shared/Auth/AuthClaimTypes.cs:134, :140, :146). The token's sub is the service account and its permission claims are the role's, baked in exactly as for a person (MMCA.Common/Source/Core/MMCA.Common.Infrastructure/Auth/TokenService.cs:118-128, :159-171). It carries no refresh token, no session (sid), no auth_time and no mfa (MachineClientService.cs:14-21), so an IRequiresMfa use case refuses it with no special case.
  6. The lifetime is capped below the revocation marker. MachineClients:AccessTokenMinutes defaults to 15 and is validated from 1 to 15 (MachineClientSettings.cs:24-33, :42; MachineClientSettingsValidator.cs:23-27). The soft-deleted marker lives at least 20 minutes (SoftDeletedUserCache.cs:41), and revoke writes it through MarkerDurationFor, which covers the longer of the machine token's lifetime and the host's access-token lifetime plus the 5-minute bearer clock skew and never drops below those 20 minutes (SoftDeletedUserCache.cs:51-55; MachineClientService.cs:230-234). A 15-minute token therefore always lapses while the marker still exists; a longer token would outlive the revocation that is meant to stop it (MachineClientSettings.cs:27-33).
  7. Secrets are random, hashed and rotatable. A secret is 32 random bytes shown once, stored as SHA-256 and compared in constant time (MMCA.Common/Source/Core/MMCA.Common.Domain/Auth/MachineClients/MachineClientSecret.cs:18-41). Rotate issues a secondary secret beside the primary, promote retires the old primary, and both honor an optional expiry (MMCA.Common/Source/Core/MMCA.Common.Domain/Auth/MachineClients/MachineClient.cs:109, :130, :150).
  8. Revocation reuses the soft-deleted marker. RevokeAsync saves RevokedOn first, so no new token is minted, then writes the soft-deleted marker for the service account, so every service's SoftDeletedUserMiddleware answers 401 to the tokens the client already holds, for the marker lifetime point 6 gives (MachineClientService.cs:211-237).
  9. Four permissions can never back a client. A role granting any of them is refused at create, before the service account is provisioned, and at every mint, because a role can gain a permission after the client exists (MachineClientService.cs:47-58, :95-101, :141-149, :250-254):
    • users:view-as (AdministrationPermissions.ViewAsUsers): a program holding it could read as any user, which ADR-137 reserves for a named staff member giving a reason;
    • users:manage (ManageUsers): it could lock, re-role or administer people's accounts;
    • roles:manage (ManageRoles): it could grant its own role anything, the three above included;
    • clients:manage (ManageClients): it could mint further clients, and fresh secrets, for itself (MMCA.Common/Source/Core/MMCA.Common.Shared/Auth/Permissions/AdministrationPermissions.cs:18-40).
  10. Administration is a separate, permissioned base. MachineClientsControllerBase (abstract, no route, [HasPermission(clients:manage)]) lists, creates (the secret returned once), rotates, promotes and revokes (MMCA.Common/Source/Presentation/MMCA.Common.API/Controllers/MachineClients/MachineClientsControllerBase.cs:38-39, :48, :68, :93, :115, :140), and a routeless Common.UI page sits over it (AddMachineClientAdministrationUI, MMCA.Common/Source/Presentation/MMCA.Common.UI/DependencyInjection.cs:360).
  11. The table is gated. MachineClients is mapped only where enabled (MMCA.Common/Source/Core/MMCA.Common.Infrastructure/Persistence/DbContexts/ApplicationDbContext.cs:164-169, :440, :540-545, :1127-1132), and DesignTimeDbContextOptions.EnableMachineClients opens the gate for dotnet ef (MMCA.Common/Source/Core/MMCA.Common.Infrastructure/Persistence/DbContexts/Design/DesignTimeDbContextOptions.cs:143).
  12. MCP needs no change. A permissioned MCP tool checks the same perm: policy as [HasPermission] through the host's bearer handler (ADR-138, point 4), and a machine token is such a bearer token with the role's permission claims, so server-to-server MCP callers are admitted with no MCP code.

Rationale

  • A service account keeps one id space. Audit stamps, ownership and the rate-limit partition all key on an integer user id; a client principal of its own would need a second id space in each, and a client id and a user id would collide.
  • Client credentials is the standard grant for this caller, and an RFC 6749 response is what every OAuth library a program already uses expects.
  • No new validation path. The result is an ordinary RS256 access token, validated by every service and the gateway exactly as today.
  • Revocation reuses a marker every service already reads, instead of a per-request lookup against Identity's store.
  • The refused permissions are the escalation paths. A program's blast radius is its role; denying the four permissions that widen a role, mint clients or act as a person keeps it there.

Trade-offs

  • Turning it on needs consumer code: the provisioner, the IsServiceAccount answer on the app's user type and the view-as resolver flag (MMCA.Common/UPGRADING.md:529-542). MMCA.ADC is the first consumer to carry that code (see Consequences).
  • A machine identity is a user row. It shows up wherever the app lists users unless the app filters on IsServiceAccount.
  • Revocation takes effect through the marker's cache. Outstanding tokens are refused within the soft-deleted check's window, not instantly, and the check fails open on a cache or validator error (ADR-047).
  • No refresh token. A program asks for a new token when one expires; at 15 minutes this is one request per quarter hour per program.
  • One more migration on the Identity database where enabled.

Alternatives rejected

  • API keys (2026-11-08). Every service would need a lookup against Identity's store on each request, a second validation path beside JWKS.
  • A separate client principal type (2026-11-08). Audit and ownership key on an integer user id, and a second id space would collide with it.
  • Putting the token action on AuthControllerBase (2026-11-08). Every consumer inherits that base, so every consumer's OpenAPI documents would change for a feature none of them has turned on.
  • Refresh tokens for clients (2026-11-08). A program holds its secret already; a refresh token adds a second long-lived credential and a session row for nothing.
  • An OAuth 2.1 authorization server with consent screens and dynamic client registration (2026-11-08). Still deferred, as ADR-138 records. Revisit: a third-party MCP client that needs delegated user consent.

Consequences

  • A consumer that opts in implements the provisioner, calls AddMachineClients, adds the MachineClients migration on its Identity database, routes the two controller subclasses, and grants clients:manage to an operator role that no client can hold (MMCA.Common/UPGRADING.md:529-542).
  • MMCA.ADC is the first consumer to carry machine clients. Its Identity service calls AddMachineClients (MMCA.ADC/Source/Services/MMCA.ADC.Identity.Service/Program.cs:196-203), and it carries the feature switched off in production configuration, exactly as it carries passkeys (ADR-139): the service's base appsettings.json sets MachineClients:Enabled false with AccessTokenMinutes 15 (MMCA.ADC/Source/Services/MMCA.ADC.Identity.Service/appsettings.json:140-152, Enabled at :149), so auth/token and every Admin/MachineClients route answer 404 there. Only local development turns it on: appsettings.Development.json (MMCA.ADC/Source/Services/MMCA.ADC.Identity.Service/appsettings.Development.json:36-41) and the AppHost's MachineClients__Enabled (MMCA.ADC/Source/Hosting/MMCA.ADC.AppHost/Program.cs:481-485). Nothing under MMCA.ADC/infra/ or MMCA.ADC/.github/ names the feature (no match for "machine client" in either). The Identity design-time factory still sets EnableMachineClients, so the schema carries the MachineClients table either way (MMCA.ADC/Source/Hosting/MMCA.ADC.Migrations.SqlServer.Identity/DesignTimeSQLServerDbContextFactory.cs:52-57). ServiceAccountProvisioner implements the provisioner over ADC's own User (MMCA.ADC/Source/Modules/Identity/MMCA.ADC.Identity.Application/Users/Administration/ServiceAccountProvisioner.cs:25-52), creating the account through User.CreateServiceAccount, which raises no registration event, accepts any valid ADC role and sets IsServiceAccount (MMCA.ADC/Source/Modules/Identity/MMCA.ADC.Identity.Domain/Users/User.cs:341-377). The cross-module attendee-id query does not count a service account: it admits an Attendee-role user only when it is not a service account (MMCA.ADC/Source/Modules/Identity/MMCA.ADC.Identity.Application/Users/AttendeeQueryService.cs:24).
  • In ADC the token endpoint is a sealed MachineTokenControllerBase subclass routed at auth/token (MMCA.ADC/Source/Modules/Identity/MMCA.ADC.Identity.API/Controllers/MachineClients/MachineTokenController.cs:18-20), and the gateway routes /Auth/token on the auth-tight policy, as it does login and register (MMCA.ADC/Source/Hosts/MMCA.ADC.Gateway/appsettings.json:104-111). Administration is a sealed MachineClientsControllerBase subclass routed at Admin/MachineClients (MMCA.ADC/Source/Modules/Identity/MMCA.ADC.Identity.API/Controllers/MachineClients/AdminMachineClientsController.cs:18-20), and ADC grants clients:manage to Organizer and no other role (MMCA.ADC/Source/Modules/Identity/MMCA.ADC.Identity.Shared/Authorization/IdentityPermissionGrants.cs:20, :43-49), which IdentityPermissionGrantsTests pins (MMCA.ADC/Tests/Modules/Identity/MMCA.ADC.Identity.Shared.Tests/Authorization/IdentityPermissionGrantsTests.cs:24-34, :39). The Organizer-only page at /users/machine-clients renders the framework's MachineClientAdmin (MMCA.ADC/Source/Modules/Identity/MMCA.ADC.Identity.UI/Pages/Users/MachineClients.razor:1-2, :11), reached from an Organizer-only Admin menu entry that also requires clients:manage (MMCA.ADC/Source/Modules/Identity/MMCA.ADC.Identity.UI/IdentityUIModule.cs:44). The entry and the page stay with the feature off: the framework's MachineClientAdmin then renders one "not enabled" notice in place of the create form and the list, because its list load answers not found (MMCA.Common/Source/Presentation/MMCA.Common.UI/Pages/Administration/MachineClientAdmin.razor.cs:56-61; MMCA.Common/Source/Presentation/MMCA.Common.UI/Pages/Administration/MachineClientAdmin.razor:7-13; MMCA.Common/CHANGELOG.md:565). The AddMachineClients migration adds Identity.User.IsServiceAccount (default false), creates the MachineClients table and a unique index on ServiceAccountUserId filtered to undeleted rows (MMCA.ADC/Source/Hosting/MMCA.ADC.Migrations.SqlServer.Identity/Migrations/20261112192549_AddMachineClients.cs:14-55).
  • Endpoints where a person takes part refuse machine clients. A machine client holds what its backing role holds, so an endpoint that asks only for a signed-in caller (casting a vote, saving a bookmark, checking in) is open to every machine client whatever role backs it. Choosing the backing role cannot close that, and the framework refuses only the four permissions of point 9 while ADC's factory takes any valid role (User.cs:363), so the endpoint itself has to say its caller is a person. MMCA.Common's [RefuseMachineClients] is that statement: an authorization filter for a controller or an action that answers 403 with the error code MachineClients.EndpointRefused to a request whose token carries token_use = machine and lets every other caller through; declared on a controller it covers every action, the permission-gated ones included, and it adds nothing to the API description (MMCA.Common/Source/Presentation/MMCA.Common.API/Authorization/RefuseMachineClientsAttribute.cs:13-37, check at :44-49; MMCA.Common/CHANGELOG.md:526). ADC declares it at class level on eight controllers: Engagement's BookmarksController, CheckInsController, LivePollVotingController, PointsController, SessionQuestionsController and TicketsController (MMCA.ADC/Source/Modules/Engagement/MMCA.ADC.Engagement.API/Controllers/BookmarksController.cs:36, CheckInsController.cs:41, LivePollVotingController.cs:36, PointsController.cs:36, SessionQuestionsController.cs:38, TicketsController.cs:41), and Conference's SessionQuestionAnswersController and EventQuestionAnswersController (MMCA.ADC/Source/Modules/Conference/MMCA.ADC.Conference.API/Controllers/Sessions/SessionQuestionAnswersController.cs:81, MMCA.ADC/Source/Modules/Conference/MMCA.ADC.Conference.API/Controllers/Events/EventQuestionAnswersController.cs:81). MachineClientParticipationTests pins the classification: every concrete Engagement controller is either one of the six participation controllers carrying the attribute or on an allow-list with a reason, and the two Conference controllers carry it (MMCA.ADC/Tests/Architecture/MMCA.ADC.Architecture.Tests/Api/MachineClientParticipationTests.cs:38-54, allow-list at :62-73, classification fact at :90-91). This settles whether an Attendee-backed machine client may earn points or check in: it may not.
  • Accepted limit: the attribute is declared at class level, so it also refuses a machine client on the organizer actions inside those eight controllers (RefuseMachineClientsAttribute.cs:28-30).
  • Precondition for turning machine clients on in a production environment: creating a machine client does not require a recent interactive sign-in (no step-up, as passkey registration requires through auth_time).
  • Machine activity is audited under a named service account.
  • The Enterprise-scale register of the Common backlog no longer holds client credentials; webhooks and versioned OpenAPI with Sunset stay there.

Revision (2026-11-23)

Re-verified against current source. The decision is unchanged: client credentials over a service-account user, the four refused permissions, the 15-minute cap, the gated table and ADC's eight [RefuseMachineClients] controllers all hold. Two descriptions moved with the code, and most anchors moved with later releases through v1.315.0.

  1. The interactive-path backstop is the issuance core. The service-account refusal sits in the private IssueTokensCoreAsync (MMCA.Common/Source/Core/MMCA.Common.Application/Auth/AuthenticationServiceBase.cs:725-735), which the framework's own sign-in paths call directly; the protected IssueTokensAsync that app-level flows call skips the second-factor challenge for a service account and delegates to it (:691-713). Point 2 now says so.
  2. The revocation marker can outlast 20 minutes. RevokeAsync writes the marker through SoftDeletedUserCache.MarkerDurationFor, sized to the longer of the machine token's lifetime and the host's access-token lifetime plus the bearer clock skew, with 20 minutes as the floor (MMCA.Common/Source/Core/MMCA.Common.Application/Auth/MachineClients/MachineClientService.cs:230-234; MMCA.Common/Source/Core/MMCA.Common.Application/Auth/SoftDeletedUserCache.cs:41, :51-55). Points 6 and 8 now say so.
  3. Anchors re-verified against current source: AuthenticationServiceBase.cs:197-209, :938-939, :564-570, :609-615; ViewAsService.cs:177-181; SoftDeletedUserCache.cs:41, :73-74; AuthClaimTypes.cs:134, :140, :146; MachineClientService.cs:211-237, :250-254; MachineClientsControllerBase.cs:38-39, :48, :68, :93, :115, :140; MMCA.Common.UI/DependencyInjection.cs:360; ApplicationDbContext.cs:164-169, :440, :540-545, :1127-1132; MMCA.Common/UPGRADING.md:529-542; MMCA.Common/CHANGELOG.md:526, :565; in MMCA.ADC, MMCA.ADC.Identity.Service/Program.cs:196-203, MMCA.ADC.AppHost/Program.cs:481-485, DesignTimeSQLServerDbContextFactory.cs:52-57, User.cs:341-377 (role check at :363), IdentityUIModule.cs:44, BookmarksController.cs:36, CheckInsController.cs:41, and both Conference answer controllers at :81.

ADR-004 (the JWKS validation every service already does), ADR-020 (the role-to-permission registry the token carries), ADR-047 (the marker revocation reuses), ADR-116 (the consumer-supplied-store shape), ADR-137 (the view-as permission a client can never hold), ADR-138 (the permissioned tools a machine token now reaches), ADR-139 (the other identity opt-in of this release).