Skip to content

Commit 12a934a

Browse files
committed
fix(operator): support private VPC S3 endpoints in Loki operator
1 parent 37eddab commit 12a934a

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

operator/internal/handlers/internal/storage/secrets.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -506,10 +506,20 @@ func validateS3Endpoint(endpoint string, region string) error {
506506
return fmt.Errorf("%w: %s", errSecretMissingField, storage.KeyAWSRegion)
507507
}
508508

509+
// Check if it's a standard AWS S3 endpoint
509510
validEndpoint := fmt.Sprintf("https://s3.%s%s", region, awsEndpointSuffix)
510-
if endpoint != validEndpoint {
511-
return fmt.Errorf("%w: %s", errS3EndpointAWSInvalid, validEndpoint)
511+
if endpoint == validEndpoint {
512+
return nil
512513
}
514+
515+
// Check if it's a VPC endpoint format: https://bucket.vpce-*-region.s3.region.vpce.amazonaws.com
516+
// or https://vpce-*-region.s3.region.vpce.amazonaws.com
517+
if strings.Contains(endpoint, ".vpce.amazonaws.com") && strings.Contains(endpoint, region) {
518+
return nil
519+
}
520+
521+
// If neither standard nor VPC endpoint format, return error
522+
return fmt.Errorf("%w: %s", errS3EndpointAWSInvalid, validEndpoint)
513523
}
514524
return nil
515525
}

operator/internal/handlers/internal/storage/secrets_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,44 @@ func TestS3Extract_ForcePathStyle(t *testing.T) {
719719
ForcePathStyle: true,
720720
},
721721
},
722+
{
723+
desc: "aws s3 vpc endpoint",
724+
secret: &corev1.Secret{
725+
ObjectMeta: metav1.ObjectMeta{Name: "test"},
726+
Data: map[string][]byte{
727+
"endpoint": []byte("https://bucket.vpce-1234567-us-east-1c.s3.us-east-1.vpce.amazonaws.com"),
728+
"region": []byte("us-east-1"),
729+
"bucketnames": []byte("this,that"),
730+
"access_key_id": []byte("id"),
731+
"access_key_secret": []byte("secret"),
732+
},
733+
},
734+
wantOptions: &storage.S3StorageConfig{
735+
Endpoint: "https://bucket.vpce-1234567-us-east-1c.s3.us-east-1.vpce.amazonaws.com",
736+
Region: "us-east-1",
737+
Buckets: "this,that",
738+
ForcePathStyle: false,
739+
},
740+
},
741+
{
742+
desc: "aws s3 vpc endpoint without bucket prefix",
743+
secret: &corev1.Secret{
744+
ObjectMeta: metav1.ObjectMeta{Name: "test"},
745+
Data: map[string][]byte{
746+
"endpoint": []byte("https://vpce-1234567-us-east-1c.s3.us-east-1.vpce.amazonaws.com"),
747+
"region": []byte("us-east-1"),
748+
"bucketnames": []byte("this,that"),
749+
"access_key_id": []byte("id"),
750+
"access_key_secret": []byte("secret"),
751+
},
752+
},
753+
wantOptions: &storage.S3StorageConfig{
754+
Endpoint: "https://vpce-1234567-us-east-1c.s3.us-east-1.vpce.amazonaws.com",
755+
Region: "us-east-1",
756+
Buckets: "this,that",
757+
ForcePathStyle: false,
758+
},
759+
},
722760
{
723761
desc: "invalid forcepathstyle value",
724762
secret: &corev1.Secret{

0 commit comments

Comments
 (0)