infra: expire media-results/ and let the console delete its versions
The deployment bucket's lifecycle gains two rules for media-results/ (objects and noncurrent versions after a day, expired delete markers), joining the existing rules in the one configuration resource. The console's media policy gains s3:ListBucketVersions on the deployment bucket held to s3:prefix media-results/*, and s3:DeleteObjectVersion on media-results/* only. tofu tests assert both and that the existing rules are unchanged. The MinIO contract step versions the results bucket and grants the local runner's user the version calls.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5 files changed,
+178
−3
.amadan/ci.d/30-minio-contract+7 −1infra/modules/deployment-buckets/main.tf+44 −2infra/modules/deployment-buckets/tests/media_results.tftest.hcl+100 −0infra/modules/media-engine/iam.tf+19 −0infra/modules/media-engine/tests/media_engine.tftest.hcl+8 −0
diff --git a/.amadan/ci.d/30-minio-contract b/.amadan/ci.d/30-minio-contract| index 368646662..4f7ea9c0b 100755 |
| --- a/.amadan/ci.d/30-minio-contract |
| +++ b/.amadan/ci.d/30-minio-contract |
| @@ -553,6 +553,10 @@ fi |
| # it looks for the bucket, so the user is allowed that one delete and the |
| # test can see NoSuchBucket rather than a denial. |
| "$mc" --quiet mb local/media-transfers local/media-transfer-results |
| +# Versioned, as the deployment bucket the results live in is: the test |
| +# replays drills F1 and F2 (a delete leaves a marker, a create-only PUT |
| +# succeeds over it) and checks the cleanup removes every version. |
| +"$mc" --quiet version enable local/media-transfer-results |
| cat >"$rundir/media-transfers.json" <<'EOF' |
| {"Version": "2012-10-17", "Statement": [ |
| {"Effect": "Allow", "Action": ["s3:*"], "Resource": [ |
| @@ -602,9 +606,11 @@ cat >"$rundir/media-local.json" <<'EOF' |
| {"Effect": "Allow", "Action": ["s3:ListBucket"], "Resource": [ |
| "arn:aws:s3:::media-local-store", "arn:aws:s3:::media-local-results" |
| ]}, |
| + {"Effect": "Allow", "Action": ["s3:ListBucketVersions"], "Resource": ["arn:aws:s3:::media-local-results"]}, |
| {"Effect": "Allow", "Action": ["s3:GetObject", "s3:PutObject", "s3:DeleteObject"], "Resource": [ |
| "arn:aws:s3:::media-local-store/*", "arn:aws:s3:::media-local-results/*" |
| - ]} |
| + ]}, |
| + {"Effect": "Allow", "Action": ["s3:DeleteObjectVersion"], "Resource": ["arn:aws:s3:::media-local-results/media-results/*"]} |
| ]} |
| EOF |
| "$mc" --quiet admin policy create local media-local "$rundir/media-local.json" |
diff --git a/infra/modules/deployment-buckets/main.tf b/infra/modules/deployment-buckets/main.tf| index 625635b54..240166d7a 100644 |
| --- a/infra/modules/deployment-buckets/main.tf |
| +++ b/infra/modules/deployment-buckets/main.tf |
| @@ -29,8 +29,12 @@ resource "aws_s3_bucket_versioning" "deployment" { |
| # or superseded blob under control/geoip/ must not live on as a noncurrent |
| # version, because MaxMind's GeoLite EULA requires destroying superseded |
| # editions. Forwarded db reads (db region forward spec §5.7, J4): every |
| -# object under db-reads/ expires. Each rule is scoped to its own prefix; |
| -# nothing else in this bucket expires. |
| +# object under db-reads/ expires. Media conversion results (video conversion |
| +# spec §11 A8): every object under media-results/ expires. Each rule is |
| +# scoped to its own prefix; nothing else in this bucket expires. This is the |
| +# bucket's only lifecycle configuration: S3 replaces the whole configuration |
| +# on every write, so a rule for this bucket joins this resource and never |
| +# gets one of its own. |
| resource "aws_s3_bucket_lifecycle_configuration" "deployment" { |
| bucket = aws_s3_bucket.deployment.id |
| @@ -84,6 +88,44 @@ resource "aws_s3_bucket_lifecycle_configuration" "deployment" { |
| } |
| } |
| + # Media conversion results (video conversion spec §5.4, §11 A8): the |
| + # console reads media-results/<execution>.json once, within its job's |
| + # grant and ECS's record retention, and its cleanup deletes every version |
| + # of it. These rules are the backstop for anything cleanup missed: a |
| + # result written for an execution whose row was never cleaned, or one a |
| + # cleanup failed to reach. Each object expires a day after it is written, |
| + # each noncurrent version a day after it becomes noncurrent, and expired |
| + # delete markers go. On for every deployment: nothing but the media |
| + # engine writes under this prefix, so where media is off the rules match |
| + # nothing, and a switch would only be a way to run media without them. |
| + rule { |
| + id = "media-results-expire" |
| + status = "Enabled" |
| + filter { |
| + prefix = "media-results/" |
| + } |
| + expiration { |
| + days = 1 |
| + } |
| + noncurrent_version_expiration { |
| + noncurrent_days = 1 |
| + } |
| + abort_incomplete_multipart_upload { |
| + days_after_initiation = 1 |
| + } |
| + } |
| + |
| + rule { |
| + id = "media-results-delete-markers" |
| + status = "Enabled" |
| + filter { |
| + prefix = "media-results/" |
| + } |
| + expiration { |
| + expired_object_delete_marker = true |
| + } |
| + } |
| + |
| depends_on = [aws_s3_bucket_versioning.deployment] |
| } |
diff --git a/infra/modules/deployment-buckets/tests/media_results.tftest.hcl b/infra/modules/deployment-buckets/tests/media_results.tftest.hcl| new file mode 100644 |
| index 000000000..b911e088f |
| --- /dev/null |
| +++ b/infra/modules/deployment-buckets/tests/media_results.tftest.hcl |
| @@ -0,0 +1,100 @@ |
| +# Video conversion spec §11 A8 (drills F1, F2): the deployment bucket |
| +# expires everything under media-results/: current versions a day after |
| +# they are written, noncurrent versions a day after they become noncurrent, |
| +# and expired delete markers. The console's cleanup deletes every version; |
| +# these rules are the backstop. S3 replaces a bucket's whole lifecycle |
| +# configuration on every write, so the rules join the one resource and |
| +# every rule that was there stays exactly as it was. |
| + |
| +mock_provider "aws" {} |
| + |
| +variables { |
| + deployment_bucket_name = "dep" |
| + data_bucket_name = "data" |
| +} |
| + |
| +run "media_results_expire_with_their_versions_and_markers" { |
| + command = plan |
| + |
| + assert { |
| + condition = length([ |
| + for r in aws_s3_bucket_lifecycle_configuration.deployment.rule : r |
| + if r.id == "media-results-expire" && r.status == "Enabled" && |
| + one(r.filter).prefix == "media-results/" && |
| + one(r.expiration).days == 1 && |
| + one(r.noncurrent_version_expiration).noncurrent_days == 1 && |
| + one(r.abort_incomplete_multipart_upload).days_after_initiation == 1 |
| + ]) == 1 |
| + error_message = "media-results/ must expire current versions after 1 day and noncurrent versions 1 day after they become noncurrent" |
| + } |
| + |
| + assert { |
| + condition = length([ |
| + for r in aws_s3_bucket_lifecycle_configuration.deployment.rule : r |
| + if r.id == "media-results-delete-markers" && r.status == "Enabled" && |
| + one(r.filter).prefix == "media-results/" && |
| + one(r.expiration).expired_object_delete_marker == true && |
| + length(r.noncurrent_version_expiration) == 0 |
| + ]) == 1 |
| + error_message = "media-results/ must remove expired delete markers" |
| + } |
| +} |
| + |
| +run "the_existing_rules_are_unchanged" { |
| + command = plan |
| + |
| + assert { |
| + condition = ( |
| + length(aws_s3_bucket_lifecycle_configuration.deployment.rule) == 5 && |
| + toset([for r in aws_s3_bucket_lifecycle_configuration.deployment.rule : r.id]) == toset([ |
| + "geoip-noncurrent", "db-reads-expire", "db-reads-delete-markers", |
| + "media-results-expire", "media-results-delete-markers", |
| + ]) |
| + ) |
| + error_message = "the deployment bucket's lifecycle holds exactly the geoip, db-reads and media-results rules" |
| + } |
| + |
| + assert { |
| + condition = length([ |
| + for r in aws_s3_bucket_lifecycle_configuration.deployment.rule : r |
| + if r.id == "geoip-noncurrent" && r.status == "Enabled" && |
| + one(r.filter).prefix == "control/geoip/" && |
| + length(r.expiration) == 0 && |
| + one(r.noncurrent_version_expiration).noncurrent_days == 1 && |
| + one(r.abort_incomplete_multipart_upload).days_after_initiation == 1 |
| + ]) == 1 |
| + error_message = "the control/geoip/ rule must stay as it was" |
| + } |
| + |
| + assert { |
| + condition = length([ |
| + for r in aws_s3_bucket_lifecycle_configuration.deployment.rule : r |
| + if r.id == "db-reads-expire" && r.status == "Enabled" && |
| + one(r.filter).prefix == "db-reads/" && |
| + one(r.expiration).days == 1 && |
| + one(r.noncurrent_version_expiration).noncurrent_days == 1 && |
| + one(r.abort_incomplete_multipart_upload).days_after_initiation == 1 |
| + ]) == 1 |
| + error_message = "the db-reads/ expiry rule must stay as it was" |
| + } |
| + |
| + assert { |
| + condition = length([ |
| + for r in aws_s3_bucket_lifecycle_configuration.deployment.rule : r |
| + if r.id == "db-reads-delete-markers" && r.status == "Enabled" && |
| + one(r.filter).prefix == "db-reads/" && |
| + one(r.expiration).expired_object_delete_marker == true |
| + ]) == 1 |
| + error_message = "the db-reads/ delete-marker rule must stay as it was" |
| + } |
| + |
| + # The data bucket's configuration is its own resource and keeps its one |
| + # rule. |
| + assert { |
| + condition = ( |
| + length(aws_s3_bucket_lifecycle_configuration.data.rule) == 1 && |
| + one(aws_s3_bucket_lifecycle_configuration.data.rule).id == "expire-noncurrent" |
| + ) |
| + error_message = "the data bucket's lifecycle must stay as it was" |
| + } |
| +} |
diff --git a/infra/modules/media-engine/iam.tf b/infra/modules/media-engine/iam.tf| index eb63af0b3..c6bbef269 100644 |
| --- a/infra/modules/media-engine/iam.tf |
| +++ b/infra/modules/media-engine/iam.tf |
| @@ -155,6 +155,25 @@ resource "aws_iam_policy" "console" { |
| Action = "s3:ListBucket" |
| Resource = "arn:aws:s3:::${var.deployment_bucket_name}" |
| }, |
| + { |
| + # The deployment bucket is versioned, so a plain delete of a result |
| + # leaves it as a noncurrent version under a delete marker (drills |
| + # F1, F2). Cleanup lists the one key's versions, with the exact key |
| + # as the prefix, and deletes each by version id (spec §11 A8). The |
| + # listing is held to media-results/; S3 checks s3:prefix against |
| + # the request's prefix, which is the key itself. |
| + Sid = "ListResultVersions" |
| + Effect = "Allow" |
| + Action = "s3:ListBucketVersions" |
| + Resource = "arn:aws:s3:::${var.deployment_bucket_name}" |
| + Condition = { StringLike = { "s3:prefix" = "media-results/*" } } |
| + }, |
| + { |
| + Sid = "DeleteResultVersions" |
| + Effect = "Allow" |
| + Action = "s3:DeleteObjectVersion" |
| + Resource = local.results_objects |
| + }, |
| ] |
| }) |
| } |
diff --git a/infra/modules/media-engine/tests/media_engine.tftest.hcl b/infra/modules/media-engine/tests/media_engine.tftest.hcl| index 7a19f7ce0..7910311cd 100644 |
| --- a/infra/modules/media-engine/tests/media_engine.tftest.hcl |
| +++ b/infra/modules/media-engine/tests/media_engine.tftest.hcl |
| @@ -589,6 +589,14 @@ run "console_policy_exact" { |
| Sid = "PassExecutionRole" |
| }, |
| { Action = "s3:ListBucket", Effect = "Allow", Resource = "arn:aws:s3:::carlos-test-deployment", Sid = "ListResults" }, |
| + { |
| + Action = "s3:ListBucketVersions" |
| + Condition = { StringLike = { "s3:prefix" = "media-results/*" } } |
| + Effect = "Allow" |
| + Resource = "arn:aws:s3:::carlos-test-deployment" |
| + Sid = "ListResultVersions" |
| + }, |
| + { Action = "s3:DeleteObjectVersion", Effect = "Allow", Resource = "arn:aws:s3:::carlos-test-deployment/media-results/*", Sid = "DeleteResultVersions" }, |
| ]) |
| error_message = "the console's grants, exactly" |
| } |