carlos / platform Public

awsmanaged: keep refusing a lifecycle rule with the legacy Prefix

LifecycleRule.Prefix is deprecated, but S3 can still return it on a
rule written long ago. isFleetLifecycleRule has to read it: a rule
scoped to a prefix does not cover the whole bucket, so it is not the
fleet's rule and must not be accepted as one.

The new case in TestAWSFleetBucketContract fails if the check goes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 547b45c699ec02108cdd485c558e5f59e47a8bd6 parent ecf8fa5
2 files changed, +7 −0
  • internal/awsmanaged/storage.go +1 −0
  • internal/awsmanaged/storage_test.go +6 −0
diff --git a/internal/awsmanaged/storage.go b/internal/awsmanaged/storage.go
index fee899674..da47174fb 100644
--- a/internal/awsmanaged/storage.go
+++ b/internal/awsmanaged/storage.go
@@ -428,6 +428,7 @@ func fleetLifecycleRule() s3types.LifecycleRule {
// S3 reads it back (an empty filter may come back with or without Prefix).
func isFleetLifecycleRule(r s3types.LifecycleRule) bool {
f := r.Filter
+ //lint:ignore SA1019 S3 can still return a rule scoped by the legacy Prefix, and such a rule does not cover the whole bucket
return aws.ToString(r.ID) == lifecycleRuleID && r.Status == s3types.ExpirationStatusEnabled && r.Prefix == nil &&
f != nil && f.And == nil && f.Tag == nil && f.ObjectSizeGreaterThan == nil && f.ObjectSizeLessThan == nil && aws.ToString(f.Prefix) == "" &&
r.Expiration == nil && len(r.Transitions) == 0 && len(r.NoncurrentVersionTransitions) == 0 &&
diff --git a/internal/awsmanaged/storage_test.go b/internal/awsmanaged/storage_test.go
index 85d9c1108..b56b46bb4 100644
--- a/internal/awsmanaged/storage_test.go
+++ b/internal/awsmanaged/storage_test.go
@@ -550,6 +550,12 @@ func TestAWSFleetBucketContract(t *testing.T) {
r.NoncurrentVersionExpiration = &s3types.NoncurrentVersionExpiration{NoncurrentDays: aws.Int32(30)}
w.buckets[b] = &fakeBucket{region: testRegion, owner: testAccount, tags: ownTags(testFleet), rules: []s3types.LifecycleRule{r}}
}},
+ "our rule scoped by the legacy top-level prefix": {testRegion, func(w *fakeS3World, b string) {
+ r := fleetLifecycleRule()
+ //lint:ignore SA1019 S3 can still return this field, and the rule that sets it is not ours
+ r.Prefix = aws.String("logs/")
+ w.buckets[b] = &fakeBucket{region: testRegion, owner: testAccount, tags: ownTags(testFleet), rules: []s3types.LifecycleRule{r}}
+ }},
"our rule plus another": {testRegion, func(w *fakeS3World, b string) {
w.buckets[b] = &fakeBucket{region: testRegion, owner: testAccount, tags: ownTags(testFleet), rules: []s3types.LifecycleRule{fleetLifecycleRule(),
{ID: aws.String("x"), Status: s3types.ExpirationStatusDisabled, Filter: &s3types.LifecycleRuleFilter{}}}}