KIDA: identity
KIDA is Ngamia’s identity engine. It answers one question: which KIDA user, in which workspace, is making this request? It answers it once, when a trusted service exchanges a person’s sign-in token, and returns a short-lived signed token. Other services then check that token locally against KIDA’s public keys.
KIDA is private. In the deployment, only its public keys and discovery document are reachable from the internet.
What KIDA owns
| Concern | Owner |
|---|---|
| Passwords, MFA, passkeys, Google sign-in, recovery, provider sessions | Camel Accounts |
| KIDA user ID, workspaces (tenants), membership, identity audit, KIDA signing keys | KIDA |
| Member roles, invites, API keys, what a person may do in a workspace | The platform (PLATFORM/) |
| What a user may do with a resource (runs, tools, memory, documents) | Each engine |
KIDA has no sign-in UI. It is not an OAuth authorization-code broker. A model-gateway key is never an identity credential and is never sent to KIDA.
Role in the platform
- People sign in at Camel Accounts (
https://accounts.camelcreatives.com), an OIDC provider. The agent builder signs people in with its own public PKCE client,ngamia-agent-web; the platform API owns the callback. - The platform is KIDA’s trusted caller
ngamia-platform. It may request appplatformand holds the capabilitiesissue_identity_tokenandprovision_tenant.deploy/bin/init-secrets.shwrites this registry entry. - The platform sends the person’s Camel token to KIDA. KIDA verifies it, checks membership, and returns a KIDA access token with audience
ngamia-platformand appplatform. People use that token as their platform bearer. The platform verifies it against KIDA’s JWKS on every request. - Workspace = KIDA tenant. A workspace ID is its KIDA tenant UUID. The same ID scopes the workspace’s data in every engine.
- Sign-up calls KIDA
POST /v1/tenantsto create the tenant with the person as owner. Joining by invite callsPOST /v1/tenants/{tenant_id}/membersafter the platform has checked the invite code. - KIDA owns who belongs to which workspace. The platform keeps each member’s role, and treats a member it removed as removed even if the KIDA membership still exists.
What KIDA checks on every exchange:
- The caller is allowed this app and operation.
- The Camel token: RS256,
typ=JWT, exact issuer, exact audience for the requested app, expiry (30 s skew), knownkid. - Camel
/oauth/userinfostill accepts the token and returns the samesub. - (Camel issuer,
sub) maps to a KIDA user with an active membership in the tenant. - An audit event is written. If the audit write fails, no token is issued.
Access token contract
The token is kida-access-token-v1 (KIDA/contracts/kida-access-token-v1.md).
| Header | Value |
|---|---|
alg | RS256 (the only accepted algorithm) |
typ | JWT |
kid | Must name exactly one key in KIDA’s JWKS (kty=RSA, use=sig, alg=RS256) |
| Claim | Meaning |
|---|---|
iss | KIDA issuer (KIDA_ISSUER, HTTPS, no trailing slash). In the deployment: https://api.ngamia.com/identity |
sub | KIDA user UUID. Never the Camel subject |
aud | Target service, from KIDA’s token-audience map. The platform’s is ngamia-platform |
iat | Issue time (Unix seconds) |
exp | Expiry (Unix seconds), see lifetime below |
jti | Unique token UUID. There is no replay store: a token is reusable until it expires |
app_id | KIDA app the token was issued for (platform in the deployment) |
tenant_id | KIDA tenant (workspace) UUID. Membership was active at issue |
auth_time | When the person signed in at the provider |
assurance | basic, multi_factor or hardware_bound. Always basic for Camel Accounts |
All claims are required. Consumers reject unknown claims, so adding, removing or renaming a claim is a breaking change. The token never carries the provider issuer or subject, email, name, roles or permissions.
Lifetime. KIDA_TOKEN_TTL_SECONDS sets the lifetime (60 to 900 s, default 300; the deployment compose file sets 900).
The issued exp is also capped by the verification result, which kida-server limits to 300 s, and by the remaining life of the Camel token.
Audience comes from KIDA’s configuration. A caller picks an app_id; KIDA looks up the audience in KIDA_TOKEN_AUDIENCES_FILE. A caller cannot choose an arbitrary audience.
Validation. Consumers fetch keys from <issuer>/.well-known/jwks.json. In the deployment that is https://api.ngamia.com/identity/.well-known/jwks.json. Consumers refresh the JWKS periodically and on an unknown kid.
HTTP surface
“Protected” routes need Authorization: Bearer <caller credential> and must arrive from a trusted peer (see below). The capability column is the one the caller registry must grant.
| Method | Path | Who may call | Purpose |
|---|---|---|---|
GET | /health/live | Anyone who can reach KIDA | Process liveness. Returns {"status":"alive"} |
GET | /health/ready | Anyone who can reach KIDA | Readiness (store). 200 ready, 503 not ready |
GET | /.well-known/kida-configuration | Public | issuer, jwks_uri, token_endpoint, token_profile, signing_algorithms |
GET | /.well-known/jwks.json | Public | KIDA’s public signing keys (current and any still-valid previous keys) |
POST | /v1/tokens/exchange | Caller with issue_identity_token for the app | Verify a Camel token and membership; return a KIDA access token |
POST | /v1/authentication/verify | Caller with verify_identity | Verify evidence and return a short-lived principal. Not a signed token |
POST | /v1/tenants | Caller with provision_tenant | Sign-up: create a tenant with the person as owner and issue their token |
POST | /v1/tenants/{tenant_id}/members | Caller with provision_tenant | Add the person as a member (already a member is fine) and issue their token |
POST | /v1/memberships | Caller with provision_tenant | List the person’s active workspaces |
POST | /mcp | Caller with verify_identity | MCP over Streamable HTTP with one tool, verify_identity |
The exchange and well-known routes exist only when a token issuer is configured. The three enrollment routes exist only when enrollment is enabled, which kida-server always does.
In the deployment, Caddy forwards only /identity/.well-known/* to KIDA and answers 404 for every other /identity/* path.
The caller API, /mcp and /health/* are reachable only inside the stack. The token_endpoint in the discovery document is therefore not usable from the internet.
Request bodies
Exchange and verify take:
{ "contract_version": 1, "app_id": "platform", "tenant_id": "<tenant UUID>",
"correlation_id": "<UUID>", "evidence_type": "oidc.jwt", "evidence": "<Camel access token>" }The three enrollment routes take the same body without tenant_id. POST /v1/tenants also needs name (1 to 128 characters). Unknown fields are rejected.
Responses
| Route | Success | Rejected evidence |
|---|---|---|
/v1/tokens/exchange | 200 {"outcome":"authenticated","token":{access_token, token_type, expires_in, principal}} | 200 {"outcome":"rejected","reason_code","correlation_id"} |
/v1/tenants | 201 {tenant_id, tenant_name, exchange} | 401 {"outcome":"rejected",...} |
/v1/tenants/{tenant_id}/members | 200 {tenant_id, exchange} | 401 {"outcome":"rejected",...} |
/v1/memberships | 200 {"memberships":[{tenant_id, tenant_name, role, user_id}]} | 401 {"outcome":"rejected",...} |
exchange has the same shape as the /v1/tokens/exchange response.
Reason codes are invalid_evidence, evidence_expired, evidence_unsupported, identity_unmapped, identity_ambiguous, identity_disabled, context_mismatch, verifier_unavailable and indeterminate.
Other errors use {"error":{"code","message"}}:
| Status | Codes |
|---|---|
400 | invalid_request, unsupported_contract_version |
401 | unauthorized (missing, malformed or unknown caller credential) |
403 | untrusted_transport_peer, forbidden (caller lacks the app or capability) |
404 | not_found, tenant_not_found |
409 | conflict |
503 | overloaded, caller_auth_unavailable, authorization_unavailable, audit_unavailable, directory_unavailable, token_issuance_unavailable |
504 | request_timeout |
Server limits: 64 KiB request bodies, 10 s per protected request, 8 KiB evidence, 8 KiB Authorization header.
Callers and trusted peers
Caller registry
KIDA_CALLERS_FILE lists every service allowed to call KIDA:
{ "callers": [ {
"id": "ngamia-platform",
"credential_sha256": ["<64 lowercase hex>"],
"apps": ["platform"],
"capabilities": ["issue_identity_token", "provision_tenant"]
} ] }- Only SHA-256 hashes are stored, so the file is not itself a secret. Presented credentials are compared against every hash in constant time.
- A caller may list several hashes, so a credential can be rotated without downtime.
- Capabilities are
verify_identity,issue_identity_tokenandprovision_tenant. - Startup fails if the file is empty, has unknown fields, a duplicate caller ID or credential hash, a caller with no apps or no capabilities, or an app with no token audience.
- Caller IDs are 1 to 128 characters of letters, digits,
.,_or-. - Generate entries with
kida-admin new-caller-credential <caller-id>.
Trusted peers
Protected routes and /mcp check the TCP peer address before anything else:
- Development: only loopback peers are accepted.
- Production: only the exact IPs in
KIDA_TRUSTED_PROXY_IPSare accepted. There are no ranges. Any other peer gets403 untrusted_transport_peer.
In the deployment compose file, the list is 172.31.250.10,172.31.250.11: Caddy and the platform.
The health and well-known routes do not check the peer.
Configuration
kida-server reads its configuration from the environment.
| Variable | Meaning |
|---|---|
KIDA_RUN_MODE | development (default) or production. Production enables the checks listed below |
KIDA_BIND | Listen address. Default 127.0.0.1:8095; the image and deployment use 0.0.0.0:8095 |
KIDA_ISSUER | Issuer put in tokens and pinned by every consumer. HTTPS in production, no trailing slash |
KIDA_TRUSTED_PROXY_IPS | Comma-separated exact peer IPs. Required in production |
KIDA_MCP_ALLOWED_HOSTS | Comma-separated host names accepted on /mcp. Required in production |
KIDA_STORE | sqlite (development default) or postgres (production default and only allowed value) |
KIDA_DATABASE_PATH | SQLite file (development only) |
KIDA_DATABASE_URL_FILE | File holding the PostgreSQL URL. Production requires sslmode=verify-full |
KIDA_DATABASE_URL | PostgreSQL URL in the environment. Accepted, but prefer the file |
KIDA_DATABASE_MAX_CONNECTIONS | Pool size per replica. Default 16 |
KIDA_RUN_MIGRATIONS | true (default) or false. Set false in production; startup then fails if the schema is behind |
KIDA_SIGNING_KEY_ID | kid of the active signing key |
KIDA_SIGNING_PRIVATE_KEY_FILE | RSA private key, PEM. 3072 bits recommended |
KIDA_SIGNING_PUBLIC_JWKS_FILE | Published JWKS: the active key plus previous keys still in use. Each kid must be unique |
KIDA_TOKEN_AUDIENCES_FILE | Map of app ID to token audience, for example {"platform": "ngamia-platform"} |
KIDA_PROVIDER_CONFIG_FILE | OIDC provider profile (Camel Accounts). Every token app needs a provider audience here |
KIDA_CALLERS_FILE | Caller registry |
KIDA_TOKEN_TTL_SECONDS | Token lifetime, 60 to 900. Default 300 |
KIDA_MAX_CONCURRENT_REQUESTS | Protected requests in flight per replica. Default 64. Beyond it: 503 overloaded |
KIDA_CALLER_ID, KIDA_CALLER_CREDENTIAL_FILE and KIDA_DEFAULT_APP_ID are retired. Setting any of them stops startup with a migration message.
The provider profile sets issuer, audiences (KIDA app ID to Camel client ID), allowed_algorithms, token_type, check_userinfo, request_timeout_seconds, jwks_cache_ttl_seconds and clock_skew_seconds.
In the deployment it maps platform to ngamia-agent-web (deploy/kida/provider.json).
Production startup refuses: SQLite; a database URL without sslmode=verify-full; a non-HTTPS issuer; secret files readable by group or others; check_userinfo: false; a signing key that does not match its published key; a JWKS with a missing or duplicate kid; callers listing apps with no token audience; loopback-only TLS mode; an empty MCP host list.
KIDA also needs outbound HTTPS to Camel Accounts at startup. A discovery mismatch or outage stops startup.
Operations
The full runbook is KIDA/docs/OPERATIONS.md.
Admin CLI
kida-admin uses the same store settings as kida-server (KIDA_RUN_MODE, KIDA_STORE, KIDA_DATABASE_*). Database credentials never go on the command line.
| Command | Effect |
|---|---|
kida-admin migrate | Apply pending migrations under a lock. No-op when current |
kida-admin create-tenant <name> <actor-id> | Create a tenant. Prints TENANT_ID= |
kida-admin assign-member <tenant-id> <provider-subject> <owner|member> <actor-id> | Add a membership. Prints KIDA_USER_ID= |
kida-admin revoke-member <tenant-id> <provider-subject> <actor-id> | Remove a membership |
kida-admin suspend-tenant|activate-tenant|delete-tenant <tenant-id> <actor-id> | Change tenant status |
kida-admin new-caller-credential <caller-id> | Print a new random credential and the registry entry with its hash |
assign-member and revoke-member read the provider issuer from KIDA_PROVIDER_CONFIG_FILE. The provider subject is the person’s Camel user ID (the token sub).
Migrations
Migrations are additive and tracked in kida_schema_migrations. An advisory lock serializes them, so replicas can start together.
In production set KIDA_RUN_MIGRATIONS=false and run kida-admin migrate as a release step. The deployment does this with the one-off kida-migrate service, which runs before kida.
Signing-key rotation
Rotate every 90 days, or immediately on suspicion:
- Generate a new key (for example
kida-YYYY-MM) and append its public key to the JWKS, keeping the current key. - Deploy the new JWKS with the old
KIDA_SIGNING_KEY_ID. Wait at least the consumers’ JWKS refresh interval. - Switch
KIDA_SIGNING_KEY_IDand the private key file to the new key and redeploy. - After the token lifetime plus clock skew (at least 10 minutes), remove the old public key and redeploy. Destroy the old private key.
If the key is exposed, publish a JWKS with only the new key and redeploy all replicas at once.
Caller credential rotation
Run kida-admin new-caller-credential <id>, append the new hash to that caller’s credential_sha256, redeploy KIDA, update the caller’s secret, then remove the old hash and redeploy. Both credentials work during the overlap.
Health and monitoring
- Probe
GET /health/readyfrom the orchestrator; it checks the database.GET /health/liveis process liveness only. - KIDA writes one JSON line per event to stderr:
http_request(method, path, status, duration),kida_started,startup_failed,shutdown_requested,kida_stopped. Request lines never contain headers, bodies or tokens. kida_startedlists the callers, apps, store andsigning_key_id. Check it after each deploy.- SIGTERM drains in-flight requests before stopping.
- Audit tables:
identity_events(every exchange and verification outcome, with reason codes, no tokens) andtenant_audit_events(every workspace and membership change with its operator).
Security properties
- Audience is the boundary with Camel. Camel signs tokens for every client with the same issuer and key, including its admin tokens. KIDA accepts only tokens whose audience is a configured Ngamia client.
- Userinfo recheck. Production requires
check_userinfo: true, so a revoked Camel token fails at the next exchange. - No provider identifiers leak. KIDA tokens carry the KIDA user UUID, never the Camel
sub. - Fail closed. No audit record means no token. If Camel is unavailable, exchanges fail with
verifier_unavailable. - Caller credentials are stored only as SHA-256 hashes and compared in constant time. Each caller is limited to its own apps and capabilities.
- Transport. Protected routes accept only exact trusted peer IPs. The proxy must not expose
/v1/*to browsers. - Stateless replicas. All state is in PostgreSQL; run two or more replicas behind the proxy.
Known limits
- Revocation is not instant. Revoking a membership or suspending a tenant blocks new exchanges. Tokens already issued stay valid until
exp. For an urgent cut-off, also revoke the person’s sessions in Camel Accounts. - The Camel token must still be live (15 minutes) at exchange time and accepted by userinfo.
- API-key traffic has no Camel token and cannot get a KIDA token. The platform uses its own API keys and NAK service assertions for that path.
- Camel account deletion is not pushed. It takes effect at the next exchange, through userinfo.
- No assurance level from Camel. Camel emits no
amr, so every token saysassurance: basic. Step-up policies cannot rely on it. - No replay store for KIDA tokens;
jtiis not tracked. - Go-live items owned by the deploying team (secret manager, managed PostgreSQL with point-in-time recovery, log shipping and alerts, a staging run with a real Camel sign-in, a load test, a security review) are listed in
KIDA/docs/V1-IMPLEMENTATION.md.
Source documents
| Path | Contents |
|---|---|
KIDA/README.md | Overview, local run, crates |
KIDA/docs/OPERATIONS.md | Production runbook |
KIDA/docs/PLATFORM-INTEGRATION.md | How each engine and the platform use KIDA |
KIDA/docs/integrations/camel-accounts.md | Camel Accounts provider profile and limits |
KIDA/docs/integrations/oidc.md | Generic OIDC provider integration |
KIDA/contracts/kida-access-token-v1.md | Token contract and consumers |
KIDA/crates/kida-server/src/lib.rs | Routes, peer check, error codes |
KIDA/crates/kida-server/src/callers.rs | Caller registry |
KIDA/crates/kida-server/src/bin/kida-server.rs | Environment variables and startup checks |
docs/ARCHITECTURE.md | Platform architecture |
deploy/compose.yaml, deploy/Caddyfile | Deployment wiring |