This Changes Everything About .env Files


Thank you to our sponsors who keep this newsletter free to the reader:

Aikido is your no-nonsense DevSecOps platform. One central system that shows you what matters and how to fix it, from code to cloud. So you can get back to building. Try Aikido today!​

We’ve all been there – that heart-stopping moment when you realize you’ve accidentally exposed sensitive information.

Today, I’m sharing a personal story and introducing a tool that could save you from a similar nightmare.

The Nightmare Scenario

London, February 2019, I was about to release an infrastructure project I’ve been working on for two weeks. I used the client’s AWS master key for testing. Yes, I know – I’m cringing too 😬. I pushed the container to a public repo for “easier access.” 🤡

Within seconds, an email arrived, cc’ing the entire company leadership about a critical security breach in production. Cold sweat. Near-firing experience. Lessons learned the hard way.

The Common Pitfall

Many developers, especially those working on side projects or open-source repos, face a common dilemma: How do you store secrets locally in a way that’s both secure and convenient? Is it enough to put them in clear text and add them to .gitignore or .dockerignore?

The answer is a resounding no. But the solution isn’t always clear.

Enter: dotenvx

Here’s where dotenvx comes in – a tool that could have saved me a world of pain. dotenvx is a “better .env” with three key features:

  1. It runs everywhere
  2. It encrypts your data
  3. It supports multiple environments

Getting Started with dotenvx

Installation is simple: `curl -sfS https://dotenvx.sh | sh # or brew install dotenvx` (I used Nix)

Key Features:

  1. Automatic Encryption: Use dotenvx encrypt to secure your .env file.
  2. Public/Private Key System: Share the public key safely, keep the private key secret.
  3. Language Agnostic: Works with any programming language or deployment method.
  4. Direct Process Injection: Exposes variables directly to the application process.

Enhancing Security

While dotenvx is a great start, it’s not a silver bullet. I recommend coupling it with security scanning tools like Snyk. These tools can help identify exposed secrets and other vulnerabilities in your project.

Multi-Environment Support

dotenvx supports multiple environments (staging, production, etc.) through separate .env files. You can use the -f flag to specify which file to use.

Docker Integration

When using dotenvx with Docker, remember to:

  1. Ignore the keys file in .dockerignore
  2. Install dotenvx in your Dockerfile
  3. Wrap your application execution with dotenvx: dotenvx run --

The Balanced Approach

While .env files remain controversial in professional settings, tools like dotenvx offer a middle ground between security and practicality for side projects and open-source work. Remember, no solution is perfect. Always stay vigilant and use supporting systems to minimize risks.

As always, feel free to reply directly with thoughts and comments.
Have a great weekend!

​

ESPRESSO FRIDAYS

Every once in a while I send hand picked things I've learned. Kind of like your filter to the tech internet. No spam, I promise!

Read more from ESPRESSO FRIDAYS

Rex is Probably The Best Terminal Emulator I’ve Ever Used This issue is brought to you by: Stop juggling infrastructure automation tools Terraform, Ansible, and all your automation in one place. Kestra brings everything together with YAML workflows, built-in monitoring, and the freedom to self-host. Get started with Kestra For years, tmux has been the thing I refuse to open a terminal without.Persistent sessions, panes, shortcuts, the whole shabang. Ghostty (the more recent addition) handles...

I Switched to an Open Source Code Reviewer And I'm Not Looking Back This issue is brought to you by: Stop typing. Start talking with Wispr Flow. Your voice is faster than your keyboard. Wispr Flow turns natural speech into polished, ready-to-send text across your favorite apps, without the usual dictation mistakes or endless editing. Try Wispr Flow For Free and Get 1 Month of Wispr Flow Pro (unlimited words): Be honest.. how much of your code are you actually reading?Not the quick glance...

AI Can Write Your Terraform. You Still Own the Blast Radius. This issue is brought to you by: 18 Kubernetes agentic AI security best practices CNCF and Teleport lay out the top cloud-native agentic standards that you should know before you deploy autonomous AI agents in your Kubernetes clusters. Read the full Kubernetes agentic AI blog I can ask an agent to generate a cloud environment and get hundreds of lines of Terraform back in seconds. I promise it's going to be BEAUTIFUL.It also means I...