17.3.2.4 Production Secret Discipline
A focused guide to Production Secret Discipline, connecting core concepts with practical Docker and container operations.
Production secret discipline covers the personal, operational habits of anyone who handles a genuine production credential directly, shell history, terminal scrollback, screen sharing, clipboard managers, which are entirely separate from the system-level mechanisms, secrets managers, mounted files, that protect credentials within the infrastructure itself, since a credential can leak through an operator's own human workflow even when every system-level control is configured perfectly.
Shell history as an overlooked exposure path
A secret value typed directly into a terminal, even briefly, for a quick manual test or a one-off operation, is recorded in shell history by default, persisting on disk indefinitely unless explicitly prevented:
export DB_PASSWORD=supersecretvalue
history -d $(history | tail -1 | awk '{print $1}')
export HISTCONTROL=ignorespace
export DB_PASSWORD=supersecretvalue
Configuring HISTCONTROL=ignorespace and then prefixing any command containing a sensitive value with a leading space prevents it from being recorded in history at all, which is a more reliable habit than remembering to manually delete a specific history entry after the fact.
Terminal scrollback and logging tools
Beyond shell history, a terminal's own scrollback buffer, and any tool that records terminal sessions for later review or audit purposes, can retain a secret value displayed on screen even if it was never actually typed as a command argument:
cat /run/secrets/db_password
Running a command like this to verify a secret's presence prints its value directly to the terminal, which then exists in scrollback and any session recording for as long as that retention lasts; checking presence and length without printing the actual value, as covered in dedicated verification practices, avoids this exposure entirely.
Screen sharing and pairing session risk
A terminal session shared during a screen-sharing call, a pairing session, or a recorded demo carries the same exposure risk as scrollback, amplified by however many people are watching live or could later review a recording; being deliberately mindful of what is on screen before running any command that might reveal sensitive output is a habit worth maintaining specifically during these higher-visibility situations:
clear
docker exec my-api sh -c '[ -s /run/secrets/db_password ] && echo present'
Clearing the screen before and after any operation involving sensitive material, and preferring presence checks over value-revealing commands specifically during a shared session, reduces this exposure window directly.
Clipboard managers and secret persistence
Many modern clipboard managers retain a history of everything copied, sometimes for an extended period and synced across devices, which means copying a secret value, even briefly, to paste it somewhere else can leave that value persisted in a clipboard history tool entirely outside of any system the original secret was meant to be protected by:
echo "supersecretvalue" | xclip -selection clipboard
Being aware of whether a clipboard manager with history retention is active, and clearing clipboard history after pasting a genuinely sensitive value, or avoiding the clipboard for secrets entirely in favor of a more direct, non-clipboard transfer mechanism where feasible, closes this specific, easily overlooked exposure path.
Browser developer tools during API debugging
Debugging an API integration directly through browser developer tools can reveal a request header or body containing a credential, and that network request history persists in the browser's own developer tools session, and potentially in exported HAR files saved for later analysis or shared with a colleague for troubleshooting:
Authorization: Bearer sk_live_abc123
Reviewing and redacting any sensitive header or body content before exporting or sharing a HAR file or network request log avoids inadvertently distributing a live credential through what is meant to be a routine debugging artifact.
Establishing personal habits as a documented practice
Because these risks stem from individual, human workflow rather than system configuration, documenting expected personal practices explicitly, as part of onboarding or a security guidelines document, rather than assuming everyone will independently arrive at the same careful habits, makes the expectation explicit rather than left to individual judgment alone:
# Security practices for handling credentials
- Never print a secret's full value to the terminal; check presence and length only.
- Prefix any command containing a sensitive value with a leading space (HISTCONTROL=ignorespace).
- Clear the screen before and after any sensitive operation during a shared session.
- Redact credentials from any exported HAR file or log before sharing.
Responding when a personal-workflow leak is suspected
If a secret is suspected to have been exposed through one of these personal-workflow paths, terminal scrollback visible during a recorded call, a clipboard sync, an unredacted HAR file shared with someone outside the immediate team, the response is identical to any other confirmed credential leak: treat it as compromised and rotate it immediately, rather than assuming the exposure was too brief or too informal to matter.
vault write database/rotate-root/my-postgres-db
Common mistakes
- Typing a secret value directly as a command argument without taking any steps to prevent it from being recorded in shell history.
- Printing a secret's actual value to verify its presence, rather than checking only its presence and approximate length.
- Not being deliberately careful about what is visible on screen during a screen-sharing call or recorded pairing session specifically.
- Copying a secret value to the clipboard without considering whether a clipboard manager with persistent history retention is active.
- Sharing an unredacted HAR file or browser network log containing a live credential during routine API debugging.
Production secret discipline addresses the human, individual-workflow side of credential protection, shell history, scrollback, screen sharing, clipboard managers, browser debugging tools, that no system-level secrets manager or mounted file mechanism can fully protect against on its own, and treating any suspected exposure through one of these paths with the same seriousness as any other confirmed leak, immediate rotation, is the necessary, consistent response regardless of how informal or brief the actual exposure might have seemed.