Config Is Not a Secret
Settings and secrets both arrive as environment variables, but they need different care. How to tell them apart and where each one should live.
One mechanism, two kinds of value
A server needs values it should not hard-code: which region it is in, which features are switched on, and the keys to outside services. On Cloud Run, and on this site, all of them reach the code the same way, as environment variables read with process.env.NAME.
That shared mechanism hides an important difference.
| Configuration | Secret | |
|---|---|---|
| Examples | Site address, feature switches, limits, time windows | API keys, passwords, signing secrets, tokens |
| If someone sees it | Nothing happens | They can act as you |
| Can be in Git? | Defaults and examples, yes | Never |
| Can appear in logs? | Yes | Never |
| Needs rotation? | No | Yes, regularly and after any leak |
The rule of thumb
Ask: if this value were printed on a public page, could anyone do something with it? If yes, it is a secret. If no, it is configuration.
On this site, the code reads around fifty environment variables. Most are configuration: limits for the AI mentor, the analytics address, how many days before a visa page counts as stale, whether paid sections are switched on. About a dozen are secrets: admin passwords, the key that protects scheduled jobs, keys for email, payments, analytics and the AI model, and the secret that verifies payment webhooks.
Where each kind lives
Locally: a .env file in the project folder, which Git ignores. A committed .env.example lists every variable name with a harmless placeholder, so a new machine can be set up without guessing. The example file is the documentation; the real file never leaves the laptop.
In production, configuration can be plain Cloud Run environment variables. They are visible to anyone with view access to the service, which is fine for configuration.
Secrets in production belong in a dedicated secret store (Secret Manager on Google Cloud), with Cloud Run reading them at start-up. The next chapter covers the move.
Safe defaults
Configuration should fail safe when it is missing:
- a switch that is unset should mean the safer behaviour. On this site, the paid-content switch is explicit: only the exact value
offturns paywalls off, and a test pins that rule; - a missing secret should stop the feature that needs it, loudly, instead of running unprotected. The scheduled health job answers 503: the secret is not set rather than accepting anyone;
- the server should start even when an optional service's key is missing, with that one feature disabled.
Never log a secret
Error messages love to include "the request that failed", and requests contain headers, and headers contain keys. Habits:
- log the name of a missing setting, never its value;
- when showing setup commands in a dashboard, show placeholders. This site has a test that fails if a setup command in Ravi OS contains anything that looks like a real token;
- treat any secret that appears in a log as leaked, and rotate it.
Compare secrets safely
When code checks a secret, for example a key sent in a request header, compare in constant time (crypto.timingSafeEqual in Node) rather than with ===. An ordinary comparison stops at the first wrong character, and the timing difference can leak the secret one character at a time.
Try it yourself
List every environment variable your service reads (search the code for process.env.). Mark each one config or secret with the rule of thumb above. Every secret that is not in a secret store is your next task.