Chapter 94: HashiCorp Vault and Secrets Management
94.12 Applications and CI — deliver without leaking
Story (fictional teaching scenario). At a fictional Chennai shop, Yuki from Osaka removes a debug command that prints every environment variable in CI.
Why
Even good secret storage fails if a consumer prints the value into build logs or artifacts.
What
- Vault Agent can help authenticate, renew supported identities and render templates under its configuration.
- Template rendering writes selected fields into a file; that file still needs restricted access and safe refresh/reload behaviour.
- In-memory use avoids a persistent file but does not eliminate process/crash-dump risks.
- Rotation needs consumers to refresh; a file changing does not automatically reopen an application’s database connections.
How
-
Use a scoped workload identity, not a human’s token.
-
Keep values out of command arguments, logs, test reports and images.
-
If rendering files, restrict access and test atomic replacement/reload.
-
Define safe behaviour when Vault is unavailable or renewal fails.
Example 1: Safe diagnostic output
- Read the command or request.
Bad diagnostic: print the complete secret response
Better diagnostic: print operation status and non-sensitive error category
- Read the result.
Output (illustrative; NOT executed against Vault)
config_refresh status=ok
config_refresh status=error category=permission_denied
- Line by line: The examples contain no secret or token. Do not log full events, environment dumps or connection strings. Masking in CI is useful but does not guarantee that a transformed secret stays hidden.
Example 2: Consumer refresh contract
- Read the command or request.
Agent updates restricted file -> app reloads -> new connections use new credential
Old credential retires after tested overlap policy
- Read the result.
Output (illustrative; NOT executed against Vault)
A refreshed file alone is not proof that existing connections switched.
- Line by line: The arrow sequence is an operational design, not executed automation. Coordinate old/new lifetimes and application support. Never lengthen access indefinitely just to hide a broken renewer.
Ravindra Bagale's Tip
A secret in an artifact is still a leaked secret.
Artifact मध्ये secret गेलं तरी ते leakच आहे.
Artifact में secret गया तो वह भी leak है.
Did you understand? Let us try it once more.