A CLI tool that securely retrieves secrets from Google Cloud or AWS using IAM permissions and stores them as environment variables in env files. Simplifies secret management while maintaining security through cloud provider access controls.
- Multi-Account Support
- Providers:
- Google Cloud Secret Manager
- AWS Secrets Manager
- Commands:
init: Interactive secret selection from AWS or Google Cloud (choose provider at runtime)load: Read env file and output environment variables (with optionalexportprefix)update: Refresh secrets in the env file from cloud providers
make installmake uninstallbrew install gumi/tap/secret-env-managersem -h| Command | Description |
|---|---|
init |
Interactive secret selection from both AWS and Google Cloud providers |
load |
Output environment variables from cached secrets |
update |
Update cached secrets by fetching latest values |
For AWS Secrets Manager:
AWS_PROFILE: AWS profile to useAWS_REGION: AWS region to query
For Google Cloud Secret Manager:
GOOGLE_CLOUD_PROJECT: Google Cloud project ID
Secret Env Manager works seamlessly with direnv to automatically load environment variables when entering your project directory. Here's how to set it up:
-
First, create an environment file (e.g.,
.env) containing your secret URIs:DB_PASSWORD=sem://aws:secretsmanager/dev-profile/database/credentials?key=password API_KEY=sem://googlecloud:secretmanager/my-project/api-key -
Run the
updatecommand to retrieve secrets and generate a cache file:sem update --input .env
This will create a cache file named
.cache.envcontaining the actual secret values. -
Add the following to your
.envrcfile:# Update secrets cache (optional but ensures freshness) sem update --input .env # Load environment variables from the cache file dotenv .cache.env
-
Allow the direnv configuration:
direnv allow
Now whenever you enter your project directory, direnv will automatically load the environment variables from the cache file, making your secrets available to your application.
The env file supports various ways to specify secrets. Each line in the file follows the SecretURI format.
# Comment line starts with #
KEY=VALUE # Regular environment variable (direct value assignment)
# Secret URIs - used to fetch secrets from providers
sem://aws:secretsmanager/profile/path/secret-name
ENV_VAR=sem://aws:secretsmanager/profile/path/secret-name
You can mix both direct value assignments and Secret URIs in the same env file. Direct value assignments are preserved as-is, while Secret URIs are processed to fetch values from cloud providers.
In your env file:
sem://aws:secretsmanager/xxx-profile/test/test_secret
After processing, becomes:
key1=value1
key2=value2
...
keyN=valueN
In your env file:
KEY=sem://aws:secretsmanager/xxx-profile/test/test_secret
After processing, becomes:
KEY_key1=value1
KEY_key2=value2
...
KEY_keyN=valueN
In your env file:
sem://aws:secretsmanager/xxx-profile/test/test_secret?key=username
After processing, becomes:
username=value
In your env file:
DB_USER=sem://aws:secretsmanager/xxx-profile/test/test_secret?key=username
After processing, becomes:
DB_USER=value
In your env file:
sem://googlecloud:secretmanager/xxx-project/sample_secret
After processing, becomes:
sample_secret=value
In your env file:
API_KEY=sem://googlecloud:secretmanager/xxx-project/sample_secret
After processing, becomes:
API_KEY=value
# Database credentials
DB_HOST=localhost
DB_PORT=5432
DB_NAME=myapp
DB_USER=sem://aws:secretsmanager/dev-profile/database/credentials?key=username
DB_PASSWORD=sem://aws:secretsmanager/dev-profile/database/credentials?key=password
# API Keys
GOOGLE_API_KEY=sem://googlecloud:secretmanager/my-project/google-api-key
PAYMENT_API_SECRET=sem://aws:secretsmanager/payments-profile/payment/api-keys?key=secret
# Import all email service settings with prefix
EMAIL_SERVICE=sem://aws:secretsmanager/marketing-profile/email-service/settings
# Version specific secret (retrieve a specific version)
CONFIG_V1=sem://aws:secretsmanager/dev-profile/versioned-config?version=v1
EXPORT_NAME=sem://<Platform>:<Service>/<Account>/<SecretName>?version=<Version>&key=<Key>
| Field | Description |
|---|---|
| Platform | Cloud platform (aws or gcp) |
| Service | Secret service (secretsmanager for AWS, secretmanager for GCP) |
| Account | Account/profile/project name |
| SecretName | Name of the secret |
| ExportName | Environment variable name |
| Version | Secret version (AWSCURRENT for AWS, latest for GCP) |
| Key | (AWS only, for JSON secrets) Key to extract |
Note: For GoogleCloud, key can only be specified when the value is in JSON format.
Apache License, Version 2.0