|
| 1 | +# AWS Authentication |
| 2 | + |
| 3 | +Keep uses AWS services (SSM Parameter Store and Secrets Manager) to store your secrets. This page explains how to properly configure AWS authentication so Keep can access these vaults. |
| 4 | + |
| 5 | +## The Secret Zero Problem |
| 6 | + |
| 7 | +Before diving into solutions, it's worth understanding the "Secret Zero" problem: if Keep fetches secrets from AWS to generate your `.env` file, but AWS credentials are typically stored in `.env` files... we have a circular dependency. You need credentials to get credentials. |
| 8 | + |
| 9 | +The solution is to keep AWS authentication separate from your application secrets. |
| 10 | + |
| 11 | +## What NOT to Do |
| 12 | + |
| 13 | +```env |
| 14 | +# .env file - DON'T DO THIS with Keep! |
| 15 | +AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE |
| 16 | +AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY |
| 17 | +DB_PASSWORD=my-secret-password |
| 18 | +API_KEY=sk_live_abc123 |
| 19 | +``` |
| 20 | + |
| 21 | +Storing AWS credentials in `.env` defeats the purpose of Keep. You're storing the keys to the vault alongside the secrets themselves. |
| 22 | + |
| 23 | +## Authentication Methods |
| 24 | + |
| 25 | +### Development Environment |
| 26 | + |
| 27 | +**Option 1: AWS CLI Configuration (Good)** |
| 28 | + |
| 29 | +Use the AWS CLI's standard credential file: |
| 30 | + |
| 31 | +```bash |
| 32 | +# Configure AWS CLI |
| 33 | +aws configure |
| 34 | + |
| 35 | +# This creates ~/.aws/credentials |
| 36 | +[default] |
| 37 | +aws_access_key_id = AKIAIOSFODNN7EXAMPLE |
| 38 | +aws_secret_access_key = wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY |
| 39 | +region = us-east-1 |
| 40 | +``` |
| 41 | + |
| 42 | +Keep automatically uses these credentials. Your `.env` file stays clean: |
| 43 | + |
| 44 | +```env |
| 45 | +# .env - generated by Keep, no AWS credentials! |
| 46 | +DB_PASSWORD=my-secret-password |
| 47 | +API_KEY=sk_live_abc123 |
| 48 | +``` |
| 49 | + |
| 50 | +**Option 2: aws-vault (Better)** |
| 51 | + |
| 52 | +[aws-vault](https://github.com/99designs/aws-vault) stores credentials encrypted in your OS keychain: |
| 53 | + |
| 54 | +```bash |
| 55 | +# Install aws-vault |
| 56 | +brew install aws-vault # macOS |
| 57 | +# or download from GitHub releases |
| 58 | + |
| 59 | +# Add your default AWS profile, or use a named profile |
| 60 | +aws-vault add default |
| 61 | +``` |
| 62 | + |
| 63 | +Edit your ~/.aws/config to set a default region and use aws-vault for credential_process: |
| 64 | + |
| 65 | +```ini |
| 66 | +[default] |
| 67 | +region = us-east-1 |
| 68 | +credential_process = aws-vault exec default --json --no-session |
| 69 | +``` |
| 70 | + |
| 71 | +Edit your ~/.aws/credentials and add the same credential_process: |
| 72 | + |
| 73 | +```ini |
| 74 | +[default] |
| 75 | +credential_process = aws-vault exec default --json --no-session |
| 76 | +``` |
| 77 | + |
| 78 | +Now when you run Keep (or any AWS CLI command), it will use aws-vault to fetch temporary credentials automatically. |
| 79 | + |
| 80 | +**Option 3: AWS SSO (Best for Teams)** |
| 81 | + |
| 82 | +If your organization uses AWS SSO: |
| 83 | + |
| 84 | +```bash |
| 85 | +# Configure SSO |
| 86 | +aws configure sso |
| 87 | + |
| 88 | +# Login |
| 89 | +aws sso login --profile myproject |
| 90 | + |
| 91 | +# Keep uses the SSO session automatically |
| 92 | +keep list --stage=development |
| 93 | +``` |
| 94 | + |
| 95 | +### Production Environment |
| 96 | + |
| 97 | +**Option 1: EC2 Instance Roles (Best for AWS)** |
| 98 | + |
| 99 | +When running on EC2, ECS, or Lambda, use IAM roles: |
| 100 | + |
| 101 | +```bash |
| 102 | +# No credentials needed in your application! |
| 103 | +# The AWS SDK automatically uses the instance role |
| 104 | + |
| 105 | +# In your deployment script: |
| 106 | +keep export --stage=production --output=.env |
| 107 | +php artisan config:cache |
| 108 | +``` |
| 109 | + |
| 110 | +Configure your EC2 instance role with appropriate IAM permissions for your vault type. |
| 111 | + |
| 112 | +**Option 2: Non-AWS Servers** |
| 113 | + |
| 114 | +For servers outside AWS, you have limited secure options: |
| 115 | + |
| 116 | +```bash |
| 117 | +# Option A: Credentials file on server (secured with proper permissions) |
| 118 | +# /home/myapp/.aws/credentials (chmod 600) |
| 119 | +[default] |
| 120 | +aws_access_key_id = AKIAIOSFODNN7EXAMPLE |
| 121 | +aws_secret_access_key = wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY |
| 122 | + |
| 123 | +# Option B: Environment variables set during provisioning |
| 124 | +# For systemd services: /etc/systemd/system/myapp.service.d/override.conf |
| 125 | +[Service] |
| 126 | +Environment="AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE" |
| 127 | +Environment="AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY" |
| 128 | + |
| 129 | +# For Docker: passed securely during container start |
| 130 | +docker run -e AWS_ACCESS_KEY_ID=... -e AWS_SECRET_ACCESS_KEY=... myapp |
| 131 | + |
| 132 | +# For traditional setups: /etc/environment or user's ~/.bashrc |
| 133 | +``` |
| 134 | + |
| 135 | +## CI/CD Pipelines |
| 136 | + |
| 137 | +**GitHub Actions** |
| 138 | + |
| 139 | +Use OIDC (recommended) or secrets: |
| 140 | + |
| 141 | +```yaml |
| 142 | +# .github/workflows/deploy.yml |
| 143 | +name: Deploy |
| 144 | +on: push |
| 145 | + |
| 146 | +jobs: |
| 147 | + deploy: |
| 148 | + runs-on: ubuntu-latest |
| 149 | + permissions: |
| 150 | + id-token: write # for OIDC |
| 151 | + steps: |
| 152 | + - uses: aws-actions/configure-aws-credentials@v4 |
| 153 | + with: |
| 154 | + role-to-assume: arn:aws:iam::123456789012:role/github-actions |
| 155 | + aws-region: us-east-1 |
| 156 | + |
| 157 | + - run: | |
| 158 | + vendor/bin/keep export --stage=production --output=.env |
| 159 | + # Deploy your application |
| 160 | +``` |
| 161 | +
|
| 162 | +**GitLab CI** |
| 163 | +
|
| 164 | +```yaml |
| 165 | +# .gitlab-ci.yml |
| 166 | +deploy: |
| 167 | + script: |
| 168 | + # Using GitLab's AWS integration |
| 169 | + - vendor/bin/keep export --stage=production --output=.env |
| 170 | + id_tokens: |
| 171 | + AWS_TOKEN: |
| 172 | + aud: https://gitlab.com |
| 173 | +``` |
| 174 | +
|
| 175 | +## Security Best Practices |
| 176 | +
|
| 177 | +### Never Do This |
| 178 | +
|
| 179 | +❌ Store AWS credentials in your repository |
| 180 | +❌ Put AWS credentials in `.env` files tracked by git |
| 181 | +❌ Use long-lived AWS access keys in production |
| 182 | +❌ Share AWS credentials between environments |
| 183 | + |
| 184 | +### Always Do This |
| 185 | + |
| 186 | +✅ Use temporary credentials when possible (aws-vault, SSO, instance roles) |
| 187 | +✅ Apply least-privilege IAM policies |
| 188 | +✅ Rotate credentials regularly |
| 189 | +✅ Use different credentials for each environment |
| 190 | +✅ Audit credential usage with CloudTrail |
| 191 | + |
| 192 | +## Quick Decision Guide |
| 193 | + |
| 194 | +| Environment | Hosting | Recommended Solution | |
| 195 | +|------------|---------|---------------------| |
| 196 | +| Development | Local | aws-vault or AWS SSO | |
| 197 | +| Production | EC2/ECS | Instance/Task IAM Roles | |
| 198 | +| Production | Lambda | Lambda Execution Role | |
| 199 | +| Production | Kubernetes (EKS) | IRSA (Service Accounts) | |
| 200 | +| Production | Non-AWS | ~/.aws/credentials (secured) | |
| 201 | +| CI/CD | GitHub Actions | OIDC with IAM Role | |
| 202 | +| CI/CD | GitLab | OIDC with IAM Role | |
| 203 | +| CI/CD | Other | Secure secret storage | |
| 204 | + |
| 205 | +## IAM Permissions |
| 206 | + |
| 207 | +After setting up authentication, you need to configure IAM permissions for the AWS services Keep will access: |
| 208 | + |
| 209 | +- **For AWS SSM Parameter Store**: See [SSM IAM Permissions](/guide/vaults/aws-ssm#iam-permissions) |
| 210 | +- **For AWS Secrets Manager**: See [Secrets Manager IAM Permissions](/guide/vaults/aws-secrets-manager#iam-permissions) |
| 211 | + |
| 212 | +Each vault type requires specific IAM permissions based on your usage pattern (read-only, read-write, or admin access). |
| 213 | + |
| 214 | +## Laravel-Specific Considerations |
| 215 | + |
| 216 | +When using Keep with Laravel: |
| 217 | + |
| 218 | +1. **Don't cache config with AWS credentials** |
| 219 | + ```php |
| 220 | + // config/aws.php - DON'T DO THIS |
| 221 | + 'credentials' => [ |
| 222 | + 'key' => env('AWS_ACCESS_KEY_ID'), |
| 223 | + 'secret' => env('AWS_SECRET_ACCESS_KEY'), |
| 224 | + ] |
| 225 | + ``` |
| 226 | + |
| 227 | +2. **Let the SDK find credentials automatically** |
| 228 | + ```php |
| 229 | + // config/aws.php - DO THIS |
| 230 | + 'credentials' => null, // SDK will use IAM role, ~/.aws/credentials, etc. |
| 231 | + ``` |
| 232 | + |
| 233 | +3. **Generate .env before config:cache** |
| 234 | + ```bash |
| 235 | + # deployment.sh |
| 236 | + keep export --stage=production --output=.env |
| 237 | + php artisan config:cache |
| 238 | + php artisan route:cache |
| 239 | + ``` |
| 240 | + |
| 241 | +## Troubleshooting |
| 242 | + |
| 243 | +**"Keep can't find AWS credentials"** |
| 244 | + |
| 245 | +Check credential chain: |
| 246 | +```bash |
| 247 | +# 1. Environment variables |
| 248 | +env | grep AWS |
| 249 | +
|
| 250 | +# 2. Credentials file |
| 251 | +cat ~/.aws/credentials |
| 252 | +
|
| 253 | +# 3. Instance role (on EC2) |
| 254 | +curl http://169.254.169.254/latest/meta-data/iam/security-credentials/ |
| 255 | +
|
| 256 | +# 4. Test with AWS CLI |
| 257 | +aws sts get-caller-identity |
| 258 | +``` |
| 259 | + |
| 260 | +**"Access denied when Keep tries to fetch secrets"** |
| 261 | + |
| 262 | +Verify IAM permissions: |
| 263 | +```bash |
| 264 | +# Test SSM access |
| 265 | +aws ssm get-parameter --name /myapp/production/test |
| 266 | +
|
| 267 | +# Test Secrets Manager access |
| 268 | +aws secretsmanager get-secret-value --secret-id myapp/production/test |
| 269 | +``` |
| 270 | + |
| 271 | +## Summary |
| 272 | + |
| 273 | +The Secret Zero problem is real, but solvable. By keeping AWS credentials **out** of your application configuration and using platform-native credential management, you maintain security while enabling Keep to manage your application secrets effectively. |
| 274 | + |
| 275 | +Remember: Keep manages your application secrets, not your AWS credentials. Keep AWS credentials separate, secure, and platform-appropriate. |
0 commit comments