|
| 1 | +package e2e_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "bytes" |
| 5 | + "context" |
| 6 | + "fmt" |
| 7 | + "time" |
| 8 | + |
| 9 | + "github.com/aws/aws-sdk-go-v2/aws" |
| 10 | + "github.com/aws/aws-sdk-go-v2/service/s3" |
| 11 | + . "github.com/onsi/ginkgo/v2" |
| 12 | + . "github.com/onsi/gomega" |
| 13 | +) |
| 14 | + |
| 15 | +var _ = Describe("aclRequired field in access logs", func() { |
| 16 | + var testCtx *E2ETestContext |
| 17 | + |
| 18 | + BeforeEach(func() { |
| 19 | + testCtx = setupE2ETest() |
| 20 | + }) |
| 21 | + |
| 22 | + AfterEach(func() { |
| 23 | + cleanupE2ETest(testCtx) |
| 24 | + }) |
| 25 | + |
| 26 | + It("logs aclRequired as dash for bucket owner requests", func(ctx context.Context) { |
| 27 | + testKey := "acl-owner-test.txt" |
| 28 | + testContent := []byte("owner request test data") |
| 29 | + |
| 30 | + _, err := testCtx.S3Client.PutObject(ctx, &s3.PutObjectInput{ |
| 31 | + Bucket: aws.String(testCtx.SourceBucket), |
| 32 | + Key: aws.String(testKey), |
| 33 | + Body: bytes.NewReader(testContent), |
| 34 | + }) |
| 35 | + Expect(err).NotTo(HaveOccurred(), "PUT should succeed") |
| 36 | + |
| 37 | + resp, err := testCtx.S3Client.GetObject(ctx, &s3.GetObjectInput{ |
| 38 | + Bucket: aws.String(testCtx.SourceBucket), |
| 39 | + Key: aws.String(testKey), |
| 40 | + }) |
| 41 | + Expect(err).NotTo(HaveOccurred(), "GET should succeed") |
| 42 | + _ = resp.Body.Close() |
| 43 | + |
| 44 | + testCtx.VerifyLogs( |
| 45 | + testCtx.ObjectOp("REST.PUT.OBJECT", testKey, 200). |
| 46 | + WithObjectSize(int64(len(testContent))). |
| 47 | + WithACLRequired("-"), |
| 48 | + testCtx.ObjectOp("REST.GET.OBJECT", testKey, 200). |
| 49 | + WithBytesSent(int64(len(testContent))). |
| 50 | + WithObjectSize(int64(len(testContent))). |
| 51 | + WithACLRequired("-"), |
| 52 | + ) |
| 53 | + }) |
| 54 | + |
| 55 | + It("logs aclRequired as Yes for IAM user authorized by ACL", func(ctx context.Context) { |
| 56 | + testKey := "acl-iam-test.txt" |
| 57 | + testContent := []byte("IAM user ACL test data") |
| 58 | + |
| 59 | + // PUT object as bucket owner |
| 60 | + _, err := testCtx.S3Client.PutObject(ctx, &s3.PutObjectInput{ |
| 61 | + Bucket: aws.String(testCtx.SourceBucket), |
| 62 | + Key: aws.String(testKey), |
| 63 | + Body: bytes.NewReader(testContent), |
| 64 | + }) |
| 65 | + Expect(err).NotTo(HaveOccurred(), "PUT should succeed") |
| 66 | + |
| 67 | + // Create IAM user with s3:GetObject permission |
| 68 | + userName := fmt.Sprintf("e2e-acl-test-%d", time.Now().UnixNano()) |
| 69 | + policy := fmt.Sprintf(`{ |
| 70 | + "Version": "2012-10-17", |
| 71 | + "Statement": [{ |
| 72 | + "Effect": "Allow", |
| 73 | + "Action": "s3:GetObject", |
| 74 | + "Resource": "arn:aws:s3:::%s/*" |
| 75 | + }] |
| 76 | + }`, testCtx.SourceBucket) |
| 77 | + iamUser := createIAMUser(ctx, userName, "allow-get-object", policy) |
| 78 | + defer iamUser.Cleanup() |
| 79 | + |
| 80 | + // GET object as the IAM user — authorized via ACL (same account) |
| 81 | + iamS3Client := iamUser.S3Client |
| 82 | + |
| 83 | + resp, err := iamS3Client.GetObject(ctx, &s3.GetObjectInput{ |
| 84 | + Bucket: aws.String(testCtx.SourceBucket), |
| 85 | + Key: aws.String(testKey), |
| 86 | + }) |
| 87 | + Expect(err).NotTo(HaveOccurred(), "GET as IAM user should succeed") |
| 88 | + _ = resp.Body.Close() |
| 89 | + |
| 90 | + logs := testCtx.VerifyLogs( |
| 91 | + testCtx.ObjectOp("REST.PUT.OBJECT", testKey, 200). |
| 92 | + WithObjectSize(int64(len(testContent))). |
| 93 | + WithACLRequired("-"), |
| 94 | + testCtx.ObjectOp("REST.GET.OBJECT", testKey, 200). |
| 95 | + WithBytesSent(int64(len(testContent))). |
| 96 | + WithObjectSize(int64(len(testContent))). |
| 97 | + WithACLRequired("Yes"), |
| 98 | + ) |
| 99 | + |
| 100 | + // Additional verification: the two requests have different requesters |
| 101 | + Expect(logs[0].Requester).NotTo(Equal(logs[1].Requester), |
| 102 | + "PUT (owner) and GET (IAM user) should have different requesters") |
| 103 | + }) |
| 104 | + |
| 105 | + It("logs aclRequired as Yes for both sides of a copy by IAM user", func(ctx context.Context) { |
| 106 | + sourceKey := "acl-copy-source.txt" |
| 107 | + destKey := "acl-copy-dest.txt" |
| 108 | + testContent := []byte("copy test data") |
| 109 | + |
| 110 | + // PUT object as bucket owner |
| 111 | + _, err := testCtx.S3Client.PutObject(ctx, &s3.PutObjectInput{ |
| 112 | + Bucket: aws.String(testCtx.SourceBucket), |
| 113 | + Key: aws.String(sourceKey), |
| 114 | + Body: bytes.NewReader(testContent), |
| 115 | + }) |
| 116 | + Expect(err).NotTo(HaveOccurred(), "PUT should succeed") |
| 117 | + |
| 118 | + // Create IAM user with GetObject + PutObject permissions for the copy |
| 119 | + userName := fmt.Sprintf("e2e-acl-copy-%d", time.Now().UnixNano()) |
| 120 | + policy := fmt.Sprintf(`{ |
| 121 | + "Version": "2012-10-17", |
| 122 | + "Statement": [{ |
| 123 | + "Effect": "Allow", |
| 124 | + "Action": ["s3:GetObject", "s3:PutObject"], |
| 125 | + "Resource": "arn:aws:s3:::%s/*" |
| 126 | + }] |
| 127 | + }`, testCtx.SourceBucket) |
| 128 | + iamUser := createIAMUser(ctx, userName, "allow-copy", policy) |
| 129 | + defer iamUser.Cleanup() |
| 130 | + |
| 131 | + // Copy as IAM user — both source GET and destination PUT go through ACL path |
| 132 | + iamS3Client := iamUser.S3Client |
| 133 | + |
| 134 | + _, err = iamS3Client.CopyObject(ctx, &s3.CopyObjectInput{ |
| 135 | + Bucket: aws.String(testCtx.SourceBucket), |
| 136 | + Key: aws.String(destKey), |
| 137 | + CopySource: aws.String(fmt.Sprintf("%s/%s", testCtx.SourceBucket, sourceKey)), |
| 138 | + }) |
| 139 | + Expect(err).NotTo(HaveOccurred(), "COPY as IAM user should succeed") |
| 140 | + |
| 141 | + testCtx.VerifyLogs( |
| 142 | + testCtx.ObjectOp("REST.PUT.OBJECT", sourceKey, 200). |
| 143 | + WithObjectSize(int64(len(testContent))). |
| 144 | + WithACLRequired("-"), |
| 145 | + testCtx.ObjectOp("REST.COPY.OBJECT_GET", sourceKey, 200). |
| 146 | + WithObjectSize(int64(len(testContent))). |
| 147 | + WithACLRequired("Yes"), |
| 148 | + testCtx.ObjectOp("REST.COPY.OBJECT", destKey, 200). |
| 149 | + WithObjectSize(int64(len(testContent))). |
| 150 | + WithACLRequired("Yes"), |
| 151 | + ) |
| 152 | + }) |
| 153 | +}) |
0 commit comments