Hi. We successfully store secrets in ansible variables files with either ansible-vault or sops. It is a good approach when Ansible itself configures something that requires a secret, such as configuring a database admin password.

But I’d like to ask you about how you store secrets meant to be used by applications. Example: we have a an application in PHP with a config.php file with all credentials needed by the application. Developers have a config.php setup to work with the test environment, while we maintain a different config.php for production in production machines. Nowadays this config.php file is stored in ansible repository, encrypted by ansible-vault or sops. We thought about moving the config.php production file to the application repository, so we could get advantage of the CI/CD pipeline.

It doesn’t smell right, because it would require to encrypt it somehow, and store keys to decrypt it in CI/CD, but I decided to ask you anyway what do you think of that and how you solved it yourselves.

Thanks!

You are viewing a single thread.
View all comments
0 points

Depends where you are deploying. If you’re deploying to AWS or Azure you can use their secret manager and replace the secret text in the config.php file with the path to the secret, then write a simple utility file to read the secret. If you are deploying to a Windows Server you can store an encrypted value in the registry and write a class to decrypt/read from the registry.

permalink
report
reply
1 point

Thanks for the answer. I’m actually deploying to a local Linux server. Is there any tool I could use?

permalink
report
parent
reply
0 points

You can probably write a utility in your PHP that just pulls the value from Ansible Vault and decrypts at runtime. Still not 100% secure but better than having the value in plaintext in your config.php.

permalink
report
parent
reply
0 points

Thanks. I would still have to store ansible-vault password locally or something like that, no?

permalink
report
parent
reply
0 points

We use Hashicorp Vault to do this. A local Agent on the box can get the secret for you on your behalf and either you can use that in your app launch process, or have the app call the agent or the vault server itself.

permalink
report
parent
reply
1 point

That is exactly what I’m looking now! Thanks! I’m actually new to this paradigm. How is it more secure than storing password in plain text? I mean, in your application, you’ll have to store a token or something, so you can query Vault server, right? If an attacker have access to the server, it can query the Vault server with the token, retrieving relevant secrets, no?

permalink
report
parent
reply

DevOps

!devops@lemmy.ml

Create post

Development & operations

Community stats

  • 3

    Monthly active users

  • 42

    Posts

  • 14

    Comments

Community moderators