Security
Deployment Preview Secret Cleanup: Remove Credentials After Branch Environments Expire
Deployment Preview Secret Cleanup: Remove Credentials After Branch Environments Expire starts with credentials created for a branch preview that no longer exists. The preview secret may look quiet, but quiet is not the same as unused. It can still support a rare workflow, a contract, a rollback path, or an owner who no longer sits near the team doing the cleanup.
Use this note when you need to reduce stale software surface area without turning deletion into the first real test. The useful result is a small decision record: current owner, current purpose, evidence reviewed, reversible first step, caveats, and the rule that prevents the same preview secret from returning.
What makes this cleanup risky
The risk is not age. The risk is losing a dependency that is visible only during unusual conditions. In deployment preview secret cleanup, the review should start by naming the exact behavior the preview secret still enables and the exact behavior that has replaced it.
| Review area | What to inspect | Cleanup signal |
|---|---|---|
| Current owner | Team, service, data owner, or support path | Someone can approve a keep or remove decision |
| Runtime evidence | branch state, preview teardown logs, deployment config references, vendor token use, callback URLs, and copied data stores | Recent use is absent or explained |
| Replacement path | environment-scoped short-lived credential | The new path handles the same real cases |
| Rollback or history | Backup, audit, archive, or recreation plan | A wrong decision is recoverable |
| Creation path | How new items are created | A prevention rule can stop recurrence |
A cleanup candidate with no owner should not be treated as safe. It should be treated as an ownership bug that must be resolved before the final removal.
Evidence checks that fit the subject
Collect several signals before acting:
- Inspect branch state, preview teardown logs, deployment config references, vendor token use, callback URLs, and copied data stores.
- Confirm the replacement path, not just the absence of recent edits.
- Review the longest business, reporting, incident, or customer cycle that could still use the preview secret.
- Ask the owner to choose keep, narrow, archive, disable, remove, or investigate.
A focused review sample can keep the conversation concrete:
secret: PREVIEW_PARTNER_API_TOKEN
scope: branch-preview-only
last_seen: 2026-04-11
decision: revoke after data copy is destroyed
Treat the output as a candidate list, not a deletion command. It proves one slice of behavior and must be paired with ownership, dependency review, and a rollback plan.
Prefer a reversible first move
Good cleanup usually happens in stages. First stop creating new preview secret records or references. Then narrow the scope, disable the stale path, or archive the visible surface while watching for unexpected use. Remove only after the waiting window matches how the system is actually used.
Do not rush when the preview secret touches security response, customer commitments, billing, compliance, incident recovery, or low-frequency operational work. Also slow down when the replacement changed semantics rather than only names; similar labels can hide different behavior.
Prevention rule
preview environments should issue short-lived secrets with branch, owner, pull request, and expiration metadata. Add the rule where the preview secret is created, not only in a cleanup spreadsheet. The next cleanup should begin with owner and sunset context already attached.
Key takeaways
- Stale preview secret cleanup needs evidence about use, ownership, replacement, and reversibility.
- Recent silence is helpful, but it is not enough by itself.
- The best first move is usually narrowing, disabling, or archiving before final removal.
- Prevention belongs in the creation path so the same stale item does not return.