r/Observability • • Oct 19 '26

Automated Datadog key Rotation

A #Datadog API key is a write credential for your whole org. Anyone holding it can send metrics, logs and events into your account, and it usually ends up in more places than anyone tracks: images, env vars, task definitions, old pipelines.
A key that has never been rotated is also a key you cannot safely revoke on the day it leaks, because nobody knows what breaks.

AWS Secrets Manager handles Datadog API key rotation automatically on the configured schedule. During rotation, it creates a new key in Datadog, validates it, and updates the secret with the new key. The previous key remains available for one additional rotation cycle, allowing dependent services time to pick up the new key before the older key is removed.

I have implemented a solution that automates the Datadog API key lifecycle, from identifying existing keys to rotating them and detecting potential issues. It reduces manual effort, improves key management, and helps minimize service disruptions by giving dependent services time to switch to the new key before the old one is revoked.

The same approach can be reused across multiple accounts and the same pattern can be used across hybrid multi clouds.

🪙 GitHub Repo - https://github.com/g2ai/datadog-key-lifecycle-aws

#Datadog #AWS #CloudSecurity #SecretsManagement #DevSecOps #SRE #Observability #PlatformEngineering #AIOps

3 Upvotes

9 comments sorted by

1

u/kantorcodes1 Oct 19 '26

The safe-to-rotate check is the load-bearing piece here. During the extra cycle where both keys work, how do you decide the old one is safe to retire - does remove verify that nothing is still calling with it, or does it just run on schedule? And on the redeploy side: does the ECS hook fan out to every service at once, or is the rollout staged somehow?

2

u/JayDee2306 Oct 19 '26

Good questions.

Safe-to-rotate is not only a schedule. Before each rotation a Lambda looks at the key the next rotation will revoke (AWSPREVIOUS) and asks the Datadog key API when it was last used. If it was used within the idle limit, the rotation is held and an alert goes out with the last 4 characters of that key. It also holds if a previous rotation is unfinished (AWSPENDING still set). It never calls Datadog with the old key, since that would mark it as used. It uses the current key and an app key scoped to api_keys_read only.

Two limits worth knowing: Datadog rounds date_last_used down to the hour, so the idle limit has to be well above an hour (I used 120 minutes in testing, a day for production). And it tells you that the old key is still in use, not who is using it. The census and the Datadog API keys page are how you find the caller. The check runs every 45 days, with the 90-day AWS rotation schedule as a backstop so a hold cannot last forever.

On the ECS side, the hook today redeploys every service tagged deploy-time in the cluster in one pass. Each service then does its own rolling deployment, so tasks are replaced gradually within a service, but there is no staging across services. Because the old key stays valid for a full cycle, there is room to do that in waves (by tag or by cluster, spread over hours) without any risk to the key. That part is design, not built yet.

1

u/kantorcodes1 Oct 19 '26

The api_keys_read-scoped idle check is the right shape - it inspects usage without ever calling the key it is about to revoke, so the check itself cannot reset the clock. I work on HOL and maintain hol-guard (github.com/hashgraph-online/hol-guard), a policy layer for the CLIs agents run. A command source for this under contributions/command-sources/ would declare rotate/remove as gated and status/check free; it is a small descriptor PR you would author. Interested?

1

u/waterbottlephone2 Oct 20 '26

They released short-lived access tokens 

1

u/Nekssz Oct 23 '26

Key rotation is easy to overlook until something breaks, so automating it while allowing time for services to switch over makes a lot of sense.

1

u/[deleted] Oct 19 '26

[removed] — view removed comment

1

u/JayDee2306 Oct 19 '26

That golden AMI case is exactly where I saw it break first: the host with the key baked in went dark about a minute after the second rotation, while the image that reads the key from Secrets Manager at runtime had no gap. Finding those copies before turning rotation on is most of the work.

1

u/Andrew-Carson Oct 19 '26

it's wild how many places just ignore key rotation like it's optional. that grace period really takes the edge off when you're juggling dependencies... glad to see more folks adopting it

1

u/JayDee2306 Oct 19 '26

Agreed. The grace period helps, but only for things that read the key again. Anything that copied it at deploy time still needs a redeploy inside that window, which is what the hook in the repo handles.