Karyo
Documentation/ Integration and extension

Identity for an integrating system

Karyo 2.1.1rendered at build time
On this page

What a caller must present to reach /api/v1, who can issue it, and what decides what it may do. Identity and tenancy owns silo tenancy, principal_kind and what does and does not enforce isolation; this document covers the same machinery from the outside - as a contract an integrating system has to satisfy.

1. The token contract

Karyo is a standards-based OIDC resource server (ADR 0037). An API access token must be signed with the configured algorithm (RS256 by default), carry the exact configured issuer and karyo-api audience, and contain a non-empty opaque sub. A reviewed local binding from that exact issuer and subject to an active Karyo principal is also mandatory. Karyo never substitutes email, username, azp or client_id for sub, and first use never creates an account.

The deployment selects claim paths for username, Business Unit, principal kind and tenant code (services/karyo-app/src/main/resources/application.yaml, karyo.identity.claims); there is no role claim path. The stored principal kind and affiliation are authoritative, and the two custom claims can only confirm or narrow them (rule R of ADR 0048, services/karyo-app/src/main/kotlin/com/karyo/app/auth/PrincipalSecurityIdentityAugmentor.kt, PrincipalSecurityIdentityAugmentor.resolve):

  • An absent Business Unit or principal-kind claim uses the stored value, so a provider that emits neither claim works.
  • A present Business Unit claim must equal the stored affiliation (0 means none), or the token is refused with affiliation-mismatch.
  • A principal-kind claim of business_unit_user narrows a stored operations principal to the Business Unit kind; ops on a stored Business Unit principal is refused with principal-kind-mismatch.
  • A malformed claim of either kind is refused, and a stored affiliation must be an active Business Unit.

Provider roles, groups, scopes, permissions, warehouse_id and descendant claims never add authority: the augmentor builds the identity without any token role (PrincipalSecurityIdentityAugmentor.builder).

A maintenance overlap may configure exact issuer-to-named-tenant mappings with KARYO_OIDC_ADDITIONAL_ISSUER_TENANTS. The unverified iss only chooses an already configured Quarkus validation profile. That profile still verifies its own signature, issuer, algorithm and audience, after which Karyo performs exact binding lookup. Unknown issuers and near matches fail.

There is no API key, basic authentication or shared-secret request header. Integrations obtain the normalized identity and operational choices from GET /api/v1/me; treat the UUID as identity and names as display snapshots. The HTTP contract owns that projection and the Business Unit selection header; a provider's affiliation claim is not operational context or a grant.

2. Who can mint a token

The managed Keycloak profile ships browser, administration and event-reader clients. The browser uses authorization code with PKCE. karyo-admin and karyo-backend are outbound administrative identities; they are not enrolled warehouse principals and cannot use their client identity in place of a token subject.

An integrating system needs a provider client that can obtain a signed karyo-api access token and a separately reviewed local SERVICE principal enrollment for that token's exact issuer and subject. The migration/enrollment manifest records account type, affiliation and evidence; any legacy provider roles it carries grant nothing at runtime and only propose the actions of a reviewed grant during access activation (scripts/identity_migration.py, access_preflight). The enrolled principal can do nothing until it holds a grant (§3). Rotating credentials while retaining the provider subject preserves the Karyo principal; a new subject requires an explicit new binding. Karyo does not ship a universal service credential and does not accept opaque tokens in this profile.

3. Authority is a grant, not a role

Every endpoint declares one catalogue action with @DeclaredAction, except identity self-service and public methods (libs/karyo-security/src/main/kotlin/com/karyo/security/Actions.kt, Actions). TenantFilter refuses a caller that holds the declared action nowhere with 403 action-not-granted, then scopes the request to the Business Units and Facilities where that action is granted (services/karyo-app/src/main/kotlin/com/karyo/app/auth/TenantFilter.kt, TenantFilter.populateOrganizationScope, TenantFilter.resolveGrantedScope). A principal holds an action at a node when an active grant there names a permission 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 (services/auth-service/karyo-auth-core/src/main/kotlin/com/karyo/auth/service/CurrentAccessService.kt, GrantAuthority.positions). Grants are read on every request, so a revoked grant stops the next call while the token is still valid.

The managed realm files still define realm roles, but nothing reads them. A provider role, group or scope grants nothing, and no setting maps one to an action. The actions and the profiles that hold them are listed in users, roles and permissions.

4. The integrator profile

The standard integrator profile is the grant for an integrating system that exchanges master data and orders (services/karyo-app/src/main/resources/db/migration/auth/V1214__action_catalogue.sql, V1214__action_catalogue):

integrator -> arrangement.read, inventory.read, orders.read, orders.release, orders.write,
              products.read, products.write, work.claim

It does not hold integrations.manage, which every webhook subscription and delivery route declares, so its holder cannot administer webhook subscriptions or redeliveries. A system that must manage its own subscriptions also needs a grant of the integrations profile, which holds only integrations.manage (V1214__action_catalogue.sql, V1214__action_catalogue). Both are grants an administrator makes in Karyo, not an authentication setting. Karyo ships no universal machine client: an operator must configure a provider client with the API audience, enroll its exact service-account subject as described in §2, and grant it a profile at the Company, a Business Unit or a Facility.

5. X-Correlation-Id and the journal

Send X-Correlation-Id on a sequence of related requests and query the journal with the same value: GET /api/v1/journals?correlationId=<value> returns the rows those requests wrote. The journal response shows the value in each row's correlationId, and the value is an exact match, not a prefix.

Karyo takes the header like this:

  • It labels rows that have no correlation of their own. A stock adjustment, a transfer, a stock creation, a deletion, and a batch release of reservations made without a business reference all take the header of the request that wrote them.
  • It never replaces a correlation the operation sets on purpose. A row keeps the pick order number (PickOrderService.coverWithFollowUps), the order number (OrderService, DefaultStockPicker.pickStock) or the cross-dock key "cross-dock:{orderNumber}" (DefaultCrossDockOrdersPort) that its operation sets. Query by that business reference to find those rows, for example correlationId=<order number>.
  • A request without a usable header leaves the row as it was. A header that is blank or longer than 100 characters (the width of the correlation_id column) is ignored, not refused. A reservation or single release made with the default tag keeps "stock-reserver" whatever the header says; a batch release with no header carries the same tag. Other unlabelled rows carry no correlation. Rows written outside a request, such as the scheduled purge, never carry a header.
  • Karyo does not generate an id. The caller chooses the value and its uniqueness.

The journal records stock movements only. The header is also in the logging context (ADR 0026), but a container log lives only in the host's journal, for as long as the host retains it, and nothing ships it off the host (see Operating an installation); the journal row stays in the database. With tracing disabled in both profiles, the journal is the correlation mechanism there is (ADR 0025).