Gary like Bubble Tea!
Tags

Manage rails 6 credentials for multi environments

2021-08-23

The idea of using a credential file to manging all credentials is smart. In the past, for example, everytime we added a new third party API integration, we have to remember to share the api key to your colleague or deploy to the cloud. It caused problems. Like your colleague can't run up the App after pulling the new code. Tests can't be passed in the CI. The worst part is the production server is down because the key is missing or misplaced. And people forget things! However, all these problems have been solved by this feature. Now, all we need to handle is one key only.

However, sharing the master.key to everyone is dangerous. We should avoid it. In this post, I want to share a thing the documentation hasn't mentioned yet.

We can easily generate a "development" only credential by running this command:

$ rails credentials:edit --environment development

This command generates two files: config/credentials/development.key and config/credentials/development.yml.enc. Remember to add config/credentials/development.key into .gitignore and remove config/credentials/development.yml.enc from .gitignore. Afterward, we can just share development.key with coworkers and only use testing or development credentials there.

Hope this post help you!

© 2021 Gary Lai. All rights reserved

TwitterGithub