SECURITY ENGINEERING · PART 9 · DEVSECOPS AND SUPPLY CHAIN · SECRETS · 130 OF 229

Secret Rotation and Short-Lived Credentials

The best defence against a leaked secret is a secret that is already worthless. This episode covers managing secrets at runtime: secret managers and vaults, dynamic secrets created on demand and expired automatically, workload identity and OIDC federation so CI and cloud workloads need no stored keys, and how to migrate from static secrets to short-lived ones that make rotation and leaks almost a non-issue.

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 9
  9. 10
  10. 11
  11. 12
  12. 13
  13. 14
  14. 15
  15. 16
  16. 17
  17. 18
  18. 19
  19. 20
  20. 21
  21. 22
  22. 23
  23. 24
  24. 25
  25. 26
  26. 27
  27. 28
  28. 29
  29. 30
  30. 31
  31. 32
  32. 33
  33. 34
  34. 35
  35. 36
  36. 37
  37. 38
  38. 39
  39. 40
  40. 41
  41. 42
  42. 43
  43. 44
  44. 45
  45. 46
  46. 47
  47. 48
  48. 49
  49. 50
  50. 51
  51. 52
  52. 53
  53. 54
  54. 55
  55. 56
  56. 57
  57. 58
  58. 59
  59. 60
  60. 61
  61. 62
  62. 63
  63. 64
  64. 106
  65. 107
  66. 108
  67. 109
  68. 110
  69. 111
  70. 112
  71. 113
  72. 114
  73. 115
  74. 116
  75. 117
  76. 118
  77. 119
  78. 120
  79. 121
  80. 122
  81. 123
  82. 124
  83. 125
  84. 126
  85. 127
  86. 128
  87. 129
  88. 130
  89. 131
  90. 132
  91. 133
  92. 134
  93. 135
  94. 136
  95. 137
  96. 138
  97. 139
  98. 140
  99. 141
  100. 142
  101. 143
  102. 144
1 / 10

Press play to hear the narration, or step through at your own pace.

Key takeaways

  • Secrets in a manager, not code
  • dynamic secrets expire on their own
  • workload identity and OIDC need no stored key

Notes

Secret managers

The baseline every team should reach is a secret manager. Instead of secrets in code or config files, they live in a central store, Vault or the cloud providers' secret managers, with access control, auditing and versioning. Applications fetch what they need at runtime, so no secret is committed. This alone gives central rotation, revocation and a full audit log. It is the foundation, but it still stores long-lived secrets, and the next steps reduce even that.

The baseline
  • a secret manager stores secrets centrally with access control and audit
  • apps fetch at runtime; secrets never sit in code or config
  • tools: HashiCorp Vault, AWS Secrets Manager, Azure Key Vault, GCP Secret Manager
  • central rotation, central revocation, full audit log

Dynamic secrets

The first big step up is dynamic secrets. Rather than one shared, static database password every instance uses forever, a tool like Vault creates a unique database user on demand per application instance, valid for an hour, and revokes it when that lease ends. There is nothing to rotate, because the credential never lives long enough to matter, and a leaked one expires by itself within the hour. The same pattern works for cloud credentials and certificates. Dynamic secrets make rotation automatic.

Secrets made to order
  • instead of one shared static DB password, Vault creates a unique DB user per app instance, valid for an hour
  • it is auto-revoked when the lease ends
  • no rotation needed: they never live long enough to matter
  • a leak expires by itself

Workload identity

The best step of all is to store no secret. With workload identity, a workload proves who it is using the platform's identity, a cloud instance, a Kubernetes pod, a serverless function, and receives a short-lived token for exactly what it needs. Cloud roles for instances, pods and functions work this way: the machine's identity is the credential, so there is no key to store, leak or rotate. This is the modern default in cloud, and it removes the static access keys behind so many breaches.

No credential to store
  • the workload proves WHO it is (its platform identity)
  • and receives a short-lived token for what it needs
  • cloud: IAM roles for instances, pods, functions (IRSA, workload identity)
  • nothing is stored; nothing to leak or rotate
  • the modern default in cloud

OIDC federation in CI

The same idea solves a classic weak spot: pipeline credentials. The old way stored a long-lived cloud access key as a CI secret, a huge target, because whoever steals it can act in your cloud account. With OIDC federation, the CI system, such as GitHub Actions, proves its identity to the cloud with a short-lived token, and the cloud hands back temporary credentials. No long-lived key is stored anywhere. This should be the default for any pipeline that touches a cloud account.

Keyless CI to cloud
  • old way: a long-lived cloud key stored as a CI secret (a huge target)
  • OIDC federation: the CI system proves its identity with a short-lived token
  • the cloud trusts that identity and issues temporary creds
  • GitHub Actions, GitLab -> AWS, Azure, GCP; no stored key

Migrating

You do not get there overnight; migrate in stages. First, get secrets out of code into a secret manager, the highest-value move. Second, rotate the long-lived secrets you have and automate it. Third, replace static cloud access keys with workload identity. Fourth, adopt OIDC federation in your pipelines so no cloud key is stored in CI. Fifth, move databases and services to dynamic secrets. Each stage meaningfully cuts risk, so there is value even partway.

A migration path
  1. get secrets out of code into a secret manager
  2. rotate the long-lived ones, automate it
  3. replace static cloud keys with workload identity
  4. adopt OIDC federation in CI
  5. dynamic secrets for databases and more each stage cuts risk

Why this wins

Why is this the direction everything is moving? Because short lifetimes change the game. A leaked credential expires on its own, quickly, so a leak is no longer a crisis. Rotation becomes automatic rather than a quarterly chore. You have far fewer long-lived secrets to guard. And every access is tied to an identity and audited. The ideal is that nothing static lives long enough to be worth stealing, which makes most of the secret incidents from the last two episodes stop happening.

The payoff
  • a leaked secret expires on its own, fast
  • rotation becomes automatic, not a quarterly chore
  • far fewer long-lived secrets to inventory and guard
  • every access is identity-based and audited
  • the ideal: nothing static long enough to be worth stealing

Common mistakes

Mistakes. Storing long-lived cloud keys in CI when OIDC federation would remove them entirely. Treating a secret manager as a dumping ground for static secrets that are never rotated, which is better than code but not the goal. Using static access keys where workload identity would work. Having no automated rotation. Setting very long token lifetimes, which throws away the main benefit of short-lived credentials. And printing secrets into logs, undoing all the careful storage in one line.

Avoid these
  • long-lived cloud keys in CI instead of OIDC federation
  • a secret manager used as a dumping ground, never rotated
  • static keys where workload identity would work
  • no automated rotation
  • very long token lifetimes, losing the benefit
  • secrets printed in logs

Say it like this

In the interview: the baseline is a secret manager with secrets fetched at runtime, never hard-coded, giving central rotation, revocation and audit. But I push toward short-lived credentials. I use workload identity so cloud workloads have no stored key, OIDC federation so pipelines reach the cloud without a long-lived key, and dynamic secrets so databases hand out per-use credentials that expire in an hour. The goal is that nothing static lives long enough to be worth stealing.

In the interview
  • "Secrets in a manager, fetched
  • at runtime, never in code.
  • Then push toward short-lived: workload identity so there is no stored key, OIDC federation
  • for CI to cloud, and dynamic
  • secrets for databases. A leaked short-lived credential
  • expires on its own, so rotation is automatic."

Interview questions

Q1What is a secret manager?

A system that stores secrets centrally with access control, auditing and versioning, so applications fetch them at runtime instead of hard-coding them. Examples include HashiCorp Vault and the cloud providers' secret managers. It enables central rotation, revocation and audit.

Q2What are dynamic secrets?

Credentials generated on demand for a specific consumer and automatically revoked after a short lease, such as a unique database user created per application instance for one hour. Because they are short-lived and unique, rotation is automatic and a leak expires on its own.

Q3What is workload identity?

A mechanism where a workload authenticates using its platform identity, such as a cloud instance, Kubernetes pod or serverless function role, and receives short-lived tokens for the resources it needs, so no static credential is stored, leaked or rotated.

Q4What is OIDC federation for CI/CD?

A method where a CI system proves its identity to a cloud provider with a short-lived OIDC token and receives temporary credentials, instead of storing a long-lived cloud access key as a CI secret. It removes one of the most dangerous stored credentials.

Q5Why are short-lived credentials more secure than static ones?

Because a leaked credential expires quickly on its own, rotation becomes automatic, there are far fewer long-lived secrets to protect, and every access is tied to an identity and audited. The window in which a stolen secret is useful shrinks dramatically.

Q6How do you migrate from static to short-lived credentials?

In stages: move secrets from code into a secret manager, automate rotation of long-lived secrets, replace static cloud keys with workload identity, adopt OIDC federation in pipelines, and introduce dynamic secrets for databases and services. Each stage reduces risk.

Q7Is a secret manager alone enough?

It is the essential baseline and far better than secrets in code, but on its own it still stores long-lived secrets. Combining it with dynamic secrets, workload identity and OIDC federation reduces or eliminates long-lived credentials, which is the stronger position.

Q8Why avoid long token lifetimes with short-lived credentials?

Because the security benefit comes from the short lifetime: a token valid for many hours or days behaves much like a static secret, giving an attacker a long window of use. Keeping lifetimes short preserves the automatic expiry and rotation benefits.