grada-run 0.49.1 → 0.49.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "grada-run",
3
- "version": "0.49.1",
3
+ "version": "0.49.2",
4
4
  "description": "Provision production-ready AWS infrastructure and CI/CD pipelines in seconds.",
5
5
  "engines": {
6
6
  "node": ">=18.0.0"
@@ -112,7 +112,7 @@ const RUNBOOKS = {
112
112
  interactive: 'Wait 5–15 minutes for the distribution to settle, then re-run the same command.',
113
113
  },
114
114
  BUCKET_NOT_EMPTY: {
115
- message: 'S3 buckets still report object versions after draining.',
115
+ message: 'Terraform destroy failed twice: an S3 bucket still holds object versions.',
116
116
  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
117
  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
118
  },
@@ -218,9 +218,13 @@ export function runTerraformCommand(args, cwd, spin, loadingPrefix, options = {}
218
218
  if (timer && typeof timer.unref === 'function') timer.unref();
219
219
  }
220
220
 
221
- child.stdout.on('data', (data) => {
222
- if (isDone) return;
223
- const lines = data.toString().split('\n').filter(line => line.trim() !== '');
221
+ // BUG-213: pipe chunks split lines at arbitrary byte offsets, so
222
+ // each chunk's trailing fragment is carried over and only
223
+ // newline-terminated lines are delivered. Splitting per chunk
224
+ // injects newlines into giant single-line JSON (show -json),
225
+ // which breaks parsing downstream.
226
+ let pendingFragment = '';
227
+ const handleLines = (lines) => {
224
228
  if (typeof onStdoutLine === 'function') {
225
229
  for (const line of lines) onStdoutLine(line);
226
230
  }
@@ -237,6 +241,21 @@ export function runTerraformCommand(args, cwd, spin, loadingPrefix, options = {}
237
241
  const latestLine = lines[lines.length - 1].trim();
238
242
  emit(`${loadingPrefix} - ${color.dim(truncateSpinnerText(latestLine, { fixedOverhead: lineOverhead }))}`);
239
243
  }
244
+ };
245
+ const flushFragment = () => {
246
+ if (pendingFragment.trim() === '') {
247
+ pendingFragment = '';
248
+ return;
249
+ }
250
+ const trailing = pendingFragment;
251
+ pendingFragment = '';
252
+ handleLines([trailing]);
253
+ };
254
+ child.stdout.on('data', (data) => {
255
+ if (isDone) return;
256
+ const parts = (pendingFragment + data.toString()).split('\n');
257
+ pendingFragment = parts.pop() ?? '';
258
+ handleLines(parts.filter(line => line.trim() !== ''));
240
259
  });
241
260
 
242
261
  child.stderr.on('data', (data) => {
@@ -247,6 +266,7 @@ export function runTerraformCommand(args, cwd, spin, loadingPrefix, options = {}
247
266
  if (isDone) return;
248
267
  isDone = true;
249
268
  cleanup();
269
+ flushFragment();
250
270
  if (code === 0) {
251
271
  settleMarker('completed', { exitCode: code });
252
272
  resolve();
@@ -34,9 +34,10 @@ WORKDIR /app
34
34
  RUN addgroup -g 1001 appgroup && \
35
35
  adduser -u 1001 -G appgroup -s /bin/sh -D appuser
36
36
 
37
- # Runtime libraries only (native wheels arrive inside the venv)
37
+ # Runtime libraries only (native wheels arrive inside the venv), plus a
38
+ # CA bundle: without it no verified TLS egress works (RDS, AWS APIs).
38
39
  RUN apk update && apk upgrade --no-cache && \
39
- apk add --no-cache libpq
40
+ apk add --no-cache libpq ca-certificates
40
41
 
41
42
  # Strip the base image's system pip (the venv already ships without one)
42
43
  RUN /usr/local/bin/python -m pip uninstall -y setuptools wheel pip && \
@@ -10,6 +10,10 @@ RUN CGO_ENABLED=0 GOOS=linux go build -o /main .
10
10
  FROM alpine:3.20@sha256:d9e853e87e55526f6b2917df91a2115c36dd7c696a35be12163d44e6e2a4b6bc
11
11
  WORKDIR /app
12
12
 
13
+ # Ship a CA bundle: without it the static binary cannot verify any TLS
14
+ # egress (RDS, AWS APIs, webhooks).
15
+ RUN apk add --no-cache ca-certificates
16
+
13
17
  # Create unprivileged user
14
18
  RUN addgroup -g 1001 -S appgroup && \
15
19
  adduser -S appuser -u 1001 -G appgroup
@@ -9,8 +9,10 @@ RUN npm run build
9
9
  # --- Stage 2: Production ---
10
10
  FROM node:22-alpine@sha256:fe4f6d74e20370acb04ad889077d14d0f64a9c8ea6a42bc60cddf1e844699914
11
11
 
12
- # 1. DevSecOps: Patch Alpine OS
13
- RUN apk update && apk upgrade --no-cache
12
+ # 1. DevSecOps: Patch Alpine OS, and ship a CA bundle: without it no
13
+ # verified TLS egress works (RDS, AWS APIs, webhooks) from runtimes
14
+ # using the system store.
15
+ RUN apk update && apk upgrade --no-cache && apk add --no-cache ca-certificates
14
16
 
15
17
  ENV NODE_ENV=production
16
18
  WORKDIR /app
@@ -24,6 +24,7 @@ WORKDIR /app
24
24
  # FIX 2: Upgrade Alpine packages and absolutely destroy npm, yarn, and corepack
25
25
  # to eliminate all remaining Critical/High container vulnerabilities.
26
26
  RUN apk upgrade --no-cache && \
27
+ apk add --no-cache ca-certificates && \
27
28
  rm -rf /usr/local/lib/node_modules/npm \
28
29
  /usr/local/bin/npm \
29
30
  /usr/local/bin/npx \
@@ -9,8 +9,10 @@ RUN npm ci --omit=dev && npm cache clean --force && mkdir -p node_modules
9
9
  # --- Stage 2: Production runner (no package managers) ---
10
10
  FROM node:22-alpine@sha256:fe4f6d74e20370acb04ad889077d14d0f64a9c8ea6a42bc60cddf1e844699914 AS runner
11
11
 
12
- # 1. DevSecOps: Patch underlying Alpine OS vulnerabilities
13
- RUN apk update && apk upgrade --no-cache
12
+ # 1. DevSecOps: Patch underlying Alpine OS vulnerabilities, and ship a
13
+ # CA bundle: without it no verified TLS egress works (RDS, AWS APIs,
14
+ # webhooks) from runtimes using the system store.
15
+ RUN apk update && apk upgrade --no-cache && apk add --no-cache ca-certificates
14
16
 
15
17
  # 2. Set production environment (optimizes Node and prevents dev dependencies)
16
18
  ENV NODE_ENV=production
@@ -26,6 +26,7 @@ ENV NITRO_HOST="0.0.0.0"
26
26
  # 1. Upgrade Alpine OS packages to clear OpenSSL/crypto CVEs
27
27
  # 2. Vaporize Node package managers (npm, yarn, corepack) to clear ghost CVEs
28
28
  RUN apk update && apk upgrade --no-cache && \
29
+ apk add --no-cache ca-certificates && \
29
30
  rm -rf /usr/local/lib/node_modules \
30
31
  /usr/local/bin/npm \
31
32
  /usr/local/bin/npx \
@@ -34,9 +34,10 @@ WORKDIR /app
34
34
  RUN addgroup -S appgroup && \
35
35
  adduser -S appuser -G appgroup -D -s /bin/sh
36
36
 
37
- # Runtime libraries only (native wheels arrive inside the venv)
37
+ # Runtime libraries only (native wheels arrive inside the venv), plus a
38
+ # CA bundle: without it no verified TLS egress works (RDS, AWS APIs).
38
39
  RUN apk update && apk upgrade --no-cache && \
39
- apk add --no-cache libpq
40
+ apk add --no-cache libpq ca-certificates
40
41
 
41
42
  # Strip the base image's system pip (the venv already ships without one)
42
43
  RUN /usr/local/bin/python -m pip uninstall -y setuptools wheel pip && \
@@ -33,7 +33,7 @@ ENV RAILS_ENV=production \
33
33
  # Upgrade Alpine OS to patch system CVEs and install runtime libs
34
34
  # Explicitly patch Ruby's default gems and remove their legacy gemspecs so Trivy ignores them
35
35
  RUN apk update && apk upgrade --no-cache && \
36
- apk add --no-cache postgresql-libs tzdata && \
36
+ apk add --no-cache postgresql-libs tzdata ca-certificates && \
37
37
  apk add --no-cache --virtual .build-deps build-base zlib-dev && \
38
38
  gem install erb net-imap resolv rexml uri zlib && \
39
39
  rm -f /usr/local/lib/ruby/gems/*/specifications/default/erb-*.gemspec \
@@ -26,8 +26,10 @@ RUN GRADA_BYPASS=true npm run build
26
26
  # ==========================================
27
27
  FROM node:22-alpine@sha256:fe4f6d74e20370acb04ad889077d14d0f64a9c8ea6a42bc60cddf1e844699914
28
28
 
29
- # 1. DevSecOps: Patch underlying Alpine OS vulnerabilities
30
- RUN apk update && apk upgrade --no-cache
29
+ # 1. DevSecOps: Patch underlying Alpine OS vulnerabilities, and ship a
30
+ # CA bundle: without it no verified TLS egress works (RDS, AWS APIs,
31
+ # webhooks) from runtimes using the system store.
32
+ RUN apk update && apk upgrade --no-cache && apk add --no-cache ca-certificates
31
33
 
32
34
  # 2. Set production environment
33
35
  ENV NODE_ENV=production
@@ -13,7 +13,8 @@
13
13
 
14
14
  # --- IAM Role assumed by EventBridge Scheduler ---
15
15
  resource "aws_iam_role" "scheduler_cron_role" {
16
- name = "${local.app_name}-cron-scheduler-role"
16
+ name = "${local.app_name}-cron-scheduler-role"
17
+ permissions_boundary = local.preview_boundary_arn
17
18
  assume_role_policy = jsonencode({
18
19
  Version = "2012-10-17"
19
20
  Statement = [
@@ -7,7 +7,8 @@
7
7
 
8
8
  # --- IAM Role assumed by EventBridge Scheduler ---
9
9
  resource "aws_iam_role" "scheduler_cron_role" {
10
- name = "${local.app_name}-cron-scheduler-role"
10
+ name = "${local.app_name}-cron-scheduler-role"
11
+ permissions_boundary = local.preview_boundary_arn
11
12
  assume_role_policy = jsonencode({
12
13
  Version = "2012-10-17"
13
14
  Statement = [
@@ -85,8 +85,9 @@ data "aws_iam_policy_document" "ecs_trust" {
85
85
  }
86
86
 
87
87
  resource "aws_iam_role" "execution_role" {
88
- name = "${local.app_name}-execution-role"
89
- assume_role_policy = data.aws_iam_policy_document.ecs_trust.json
88
+ name = "${local.app_name}-execution-role"
89
+ assume_role_policy = data.aws_iam_policy_document.ecs_trust.json
90
+ permissions_boundary = local.preview_boundary_arn
90
91
  }
91
92
 
92
93
  resource "aws_iam_role_policy_attachment" "execution_role_policy" {
@@ -109,8 +110,9 @@ data "aws_iam_policy_document" "lambda_task_trust" {
109
110
  }
110
111
 
111
112
  resource "aws_iam_role" "task_role" {
112
- name = "${local.app_name}-task-role"
113
- assume_role_policy = data.aws_iam_policy_document.lambda_task_trust.json
113
+ name = "${local.app_name}-task-role"
114
+ assume_role_policy = data.aws_iam_policy_document.lambda_task_trust.json
115
+ permissions_boundary = local.preview_boundary_arn
114
116
  }
115
117
 
116
118
  # VPC ENI management plus CloudWatch Logs delivery (this single managed
@@ -94,8 +94,9 @@ data "aws_iam_policy_document" "ecs_trust" {
94
94
  }
95
95
 
96
96
  resource "aws_iam_role" "execution_role" {
97
- name = "${local.app_name}-execution-role"
98
- assume_role_policy = data.aws_iam_policy_document.ecs_trust.json
97
+ name = "${local.app_name}-execution-role"
98
+ assume_role_policy = data.aws_iam_policy_document.ecs_trust.json
99
+ permissions_boundary = local.preview_boundary_arn
99
100
  }
100
101
 
101
102
  resource "aws_iam_role_policy_attachment" "execution_role_policy" {
@@ -106,8 +107,9 @@ resource "aws_iam_role_policy_attachment" "execution_role_policy" {
106
107
  # --- IAM: Task Role ---
107
108
  # Allows your application code running INSIDE the container to access AWS services
108
109
  resource "aws_iam_role" "task_role" {
109
- name = "${local.app_name}-task-role"
110
- assume_role_policy = data.aws_iam_policy_document.ecs_trust.json
110
+ name = "${local.app_name}-task-role"
111
+ assume_role_policy = data.aws_iam_policy_document.ecs_trust.json
112
+ permissions_boundary = local.preview_boundary_arn
111
113
  }
112
114
 
113
115
  # --- IAM: ECS Exec (SSM) permissions for the task role ---
@@ -36,6 +36,11 @@ locals {
36
36
  # (not local.app_name): app_name carries the workspace suffix in preview
37
37
  # workspaces, while these denies must always name production.
38
38
  prod_prefix = "{{PROJECT_NAME}}{{RESOURCE_SUFFIX}}"
39
+ # Boundary ARN resolving in every workspace: created in default, read
40
+ # everywhere else (mirrors the secrets-vault pattern). Consumed by the
41
+ # task/execution/cron roles, which static trees lack.
42
+ # tflint-ignore: terraform_unused_declarations
43
+ preview_boundary_arn = terraform.workspace == "default" ? aws_iam_policy.preview_boundary[0].arn : data.aws_iam_policy.preview_boundary[0].arn
39
44
  }
40
45
 
41
46
  # Deploy role FIRST: readTerraformOidcTrust anchors on this block so re-init
@@ -303,6 +308,191 @@ resource "aws_iam_role_policy" "preview_guardrails" {
303
308
  "arn:aws:logs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:log-group:/ecs/${local.prod_prefix}",
304
309
  ]
305
310
  },
311
+ {
312
+ # BUG-212: every role preview credentials create must carry the
313
+ # boundary — a missing key fails StringNotEquals, so unbounded
314
+ # creation is denied and born-capped roles cannot escalate.
315
+ Sid = "DenyRoleWithoutBoundary"
316
+ Effect = "Deny"
317
+ Action = ["iam:CreateRole"]
318
+ Resource = "*"
319
+ Condition = {
320
+ StringNotEquals = {
321
+ "iam:PermissionsBoundary" = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:policy/${local.prod_prefix}-preview-boundary"
322
+ }
323
+ }
324
+ },
325
+ {
326
+ # The boundary cannot be swapped or removed after creation:
327
+ # legitimate Terraform never touches it (stable ARN, and
328
+ # deleting a role needs no boundary call).
329
+ Sid = "DenyBoundarySwap"
330
+ Effect = "Deny"
331
+ Action = ["iam:PutRolePermissionsBoundary", "iam:DeleteRolePermissionsBoundary"]
332
+ Resource = "*"
333
+ },
334
+ {
335
+ # The boundary policy itself cannot be neutered (preview
336
+ # Terraform never manages it: this file is
337
+ # default-workspace-only).
338
+ Sid = "DenyBoundaryMutation"
339
+ Effect = "Deny"
340
+ Action = ["iam:*"]
341
+ Resource = [
342
+ "arn:aws:iam::${data.aws_caller_identity.current.account_id}:policy/${local.prod_prefix}-preview-boundary",
343
+ ]
344
+ },
306
345
  ]
307
346
  })
308
347
  }
348
+
349
+ # BUG-212: permissions boundary capping every role preview credentials
350
+ # can create. The guardrail above denies CreateRole unless the request
351
+ # carries this boundary, so a backdoor role is born capped: its
352
+ # effective permissions are its own policies intersected with this one.
353
+ # Deny-list shape (default-allow) on purpose: a missing entry weakens
354
+ # security instead of breaking prod tasks. Keep the data denies in sync
355
+ # with preview_guardrails above.
356
+ resource "aws_iam_policy" "preview_boundary" {
357
+ count = terraform.workspace == "default" ? 1 : 0
358
+ name = "${local.prod_prefix}-preview-boundary"
359
+ description = "Permissions boundary capping roles created by preview CI runs"
360
+
361
+ policy = jsonencode({
362
+ Version = "2012-10-17"
363
+ Statement = [
364
+ {
365
+ Sid = "BoundaryBaseAllow"
366
+ Effect = "Allow"
367
+ Action = "*"
368
+ Resource = "*"
369
+ },
370
+ {
371
+ Sid = "BoundaryDenyIAM"
372
+ Effect = "Deny"
373
+ Action = ["iam:*"]
374
+ Resource = "*"
375
+ },
376
+ {
377
+ Sid = "BoundaryDenyAuditBilling"
378
+ Effect = "Deny"
379
+ Action = ["cloudtrail:*", "organizations:*", "aws-portal:*", "billing:*"]
380
+ Resource = "*"
381
+ },
382
+ {
383
+ Sid = "BoundaryDenyComputeAbuse"
384
+ Effect = "Deny"
385
+ Action = ["ec2:RunInstances"]
386
+ Resource = "*"
387
+ },
388
+ {
389
+ Sid = "BoundaryDenySnapshotSharing"
390
+ Effect = "Deny"
391
+ Action = ["rds:ModifyDBSnapshotAttribute"]
392
+ Resource = "*"
393
+ },
394
+ {
395
+ Sid = "BoundaryDenyStateDestruction"
396
+ Effect = "Deny"
397
+ Action = ["s3:DeleteBucket", "s3:DeleteObjectVersion"]
398
+ Resource = [
399
+ "arn:aws:s3:::{{STATE_BUCKET}}",
400
+ "arn:aws:s3:::{{STATE_BUCKET}}/*",
401
+ ]
402
+ },
403
+ {
404
+ Sid = "BoundaryDenyECSShutdown"
405
+ Effect = "Deny"
406
+ Action = ["ecs:UpdateService", "ecs:DeleteService", "ecs:DeleteCluster"]
407
+ Resource = [
408
+ "arn:aws:ecs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:cluster/${local.prod_prefix}-cluster",
409
+ "arn:aws:ecs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:service/${local.prod_prefix}-cluster/${local.prod_prefix}-service",
410
+ "arn:aws:ecs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:service/${local.prod_prefix}-cluster/${local.prod_prefix}-worker-service",
411
+ ]
412
+ },
413
+ {
414
+ Sid = "BoundaryDenyImageDeletion"
415
+ Effect = "Deny"
416
+ Action = ["ecr:BatchDeleteImage"]
417
+ Resource = [
418
+ "arn:aws:ecr:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:repository/${local.prod_prefix}-repo",
419
+ ]
420
+ },
421
+ {
422
+ Sid = "BoundaryDenyLambdaRewrite"
423
+ Effect = "Deny"
424
+ Action = ["lambda:UpdateFunctionCode", "lambda:DeleteFunction"]
425
+ Resource = [
426
+ "arn:aws:lambda:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:function:${local.prod_prefix}-fn",
427
+ ]
428
+ },
429
+ {
430
+ Sid = "BoundaryDenyQueueDestruction"
431
+ Effect = "Deny"
432
+ Action = ["sqs:PurgeQueue", "sqs:DeleteQueue"]
433
+ Resource = [
434
+ "arn:aws:sqs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:${local.prod_prefix}-queue",
435
+ "arn:aws:sqs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:${local.prod_prefix}-dlq",
436
+ ]
437
+ },
438
+ {
439
+ Sid = "BoundaryDenyDatabaseDestruction"
440
+ Effect = "Deny"
441
+ Action = ["rds:DeleteDBInstance", "rds:ModifyDBInstance"]
442
+ Resource = [
443
+ "arn:aws:rds:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:db:${local.prod_prefix}-db",
444
+ "arn:aws:rds:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:db:${local.prod_prefix}-db-instance-1",
445
+ ]
446
+ },
447
+ {
448
+ Sid = "BoundaryDenyAuroraDestruction"
449
+ Effect = "Deny"
450
+ Action = ["rds:DeleteDBCluster", "rds:ModifyDBCluster"]
451
+ Resource = [
452
+ "arn:aws:rds:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:cluster:${local.prod_prefix}-db-cluster",
453
+ ]
454
+ },
455
+ {
456
+ Sid = "BoundaryDenyTableDeletion"
457
+ Effect = "Deny"
458
+ Action = ["dynamodb:DeleteTable"]
459
+ Resource = [
460
+ "arn:aws:dynamodb:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:table/${local.prod_prefix}-table",
461
+ ]
462
+ },
463
+ {
464
+ Sid = "BoundaryDenySnapshotDeletion"
465
+ Effect = "Deny"
466
+ Action = ["rds:DeleteDBSnapshot", "rds:DeleteDBClusterSnapshot"]
467
+ Resource = [
468
+ "arn:aws:rds:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:snapshot:${local.prod_prefix}-db-*",
469
+ "arn:aws:rds:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:cluster-snapshot:${local.prod_prefix}-db-cluster-*",
470
+ ]
471
+ },
472
+ {
473
+ Sid = "BoundaryDenySecretsDeletion"
474
+ Effect = "Deny"
475
+ Action = ["secretsmanager:DeleteSecret"]
476
+ Resource = [
477
+ "arn:aws:secretsmanager:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:secret:${local.prod_prefix}-secrets-*",
478
+ ]
479
+ },
480
+ {
481
+ Sid = "BoundaryDenyLogDeletion"
482
+ Effect = "Deny"
483
+ Action = ["logs:DeleteLogGroup"]
484
+ Resource = [
485
+ "arn:aws:logs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:log-group:/ecs/${local.prod_prefix}",
486
+ ]
487
+ },
488
+ ]
489
+ })
490
+ }
491
+
492
+ # Preview workspaces create pr-suffixed roles through the same templates,
493
+ # so they read the default workspace's boundary instead of creating one
494
+ # (IAM names are account-global).
495
+ data "aws_iam_policy" "preview_boundary" {
496
+ count = terraform.workspace == "default" ? 0 : 1
497
+ name = "${local.prod_prefix}-preview-boundary"
498
+ }