Password Encryption
Addax supports password encryption to enhance security when storing database credentials in configuration files.
Overview
Instead of storing passwords in plain text in job configuration files, you can use encrypted passwords. This feature helps protect sensitive credentials, especially in shared environments or version control systems.
Generating Encrypted Passwords
Use the provided script to encrypt passwords:
bin/encrypt.sh <password>Example:
bin/encrypt.sh mypassword123Output:
Encrypted password: addax:enc:AES:7kMgvpYVGh2kH5tZ1AxyHQ==
Using Encrypted Passwords
In Job Configuration
Replace plain text passwords with encrypted ones in your job configuration:
{
"job": {
"content": {
"reader": {
"name": "mysqlreader",
"parameter": {
"username": "dbuser",
"password": "addax:enc:AES:7kMgvpYVGh2kH5tZ1AxyHQ==",
"connection":
{
"jdbcUrl": "jdbc:mysql://localhost:3306/testdb",
"table": ["users"]
}
}
}
}
}
}Environment Variables
You can also store encrypted passwords in environment variables:
export DB_PASSWORD="addax:enc:AES:7kMgvpYVGh2kH5tZ1AxyHQ=="Then reference it in your configuration:
{
"parameter": {
"password": "${DB_PASSWORD}"
}
}Encryption Algorithm
Addax uses AES (Advanced Encryption Standard) for password encryption:
- Algorithm: AES-128
- Mode: CBC (Cipher Block Chaining)
- Padding: PKCS5Padding
- Key: Generated based on system properties
Security Considerations
Key Management
The encryption key is derived from system properties. For enhanced security:
Set custom encryption key:
bashexport ADDAX_ENCRYPT_KEY="your-custom-key-here"Use different keys per environment:
bash# Development export ADDAX_ENCRYPT_KEY="dev-key-2024" # Production export ADDAX_ENCRYPT_KEY="prod-key-2024"
Best Practices
- Rotate encryption keys regularly
- Use different keys for different environments
- Store keys securely (not in source code)
- Limit access to encryption keys
- Use encrypted passwords for all sensitive data
Advanced Usage
Custom Encryption Provider
You can implement a custom encryption provider by implementing the PasswordEncryptor interface:
public class CustomPasswordEncryptor implements PasswordEncryptor {
@Override
public String encrypt(String plainPassword) {
// Your custom encryption logic
return "custom:enc:" + encryptedPassword;
}
@Override
public String decrypt(String encryptedPassword) {
// Your custom decryption logic
return decryptedPassword;
}
}Batch Encryption
For multiple passwords, create a script:
#!/bin/bash
passwords=("password1" "password2" "password3")
for pwd in "${passwords[@]}"; do
echo "Encrypting: $pwd"
bin/encrypt.sh "$pwd"
echo "---"
doneConfiguration Examples
MySQL with Encrypted Password
{
"job": {
"content": [
{
"reader": {
"name": "mysqlreader",
"parameter": {
"username": "readonly_user",
"password": "addax:enc:AES:7kMgvpYVGh2kH5tZ1AxyHQ==",
"column": ["*"],
"connection": [
{
"jdbcUrl": "jdbc:mysql://prod-db:3306/analytics",
"table": ["user_events"]
}
]
}
},
"writer": {
"name": "postgresqlwriter",
"parameter": {
"username": "analytics_user",
"password": "addax:enc:AES:9nPsrKlMN8xR2vY5aBcDfG==",
"column": ["*"],
"connection": [
{
"jdbcUrl": "jdbc:postgresql://warehouse:5432/analytics",
"table": ["user_events"]
}
]
}
}
}
]
}
}Multiple Environments
Development (dev.json):
{
"parameter": {
"password": "addax:enc:AES:devKeyEncryptedPassword=="
}
}Production (prod.json):
{
"parameter": {
"password": "addax:enc:AES:prodKeyEncryptedPassword=="
}
}Troubleshooting
Decryption Errors
If you encounter decryption errors:
- Verify encryption key: Ensure the same key is used for encryption and decryption
- Check password format: Ensure the encrypted password starts with
addax:enc:AES: - Validate environment: Confirm environment variables are set correctly
Password Not Recognized
# Test decryption
bin/decrypt.sh "addax:enc:AES:7kMgvpYVGh2kH5tZ1AxyHQ=="Key Management Issues
# Check current encryption key
echo $ADDAX_ENCRYPT_KEY
# Set temporary key for testing
export ADDAX_ENCRYPT_KEY="test-key-123"Migration Guide
From Plain Text to Encrypted
- Identify all passwords in configuration files
- Encrypt each password using the encrypt script
- Replace plain text with encrypted values
- Test the configuration to ensure it works
- Update documentation with new security procedures
Example Migration Script
#!/bin/bash
# Backup original files
cp config/job.json config/job.json.backup
# Replace passwords (adjust patterns as needed)
sed -i 's/"password": "plainpassword"/"password": "addax:enc:AES:encryptedvalue"/g' config/job.json
echo "Migration complete. Test the configuration before deploying."This encryption feature significantly improves the security posture of your Addax deployments while maintaining ease of use.