set
Add or update environment variables in encrypted files.
Synopsis
Section titled “Synopsis”kiln set <name> [value] [options]The set command securely stores environment variables by encrypting them for authorized recipients. Variables are validated for security and stored in the specified environment file.
Arguments
Section titled “Arguments”<name>: Environment variable name (optional, if--from-fileis provided)[value]: Variable value (optional, prompts if not provided)
Options
Section titled “Options”--file,-f: Environment file to modify (default:default)--from-file: JSON file containing environment variables to set
Examples
Section titled “Examples”Interactive Input
Section titled “Interactive Input”kiln set DATABASE_URL# Prompts: Enter value for DATABASE_URL: [hidden input]Direct Value
Section titled “Direct Value”kiln set PORT 8080kiln set API_KEY "sk-1234567890abcdef"Bulk Import from JSON
Section titled “Bulk Import from JSON”kiln set --from-file variables.jsonkiln set --from-file config/prod-vars.json --file productionSpecific Environment File
Section titled “Specific Environment File”kiln set DATABASE_URL --file productionkiln set DEBUG_MODE true --file developmentVariable Name Validation
Section titled “Variable Name Validation”Variable names must follow environment variable conventions:
- Start with letter or underscore (
A-Z,a-z,_) - Contain only letters, numbers, and underscores
- Case-sensitive (uppercase recommended)
Valid names:
kiln set DATABASE_URLkiln set API_KEY_V2kiln set _PRIVATE_VARInvalid names:
kiln set api-key # hyphens not allowedkiln set 123_VAR # cannot start with numberkiln set var.name # dots not allowedValue Handling
Section titled “Value Handling”Secure Input
Section titled “Secure Input”When no value is provided, set prompts for input with hidden characters:
kiln set SECRET_PASSWORD# Enter value for SECRET_PASSWORD: ********Value Validation
Section titled “Value Validation”- Maximum size: 1MB per variable
- No null bytes allowed
- Control characters are sanitized
- Newlines and tabs are preserved
JSON File Format
Section titled “JSON File Format”Supported JSON Structure
Section titled “Supported JSON Structure”{ "DATABASE_URL": "postgresql://localhost:5432/myapp", "API_KEY": "sk-1234567890abcdef", "PORT": 8080, "DEBUG_MODE": true, "OPTIONAL_VAR": null, "TIMEOUT": 30.5}Type Conversion
Section titled “Type Conversion”- Strings: Used as-is
- Numbers: Converted to string representation (integers without decimal, floats with appropriate precision)
- Booleans: Converted to
"true"or"false" - null: Converted to empty string
- Objects/Arrays: Not supported (validation error)
JSON File Examples
Section titled “JSON File Examples”Development configuration:
{ "NODE_ENV": "development", "DATABASE_URL": "postgresql://localhost:5432/myapp_dev", "REDIS_URL": "redis://localhost:6379", "DEBUG": true, "LOG_LEVEL": "debug", "PORT": 3000}Production secrets:
{ "DATABASE_URL": "postgresql://prod-db:5432/myapp", "JWT_SECRET": "super-secret-key-for-production", "API_KEY": "prod-api-key-12345", "ENCRYPTION_KEY": "32-byte-base64-encoded-key", "DEBUG": false}Values containing spaces, quotes, or special characters are handled automatically:
kiln set CONNECTION_STRING "host=localhost;user=admin;password=complex!@#"kiln set JSON_CONFIG '{"key": "value", "nested": {"prop": true}}'Security Features
Section titled “Security Features”Memory Safety
Section titled “Memory Safety”- Values are wiped from memory after encryption
- Input is cleared from terminal buffers
- No sensitive data persists in process memory
Access Control
Section titled “Access Control”The command respects file-level access control defined in kiln.toml:
[files.production]filename = "prod.env"access = ["admin", "deploy-team"]
[files.development]filename = "dev.env"access = ["*"] # All recipientsFile Operations
Section titled “File Operations”Atomic Updates
Section titled “Atomic Updates”Variables are updated atomically:
- Load existing variables
- Update target variable
- Re-encrypt entire file
- Write to disk atomically
File Creation
Section titled “File Creation”If the target file doesn’t exist, set creates it with the first variable:
kiln set FIRST_VAR "initial value" --file new-environment# Creates new-environment.env with proper encryptionError Handling
Section titled “Error Handling”Common Errors
Section titled “Common Errors”Configuration not found:
kiln set VAR value# Error: configuration file 'kiln.toml' not found (use 'kiln init config' to create)Invalid variable name:
kiln set invalid-name value# Error: invalid variable name: must start with letter or underscore, followed by letters, numbers, or underscoresAccess denied:
kiln set PROD_VAR value --file production# Error: security error: access denied for 'production' (check file permissions in kiln.toml)JSON file not found:
kiln set --from-file missing.json# Error: file does not existInvalid JSON file:
kiln set --from-file invalid.json# Error: invalid JSON in file 'invalid.json': unexpected character ',' at position 15Unsupported value types:
# JSON with array valueecho '{"CONFIG": ["item1", "item2"]}' > config.jsonkiln set --from-file config.json# Error: unsupported value type for 'CONFIG': []interface {}Variable name conflicts:
kiln set DATABASE_URL --from-file config.json# Error: cannot use both --from-file and variable name argumentFile not configured:
kiln set VAR value --file undefined# Error: configuration error: file 'undefined' not configured (check kiln.toml file definitions)Integration Patterns
Section titled “Integration Patterns”CI/CD Pipelines
Section titled “CI/CD Pipelines”# Set deployment variables from environmentkiln set DATABASE_URL "$CI_DATABASE_URL" --file productionkiln set API_TOKEN "$CI_API_TOKEN" --file production
# Bulk import from generated JSONecho "$CI_CONFIG_JSON" > /tmp/config.jsonkiln set --from-file /tmp/config.json --file productionConfiguration Migration
Section titled “Configuration Migration”# Export from existing systemkubectl get secret app-config -o json | jq '.data | map_values(@base64d)' > config.jsonkiln set --from-file config.json --file production
# Import from dotenv-style files (with conversion)env | grep '^APP_' | jq -R 'split("=") | {(.[0]): .[1]}' | jq -s add > app-vars.jsonkiln set --from-file app-vars.json --file developmentLocal Development
Section titled “Local Development”# Load from .env for developmentexport $(cat .env.local | xargs)kiln set DATABASE_URL "$DATABASE_URL" --file developmentSecret Rotation
Section titled “Secret Rotation”# Update API keyskiln set OLD_API_KEY "" # Clear old valuekiln set NEW_API_KEY "$(generate-new-api-key)" --file productionWorkflow Examples
Section titled “Workflow Examples”Development Environment Setup
Section titled “Development Environment Setup”# Create comprehensive development configurationcat > dev-config.json << 'EOF'{ "NODE_ENV": "development", "DATABASE_URL": "postgresql://localhost:5432/myapp_dev", "REDIS_URL": "redis://localhost:6379", "DEBUG_MODE": true, "LOG_LEVEL": "debug", "PORT": 3000, "SESSION_SECRET": "dev-session-secret", "ENABLE_HOT_RELOAD": true}EOF
kiln set --from-file dev-config.json --file developmentProduction Configuration
Section titled “Production Configuration”# Set up production environment with mix of approacheskiln set DATABASE_URL --file production# Enter value for DATABASE_URL: [hidden - production connection string]
kiln set JWT_SECRET --file production# Enter value for JWT_SECRET: [hidden - cryptographic secret]
# Add additional config from JSONcat > prod-extras.json << 'EOF'{ "NODE_ENV": "production", "LOG_LEVEL": "info", "PORT": 80, "CACHE_TTL": 3600, "ENABLE_METRICS": true}EOF
kiln set --from-file prod-extras.json --file productionBulk Environment Migration
Section titled “Bulk Environment Migration”# Migrate from multiple sourcesenvironments=("development" "staging" "production")
for env in "${environments[@]}"; do if [ -f "configs/${env}.json" ]; then echo "Importing $env configuration..." kiln set --from-file "configs/${env}.json" --file "$env" fidoneBest Practices
Section titled “Best Practices”- Use descriptive variable names that clearly indicate purpose and scope
- Prompt for sensitive values rather than passing them as command-line arguments
- Organize variables by environment using meaningful file names
- Validate values before setting them in production environments
- Document variable purposes in team documentation or comments
- Rotate secrets regularly by updating values and rekeying access
Performance Considerations
Section titled “Performance Considerations”Large Variables
Section titled “Large Variables”For individual variables approaching the 1MB limit:
- Consider storing file paths instead of content
- Use external secret management for large binary data
- Split complex configurations into multiple variables
Frequent Updates
Section titled “Frequent Updates”The set command re-encrypts the entire file on each update:
- Batch multiple updates when possible
- Use
editcommand for interactive multi-variable updates - Consider update frequency in automation scripts
Next Steps
Section titled “Next Steps”Continue building your environment management workflow:
Retrieve Variables Export for Applications Manage Team Access