@grada-run/grada 0.50.0 → 0.50.2

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.
@@ -49,18 +49,16 @@ locals {
49
49
  # ${prod_prefix}-* pattern matches prod only. Anchoring also keeps
50
50
  # the boundary under the 6144-char managed-policy quota that broke
51
51
  # tier1 E2E at a 24-char prefix — prefer one anchored wildcard over
52
- # several exact ARNs when adding entries. Headroom is now single
53
- # digits at 32-char prefixes: the next IAM addition must economize
54
- # (shorter Sids, fewer verbs, or slimmer patterns) before extending.
52
+ # several exact ARNs when adding entries. Headroom is 64 chars
53
+ # at 32-char prefixes (286 at 24): the PITR/backup verbs plus
54
+ # their backup-ARN entry spent the suffix-loosening payback, with
55
+ # the verb-collapse battery covering the rest — the next addition
56
+ # re-runs the quota probe before extending.
55
57
  guardrail_compute_abuse_resources = ["*"]
56
58
  guardrail_snapshot_sharing_resources = ["*"]
57
59
  guardrail_state_destruction_resources = [
58
60
  "arn:aws:s3:::{{STATE_BUCKET}}*",
59
61
  ]
60
- guardrail_ecs_shutdown_resources = [
61
- "arn:aws:ecs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:cluster/${local.prod_prefix}-cluster",
62
- "arn:aws:ecs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:service/${local.prod_prefix}-cluster/*",
63
- ]
64
62
  guardrail_image_deletion_resources = [
65
63
  "arn:aws:ecr:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:repository/${local.prod_prefix}-repo",
66
64
  ]
@@ -76,12 +74,18 @@ locals {
76
74
  guardrail_aurora_destruction_resources = [
77
75
  "arn:aws:rds:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:cluster:${local.prod_prefix}-db-cluster",
78
76
  ]
79
- guardrail_table_deletion_resources = [
77
+ guardrail_table_data_resources = [
80
78
  "arn:aws:dynamodb:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:table/${local.prod_prefix}-table",
79
+ # Backup ARNs authorize backup create/delete/restore-from; the table
80
+ # entry alone can't match them.
81
+ "arn:aws:dynamodb:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:table/${local.prod_prefix}-table/backup/*",
81
82
  ]
82
- guardrail_snapshot_deletion_resources = [
83
- "arn:aws:rds:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:snapshot:${local.prod_prefix}-db-*",
84
- "arn:aws:rds:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:cluster-snapshot:${local.prod_prefix}-db-cluster-*",
83
+ guardrail_snapshot_data_resources = [
84
+ # Middle-wildcard: automated snapshots carry an `rds:` name prefix
85
+ # (AWS CopyDBSnapshot API reference), so prefix anchoring would
86
+ # miss them. The infix still can't match `-pr-<n>-` names.
87
+ "arn:aws:rds:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:snapshot:*${local.prod_prefix}-db*",
88
+ "arn:aws:rds:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:cluster-snapshot:*${local.prod_prefix}-db-cluster*",
85
89
  # Legacy bare pre-deploy-<sha> ids carry no db prefix, so
86
90
  # they match no prod pattern above — deny them outright. gc never
87
91
  # runs under preview credentials, so nothing legitimate needs them.
@@ -113,20 +117,29 @@ locals {
113
117
  "arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/${local.prod_prefix}-*-role",
114
118
  ]
115
119
  # Data-plane confinement: prod data ARNs shared by the
116
- # DenyProdAppData twins. One statement is exact here, not
117
- # lazy — every denied action only ever matches its own service's
118
- # ARNs in a real call, so the cross-product cannot over-match.
120
+ # DenyProdAppData twins. Queue entries are suffix-anchored on
121
+ # purpose: hashed names keep their tails, so prefix anchoring
122
+ # would miss them. Preview queues match too — safe, because the
123
+ # preview role never sends/receives (pinned by test) and tasks
124
+ # stay carved out. Every denied action only ever matches its own
125
+ # service's ARNs in a real call, so the cross-product cannot
126
+ # over-match.
119
127
  guardrail_app_data_resources = [
120
128
  "arn:aws:secretsmanager:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:secret:${local.prod_prefix}-secrets-*",
121
- "arn:aws:sqs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:${local.prod_prefix}-*",
129
+ "arn:aws:sqs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:*-queue",
130
+ "arn:aws:sqs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:*-dlq",
122
131
  ]
123
132
  # Lifecycle twin of the above, deliberately carve-free: no bounded
124
- # role ever stops or reboots a database (sleep/wake and db commands
125
- # run on user credentials), and one fewer condition keeps the pair
126
- # under the 6144-char boundary quota.
133
+ # role ever stops, starts, reboots, or restores a database
134
+ # (sleep/wake and db commands run on user credentials), and one
135
+ # fewer condition keeps the pair under the 6144-char boundary
136
+ # quota. Suffix-anchored like the queues (hashed identifiers keep
137
+ # their tails); preview DBs match too, safe because no preview
138
+ # workflow calls these verbs (pinned by test) and Terraform's
139
+ # Modify calls live in the anchored destruction statements.
127
140
  guardrail_db_lifecycle_resources = [
128
- "arn:aws:rds:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:db:${local.prod_prefix}-db*",
129
- "arn:aws:rds:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:cluster:${local.prod_prefix}-db-cluster",
141
+ "arn:aws:rds:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:db:*-db*",
142
+ "arn:aws:rds:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:cluster:*-db-cluster",
130
143
  ]
131
144
  # Carve-out principal for the app-data twins: the exact prod task
132
145
  # role ARN (workers send/receive prod queues). Singular on purpose:
@@ -141,7 +154,7 @@ locals {
141
154
  # task name, and the carve-out must track the rendered name exactly
142
155
  # (a stale plain ARN would silently uncarve workers).
143
156
  guardrail_task_role_principals = [
144
- length("${local.prod_prefix}-task-role") > 64 ? "arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/${substr(local.prod_prefix, 0, 64 - 1 - 5 - 10)}-${substr(md5(local.prod_prefix), 0, 5)}-task-role" : "arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/${local.prod_prefix}-task-role",
157
+ length("${local.prod_prefix}-task-role") > 64 ? "arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/${trimsuffix(substr(local.prod_prefix, 0, 64 - 1 - 5 - 10), "-")}-${substr(md5(local.prod_prefix), 0, 5)}-task-role" : "arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/${local.prod_prefix}-task-role",
145
158
  ]
146
159
  }
147
160
 
@@ -306,7 +319,7 @@ resource "aws_iam_role_policy" "preview_guardrails" {
306
319
  {
307
320
  Sid = "DenySnapshotSharing"
308
321
  Effect = "Deny"
309
- Action = ["rds:ModifyDBSnapshotAttribute"]
322
+ Action = ["rds:Modify*SnapshotAttribute"]
310
323
  Resource = local.guardrail_snapshot_sharing_resources
311
324
  },
312
325
  {
@@ -315,12 +328,6 @@ resource "aws_iam_role_policy" "preview_guardrails" {
315
328
  Action = ["s3:DeleteBucket", "s3:DeleteObjectVersion"]
316
329
  Resource = local.guardrail_state_destruction_resources
317
330
  },
318
- {
319
- Sid = "DenyProdECSShutdown"
320
- Effect = "Deny"
321
- Action = ["ecs:UpdateService", "ecs:DeleteService", "ecs:DeleteCluster"]
322
- Resource = local.guardrail_ecs_shutdown_resources
323
- },
324
331
  {
325
332
  Sid = "DenyProdImageDeletion"
326
333
  Effect = "Deny"
@@ -330,7 +337,7 @@ resource "aws_iam_role_policy" "preview_guardrails" {
330
337
  {
331
338
  Sid = "DenyProdLambdaRewrite"
332
339
  Effect = "Deny"
333
- Action = ["lambda:UpdateFunctionCode", "lambda:DeleteFunction"]
340
+ Action = ["lambda:UpdateFunctionCode", "lambda:Delete*"]
334
341
  Resource = local.guardrail_lambda_rewrite_resources
335
342
  },
336
343
  {
@@ -352,10 +359,16 @@ resource "aws_iam_role_policy" "preview_guardrails" {
352
359
  Resource = local.guardrail_aurora_destruction_resources
353
360
  },
354
361
  {
355
- Sid = "DenyProdTableDeletion"
362
+ # Item data joins the table deny: preview apps use preview
363
+ # tables, so no bounded role ever reads prod items — and the
364
+ # wildcard set below leaves Describe*/List* (plan refresh) and
365
+ # control verbs alone. Streams stay out of reach of this
366
+ # pattern (stream ARNs carry a /stream suffix): accepted, the
367
+ # iterator dance is narrow and unactionable without table reads.
368
+ Sid = "DenyProdTableData"
356
369
  Effect = "Deny"
357
- Action = ["dynamodb:DeleteTable"]
358
- Resource = local.guardrail_table_deletion_resources
370
+ Action = ["dynamodb:Delete*", "dynamodb:Batch*", "dynamodb:*Item", "dynamodb:Query", "dynamodb:Scan", "dynamodb:Execute*", "dynamodb:Transact*", "dynamodb:Export*", "dynamodb:Restore*", "dynamodb:CreateBackup", "dynamodb:DeleteBackup", "dynamodb:UpdateTable"]
371
+ Resource = local.guardrail_table_data_resources
359
372
  },
360
373
  {
361
374
  # Manual snapshots (grada names them
@@ -363,10 +376,14 @@ resource "aws_iam_role_policy" "preview_guardrails" {
363
376
  # <db-identifier>-pre-deploy-<sha>) are directly deletable;
364
377
  # automated snapshots can only go away via retention changes or
365
378
  # instance deletion, both already denied above.
366
- Sid = "DenyProdSnapshotDeletion"
379
+ # Copies, snapshot-based restores, and S3 exports authorize
380
+ # the source snapshot (service authorization reference), so
381
+ # denying them here closes the copy-then-read and
382
+ # export-to-attacker-bucket paths. Deletion keeps its verbs.
383
+ Sid = "DenyProdSnapshotData"
367
384
  Effect = "Deny"
368
- Action = ["rds:DeleteDBSnapshot", "rds:DeleteDBClusterSnapshot"]
369
- Resource = local.guardrail_snapshot_deletion_resources
385
+ Action = ["rds:DeleteDB*Snapshot", "rds:Copy*", "rds:Restore*", "rds:StartExportTask"]
386
+ Resource = local.guardrail_snapshot_data_resources
370
387
  },
371
388
  {
372
389
  # The vault ARN carries a random suffix and static trees have no
@@ -424,9 +441,15 @@ resource "aws_iam_role_policy" "preview_guardrails" {
424
441
  # ARNs while pr-* stays allowed. No describes: plan.yml
425
442
  # refreshes prod state with preview credentials, so describing
426
443
  # prod is legitimate traffic.
444
+ # Service shutdown verbs live here (not in a separate
445
+ # statement): they share the cluster+service resources below,
446
+ # and a twin pair of their own would re-inline ~280 chars of
447
+ # ARNs against the boundary quota. The scheduler carve-out is
448
+ # a no-op for them — the scheduler role can never call
449
+ # Update/DeleteService or DeleteCluster.
427
450
  Sid = "DenyProdTaskExecution"
428
451
  Effect = "Deny"
429
- Action = ["ecs:RunTask", "ecs:StopTask", "ecs:ExecuteCommand", "ecs:CreateService"]
452
+ Action = ["ecs:RunTask", "ecs:StopTask", "ecs:ExecuteCommand", "ecs:CreateService", "ecs:UpdateService", "ecs:Delete*"]
430
453
  Resource = local.guardrail_task_execution_resources
431
454
  # The bounded scheduler role must RunTask its task
432
455
  # definition at trigger time. A no-op on this side (the preview
@@ -441,7 +464,7 @@ resource "aws_iam_role_policy" "preview_guardrails" {
441
464
  {
442
465
  # RegisterTaskDefinition is likely resource-*-only (void half);
443
466
  # the cluster-scoped RunTask deny above is the real choke.
444
- Sid = "DenyProdTaskDefinitionRegistration"
467
+ Sid = "DenyProdTaskDefRegistration"
445
468
  Effect = "Deny"
446
469
  Action = ["ecs:RegisterTaskDefinition", "ecs:DeregisterTaskDefinition"]
447
470
  Resource = local.guardrail_task_definition_resources
@@ -475,9 +498,14 @@ resource "aws_iam_role_policy" "preview_guardrails" {
475
498
  # is never a task role) so the twins stay identical.
476
499
  # Accepted residual: GetSecretValue + prod state reads (plan
477
500
  # refresh requires both; state additionally exposes adopted
478
- # live values), snapshot export/restore, Bedrock/SES spend
479
- # verbs, DynamoDB data verbs, and RDS Start — follow-ups, not
480
- # oversights.
501
+ # live values), Bedrock/SES spend verbs (denying would gut
502
+ # preview fidelity for AI/email apps — previews are full
503
+ # copies; same-repo guard + PR review are the controls), and
504
+ # DynamoDB stream reads (narrow iterator dance, unactionable
505
+ # without the table reads denied below). Snapshot copy/
506
+ # restore/export, point-in-time restore, DynamoDB item data,
507
+ # and RDS Start all landed as denies; DeleteMessage stays
508
+ # unreachable with Receive denied.
481
509
  Sid = "DenyProdAppData"
482
510
  Effect = "Deny"
483
511
  Action = [
@@ -492,12 +520,13 @@ resource "aws_iam_role_policy" "preview_guardrails" {
492
520
  }
493
521
  },
494
522
  {
495
- # ...nor stop or reboot prod databases. Deliberately
496
- # carve-free: no bounded role ever calls these (sleep/wake
497
- # and db commands run on user credentials).
523
+ # ...nor stop, start, reboot, or point-in-time-restore prod
524
+ # databases. Deliberately carve-free: no bounded role ever
525
+ # calls these (sleep/wake and db commands run on user
526
+ # credentials).
498
527
  Sid = "DenyProdDbLifecycle"
499
528
  Effect = "Deny"
500
- Action = ["rds:Stop*", "rds:Reboot*"]
529
+ Action = ["rds:Stop*", "rds:Reboot*", "rds:Start*", "rds:Restore*"]
501
530
  Resource = local.guardrail_db_lifecycle_resources
502
531
  },
503
532
  ]
@@ -537,7 +566,7 @@ resource "aws_iam_policy" "preview_boundary" {
537
566
  # weaken security instead of breaking prod tasks.
538
567
  Sid = "BoundaryDenyIAM"
539
568
  Effect = "Deny"
540
- Action = ["iam:CreateRole", "iam:DeleteRole", "iam:UpdateAssumeRolePolicy", "iam:PutRolePolicy", "iam:DeleteRolePolicy", "iam:AttachRolePolicy", "iam:DetachRolePolicy", "iam:PutRolePermissionsBoundary", "iam:DeleteRolePermissionsBoundary", "iam:CreatePolicy", "iam:DeletePolicy", "iam:CreatePolicyVersion", "iam:DeletePolicyVersion", "iam:CreateUser", "iam:DeleteUser", "iam:CreateAccessKey", "iam:DeleteAccessKey"]
569
+ Action = ["iam:CreateRole", "iam:DeleteRole", "iam:UpdateAssumeRolePolicy", "iam:PutRolePolicy", "iam:DeleteRolePolicy", "iam:AttachRolePolicy", "iam:DetachRolePolicy", "iam:*PermissionsBoundary", "iam:CreatePolicy", "iam:DeletePolicy", "iam:*PolicyVersion", "iam:CreateUser", "iam:DeleteUser", "iam:CreateAccessKey", "iam:DeleteAccessKey"]
541
570
  Resource = "*"
542
571
  },
543
572
  {
@@ -555,7 +584,7 @@ resource "aws_iam_policy" "preview_boundary" {
555
584
  {
556
585
  Sid = "BoundaryDenySnapshotSharing"
557
586
  Effect = "Deny"
558
- Action = ["rds:ModifyDBSnapshotAttribute"]
587
+ Action = ["rds:Modify*SnapshotAttribute"]
559
588
  Resource = local.guardrail_snapshot_sharing_resources
560
589
  },
561
590
  {
@@ -564,12 +593,6 @@ resource "aws_iam_policy" "preview_boundary" {
564
593
  Action = ["s3:DeleteBucket", "s3:DeleteObjectVersion"]
565
594
  Resource = local.guardrail_state_destruction_resources
566
595
  },
567
- {
568
- Sid = "BoundaryDenyECSShutdown"
569
- Effect = "Deny"
570
- Action = ["ecs:UpdateService", "ecs:DeleteService", "ecs:DeleteCluster"]
571
- Resource = local.guardrail_ecs_shutdown_resources
572
- },
573
596
  {
574
597
  Sid = "BoundaryDenyImageDeletion"
575
598
  Effect = "Deny"
@@ -579,7 +602,7 @@ resource "aws_iam_policy" "preview_boundary" {
579
602
  {
580
603
  Sid = "BoundaryDenyLambdaRewrite"
581
604
  Effect = "Deny"
582
- Action = ["lambda:UpdateFunctionCode", "lambda:DeleteFunction"]
605
+ Action = ["lambda:UpdateFunctionCode", "lambda:Delete*"]
583
606
  Resource = local.guardrail_lambda_rewrite_resources
584
607
  },
585
608
  {
@@ -601,16 +624,16 @@ resource "aws_iam_policy" "preview_boundary" {
601
624
  Resource = local.guardrail_aurora_destruction_resources
602
625
  },
603
626
  {
604
- Sid = "BoundaryDenyTableDeletion"
627
+ Sid = "BoundaryDenyTableData"
605
628
  Effect = "Deny"
606
- Action = ["dynamodb:DeleteTable"]
607
- Resource = local.guardrail_table_deletion_resources
629
+ Action = ["dynamodb:Delete*", "dynamodb:Batch*", "dynamodb:*Item", "dynamodb:Query", "dynamodb:Scan", "dynamodb:Execute*", "dynamodb:Transact*", "dynamodb:Export*", "dynamodb:Restore*", "dynamodb:CreateBackup", "dynamodb:DeleteBackup", "dynamodb:UpdateTable"]
630
+ Resource = local.guardrail_table_data_resources
608
631
  },
609
632
  {
610
- Sid = "BoundaryDenySnapshotDeletion"
633
+ Sid = "BoundaryDenySnapshotData"
611
634
  Effect = "Deny"
612
- Action = ["rds:DeleteDBSnapshot", "rds:DeleteDBClusterSnapshot"]
613
- Resource = local.guardrail_snapshot_deletion_resources
635
+ Action = ["rds:DeleteDB*Snapshot", "rds:Copy*", "rds:Restore*", "rds:StartExportTask"]
636
+ Resource = local.guardrail_snapshot_data_resources
614
637
  },
615
638
  {
616
639
  Sid = "BoundaryDenySecretsDeletion"
@@ -625,9 +648,11 @@ resource "aws_iam_policy" "preview_boundary" {
625
648
  Resource = local.guardrail_log_deletion_resources
626
649
  },
627
650
  {
651
+ # Shutdown verbs merged here; see the twin's comment (quota
652
+ # economy — a separate pair would re-inline the ARNs below).
628
653
  Sid = "BoundaryDenyTaskExecution"
629
654
  Effect = "Deny"
630
- Action = ["ecs:RunTask", "ecs:StopTask", "ecs:ExecuteCommand", "ecs:CreateService"]
655
+ Action = ["ecs:RunTask", "ecs:StopTask", "ecs:ExecuteCommand", "ecs:CreateService", "ecs:UpdateService", "ecs:Delete*"]
631
656
  Resource = local.guardrail_task_execution_resources
632
657
  # The bounded scheduler role must RunTask its task
633
658
  # definition at trigger time; every other capped caller stays
@@ -639,7 +664,7 @@ resource "aws_iam_policy" "preview_boundary" {
639
664
  }
640
665
  },
641
666
  {
642
- Sid = "BoundaryDenyTaskDefinitionRegistration"
667
+ Sid = "BoundaryDenyTaskDefRegistration"
643
668
  Effect = "Deny"
644
669
  Action = ["ecs:RegisterTaskDefinition", "ecs:DeregisterTaskDefinition"]
645
670
  Resource = local.guardrail_task_definition_resources
@@ -674,7 +699,7 @@ resource "aws_iam_policy" "preview_boundary" {
674
699
  {
675
700
  Sid = "BoundaryDenyDbLifecycle"
676
701
  Effect = "Deny"
677
- Action = ["rds:Stop*", "rds:Reboot*"]
702
+ Action = ["rds:Stop*", "rds:Reboot*", "rds:Start*", "rds:Restore*"]
678
703
  Resource = local.guardrail_db_lifecycle_resources
679
704
  },
680
705
  {