Dando Mando Nogger
Dando Mando Nogger

Reputation: 157

Looking for ways to encrypt password in text files on ruby on rails

I'm looking for a way to encrypt the database password that shows on the database.yml file on a ruby on rails application, any ideas how I could make this? Something like this:

development:
  adapter: sqlserver
  mode: dblib
  database: db name
  host: host
  port: xxxx
  username: teste
  password: encryptedpass

Upvotes: 0

Views: 526

Answers (2)

Deepak Mahakale
Deepak Mahakale

Reputation: 23671

You can use Environment variables

development:
  adapter: sqlserver
  mode: dblib
  database: db name
  host: host
  port: xxxx
  username: <%= ENV['DATABASE_USERNAME'] %>
  password: <%= ENV['DATABASE_PASS'] %>

There's a good gem dotenv if you need to manage lot of ENV variables

Upvotes: 1

user229044
user229044

Reputation: 239382

You can use https://github.com/Shopify/ejson to add encrypted secrets to your app. It uses a public/private key pair to allow you to encrypt your secrets such that only your deployment environment can read them.

After generating your keys, you would place your plain text string your secrets.production.ejson file, then run ejson encrypt <path/to/secrets.production.ejson>, which would encrypt any unencrypted values. You can then safely add the results to source control.

You can then load the ejson file and makes its contents available via ENV, and use key: <%= ENV['...'] %> in your YAML files to read the decrypted values.

Upvotes: 0

Related Questions