Prepare a template for deployment
Source content/
The project templates start in Development: dotnet run picks up
ASPNETCORE_ENVIRONMENT=Development from Properties/launchSettings.json. A published build
started with dotnet MyCompany.Hub.dll, or in a container, runs in Production unless the
environment says otherwise, and two things exist only in Development:
| What | Where | Outside Development |
|---|---|---|
The operations console at /trax/dashboard | trax-scheduler, trax-hub | Not mapped; /trax/dashboard is a 404. |
The demo API key (X-Api-Key: demo-key-do-not-use-in-production) | trax-api, trax-hub | Not registered. Every template train and the Note query model carry [TraxAuthorize], so every operation is refused. |
The operator key (X-Api-Key: operator-key-do-not-use-in-production) | trax-scheduler, trax-hub | Not registered. The operations namespace is gated to Operator, so the console's every read and write is refused. |
Serve the console outside Development
The console can queue, run and cancel trains and change scheduler settings, and
AllowAnonymousShell() puts no authorization in front of its page. What it reads and changes is
still gated by GateOperations.
- Register a sign-in the browser carries on a page load, a cookie or OpenID Connect, for your
operators. A page load sends no
X-Api-KeyorAuthorizationheader, so an API key or a bearer token cannot gate the page. - Replace
AllowAnonymousShell()withRequirePolicy("<policy>")orRequireRoles("<role>")(see UseTraxApiDashboard). - Remove the
IsDevelopment()check aroundUseTraxApiDashboard.
A policy or roles with no authentication scheme to challenge with refuses to start, naming
AddAuthentication, because every request the console refused would otherwise be a 500 rather
than a 401 or 403.
Replace the demo keys
- Register real credentials, such as
AddHashedkeys loaded from a secret store, orAddTraxJwtAuth. - Then remove the
IsDevelopment()check aroundAddTraxApiKeyAuth, with the demo keys gone from it. Moving the demo key out of the check does not work: a host refuses to start outside Development with a key containingdo-not-use-in-productionregistered. - Keep
[TraxAuthorize]on the trains you add. Mark one[TraxAllowAnonymous]only when anyone who can reach the host may call it.
Secure a GraphQL host covers the rest of a production posture.