|
| 1 | +package e2e_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "bytes" |
| 5 | + "context" |
| 6 | + "crypto/tls" |
| 7 | + "net" |
| 8 | + "net/http" |
| 9 | + "os" |
| 10 | + "time" |
| 11 | + |
| 12 | + "github.com/aws/aws-sdk-go-v2/aws" |
| 13 | + "github.com/aws/aws-sdk-go-v2/service/s3" |
| 14 | + . "github.com/onsi/ginkgo/v2" |
| 15 | + . "github.com/onsi/gomega" |
| 16 | +) |
| 17 | + |
| 18 | +const ( |
| 19 | + testS3FrontendEndpoint = "https://127.0.0.1:443" |
| 20 | +) |
| 21 | + |
| 22 | +func newTLSS3Client(accessKeyID, secretAccessKey, endpoint string) *s3.Client { |
| 23 | + transport := &http.Transport{ |
| 24 | + DialContext: (&net.Dialer{ |
| 25 | + Timeout: 10 * time.Second, |
| 26 | + }).DialContext, |
| 27 | + TLSClientConfig: &tls.Config{ |
| 28 | + InsecureSkipVerify: true, //nolint:gosec // self-signed cert in test environment |
| 29 | + }, |
| 30 | + TLSHandshakeTimeout: 10 * time.Second, |
| 31 | + } |
| 32 | + |
| 33 | + return s3.NewFromConfig(aws.Config{ |
| 34 | + Region: testRegion, |
| 35 | + Credentials: aws.CredentialsProviderFunc(func(ctx context.Context) (aws.Credentials, error) { |
| 36 | + return aws.Credentials{ |
| 37 | + AccessKeyID: accessKeyID, |
| 38 | + SecretAccessKey: secretAccessKey, |
| 39 | + }, nil |
| 40 | + }), |
| 41 | + HTTPClient: &http.Client{Transport: transport}, |
| 42 | + }, func(o *s3.Options) { |
| 43 | + o.BaseEndpoint = aws.String(endpoint) |
| 44 | + o.UsePathStyle = true |
| 45 | + }) |
| 46 | +} |
| 47 | + |
| 48 | +var _ = Describe("TLS fields in access logs", func() { |
| 49 | + var testCtx *E2ETestContext |
| 50 | + |
| 51 | + BeforeEach(func() { |
| 52 | + testCtx = setupE2ETest() |
| 53 | + }) |
| 54 | + |
| 55 | + AfterEach(func() { |
| 56 | + cleanupE2ETest(testCtx) |
| 57 | + }) |
| 58 | + |
| 59 | + It("logs CipherSuite and TLSVersion for requests through the S3 frontend", func(ctx context.Context) { |
| 60 | + endpoint := os.Getenv("E2E_S3_FRONTEND_ENDPOINT") |
| 61 | + if endpoint == "" { |
| 62 | + endpoint = testS3FrontendEndpoint |
| 63 | + } |
| 64 | + |
| 65 | + accessKey := os.Getenv("E2E_S3_ACCESS_KEY_ID") |
| 66 | + if accessKey == "" { |
| 67 | + accessKey = testAccessKeyID |
| 68 | + } |
| 69 | + |
| 70 | + secretKey := os.Getenv("E2E_S3_SECRET_ACCESS_KEY") |
| 71 | + if secretKey == "" { |
| 72 | + secretKey = testSecretAccessKey |
| 73 | + } |
| 74 | + |
| 75 | + tlsClient := newTLSS3Client(accessKey, secretKey, endpoint) |
| 76 | + |
| 77 | + testKey := "tls-test-object.txt" |
| 78 | + testContent := []byte("test data for TLS field verification") |
| 79 | + |
| 80 | + _, err := tlsClient.PutObject(ctx, &s3.PutObjectInput{ |
| 81 | + Bucket: aws.String(testCtx.SourceBucket), |
| 82 | + Key: aws.String(testKey), |
| 83 | + Body: bytes.NewReader(testContent), |
| 84 | + }) |
| 85 | + Expect(err).NotTo(HaveOccurred(), "PUT through S3 frontend should succeed") |
| 86 | + |
| 87 | + _, err = tlsClient.GetObject(ctx, &s3.GetObjectInput{ |
| 88 | + Bucket: aws.String(testCtx.SourceBucket), |
| 89 | + Key: aws.String(testKey), |
| 90 | + }) |
| 91 | + Expect(err).NotTo(HaveOccurred(), "GET through S3 frontend should succeed") |
| 92 | + |
| 93 | + logs := testCtx.VerifyLogs( |
| 94 | + testCtx.ObjectOp("REST.PUT.OBJECT", testKey, 200).WithObjectSize(int64(len(testContent))), |
| 95 | + testCtx.ObjectOp("REST.GET.OBJECT", testKey, 200).WithBytesSent(int64(len(testContent))).WithObjectSize(int64(len(testContent))), |
| 96 | + ) |
| 97 | + |
| 98 | + for _, log := range logs { |
| 99 | + Expect(log.CipherSuite).NotTo(Equal("-"), |
| 100 | + "CipherSuite should be populated for TLS requests (got '-')") |
| 101 | + Expect(log.CipherSuite).NotTo(BeEmpty(), |
| 102 | + "CipherSuite should not be empty for TLS requests") |
| 103 | + |
| 104 | + Expect(log.TLSVersion).NotTo(Equal("-"), |
| 105 | + "TLSVersion should be populated for TLS requests (got '-')") |
| 106 | + Expect(log.TLSVersion).NotTo(BeEmpty(), |
| 107 | + "TLSVersion should not be empty for TLS requests") |
| 108 | + Expect(log.TLSVersion).To(MatchRegexp(`^TLSv1\.[23]$`), |
| 109 | + "TLSVersion should be TLSv1.2 or TLSv1.3") |
| 110 | + } |
| 111 | + }) |
| 112 | +}) |
0 commit comments