Skip to Content
The Ngamia platform API is in preview. Endpoints may change before general availability.
EnginesKIDA: identity

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

ConcernOwner
Passwords, MFA, passkeys, Google sign-in, recovery, provider sessionsCamel Accounts
KIDA user ID, workspaces (tenants), membership, identity audit, KIDA signing keysKIDA
Member roles, invites, API keys, what a person may do in a workspaceThe 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 app platform and holds the capabilities issue_identity_token and provision_tenant. deploy/bin/init-secrets.sh writes 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-platform and app platform. 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/tenants to create the tenant with the person as owner. Joining by invite calls POST /v1/tenants/{tenant_id}/members after 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:

  1. The caller is allowed this app and operation.
  2. The Camel token: RS256, typ=JWT, exact issuer, exact audience for the requested app, expiry (30 s skew), known kid.
  3. Camel /oauth/userinfo still accepts the token and returns the same sub.
  4. (Camel issuer, sub) maps to a KIDA user with an active membership in the tenant.
  5. 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).

HeaderValue
algRS256 (the only accepted algorithm)
typJWT
kidMust name exactly one key in KIDA’s JWKS (kty=RSA, use=sig, alg=RS256)
ClaimMeaning
issKIDA issuer (KIDA_ISSUER, HTTPS, no trailing slash). In the deployment: https://api.ngamia.com/identity
subKIDA user UUID. Never the Camel subject
audTarget service, from KIDA’s token-audience map. The platform’s is ngamia-platform
iatIssue time (Unix seconds)
expExpiry (Unix seconds), see lifetime below
jtiUnique token UUID. There is no replay store: a token is reusable until it expires
app_idKIDA app the token was issued for (platform in the deployment)
tenant_idKIDA tenant (workspace) UUID. Membership was active at issue
auth_timeWhen the person signed in at the provider
assurancebasic, 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.

MethodPathWho may callPurpose
GET/health/liveAnyone who can reach KIDAProcess liveness. Returns {"status":"alive"}
GET/health/readyAnyone who can reach KIDAReadiness (store). 200 ready, 503 not ready
GET/.well-known/kida-configurationPublicissuer, jwks_uri, token_endpoint, token_profile, signing_algorithms
GET/.well-known/jwks.jsonPublicKIDA’s public signing keys (current and any still-valid previous keys)
POST/v1/tokens/exchangeCaller with issue_identity_token for the appVerify a Camel token and membership; return a KIDA access token
POST/v1/authentication/verifyCaller with verify_identityVerify evidence and return a short-lived principal. Not a signed token
POST/v1/tenantsCaller with provision_tenantSign-up: create a tenant with the person as owner and issue their token
POST/v1/tenants/{tenant_id}/membersCaller with provision_tenantAdd the person as a member (already a member is fine) and issue their token
POST/v1/membershipsCaller with provision_tenantList the person’s active workspaces
POST/mcpCaller with verify_identityMCP 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

RouteSuccessRejected evidence
/v1/tokens/exchange200 {"outcome":"authenticated","token":{access_token, token_type, expires_in, principal}}200 {"outcome":"rejected","reason_code","correlation_id"}
/v1/tenants201 {tenant_id, tenant_name, exchange}401 {"outcome":"rejected",...}
/v1/tenants/{tenant_id}/members200 {tenant_id, exchange}401 {"outcome":"rejected",...}
/v1/memberships200 {"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"}}:

StatusCodes
400invalid_request, unsupported_contract_version
401unauthorized (missing, malformed or unknown caller credential)
403untrusted_transport_peer, forbidden (caller lacks the app or capability)
404not_found, tenant_not_found
409conflict
503overloaded, caller_auth_unavailable, authorization_unavailable, audit_unavailable, directory_unavailable, token_issuance_unavailable
504request_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_token and provision_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_IPS are accepted. There are no ranges. Any other peer gets 403 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.

VariableMeaning
KIDA_RUN_MODEdevelopment (default) or production. Production enables the checks listed below
KIDA_BINDListen address. Default 127.0.0.1:8095; the image and deployment use 0.0.0.0:8095
KIDA_ISSUERIssuer put in tokens and pinned by every consumer. HTTPS in production, no trailing slash
KIDA_TRUSTED_PROXY_IPSComma-separated exact peer IPs. Required in production
KIDA_MCP_ALLOWED_HOSTSComma-separated host names accepted on /mcp. Required in production
KIDA_STOREsqlite (development default) or postgres (production default and only allowed value)
KIDA_DATABASE_PATHSQLite file (development only)
KIDA_DATABASE_URL_FILEFile holding the PostgreSQL URL. Production requires sslmode=verify-full
KIDA_DATABASE_URLPostgreSQL URL in the environment. Accepted, but prefer the file
KIDA_DATABASE_MAX_CONNECTIONSPool size per replica. Default 16
KIDA_RUN_MIGRATIONStrue (default) or false. Set false in production; startup then fails if the schema is behind
KIDA_SIGNING_KEY_IDkid of the active signing key
KIDA_SIGNING_PRIVATE_KEY_FILERSA private key, PEM. 3072 bits recommended
KIDA_SIGNING_PUBLIC_JWKS_FILEPublished JWKS: the active key plus previous keys still in use. Each kid must be unique
KIDA_TOKEN_AUDIENCES_FILEMap of app ID to token audience, for example {"platform": "ngamia-platform"}
KIDA_PROVIDER_CONFIG_FILEOIDC provider profile (Camel Accounts). Every token app needs a provider audience here
KIDA_CALLERS_FILECaller registry
KIDA_TOKEN_TTL_SECONDSToken lifetime, 60 to 900. Default 300
KIDA_MAX_CONCURRENT_REQUESTSProtected 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.

CommandEffect
kida-admin migrateApply 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:

  1. Generate a new key (for example kida-YYYY-MM) and append its public key to the JWKS, keeping the current key.
  2. Deploy the new JWKS with the old KIDA_SIGNING_KEY_ID. Wait at least the consumers’ JWKS refresh interval.
  3. Switch KIDA_SIGNING_KEY_ID and the private key file to the new key and redeploy.
  4. 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/ready from the orchestrator; it checks the database. GET /health/live is 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_started lists the callers, apps, store and signing_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) and tenant_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 says assurance: basic. Step-up policies cannot rely on it.
  • No replay store for KIDA tokens; jti is 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

PathContents
KIDA/README.mdOverview, local run, crates
KIDA/docs/OPERATIONS.mdProduction runbook
KIDA/docs/PLATFORM-INTEGRATION.mdHow each engine and the platform use KIDA
KIDA/docs/integrations/camel-accounts.mdCamel Accounts provider profile and limits
KIDA/docs/integrations/oidc.mdGeneric OIDC provider integration
KIDA/contracts/kida-access-token-v1.mdToken contract and consumers
KIDA/crates/kida-server/src/lib.rsRoutes, peer check, error codes
KIDA/crates/kida-server/src/callers.rsCaller registry
KIDA/crates/kida-server/src/bin/kida-server.rsEnvironment variables and startup checks
docs/ARCHITECTURE.mdPlatform architecture
deploy/compose.yaml, deploy/CaddyfileDeployment wiring
Last updated on