6 KiB
6 KiB
PowerOn Key Management Specification
1. Objective
PowerOn requires a secure, pragmatic key management system that:
- Encrypts all sensitive configuration values (API keys, passwords, tokens) in configuration files
- Maintains strict environment separation (dev/int/prod) with different master keys
- Enables local development without internet dependency
- Provides simple developer workflow for adding/updating encrypted keys
- Ensures production security with external master key storage
2. Key Management Logic
2.1 Master Key Storage Strategy
Development Environment:
- Master key stored locally in
<key file path>/key.txtfile - File format:
env = 256bit-base64-encoded-key - Never committed to Git repository
- Accessible for local development without internet
Production/Integration Environments:
- Master key stored as Azure environment variable
- Variable name defined by
APP_KEY_SYSVARconfiguration - to set to HIDDEN! - Fallback to file-based storage if environment variable not found
- Complete separation from development keys
2.2 Encryption/Decryption Process
Encryption Process:
- Key Detection: Identify if value needs encryption (ends with
_SECRET) - Master Key Retrieval: Load appropriate master key based on environment
- Key Derivation: Use PBKDF2 to derive encryption key from master key
- Value Encryption: Encrypt using AES-256-GCM via Fernet
- Prefix Addition: Add environment-specific prefix (
DEV_ENC:,INT_ENC:,PROD_ENC:) - Storage: Save encrypted value to configuration file
Decryption Process:
- Prefix Detection: Check if value starts with environment prefix
- Environment Validation: Ensure prefix matches current environment
- Master Key Retrieval: Load master key for current environment
- Key Derivation: Derive same encryption key using PBKDF2
- Value Decryption: Decrypt using Fernet
- Return: Provide plain text value to application
2.3 Environment-Specific Master Keys
Key Format in key.txt:
prod = 256bit-key-for-config-encryption
int = 256bit-key-for-config-encryption
dev = 256bit-key-for-config-encryption
Environment Variable (Azure):
- Variable name: Value of
APP_KEY_SYSVAR(e.g.,CONFIG_KEY) - Value: 256-bit base64-encoded master key
- Used for production and integration environments
3. Developer Workflow
3.1 Adding New Encrypted Keys
Step 1: Identify Secret Value
- Locate configuration value ending with
_SECRET - Determine if it's text or JSON format
Step 2: Use Encryption Tool
cd gateway
python tool_encrypt_config_value.py --value "my_secret_value" --env dev
Step 3: Update Configuration File
- Copy encrypted output to appropriate
.envfile - Replace plain text value with encrypted version
Step 4: Verify
- Restart application
- Confirm secret is properly decrypted and accessible
3.2 Development Environment Setup
Prerequisites:
- Master key file exists at
<key file path>/key.txt - Environment variable
APP_KEY_SYSVARpoints to key file path - Environment variable
APP_ENV_TYPEset todev
Setup Steps:
- Generate Master Key: Create secure 256-bit key for development
- Create Key File: Save key in
<key file path>/key.txtwithdev = <key> - Configure Environment: Set
APP_KEY_SYSVARto key file path - Test Encryption: Use tool to encrypt a test value
- Verify Decryption: Confirm application can decrypt values
- Share key file with developer: Share the key file with the developer
3.3 Azure Environment Setup
Production Environment:
- Generate Production Key: Create unique 256-bit master key
- Store in Azure: Add as environment variable with name from
APP_KEY_SYSVAR - Deploy: Application automatically uses Azure environment variable
Integration Environment:
- Generate Integration Key: Create unique 256-bit master key
- Store in Azure: Add as environment variable
- Deploy: Application uses integration-specific master key
4. Security Considerations
4.1 Master Key Protection
- Never log master keys in application logs
- Use secure key derivation (PBKDF2 with 100,000 iterations)
- Environment isolation prevents cross-environment decryption
- External storage keeps keys out of code repository
4.2 Encryption Security
- AES-256-GCM encryption provides authenticated encryption
- Unique salt per environment prevents key reuse
- Base64 encoding for safe storage in configuration files
- Environment prefixes prevent accidental cross-environment usage
4.3 Key Rotation Strategy
- Regular rotation of master keys: No rotation, as keys are rotated
5. Configuration File Structure
5.1 Environment Files
gateway/
├── .env # Active environment file for the application
├── env_dev.env # Environment file for development including encrypted keys (*_SECRET)
├── env_int.env # Environment file for integration including encrypted keys (*_SECRET)
├── env_prod.env # Environment file for production including encrypted keys (*_SECRET)
└── config.ini # Non-sensitive configuration parts for all environments
5.2 Encrypted Value Format
# Text secrets
API_KEY_SECRET = DEV_ENC:gAAAAABh...encrypted_value...
# JSON secrets
SERVICE_ACCOUNT_SECRET = DEV_ENC:gAAAAABh...encrypted_json...
6. Monitoring and Alerts
- Track decryption attempts per environment
- Alert on failed decryptions or missing keys
- Log security events (without exposing keys)
7. Best Practices
7.1 Developer Guidelines
- Always use encryption tool for new secrets
- Never commit plain text secrets to repository
- Test decryption after encryption
- Use environment-specific tools for each environment
7.2 Production Guidelines
- Secure key storage in Azure Key Vault (future enhancement)
- Audit logging for all key operations
- Documentation updates for any changes