A lightweight CLI tool for securely managing environment variables and secrets.
envsecrets encrypts your environment variables using AES-GCM encryption with Argon2 key derivation. Your secrets are protected with a passphrase that can be stored securely in your system's keyring.
Version control your secrets safely. Unlike traditional approaches where .env files must be kept out of version control, envsecrets encrypts your secrets so they can be safely committed to your repository. This means:
- Track secret changes over time - See when secrets were added, modified, or removed through git history
- Collaborate securely - Share encrypted secrets with your team through version control
- Environment parity - Keep development, staging, and production secrets in the same repo
- Disaster recovery - Your encrypted secrets are backed up wherever your code is
- Simplify deployment - No need for separate secret management infrastructure
The .envsecrets/*.vault files are encrypted and safe to commit. Only those with the passphrase can decrypt them.
- Go 1.22 or higher
go install github.com/suvaidkhan/envsecrets@latestThis will download, build, and install the envsecrets binary to your $GOPATH/bin directory.
Make sure $GOPATH/bin is in your PATH:
export PATH=$PATH:$(go env GOPATH)/bin# Clone the repository
git clone https://github.com/suvaidkhan/envsecrets.git
cd envsecrets
# Build the binary
go build -o envsecrets
# Optionally, move to a directory in your PATH
sudo mv envsecrets /usr/local/bin/envsecrets --version| Command | Description |
|---|---|
init |
Initialize a new encrypted vault |
add |
Add or update a secret in a vault |
get |
Retrieve a specific secret |
delete |
Remove a secret from a vault |
export |
Export all secrets to dotenv or JSON |
import |
Import secrets from dotenv or JSON file |
rotate |
Change vault passphrase |
clear |
Clear cached passphrase from keyring |
destroy |
Permanently delete a vault |
Create a new encrypted vault for an environment.
# Initialize a vault
envsecrets init --env prod
# Using short flag
envsecrets init -e stagingWhat it does:
- Prompts for a passphrase
- Creates
.envsecrets/{env}.vaultfile - Generates a salt and fingerprint
- Sets secure file permissions (0o600)
Add a new secret or update an existing one in a vault.
# Add with flags
envsecrets add --env prod --key API_KEY --value secret123
# Interactive mode
envsecrets add --env prod
# Hide value input (for sensitive data)
envsecrets add --env prod --secretFlags:
--env, -e- Environment name (required)--key, -k- Entry key (prompts if not provided)--value, -v- Entry value (prompts if not provided)--secret, -s- Hide value input in terminal
What it does:
- Opens the vault with passphrase
- Encrypts the value with AES-GCM
- Stores encrypted entry with timestamps
- Updates existing entries automatically
Change the passphrase for a vault by re-encrypting all entries.
envsecrets rotate --env prodWhat it does:
- Opens vault with current passphrase
- Prompts for new passphrase (with confirmation)
- Generates new salt
- Re-encrypts all entries with new passphrase
- Updates keyring cache
- Preserves all timestamps
Use case: Periodic security rotation or when passphrase is compromised.
Get a decrypted secret from a vault and print it to stdout.
envsecrets get --env prod --key API_KEYFlags:
--env, -e- Environment name (required)--key, -k- Secret key to retrieve (required)
What it does:
- Opens the vault with passphrase
- Retrieves and decrypts the specified secret
- Prints the value to stdout
Use case: Scripts, CI/CD pipelines, or exporting a single secret.
Remove a secret from a vault.
# Delete with flags
envsecrets delete --env prod --key API_KEY
# Interactive mode
envsecrets delete --env prodFlags:
--env, -e- Environment name (required)--key, -k- Secret key to delete (prompts if not provided)
What it does:
- Opens the vault with passphrase
- Removes the specified entry
- Updates the vault file
Export all decrypted secrets from a vault in dotenv or JSON format.
# Export as dotenv format
envsecrets export --env prod > .env
# Export as JSON
envsecrets export --env staging --format json > env.jsonFlags:
--env, -e- Environment name (required)--format- Output format:dotenvorjson(default: dotenv)
What it does:
- Opens the vault with passphrase
- Decrypts all entries
- Outputs to stdout in the specified format
Use case: Generate .env files for local development or deployment.
Import secrets from a dotenv or JSON file into a vault.
# Import from dotenv file
envsecrets import .env --env prod --format dotenv
# Import from JSON file
envsecrets import config.json --env staging --format json
# Import from stdin
cat .env | envsecrets import --env local --format dotenv
# Overwrite existing keys
envsecrets import .env --env prod --format dotenv --overwriteFlags:
--env, -e- Environment name (required)--format- Input format:dotenvorjson(required)--overwrite- Overwrite existing keys (default: false)
What it does:
- Parses the input file (dotenv or JSON format)
- Opens the vault with passphrase
- Encrypts and adds entries to the vault
- Skips existing keys unless
--overwriteis used
Use case: Migrate existing .env files to encrypted storage.
Remove the cached passphrase for an environment from the system keyring.
envsecrets clear --env prodFlags:
--env, -e- Environment name (required)
What it does:
- Removes the cached passphrase from system keyring
- Next command will prompt for passphrase again
Use case: Security best practice, logout, or switching users.
Permanently delete a vault and all its secrets.
envsecrets destroy --env prodFlags:
--env, -e- Environment name (required)
What it does:
- Clears cached passphrase
- Prompts for passphrase to verify authorization
- Asks for confirmation
- Permanently deletes the vault file
Warning: This action cannot be undone. All secrets will be lost unless backed up.
Passphrases are retrieved in this order:
- Environment variable:
ENVSECRET_PASSPHRASE - System keyring: Cached from previous use
- Interactive prompt: Asks user for input
The passphrase is cached in your system's keyring after first use for convenience.
- Encryption: AES-256-GCM (authenticated encryption)
- Key Derivation: Argon2id (memory-hard, GPU-resistant)
- Authentication: GCM provides authenticity verification
- File Permissions: Only owner can read/write vault files (0o600)
- Memory Safety: Sensitive data cleared after use
- Keyring Integration: Secure passphrase caching
Vaults are stored in .envsecrets/{env}.vault:
{
"meta": {
"env": "production",
"salt": "base64-encoded-salt",
"fingerprint": "bcrypt-hash-of-passphrase"
},
"entries": {
"API_KEY": {
"value": "base64-encrypted-value",
"created_at": "2025-01-05T10:00:00Z",
"updated_at": "2025-01-05T10:00:00Z"
}
}
}# Create a production vault
envsecrets init --env production
# Add some secrets
envsecrets add --env production --key DATABASE_URL --value "postgres://..."
envsecrets add --env production --key API_KEY --value "sk-..." --secret
# Retrieve a secret
envsecrets get --env production --key API_KEY
# Delete a secret
envsecrets delete --env production --key OLD_KEY# Import existing .env file
envsecrets init --env development
envsecrets import .env --env development --format dotenv
# Commit the encrypted vault
git add .envsecrets/development.vault
git commit -m "Add encrypted development secrets"# Generate .env file for local development
envsecrets export --env development > .env
# Export as JSON for configuration
envsecrets export --env production --format json > config.json# Rotate passphrase periodically
envsecrets rotate --env production
# Clear cached passphrase when done
envsecrets clear --env production
# Destroy a vault (DANGEROUS)
envsecrets destroy --env old-envSet the ENVSECRET_PASSPHRASE environment variable in your CI/CD pipeline:
# Set passphrase in CI environment
export ENVSECRET_PASSPHRASE="your-passphrase"
# Export secrets to .env for your application
envsecrets export --env prod > .env
# Or retrieve individual secrets
API_KEY=$(envsecrets get --env prod --key API_KEY)
DATABASE_URL=$(envsecrets get --env prod --key DATABASE_URL)Best practices:
- Store the passphrase as a secret in your CI/CD platform (GitHub Secrets, GitLab CI Variables, etc.)
- Use different passphrases for each environment
- The encrypted
.envsecrets/*.vaultfiles can be safely committed to your repository