Ansible Vault Problems That Weren't Leaks: A Placeholder That Broke Every Deploy and a Password in the Wrong File

By Lars Nielsen ·

My search engine's servers were configured with Ansible, and their secrets lived in Ansible Vault files: database passwords, the admin password, API keys, encrypted in the repository and decrypted at deploy time. In mid-August, I cleaned up two problems in those files. Neither was a leak, but each was the kind of thing that makes the next leak, or the next outage, more likely.

A placeholder that broke every deploy

One entry in the shared vault file wasn't an encrypted value at all. It was the literal text PLACEHOLDER_REPLACE_WITH_REAL_ENCRYPTED_VALUE, left from whenever the entry had been added. It wasn't valid vault data, and any task that rendered the application's .env file failed with:

  • Vault format unhexlify error: Odd-length string

That step is part of every deploy that touches configuration, on every server. So it failed everywhere, every time.

What happened next is the useful part. The failure was hit repeatedly, while deploying unrelated changes, and each time it was worked around by patching the .env file on the server directly. The deploy tool designed to keep servers consistent was being bypassed by hand, over and over, because of one bad line nobody had stopped to fix. Each workaround took less time than the fix, and together they took far more.

The fix replaced the placeholder with a real random value, encrypted properly. Only three of the four servers used it: the frontend, the only one that serves the admin area publicly, had its own value that had been correct all along. So the placeholder blocked deploys, but never locked anyone out of the admin area.

Checking the fix the wrong way first

The first check after deploying the fix looked like a failure. docker exec ... printenv in the PHP container didn't show the new variable, even after rendering .env again, clearing the cache and recreating the container.

That was the wrong test, not a broken fix. The application never receives these values as container environment variables. The .env file sits in the project directory, mounted into the container, and Symfony's Dotenv component reads it from disk when the application boots. printenv shows the process environment, and the values were never meant to be there. The right check was to do what the application does: load the file with Dotenv's bootEnv() and look up the value the way the app would. That showed the new value. The other servers had byte-identical .env content, so the result carried over.

A day later, the roadmap entry for the problem was closed with one more check: rendering the configuration to a scratch path, rather than diffing it against the real file, completed cleanly. Full deploys no longer needed to skip the configuration step.

A secret-shaped value in a non-secret file

The second problem was the opposite kind. The project's vars.yml, documented as holding non-secret defaults, contained a plaintext database password. It wasn't used: the real configuration read the encrypted value from the vault, and nothing referenced the plaintext one. And it wasn't valid anymore either: it was a value that had already been rotated away after an earlier incident.

So it was harmless in the narrow sense. It was removed anyway, because a password-shaped string in a file labelled "non-secret" is exactly how secrets end up copied, committed and pasted somewhere they shouldn't be. The earlier incident, the one that forced that password's rotation, had started with a secret in a place it shouldn't have been.

What generalises

Three habits came out of this:

  • A placeholder in a secrets file should fail loudly in one place, or not exist. If a workaround becomes routine, fix the cause the second time you need the workaround, not the tenth.
  • Verify configuration the way the application reads it. For a Symfony app with a .env file, that's Dotenv, not the container's environment.
  • Keep secrets out of files that are labelled non-secret, even dead ones. A file's label is what people trust when they copy from it.

The same project had another lesson about where secrets end up: a database password in a command line, visible to every user on the server.

Filed under

Leave a comment

Comments are reviewed before they appear.

Basic HTML allowed: links, emphasis, code and lists. Web addresses become links automatically.