Sign-in, Roles and API Keys¶
This page explains how GHOSTS decides who someone is, and how to set it up. You don't need to know the code to use it.
One setting controls everything: Authorization:Mode. The API reads it once, when it starts. The browser never decides it.
Which mode do I want?¶
None (the default). Nobody signs in. Everyone who can reach GHOSTS is an administrator and can do everything.
If an auth proxy in front of GHOSTS sends an X-Forwarded-User header, GHOSTS uses it as the person's name, so
their drafts stay theirs. Without the header, everyone is named admin. Pick this for one person on a laptop, or
when something in front of GHOSTS (a VPN, an auth proxy) already decides who gets in. None is not a security
boundary. Anyone who reaches the API can do anything, and anyone can set the header.
Local. GHOSTS keeps its own list of users and passwords, and shows its own sign-in form. Pick this when you want real sign-in but have no Keycloak. The first administrator comes from your configuration.
Keycloak. People sign in on your Keycloak's page, and their Keycloak realm roles decide what they can do. Pick this when your range already runs Keycloak, as Crucible does. Keycloak must be reachable: if it isn't, sign-in fails. GHOSTS never falls back to letting people in.
| I have... | Use |
|---|---|
| Just me, on my own machine | None |
| An auth proxy or VPN that already controls who gets in | None |
| Several people, no Keycloak | Local |
| Keycloak (for example, a Crucible range) | Keycloak |
Setting each mode¶
Every setting can go in appsettings.json or in an environment variable. In environment variables, each :
becomes a double underscore (__). That's the form Docker Compose, Kubernetes and Aspire use. Both forms below do
the same thing.
None¶
Nothing to set: it's the default. To say so explicitly:
"Authorization": {
"Mode": "None"
}
Authorization__Mode=None
Optional settings:
"Authorization": {
"Mode": "None",
"DefaultUser": "operator"
}
Authorization__DefaultUser=operator # the name used when no X-Forwarded-User header is sent (default: admin)
Identity__UserHeader=X-Remote-User # read a different header than X-Forwarded-User
Local¶
The minimum is the mode and the first administrator's password:
"Authorization": {
"Mode": "Local",
"Local": {
"AdminPassword": "change-me-to-something-long"
}
}
Authorization__Mode=Local
Authorization__Local__AdminPassword=change-me-to-something-long
The first time GHOSTS starts with an empty users table, it creates the user admin with that password and the
Administrator role. After that, GHOSTS ignores AdminPassword. Changing it in your configuration later does
not change anyone's password. To change your own password, sign in and use Change password in the profile
menu (top right).
Adding people. An Administrator opens Users in the profile menu. There they add a user (username, name, password, roles), change anyone's roles, disable or enable someone, and reset a password (which also lifts a lockout). Nobody can sign themselves up. GHOSTS refuses to disable or demote the last enabled Administrator, so there is always someone who can get in. A change takes effect on the person's next click: a disabled user is signed out, and new roles apply at once.
Optional settings:
Authorization__Local__AdminUsername=rangeadmin # the first administrator's username (default: admin)
Authorization__Local__MaxFailedSignIns=5 # wrong passwords in a row before a lockout (default: 5)
Authorization__Local__LockoutMinutes=15 # how long a lockout lasts (default: 15)
Authorization__Local__ResetAdminPassword=... # recovery only: see Troubleshooting
Authorization__SessionHours=8 # how long a sign-in lasts without use (default: 8)
When a sign-in fails, GHOSTS only says it failed. It doesn't say whether the username exists, whether the user is locked out, or whether they are disabled. Passwords need at least 8 characters.
Keycloak¶
The minimum is the mode and your realm's address (the "Authority"):
"Authorization": {
"Mode": "Keycloak",
"Authority": "https://keycloak.example.org/realms/crucible"
}
Authorization__Mode=Keycloak
Authorization__Authority=https://keycloak.example.org/realms/crucible
Optional settings. The defaults match the client names in the checklist below.
Authorization__ClientId=ghosts.ui # the client the browser signs in with
Authorization__Audience=ghosts # the audience a token must carry to call the API
Authorization__SwaggerClientId=ghosts.api # the client Swagger UI signs in with
Authorization__RolesClaimPath=realm_access.roles # where the token keeps the user's roles
Authorization__UserClaim=preferred_username # the token claim that names the user
Authorization__RequireHttpsMetadata=true # set false only for a Keycloak on plain http in development
Authorization__SessionHours=8
# Only if your Keycloak's endpoints aren't under the Authority (Swagger UI uses these):
Authorization__AuthorizationUrl=https://keycloak.example.org/realms/crucible/protocol/openid-connect/auth
Authorization__TokenUrl=https://keycloak.example.org/realms/crucible/protocol/openid-connect/token
What happens if I get it wrong¶
GHOSTS refuses to start rather than start unprotected. The API's log shows one of these messages.
| You see | Why | Fix |
|---|---|---|
Authorization:Mode is 'Keycloack', which GHOSTS doesn't know. Set it to None, Local or Keycloak. |
A typo in the mode | Use exactly None, Local or Keycloak (capital letters don't matter) |
Authorization:Mode is Keycloak but Authorization:Authority isn't set. Set it to the Keycloak realm, e.g. https://localhost:8443/realms/crucible, or set Authorization:Mode to None or Local. |
Keycloak mode with no realm address | Set Authorization__Authority |
Authorization:Mode is Local and there are no users yet, but Authorization:Local:AdminPassword isn't set. Set it (Authorization__Local__AdminPassword) to create the first administrator. |
Local mode, no users yet, and no password for the first administrator | Set Authorization__Local__AdminPassword and start again |
If Keycloak is down, or a token can't be checked, GHOSTS answers 401 (not signed in). It never treats the caller as
an administrator. Going to the sign-in page while Keycloak is down shows 503 with the message GHOSTS can't reach
Keycloak at <your Authority>, so it can't sign you in.
Keycloak checklist¶
Create these in your realm (Crucible's development realm already has them).
- Client
ghosts.ui, for people signing in through the browser.- Client authentication: off (a public client: the browser can't keep a secret).
- Standard flow: on. PKCE method: S256.
- Valid redirect URIs:
https://ghosts.example.org/api/auth/callback. This is where Keycloak sends people back after they sign in. - Valid post logout redirect URIs:
https://ghosts.example.org/api/auth/signed-out. - Web origins:
https://ghosts.example.org.
- Client
ghosts.api, for Swagger UI's Authorize button.- Public, standard flow, PKCE S256.
- Valid redirect URIs:
https://ghosts-api.example.org/swagger/oauth2-redirect.html(the API's own address).
- Client scope
ghosts, with an Audience mapper whose included client audience isghosts, added to the access token. Add it as a default client scope ofghosts.ui,ghosts.apiand any service account that calls GHOSTS. Without it, tokens don't say they're meant for GHOSTS, and GHOSTS refuses them. - Realm roles
Administrator,Content Developer,Range OperatorandIntegration, assigned to your users. Keycloak puts a user's realm roles in the token atrealm_access.roles(the built-inrolesclient scope does this). GHOSTS reads them from there and ignores capital letters.
Under a path. When GHOSTS runs under a path such as /ghosts (see
Running under a path), every address above gets the prefix:
https://range.example.org/ghosts/api/auth/callback, https://range.example.org/ghosts/api/auth/signed-out, and
https://range.example.org/ghosts/swagger/oauth2-redirect.html. The sign-in cookie's path becomes /ghosts too, so
other apps on the same host don't receive it.
The UI and the API must share one origin (the same scheme, host and port), for example
https://ghosts.example.org/ for the UI and https://ghosts.example.org/api/ for the API, through your ingress or
reverse proxy. Why: the sign-in is a cookie, and browsers only send it back to the site that set it. In development,
the UI's dev server forwards /api to the API, which does the same job.
In containers (the dustinupdyke/ghosts API image), two more things are taken care of, as long as you mount a
volume:
- The proxy's headers are trusted. The image sets
ASPNETCORE_FORWARDEDHEADERS_ENABLED=true, so behind anhttps://ingress the Keycloak sign-in builds its return address withhttps://. Without that, Keycloak refuses the sign-in with "Invalid parameter: redirect_uri". - Session keys are kept on the volume. The image keeps the keys that sign session cookies in
/data/keys(DataProtection__KeysPath). Mount a volume at/data. Without one, every restart signs everyone out. If you run more than one copy of the API, give them the same/data.
Roles in plain words¶
Each person has zero or more of these roles. In Keycloak mode they come from Keycloak (GHOSTS can't change them). In Local mode an Administrator sets them on the Users page. API keys have the roles you give them.
| Role | For | Can | Can't |
|---|---|---|---|
Administrator |
Whoever runs GHOSTS | Everything: users, webhooks, ATT&CK import, every scenario and execution | — |
Content Developer |
Scenario authors | Create and import scenarios, edit the ones they are an Owner or Editor of, see published scenarios, use AI authoring, manage NPCs, objectives, hypotheses and saved timelines, see machines and timelines | Change machines, send timelines to machines, manage n8n animations, run a scenario they aren't an Owner or Deployer of |
Range Operator |
Whoever runs exercises | See every scenario and execution, start, pause, stop and steer any execution, manage machines, machine groups, timelines sent to machines and n8n animations, see NPCs | Edit scenarios (unless they're an Owner or Editor of it), change NPCs, manage users |
Integration |
Other apps (Pandora, n8n) | Look up NPCs, read one NPC and its activity, connections, beliefs, preferences and knowledge, and record those | Create or delete NPCs, see machines, see scenarios |
Everyone who is signed in, with or without a role, can read the ATT&CK data. In None mode everyone is an Administrator, so they can do everything, including seeing every draft.
Scenario members¶
A scenario has members. Each member has one role on that scenario:
| Member role | See it | Change it | Run it | Take part | Publish, delete, manage members |
|---|---|---|---|---|---|
Owner |
yes | yes | yes | yes | yes |
Editor |
yes | yes | yes | ||
Deployer |
yes | yes | yes | ||
Participant |
yes | yes |
"Take part" means seeing the scenario's executions and answering their timeline items.
An AI authoring session belongs to whoever started it; nobody else but an Administrator can open it. The assistant works as that person: it only sees and changes the scenarios they could.
- Whoever creates a scenario is its Owner. Scenarios that existed before this version get their author as Owner the first time GHOSTS starts.
- An Owner adds members on the scenario's page (the Members panel), by username. They can add someone before that person has ever signed in.
- A scenario always keeps at least one Owner. To leave, make someone else Owner first.
- App-wide roles still apply on top: a Range Operator can run any scenario, and a Content Developer can see any published one.
- Someone who can't see a scenario gets "not found", so they don't learn it exists.
Machine callers¶
NPC clients (Universal, Windows, Lite) need nothing. Their report-in endpoints and their live connection stay open in every mode, because clients already deployed on range machines can't be given credentials. These are always open:
| Endpoint | Why |
|---|---|
GET /api/clientid, POST /api/clientresults, POST /api/clientsurvey, POST /api/clienttimeline, GET /api/clientupdates (and the /secure variants) |
Client report-in |
/clientHub and /api/clientHub |
The clients' live connection |
GET /server |
Version and health check |
/stubs/grayspace/... |
The GraySpace simulator, which checks its own token |
/swagger/... |
The API description; it holds no data |
Pandora, n8n and the MCP tool use an API key in Local and Keycloak modes. In None mode they need nothing.
- Make a long random key, for example with
openssl rand -hex 32. -
Add it to the API's configuration. Keep it out of source control.
"Authorization": { "ApiKeys": [ { "Name": "pandora", "Key": "3f9c...e1", "Roles": [ "Integration" ] }, { "Name": "n8n", "Key": "a71b...0d", "Roles": [ "Integration" ] }, { "Name": "mcp", "Key": "c4d2...9a", "Roles": [ "Content Developer" ] } ] }Authorization__ApiKeys__0__Name=pandora Authorization__ApiKeys__0__Key=3f9c...e1 Authorization__ApiKeys__0__Roles__0=Integration Authorization__ApiKeys__1__Name=n8n Authorization__ApiKeys__1__Key=a71b...0d Authorization__ApiKeys__1__Roles__0=Integration Authorization__ApiKeys__2__Name=mcp Authorization__ApiKeys__2__Key=c4d2...9a Authorization__ApiKeys__2__Roles__0=Content Developer -
Give each caller its key:
| Caller | Environment variable | Role to give its key |
|---|---|---|
| Pandora | GHOSTS_API_KEY |
Integration |
| n8n (its container) | GHOSTS_API_KEY |
Integration |
| MCP tool | GHOSTS_API_TOKEN |
Content Developer |
| Live acceptance tests | GHOSTS_LIVE_API_KEY |
Content Developer |
A caller sends its key as Authorization: Bearer <key>. GHOSTS names the caller after the key's Name. In Keycloak
mode, an app can send a Keycloak service account's token the same way instead.
Every setting¶
| Key | Environment variable | Default | What it does | Modes |
|---|---|---|---|---|
Authorization:Mode |
Authorization__Mode |
None |
None, Local or Keycloak |
All |
Authorization:DefaultUser |
Authorization__DefaultUser |
admin |
The name when no auth proxy names the caller | None |
Identity:UserHeader |
Identity__UserHeader |
X-Forwarded-User |
The header an auth proxy names the caller in | None |
Authorization:Local:AdminUsername |
Authorization__Local__AdminUsername |
admin |
The first administrator's username | Local |
Authorization:Local:AdminPassword |
Authorization__Local__AdminPassword |
(none) | The first administrator's password; read only while there are no users | Local |
Authorization:Local:MaxFailedSignIns |
Authorization__Local__MaxFailedSignIns |
5 |
Wrong passwords in a row before a lockout | Local |
Authorization:Local:LockoutMinutes |
Authorization__Local__LockoutMinutes |
15 |
How long a lockout lasts | Local |
Authorization:Local:ResetAdminPassword |
Authorization__Local__ResetAdminPassword |
(none) | Recovery: at startup, sets AdminUsername's password, unlocks and enables them and makes them an Administrator. Remove it afterwards |
Local |
Authorization:SessionHours |
Authorization__SessionHours |
8 |
How long a sign-in lasts without use | Local, Keycloak |
Authorization:ApiKeys |
Authorization__ApiKeys__0__Name, __Key, __Roles__0 |
(none) | Keys for apps and tools | Local, Keycloak |
Authorization:Authority |
Authorization__Authority |
(none) | The Keycloak realm's address | Keycloak |
Authorization:ClientId |
Authorization__ClientId |
ghosts.ui |
The browser's sign-in client | Keycloak |
Authorization:Audience |
Authorization__Audience |
ghosts |
The audience a token must carry | Keycloak |
Authorization:SwaggerClientId |
Authorization__SwaggerClientId |
ghosts.api |
Swagger UI's sign-in client | Keycloak |
Authorization:AuthorizationUrl |
Authorization__AuthorizationUrl |
under Authority |
Keycloak's sign-in endpoint, for Swagger UI | Keycloak |
Authorization:TokenUrl |
Authorization__TokenUrl |
under Authority |
Keycloak's token endpoint, for Swagger UI | Keycloak |
Authorization:RequireHttpsMetadata |
Authorization__RequireHttpsMetadata |
true |
Refuse a Keycloak that isn't on https | Keycloak |
Authorization:UserClaim |
Authorization__UserClaim |
preferred_username |
The token claim that names the user | Keycloak |
Authorization:RolesClaimPath |
Authorization__RolesClaimPath |
realm_access.roles |
Where the token keeps the user's roles | Keycloak |
Troubleshooting¶
The browser keeps bouncing between GHOSTS and Keycloak. The session cookie isn't coming back. Usually the UI and
the API are on different origins, or Keycloak's redirect URI points at the API's own address instead of the UI's.
Serve both under one origin, and set ghosts.ui's redirect URI to <ui-origin>/api/auth/callback.
Keycloak says "Invalid parameter: redirect_uri". The address GHOSTS sent isn't in ghosts.ui's valid redirect
URIs. Add <ui-origin>/api/auth/callback exactly, including https and any port.
Every page says I'm not signed in, right after I signed in. The UI is calling the API on a different origin (for
example, the UI on :4200 with apiUrl pointing at http://localhost:5000/api), so the browser doesn't send the
cookie. Make the UI reach the API at /api on its own origin, through the ingress or the dev server's proxy.
An NPC client gets 401. The client endpoints never ask for credentials, so this 401 is the endpoint saying it
doesn't know the machine, or the client is calling the wrong address. Point the client at
http://YOUR-API-HOST:5000/api and check the client endpoint names above. Pandora or n8n getting 401 is different:
their API key is missing or doesn't match. Check GHOSTS_API_KEY against Authorization:ApiKeys.
The admin is locked out (Local mode). Wait 15 minutes (or LockoutMinutes), or have another Administrator
use Reset password on the Users page, which also lifts the lockout.
Nobody knows the admin password, or every Administrator is locked out (Local mode). Changing AdminPassword
does nothing once users exist. Instead, start GHOSTS once with a recovery password:
Authorization__Local__ResetAdminPassword=a-new-long-password
On startup GHOSTS gives admin (or AdminUsername) that password, unlocks and enables them, makes them an
Administrator, and creates them if they were deleted. Sign in, then remove the setting and restart: while it's
set, every restart resets the password again. The API's log has a warning reminding you.
Someone can't see a scenario, or gets "You don't have access". They need a membership on the scenario (ask one of its Owners to add them on the scenario's page) or an app-wide role. The profile menu shows their roles.