Authentication rendering
A model’s authentication block names the identity providers an application signs people in with. The Cratis renderer turns it into an application that runs behind Cratis AuthProxy and a configuration AuthProxy starts from.
What the renderer emits
Section titled “What the renderer emits”For a model that declares
authentication provider EntraId provider GitHub provider OpenId name Partneran application plan adds the following to the application:
| File | What it is |
|---|---|
appsettings.json |
Cratis:Arc:TrustForwardedIdentityHeaders is true, so Arc builds the caller from the identity headers AuthProxy forwards. |
Program.cs |
Calls RuntimeConventions.Apply before Cratis reads its configuration. |
GeneratedAuthentication/RuntimeConventions.cs |
Reads the Chronicle connection string from the file named by CRATIS_CHRONICLE_CONNECTION_STRING_FILE. |
GeneratedAuthentication/Personas.cs |
The personas of the model with the roles and claims that satisfy the policies each one holds. |
GeneratedAuthentication/MemberIdentity.cs |
The identity of a person: the provider they sign in with and their subject. |
.runtime/authproxy.application.json |
The provider list in AuthProxy’s Cratis:AuthProxy:Application shape. |
.runtime/environment.json |
The environment keys the model needs, with the secrets marked. |
By default the identity headers are not signed. Arc ignores them unless TrustForwardedIdentityHeaders is on, and AuthProxy removes every identity header a client sends and writes its own, so the setting is right only when every request reaches the application through AuthProxy. Never expose a rendered application with authentication directly. The plan reports this as the warning STAGE-AUTH-003; to have Arc verify the forwarded identity by its signature, opt in to signed forwarded identity.
The policies the commands and queries already carry need nothing else. A caller AuthProxy forwarded satisfies require authenticated, require role and require claim through the roles and claims in the forwarded principal; an anonymous caller satisfies none of them, and an authorize Anyone policy still renders as [AllowAnonymous].
The files a runtime reads
Section titled “The files a runtime reads”cratis run and Stage Manager find the runtime files in the .runtime folder of the rendered application and add what only they know: the environment name, the secrets directory, Development and the values of the environment.
{ "Cratis": { "AuthProxy": { "Application": { "Providers": [ { "Kind": "EntraId", "Identity": "EntraId" }, { "Kind": "GitHub", "Identity": "GitHub" }, { "Kind": "OpenId", "Identity": "Partner" } ] } } }}Onboarding is true in the same file when the model declares onboarding. The kinds are EntraId, GitHub, Google, Apple and OpenId; a provider of another kind is reported as STAGE-AUTH-001 and left out. RuntimeConfigurationFiles.Render produces the same files for a caller that holds only a realization.
The application container receives:
| Variable | Meaning |
|---|---|
CRATIS_ENVIRONMENT |
The name of the environment. |
CRATIS_SECRETS_DIRECTORY |
A directory with one file per environment key, named by the key. |
CRATIS_CHRONICLE_CONNECTION_STRING_FILE |
A file holding the Chronicle connection string. |
Signed forwarded identity (opt-in)
Section titled “Signed forwarded identity (opt-in)”AuthProxy can sign the identity it forwards, and Arc can refuse forwarded identity that is not signed with a key it knows. Set SignedForwardedIdentity on CratisRenderingOptions, or on CratisPlanOptions for CratisRendering.PlanFrom, to render an application that verifies the signature:
var profile = CratisRendering.WithRealization(CratisRendering.CreateProfile(name, options with { SignedForwardedIdentity = true }), compilation, modelRoot);The option is a profile input, so it is part of the input digest. This repository exposes it through these options only; it adds no command-line flag. Without it the output does not change. An application without authentication trusts no forwarded identity, so the option changes nothing there.
It needs AuthProxy 2.44.0 or later and Arc 22.168.0 or later (the minimum AuthProxy documents). With the option on, the plan no longer reports STAGE-AUTH-003 and renders:
| Setting | Value |
|---|---|
Cratis:Arc:TrustForwardedIdentityHeaders |
true, as before. |
Cratis:Arc:ForwardedIdentity:Enabled |
true |
Cratis:Arc:ForwardedIdentity:Audience |
<application>-api, the application name in lower case with every other character run turned into -. |
Cratis:Arc:ForwardedIdentity:Keys |
One key whose KeyId is <application>-v1. |
The renderer never writes a secret. .runtime/environment.json declares two more secret keys. The runtime supplies their value and has to make it available as the configuration in the second column:
| Key | Configuration it must become |
|---|---|
forwardedIdentity.arc.secretBase64 |
Cratis__Arc__ForwardedIdentity__Keys__0__SecretBase64 for the application. |
forwardedIdentity.authProxy.secretBase64 |
Cratis__AuthProxy__Services__<name>__ForwardedIdentity__SecretBase64 for AuthProxy. |
Each entry of .runtime/environment.json has this shape:
{ "key": "forwardedIdentity.arc.secretBase64", "secret": true, "target": "application", "configuration": "Cratis:Arc:ForwardedIdentity:Keys:0:SecretBase64"}| Field | Meaning |
|---|---|
key |
The name of the value in the model. |
secret |
Whether the value is a secret. |
target |
The process the key configures: application for the rendered application, authProxy for the AuthProxy in front of it. |
configuration |
The full .NET configuration path, in colon form, the value must become. |
The environment variable for a configuration path is the path with every : replaced by __, so Cratis:Arc:ForwardedIdentity:Keys:0:SecretBase64 is Cratis__Arc__ForwardedIdentity__Keys__0__SecretBase64. target and configuration are written only for keys whose configuration Stage knows: the two keys above and the authentication provider keys. The onboarding keys (onboarding.email.*) carry only key and secret, because who reads them (Ante or the application’s Herald) is not confirmed. The AuthProxy service that routes to the application is the operator’s choice and AuthProxy has no convention for it, so the configuration of forwardedIdentity.authProxy.secretBase64 keeps the literal <name> placeholder; the operator replaces it with the name of the AuthProxy service that routes to the application.
Every authentication.providers.<Identity>.<key> key targets authProxy, and its configuration is Cratis:AuthProxy:Application:Environment:authentication.providers.<Identity>.<key>, with the identity written exactly as the model declares it, spaces and hyphens included. The last segment, authentication.providers.<Identity>.<key>, contains dots and is one configuration key. Only : becomes __ in the environment variable, so the dots stay: Cratis__AuthProxy__Application__Environment__authentication.providers.<Identity>.<key>. AuthProxy also accepts a <path>_FILE form for a secret, whose value is the path of a file holding it, and Cratis:AuthProxy:Application:SecretsDirectory, a directory with one file per key.
The model declares clientId and clientSecret for every provider, tenantId for EntraId and authority for OpenId. AuthProxy requires exactly these for EntraId, GitHub and OpenId; for Google and Apple it accepts an optional authority that the model does not declare.
Both hold the same value: the standard base64 of exactly 32 random bytes, for example from openssl rand -base64 32. Keep it in a secret store and never commit it. Use a separate key for every audience.
Stage renders only AuthProxy’s Cratis:AuthProxy:Application contract, so configure the sending side of AuthProxy yourself:
Cratis:AuthProxy:Services:<name>:ForwardedIdentitywithAudience<application>-api,KeyId<application>-v1and the secret above.<name>is the service AuthProxy routes to the application.- The tenant list flow is signed separately, under
TenantResolutions:<i>:Options:ForwardedIdentity, with the same shape. - By convention an MCP flow uses the audience
<application>-mcpand its own key. - Outside local development the application must be reached over HTTPS with a client certificate. Stage does not render these.
- A custom
Tenancy.HttpHeaderis not signed by AuthProxy, so it cannot be combined with signed forwarded identity.
To rotate a key, add the new key at every receiver first, then switch AuthProxy to the new key id and secret, wait out the replay window and remove the old key. AuthProxy’s forwarded identity signing documentation describes the details.
The caller’s identifier in a policy
Section titled “The caller’s identifier in a policy”A policy that reads recorded state can compare a property with the identifier of whoever is asking, as in article.author == $identity.id. The generated policy reads that identifier from the principal Arc authorized:
- The
urn:cratis:identity:subjectclaim, which AuthProxy forwards as the subject the identity provider gave. - Otherwise the name identifier claim.
- Otherwise the
subclaim.
The first of those the principal carries decides. A principal that carries none of them, or two different values of the same claim, has no identifier, and a policy that compares with it is unavailable, so it denies. != is no exception: a caller that cannot say who it is is not allowed because it differs from the author.
An application that identifies callers another way supplies the identifier itself by implementing the partial method ResolveCallerId on the generated PolicyValues class; leaving the identifier unset keeps the default above. In a specification, id "alice" on the caller puts that value in the name identifier claim of the principal the generated test uses.
Personas
Section titled “Personas”A persona holds policies. Personas.cs records, per persona, the smallest set of roles and claims that satisfies all of its policies, in the order Screenplay’s persona callers use. Personas.Holds is true for a caller who has all of them. A persona whose policies are not requirements on authentication, roles or claims cannot be reduced to roles and claims, is never matched and is reported as STAGE-AUTH-002.
Planning
Section titled “Planning”The realization is not part of the executable model, so a caller adds it to the profile:
var profile = CratisRendering.WithRealization(CratisRendering.CreateProfile(name, options), compilation, modelRoot);compilation is the SemanticCompilation the plan is made from. modelRoot is the folder holding the .play files, from which the images of onboarding emails are read; leave it out when there are none. SemanticModelLoader does the same for LoadedSemanticModel.Realization, and CratisRendering.PlanFrom adds it itself. The realization is a profile input, so it is part of the input digest.
The sandbox
Section titled “The sandbox”cratis run starts the Stage sandbox behind AuthProxy when the model has authentication. Set Stage:Sandbox:ForwardedIdentity (environment variable Stage__Sandbox__ForwardedIdentity) to true and the sandbox trusts the forwarded identity exactly as a rendered application does: it plays no persona and the signed-in caller is the caller its authorization runs for. Without the setting, the sandbox keeps playing a persona and removes the identity headers a caller sends.
The legacy writer
Section titled “The legacy writer”The syntax-based writer that IRenderer exposes writes .runtime/authproxy.application.json and .runtime/environment.json, and reports a provider kind AuthProxy does not know. It does not change the scaffold, so the application it writes does not trust the forwarded identity; use cratis render for that.