VaultX Configuration

View Source

VaultX provides comprehensive configuration management with support for environment variables, application configuration, and runtime validation. This guide covers all available configuration options and best practices.

Configuration Philosophy

VaultX follows modern Elixir library conventions:

  • Stateless: No GenServer or caching, pure function-based configuration
  • Dynamic: Configuration changes take effect immediately
  • Hierarchical: Environment variables override application configuration
  • Validated: Comprehensive validation using NimbleOptions
  • Secure: Built-in security validation and best practices

Configuration Sources

Configuration is resolved in the following priority order:

  1. Environment variables (highest priority)
  2. Application configuration
  3. Default values (lowest priority)

Core Configuration

Basic Settings

SettingEnvironment VariableDefaultDescription
urlVAULTX_URL or VAULT_ADDRhttp://localhost:8200Vault server URL
tokenVAULTX_TOKEN or VAULT_TOKENnilAuthentication token
namespaceVAULTX_NAMESPACE or VAULT_NAMESPACEnilVault namespace (Enterprise)

Network & Timeouts

SettingEnvironment VariableDefaultDescription
timeoutVAULTX_TIMEOUT30000Request timeout (ms)
connect_timeoutVAULTX_CONNECT_TIMEOUT10000Connection timeout (ms)
retry_attemptsVAULTX_RETRY_ATTEMPTS3Number of retry attempts
retry_delayVAULTX_RETRY_DELAY1000Initial retry delay (ms)
retry_backoffVAULTX_RETRY_BACKOFFexponentialBackoff strategy (linear/exponential)
max_retry_delayVAULTX_MAX_RETRY_DELAY30000Maximum retry delay (ms)

SSL/TLS Configuration

SettingEnvironment VariableDefaultDescription
ssl_verifyVAULTX_SSL_VERIFYtrueEnable SSL verification
cacertVAULTX_CACERT or VAULT_CACERTnilCA certificate file path
cacerts_dirVAULTX_CACERTS_DIRnilDirectory of CA certificates (loaded into :cacerts)
client_certVAULTX_CLIENT_CERT or VAULT_CLIENT_CERTnilClient certificate (mTLS)
client_keyVAULTX_CLIENT_KEY or VAULT_CLIENT_KEYnilClient private key (mTLS)
tls_server_nameVAULTX_TLS_SERVER_NAMEnilTLS SNI server name
tls_min_versionVAULTX_TLS_MIN_VERSION1.2Minimum TLS version

Connection Pool

SettingEnvironment VariableDefaultDescription
pool_sizeVAULTX_POOL_SIZE10Connection pool size
pool_max_idle_timeVAULTX_POOL_MAX_IDLE_TIME300000Max idle time (ms)

Logging & Telemetry

SettingEnvironment VariableDefaultDescription
logger_levelVAULTX_LOGGER_LEVELinfoLogger level
telemetry_enabledVAULTX_TELEMETRY_ENABLEDtrueEnable telemetry
audit_enabledVAULTX_AUDIT_ENABLEDfalseEnable audit logging
metrics_enabledVAULTX_METRICS_ENABLEDtrueEnable metrics

Security & Compliance

SettingEnvironment VariableDefaultDescription
rate_limit_enabledVAULTX_RATE_LIMIT_ENABLEDfalseEnable rate limiting
rate_limit_requestsVAULTX_RATE_LIMIT_REQUESTS100Requests per second (per-bucket: host|namespace)
rate_limit_burstVAULTX_RATE_LIMIT_BURST0Additional burst tokens allowed
token_renewal_enabledVAULTX_TOKEN_RENEWAL_ENABLEDtrueAuto token renewal
token_renewal_thresholdVAULTX_TOKEN_RENEWAL_THRESHOLD80Renewal threshold (%)
security_headers_enabledVAULTX_SECURITY_HEADERS_ENABLEDfalseValidate security headers (non-fatal warnings)

Usage Examples

Basic Configuration

# Get complete configuration
config = Vaultx.Base.Config.get()

# Get specific values
url = Vaultx.Base.Config.get_url()
timeout = Vaultx.Base.Config.get_timeout()

Environment Variables

# Core settings
export VAULTX_URL="https://vault.example.com:8200"
export VAULTX_TOKEN="hvs.CAESIJ..."
export VAULTX_NAMESPACE="my-namespace"

# SSL/TLS settings
export VAULTX_SSL_VERIFY="true"
export VAULTX_CACERT="/etc/ssl/certs/vault-ca.pem"
export VAULTX_CLIENT_CERT="/etc/ssl/certs/client.pem"
export VAULTX_CLIENT_KEY="/etc/ssl/private/client-key.pem"
export VAULTX_CACERTS_DIR="/etc/ssl/certs"

# Performance tuning
export VAULTX_TIMEOUT="60000"
export VAULTX_RETRY_ATTEMPTS="5"
export VAULTX_POOL_SIZE="20"

Application Configuration

# config/config.exs
config :vaultx,
  url: "https://vault.example.com:8200",
  timeout: 30_000,
  retry_attempts: 3,
  ssl_verify: true,
  pool_size: 10

Configuration Validation

# Validate configuration
case Vaultx.Base.Config.validate() do
  :ok -> :ok
  {:error, errors} -> handle_errors(errors)
end

# Get detailed diagnostics
diagnostics = Vaultx.Base.Config.diagnose()
IO.inspect(diagnostics)

Convenience Functions

# Check SSL configuration
Vaultx.Base.Config.ssl_configured?()
Vaultx.Base.Config.mtls_configured?()

# Get grouped configurations
retry_config = Vaultx.Base.Config.get_retry_config()
pool_config = Vaultx.Base.Config.get_pool_config()
# => %{size: 10, max_idle_time: 300_000}

# Print configuration summary
Vaultx.Base.Config.print_summary()

Best Practices

Security

  1. Always use HTTPS in production environments
  2. Enable SSL verification (ssl_verify: true)
  3. Use strong TLS versions (prefer TLS 1.3)
  4. Implement mutual TLS for high-security environments
  5. Enable audit logging for compliance requirements

Performance

  1. Tune connection pools based on your workload
  2. Configure appropriate timeouts for your network
  3. Use exponential backoff for retry strategies
  4. Enable metrics for monitoring
  5. Consider rate limiting to protect Vault

Reliability

  1. Configure retry attempts appropriately
  2. Set reasonable timeouts to avoid hanging requests
  3. Enable token renewal for long-running applications
  4. Monitor configuration diagnostics regularly

Development vs Production

# Development
config :vaultx,
  url: "http://localhost:8200",
  ssl_verify: false,
  logger_level: :debug

# Production
config :vaultx,
  url: {:system, "VAULTX_URL"},
  ssl_verify: true,
  logger_level: :info,
  audit_enabled: true

Troubleshooting

Common Issues

  1. SSL Certificate Errors: Check cacert and ssl_verify settings
  2. Connection Timeouts: Adjust timeout and connect_timeout
  3. Pool Exhaustion: Increase pool_size
  4. Authentication Failures: Verify token and namespace settings

Diagnostic Tools

# Run comprehensive diagnostics
diagnostics = Vaultx.Base.Config.diagnose()

# Check for warnings and recommendations
if not Enum.empty?(diagnostics.warnings) do
  IO.puts("Warnings: #{inspect(diagnostics.warnings)}")
end

# Print configuration summary
Vaultx.Base.Config.print_summary()

Migration Guide

From Previous Versions

The Vaultx library was only officially released to the public starting from version v0.6.0, so there is currently no relevant content for this entry.