ADR 0048: Karyo authorizes every call from its own grants
Status: Accepted. Supersedes the parts of ADR 0037 that let a token's roles narrow a local compatibility-role ceiling and offered role management through the identity SPI, the parts of ADR 0038 that kept coarse endpoint roles and resolved only operations.read and operations.write, and the role equality of the mirror guard in ADR 0047.
Context
Karyo already owned its principals (ADR 0037) and resolved operational scope from Company,
Business Unit and Facility grants (ADR 0038, ADR 0040). Two things still came from the identity
provider. Every endpoint was gated by a provider role with @RolesAllowed, so a provider without
Karyo's realm roles could not run Karyo, and a role mapping mistake changed what a person could
do. And the kind and Business Unit claims were mandatory: a token without principal_kind was
narrowed to the Business Unit kind and a token without the Business Unit claim was refused, so
only a provider configured with Karyo's two custom claims worked.
The captain asked for equivalent Karyo-owned authorization across APIs, background operations and UI controls, backed by isolation and revocation tests, and approved the claim rule below (option A of the design review). Karyo has no users and is unreleased, so the change converts straight to the final model with no compatibility path.
Decision
- One catalogue of actions.
Actionslists 33 action keys (for exampleinventory.read,orders.release,counts.approve,users.manage). The auth migration installs the same keys and the node types each one may be granted at: seven administration actions only at Company or Business Unit, every other action also at one Facility. - Every call declares its action. Each REST method declares one action with
@DeclaredAction, except identity self-service and public methods.TenantFilterrefuses a Karyo method that declares a scope kind but no action (500action-undeclared) and a caller that holds the action nowhere (403action-not-granted). It then resolves the readable and writable Business Units and Facilities from the nodes where that one action is granted, so an action granted in one Facility never travels to another. Every@Scheduledjob and every agent tool declares an action too; a tool's action must equal its mirrored endpoint's. - Grants are the only authority. A principal holds an action at a node when an active grant
there names a profile with that action, and the grant is admitted for the principal's kind and
affiliation: Company only for an operations principal, a Business Unit or Facility only for an
operations principal or one affiliated to that unit. Grants are read once per request, so a
revoked grant stops the next request while the token is still valid. Provider roles, groups and
scopes grant nothing; the identity SPI no longer assigns roles, and
/api/v1/mereturns the held actions instead of roles. - A target never travels either. Holding an administration or configuration action somewhere is
not enough to name any target. Company-wide targets need the endpoint's action at the Company
node: updating the Company, creating, deactivating or reactivating a Business Unit, the
consistency scan, and system properties, Home defaults and document templates of client 0. A
Business Unit target must lie in a unit the action reaches: a system property, a Home default or a
document template of unit N, and updating unit N. An operations principal holding the
Administrator profile on one unit is refused every other target with each resource's existing
denial: 422
system-property-target-forbiddenandhome-layout-target-forbidden, 403company-administration-forbidden,business-unit-administration-forbiddenanddocument-template-forbidden, and 404 for a unit it cannot reach. The console rule is unchanged: its controls check the nine administration actions as held anywhere. - Equivalence with the shipped roles. Each action is gated by exactly the roles that used to admit its endpoints. The seven standard profiles (viewer, receiver, operator, manager, administrator, integrator, integrations) are generated from that table and reproduce the shipped job roles. The same table drives the Python identity manifest and the test translation, and a parity test keeps the three equal.
- Rule R for the kind and Business Unit claims. The stored principal kind and affiliation are
authoritative. An absent claim uses the stored value. A present Business Unit claim must equal
the stored affiliation (
0means none) or the token is refusedaffiliation-mismatch. A kind claim ofownernarrows a stored operations principal to the Business Unit kind;opson a stored Business Unit principal is refusedprincipal-kind-mismatch. A malformed claim is refused as before. A provider without Karyo's custom claims therefore works, and a claim can only confirm or narrow what Karyo stored. - The console follows the same actions. The console and floor app show a control only when the selected Business Unit's actions include the action of the call it makes; the server still checks the exact Facility on every request.
Consequences
Karyo is provider neutral for authorization: any OIDC provider that proves issuer and subject works, and nothing the provider adds to a token widens Karyo authority. A role mapping can no longer be misconfigured because there is none.
Access must be granted in Karyo. An installation that relied on realm roles grants nothing until
an administrator grants profiles; the demo data must be re-granted after this change because the
retired standard-* profiles and their grants are deleted.
Resource tests that use issuer-less @TestSecurity identities still pass role names. The test
classpath translates those roles with the gate table; production supplies no translation, and a
provider token always names its issuer, so it can never take that path.
An affiliation changed in Karyo refuses a still-valid token that named the old unit, and a token that named none follows the change on its next request.
Alternatives considered
- Keep
@RolesAllowedbeside the grant check. Rejected: the captain asked to replace the provider checks, and two gates that must agree drift. - Ignore the kind and Business Unit claims entirely (option B). Not chosen: rule R keeps the claims useful as a narrowing signal at no cost to providers that omit them.
- Keep the fail-closed claim rule (option C). Rejected: it keeps Karyo dependent on two custom claims, which defeats provider neutrality.
- Map provider roles to actions at sign-in. Rejected: it keeps the provider as a source of authority and needs a mapping to administer.
Evidence
libs/karyo-security/src/main/kotlin/com/karyo/security/Actions.kt,Actions- the catalogue and@DeclaredAction.services/karyo-app/src/main/resources/db/migration/auth/V1214__action_catalogue.sql,V1214__action_catalogue- installed actions, node types and standard profiles.services/karyo-app/src/main/kotlin/com/karyo/app/auth/TenantFilter.kt,TenantFilter.declaredAction- declared action required, checked and resolved.services/auth-service/karyo-auth-core/src/main/kotlin/com/karyo/auth/service/CurrentAccessService.kt,CurrentAccessService- grant admission shared by REST and agent dispatch.services/auth-service/karyo-auth-core/src/main/kotlin/com/karyo/auth/repository/PermissionRepositories.kt,AccessGrantRepository.activePositions- one grant read per request.services/karyo-app/src/main/kotlin/com/karyo/app/auth/PrincipalSecurityIdentityAugmentor.kt,PrincipalSecurityIdentityAugmentor.resolve- rule R.services/karyo-app/src/main/kotlin/com/karyo/app/agent/AgentDispatchFilter.kt,AgentDispatchFilter.authorizeTool- the tool's action checked before conversion.scripts/identity_migration.py,ACTION_ROLES- the gate table of the identity manifest.services/karyo-app/src/test/kotlin/com/karyo/security/guards/ActionDeclarationTest.kt,ActionDeclarationTest- every endpoint, job and tool declares a catalogue action; no@RolesAllowedremains.services/karyo-app/src/test/kotlin/com/karyo/app/auth/GrantIsolationTest.kt,GrantIsolationTest- the isolation matrix and revocation with signed tokens.services/karyo-app/src/test/kotlin/com/karyo/app/auth/AdministrationTargetIsolationTest.kt,AdministrationTargetIsolationTest- a unit's Administrator against Company-wide and foreign-unit targets in all five resources, and a Company Administrator against all of them.libs/karyo-security/src/main/kotlin/com/karyo/security/TenantContext.kt,TenantContext.holdsAtCompany-holdsAtCompanyandreachesBusinessUnit, the two target checks.services/karyo-app/src/test/kotlin/com/karyo/app/auth/ClaimRuleTest.kt,ClaimRuleTest- rule R with signed tokens.services/karyo-app/src/test/kotlin/com/karyo/app/auth/OrganizationPilotTest.kt,OrganizationPilotTest- receiving to shipping by the standard profiles alone.services/karyo-app/src/test/kotlin/com/karyo/auth/OrganizationGrantResolutionTest.kt,OrganizationGrantResolutionTest- parity of the profiles, the manifest and the test translation.
Related
- ADR 0037 - principals over provider identities.
- ADR 0038 and ADR 0040 - grant-based scope and the Facility tier.
- ADR 0039 - declared scope kinds, which the action declaration sits beside.
- ADR 0047 - the agent tools, now checked by action.
- Users, roles and permissions - the actions and standard profiles in use.