Skip to content

About

a secure dotenv–from the creator of `dotenv`

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Latest commit

 

History

39 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dotenvx

The secure dotenv–from the creator of dotenv.

  • Encrypt
  • Commit
  • Ship

Install · Quickstart · Changelog

Quickstart

gem install dotenvx

Create a .env file next to your Ruby script.

# .env
HELLO=World
# index.rb
require "dotenvx"

Dotenvx.load

puts "Hello #{ENV["HELLO"]}"

Run the script from that directory.

ruby index.rb
# Hello World

 

Rails Quickstart

Add dotenvx-rails to your Gemfile:

gem "dotenvx-rails"

Then install it:

bundle install

Dotenvx automatically loads your environment when your Rails app boots, before application configuration. You do not need to call Dotenvx.load yourself.

Rails uses the same file selection as the other SDKs, with no automatic layering: DOTENV_FILE (or DOTENV_PATH) selects the files to load. Otherwise, exported private-key names select their matching files (for example, DOTENV_PRIVATE_KEY_PRODUCTION selects .env.production); without either, Dotenvx loads .env. RAILS_ENV=production alone does not select .env.production. Paths are resolved from your Rails app root. Layering is opt-in through DOTENV_CONVENTION.

 

Usage

Install dotenvx.

$ curl -sfS https://dotenvx.sh | sh
◈ installed (2.38.2:/usr/local/bin/dotenvx)

Encrypt your secrets in .env files. The values become ciphertext and only your private key can unlock them.

$ dotenvx encrypt
◈ encrypted .env (039 BCA) via .env.keys ⛉

Commit the encrypted .env with your code. Keep the generated .env.keys file out of version control.

$ git add .env
$ git commit -m "encrypt .env"

Ship your code and secrets together. For this .env file, set DOTENV_PRIVATE_KEY in your deployment environment to the matching key from .env.keys. Dotenvx uses it when your app starts.

$ ruby index.rb
⟐ injected env (2) from .env (039 BCA) via .env.keys ⛉

 

Design

Three widely used and proven primitives make up Dotenvx's design. Git, .env, and secp256k1.

We chose git because it is the best way to deliver digital goods. It is the container ship of the digital world. All code travels on its ships. Why not secrets? Why invent an inferior secrets delivery mechanism when the world class one is right there at your fingertips.

We chose .env because it is the open standard for loading secrets into code. It represents environment variables, the core primitive that all secrets end up injected into at runtime of code.

Lastly, we needed to choose an encryption algorithm. Encryption of the values inside the .env file would allow us to place those values with code, leveraging git's distribution advantages while still following the twelve-factor config – by separating the decryption key from the code (environment).

It was important that we choose a proven, simple, asymmetric standard with small keys. We chose secp256k1, battle-tested by Bitcoin for more than seventeen years. We made cryptography an opinionated choice so developers wouldn't have to. Encryption just worked.

The result is a system built entirely from primitives, developers already understand, and infrastructure they already use. Secrets can travel with code without becoming part of the code. Git distributes them, .env defines how apps consume them, and secp256k1 keeps their values unreadable. The kicker, all this works by setting a single private key on your infrastructure - no more risky async coordination of secrets, no more centralized downtime risk. Your secrets are always just there with your code, ready to be unlocked at runtime.

Read the whitepaper →

 

About

a secure dotenv–from the creator of `dotenv`

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Used by

Contributors

Languages