r/platformengineering • u/NoDevelopment206 • 7d ago
how do you rotate api keys and secrets without anything breaking
every time a key needs to change it feels risky. you update it in one place and some service still has the old one cached and starts failing. do you support two valid keys at the same time for a while or just do it fast and watch the logs. also curious if anyone actually rotates on a schedule or only when something leaks
9
Upvotes
5
u/cyb3rstrik3 6d ago
Green-Blue deployment strategy spin up an identical copy of your production stack with the new keys, then swap the load balancers to the new stack, and you can dispose of the old one.
15
u/Starks1293 7d ago
two valid keys at once, always. doing it fast and watching logs is how u find the one cron job that runs monthly lol
the order that doesnt break things
this is exactly how secrets manager rotation works for databases, it alternates between two users so one is always valid
on schedule vs only on leak, rotate on a schedule mostly so the process stays exercised. if u only rotate after a leak thats the first time u find out it takes 2 days and breaks 4 services. better still is not having long lived keys at all where u can, oidc for ci, workload identity or irsa for pods, dynamic db creds from vault. whats left gets rotated every 90 days or so
2
u/nilarrs 5d ago
In kubernetes secrets are mounted as environment vars. Atleast most commonly. You update the secret in kubernetes then restart 1 pod at a time. Envvars only update on pod restart. You can then cycle through high availability one at the time
1
u/Flashy-Bus1663 21h ago
If you can help it consider moving to like jwt with with like workload identity it even works with 3rd parties assuming oauth endpoints and jwks are public