SECRETS MANAGEMENT - nself-org/cli GitHub Wiki
nself CLI version: 0.9.6+ Last updated: January 31, 2026
nself provides comprehensive secrets management to protect sensitive credentials, API keys, and passwords. This guide covers best practices, command usage, and integrations with external secret managers.
# During initialization
nself init
# Wizard will prompt for secrets generation
# Or generate manually
nself config secrets generateThis creates .env.secrets with strong random values:
# View generated secrets (masked)
nself config secrets list
# View specific secret (masked)
nself config secrets get POSTGRES_PASSWORD
# View actual value (use carefully!)
nself config secrets get POSTGRES_PASSWORD --reveal# Check secret strength and security
nself config secrets validate
# Output:
# โ POSTGRES_PASSWORD is set (32 chars)
# โ HASURA_GRAPHQL_ADMIN_SECRET is set (64 chars)
# โ JWT_SECRET is set (64 chars)
# โ File permissions are correct (600)
# โ Secrets file is properly ignored by gitAutomatic Protection:
-
.env.secretsis automatically added to.gitignore -
nself doctorwarns if secrets are tracked by git
Manual Verification:
# Check if secrets are tracked
git ls-files | grep .env.secrets
# Should return nothing
# If found, remove from git:
git rm --cached .env.secrets
git commit -m "Remove secrets from git"โ Good: Generated by nself (32-64 characters, random)
POSTGRES_PASSWORD=aB3kL9mP2xQ7vN4wY8zR1tS5uO6cF0dH
โ Bad: Weak, default, or predictable
POSTGRES_PASSWORD=postgres123
POSTGRES_PASSWORD=password
POSTGRES_PASSWORD=admin
Check for Weak Secrets:
nself doctor
# Automatically detects weak/default secretsCorrect Permissions: 600 (owner read/write only)
# Set correct permissions
chmod 600 .env.secrets
# Verify
ls -la .env.secrets
# Should show: -rw-------Security Check:
nself doctor
# Checks file permissions automaticallySingle Secret:
# Rotate specific secret
nself config secrets rotate POSTGRES_PASSWORD
# Backup created automatically
# New value generated
# Restart required to applyAll Secrets:
# Rotate everything
nself config secrets rotate --all
# โ ๏ธ Warning: This will generate new values for ALL secrets
# Continue? (y/N) yAfter Rotation:
# Restart services to apply new secrets
nself restartDevelopment:
# .env.secrets (weak passwords OK)
POSTGRES_PASSWORD=dev-password-123Production:
# .env.secrets (MUST be strong)
POSTGRES_PASSWORD=$(nself config secrets generate POSTGRES_PASSWORD)
# Or use external secret managernself config secrets generate
# Output file: .env.secrets (default)
# Generates:
# - POSTGRES_PASSWORD (32 chars, alphanumeric)
# - HASURA_GRAPHQL_ADMIN_SECRET (64 chars, hex)
# - JWT_SECRET (64 chars, hex)
# - COOKIE_SECRET (32 chars, hex)
# - MINIO_ROOT_PASSWORD (32 chars, alphanumeric)
# - REDIS_PASSWORD (32 chars, alphanumeric)
# - GRAFANA_ADMIN_PASSWORD (24 chars, alphanumeric)# Generate custom secret
nself config secrets generate MY_API_KEY
# Specify length and type
nself config secrets generate MY_SECRET 64 hex
# Types: hex, base64, alphanumeric# List all secrets (masked)
nself config secrets list
# Output:
# POSTGRES_PASSWORD (32 chars)
# HASURA_GRAPHQL_ADMIN_SECRET (64 chars)
# JWT_SECRET (64 chars)
# List for specific environment
nself config secrets list --env staging# Get masked value (safe)
nself config secrets get POSTGRES_PASSWORD
# Output: ********
# Get actual value (use carefully!)
nself config secrets get POSTGRES_PASSWORD --reveal
# Output: aB3kL9mP2xQ7vN4wY8zR1tS5uO6cF0dH# Set manually (not recommended - use generate instead)
nself config secrets set API_KEY "your-api-key-here"
# โ ๏ธ Better: Generate random value
nself config secrets generate API_KEY# Remove secret from file
nself config secrets delete OLD_API_KEY
# Confirm deletion
nself config secrets list# Rotate single secret
nself config secrets rotate POSTGRES_PASSWORD
# Backup created: .env.secrets.backup-20260131-120000
# New value generated and replaced
# Restart services: nself restart
# Rotate all secrets (with confirmation)
nself config secrets rotate --all
# โ ๏ธ Warning shown
# Requires confirmation
# Creates backup automatically# Run comprehensive validation
nself config secrets validate
# Checks:
# โ Required secrets present
# โ Secret length sufficient (16+ chars)
# โ No weak/default values
# โ File permissions (600)
# โ Git ignore status
# โ Not tracked in git# Encrypt secrets file
nself config secrets encrypt .env.secrets
# Enter encryption password: ****
# Creates: .env.secrets.enc
# Decrypt when needed
nself config secrets decrypt .env.secrets.enc
# Enter decryption password: ****
# Restores: .env.secretsUse Cases:
- Store encrypted backup in cloud storage
- Share with team members securely
- Archive old secrets safely
# Install Vault CLI
brew install vault
# or: https://www.vaultproject.io/downloads# Import secrets from Vault
nself config secrets import vault secret/nself
# Reads from: secret/nself
# Writes to: .env.secrets# Export secrets to Vault
nself config secrets export vault secret/nself
# Reads from: .env.secrets
# Writes to: secret/nselfVault Configuration:
# Set Vault address
export VAULT_ADDR='http://127.0.0.1:8200'
# Authenticate
vault login
# Then use nself commands
nself config secrets import vault# Install AWS CLI
brew install awscli
# or: https://aws.amazon.com/cli/
# Configure credentials
aws configure# Import secrets from AWS Secrets Manager
nself config secrets import aws nself/production
# Secret ID: nself/production
# Writes to: .env.secrets# Export secrets to AWS Secrets Manager
nself config secrets export aws nself/production
# Creates/updates secret: nself/production
# Source: .env.secretsAWS IAM Permissions Required:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"secretsmanager:GetSecretValue",
"secretsmanager:CreateSecret",
"secretsmanager:UpdateSecret"
],
"Resource": "arn:aws:secretsmanager:*:*:secret:nself/*"
}
]
}# Import from environment variables
export NSELF_SECRET_POSTGRES_PASSWORD="secure-password"
export NSELF_SECRET_REDIS_PASSWORD="another-secure-password"
nself config secrets import env
# Imports all NSELF_SECRET_* variables
# Strips prefix and writes to .env.secretsCustom Prefix:
export MY_APP_POSTGRES_PASSWORD="password"
export MY_APP_REDIS_PASSWORD="password"
nself config secrets import env MY_APP_Problem:
nself config secrets list
# No secrets file found: .env.secretsSolution:
# Generate secrets
nself config secrets generateProblem:
nself doctor
# โ Detected 3 weak or default secret(s)Solution:
# Rotate all weak secrets
nself config secrets rotate --all
# Or rotate individually
nself config secrets rotate POSTGRES_PASSWORD
nself config secrets rotate HASURA_GRAPHQL_ADMIN_SECRETProblem:
nself doctor
# โ .env.secrets IS TRACKED BY GIT - CRITICAL SECURITY ISSUE!Solution:
# Remove from git immediately
git rm --cached .env.secrets
# Ensure it's in .gitignore
echo ".env.secrets" >> .gitignore
# Commit the fix
git commit -m "Remove secrets from git and add to .gitignore"
# โ ๏ธ IMPORTANT: Rotate ALL secrets immediately
nself config secrets rotate --all
# Because they were exposed in git historyProblem:
nself doctor
# โ .env.secrets has insecure permissions: 644 (should be 600)Solution:
# Fix permissions
chmod 600 .env.secrets
# Verify
ls -la .env.secrets
# -rw------- (owner read/write only)Problem:
nself config secrets validate
# โ ๏ธ POSTGRES_PASSWORD is too short (12 chars)Solution:
# Rotate to generate longer secret
nself config secrets rotate POSTGRES_PASSWORD
# Or manually set strong value
nself config secrets generate POSTGRES_PASSWORD 32 alphanumericProblem: Accidentally deleted .env.secrets
Solution:
# Check for backup
ls -la .env.secrets.backup-*
# If backup exists, restore it
cp .env.secrets.backup-20260131-120000 .env.secrets
chmod 600 .env.secrets
# If no backup, regenerate (โ ๏ธ will lose access to data)
nself config secrets generate
# You'll need to:
# 1. Update database password
# 2. Restart all services
# 3. May lose access to encrypted dataPrevention: Always backup .env.secrets securely:
# Encrypted backup to safe location
nself config secrets encrypt .env.secrets
# Store .env.secrets.enc in secure backup locationDevelopment:
- Rotate when compromised
- No regular rotation needed
Staging:
- Rotate monthly
- After team member changes
Production:
- Rotate quarterly (minimum)
- After security incidents
- When team members leave
- After 3rd party breaches
# 1. Generate new secret value
NEW_PASSWORD=$(nself config secrets generate POSTGRES_PASSWORD)
# 2. Update database to accept both old and new
# (implementation depends on service)
# 3. Update .env.secrets with new value
nself config secrets set POSTGRES_PASSWORD "$NEW_PASSWORD"
# 4. Rolling restart of services
nself restart --rolling
# 5. Remove old password from database
# (after confirming all services using new password)# Development
.env.secrets # Weak passwords OK
# Staging
.environments/staging/.env.secrets
# Production
.environments/production/.env.secrets
# Generate for each environment
nself config secrets generate --env staging
nself config secrets generate --env production# Check who rotated secrets
cat .env.secrets.backup-* | head -5
# Shows generation date and user
# Git log for secret rotation commits
git log --all --grep="rotate.*secret" --onelineBefore deploying to production:
- All secrets generated with
nself config secrets generate - No weak or default passwords (
nself doctorpasses) - File permissions set to 600 (
ls -la .env.secrets) - File in .gitignore (
grep .env.secrets .gitignore) - Not tracked by git (
git ls-files | grep secretsreturns nothing) - Backup created and stored securely
- Secret rotation schedule defined
- Access limited to necessary team members
- Encrypted backups in secure storage
- Integration with secret manager (Vault/AWS) configured
Last Updated: January 31, 2026 nself Version: 0.9.6+ Maintainers: nself Core Team