Appearance
ADR-2490: Fail-Fast Startup Validation of Required Settings
- Status: Accepted
- Date: 2026-09-30
- Authors: @fderuiter, Claude Code
- Deciders: @fderuiter
- Requirements: PRD-SYS-190
1. Context & Problem Statement
Most required settings already stop a service at boot:
GATEWAY_SECRET(ADR-2256)OIDC_AUTHORITYon the gateway- the PostgreSQL connection string outside Development
Two settings still failed late or silently:
- Demographics encryption key (execution):
DemographicsEncryption__KeyBase64defaulted to an empty string, and the service started without it. The first subject registration then failed deep in AES-GCM. - Service addresses (gateway): a missing
<SERVICE>_SERVICE_URLfell back tohttp://localhost:<port>in every environment. A deployment that forgot one kept running and forwarded that service's traffic to localhost.
2. Decision Drivers & Constraints
- A misconfigured deployment should fail when it starts, with a message that names the setting.
- No secret or key may appear as a literal default in source (
01_spec.md§3). - Local development stays zero-config for the settings that are only addresses.
3. Options Considered
Option 1: Keep the defaults and log a warning
- Cons:
- ❌ A warning in a startup log is easy to miss, and the service still takes traffic it cannot serve.
Option 2: Validate required settings at startup (Selected)
- Overview:
- Execution:
DemographicsEncryptionOptionsis bound withValidateOnStart(). The key must be Base64 that decodes to 16, 24 or 32 bytes in every environment, because there is no safe default key. - Gateway: a missing
<SERVICE>_SERVICE_URLfalls back to localhost only in Development. Anywhere else startup fails. A value that is not an absolute http or https URL fails startup in every environment.
- Execution:
- Pros:
- ✅ Follows the pattern
GATEWAY_SECRETalready uses. - ✅ The error names the setting and how to generate a key.
- ✅ Follows the pattern
- Cons:
- ❌ Every host that runs the execution service needs a key, test hosts included.
4. Decision Outcome
- Chosen Option: Option 2.
- Justification: It turns two late or silent failures into a clear error at boot, with no new dependency.
5. Consequences & Trade-offs
- Positive Impact:
- A missing demographics key or service address is found at deploy time, not by a site user.
- Negative Impact / Technical Debt:
- Test hosts call
UseTestDemographicsKey()fromCadence.Testing, and the OpenAPI exporter supplies a throwaway key. - The Aspire AppHost does not yet pass a demographics key to the execution service, so running through it needs
DemographicsEncryption__KeyBase64set in the environment.
- Test hosts call
6. Implementation & Verification
- Affected Repositories / Services:
apps/execution/src/Program.cs,apps/execution/src/Infrastructure/Security/DemographicsEncryptionOptions.csapps/gateway/src/Program.cspackages/testing/src/Security/TestSecurityContext.cs,packages/tooling_core/src/Cadence.OpenApiExporter/Program.csdocs/ENVIRONMENT_VARIABLES.md,apps/execution/README.md,apps/gateway/README.md,.env.example
- Verification Plan:
tests/Cadence.UnitTests/Execution/Security/DemographicsKeyStartupValidationTests.cschecks that an empty, non-Base64 or wrong-length key stops the host at startup.tests/Cadence.UnitTests/Gateway/GatewayServiceUrlValidationTests.cschecks that the gateway will not start outside Development without service addresses, or with a relative address.