The Setup

Every night, a snapshot job collects configuration from every node in the realm. It takes system units, proxy configs, firewall rules and scripts. It puts them into a private Git repository on my self-hosted forge. Before the job commits anything, it does three things:

  1. Scrubs secrets with a set of patterns: password = ..., token: ..., API keys in URLs, PEM private keys, password hashes, and so on.
  2. Runs gitleaks over the result. If gitleaks flags anything, the job does not commit.
  3. Sends a drift alert if it finds changes that I did not record on purpose. I record changes with a companion command, snapshot-now "what changed and why".

The Alert I Kept Seeing

“The nightly snapshot found changes that weren’t recorded.” This alert came night after night. Every time, the answer was the same: it was me. I changed something during the day and did not record it.

That is a process bug. The tooling was fine. The fix is boring: record every host change at the end of the task that made it. But the important part came when I finally read the diff line by line. Before that, I only shrugged.

The Line That Shouldn’t Have Been There

One of the changed files was a realm configuration for single sign-on on my hypervisors and backup server. The change itself was small: trailing whitespace. But the line was this:

	client-key <the actual OIDC client secret>

All the scrubber patterns looked for a key = value or key: value shape. This config format uses neither. It has the key, a space, and the value. The secret scanner did not see it either. So the job committed the client secret in plain text every night since I set up SSO.

The repository is private and self-hosted, so the blast radius was small. But “private” is not a security control. Also, the value was a password-style string that a person could guess. So it had to go.

Fix the Tool First

I gave the scrubber a new rule for the space-separated shape:

(re.compile(r"(?im)^(\s*client-key\s+)\S+"), r"\1<redacted>")

Then I ran the snapshot in dry-run mode. I grepped the work tree to make sure the rule redacted every copy. Only then did I let it commit. A new rule is only real when you see it fire on real data.

Rotate Without Breaking Anything

One SSO client and five consumers shared the secret. The consumers were the hypervisor realm on three nodes and the backup server realm on two. This was the rotation plan:

  1. Generate the new secret on the workstation, in memory only. It never touches a terminal, a log or a file. It goes to each host over SSH standard input.
  2. Update the identity provider first. Hash the secret inside the SSO container and write the digest into the client config. Run the provider’s own config validator. Restart only if the validation passes. If the validation fails, the old config comes back automatically. The consumers stay as they are.
  3. Update all five realms one after the other with the CLI of each product. Each CLI reads the secret from stdin.

The gap between steps 2 and 3 was a few seconds. Existing sessions did not change at all. The provider uses the client secret only when it exchanges a new login for tokens.

Prove It, Don’t Assume It

“It restarted fine” is no proof. Two checks gave me certainty, and I did not need a real login for them.

Fingerprints. On every host, I hashed the stored value and printed only the first 12 characters. Five identical fingerprints mean five identical secrets. Nobody ever sees the secret.

The token endpoint’s error codes. I sent a token request with a bogus authorization code on purpose:

  • With the new secret, the provider replies invalid_grant. Client authentication passed. The provider rejected only the fake code.
  • With any other secret, it replies invalid_client. Authentication failed.

This difference proves two things: the new secret works, and the old one is dead. After that, a real SSO login confirmed it.

Lessons

  • Read the diff. Interesting things hide in the drift alerts that you learned to ignore.
  • Secret scrubbing is pattern matching, and formats vary. Test your scrubber on every config format you collect. Do not test only the YAML and .env files that you had in mind.
  • Rotate as if the secret is public. Generate it unseen and change the authority first. Validate before you restart. Use evidence for the check, not vibes.
  • Fix the process too. Record changes when you make them. Then the alert fires only for things you did not do.