ADR-0014: A service identity that is not a user, for machine-to-machine project exports
Date: 2026-11-19
Relates to: DEV-7936, ADR-0013 (the Policy ADT this extends),
modules/jwt (EdDsaJwt), slice/security/ServiceTokenVerifier.scala and TrustedServiceKeys.scala,
slice/api/v3/V3BaseEndpoint.scala (token routing), slice/api/v3/projects/V3ProjectsRestService.scala and
ExportServiceAudit.scala (ownership and audit), slice/export/domain/TaskCreator.scala, the Identity & Access
context (docs/contexts/identity-access/CONTEXT.md), the project migration endpoints
(project-migration.md).
Status
Proposed
Context
dsp-repository's nightly sync must export full project data from any dsp-api server. Every export route requires a SystemAdmin user's token, and no machine credential exists. The HS256 secret that signs user tokens cannot be handed out: whoever holds it mints SystemAdmin tokens for every user on that server. A SystemAdmin service account per server was ruled out too: it would need an account on each server, and a SystemAdmin can do everything, not just exports.
What the sync needs is narrow: trigger an export of a project, poll it, download the zip, delete it. It must not see or touch anything else, including other callers' exports in the server-wide export slot.
Decision
-
A service identity is not a user. A trusted service is named by a
ServiceName(lower-case letters, digits, hyphens) and authenticates with an Ed25519-signed JWT (alg: EdDSA, RFC 8037) that it mints for itself with its own private key. dsp-api holds public keys only and never signs a service token. No user is looked up, and the token'ssubis never read as a user IRI. -
Off by default; keys come from configuration.
app.service-identity.trusted-keys(environment variableKNORA_WEBAPI_SERVICE_IDENTITY_TRUSTED_KEYS) holds a JSON array of{name, kid, publicKey}, wherepublicKeyis the base64 X.509 SubjectPublicKeyInfo of an Ed25519 key, with or without PEM armour. The default[]trusts no key; an empty or blank value means the same, because a declared but unset variable renders as"". A malformed array, an unparsable or non-Ed25519 key, a blankkid, an invalid name or a duplicatekidfails startup with a message naming the entry index and field, never key material. Several keys may share a name, so a service can rotate with an overlap. At startup one INFO line lists the number of keys with their names andkids. The setting is parsed inTrustedServiceKeys(slice/security), not inAppConfig's validation chain, which would make the configuration component depend on security. -
The token contract. Header
algexactlyEdDSAand akidnaming a configured key;critis rejected andjku,jwk,x5u,x5care ignored. Each part is unpadded base64url; the signature is 64 bytes, checked over the receivedheader.payload. Claims:issandsubboth equal the key's name, so a key cannot claim another service's name;aud(a string or an array) contains this server's external base URL;iat,expand a non-blankjtiare present;exp - iatis at most 15 minutes, with no leeway; the token is current within 30 seconds of leeway (now < exp + 30 s,iat <= now + 30 s).audis compared after normalisation on both sides: lower-case scheme and host, the scheme's default port and a trailing slash dropped, anything beyond scheme, host and port matching nothing. A server configured ashttps, hostapi.dasch.swiss, port 443 thus acceptsaud: "https://api.dasch.swiss".nbfis not checked; the lifetime cap bounds the token. Bearer only. -
One policy, routed by the header. A new
Policy.SystemAdminOrExportService(decision 4 of ADR-0013) admits active SystemAdmins and trusted export services. Its factoryBaseEndpoints.bearerSystemAdminOrServicePolicyEndpointsets the policy; the routing functionV3BaseEndpoint.systemAdminOrExportServicePolicypeeks at the unverified header. Whenalgis exactlyEdDSAthe token goes toServiceTokenVerifierand never reaches the user authenticator; otherwise the user path runs and the user must be a SystemAdmin. The handler receives anExportCaller:Admin(user)orService(principal). Every other endpoint rejects a service token with 401, because the HS256 decoder cannot verify an EdDSA signature; ingest included. Only that routing function callsServiceTokenVerifier. -
What a service may do. Only the four project export endpoints use the new policy: trigger, status, download and delete. Imports and data imports stay
SystemAdmin. There is no server-side project allowlist: a service may export any project. -
A service sees only the exports it created. An export's creator is a
TaskCreator, a user IRI or a service name. In the task file and inDataTaskStatusResponse.createdByit is one string: the user IRI as before, orurn:dsp:service:<name>; task files written by earlier versions load unchanged. Status, download and delete look the export up by id alone (never resolving the project, see DEV-6766), then check ownership before any state check or deletion. A service asking for an export it did not create gets404 export_not_found, the answer for an unknown id, so it cannot read, download or delete it, nor learn its state. Ownership is keyed on the service name, never thekid, so an export survives a key rotation. SystemAdmins keep access to every export. The rule lives inV3ProjectsRestService(findExportandmayAccess); theExportCallermatches there are exhaustive. -
An occupied slot. The export slot is server-wide. When a service triggers an export while the slot holds any export, its own or anyone else's, it gets
409 export_existswith that export's id and project, exactly as a SystemAdmin does. There is no separate code that hides the occupant: exporting is reserved for SystemAdmins and trusted services, so telling a service another caller's export id and project is not a leak worth one. With its own export in the slot, the service recovers after a crash by polling, deleting and triggering again. When the export is not its own, its status answers404(rule 6), and the client is told to give up for this run and retry on the next one, never loop. -
Every service call is audited. Each export call by a service writes exactly one INFO line when it ends, whether it succeeded, failed, died or was interrupted:
Export service call: action=export.status outcome=not_owner service=dsp-repository kid=dsp-repository-2026-11 project_iri=<the export's project> requested_project_iri=<the path value> export_id=<id> jti="<jti>"(one line in the log).
actionisexport.create,export.status,export.downloadorexport.delete;outcomeisok,not_owner,not_found,conflictorerror, so operators can tell an ownership refusal from an unknown id although the client gets the same 404.project_iriis the export's project when the export was found, else the requested one;requested_project_iriis always the path value. An unknown field is-;export_idis-only on a trigger that created none.jtiis the only freely chosen value, so it comes last, quoted, cut to 256 characters, with control, line-separator and format characters replaced. The same calls set four bounded span attributes on the server span:dsp.service.name,dsp.service.kid,dsp.service.actionanddsp.project.shortcodefrom the resolved project on trigger or the service's own export otherwise. No IRI,jtior export id becomes an attribute, because spanmetrics can turn attributes into labels. SystemAdmin calls are logged as before and get no service attributes. -
Rejected service tokens are logged. Each rejection writes one WARN line
Service token rejected: reason=<category> kid=<kid or ->. The categories:disabled(no key configured, checked first),bad_signature(the token fails as a JWS: a malformed part,crit, bad encoding or signature),unknown_kid(also a missingkid),bad_claims(issorsubnot the key's name;iat,exporjtimissing;expbeforeiat;iatmore than 30 seconds ahead),bad_audience,lifetime_too_long,expired. Thekidis logged only once it matched a configured key; the token is never logged. The client always gets the same401 Invalid token.. A token whose header does not parse or whosealgis not exactlyEdDSAnever reaches the verifier: it takes the user path and gets401with no such line. Rate limiting stays with the reverse proxy. -
The export format is unchanged. A service receives the same zip as a SystemAdmin, password hashes included by design.
Consequences
Exposure of a leaked key. A leaked private key exports any project in full, password hashes included, on every server that trusts its public key, until the key is removed from that server's configuration. No project allowlist narrows this, so the audit log is the only after-the-fact control. The key never leaves the service, and dsp-api holds no secret that could leak it. Removing a key takes effect only when each server restarts without it, and exports belong to the name, so after a leak the operator also deletes the exports the name still holds and reviews the audit log since the leak.
The configuration is the trust root. Whoever can change KNORA_WEBAPI_SERVICE_IDENTITY_TRUSTED_KEYS can grant
export of every project, the equivalent of a SystemAdmin credential. The E2E tests trust a key whose private half
is committed to the repository; it must never be added to a real server, and nothing but review prevents that.
Replay. jti is logged, not checked: a captured token can be replayed until it expires, at most 15 minutes
after iat plus 30 seconds of leeway. The client is asked to set exp five minutes after iat. aud limits replay
to one server only as long as servers have distinct external base URLs.
Limits of the audit. A download is logged when its response stream starts, so a download cut off mid-stream is
still ok. error covers both defects and interruptions such as a client disconnect. A call whose path fails to
decode (a malformed project IRI or export id) never reaches the handler and writes no audit line; only the
server's request log sees it.
Information a service can still learn. On trigger, an unknown project IRI answers 404 project_not_found, a
known one 202 or 409, so a service can tell existing project IRIs from unknown ones. That follows from having no
project allowlist. Ownership by name assumes one operator per service name: two services given the same name in
the configuration share their exports. A service, or anyone holding its key, can keep the server-wide export slot
occupied with its own exports and so lock out every other caller until a SystemAdmin deletes them.
Rollback. A dsp-api version from before this decision cannot decode a task file whose creator is
urn:dsp:service:<name> and drops it as corrupt, leaving the export directory to be cleaned by hand.
What enforces the rules. The policy is declared and checked like every ADR-0013 policy; the four export
endpoints stay in the exempt list of V3SystemAdminRoutesE2ESpec, and ExportServiceIdentityE2ESpec covers them
with a service token. The rest rests on tests and review:
- Only
V3BaseEndpoint's routing function callsServiceTokenVerifier. Nothing stops another slice from injecting it throughSecurityModule; review does. - Ownership is enforced in
V3ProjectsRestService, whileProjectMigrationExportService.getExportStatus,downloadExportanddeleteExporttake a bare export id. A new handler on the export policy that skippedfindExport, or the audit wrapper, would compile. TheV3ProjectsRestServicetests pin today's four handlers. A structural guard, such as a proof of ownership that those methods require, is not built. - A new
ExportCallercase must extendcreatorOfandmayAccess; both matches are exhaustive, so the compiler names them.
Open points.
- Log level of rejected tokens. Every rejection is logged at WARN. Anyone can send a token with
alg: EdDSAand so write one WARN line per request, also when no key is configured (disabled). The alternative is a lower level fordisabled,unknown_kidandbad_signature, the rejections before the sender is shown to hold a key, or sampling. - Location of
ServiceName. It lives inslice/common/domain, so the export domain can use it without depending onslice/security. The alternative isslice/security, which would avoid an edge from security into the shared kernel that the modularization dissolves. - Verifier and ownership guards. The single caller of
ServiceTokenVerifierand the ownership check are enforced by review and tests only. A test that fails when a new file referencesServiceTokenVerifierorEdDsaJwt.verify, and an ownership proof that the export service's methods require, would raise both to a check.
Alternatives rejected
- HS256 with a per-server shared secret. The cheapest shape, reusing
JwtCodec, but the secret mints SystemAdmin user tokens on that server, and every server would need its own client secret. - A SystemAdmin service account per server. An account on each server, and a SystemAdmin can do everything.
- The JWT
scopeclaim on user tokens. Still a user, and ADR-0013 keeps scope apart from authorization. - A JWT library (jwt-scala, nimbus). The JDK verifies Ed25519 natively (JEP 339) and
modules/jwtis the leaf for JWT mechanics; a library would add dependencies to every image for about a hundred lines. - A JSON object for a service creator in
createdBy. It would break the response's string type and the generated OpenAPI client; a second optional field would leavecreatedBymeaningless for service tasks.