Overview
AWS credentials are automatically configured onwork and hybrid machines by pulling secrets from Bitwarden.
Prerequisites
- Bitwarden CLI (
bw) installed - Bitwarden vault unlocked
- AWS credentials stored in Bitwarden as an item named
AWS {work_email}
Required Bitwarden Fields
Your Bitwarden item must have these custom fields:- Access key: AWS access key ID
- Secret access key: AWS secret access key
- Region: Default AWS region (e.g.,
us-east-1)
AWS Config Template
Configuration file pulled from Bitwarden:dot_aws/private_config.tmpl
~/.aws/config with the region from Bitwarden.
AWS Credentials Template
Credentials file pulled from Bitwarden:dot_aws/private_credentials.tmpl
~/.aws/credentials with access keys from Bitwarden.
Bitwarden Item Lookup
The item name is dynamically constructed:work_email is [email protected], it looks for an item named:
How It Works
- During
chezmoi init, you’re prompted for work email (if work/hybrid machine) - Chezmoi uses
bitwardenFieldsfunction to fetch fields from Bitwarden - Access keys, secret keys, and region are pulled from custom fields
- Files are templated and placed in
~/.aws/configand~/.aws/credentials - Files are marked as
private_(encrypted with age)
Switching AWS Profiles
Use theaws_env function to switch between profiles:
- Validates the profile exists
- Exports
AWS_PROFILE,AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY,AWS_DEFAULT_REGION - Displays all exported AWS environment variables
AWS Environment Function
Fromdot_bash_functions:
Bitwarden Session Management
Unlock Bitwarden before runningchezmoi apply:
Security Features
Encrypted Storage
AWS files are encrypted with age:- Prefix
private_tells chezmoi to encrypt the file - Only decrypted when applied to the home directory
- Source files in chezmoi remain encrypted in the repository
File Permissions
AWS credentials files are created with restrictive permissions:Adding Additional Profiles
To add more AWS profiles, edit the templates:dot_aws/private_config.tmpl
dot_aws/private_credentials.tmpl
Troubleshooting
Bitwarden Not Unlocked
Item Not Found
Missing Custom Fields
Ensure your Bitwarden item has custom fields with exact names:Access key(not “access_key” or “AccessKey”)Secret access key(not “secret_access_key”)Region(not “region”)