Skip to content

Hooking up the sign-in service

The Stage Manager operator renders the AuthProxy bearer route for /mcp from the Performance (authProxy.bearerRoutes, Showrunner 2.30.0 and later), and the deployment program deploys Identity beside the application. Everything below is switched on by identityHost. Not yet exercised against the real MongoDB, fence log and Chronicle: see What is not proven yet.

For whoever runs Kelda Kraft. AI assistants sign in through Kelda Kraft’s own Cratis Identity instance. It is separate from every other product’s. It issues the access tokens, the AuthProxy in front of the application validates them, and the application never checks a credential itself. This page is the sequence. Steps marked human cannot be automated.

What Value
Application https://app.keldakraft.no
Sign-in service (the issuer) https://identity.keldakraft.no/

The issuer is the exact string Identity signs into every token, with the trailing slash.

  1. Point identity.keldakraft.no at the cluster ingress.
  2. Create a GitHub OAuth app with the callback https://identity.keldakraft.no/signin-github. Keep its client ID and secret.
  3. Create the key store: the offline signing material, as the Kubernetes Secret keldakraft-identity-keys in the application’s namespace. Create it by hand so no key enters Pulumi state. The format is in the Cratis Identity image contract.
  4. Choose the security owners: the GitHub subjects that administer the instance.
  5. Make a shared secret of at least 32 characters for the tenants callback.

What the fence log is. Identity revokes access by writing a fence for every revoked grant, account or key epoch. The fence log is the independent, append-only record of those fences. If Identity’s database were restored from an older backup, the fence log is how it knows a restored account was revoked after the backup, so a revocation can never be undone by a restore. It lives in the platform’s own MongoDB, in its own database, keldakraft-identity-fences, with its own user, exactly as Cratis Direct does it. Backups and restores there are per database, so the fence-log database has its own archive, and the stack sets Identity__FenceLog__AllowSharedDeployment=true as the statement that this holds. Identity’s operational database, keldakraft-identity, uses the platform’s mongoUri stack output, so there is no second URI to keep. Never restore the fence-log database with, or to an earlier point than, Identity’s database, and never restore the whole replica set from a snapshot.

Create it once, as the user administrator, with a generated password, then seed the custody record as that user and keep the connection string as the identityFenceLogMongoUri secret:

const d = db.getSiblingDB('keldakraft-identity-fences');
d.createUser({ user: 'keldakraft-identity-fences', pwd: '<generated>', roles: [{ role: 'readWrite', db: 'keldakraft-identity-fences' }, { role: 'clusterMonitor', db: 'admin' }] });
// then, authenticated as that user:
d.getCollection('fence-custody').insertOne({ _id: 'metadata', instanceId: 'keldakraft-identity', allocated: Long(0), epoch: Long(0) });
Terminal window
pulumi config set identityHost identity.keldakraft.no
pulumi config set identityFenceLogMongoUri --secret # its own database and user, see above
pulumi config set identityGitHubClientId --secret # optional: defaults to applicationGitHubClientId
pulumi config set identityGitHubClientSecret --secret # optional: defaults to applicationGitHubClientSecret
pulumi config set identityAccountLookupKey --secret # base64, at least 32 bytes
pulumi config set identitySecurityOwners "<github subject>,<github subject>"
pulumi config set identityTrustedNetworks "<ingress CIDR>"
pulumi config set assistantCallbackSecret --secret # the shared secret, at least 32 characters
pulumi config set authProxyImage <image 2.70.0>

identityImage defaults to docker.io/cratis/identity:1.4.0, which is public. assistantIssuer defaults to https://<identityHost>/ and must equal it when Identity is deployed here. Setting identityHost turns AI assistant access on.

Apply the change through CI. Never run pulumi up from a workstation.

The stack then deploys the Identity pod, its service and ingress, serves only the Kelda Kraft audience (keldakraft-mcp, scope keldakraft:mcp:read) and lets any MCP client sign in by publishing a client metadata document. It adds the bearer route for /mcp to the application’s Performance, with the issuer, the audience and the tid organization claim, so the AuthProxy validates the token and Core reads no credential. Identity only calls an https address, so one more Ingress routes exactly /api/internal/assistants/tenants on the application’s host straight to Core, past the AuthProxy, with the application host’s own certificate. Core checks the shared secret on that path itself and trusts nothing the caller sends. That path is how Identity asks which organizations a person belongs to.

Put the Core settings in the Cratis environment file (stageManagerEnvironment) at the same time: KeldaKraft__Assistants__Enabled, __PublicOrigin, __IssuerUrl and KeldaKraft__Assistants__Callback__Secret, the last with the same value as assistantCallbackSecret. They are listed in Deployment/README.md.

Terminal window
curl -s -o /dev/null -D - https://app.keldakraft.no/mcp

Expect 401 with a WWW-Authenticate: Bearer header carrying a resource_metadata address. A redirect to a sign-in page means the bearer route is missing.

Terminal window
curl -s https://app.keldakraft.no/.well-known/oauth-protected-resource/mcp
curl -s https://identity.keldakraft.no/.well-known/openid-configuration

Expect the issuer in both. Then connect an assistant as described in Claude, OpenAI Codex or pi, and ask which plants the organization has.

  • The Identity container starting against the real MongoDB, fence log and Chronicle.
  • The Chronicle CA reaching the image through SSL_CERT_DIR.
  • The callback Ingress reaching Core with the Authorization header intact. If it does not, the callback answers 401 and the sign-in cannot list organizations.
  • Which networks to trust for forwarded headers (identityTrustedNetworks).

If one of them fails, troubleshooting.md and the Identity pod’s log are the first places to look.