grada-run 0.49.2 → 0.49.4
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 +1 -1
- package/src/commands/db/backup.js +64 -0
- package/src/commands/db/migrate.js +18 -4
- package/src/commands/gc.js +23 -7
- package/src/commands/init.js +6 -2
- package/src/utils/resolvers.js +15 -0
- package/templates/terraform/oidc.tf +281 -153
package/package.json
CHANGED
|
@@ -25,6 +25,31 @@ const SNAPSHOT_ALREADY_EXISTS_NAMES = new Set([
|
|
|
25
25
|
// wastes the timeout and misreports.
|
|
26
26
|
const TERMINAL_SNAPSHOT_STATUSES = new Set(['failed', 'deleted', 'deleting']);
|
|
27
27
|
|
|
28
|
+
// Source database of a described snapshot, by kind. Missing attributes
|
|
29
|
+
// read as undefined (never equal to the target): ownership callers fail
|
|
30
|
+
// closed on unattributed snapshots.
|
|
31
|
+
function snapshotSourceDb(snapshot, isCluster) {
|
|
32
|
+
if (!snapshot) return undefined;
|
|
33
|
+
return isCluster ? snapshot.DBClusterIdentifier : snapshot.DBInstanceIdentifier;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// BUG-204 failure: the reused id names another database's snapshot.
|
|
37
|
+
// Shared by the wait and no-wait paths (they differ only in `waited`).
|
|
38
|
+
function failSnapshotMismatch({ spinnerHandle, snapshotId, foreignDb, targetId, projectName, waited, dbIdentifier, region }) {
|
|
39
|
+
spinnerHandle.stop(color.red('❌ Snapshot belongs to another database.'));
|
|
40
|
+
return failCommand({
|
|
41
|
+
print: () => {
|
|
42
|
+
console.log(color.red(`\n✖ Snapshot ${snapshotId} belongs to ${foreignDb ?? 'an unknown database'}, not ${targetId} — refusing to adopt it.`));
|
|
43
|
+
console.log(' Pass a different --id, or delete the foreign snapshot first.\n');
|
|
44
|
+
},
|
|
45
|
+
event: 'db_backup_run',
|
|
46
|
+
telemetry: { projectName, waited },
|
|
47
|
+
errorCode: 'SNAPSHOT_MISMATCH',
|
|
48
|
+
reason: 'snapshot-mismatch',
|
|
49
|
+
resultExtra: { dbIdentifier, region, snapshotId },
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
28
53
|
export function parseDbBackupArgs(argv = []) {
|
|
29
54
|
const args = normalizeArgv(argv);
|
|
30
55
|
if (args[0] === 'db') args.shift();
|
|
@@ -177,6 +202,31 @@ async function runDbBackupMain(input = {}) {
|
|
|
177
202
|
|
|
178
203
|
if (noWait) {
|
|
179
204
|
if (reusedExisting) {
|
|
205
|
+
// BUG-204: verify ownership even when not waiting — one
|
|
206
|
+
// describe, fail closed on a foreign snapshot. A
|
|
207
|
+
// not-found here is transient (eventual consistency),
|
|
208
|
+
// so only proceed past it.
|
|
209
|
+
let ownedSnapshot = null;
|
|
210
|
+
try {
|
|
211
|
+
if (isCluster) {
|
|
212
|
+
const resp = await rdsClient.send(
|
|
213
|
+
new DescribeDBClusterSnapshotsCommand({ DBClusterSnapshotIdentifier: snapshotId })
|
|
214
|
+
);
|
|
215
|
+
ownedSnapshot = resp.DBClusterSnapshots?.[0] ?? null;
|
|
216
|
+
} else {
|
|
217
|
+
const resp = await rdsClient.send(
|
|
218
|
+
new DescribeDBSnapshotsCommand({ DBSnapshotIdentifier: snapshotId })
|
|
219
|
+
);
|
|
220
|
+
ownedSnapshot = resp.DBSnapshots?.[0] ?? null;
|
|
221
|
+
}
|
|
222
|
+
} catch (error) {
|
|
223
|
+
const notFoundNames = isCluster ? CLUSTER_SNAPSHOT_NOT_FOUND_NAMES : SNAPSHOT_NOT_FOUND_NAMES;
|
|
224
|
+
if (!(error && notFoundNames.has(error.name))) throw error;
|
|
225
|
+
}
|
|
226
|
+
const foreignDb = snapshotSourceDb(ownedSnapshot, isCluster);
|
|
227
|
+
if (ownedSnapshot && foreignDb !== target.id) {
|
|
228
|
+
return failSnapshotMismatch({ spinnerHandle: s, snapshotId, foreignDb, targetId: target.id, projectName, waited: false, dbIdentifier, region });
|
|
229
|
+
}
|
|
180
230
|
s.stop(color.green('Snapshot already exists.'));
|
|
181
231
|
console.log(`\n Snapshot ${color.cyan(snapshotId)} already exists — reusing it.`);
|
|
182
232
|
} else {
|
|
@@ -218,6 +268,16 @@ async function runDbBackupMain(input = {}) {
|
|
|
218
268
|
throw error;
|
|
219
269
|
}
|
|
220
270
|
const snapshot = snapshots[0] || null;
|
|
271
|
+
// BUG-204: an explicit --id can name another database's
|
|
272
|
+
// snapshot (AlreadyExists proves existence, not
|
|
273
|
+
// ownership) — fail closed instead of adopting a
|
|
274
|
+
// foreign snapshot as our safety backup. Checked
|
|
275
|
+
// before status handling so a foreign snapshot fails
|
|
276
|
+
// fast instead of burning the timeout.
|
|
277
|
+
const foreignDb = snapshotSourceDb(snapshot, isCluster);
|
|
278
|
+
if (snapshot && foreignDb !== target.id) {
|
|
279
|
+
return { done: true, value: { sourceMismatch: true, sourceDb: foreignDb } };
|
|
280
|
+
}
|
|
221
281
|
if (snapshot && snapshot.Status === 'available') {
|
|
222
282
|
return { done: true, value: snapshot };
|
|
223
283
|
}
|
|
@@ -232,6 +292,10 @@ async function runDbBackupMain(input = {}) {
|
|
|
232
292
|
},
|
|
233
293
|
});
|
|
234
294
|
|
|
295
|
+
if (outcome.value?.sourceMismatch) {
|
|
296
|
+
return failSnapshotMismatch({ spinnerHandle: s, snapshotId, foreignDb: outcome.value.sourceDb, targetId: target.id, projectName, waited: true, dbIdentifier, region });
|
|
297
|
+
}
|
|
298
|
+
|
|
235
299
|
if (outcome.value?.terminalFailure) {
|
|
236
300
|
const failedStatus = outcome.value.status;
|
|
237
301
|
s.stop(color.red(`❌ Snapshot ${failedStatus}.`));
|
|
@@ -16,7 +16,9 @@ import {
|
|
|
16
16
|
resolveHeadless,
|
|
17
17
|
resolveCwd,
|
|
18
18
|
readTerraformComputeTarget,
|
|
19
|
+
readTerraformDbKind,
|
|
19
20
|
} from '../../utils/resolvers.js';
|
|
21
|
+
import { resolveDbIdentifier, resolveDbClusterIdentifier } from '../../utils/rds.js';
|
|
20
22
|
import { detectMigrationCommand } from '../../utils/detector.js';
|
|
21
23
|
import { resolveContainer } from '../../utils/ecs.js';
|
|
22
24
|
import { runEphemeralEcsTask, buildRunnerCommand, parseRunnerTimeout, guardNpmStrippedRunner, reportRunnerOutcome } from '../../utils/ecs-runner.js';
|
|
@@ -144,15 +146,20 @@ function injectGateBlock(content, { steps, anchor }) {
|
|
|
144
146
|
|
|
145
147
|
// Idempotently injects (or refreshes) the migration gate block into a
|
|
146
148
|
// deploy.yml document. Returns the updated content, or null when neither
|
|
147
|
-
// anchor step is present. Pure and unit-tested.
|
|
148
|
-
|
|
149
|
+
// anchor step is present. Pure and unit-tested. The snapshot id embeds
|
|
150
|
+
// the database identifier (BUG-205): bare pre-deploy-<sha> ids match no
|
|
151
|
+
// guardrail or gc name pattern, so they were never protected or retired.
|
|
152
|
+
export function injectMigrationGate(workflowContent, { cmd, cliVersion, dbIdentifier } = {}) {
|
|
153
|
+
if (typeof dbIdentifier !== 'string' || dbIdentifier.trim() === '') {
|
|
154
|
+
throw new Error('injectMigrationGate requires dbIdentifier for the snapshot id');
|
|
155
|
+
}
|
|
149
156
|
const taskDefRef = '${{ steps.register-task-def.outputs.task-arn }}';
|
|
150
157
|
const runner = buildRunnerInvocation(cliVersion);
|
|
151
158
|
return injectGateBlock(workflowContent, {
|
|
152
159
|
steps: [
|
|
153
160
|
{
|
|
154
161
|
stepName: 'Take pre-migration database snapshot',
|
|
155
|
-
runLine: `${runner} db backup --id "pre-deploy-\${{ github.sha }}" --headless`,
|
|
162
|
+
runLine: `${runner} db backup --id "${dbIdentifier.trim()}-pre-deploy-\${{ github.sha }}" --headless`,
|
|
156
163
|
},
|
|
157
164
|
{
|
|
158
165
|
stepName: 'Pre-Deploy Database Migration',
|
|
@@ -321,7 +328,14 @@ async function runDbMigrateMain(input = {}) {
|
|
|
321
328
|
resultExtra: { cluster, service, region },
|
|
322
329
|
});
|
|
323
330
|
}
|
|
324
|
-
|
|
331
|
+
// BUG-205: the gate always targets production (deploy.yml), so
|
|
332
|
+
// resolve the prod db id even with a preview workspace checked
|
|
333
|
+
// out locally. Aurora needs the cluster prefix: cluster
|
|
334
|
+
// snapshots named with the instance prefix would miss the
|
|
335
|
+
// cluster-snapshot guardrail pattern.
|
|
336
|
+
const setupDbResolver = readTerraformDbKind(cwd) === 'cluster' ? resolveDbClusterIdentifier : resolveDbIdentifier;
|
|
337
|
+
const setupDbIdentifier = setupDbResolver({ projectName, workspace: 'default' }, cwd);
|
|
338
|
+
const updated = injectMigrationGate(workflowContent, { cmd: resolvedCmd, cliVersion: getCliVersion(), dbIdentifier: setupDbIdentifier });
|
|
325
339
|
if (updated === null) {
|
|
326
340
|
return failCommand({
|
|
327
341
|
message: '\n✖ Could not find the task-definition registration or ECS deployment step in .github/workflows/deploy.yml to anchor the migration gate.\n',
|
package/src/commands/gc.js
CHANGED
|
@@ -273,7 +273,8 @@ async function discoverUnattachedEips({ ec2Client, projectName }) {
|
|
|
273
273
|
|
|
274
274
|
// Standard target discovery: pre-destroy manual snapshots older than
|
|
275
275
|
// the age threshold. Scoped by the exact `<db>-manual-<stamp>` naming
|
|
276
|
-
// pattern destroy writes
|
|
276
|
+
// pattern destroy writes plus the `<db>-pre-deploy-<sha>` pattern the
|
|
277
|
+
// migration gate writes (instance AND cluster snapshots) — foreign,
|
|
277
278
|
// automated, non-available, and young snapshots are never proposed.
|
|
278
279
|
// Tolerant of missing clients/identifiers (programmatic callers without
|
|
279
280
|
// RDS context discover nothing instead of throwing).
|
|
@@ -281,22 +282,37 @@ async function discoverOldManualSnapshots({ rdsClient, dbIdentifier, dbClusterId
|
|
|
281
282
|
if (!rdsClient || (!dbIdentifier && !dbClusterIdentifier)) return [];
|
|
282
283
|
const maxAgeDays = Number(snapshotMaxAgeDays ?? DEFAULT_SNAPSHOT_MAX_AGE_DAYS);
|
|
283
284
|
const cutoffMs = Date.now() - (Number.isFinite(maxAgeDays) ? maxAgeDays : DEFAULT_SNAPSHOT_MAX_AGE_DAYS) * 86400000;
|
|
284
|
-
const
|
|
285
|
+
const dbIds = [dbIdentifier, dbClusterIdentifier]
|
|
285
286
|
.filter((id) => typeof id === 'string' && id.trim())
|
|
286
|
-
.map((id) =>
|
|
287
|
+
.map((id) => id.trim().toLowerCase());
|
|
288
|
+
const patterns = dbIds
|
|
289
|
+
.map((id) => new RegExp(`^${escapeRegExp(id)}-manual-\\d{8}-\\d{6}$`));
|
|
290
|
+
// BUG-205: the gate's pre-deploy snapshots are per-commit, so without
|
|
291
|
+
// a discovery rule they accumulate into the region snapshot quota.
|
|
292
|
+
const predeployPatterns = dbIds
|
|
293
|
+
.map((id) => new RegExp(`^${escapeRegExp(id)}-pre-deploy-[0-9a-f]{7,40}$`));
|
|
294
|
+
// Legacy bare pre-deploy-<sha> ids carry no db scope: retire them
|
|
295
|
+
// only with a matching source-db attribute, never by name alone.
|
|
296
|
+
const legacyPredeployPattern = /^pre-deploy-[0-9a-f]{7,40}$/;
|
|
297
|
+
const knownSourceDbs = new Set(dbIds);
|
|
287
298
|
if (patterns.length === 0) return [];
|
|
288
|
-
const isRetirable = (snapshotId, status, type, createTime) => {
|
|
299
|
+
const isRetirable = (snapshotId, status, type, createTime, sourceDb) => {
|
|
289
300
|
if (status !== 'available' || type !== 'manual') return false;
|
|
290
301
|
const createdMs = createTime ? new Date(createTime).getTime() : NaN;
|
|
291
302
|
if (!Number.isFinite(createdMs) || createdMs > cutoffMs) return false;
|
|
292
|
-
|
|
303
|
+
const name = String(snapshotId).toLowerCase();
|
|
304
|
+
if (patterns.some((pattern) => pattern.test(name))) return true;
|
|
305
|
+
if (predeployPatterns.some((pattern) => pattern.test(name))) return true;
|
|
306
|
+
return legacyPredeployPattern.test(name)
|
|
307
|
+
&& typeof sourceDb === 'string'
|
|
308
|
+
&& knownSourceDbs.has(sourceDb.toLowerCase());
|
|
293
309
|
};
|
|
294
310
|
const snapshots = [];
|
|
295
311
|
let marker;
|
|
296
312
|
do {
|
|
297
313
|
const resp = await rdsClient.send(new DescribeDBSnapshotsCommand({ Marker: marker, MaxRecords: 100 }));
|
|
298
314
|
for (const snap of resp.DBSnapshots || []) {
|
|
299
|
-
if (isRetirable(snap.DBSnapshotIdentifier, snap.Status, snap.SnapshotType, snap.SnapshotCreateTime)) {
|
|
315
|
+
if (isRetirable(snap.DBSnapshotIdentifier, snap.Status, snap.SnapshotType, snap.SnapshotCreateTime, snap.DBInstanceIdentifier)) {
|
|
300
316
|
snapshots.push({ id: snap.DBSnapshotIdentifier, kind: 'instance', createTime: snap.SnapshotCreateTime });
|
|
301
317
|
}
|
|
302
318
|
}
|
|
@@ -306,7 +322,7 @@ async function discoverOldManualSnapshots({ rdsClient, dbIdentifier, dbClusterId
|
|
|
306
322
|
do {
|
|
307
323
|
const resp = await rdsClient.send(new DescribeDBClusterSnapshotsCommand({ Marker: marker, MaxRecords: 100 }));
|
|
308
324
|
for (const snap of resp.DBClusterSnapshots || []) {
|
|
309
|
-
if (isRetirable(snap.DBClusterSnapshotIdentifier, snap.Status, snap.SnapshotType, snap.SnapshotCreateTime)) {
|
|
325
|
+
if (isRetirable(snap.DBClusterSnapshotIdentifier, snap.Status, snap.SnapshotType, snap.SnapshotCreateTime, snap.DBClusterIdentifier)) {
|
|
310
326
|
snapshots.push({ id: snap.DBClusterSnapshotIdentifier, kind: 'cluster', createTime: snap.SnapshotCreateTime });
|
|
311
327
|
}
|
|
312
328
|
}
|
package/src/commands/init.js
CHANGED
|
@@ -33,7 +33,7 @@ import { trackEvent, flushTelemetry, getCliVersion, setActiveCommandName, resetA
|
|
|
33
33
|
import { failCommand } from '../utils/command.js';
|
|
34
34
|
import { getFrameworkWarning } from '../utils/warnings.js';
|
|
35
35
|
import { provisionStateBucket, formatStateBucketName, isAuthError, printAwsAuthGuidance } from '../utils/aws.js';
|
|
36
|
-
import { generateTemplates } from '../utils/generator.js';
|
|
36
|
+
import { generateTemplates, resolveDbEngineRefs } from '../utils/generator.js';
|
|
37
37
|
import { planExistingFiles, executeBackup, preserveManagedFiles, restoreManagedFiles, refusalResultForPlan, writeInitManifest } from '../utils/backup.js';
|
|
38
38
|
import { checkStateAdoption } from '../utils/state-adoption.js';
|
|
39
39
|
import { atomicWriteFileSync } from '../utils/atomic-write.js';
|
|
@@ -1025,7 +1025,11 @@ async function mainStackMain(input = {}) {
|
|
|
1025
1025
|
if (migrationGateEnabled && migrationCmd) {
|
|
1026
1026
|
const deployYmlPath = path.join(dirConfig.targetDir, '.github', 'workflows', 'deploy.yml');
|
|
1027
1027
|
const workflowContent = readFileSafe(deployYmlPath);
|
|
1028
|
-
|
|
1028
|
+
// BUG-205: scope the gate's snapshot id to the database (aurora
|
|
1029
|
+
// takes the cluster prefix) so guardrails and gc can name it.
|
|
1030
|
+
const gateDbRefs = resolveDbEngineRefs(config.dbEngine);
|
|
1031
|
+
const gateDbIdentifier = `${dirConfig.actualProjectName}${resourceSuffix}-db${gateDbRefs.isCluster ? '-cluster' : ''}`;
|
|
1032
|
+
const gated = workflowContent ? injectMigrationGate(workflowContent, { cmd: migrationCmd, cliVersion: CLI_VERSION, dbIdentifier: gateDbIdentifier }) : null;
|
|
1029
1033
|
if (gated) {
|
|
1030
1034
|
atomicWriteFileSync(deployYmlPath, gated);
|
|
1031
1035
|
console.log(color.green('✅ Wired the pre-deploy database migration gate into .github/workflows/deploy.yml (snapshot first, then migrate)'));
|
package/src/utils/resolvers.js
CHANGED
|
@@ -45,6 +45,21 @@ export function readTerraformComputeTarget(cwd = process.cwd()) {
|
|
|
45
45
|
return detectComputeTargetFromMainTf(readFileSafe(path.join(base, 'terraform', 'main.tf')));
|
|
46
46
|
}
|
|
47
47
|
|
|
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.
|
|
53
|
+
export function readTerraformDbKind(cwd = process.cwd()) {
|
|
54
|
+
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
|
+
}
|
|
60
|
+
return 'instance';
|
|
61
|
+
}
|
|
62
|
+
|
|
48
63
|
// Predicate form of the target check for commands that adapt (rather
|
|
49
64
|
// than refuse) per target: `isComputeTarget(cwd, 'lambda')`.
|
|
50
65
|
export function isComputeTarget(cwd = process.cwd(), ...targets) {
|
|
@@ -41,6 +41,75 @@ locals {
|
|
|
41
41
|
# task/execution/cron roles, which static trees lack.
|
|
42
42
|
# tflint-ignore: terraform_unused_declarations
|
|
43
43
|
preview_boundary_arn = terraform.workspace == "default" ? aws_iam_policy.preview_boundary[0].arn : data.aws_iam_policy.preview_boundary[0].arn
|
|
44
|
+
# Shared twin resource lists: every Deny*/BoundaryDeny* pair consumes
|
|
45
|
+
# one list, so a one-sided resource edit is impossible. New pairs add
|
|
46
|
+
# their list here and reference it from both sides. Wildcards below
|
|
47
|
+
# anchor on prod_prefix (never on the bare project): preview names
|
|
48
|
+
# carry -pr-<n>- where prod carries the hex suffix, so a
|
|
49
|
+
# ${prod_prefix}-* pattern matches prod only. Anchoring also keeps
|
|
50
|
+
# the boundary under the 6144-char managed-policy quota that broke
|
|
51
|
+
# tier1 E2E at a 24-char prefix — prefer one anchored wildcard over
|
|
52
|
+
# several exact ARNs when adding entries.
|
|
53
|
+
guardrail_compute_abuse_resources = ["*"]
|
|
54
|
+
guardrail_snapshot_sharing_resources = ["*"]
|
|
55
|
+
guardrail_state_destruction_resources = [
|
|
56
|
+
"arn:aws:s3:::{{STATE_BUCKET}}*",
|
|
57
|
+
]
|
|
58
|
+
guardrail_ecs_shutdown_resources = [
|
|
59
|
+
"arn:aws:ecs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:cluster/${local.prod_prefix}-cluster",
|
|
60
|
+
"arn:aws:ecs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:service/${local.prod_prefix}-cluster/*",
|
|
61
|
+
]
|
|
62
|
+
guardrail_image_deletion_resources = [
|
|
63
|
+
"arn:aws:ecr:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:repository/${local.prod_prefix}-repo",
|
|
64
|
+
]
|
|
65
|
+
guardrail_lambda_rewrite_resources = [
|
|
66
|
+
"arn:aws:lambda:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:function:${local.prod_prefix}-fn",
|
|
67
|
+
]
|
|
68
|
+
guardrail_queue_destruction_resources = [
|
|
69
|
+
"arn:aws:sqs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:${local.prod_prefix}-*",
|
|
70
|
+
]
|
|
71
|
+
guardrail_database_destruction_resources = [
|
|
72
|
+
"arn:aws:rds:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:db:${local.prod_prefix}-db*",
|
|
73
|
+
]
|
|
74
|
+
guardrail_aurora_destruction_resources = [
|
|
75
|
+
"arn:aws:rds:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:cluster:${local.prod_prefix}-db-cluster",
|
|
76
|
+
]
|
|
77
|
+
guardrail_table_deletion_resources = [
|
|
78
|
+
"arn:aws:dynamodb:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:table/${local.prod_prefix}-table",
|
|
79
|
+
]
|
|
80
|
+
guardrail_snapshot_deletion_resources = [
|
|
81
|
+
"arn:aws:rds:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:snapshot:${local.prod_prefix}-db-*",
|
|
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
|
|
84
|
+
# they match no prod pattern above — deny them outright. gc never
|
|
85
|
+
# runs under preview credentials, so nothing legitimate needs them.
|
|
86
|
+
"arn:aws:rds:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:snapshot:pre-deploy-*",
|
|
87
|
+
"arn:aws:rds:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:cluster-snapshot:pre-deploy-*",
|
|
88
|
+
]
|
|
89
|
+
guardrail_secrets_deletion_resources = [
|
|
90
|
+
"arn:aws:secretsmanager:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:secret:${local.prod_prefix}-secrets-*",
|
|
91
|
+
]
|
|
92
|
+
guardrail_log_deletion_resources = [
|
|
93
|
+
"arn:aws:logs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:log-group:/ecs/${local.prod_prefix}",
|
|
94
|
+
]
|
|
95
|
+
guardrail_task_execution_resources = [
|
|
96
|
+
"arn:aws:ecs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:cluster/${local.prod_prefix}-cluster",
|
|
97
|
+
"arn:aws:ecs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:service/${local.prod_prefix}-cluster/*",
|
|
98
|
+
"arn:aws:ecs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:task/${local.prod_prefix}-cluster/*",
|
|
99
|
+
"arn:aws:ecs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:task-definition/${local.prod_prefix}-*:*",
|
|
100
|
+
]
|
|
101
|
+
guardrail_task_definition_resources = [
|
|
102
|
+
"arn:aws:ecs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:task-definition/${local.prod_prefix}-*:*",
|
|
103
|
+
]
|
|
104
|
+
# String-built (not HCL refs): static trees define no IAM roles, so
|
|
105
|
+
# refs would dangle and fail validate. ECS and Lambda use identical
|
|
106
|
+
# physical role names, so one pattern covers both and matches
|
|
107
|
+
# nothing on static. The wildcard also covers the CI roles (same
|
|
108
|
+
# prefix, -github-actions-*-role): capped callers never legitimately
|
|
109
|
+
# pass or mutate those, so the overlap only tightens the boundary.
|
|
110
|
+
guardrail_app_role_resources = [
|
|
111
|
+
"arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/${local.prod_prefix}-*-role",
|
|
112
|
+
]
|
|
44
113
|
}
|
|
45
114
|
|
|
46
115
|
# Deploy role FIRST: readTerraformOidcTrust anchors on this block so re-init
|
|
@@ -161,8 +230,10 @@ resource "aws_iam_role_policy" "deploy_boundary" {
|
|
|
161
230
|
|
|
162
231
|
# Preview guardrails: PR-triggered runs (preview/teardown/plan) keep full
|
|
163
232
|
# build power but cannot destroy production data, mint compute, or open
|
|
164
|
-
# IAM backdoors. Every Resource below names
|
|
165
|
-
#
|
|
233
|
+
# IAM backdoors. Every Resource below names production only — exact ARNs
|
|
234
|
+
# or prod_prefix-anchored wildcards (preview names carry -pr-<n>- where
|
|
235
|
+
# prod carries the hex suffix, so anchored patterns never match preview
|
|
236
|
+
# resources and pr-suffixed workflows keep working).
|
|
166
237
|
resource "aws_iam_role_policy" "preview_guardrails" {
|
|
167
238
|
count = terraform.workspace == "default" ? 1 : 0
|
|
168
239
|
name = "${local.prod_prefix}-preview-guardrails"
|
|
@@ -175,7 +246,7 @@ resource "aws_iam_role_policy" "preview_guardrails" {
|
|
|
175
246
|
Sid = "DenyComputeAbuse"
|
|
176
247
|
Effect = "Deny"
|
|
177
248
|
Action = ["ec2:RunInstances"]
|
|
178
|
-
Resource =
|
|
249
|
+
Resource = local.guardrail_compute_abuse_resources
|
|
179
250
|
},
|
|
180
251
|
{
|
|
181
252
|
Sid = "DenyIAMBackdoors"
|
|
@@ -203,110 +274,83 @@ resource "aws_iam_role_policy" "preview_guardrails" {
|
|
|
203
274
|
Sid = "DenySnapshotSharing"
|
|
204
275
|
Effect = "Deny"
|
|
205
276
|
Action = ["rds:ModifyDBSnapshotAttribute"]
|
|
206
|
-
Resource =
|
|
277
|
+
Resource = local.guardrail_snapshot_sharing_resources
|
|
207
278
|
},
|
|
208
279
|
{
|
|
209
|
-
Sid
|
|
210
|
-
Effect
|
|
211
|
-
Action
|
|
212
|
-
Resource =
|
|
213
|
-
"arn:aws:s3:::{{STATE_BUCKET}}",
|
|
214
|
-
"arn:aws:s3:::{{STATE_BUCKET}}/*",
|
|
215
|
-
]
|
|
280
|
+
Sid = "DenyProdStateDestruction"
|
|
281
|
+
Effect = "Deny"
|
|
282
|
+
Action = ["s3:DeleteBucket", "s3:DeleteObjectVersion"]
|
|
283
|
+
Resource = local.guardrail_state_destruction_resources
|
|
216
284
|
},
|
|
217
285
|
{
|
|
218
|
-
Sid
|
|
219
|
-
Effect
|
|
220
|
-
Action
|
|
221
|
-
Resource =
|
|
222
|
-
"arn:aws:ecs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:cluster/${local.prod_prefix}-cluster",
|
|
223
|
-
"arn:aws:ecs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:service/${local.prod_prefix}-cluster/${local.prod_prefix}-service",
|
|
224
|
-
"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",
|
|
225
|
-
]
|
|
286
|
+
Sid = "DenyProdECSShutdown"
|
|
287
|
+
Effect = "Deny"
|
|
288
|
+
Action = ["ecs:UpdateService", "ecs:DeleteService", "ecs:DeleteCluster"]
|
|
289
|
+
Resource = local.guardrail_ecs_shutdown_resources
|
|
226
290
|
},
|
|
227
291
|
{
|
|
228
|
-
Sid
|
|
229
|
-
Effect
|
|
230
|
-
Action
|
|
231
|
-
Resource =
|
|
232
|
-
"arn:aws:ecr:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:repository/${local.prod_prefix}-repo",
|
|
233
|
-
]
|
|
292
|
+
Sid = "DenyProdImageDeletion"
|
|
293
|
+
Effect = "Deny"
|
|
294
|
+
Action = ["ecr:BatchDeleteImage"]
|
|
295
|
+
Resource = local.guardrail_image_deletion_resources
|
|
234
296
|
},
|
|
235
297
|
{
|
|
236
|
-
Sid
|
|
237
|
-
Effect
|
|
238
|
-
Action
|
|
239
|
-
Resource =
|
|
240
|
-
"arn:aws:lambda:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:function:${local.prod_prefix}-fn",
|
|
241
|
-
]
|
|
298
|
+
Sid = "DenyProdLambdaRewrite"
|
|
299
|
+
Effect = "Deny"
|
|
300
|
+
Action = ["lambda:UpdateFunctionCode", "lambda:DeleteFunction"]
|
|
301
|
+
Resource = local.guardrail_lambda_rewrite_resources
|
|
242
302
|
},
|
|
243
303
|
{
|
|
244
|
-
Sid
|
|
245
|
-
Effect
|
|
246
|
-
Action
|
|
247
|
-
Resource =
|
|
248
|
-
"arn:aws:sqs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:${local.prod_prefix}-queue",
|
|
249
|
-
"arn:aws:sqs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:${local.prod_prefix}-dlq",
|
|
250
|
-
]
|
|
304
|
+
Sid = "DenyProdQueueDestruction"
|
|
305
|
+
Effect = "Deny"
|
|
306
|
+
Action = ["sqs:PurgeQueue", "sqs:DeleteQueue"]
|
|
307
|
+
Resource = local.guardrail_queue_destruction_resources
|
|
251
308
|
},
|
|
252
309
|
{
|
|
253
|
-
Sid
|
|
254
|
-
Effect
|
|
255
|
-
Action
|
|
256
|
-
Resource =
|
|
257
|
-
"arn:aws:rds:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:db:${local.prod_prefix}-db",
|
|
258
|
-
"arn:aws:rds:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:db:${local.prod_prefix}-db-instance-1",
|
|
259
|
-
]
|
|
310
|
+
Sid = "DenyProdDatabaseDestruction"
|
|
311
|
+
Effect = "Deny"
|
|
312
|
+
Action = ["rds:DeleteDBInstance", "rds:ModifyDBInstance"]
|
|
313
|
+
Resource = local.guardrail_database_destruction_resources
|
|
260
314
|
},
|
|
261
315
|
{
|
|
262
|
-
Sid
|
|
263
|
-
Effect
|
|
264
|
-
Action
|
|
265
|
-
Resource =
|
|
266
|
-
"arn:aws:rds:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:cluster:${local.prod_prefix}-db-cluster",
|
|
267
|
-
]
|
|
316
|
+
Sid = "DenyProdAuroraDestruction"
|
|
317
|
+
Effect = "Deny"
|
|
318
|
+
Action = ["rds:DeleteDBCluster", "rds:ModifyDBCluster"]
|
|
319
|
+
Resource = local.guardrail_aurora_destruction_resources
|
|
268
320
|
},
|
|
269
321
|
{
|
|
270
|
-
Sid
|
|
271
|
-
Effect
|
|
272
|
-
Action
|
|
273
|
-
Resource =
|
|
274
|
-
"arn:aws:dynamodb:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:table/${local.prod_prefix}-table",
|
|
275
|
-
]
|
|
322
|
+
Sid = "DenyProdTableDeletion"
|
|
323
|
+
Effect = "Deny"
|
|
324
|
+
Action = ["dynamodb:DeleteTable"]
|
|
325
|
+
Resource = local.guardrail_table_deletion_resources
|
|
276
326
|
},
|
|
277
327
|
{
|
|
278
328
|
# BUG-208: manual snapshots (grada names them
|
|
279
|
-
# <db-identifier>-manual-<stamp>
|
|
329
|
+
# <db-identifier>-manual-<stamp> and
|
|
330
|
+
# <db-identifier>-pre-deploy-<sha>) are directly deletable;
|
|
280
331
|
# automated snapshots can only go away via retention changes or
|
|
281
332
|
# instance deletion, both already denied above.
|
|
282
|
-
Sid
|
|
283
|
-
Effect
|
|
284
|
-
Action
|
|
285
|
-
Resource =
|
|
286
|
-
"arn:aws:rds:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:snapshot:${local.prod_prefix}-db-*",
|
|
287
|
-
"arn:aws:rds:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:cluster-snapshot:${local.prod_prefix}-db-cluster-*",
|
|
288
|
-
]
|
|
333
|
+
Sid = "DenyProdSnapshotDeletion"
|
|
334
|
+
Effect = "Deny"
|
|
335
|
+
Action = ["rds:DeleteDBSnapshot", "rds:DeleteDBClusterSnapshot"]
|
|
336
|
+
Resource = local.guardrail_snapshot_deletion_resources
|
|
289
337
|
},
|
|
290
338
|
{
|
|
291
339
|
# The vault ARN carries a random suffix and static trees have no
|
|
292
340
|
# vault at all (no secrets.tf), so match the tight name prefix —
|
|
293
341
|
# on static it simply matches nothing.
|
|
294
|
-
Sid
|
|
295
|
-
Effect
|
|
296
|
-
Action
|
|
297
|
-
Resource =
|
|
298
|
-
"arn:aws:secretsmanager:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:secret:${local.prod_prefix}-secrets-*",
|
|
299
|
-
]
|
|
342
|
+
Sid = "DenyProdSecretsDeletion"
|
|
343
|
+
Effect = "Deny"
|
|
344
|
+
Action = ["secretsmanager:DeleteSecret"]
|
|
345
|
+
Resource = local.guardrail_secrets_deletion_resources
|
|
300
346
|
},
|
|
301
347
|
{
|
|
302
348
|
# Web and worker containers share one log group; deleting it
|
|
303
349
|
# wipes the audit trail for both.
|
|
304
|
-
Sid
|
|
305
|
-
Effect
|
|
306
|
-
Action
|
|
307
|
-
Resource =
|
|
308
|
-
"arn:aws:logs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:log-group:/ecs/${local.prod_prefix}",
|
|
309
|
-
]
|
|
350
|
+
Sid = "DenyProdLogDeletion"
|
|
351
|
+
Effect = "Deny"
|
|
352
|
+
Action = ["logs:DeleteLogGroup"]
|
|
353
|
+
Resource = local.guardrail_log_deletion_resources
|
|
310
354
|
},
|
|
311
355
|
{
|
|
312
356
|
# BUG-212: every role preview credentials create must carry the
|
|
@@ -342,6 +386,41 @@ resource "aws_iam_role_policy" "preview_guardrails" {
|
|
|
342
386
|
"arn:aws:iam::${data.aws_caller_identity.current.account_id}:policy/${local.prod_prefix}-preview-boundary",
|
|
343
387
|
]
|
|
344
388
|
},
|
|
389
|
+
{
|
|
390
|
+
# BUG-215: close by target — deny the execution APIs on prod
|
|
391
|
+
# ARNs while pr-* stays allowed. No describes: plan.yml
|
|
392
|
+
# refreshes prod state with preview credentials, so describing
|
|
393
|
+
# prod is legitimate traffic.
|
|
394
|
+
Sid = "DenyProdTaskExecution"
|
|
395
|
+
Effect = "Deny"
|
|
396
|
+
Action = ["ecs:RunTask", "ecs:StopTask", "ecs:ExecuteCommand", "ecs:CreateService"]
|
|
397
|
+
Resource = local.guardrail_task_execution_resources
|
|
398
|
+
},
|
|
399
|
+
{
|
|
400
|
+
# RegisterTaskDefinition is likely resource-*-only (void half);
|
|
401
|
+
# the cluster-scoped RunTask deny above is the real choke.
|
|
402
|
+
Sid = "DenyProdTaskDefinitionRegistration"
|
|
403
|
+
Effect = "Deny"
|
|
404
|
+
Action = ["ecs:RegisterTaskDefinition", "ecs:DeregisterTaskDefinition"]
|
|
405
|
+
Resource = local.guardrail_task_definition_resources
|
|
406
|
+
},
|
|
407
|
+
{
|
|
408
|
+
Sid = "DenyProdPassRole"
|
|
409
|
+
Effect = "Deny"
|
|
410
|
+
Action = ["iam:PassRole"]
|
|
411
|
+
Resource = local.guardrail_app_role_resources
|
|
412
|
+
},
|
|
413
|
+
{
|
|
414
|
+
# Trust writes close the assume-it-directly bypass (re-trusting
|
|
415
|
+
# the prod task role would defeat every execution deny);
|
|
416
|
+
# DeleteRole guards the roles themselves. UpdateRole and
|
|
417
|
+
# tagging stay allowed (cosmetic — description, session
|
|
418
|
+
# duration within AWS bounds, tags).
|
|
419
|
+
Sid = "DenyProdAppRoleMutation"
|
|
420
|
+
Effect = "Deny"
|
|
421
|
+
Action = ["iam:AttachRolePolicy", "iam:DetachRolePolicy", "iam:PutRolePolicy", "iam:DeleteRolePolicy", "iam:UpdateAssumeRolePolicy", "iam:DeleteRole"]
|
|
422
|
+
Resource = local.guardrail_app_role_resources
|
|
423
|
+
},
|
|
345
424
|
]
|
|
346
425
|
})
|
|
347
426
|
}
|
|
@@ -351,8 +430,8 @@ resource "aws_iam_role_policy" "preview_guardrails" {
|
|
|
351
430
|
# carries this boundary, so a backdoor role is born capped: its
|
|
352
431
|
# effective permissions are its own policies intersected with this one.
|
|
353
432
|
# Deny-list shape (default-allow) on purpose: a missing entry weakens
|
|
354
|
-
# security instead of breaking prod tasks.
|
|
355
|
-
#
|
|
433
|
+
# security instead of breaking prod tasks. Twin pairs share their
|
|
434
|
+
# resource lists via the locals above, so one-sided edits fail loudly.
|
|
356
435
|
resource "aws_iam_policy" "preview_boundary" {
|
|
357
436
|
count = terraform.workspace == "default" ? 1 : 0
|
|
358
437
|
name = "${local.prod_prefix}-preview-boundary"
|
|
@@ -368,9 +447,18 @@ resource "aws_iam_policy" "preview_boundary" {
|
|
|
368
447
|
Resource = "*"
|
|
369
448
|
},
|
|
370
449
|
{
|
|
450
|
+
# BUG-214: capped roles must pass their task roles to ECS (the
|
|
451
|
+
# scheduler role passes at invocation time), so PassRole is
|
|
452
|
+
# carved out here and re-gated on service + target below.
|
|
453
|
+
# Explicit Action list on purpose: a Deny with NotAction would
|
|
454
|
+
# veto every AWS service, not just IAM (tier2 E2E proved it on
|
|
455
|
+
# secretsmanager:GetSecretValue, SES, and Bedrock). IAM reads
|
|
456
|
+
# and cosmetic writes (UpdateRole, tagging) stay allowed: they
|
|
457
|
+
# cannot escalate a backdoor role, and a missing entry must
|
|
458
|
+
# weaken security instead of breaking prod tasks.
|
|
371
459
|
Sid = "BoundaryDenyIAM"
|
|
372
460
|
Effect = "Deny"
|
|
373
|
-
Action = ["iam
|
|
461
|
+
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"]
|
|
374
462
|
Resource = "*"
|
|
375
463
|
},
|
|
376
464
|
{
|
|
@@ -383,107 +471,147 @@ resource "aws_iam_policy" "preview_boundary" {
|
|
|
383
471
|
Sid = "BoundaryDenyComputeAbuse"
|
|
384
472
|
Effect = "Deny"
|
|
385
473
|
Action = ["ec2:RunInstances"]
|
|
386
|
-
Resource =
|
|
474
|
+
Resource = local.guardrail_compute_abuse_resources
|
|
387
475
|
},
|
|
388
476
|
{
|
|
389
477
|
Sid = "BoundaryDenySnapshotSharing"
|
|
390
478
|
Effect = "Deny"
|
|
391
479
|
Action = ["rds:ModifyDBSnapshotAttribute"]
|
|
392
|
-
Resource =
|
|
480
|
+
Resource = local.guardrail_snapshot_sharing_resources
|
|
393
481
|
},
|
|
394
482
|
{
|
|
395
|
-
Sid
|
|
396
|
-
Effect
|
|
397
|
-
Action
|
|
398
|
-
Resource =
|
|
399
|
-
"arn:aws:s3:::{{STATE_BUCKET}}",
|
|
400
|
-
"arn:aws:s3:::{{STATE_BUCKET}}/*",
|
|
401
|
-
]
|
|
483
|
+
Sid = "BoundaryDenyStateDestruction"
|
|
484
|
+
Effect = "Deny"
|
|
485
|
+
Action = ["s3:DeleteBucket", "s3:DeleteObjectVersion"]
|
|
486
|
+
Resource = local.guardrail_state_destruction_resources
|
|
402
487
|
},
|
|
403
488
|
{
|
|
404
|
-
Sid
|
|
405
|
-
Effect
|
|
406
|
-
Action
|
|
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
|
-
]
|
|
489
|
+
Sid = "BoundaryDenyECSShutdown"
|
|
490
|
+
Effect = "Deny"
|
|
491
|
+
Action = ["ecs:UpdateService", "ecs:DeleteService", "ecs:DeleteCluster"]
|
|
492
|
+
Resource = local.guardrail_ecs_shutdown_resources
|
|
412
493
|
},
|
|
413
494
|
{
|
|
414
|
-
Sid
|
|
415
|
-
Effect
|
|
416
|
-
Action
|
|
417
|
-
Resource =
|
|
418
|
-
"arn:aws:ecr:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:repository/${local.prod_prefix}-repo",
|
|
419
|
-
]
|
|
495
|
+
Sid = "BoundaryDenyImageDeletion"
|
|
496
|
+
Effect = "Deny"
|
|
497
|
+
Action = ["ecr:BatchDeleteImage"]
|
|
498
|
+
Resource = local.guardrail_image_deletion_resources
|
|
420
499
|
},
|
|
421
500
|
{
|
|
422
|
-
Sid
|
|
423
|
-
Effect
|
|
424
|
-
Action
|
|
425
|
-
Resource =
|
|
426
|
-
"arn:aws:lambda:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:function:${local.prod_prefix}-fn",
|
|
427
|
-
]
|
|
501
|
+
Sid = "BoundaryDenyLambdaRewrite"
|
|
502
|
+
Effect = "Deny"
|
|
503
|
+
Action = ["lambda:UpdateFunctionCode", "lambda:DeleteFunction"]
|
|
504
|
+
Resource = local.guardrail_lambda_rewrite_resources
|
|
428
505
|
},
|
|
429
506
|
{
|
|
430
|
-
Sid
|
|
431
|
-
Effect
|
|
432
|
-
Action
|
|
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
|
-
]
|
|
507
|
+
Sid = "BoundaryDenyQueueDestruction"
|
|
508
|
+
Effect = "Deny"
|
|
509
|
+
Action = ["sqs:PurgeQueue", "sqs:DeleteQueue"]
|
|
510
|
+
Resource = local.guardrail_queue_destruction_resources
|
|
437
511
|
},
|
|
438
512
|
{
|
|
439
|
-
Sid
|
|
440
|
-
Effect
|
|
441
|
-
Action
|
|
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
|
-
]
|
|
513
|
+
Sid = "BoundaryDenyDatabaseDestruction"
|
|
514
|
+
Effect = "Deny"
|
|
515
|
+
Action = ["rds:DeleteDBInstance", "rds:ModifyDBInstance"]
|
|
516
|
+
Resource = local.guardrail_database_destruction_resources
|
|
446
517
|
},
|
|
447
518
|
{
|
|
448
|
-
Sid
|
|
449
|
-
Effect
|
|
450
|
-
Action
|
|
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
|
-
]
|
|
519
|
+
Sid = "BoundaryDenyAuroraDestruction"
|
|
520
|
+
Effect = "Deny"
|
|
521
|
+
Action = ["rds:DeleteDBCluster", "rds:ModifyDBCluster"]
|
|
522
|
+
Resource = local.guardrail_aurora_destruction_resources
|
|
454
523
|
},
|
|
455
524
|
{
|
|
456
|
-
Sid
|
|
457
|
-
Effect
|
|
458
|
-
Action
|
|
459
|
-
Resource =
|
|
460
|
-
"arn:aws:dynamodb:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:table/${local.prod_prefix}-table",
|
|
461
|
-
]
|
|
525
|
+
Sid = "BoundaryDenyTableDeletion"
|
|
526
|
+
Effect = "Deny"
|
|
527
|
+
Action = ["dynamodb:DeleteTable"]
|
|
528
|
+
Resource = local.guardrail_table_deletion_resources
|
|
462
529
|
},
|
|
463
530
|
{
|
|
464
|
-
Sid
|
|
465
|
-
Effect
|
|
466
|
-
Action
|
|
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
|
-
]
|
|
531
|
+
Sid = "BoundaryDenySnapshotDeletion"
|
|
532
|
+
Effect = "Deny"
|
|
533
|
+
Action = ["rds:DeleteDBSnapshot", "rds:DeleteDBClusterSnapshot"]
|
|
534
|
+
Resource = local.guardrail_snapshot_deletion_resources
|
|
471
535
|
},
|
|
472
536
|
{
|
|
473
|
-
Sid
|
|
474
|
-
Effect
|
|
475
|
-
Action
|
|
476
|
-
Resource =
|
|
477
|
-
|
|
478
|
-
|
|
537
|
+
Sid = "BoundaryDenySecretsDeletion"
|
|
538
|
+
Effect = "Deny"
|
|
539
|
+
Action = ["secretsmanager:DeleteSecret"]
|
|
540
|
+
Resource = local.guardrail_secrets_deletion_resources
|
|
541
|
+
},
|
|
542
|
+
{
|
|
543
|
+
Sid = "BoundaryDenyLogDeletion"
|
|
544
|
+
Effect = "Deny"
|
|
545
|
+
Action = ["logs:DeleteLogGroup"]
|
|
546
|
+
Resource = local.guardrail_log_deletion_resources
|
|
547
|
+
},
|
|
548
|
+
{
|
|
549
|
+
Sid = "BoundaryDenyTaskExecution"
|
|
550
|
+
Effect = "Deny"
|
|
551
|
+
Action = ["ecs:RunTask", "ecs:StopTask", "ecs:ExecuteCommand", "ecs:CreateService"]
|
|
552
|
+
Resource = local.guardrail_task_execution_resources
|
|
553
|
+
},
|
|
554
|
+
{
|
|
555
|
+
Sid = "BoundaryDenyTaskDefinitionRegistration"
|
|
556
|
+
Effect = "Deny"
|
|
557
|
+
Action = ["ecs:RegisterTaskDefinition", "ecs:DeregisterTaskDefinition"]
|
|
558
|
+
Resource = local.guardrail_task_definition_resources
|
|
559
|
+
},
|
|
560
|
+
{
|
|
561
|
+
Sid = "BoundaryDenyPassRole"
|
|
562
|
+
Effect = "Deny"
|
|
563
|
+
Action = ["iam:PassRole"]
|
|
564
|
+
Resource = local.guardrail_app_role_resources
|
|
565
|
+
},
|
|
566
|
+
{
|
|
567
|
+
Sid = "BoundaryDenyAppRoleMutation"
|
|
568
|
+
Effect = "Deny"
|
|
569
|
+
Action = ["iam:AttachRolePolicy", "iam:DetachRolePolicy", "iam:PutRolePolicy", "iam:DeleteRolePolicy", "iam:UpdateAssumeRolePolicy", "iam:DeleteRole"]
|
|
570
|
+
Resource = local.guardrail_app_role_resources
|
|
571
|
+
},
|
|
572
|
+
{
|
|
573
|
+
# BUG-214: carved PassRole may only pass to the ECS tasks
|
|
574
|
+
# service (mirrors the scheduler policy's own condition).
|
|
575
|
+
Sid = "BoundaryDenyPassRoleOffService"
|
|
576
|
+
Effect = "Deny"
|
|
577
|
+
Action = ["iam:PassRole"]
|
|
578
|
+
Resource = "*"
|
|
579
|
+
Condition = {
|
|
580
|
+
StringNotEquals = {
|
|
581
|
+
"iam:PassedToService" = "ecs-tasks.amazonaws.com"
|
|
582
|
+
}
|
|
583
|
+
}
|
|
479
584
|
},
|
|
480
585
|
{
|
|
481
|
-
|
|
586
|
+
# ... and only task roles: preview patterns plus the prod pair
|
|
587
|
+
# (shared local, so renames flow). Preview app names put the
|
|
588
|
+
# workspace between the project and the collision suffix
|
|
589
|
+
# (<project>-pr-<n>-<suffix>), so the preview patterns key off
|
|
590
|
+
# {{PROJECT_NAME}}, not prod_prefix. Prod roles stay
|
|
591
|
+
# scheduler-only via the statement below.
|
|
592
|
+
Sid = "BoundaryDenyPassRoleOffTarget"
|
|
482
593
|
Effect = "Deny"
|
|
483
|
-
Action = ["
|
|
484
|
-
|
|
485
|
-
"arn:aws:
|
|
486
|
-
|
|
594
|
+
Action = ["iam:PassRole"]
|
|
595
|
+
NotResource = concat([
|
|
596
|
+
"arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/{{PROJECT_NAME}}-pr-*-task-role",
|
|
597
|
+
"arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/{{PROJECT_NAME}}-pr-*-execution-role",
|
|
598
|
+
], local.guardrail_app_role_resources)
|
|
599
|
+
},
|
|
600
|
+
{
|
|
601
|
+
# Prod task roles pass only by the prod scheduler role, which
|
|
602
|
+
# passes them at invocation time (its own policy allows only
|
|
603
|
+
# those two roles, so the boundary stays a backstop). Every
|
|
604
|
+
# other capped caller stays denied, and the scheduler itself
|
|
605
|
+
# cannot pass anything outside the four roles above.
|
|
606
|
+
Sid = "BoundaryDenyProdPassRoleOffScheduler"
|
|
607
|
+
Effect = "Deny"
|
|
608
|
+
Action = ["iam:PassRole"]
|
|
609
|
+
Resource = local.guardrail_app_role_resources
|
|
610
|
+
Condition = {
|
|
611
|
+
StringNotEquals = {
|
|
612
|
+
"aws:PrincipalArn" = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/${local.prod_prefix}-cron-scheduler-role"
|
|
613
|
+
}
|
|
614
|
+
}
|
|
487
615
|
},
|
|
488
616
|
]
|
|
489
617
|
})
|