Member-only story

Rails 6: Setup Multi Environment Credentials

Rutger
3 min readMay 29, 2021

--

Since Rails version 5.2, it is possible to use Rails Credentials. Credentials is a way of storing secrets so that not just anyone can access your application credentials such as AWS or google account details.

Before Rails 6 multiple environment credentials, we had to do something like this:

development:
google:
username: production-username
password: production-password
production:
google:
username: production-username
password: production-password

This displays the credentials for each environment in one file, which can be a security risk. Now with Rails 6 we can finally separate Credentials per environment, which makes it a lot easier.

This article will explain how to use Rails Credentials and how to set it up for each environment (development/production).

Create a new application

We start by creating a new rails app, by using the following command.

rails new CredentialsTestApp

Default credentials

Once our app is created, Rails automatically creates the config/credentials.yml.enc and config/master.key files. To prevent that the master.key to be pushed into the remote repository Rails also…

--

--

Rutger
Rutger

Written by Rutger

Software Engineer in Tokyo

No responses yet

Write a response