Skip to content

Authorise every Party operation by its own policy: commands need the write scope, Retrieve queries the read scope (roadmap 1.15) - #135

Merged
KsiProgramming merged 2 commits into
mainfrom
plan/1.15-party-authorisation-policies
Nov 9, 2026
Merged

KsiProgramming merged 2 commits into
mainfrom
plan/1.15-party-authorisation-policies

Conversation

@KsiProgramming

Copy link
Copy Markdown
Owner

Roadmap phase

Phase: 1.15 Authorisation policies
Planning package: specs/2026-11-09-party-authorisation-policies/

Closes #40

Summary

Each Party Reference Data Directory operation now has its own authorisation policy. This meets the quality bar's "authorised per BIAN operation" and the 1.15 follow-ups left by ADR 0019 and ADR 0022.

Scopes (CQRS split)

  • The 8 commands need party-reference-data-directory:write: Register, Update, Demographics Update and Exchange, Reference Update, Associations Register and Update, and BankRelations Update.
  • The 5 queries need party-reference-data-directory:read: the Retrieve operations.
  • A token without the scope gets 403 shared.forbidden Problem Details. On a command this comes before the Idempotency-Key 400 and the If-Match 428, so nothing is stored. On a query it comes before the 404, so a caller without the read scope cannot probe which records exist.
  • No commands, queries, handlers or read models change.

How it is wired

  • Each policy is named by its BIAN operation id. A context's host module registers its operations through a new IServiceDomainModule.AddOperationPolicies, with AddCommand(id, WriteScope) or AddQuery(id, ReadScope). The registrations build an OperationPolicyCatalog, and registering an operation twice stops the host.
  • Every BIAN endpoint calls RequireOperation(OperationId) from the root of RimBank.Api. It names the endpoint, requires the policy and declares the 403.
  • OperationScopeAuthorization checks the space-separated scope claim with an exact, case-sensitive match. Its name avoids the Handler suffix, because Wolverine treats …Handler types in the host as message handlers.

MCP

  • The protected-resource metadata lists the scopes in scopes_supported.
  • The tools of 1.16 will carry the same policy names.

Dev realm

  • Both dev clients get both scopes by default.
  • Keycloak drops its built-in client scopes when a realm import lists its own. Verified against Keycloak 26.6: user tokens then lose sub, and openid profile email is refused. So the realm also declares:
    • basic, holding only the sub mapper;
    • profile and email, with no claims, so tokens carry no personal data.
  • An existing local setup must remove the rimbank-keycloak-data volume to import the new realm.

ADRs and docs

  • New: ADR 0038.
  • Amended: ADR 0014 (fourth module member), ADR 0019 and ADR 0022 (follow-ups done).
  • Updated: tech-stack §6 and §10, and CONTRIBUTING "Authentication".

Definition of done

  • Working code that follows tech-stack.md (naming, dependency rules, business-only names in core)
  • Commands and queries kept separate as described in tech-stack.md §8: commands go through decisions and return acknowledgements, queries read only from read models. The write scope guards commands and the read scope guards queries. Nothing else in the command or query paths changes.
  • Unit tests for domain and application logic, including a projection test (Given events → Then view) for every new or changed read model, plus integration tests (Testcontainers) for any adapter touched. No domain logic or read model changed. The host tests and the Testcontainers tests on the real host cover the new behaviour.
  • Every new or changed read model can be rebuilt from the context's own event store. N/A: no read model is new or changed.
  • Contexts stay loosely coupled as described in tech-stack.md §8.4: no shared or cross-context read models, and no cross-context references except .Subscriptions → .PublishedLanguage. Each context owns its own scopes.
  • Architecture tests green
  • Every new error path returns RFC 9457 Problem Details (on both HTTP and MCP). The 403 is shared.forbidden from the existing status-code pages. The MCP tool path comes with the tools in 1.16.
  • Every new BIAN operation exposed over HTTP is also exposed as an MCP tool, with a parity test. N/A: no new BIAN operation. Tools and their policies come in 1.16/1.17.
  • GitHub Actions CI green (build, test, format, CodeQL)
  • An ADR in docs/adr/ for any significant or BIAN-interpretation decision (ADR 0038)
  • The roadmap checkbox ticked in the same PR

Validation

  • dotnet restore RimBank.slnx --locked-mode: OK, no lock file changes.
  • dotnet build RimBank.slnx -c Release: 0 warnings, 0 errors.
  • dotnet test --solution RimBank.slnx -c Release --no-build: 2070 passed, 0 failed, 0 skipped.
  • dotnet format RimBank.slnx --verify-no-changes: exit 0.

New tests:

  • RimBank.Host.Tests Security/OperationPolicyTests:
    • an exact scope is allowed, including inside a list of scopes;
    • no scope, the other kind's scope, a prefix, a longer scope and another case all get 403 shared.forbidden;
    • no token gets 401 before any 403;
    • the catalog is right;
    • an operation registered twice stops the host;
    • a scope with whitespace is refused.
  • RimBank.Host.Tests Mcp/McpAuthorizationTests: scopes_supported lists the policy scopes, and the list is empty when no module registers a policy.
  • RimBank.Api.Tests Party/…/AuthorisationTests (Testcontainers), for all 13 operations:
    • a token with only the other kind's scope gets 403 before the 400, 428 and 404, with no stream and no idempotency outcome stored;
    • a token with no scope gets 403;
    • no token gets 401;
    • end to end, the write scope alone registers and the read scope alone retrieves.
  • RimBank.Api.Tests OperationAuthorizationCoverageTests (the guard):
    • every named endpoint carries the policy named by its operation;
    • GET is a query on the read scope, and every other verb a command on the write scope;
    • every policy protects an endpoint;
    • the context has 8 commands and 5 queries.
  • RimBank.AppHost.Tests Model/DevRealmTests:
    • the dev clients' default scopes;
    • the operation scopes are written into the token;
    • basic holds the sub mapper only, and profile and email have no mappers.
  • OpenApiDocumentTests now expects the declared 403.

Manual check, beyond validation.md: I imported the realm into a throwaway Keycloak 26.6.

  • A rimbank-dev-client client-credentials token carries sub, azp, aud=rimbank-api and both scopes.
  • A rimbank-mcp-client user token, requested with no scope or with openid profile email, carries sub, both scopes and no profile or email claims.

Review focus

  • Scope granularity: one read and one write scope per context, and one policy per operation so that a later phase can split a scope without touching endpoints. Is per-context the right grain before Current Account (4.14 adds the money-moving scope)?
  • Policy names are operation ids (Associations/Register, …). They share the host-wide namespace of endpoint names, and a clash stops the host at startup. Should they carry the service domain as a prefix now?
  • Realm client scopes: the realm declares basic, profile and email itself. roles, web-origins, acr, address and phone are gone, and offline_access is refused for the dev user, so MCP clients sign in again when the token expires.
  • Changes from the plan: the module member takes a dedicated OperationPolicies registration, not AuthorizationBuilder. No OpenAPI security requirement was added. Both are recorded in the requirements file.

🤖 Generated with Claude Code

KsiProgramming and others added 2 commits November 9, 2026 11:04
… write scopes for Party Reference Data Directory

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…write scope, Retrieve queries the read scope (roadmap 1.15)

- One policy per BIAN operation, named by its operation id and registered by the
  context's host module (AddOperationPolicies: AddCommand / AddQuery); endpoints
  use RequireOperation(OperationId).
- Scopes party-reference-data-directory:read and :write, checked exactly in the
  space-separated scope claim; 403 shared.forbidden before idempotency,
  If-Match and 404 checks.
- MCP protected-resource metadata lists scopes_supported.
- Dev realm declares the operation scopes plus basic (sub), profile and email
  (no claims), verified against Keycloak 26.6.
- ADR 0038; ADR 0014, 0019 and 0022, tech-stack and CONTRIBUTING updated.

Closes #40

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@KsiProgramming KsiProgramming added stage:1 Roadmap Stage 1: Party Reference Data Directory (first vertical slice) type:feature New business or platform behaviour area:security Authentication, authorisation, PII, threat model context:party Party / Party Reference Data Directory labels Nov 9, 2026
@KsiProgramming KsiProgramming self-assigned this Nov 9, 2026
@KsiProgramming
KsiProgramming merged commit 9a8017d into main Nov 9, 2026
0 of 3 checks passed
@KsiProgramming
KsiProgramming deleted the plan/1.15-party-authorisation-policies branch November 10, 2026 16:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:security Authentication, authorisation, PII, threat model context:party Party / Party Reference Data Directory stage:1 Roadmap Stage 1: Party Reference Data Directory (first vertical slice) type:feature New business or platform behaviour

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1.15 Authorisation policies

1 participant