|
| 1 | +# Rails Credentials for Platform ntfy - Quick Guide |
| 2 | + |
| 3 | +## TL;DR |
| 4 | + |
| 5 | +**You have per-environment credentials set up correctly!** ✅ |
| 6 | + |
| 7 | +In development, Rails reads from: |
| 8 | +- `config/credentials/development.yml.enc` (encrypted) |
| 9 | +- Decrypted with `config/credentials/development.key` |
| 10 | + |
| 11 | +The shared `config/credentials.yml.enc` is **ignored** in development when per-environment credentials exist. |
| 12 | + |
| 13 | +## File Structure |
| 14 | + |
| 15 | +``` |
| 16 | +config/ |
| 17 | +├── credentials.yml.enc # Shared (used as fallback) |
| 18 | +├── master.key # Key for shared credentials |
| 19 | +└── credentials/ |
| 20 | + ├── development.yml.enc # Development-only ✅ (being used) |
| 21 | + ├── development.key # Key for development |
| 22 | + ├── production.yml.enc # Production-only (create when deploying) |
| 23 | + └── production.key # Key for production |
| 24 | +``` |
| 25 | + |
| 26 | +## Precedence Rules |
| 27 | + |
| 28 | +Rails uses this order: |
| 29 | + |
| 30 | +1. **First**: `config/credentials/{RAILS_ENV}.yml.enc` (if it exists) |
| 31 | +2. **Fallback**: `config/credentials.yml.enc` (if environment-specific doesn't exist) |
| 32 | + |
| 33 | +**Current state (development)**: |
| 34 | +- ✅ `development.yml.enc` exists → **Uses this** |
| 35 | +- ℹ️ `credentials.yml.enc` exists → **Ignored** |
| 36 | + |
| 37 | +## Why This is Better |
| 38 | + |
| 39 | +### Per-Environment Credentials (What You Have) |
| 40 | + |
| 41 | +```yaml |
| 42 | +# config/credentials/development.yml.enc |
| 43 | +platform_ntfy: |
| 44 | + topic: pwb-dev-alerts |
| 45 | + |
| 46 | +# config/credentials/production.yml.enc (to create) |
| 47 | +platform_ntfy: |
| 48 | + topic: pwb-production-alerts |
| 49 | + access_token: tk_secret_production_token |
| 50 | +``` |
| 51 | +
|
| 52 | +**Advantages**: |
| 53 | +- ✅ Different topics per environment |
| 54 | +- ✅ Production secrets never on dev machines |
| 55 | +- ✅ Easy to manage environment-specific config |
| 56 | +- ✅ Can disable in test by not creating test credentials |
| 57 | +
|
| 58 | +### Shared Credentials (Alternative) |
| 59 | +
|
| 60 | +```yaml |
| 61 | +# config/credentials.yml.enc (shared across all environments) |
| 62 | +platform_ntfy: |
| 63 | + topic: pwb-platform-alerts # Same everywhere! |
| 64 | +``` |
| 65 | +
|
| 66 | +**Disadvantages**: |
| 67 | +- ❌ Can't have different topics per environment |
| 68 | +- ❌ Production key needed on dev machines |
| 69 | +- ❌ More security risk |
| 70 | +
|
| 71 | +## Editing Credentials |
| 72 | +
|
| 73 | +### Development (Current Environment) |
| 74 | +```bash |
| 75 | +# Opens config/credentials/development.yml.enc |
| 76 | +rails credentials:edit --environment development |
| 77 | + |
| 78 | +# Or with your preferred editor |
| 79 | +EDITOR="code --wait" rails credentials:edit --environment development |
| 80 | +``` |
| 81 | + |
| 82 | +### Production (When Deploying) |
| 83 | +```bash |
| 84 | +# Creates config/credentials/production.yml.enc and production.key |
| 85 | +rails credentials:edit --environment production |
| 86 | +``` |
| 87 | + |
| 88 | +Add: |
| 89 | +```yaml |
| 90 | +platform_ntfy: |
| 91 | + topic: pwb-production-alerts |
| 92 | + access_token: tk_your_production_token # Optional |
| 93 | + server_url: https://ntfy.yourcompany.com # Optional |
| 94 | +``` |
| 95 | +
|
| 96 | +### Shared (Not Recommended for platform_ntfy) |
| 97 | +```bash |
| 98 | +# Opens config/credentials.yml.enc |
| 99 | +rails credentials:edit |
| 100 | +``` |
| 101 | + |
| 102 | +## Viewing Current Configuration |
| 103 | + |
| 104 | +```bash |
| 105 | +# See what Rails sees right now |
| 106 | +rails runner "puts Rails.application.credentials.dig(:platform_ntfy, :topic)" |
| 107 | +# => pwb-dev-alerts |
| 108 | + |
| 109 | +# Check if enabled |
| 110 | +rails runner "puts PlatformNtfyService.enabled?" |
| 111 | +# => true |
| 112 | +``` |
| 113 | + |
| 114 | +## Deployment Strategy |
| 115 | + |
| 116 | +### Development |
| 117 | +- ✅ Already configured in `development.yml.enc` |
| 118 | +- ✅ `development.key` is gitignored (safe) |
| 119 | +- ✅ Topic: `pwb-dev-alerts` |
| 120 | + |
| 121 | +### Staging (If Needed) |
| 122 | +```bash |
| 123 | +rails credentials:edit --environment staging |
| 124 | +``` |
| 125 | + |
| 126 | +```yaml |
| 127 | +platform_ntfy: |
| 128 | + topic: pwb-staging-alerts |
| 129 | +``` |
| 130 | +
|
| 131 | +### Production |
| 132 | +```bash |
| 133 | +rails credentials:edit --environment production |
| 134 | +``` |
| 135 | + |
| 136 | +```yaml |
| 137 | +platform_ntfy: |
| 138 | + topic: pwb-production-alerts |
| 139 | + access_token: tk_your_secret_token |
| 140 | +``` |
| 141 | +
|
| 142 | +**Important**: |
| 143 | +- Keep `config/credentials/production.key` secure! |
| 144 | +- Add it to your deployment secrets manager |
| 145 | +- Never commit it to git (already in .gitignore) |
| 146 | + |
| 147 | +## Testing |
| 148 | + |
| 149 | +### Test Environment |
| 150 | +You have two options: |
| 151 | + |
| 152 | +**Option 1: Disable in tests (Recommended)** |
| 153 | +- Don't create `test.yml.enc` |
| 154 | +- Tests run faster, no external dependencies |
| 155 | +- Current specs mock the service anyway ✅ |
| 156 | + |
| 157 | +**Option 2: Enable with test credentials** |
| 158 | +```bash |
| 159 | +rails credentials:edit --environment test |
| 160 | +``` |
| 161 | + |
| 162 | +```yaml |
| 163 | +platform_ntfy: |
| 164 | + topic: pwb-test-alerts |
| 165 | +``` |
| 166 | + |
| 167 | +## Security Notes |
| 168 | + |
| 169 | +### Keys (.key files) |
| 170 | +- ✅ Already in `.gitignore` |
| 171 | +- ✅ Never commit to git |
| 172 | +- ⚠️ Back them up securely (password manager, secrets manager) |
| 173 | +- ⚠️ Share production keys only with authorized team members |
| 174 | + |
| 175 | +### Encrypted Files (.yml.enc) |
| 176 | +- ✅ Safe to commit to git (they're encrypted) |
| 177 | +- ✅ Can be in version control |
| 178 | +- ℹ️ Useless without the corresponding `.key` file |
| 179 | + |
| 180 | +## Troubleshooting |
| 181 | + |
| 182 | +### "Can't decrypt" errors |
| 183 | +```bash |
| 184 | +# Make sure the .key file exists |
| 185 | +ls config/credentials/development.key |
| 186 | +
|
| 187 | +# Make sure it has the correct permissions |
| 188 | +chmod 600 config/credentials/development.key |
| 189 | +``` |
| 190 | + |
| 191 | +### Check which file is being used |
| 192 | +```bash |
| 193 | +rails runner " |
| 194 | +if File.exist?('config/credentials/#{Rails.env}.yml.enc') |
| 195 | + puts 'Using: config/credentials/#{Rails.env}.yml.enc' |
| 196 | +else |
| 197 | + puts 'Using: config/credentials.yml.enc (fallback)' |
| 198 | +end |
| 199 | +" |
| 200 | +``` |
| 201 | + |
| 202 | +### Platform ntfy not working |
| 203 | +```bash |
| 204 | +# Check credentials are set |
| 205 | +rails runner " |
| 206 | +creds = Rails.application.credentials |
| 207 | +puts 'Topic: ' + (creds.dig(:platform_ntfy, :topic) || 'NOT SET').to_s |
| 208 | +puts 'Enabled: ' + PlatformNtfyService.enabled?.to_s |
| 209 | +" |
| 210 | +``` |
| 211 | + |
| 212 | +## Quick Reference |
| 213 | + |
| 214 | +| File | Used When | Key File | Current State | |
| 215 | +|------|-----------|----------|---------------| |
| 216 | +| `credentials.yml.enc` | Fallback only | `master.key` | ✅ Exists (fallback) | |
| 217 | +| `credentials/development.yml.enc` | Development | `credentials/development.key` | ✅ Exists & Active | |
| 218 | +| `credentials/production.yml.enc` | Production | `credentials/production.key` | ❌ Create before deploy | |
| 219 | +| `credentials/test.yml.enc` | Test | `credentials/test.key` | ❌ Optional (not created) | |
| 220 | + |
| 221 | +--- |
| 222 | + |
| 223 | +**Current Status**: ✅ Development credentials configured and working! |
| 224 | + |
| 225 | +Your platform ntfy setup is using per-environment credentials correctly. When you deploy to production, just create the production credentials file with the appropriate topic and access token. |
0 commit comments