Commit d3137e1
authored
[🔥AUDIT🔥] Fix secret access timing and deletion protection issues in scheduled-job module (#13)
🖍 _This is an audit!_ 🖍
## Summary:
Fixed a critical issue in the scheduled-job module where Cloud Run Jobs could not access secrets from different projects.
**Root Cause**: Cloud Run Jobs were referencing secrets without specifying the project ID, causing them to look for secrets in the same project where the job was running instead of the project where the secret actually exists.
**Solution**: Updated the secret reference in Cloud Run Jobs to use the full project path format: `projects/{project_id}/secrets/{secret_id}` for cross-project secret access.
**Additional Fix**: Added `deletion_protection = false` to Cloud Run Jobs to allow Terraform to properly manage the job lifecycle.
## Changes:
- **Cloud Run Job secret reference**: Now uses `projects/${var.secrets_project_id}/secrets/${env.value.secret_id}` format for cross-project secret access
- **Cloud Run Job lifecycle**: Added `deletion_protection = false` to allow Terraform to destroy and recreate jobs when needed
- **Dependencies**: Simplified to just depend on service account creation for proper resource ordering
## Technical Details:
The issue occurred because:
1. Secrets were stored in `khan-academy` project
2. Cloud Run Jobs were created in `khan-internal-services` project
3. Jobs were trying to access secrets using just the secret name, which defaulted to the same project
4. This caused "Permission denied on secret" errors even though IAM bindings were correct
The fix ensures Cloud Run Jobs explicitly reference secrets with their full project path, resolving the cross-project access issue.
Issue: None
## Test plan:
1. Deploy a Cloud Run Job with secrets from a different project using the scheduled-job module
2. Verify the job can access cross-project secrets without permission errors
3. Test both function and job execution types
4. Confirm Terraform can destroy and recreate jobs when needed
5. Verify no regression in existing functionality for same-project secrets
Author: jwbron
Auditors: csilvers
Required Reviewers:
Approved By:
Checks: ⏭️ 1 check has been skipped, ✅ 1 check was successful
Pull Request URL: #131 parent c21a7e3 commit d3137e1
1 file changed
Lines changed: 10 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
107 | 110 | | |
108 | 111 | | |
109 | 112 | | |
| |||
160 | 163 | | |
161 | 164 | | |
162 | 165 | | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
163 | 172 | | |
164 | 173 | | |
165 | 174 | | |
| |||
201 | 210 | | |
202 | 211 | | |
203 | 212 | | |
204 | | - | |
| 213 | + | |
205 | 214 | | |
206 | 215 | | |
207 | 216 | | |
| |||
0 commit comments