Skip to content

Cross-Environment Operations

Copying Secrets

keep copy copies secrets between stages or vaults, supporting both single secret and bulk operations.

Command Reference: keep copy

OptionTypeDefaultDescription
--fromstringrequiredSource context (stage or vault:stage)
--tostringrequiredDestination context (stage or vault:stage)
--overwritebooleanfalseOverwrite existing secrets without confirmation
--dry-runbooleanfalseShow what would be copied without making changes
--onlystringPattern for bulk copy - include only matching keys
--exceptstringPattern for bulk copy - exclude matching keys

Arguments:

  • [key] - Specific secret key to copy (omit when using --only or --except)

Single Secret Copy

bash
# Basic copy
keep copy DB_PASSWORD --from=local --to=staging

# With overwrite
keep copy DB_PASSWORD --from=local --to=staging --overwrite

# Dry run first
keep copy API_KEY --from=staging --to=production --dry-run

# Cross-vault
keep copy DB_PASSWORD --from=secretsmanager:local --to=ssm:production

Bulk Copy Operations

Copy multiple secrets at once using pattern matching:

bash
# Copy all database configurations
keep copy --only="DB_*" --from=local --to=staging

# Copy everything except sensitive keys
keep copy --except="*_SECRET,*_TOKEN" --from=staging --to=production

# Copy all API-related secrets with overwrite
keep copy --only="API_*" --from=local --to=production --overwrite

# Preview what would be copied (dry-run)
keep copy --only="*" --from=staging --to=production --dry-run

# Complex patterns - copy configs but not passwords
keep copy --only="*_CONFIG,*_URL" --except="*_PASSWORD" --from=dev --to=staging

Comparing Environments

keep diff shows differences between stages and vaults.

Command Reference: keep diff

OptionTypeDefaultDescription
--vaultstringall vaultsComma-separate list of vaults to compare
--stagestringall stagesComma-separated list of stages to compare
--unmaskbooleanfalseShow actual secret values (not masked)
--onlystringComma-separated list of keys to include
--exceptstringComma-separated list of keys to exclude

Examples:

bash
# Compare all
keep diff

# Specific stages
keep diff --stage=staging,production

# Show values
keep diff --stage=staging,production --unmask

# Filter keys
keep diff --stage=local,production --only="DB_*"
keep diff --stage=local,production --except="APP_DEBUG"

Importing Secrets

keep import imports secrets from .env files.

Command Reference: keep import

OptionTypeDefaultDescription
--stagestringinteractiveTarget stage to import secrets into
--vaultstringdefault vaultVault to import secrets into
--skip-existingbooleanfalseSkip secrets that already exist
--overwritebooleanfalseOverwrite existing secrets without confirmation
--dry-runbooleanfalseShow what would be imported without making changes
--onlystringComma-separated list of keys to import
--exceptstringComma-separated list of keys to exclude

Arguments:

  • [file] - Path to file to import from (uses stdin if not provided)

Examples:

bash
# Import from .env file
keep import .env.development --stage=local

# Import with existing secret protection
keep import production.env --stage=production --skip-existing

# Force overwrite existing secrets
keep import staging.env --stage=staging --overwrite

# Dry run to preview import
keep import .env --stage=local --dry-run

# Import only specific keys
keep import secrets.json --stage=production --only="API_KEY,DB_PASSWORD"

# Import from stdin
cat .env | keep import --stage=local

# Exclude sensitive keys
keep import .env --stage=local --except="PRIVATE_KEY"

Promotion Workflows

Individual Secret Promotion

bash
# 1. Review current state
keep diff --stage=local,staging

# 2. Copy individual secrets as needed
keep copy API_KEY --from=local --to=staging
keep copy DB_USERNAME --from=local --to=staging

# 3. Set staging-specific values
keep set API_URL "https://staging-api.example.com" --stage=staging

# 4. Verify the promotion
keep diff --stage=local,staging

Bulk Promotion

bash
# 1. Preview what will be promoted
keep copy --only="*" --from=local --to=staging --dry-run

# 2. Promote all configs except debug/test values
keep copy --except="*_DEBUG,*_TEST" --from=local --to=staging

# 3. Or promote specific service configurations
keep copy --only="API_*,DB_*,REDIS_*" --from=local --to=staging

# 4. Verify the promotion
keep diff --stage=local,staging

Cross-Vault Promotion

bash
# Individual secrets
keep copy API_KEY --from=secretsmanager:local --to=ssm:production --dry-run
keep copy API_KEY --from=secretsmanager:local --to=ssm:production
keep copy DB_PASSWORD --from=secretsmanager:local --to=ssm:production

# Bulk cross-vault promotion
keep copy --only="API_*" --from=secretsmanager:local --to=ssm:production
keep copy --except="*_LOCAL" --from=secretsmanager:staging --to=ssm:production

Best Practices

Always dry-run first:

bash
keep copy API_KEY --from=staging --to=production --dry-run
keep import prod-secrets.env --stage=production --dry-run

Review before promoting:

bash
keep diff --stage=staging,production --unmask

Keep environments isolated:

bash
# Set environment-specific values explicitly
keep set DB_HOST "staging-db.example.com" --stage=staging
keep set DB_HOST "prod-db.example.com" --stage=production

Safe imports:

bash
keep import backup.env --stage=production --skip-existing

Released under the MIT License.