Secrets Via Environment
Pass credentials through the environment so they never appear in process arguments or config files
Use when: a tool server needs a token to call an external service on the agent's behalf
Avoid when: the server needs no credential and reads only local files
Procedure
- Identify every credential the server needs at runtime
- Read each one from the environment inside the server, failing clearly when absent
- Keep the value out of argv, config files and log lines
- Ensure error messages never echo the value back
- Set the variables in the launching environment, not in a committed file
- Verify the server refuses to start when a required variable is missing
Signals
- the server fails fast with a message naming the missing variable, not its value
- process listings show no credential
- logs contain no token material after a failure
- the config file holds a reference, never the secret
Patterns
1. Read at startup
token = os.environ["HUNT_TOKEN"]
2. Clear failure
missing HUNT_TOKEN in environment; refusing to start
3. Redacted log
token: [set] or [unset]
Pitfalls
- Passing a token as a command line argument where every process can read it
- Logging the full request headers when an error occurs
- Using a default placeholder secret that silently works in production
Done when
- no credential appears in argv, config or logs
- a missing variable produces a clear startup failure