Documentation/ Decision records
ADR 0034: Karyo authenticates to Loci with a client-credentials token
Status: Accepted. Supersedes in part ADR 0031 (the advice call sent with no credentials).
Context
Loci validates bearer tokens from any standard OIDC provider. On Atlas that provider is Authentik. Karyo's server-side calls to Loci must therefore carry a machine token from the same provider, obtained with the OAuth client-credentials grant. ADR 0037 changes inbound Karyo identity independently; outbound Loci credentials are never rebound to a Karyo principal.
Two constraints bind the change:
- An unset token URL means Karyo sends no credential, which only an unauthenticated Loci on a private network accepts. A library client that requires a URL would fail boot when that URL is unset, which the SRCFG00040 rule forbids.
- The token is fetched server-side. A goods-owner administrator must not be able to redirect Karyo's credential, so the token settings are environment-only and never catalogue keys.
Decision
- The grant is standard
client_credentialswithclient_secret_post.LociTokenSourcepostsgrant_type,client_idandclient_secretas a form, andscopeonly when one is set. Nothing in it is specific to a provider. For Authentik the secret isbase64(<service account>:<app password>)and the scope isprofile; for a confidential client the secret is that client's own and the scope stays empty. - The token is cached until 30 seconds before it expires. The client pins HTTP/1.1 and
follows no redirects, as the advice call does.
LociClientsendsAuthorization: Bearerwhen a token is supplied and omits the header when the token URL is unset. - A rejected token is retried once.
SlottingServiceinvalidates the cache on a401and calls Loci exactly once more. A second401, a403, or any other failure is returned as it is. Both401and403are502slotting-engine-unavailable. The messages name the variables or theloci-recommendrole, and never the URL, the client id or the secret. - Boot and deploy refuse an inert or weak credential. A token URL requires a non-blank
client id and secret and must be
http(s)with a host. A client id, secret or scope without a token URL is refused. The deploy validator also requires the secret to meet the 32-character credential policy and to be distinct fromOIDC_SECRET,KEYCLOAK_ADMIN_CLIENT_SECRET,DB_PASSWORDand the bootstrap password. All four unset is valid.
Consequences
- A Loci that requires authentication, given wrong variables, is a
502whose detail namesKARYO_LOCI_TOKEN_URL,KARYO_LOCI_CLIENT_IDandKARYO_LOCI_CLIENT_SECRET, shown on the Slotting page without the URL. A token that lacksloci-recommendnames that role. - An installation that leaves the four variables unset behaves as before: no credential is sent.
- The token URL, client id, secret and scope are not runtime catalogue keys. Writing them on the system-properties screen does nothing; changing them requires a restart. The base URL remains the one Loci catalogue key.
- The bearer travels to Loci over whatever network the base URL names. Where that hop is not TLS, the token is still short-lived and scoped to Loci's audience. A TLS hop is an infrastructure choice, not this decision.
Alternatives considered
- A Quarkus OIDC client, as Karyo uses for its own Keycloak admin client. Rejected: that
client fails boot when its URL is unset, which the SRCFG00040 rule forbids, and
LociClientalready pins HTTP/1.1 on the JDK client. - Two Authentik-specific variables instead of one secret. Rejected: Authentik documents
base64(<user>:<app password>)as the standard-form client secret, so one client id and one secret work for any provider. - A catalogue key for the token URL. Rejected: the fetch is server-side, and a goods-owner administrator must not be able to point Karyo's credential at another endpoint.
Evidence
services/slotting-service/karyo-slotting-core/src/main/kotlin/com/karyo/slotting/loci/LociTokenSource.kt,LociTokenSource.bearerLociTokenSource.bearer;LociTokenSource.invalidate;LociTokenSource.REFRESH_MARGIN_SECONDS, the 30-second margin
services/slotting-service/karyo-slotting-core/src/main/kotlin/com/karyo/slotting/loci/LociClient.kt,LociClient.recommendLociClient.recommend, the bearer header;LociClient.statusFailure, the401message
services/slotting-service/karyo-slotting-core/src/main/kotlin/com/karyo/slotting/service/SlottingService.kt,SlottingService.recommend- the one retry on
401
- the one retry on
services/slotting-service/karyo-slotting-core/src/main/kotlin/com/karyo/slotting/exception/SlottingException.kt,SlottingExceptionEngineUnavailable.status
services/slotting-service/karyo-slotting-core/src/main/kotlin/com/karyo/slotting/service/SlottingConfig.kt,SlottingConfig.lociTokenScope- the four keys and the boot rules
services/karyo-app/src/main/resources/application.yaml,karyo.slotting.loci- the environment mapping, empty when unsetservices/auth-service/karyo-auth-core/src/main/kotlin/com/karyo/auth/config/SystemPropertyCatalog.kt,SystemPropertyCatalog- the base URL remains the only Loci catalogue key
scripts/deploy-server.sh,validate_env (KARYO_LOCI_* checks)- the deploy rules;scripts/.env.prod.example,KARYO_LOCI_TOKEN_URL, KARYO_LOCI_CLIENT_ID, KARYO_LOCI_CLIENT_SECRET, KARYO_LOCI_TOKEN_SCOPE
Related
- ADR 0031 - Loci as the slotting engine; the no-credentials sentence this record replaces
- ADR 0033 - slotting advice requires Loci
- The engine boundaries
- The configuration boundary - the token keys are environment-only
- Deploying - the validator rules