Is there a way to programmatically add secrets to config/credentials.yml.enc in Rails 5.2?
Pushing the credentials.yml.enc to the repository for internal use may be fine, but as soon as the app is used by other people, they require different secrets within their environment. Like the Oauth2 credentials will differ for each implementation.
Running the app within docker (for example) will require more manual interaction, and Docker-know-how than usual. In most cases the more secure way is only used if it isn't much more effort.
One will need to run docker exec <app-name> -it /bin/bash
first to be able to run rails credentials:edit
.
It would be way better to be able to fill the credentials file programmatically. One could for example provide a temporary credentials file like:
production:
postgresql:
username: 'admin'
password: 'very_insecure'
Then there could be a script adding the file's content to the credentials-file and deleting the temporary file afterwards.
For sure the RAILS_MASTER_KEY
environment variable must be set (could be again a script moving the content of the master.key file into the variable) to gain any profit of that.