Skip to content

Commit 4836043

Browse files
committed
LOGC-48: Add bucket policy for cross-account S3 access in E2E tests
Configure PutObject permission for service-access-logging-user on destination buckets. Required for Integration environment where the bucket owner account differs from the service user account.
1 parent f4c8327 commit 4836043

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

test/e2e/helpers_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,32 @@ func configureBucketLogging(client *s3.Client, sourceBucket, targetBucket, prefi
122122
return err
123123
}
124124

125+
// configureBucketPolicyForCrossAccountAccess sets up a bucket policy granting
126+
// PutObject permission to the service-access-logging-user. Required for cross-account
127+
// access in Integration environments.
128+
func configureBucketPolicyForCrossAccountAccess(client *s3.Client, bucket string) error {
129+
policy := fmt.Sprintf(`{
130+
"Version": "2012-10-17",
131+
"Statement": [
132+
{
133+
"Sid": "AllowCrossAccountPutObject",
134+
"Effect": "Allow",
135+
"Principal": {
136+
"AWS": "arn:aws:iam::000000000000:user/scality-internal/service-access-logging-user"
137+
},
138+
"Action": "s3:PutObject",
139+
"Resource": "arn:aws:s3:::%s/*"
140+
}
141+
]
142+
}`, bucket)
143+
144+
_, err := client.PutBucketPolicy(context.Background(), &s3.PutBucketPolicyInput{
145+
Bucket: aws.String(bucket),
146+
Policy: aws.String(policy),
147+
})
148+
return err
149+
}
150+
125151
// findLogObjectsSince finds all log objects in a bucket created after a given time
126152
// returns the list of object keys that were created after the given time
127153
func findLogObjectsSince(client *s3.Client, bucket, prefix string, since time.Time) ([]string, error) {
@@ -412,6 +438,10 @@ func setupE2ETest() *E2ETestContext {
412438
err = configureBucketLogging(sharedS3Client, sourceBucket, destBucket, logPrefix)
413439
Expect(err).NotTo(HaveOccurred(), "Failed to configure bucket logging")
414440

441+
// Configure bucket policy for cross-account access
442+
err = configureBucketPolicyForCrossAccountAccess(sharedS3Client, destBucket)
443+
Expect(err).NotTo(HaveOccurred(), "Failed to configure bucket policy")
444+
415445
return &E2ETestContext{
416446
TestName: testName,
417447
S3Client: sharedS3Client,

0 commit comments

Comments
 (0)