Setup
Install Azure CLI
Log In
Authenticate with Azure:Set Permissions
Your user or service principal needs the Key Vault Secrets User RBAC role:Configuration
Set a default vault in your chezmoi config:~/.config/chezmoi/chezmoi.toml
Template Function
azureKeyVault
Retrieve a secret from Azure Key Vault:
Usage Examples
Using Default Vault
Using Explicit Vault Names
~/.config/app/config.yml.tmpl
Using Vault Aliases
Define vault aliases in your config:~/.config/chezmoi/chezmoi.toml
~/.config/app/config.yml.tmpl
Database Credentials
~/.config/db/config.yml.tmpl
API Keys
~/.config/api-keys.env.tmpl
SSH Keys
Git Configuration
~/.gitconfig.tmpl
NPM Configuration
~/.npmrc.tmpl
Kubernetes Config
~/.kube/config.tmpl
Managing Secrets in Azure Key Vault
Create Secrets
List Secrets
Show Secret Value
Delete Secrets
Advanced Usage
Environment-Specific Vaults
~/.config/app/config.yml.tmpl
Secret Versioning
By default, chezmoi retrieves the latest version. Azure Key Vault maintains version history automatically.Multi-Vault Configuration
~/.config/chezmoi/chezmoi.toml
Complete Examples
Multi-Service Application Config
~/.config/services.yml.tmpl
Azure Service Connection
~/.azure/credentials.tmpl
RBAC Permissions
Required Azure RBAC role:- Key Vault Secrets User: Read secret contents
Troubleshooting
Access Denied
Ensure you have the correct RBAC role:Vault Not Found
Verify the vault exists and you have access:Secret Not Found
List secrets in the vault:Authentication Failed
Re-authenticate:Testing Templates
Test template functions:Best Practices
- Use RBAC: Prefer RBAC over access policies for granular control
- Separate vaults: Use different vaults for different environments
- Least privilege: Grant minimum required permissions
- Enable soft delete: Protect against accidental deletion
- Enable purge protection: Prevent permanent deletion during retention period
- Use managed identities: On Azure VMs, use managed identities instead of service principals
- Monitor access: Enable diagnostic logs and alerts
- Use private endpoints: Access Key Vault privately from VNet
- Rotate secrets: Implement secret rotation policies
- Tag secrets: Use tags for organization and cost tracking
Cost Considerations
Azure Key Vault pricing:- Standard tier: $0.03 per 10,000 operations
- Premium tier: $0.03 per 10,000 operations + HSM operations