grada-run 0.49.4 → 0.49.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/package.json +2 -1
  2. package/src/commands/add.js +1 -1
  3. package/src/commands/alerts.js +1 -1
  4. package/src/commands/apply.js +84 -5
  5. package/src/commands/db/backup.js +3 -3
  6. package/src/commands/db/connect.js +2 -2
  7. package/src/commands/db/enable-vector.js +1 -1
  8. package/src/commands/db/import.js +2 -2
  9. package/src/commands/db/migrate.js +7 -6
  10. package/src/commands/destroy.js +116 -10
  11. package/src/commands/diagnose.js +18 -5
  12. package/src/commands/domain.js +51 -4
  13. package/src/commands/exec.js +1 -1
  14. package/src/commands/gc.js +2 -2
  15. package/src/commands/init.js +7 -7
  16. package/src/commands/logs.js +20 -7
  17. package/src/commands/rollback.js +21 -6
  18. package/src/commands/secrets.js +19 -19
  19. package/src/commands/status.js +3 -3
  20. package/src/commands/wake.js +2 -2
  21. package/src/utils/addons.js +1 -1
  22. package/src/utils/backup.js +1 -1
  23. package/src/utils/ecs-runner.js +3 -3
  24. package/src/utils/generator.js +3 -3
  25. package/src/utils/prompts.js +1 -1
  26. package/src/utils/resolvers.js +8 -10
  27. package/src/utils/terraform-errors.js +47 -0
  28. package/src/utils/terraform.js +1 -1
  29. package/templates/README.md +2 -2
  30. package/templates/github/deploy-lambda.yml +2 -2
  31. package/templates/github/deploy-static.yml +1 -1
  32. package/templates/github/deploy.yml +2 -2
  33. package/templates/github/drift.yml +1 -1
  34. package/templates/github/plan.yml +2 -2
  35. package/templates/github/preview-lambda.yml +4 -4
  36. package/templates/github/preview.yml +4 -4
  37. package/templates/github/teardown.yml +3 -3
  38. package/templates/terraform/addons/bedrock.tf +1 -1
  39. package/templates/terraform/backend.tf +1 -1
  40. package/templates/terraform/cloudfront-lambda.tf +2 -2
  41. package/templates/terraform/cloudfront.tf +3 -3
  42. package/templates/terraform/database-aurora-postgresql.tf +1 -1
  43. package/templates/terraform/main.tf +3 -3
  44. package/templates/terraform/oidc.tf +29 -14
  45. package/templates/terraform/secrets.tf +1 -1
@@ -46,17 +46,15 @@ export function readTerraformComputeTarget(cwd = process.cwd()) {
46
46
  }
47
47
 
48
48
  // Offline database-kind detection for `--setup-ci` (no AWS calls): the
49
- // generator copies exactly one database template, so the aurora file's
50
- // presence means cluster snapshots. Unknown/absent means instance — the
51
- // runtime backup resolves the live kind anyway; the id prefix only
52
- // name-scopes the snapshot for guardrails + gc.
49
+ // generator and `add` always render to database.tf regardless of engine,
50
+ // so the kind comes from the rendered content — an aurora tree declares
51
+ // an rds cluster. Unknown/absent means instance — the runtime backup
52
+ // resolves the live kind anyway; the id prefix only name-scopes the
53
+ // snapshot for guardrails + gc.
53
54
  export function readTerraformDbKind(cwd = process.cwd()) {
54
55
  const base = resolveCwd({}, cwd);
55
- try {
56
- if (fsSync.existsSync(path.join(base, 'terraform', 'database-aurora-postgresql.tf'))) return 'cluster';
57
- } catch {
58
- // Fall through to the instance default
59
- }
56
+ const databaseTf = readFileSafe(path.join(base, 'terraform', 'database.tf'));
57
+ if (typeof databaseTf === 'string' && databaseTf.includes('resource "aws_rds_cluster"')) return 'cluster';
60
58
  return 'instance';
61
59
  }
62
60
 
@@ -210,7 +208,7 @@ function scanBracketBlock(content, openIdx) {
210
208
  // reference, so it never matches; the shape filter drops resource names
211
209
  // (`${...}`, hyphens, paths). Sorted, deduplicated, [] when unreadable.
212
210
  //
213
- // Scoped to secret-receiving containers (BUG-93): ECS collides secrets
211
+ // Scoped to secret-receiving containers: ECS collides secrets
214
212
  // with environment per container definition, so sidecar `environment`
215
213
  // arrays (whose containers get no secrets) must not contribute names —
216
214
  // parsing them would falsely render same-named secrets undeployable.
@@ -13,6 +13,7 @@ export const ERROR_CODES = [
13
13
  'OIDC_PROVIDER_CONFLICT',
14
14
  'CLOUDFRONT_IN_PROGRESS',
15
15
  'BUCKET_NOT_EMPTY',
16
+ 'SECRET_PENDING_DELETION',
16
17
  ];
17
18
 
18
19
  // AWS AlreadyExists family: every create-path "reality has what state
@@ -34,6 +35,40 @@ export function countRecreateCollisions(stderr) {
34
35
  return stderr.match(new RegExp(RECREATE_COLLISION_RE.source, 'gi'))?.length ?? 0;
35
36
  }
36
37
 
38
+ const COLLISION_NAME_RE = /creating [A-Za-z][A-Za-z0-9 ]*?\(([^)]+)\)/;
39
+ const COLLISION_WITH_RE = /^\s*[│|]?\s*with ([A-Za-z0-9_."[\]-]+),/;
40
+ const COLLISION_ERROR_RE = /^\s*[╷╵│]?\s*Error:/;
41
+
42
+ // Guided-import pairs for recreate collisions: each AlreadyExists-style
43
+ // marker carries the provider name in parens, and the resource address
44
+ // follows on a `with <addr>,` context line. Markers without either are
45
+ // skipped — the caller falls back to the manual runbook. Capped so a
46
+ // pathological stderr cannot queue unbounded imports.
47
+ export function parseCollisionImports(stderr, limit = 20) {
48
+ if (typeof stderr !== 'string' || stderr === '') return [];
49
+ const lines = stderr.split('\n');
50
+ const pairs = [];
51
+ const seen = new Set();
52
+ for (let i = 0; i < lines.length && pairs.length < limit; i++) {
53
+ if (!RECREATE_COLLISION_RE.test(lines[i])) continue;
54
+ const nameMatch = COLLISION_NAME_RE.exec(lines[i]);
55
+ if (!nameMatch) continue;
56
+ for (let j = i + 1; j < Math.min(i + 9, lines.length); j++) {
57
+ if (COLLISION_ERROR_RE.test(lines[j])) break;
58
+ const withMatch = COLLISION_WITH_RE.exec(lines[j]);
59
+ if (withMatch) {
60
+ const address = withMatch[1].replace(/"/g, '');
61
+ if (!seen.has(address)) {
62
+ seen.add(address);
63
+ pairs.push({ address, id: nameMatch[1] });
64
+ }
65
+ break;
66
+ }
67
+ }
68
+ }
69
+ return pairs;
70
+ }
71
+
37
72
  // Pure classifier over stderr text. Returns `{ code, lockId }` or null.
38
73
  export function classifyTerraformError(stderr, ctx = {}) {
39
74
  const text = typeof stderr === 'string' ? stderr : '';
@@ -49,6 +84,13 @@ export function classifyTerraformError(stderr, ctx = {}) {
49
84
  if (RECREATE_COLLISION_RE.test(text)) {
50
85
  return { code: 'RECREATE_COLLISION', lockId: null };
51
86
  }
87
+ // Re-apply inside the Secrets Manager recovery window: the committed
88
+ // suffix reuses the secret name while deletion is still pending.
89
+ // Disjoint from the collision family ("already scheduled for
90
+ // deletion" carries no AlreadyExists marker).
91
+ if (/scheduled for deletion/i.test(text)) {
92
+ return { code: 'SECRET_PENDING_DELETION', lockId: null };
93
+ }
52
94
  if (/NoSuchBucket/i.test(text) || /does not exist/i.test(text)) {
53
95
  return { code: 'STATE_BUCKET_MISSING', lockId: null };
54
96
  }
@@ -116,6 +158,11 @@ const RUNBOOKS = {
116
158
  headless: 'Re-run destroy — drained buckets usually read empty within a minute; if it persists, empty the bucket by hand in the AWS Console.',
117
159
  interactive: 'Re-run destroy — drained buckets usually read empty within a minute; if it persists, empty the bucket by hand in the AWS Console.',
118
160
  },
161
+ SECRET_PENDING_DELETION: {
162
+ message: 'A Secrets Manager secret is scheduled for deletion.',
163
+ headless: 'Restore it (aws secretsmanager restore-secret --secret-id <name>, then cd terraform && terraform import <address> <id>) or force-delete without recovery and re-apply + push — grada never force-deletes, the window protects against accidental loss.',
164
+ interactive: 'Restore it (aws secretsmanager restore-secret --secret-id <name>, then cd terraform && terraform import <address> <id>) or force-delete without recovery and re-apply + push — grada never force-deletes, the window protects against accidental loss.',
165
+ },
119
166
  };
120
167
 
121
168
  // Returns `{ message, hint }` for a named code, or null for unknown
@@ -218,7 +218,7 @@ export function runTerraformCommand(args, cwd, spin, loadingPrefix, options = {}
218
218
  if (timer && typeof timer.unref === 'function') timer.unref();
219
219
  }
220
220
 
221
- // BUG-213: pipe chunks split lines at arbitrary byte offsets, so
221
+ // Pipe chunks split lines at arbitrary byte offsets, so
222
222
  // each chunk's trailing fragment is carried over and only
223
223
  // newline-terminated lines are delivered. Splitting per chunk
224
224
  // injects newlines into giant single-line JSON (show -json),
@@ -38,7 +38,7 @@ This infrastructure provisions a highly available Application Load Balancer (ALB
38
38
  ```
39
39
 
40
40
  3. **Automated CI/CD:**
41
- Push this repository to GitHub. Your deployment pipeline uses the official [Grada GitHub Action](https://github.com/marketplace/actions/deploy-stack-aws-fargate-terraform-deploy). Every push to `{{DEPLOY_BRANCH}}` will automatically run your infrastructure changes, build your container, and deploy your application.
41
+ Push this repository to GitHub. Your deployment pipeline uses the official [Grada GitHub Action](https://github.com/marketplace/actions/deploy-stack-aws-fargate-terraform-deploy). Every push to `{{DEPLOY_BRANCH}}` will automatically build your container, run your infrastructure changes, and deploy your application.
42
42
 
43
43
  ### 📟 Day-2 Operations
44
44
  Once live, manage the stack without opening the AWS console:
@@ -63,7 +63,7 @@ Run the automated teardown command from the root of your project:
63
63
  ```bash
64
64
  npx grada-run destroy
65
65
  ```
66
- *Type `yes` when prompted. This will execute a safe Terraform teardown of your Load Balancer, ECS cluster, and networking components. You will then be asked whether to also empty and delete your remote S3 state bucket (kept by default, so you can re-provision later with `npx grada-run apply`).*
66
+ *Confirm when prompted. This will execute a safe Terraform teardown of your Load Balancer, ECS cluster, and networking components. You will then be asked whether to also empty and delete your remote S3 state bucket (kept by default, so you can re-provision later with `npx grada-run apply`).*
67
67
 
68
68
  ## ⚠️ Critical Application Prerequisites
69
69
 
@@ -64,7 +64,7 @@ jobs:
64
64
  aws-region: ${{ env.AWS_REGION }}
65
65
 
66
66
  # Deploy never skips: a failed assume fails the run with the
67
- # bootstrap pointer (BUG-138).
67
+ # bootstrap pointer.
68
68
  - name: Interpret credential failure
69
69
  if: steps.aws-creds.outcome == 'failure'
70
70
  run: |
@@ -179,7 +179,7 @@ jobs:
179
179
 
180
180
  # A cancelled apply/destroy can strand the S3 state lockfile: point
181
181
  # at recovery instead of leaving the next run to fail obscurely
182
- # (BUG-194). Generic by necessity — the lock ID only exists in the
182
+ #. Generic by necessity — the lock ID only exists in the
183
183
  # follow-up run's own error.
184
184
  - name: Cancellation recovery note
185
185
  if: cancelled()
@@ -64,7 +64,7 @@ jobs:
64
64
  aws-region: ${{ env.AWS_REGION }}
65
65
 
66
66
  # Deploy never skips: a failed assume fails the run with the
67
- # bootstrap pointer (BUG-201).
67
+ # bootstrap pointer.
68
68
  - name: Interpret credential failure
69
69
  if: steps.aws-creds.outcome == 'failure'
70
70
  run: |
@@ -68,7 +68,7 @@ jobs:
68
68
  aws-region: ${{ env.AWS_REGION }}
69
69
 
70
70
  # Deploy never skips: a failed assume fails the run with the
71
- # bootstrap pointer (BUG-138).
71
+ # bootstrap pointer.
72
72
  - name: Interpret credential failure
73
73
  if: steps.aws-creds.outcome == 'failure'
74
74
  run: |
@@ -272,7 +272,7 @@ jobs:
272
272
 
273
273
  # A cancelled apply/destroy can strand the S3 state lockfile: point
274
274
  # at recovery instead of leaving the next run to fail obscurely
275
- # (BUG-194). Generic by necessity — the lock ID only exists in the
275
+ #. Generic by necessity — the lock ID only exists in the
276
276
  # follow-up run's own error.
277
277
  - name: Cancellation recovery note
278
278
  if: cancelled()
@@ -34,7 +34,7 @@ jobs:
34
34
  # STS denies a missing role and a trust mismatch with the same
35
35
  # message, so the API won't support distinguishing them: every
36
36
  # assume failure skips loud (green) with both cases + pointers
37
- # named (BUG-199).
37
+ # named.
38
38
  - name: Interpret credential failure
39
39
  if: steps.aws-creds.outcome == 'failure'
40
40
  run: |
@@ -3,7 +3,7 @@ name: Terraform Plan on PR
3
3
  on:
4
4
  # pull_request_target (not pull_request): this file comes from the base
5
5
  # branch, so a fork PR cannot delete the same-repo guard below to reach
6
- # the privileged CI roles (BUG-140). The PR head is checked out explicitly by
6
+ # the privileged CI roles. The PR head is checked out explicitly by
7
7
  # SHA in the guarded step instead.
8
8
  pull_request_target:
9
9
  types: [opened, synchronize, reopened]
@@ -53,7 +53,7 @@ jobs:
53
53
  aws-region: ${{ env.AWS_REGION }}
54
54
 
55
55
  # Plan-on-PR is a merge signal: a failed assume fails the run with
56
- # the bootstrap pointer (deploy shape, BUG-138) — never green-silent.
56
+ # the bootstrap pointer (deploy shape) — never green-silent.
57
57
  - name: Interpret credential failure
58
58
  if: steps.aws-creds.outcome == 'failure'
59
59
  run: |
@@ -3,7 +3,7 @@ name: Ephemeral PR Preview
3
3
  on:
4
4
  # pull_request_target (not pull_request): this file comes from the base
5
5
  # branch, so a fork PR cannot delete the same-repo guard below to reach
6
- # the privileged CI roles (BUG-140). The PR head is checked out explicitly by
6
+ # the privileged CI roles. The PR head is checked out explicitly by
7
7
  # SHA in the guarded step instead.
8
8
  pull_request_target:
9
9
  types: [opened, synchronize, reopened]
@@ -58,7 +58,7 @@ jobs:
58
58
  # STS denies a missing role and a trust mismatch with the same
59
59
  # message, so the API won't support distinguishing them: every
60
60
  # assume failure skips loud (green) with both cases + pointers
61
- # named (BUG-199).
61
+ # named.
62
62
  - name: Interpret credential failure
63
63
  if: steps.aws-creds.outcome == 'failure'
64
64
  run: |
@@ -137,7 +137,7 @@ jobs:
137
137
 
138
138
  # One sticky comment per PR (updated in place), never a new
139
139
  # comment per push — and a failed run overwrites the green URL
140
- # instead of leaving it standing as truth (BUG-190).
140
+ # instead of leaving it standing as truth.
141
141
  - name: Comment PR
142
142
  if: steps.aws-creds.outcome == 'success'
143
143
  uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7
@@ -199,7 +199,7 @@ jobs:
199
199
 
200
200
  # A cancelled apply can strand the S3 state lockfile: point at
201
201
  # recovery instead of leaving the next run to fail obscurely
202
- # (BUG-194). Generic by necessity — the lock ID only exists in the
202
+ #. Generic by necessity — the lock ID only exists in the
203
203
  # follow-up run's own error.
204
204
  - name: Cancellation recovery note
205
205
  if: cancelled()
@@ -3,7 +3,7 @@ name: Ephemeral PR Preview
3
3
  on:
4
4
  # pull_request_target (not pull_request): this file comes from the base
5
5
  # branch, so a fork PR cannot delete the same-repo guard below to reach
6
- # the privileged CI roles (BUG-140). The PR head is checked out explicitly by
6
+ # the privileged CI roles. The PR head is checked out explicitly by
7
7
  # SHA in the guarded step instead.
8
8
  pull_request_target:
9
9
  types: [opened, synchronize, reopened]
@@ -58,7 +58,7 @@ jobs:
58
58
  # STS denies a missing role and a trust mismatch with the same
59
59
  # message, so the API won't support distinguishing them: every
60
60
  # assume failure skips loud (green) with both cases + pointers
61
- # named (BUG-199).
61
+ # named.
62
62
  - name: Interpret credential failure
63
63
  if: steps.aws-creds.outcome == 'failure'
64
64
  run: |
@@ -119,7 +119,7 @@ jobs:
119
119
 
120
120
  # One sticky comment per PR (updated in place), never a new
121
121
  # comment per push — and a failed run overwrites the green URL
122
- # instead of leaving it standing as truth (BUG-190).
122
+ # instead of leaving it standing as truth.
123
123
  - name: Comment PR
124
124
  if: steps.aws-creds.outcome == 'success'
125
125
  uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7
@@ -183,7 +183,7 @@ jobs:
183
183
 
184
184
  # A cancelled apply can strand the S3 state lockfile: point at
185
185
  # recovery instead of leaving the next run to fail obscurely
186
- # (BUG-194). Generic by necessity — the lock ID only exists in the
186
+ #. Generic by necessity — the lock ID only exists in the
187
187
  # follow-up run's own error.
188
188
  - name: Cancellation recovery note
189
189
  if: cancelled()
@@ -3,7 +3,7 @@ name: Destroy PR Preview
3
3
  on:
4
4
  # pull_request_target (not pull_request): this file comes from the base
5
5
  # branch, so a fork PR cannot smuggle privileged steps into its own
6
- # teardown run (BUG-140). The PR head is checked out explicitly by SHA
6
+ # teardown run. The PR head is checked out explicitly by SHA
7
7
  # in the guarded step instead.
8
8
  pull_request_target:
9
9
  types: [closed]
@@ -52,7 +52,7 @@ jobs:
52
52
  # STS denies a missing role and a trust mismatch with the same
53
53
  # message, so the API won't support distinguishing them: every
54
54
  # assume failure skips loud (green) with both cases + pointers
55
- # named (BUG-199).
55
+ # named.
56
56
  - name: Interpret credential failure
57
57
  if: steps.aws-creds.outcome == 'failure'
58
58
  run: |
@@ -109,7 +109,7 @@ jobs:
109
109
 
110
110
  # A cancelled destroy can strand the S3 state lockfile: point at
111
111
  # recovery instead of leaving the next run to fail obscurely
112
- # (BUG-194). Generic by necessity — the lock ID only exists in the
112
+ #. Generic by necessity — the lock ID only exists in the
113
113
  # follow-up run's own error.
114
114
  - name: Cancellation recovery note
115
115
  if: cancelled()
@@ -7,7 +7,7 @@
7
7
  # chosen model in the AWS Bedrock console first.
8
8
 
9
9
  # --- Least-Privilege IAM Policy for the ECS Task Role ---
10
- # Scoped to the chosen model in the deploy region (BUG-102): the
10
+ # Scoped to the chosen model in the deploy region: the
11
11
  # foundation-model ARN names the model exactly, and the
12
12
  # inference-profile line stays (profile-style model IDs invoke through
13
13
  # profiles) but pinned to the region.
@@ -10,7 +10,7 @@ terraform {
10
10
  source = "hashicorp/tls"
11
11
  version = "~> 4.0"
12
12
  }
13
- # Declared unconditionally (BUG-137): the conditional injection left
13
+ # Declared unconditionally: the conditional injection left
14
14
  # pre-existing trees without the pin when the DB arrived via
15
15
  # `add database`. Unused on DB-less trees; init installs it anyway.
16
16
  random = {
@@ -2,7 +2,7 @@
2
2
  # is wrong for an app server — one slot per path gets shared by HTML docs,
3
3
  # API/RSC variants, redirects, and errors, so a cacheable variant poisons
4
4
  # every other viewer of that path. Each traffic class below gets its own
5
- # key instead (BUG-82).
5
+ # key instead.
6
6
  data "aws_cloudfront_cache_policy" "disabled" {
7
7
  name = "Managed-CachingDisabled"
8
8
  }
@@ -63,7 +63,7 @@ data "aws_cloudfront_origin_request_policy" "all_viewer" {
63
63
  }
64
64
 
65
65
  # Managed security headers (HSTS, frame/clickjacking guards, content-type
66
- # sniffing) on every behavior (BUG-92).
66
+ # sniffing) on every behavior.
67
67
  data "aws_cloudfront_response_headers_policy" "security" {
68
68
  name = "Managed-SecurityHeadersPolicy"
69
69
  }
@@ -2,7 +2,7 @@
2
2
  # is wrong for an app server — one slot per path gets shared by HTML docs,
3
3
  # API/RSC variants, redirects, and errors, so a cacheable variant poisons
4
4
  # every other viewer of that path. Each traffic class below gets its own
5
- # key instead (BUG-82).
5
+ # key instead.
6
6
  data "aws_cloudfront_cache_policy" "disabled" {
7
7
  name = "Managed-CachingDisabled"
8
8
  }
@@ -63,7 +63,7 @@ data "aws_cloudfront_origin_request_policy" "all_viewer" {
63
63
  }
64
64
 
65
65
  # Managed security headers (HSTS, frame/clickjacking guards, content-type
66
- # sniffing) on every behavior (BUG-92).
66
+ # sniffing) on every behavior.
67
67
  data "aws_cloudfront_response_headers_policy" "security" {
68
68
  name = "Managed-SecurityHeadersPolicy"
69
69
  }
@@ -81,7 +81,7 @@ resource "aws_cloudfront_distribution" "cdn" {
81
81
  domain_name = aws_lb.main.dns_name
82
82
  origin_id = "ALBOrigin"
83
83
 
84
- # Origin secret (BUG-91): proves to the ALB that the request came
84
+ # Origin secret: proves to the ALB that the request came
85
85
  # through THIS distribution — any other tenant's distro, or a direct
86
86
  # ALB hit, lacks the header and gets a 403 from the listener rule.
87
87
  custom_header {
@@ -41,7 +41,7 @@ resource "aws_rds_cluster" "postgres" {
41
41
  storage_encrypted = true
42
42
 
43
43
  # Match the instance engines: 7-day retention with explicit off-peak
44
- # UTC windows instead of AWS-assigned ones (BUG-203).
44
+ # UTC windows instead of AWS-assigned ones.
45
45
  backup_retention_period = 7
46
46
  preferred_backup_window = "03:00-04:00"
47
47
  preferred_maintenance_window = "sun:04:00-sun:05:00"
@@ -30,7 +30,7 @@ locals {
30
30
  # Safely read the keys generated by the CLI, default to empty list if file doesn't exist.
31
31
  # distinct() collapses hand-duplicated entries (duplicates render the
32
32
  # same RegisterTaskDefinition 400 as a name collision) while preserving
33
- # file order, so upgrading trees get no task-definition churn (BUG-81).
33
+ # file order, so upgrading trees get no task-definition churn.
34
34
  secret_keys = fileexists("${path.module}/secret_keys.json") ? distinct(jsondecode(file("${path.module}/secret_keys.json"))) : []
35
35
 
36
36
  # Exact container env + static-secret names (union over app and worker
@@ -230,7 +230,7 @@ resource "aws_lb_target_group" "app" {
230
230
  }
231
231
  }
232
232
 
233
- # Origin secret (BUG-91): only requests bearing the header CloudFront
233
+ # Origin secret: only requests bearing the header CloudFront
234
234
  # injects may reach the app. The CloudFront edge-IP security group alone
235
235
  # cannot prove WHICH distribution sent a request — any tenant's distro
236
236
  # could point at this ALB — so the listener forwards solely on a header
@@ -348,7 +348,7 @@ output "ecs_task_role_arn" {
348
348
  # State-only alarm: visible in the console, notifies nobody. There is no
349
349
  # notification destination at scaffold time; `grada alerts` provisions
350
350
  # separate alarms wired to SNS, and this one stays as a console signal so
351
- # quiet trees still show red (BUG-101).
351
+ # quiet trees still show red.
352
352
  resource "aws_cloudwatch_metric_alarm" "alb_5xx_errors" {
353
353
  alarm_name = "${local.app_name}-high-5xx-errors"
354
354
  comparison_operator = "GreaterThanThreshold"
@@ -80,7 +80,7 @@ locals {
80
80
  guardrail_snapshot_deletion_resources = [
81
81
  "arn:aws:rds:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:snapshot:${local.prod_prefix}-db-*",
82
82
  "arn:aws:rds:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:cluster-snapshot:${local.prod_prefix}-db-cluster-*",
83
- # BUG-205: legacy bare pre-deploy-<sha> ids carry no db prefix, so
83
+ # Legacy bare pre-deploy-<sha> ids carry no db prefix, so
84
84
  # they match no prod pattern above — deny them outright. gc never
85
85
  # runs under preview credentials, so nothing legitimate needs them.
86
86
  "arn:aws:rds:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:snapshot:pre-deploy-*",
@@ -255,7 +255,7 @@ resource "aws_iam_role_policy" "preview_guardrails" {
255
255
  Resource = "*"
256
256
  },
257
257
  {
258
- # BUG-207: the preview role carries IAMFullAccess, so without this
258
+ # The preview role carries IAMFullAccess, so without this
259
259
  # statement it can delete its own guardrails, delete the deploy
260
260
  # role, or widen trust in one call. Scoped to the CI role ARNs
261
261
  # (not *): preview stacks legitimately manage their own
@@ -325,7 +325,7 @@ resource "aws_iam_role_policy" "preview_guardrails" {
325
325
  Resource = local.guardrail_table_deletion_resources
326
326
  },
327
327
  {
328
- # BUG-208: manual snapshots (grada names them
328
+ # Manual snapshots (grada names them
329
329
  # <db-identifier>-manual-<stamp> and
330
330
  # <db-identifier>-pre-deploy-<sha>) are directly deletable;
331
331
  # automated snapshots can only go away via retention changes or
@@ -353,7 +353,7 @@ resource "aws_iam_role_policy" "preview_guardrails" {
353
353
  Resource = local.guardrail_log_deletion_resources
354
354
  },
355
355
  {
356
- # BUG-212: every role preview credentials create must carry the
356
+ # Every role preview credentials create must carry the
357
357
  # boundary — a missing key fails StringNotEquals, so unbounded
358
358
  # creation is denied and born-capped roles cannot escalate.
359
359
  Sid = "DenyRoleWithoutBoundary"
@@ -387,7 +387,7 @@ resource "aws_iam_role_policy" "preview_guardrails" {
387
387
  ]
388
388
  },
389
389
  {
390
- # BUG-215: close by target — deny the execution APIs on prod
390
+ # Close by target — deny the execution APIs on prod
391
391
  # ARNs while pr-* stays allowed. No describes: plan.yml
392
392
  # refreshes prod state with preview credentials, so describing
393
393
  # prod is legitimate traffic.
@@ -395,6 +395,15 @@ resource "aws_iam_role_policy" "preview_guardrails" {
395
395
  Effect = "Deny"
396
396
  Action = ["ecs:RunTask", "ecs:StopTask", "ecs:ExecuteCommand", "ecs:CreateService"]
397
397
  Resource = local.guardrail_task_execution_resources
398
+ # The bounded scheduler role must RunTask its task
399
+ # definition at trigger time. A no-op on this side (the preview
400
+ # role is never the scheduler, assumable only by the scheduler
401
+ # service) but kept so the twins stay identical.
402
+ Condition = {
403
+ StringNotEquals = {
404
+ "aws:PrincipalArn" = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/${local.prod_prefix}-cron-scheduler-role"
405
+ }
406
+ }
398
407
  },
399
408
  {
400
409
  # RegisterTaskDefinition is likely resource-*-only (void half);
@@ -425,7 +434,7 @@ resource "aws_iam_role_policy" "preview_guardrails" {
425
434
  })
426
435
  }
427
436
 
428
- # BUG-212: permissions boundary capping every role preview credentials
437
+ # Permissions boundary capping every role preview credentials
429
438
  # can create. The guardrail above denies CreateRole unless the request
430
439
  # carries this boundary, so a backdoor role is born capped: its
431
440
  # effective permissions are its own policies intersected with this one.
@@ -447,7 +456,7 @@ resource "aws_iam_policy" "preview_boundary" {
447
456
  Resource = "*"
448
457
  },
449
458
  {
450
- # BUG-214: capped roles must pass their task roles to ECS (the
459
+ # Capped roles must pass their task roles to ECS (the
451
460
  # scheduler role passes at invocation time), so PassRole is
452
461
  # carved out here and re-gated on service + target below.
453
462
  # Explicit Action list on purpose: a Deny with NotAction would
@@ -550,6 +559,14 @@ resource "aws_iam_policy" "preview_boundary" {
550
559
  Effect = "Deny"
551
560
  Action = ["ecs:RunTask", "ecs:StopTask", "ecs:ExecuteCommand", "ecs:CreateService"]
552
561
  Resource = local.guardrail_task_execution_resources
562
+ # The bounded scheduler role must RunTask its task
563
+ # definition at trigger time; every other capped caller stays
564
+ # denied. Mirrors the twin's condition above.
565
+ Condition = {
566
+ StringNotEquals = {
567
+ "aws:PrincipalArn" = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/${local.prod_prefix}-cron-scheduler-role"
568
+ }
569
+ }
553
570
  },
554
571
  {
555
572
  Sid = "BoundaryDenyTaskDefinitionRegistration"
@@ -557,12 +574,10 @@ resource "aws_iam_policy" "preview_boundary" {
557
574
  Action = ["ecs:RegisterTaskDefinition", "ecs:DeregisterTaskDefinition"]
558
575
  Resource = local.guardrail_task_definition_resources
559
576
  },
560
- {
561
- Sid = "BoundaryDenyPassRole"
562
- Effect = "Deny"
563
- Action = ["iam:PassRole"]
564
- Resource = local.guardrail_app_role_resources
565
- },
577
+ # No flat BoundaryDenyPassRole twin: it denied the scheduler's
578
+ # own PassRole unconditionally, defeating the OffScheduler
579
+ # carve-out (any Deny wins). The OffService/OffTarget/
580
+ # OffScheduler trio below gates PassRole alone.
566
581
  {
567
582
  Sid = "BoundaryDenyAppRoleMutation"
568
583
  Effect = "Deny"
@@ -570,7 +585,7 @@ resource "aws_iam_policy" "preview_boundary" {
570
585
  Resource = local.guardrail_app_role_resources
571
586
  },
572
587
  {
573
- # BUG-214: carved PassRole may only pass to the ECS tasks
588
+ # Carved PassRole may only pass to the ECS tasks
574
589
  # service (mirrors the scheduler policy's own condition).
575
590
  Sid = "BoundaryDenyPassRoleOffService"
576
591
  Effect = "Deny"
@@ -5,7 +5,7 @@ resource "aws_secretsmanager_secret" "app_secrets" {
5
5
  count = terraform.workspace == "default" ? 1 : 0
6
6
  name = "{{PROJECT_NAME}}{{RESOURCE_SUFFIX}}-secrets"
7
7
  description = "Environment variables for {{PROJECT_NAME}}"
8
- # 30-day recovery (BUG-163): an instant-delete vault turns any destroy
8
+ # 30-day recovery: an instant-delete vault turns any destroy
9
9
  # bug into unrecoverable secret loss. Lower per-tree if you must.
10
10
  recovery_window_in_days = 30
11
11
  }