fix(config): require TLS credentials only when TLS_ENABLED is not false#257
Merged
Merged
Conversation
Production required TLS_KEY and TLS_CERT whenever NODE_ENV=production, with
no TLS_ENABLED condition, even though startApplicationRuntime already skips
certificate loading and the HTTPS listener entirely when TLS terminates at
the platform edge. The service therefore had to carry two real certificates
that are never read, purely to satisfy a validator that should not have been
asking for them.
Add TLS_ENABLED to the schema and gate the certificate requirement on it,
mirroring config/index.js:84 semantics where any value other than 'false'
enables TLS. The runtime already implemented the intended behavior; only the
validator disagreed.
before: NODE_ENV=production TLS_ENABLED=false, no certs
-> Config validation error: "TLS_KEY" is required
after: -> boots
TLS enabled without certificates still rejects, in production and nowhere
else. Both contracts are pinned by unit tests so they cannot regress.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
src/utils/validateEnvVars.jsrequiredTLS_KEYandTLS_CERTwheneverNODE_ENV=production, with noTLS_ENABLEDcondition.src/app.js:14runs thevalidator before
startApplication, so it could not be bypassed.Meanwhile
src/server/startApplicationRuntime.js:87-101already skipscertificate loading and the HTTPS listener entirely when TLS terminates at the
platform edge. The result: production carries two real certificates that are
never read, solely to satisfy a validator that should not be asking.
Reproduced on
mainbefore this change:The second line is the tell: the validator only checks that the strings exist,
never that they are usable. It was buying no safety.
Change
Add
TLS_ENABLEDto the schema and gate the certificate requirement on it,mirroring
config/index.js:84(process.env.TLS_ENABLED !== 'false'), so thevalidator and the runtime finally agree. The runtime is unchanged — it was
already correct.
TLS_ENABLEDis constrained totrue/false, matching the existingAPI_AUTH_ENABLEDconvention in the same schema, so a typo likeTLS_ENABLED=disabledfails fast at boot instead of silently enabling TLS.Verification
Both contracts are pinned by unit tests. Six cases added: certs not required
when disabled; required when enabled; required when unset;
TLS_CERTrequiredindependently of
TLS_KEY; invalidTLS_ENABLEDrejected; non-productionunaffected.
Full unit lane 808/808, lint and typecheck clean.
Safety
Additive only. No environment variable is added, removed or changed on the
service by this PR — the live certificates stay exactly where they are and the
service keeps booting whether or not they are present. Retiring them is a
separate, later step that depends on this being live and healthy first.