Skip to content

get

Retrieve specific environment variables from encrypted files.

Terminal window
kiln get <name> [options]

The get command decrypts and retrieves individual environment variables with secure memory handling and flexible output formatting.

  • <name>: Environment variable name (required)
  • --file, -f: Environment file to read from (default: default)
  • --format: Output format: value or json (default: value)
5432/myapp
kiln get DATABASE_URL
Terminal window
kiln get API_KEY --file production
kiln get DEBUG_MODE --file development
Terminal window
kiln get DATABASE_URL --format json
# {"DATABASE_URL": "postgresql://localhost:5432/myapp"}

Returns the raw variable value without quotes or formatting:

Terminal window
kiln get PORT
# 8080
kiln get CONNECTION_STRING
# host=localhost;user=admin;password=secret

Returns a JSON object with the variable name and value:

Terminal window
kiln get API_KEY --format json
# {"API_KEY": "sk-1234567890abcdef"}

This format is useful for:

  • Processing in scripts with jq
  • Importing into other JSON-based tools
  • Preserving variable names in output
  • Variable values are wiped from memory after output
  • No sensitive data persists in process memory
  • Secure cleanup on command completion

Access is controlled by file-level permissions in kiln.toml:

[files.production]
filename = "prod.env"
access = ["admin"] # Only admin can access
[files.development]
filename = "dev.env"
access = ["*"] # All recipients can access
  • Variable names must match stored variables exactly (case-sensitive)
  • File access is verified before decryption
  • Input validation prevents directory traversal
#!/bin/bash
DATABASE_URL=$(kiln get DATABASE_URL --file production)
API_KEY=$(kiln get API_KEY --file production)
# Use in application startup
./myapp --db="$DATABASE_URL" --api-key="$API_KEY"
Terminal window
# Export to current shell
export DATABASE_URL=$(kiln get DATABASE_URL)
export API_KEY=$(kiln get API_KEY)
Terminal window
# Extract value with jq
PORT=$(kiln get PORT --format json | jq -r '.PORT')
# Combine multiple variables
{
kiln get DATABASE_URL --format json
kiln get API_KEY --format json
kiln get DEBUG_MODE --format json
} | jq -s add
Terminal window
kiln get NONEXISTENT_VAR
# Error: variable 'NONEXISTENT_VAR' not found in 'default'
Terminal window
kiln get SECRET_KEY --file production
# Error: security error: access denied for 'production' (check file permissions in kiln.toml)
Terminal window
kiln get VAR --file undefined
# Error: configuration error: file 'undefined' not configured (check kiln.toml file definitions)
Terminal window
kiln get invalid-name
# Error: invalid variable name: must start with letter or underscore, followed by letters, numbers, or underscores
Terminal window
# Check current configuration
kiln get DATABASE_URL --file dev
kiln get API_ENDPOINT --file dev
kiln get LOG_LEVEL --file dev
Terminal window
# Verify production settings
kiln get DATABASE_URL --file production --format json
kiln get JWT_SECRET --file production >/dev/null && echo "JWT_SECRET is set"
Terminal window
# Validate required variables exist
required_vars=("DATABASE_URL" "API_KEY" "JWT_SECRET")
for var in "${required_vars[@]}"; do
if kiln get "$var" --file production >/dev/null 2>&1; then
echo "$var is configured"
else
echo "$var is missing"
fi
done
Terminal window
# Export all variables to backup script
for var in DATABASE_URL API_KEY JWT_SECRET; do
echo "kiln set $var \"$(kiln get $var --file production)\" --file backup"
done

Each get command:

  • Decrypts the entire environment file
  • Extracts the requested variable
  • Wipes decrypted data from memory

For multiple variables from the same file, consider using:

  • export command for bulk operations
  • run command for command execution with full environment
  • Memory usage scales with file size, not variable count
  • Large environment files may require more memory during decryption
  • Memory is promptly released after variable extraction
Terminal window
# Check if variable exists before using
if DATABASE_URL=$(kiln get DATABASE_URL 2>/dev/null); then
echo "Database URL: $DATABASE_URL"
else
echo "Database URL not configured"
exit 1
fi
Terminal window
# Robust error handling
get_var() {
local var_name="$1"
local file="${2:-default}"
if ! kiln get "$var_name" --file "$file" 2>/dev/null; then
echo "Error: Required variable $var_name not found in file $file" >&2
return 1
fi
}
DATABASE_URL=$(get_var DATABASE_URL production) || exit 1
Terminal window
# Use different files based on environment
ENVIRONMENT=${NODE_ENV:-development}
API_ENDPOINT=$(kiln get API_ENDPOINT --file "$ENVIRONMENT")
  1. Output redirection: Be careful when redirecting output to files that might be readable by other users
  2. Command history: Avoid using get output directly in commands that might be logged
  3. Process environment: Variables retrieved with get are not automatically added to process environment
  4. Access logging: Consider that get operations may be logged for audit purposes
  • get: Single variable, immediate output
  • export: Multiple variables, various formats
  • get: Manual variable retrieval for scripts
  • run: Automatic environment injection for commands
  • get: Read-only access to variables
  • edit: Interactive modification of multiple variables