Skip to content

Commit 0084262

Browse files
authored
fix(operator): Configure Loki to use virtual-host-style URLs for S3 AWS endpoints (#12469)
1 parent 2e32ec5 commit 0084262

File tree

6 files changed

+155
-77
lines changed

6 files changed

+155
-77
lines changed

operator/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## Main
22

3+
- [12469](https://github.com/grafana/loki/pull/12469) **btaani**: Configure Loki to use virtual-host-style URLs for S3 AWS endpoints
34
- [12181](https://github.com/grafana/loki/pull/12181) **btaani**: Improve validation of provided S3 storage configuration
45
- [12370](https://github.com/grafana/loki/pull/12370) **periklis**: Update Loki operand to v2.9.6
56
- [12333](https://github.com/grafana/loki/pull/12333) **periklis**: Bump max OpenShift version to next release

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

+6-4
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,8 @@ func extractS3ConfigSecret(s *corev1.Secret, credentialMode lokiv1.CredentialMod
404404
roleArn = s.Data[storage.KeyAWSRoleArn]
405405
audience = s.Data[storage.KeyAWSAudience]
406406
// Optional fields
407-
region = s.Data[storage.KeyAWSRegion]
407+
region = s.Data[storage.KeyAWSRegion]
408+
forcePathStyle = !strings.HasSuffix(string(endpoint), awsEndpointSuffix)
408409
)
409410

410411
sseCfg, err := extractS3SSEConfig(s.Data)
@@ -413,9 +414,10 @@ func extractS3ConfigSecret(s *corev1.Secret, credentialMode lokiv1.CredentialMod
413414
}
414415

415416
cfg := &storage.S3StorageConfig{
416-
Buckets: string(buckets),
417-
Region: string(region),
418-
SSE: sseCfg,
417+
Buckets: string(buckets),
418+
Region: string(region),
419+
SSE: sseCfg,
420+
ForcePathStyle: forcePathStyle,
419421
}
420422

421423
switch credentialMode {

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

+57
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
configv1 "github.com/grafana/loki/operator/apis/config/v1"
1111
lokiv1 "github.com/grafana/loki/operator/apis/loki/v1"
12+
"github.com/grafana/loki/operator/internal/manifests/storage"
1213
)
1314

1415
func TestHashSecretData(t *testing.T) {
@@ -617,6 +618,62 @@ func TestS3Extract(t *testing.T) {
617618
}
618619
}
619620

621+
func TestS3Extract_S3ForcePathStyle(t *testing.T) {
622+
tt := []struct {
623+
desc string
624+
secret *corev1.Secret
625+
wantOptions *storage.S3StorageConfig
626+
}{
627+
{
628+
desc: "aws s3 endpoint",
629+
secret: &corev1.Secret{
630+
ObjectMeta: metav1.ObjectMeta{Name: "test"},
631+
Data: map[string][]byte{
632+
"endpoint": []byte("https://s3.region.amazonaws.com"),
633+
"region": []byte("region"),
634+
"bucketnames": []byte("this,that"),
635+
"access_key_id": []byte("id"),
636+
"access_key_secret": []byte("secret"),
637+
},
638+
},
639+
wantOptions: &storage.S3StorageConfig{
640+
Endpoint: "https://s3.region.amazonaws.com",
641+
Region: "region",
642+
Buckets: "this,that",
643+
},
644+
},
645+
{
646+
desc: "non-aws s3 endpoint",
647+
secret: &corev1.Secret{
648+
ObjectMeta: metav1.ObjectMeta{Name: "test"},
649+
Data: map[string][]byte{
650+
"endpoint": []byte("https://test.default.svc.cluster.local:9000"),
651+
"region": []byte("region"),
652+
"bucketnames": []byte("this,that"),
653+
"access_key_id": []byte("id"),
654+
"access_key_secret": []byte("secret"),
655+
},
656+
},
657+
wantOptions: &storage.S3StorageConfig{
658+
Endpoint: "https://test.default.svc.cluster.local:9000",
659+
Region: "region",
660+
Buckets: "this,that",
661+
ForcePathStyle: true,
662+
},
663+
},
664+
}
665+
666+
for _, tc := range tt {
667+
tc := tc
668+
t.Run(tc.desc, func(t *testing.T) {
669+
t.Parallel()
670+
options, err := extractS3ConfigSecret(tc.secret, lokiv1.CredentialModeStatic)
671+
require.NoError(t, err)
672+
require.Equal(t, tc.wantOptions, options)
673+
})
674+
}
675+
}
676+
620677
func TestS3Extract_WithOpenShiftTokenCCOAuth(t *testing.T) {
621678
fg := configv1.FeatureGates{
622679
OpenShift: configv1.OpenShiftFeatureGates{

0 commit comments

Comments
 (0)