get
Retrieve specific environment variables from encrypted files.
Synopsis
Section titled “Synopsis”kiln get <name> [options]The get command decrypts and retrieves individual environment variables with secure memory handling and flexible output formatting.
Arguments
Section titled “Arguments”<name>: Environment variable name (required)
Options
Section titled “Options”--file,-f: Environment file to read from (default:default)--format: Output format:valueorjson(default:value)
Examples
Section titled “Examples”Basic Retrieval
Section titled “Basic Retrieval”kiln get DATABASE_URLSpecific Environment File
Section titled “Specific Environment File”kiln get API_KEY --file productionkiln get DEBUG_MODE --file developmentJSON Output
Section titled “JSON Output”kiln get DATABASE_URL --format json# {"DATABASE_URL": "postgresql://localhost:5432/myapp"}Output Formats
Section titled “Output Formats”Value Format (Default)
Section titled “Value Format (Default)”Returns the raw variable value without quotes or formatting:
kiln get PORT# 8080
kiln get CONNECTION_STRING# host=localhost;user=admin;password=secretJSON Format
Section titled “JSON Format”Returns a JSON object with the variable name and value:
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
Security Features
Section titled “Security Features”Memory Safety
Section titled “Memory Safety”- Variable values are wiped from memory after output
- No sensitive data persists in process memory
- Secure cleanup on command completion
Access Control
Section titled “Access Control”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 accessValidation
Section titled “Validation”- Variable names must match stored variables exactly (case-sensitive)
- File access is verified before decryption
- Input validation prevents directory traversal
Integration
Section titled “Integration”Shell Scripts
Section titled “Shell Scripts”#!/bin/bashDATABASE_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"Environment Variable Export
Section titled “Environment Variable Export”# Export to current shellexport DATABASE_URL=$(kiln get DATABASE_URL)export API_KEY=$(kiln get API_KEY)JSON Processing
Section titled “JSON Processing”# Extract value with jqPORT=$(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 addError Handling
Section titled “Error Handling”Variable Not Found
Section titled “Variable Not Found”kiln get NONEXISTENT_VAR# Error: variable 'NONEXISTENT_VAR' not found in 'default'Access Denied
Section titled “Access Denied”kiln get SECRET_KEY --file production# Error: security error: access denied for 'production' (check file permissions in kiln.toml)File Not Configured
Section titled “File Not Configured”kiln get VAR --file undefined# Error: configuration error: file 'undefined' not configured (check kiln.toml file definitions)Invalid Variable Name
Section titled “Invalid Variable Name”kiln get invalid-name# Error: invalid variable name: must start with letter or underscore, followed by letters, numbers, or underscoresWorkflow Examples
Section titled “Workflow Examples”Development Setup
Section titled “Development Setup”# Check current configurationkiln get DATABASE_URL --file devkiln get API_ENDPOINT --file devkiln get LOG_LEVEL --file devProduction Verification
Section titled “Production Verification”# Verify production settingskiln get DATABASE_URL --file production --format jsonkiln get JWT_SECRET --file production >/dev/null && echo "JWT_SECRET is set"Configuration Validation
Section titled “Configuration Validation”# Validate required variables existrequired_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" fidoneBackup Configuration
Section titled “Backup Configuration”# Export all variables to backup scriptfor var in DATABASE_URL API_KEY JWT_SECRET; do echo "kiln set $var \"$(kiln get $var --file production)\" --file backup"donePerformance Considerations
Section titled “Performance Considerations”File Decryption
Section titled “File Decryption”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:
exportcommand for bulk operationsruncommand for command execution with full environment
Memory Usage
Section titled “Memory Usage”- 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
Best Practices
Section titled “Best Practices”Scripting
Section titled “Scripting”# Check if variable exists before usingif DATABASE_URL=$(kiln get DATABASE_URL 2>/dev/null); then echo "Database URL: $DATABASE_URL"else echo "Database URL not configured" exit 1fiError Handling in Scripts
Section titled “Error Handling in Scripts”# Robust error handlingget_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 1Conditional Configuration
Section titled “Conditional Configuration”# Use different files based on environmentENVIRONMENT=${NODE_ENV:-development}API_ENDPOINT=$(kiln get API_ENDPOINT --file "$ENVIRONMENT")Security Considerations
Section titled “Security Considerations”- Output redirection: Be careful when redirecting output to files that might be readable by other users
- Command history: Avoid using
getoutput directly in commands that might be logged - Process environment: Variables retrieved with
getare not automatically added to process environment - Access logging: Consider that
getoperations may be logged for audit purposes
Comparison with Alternatives
Section titled “Comparison with Alternatives”vs. export command
Section titled “vs. export command”get: Single variable, immediate outputexport: Multiple variables, various formats
vs. run command
Section titled “vs. run command”get: Manual variable retrieval for scriptsrun: Automatic environment injection for commands
vs. edit command
Section titled “vs. edit command”get: Read-only access to variablesedit: Interactive modification of multiple variables