Skip to content

Commit 8581dad

Browse files
lsjostrofrezbo
authored andcommitted
fix: need signing region for custom s3 endpoint
Set the signing region properly. Signed-off-by: Noel Georgi <[email protected]>
1 parent c9d9843 commit 8581dad

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

cmd/talos-backup/service/service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func BackupEncryptedSnapshot(ctx context.Context, serviceConfig *config.ServiceC
4040

4141
defer util.CleanupFile(encryptedFileName)
4242

43-
client, err := s3.CreateClientWithCustomEndpoint(ctx, serviceConfig.CustomS3Endpoint)
43+
client, err := s3.CreateClientWithCustomEndpoint(ctx, serviceConfig)
4444
if err != nil {
4545
return fmt.Errorf("failed to create S3 client: %w", err)
4646
}

pkg/config/service.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
type ServiceConfig struct {
1414
CustomS3Endpoint string `yaml:"customS3Endpoint"`
1515
Bucket string `yaml:"bucket"`
16+
Region string `yaml:"region"`
1617
S3Prefix string `yaml:"s3Prefix"`
1718
ClusterName string `yaml:"clusterName"`
1819
AgeX25519PublicKey string `yaml:"ageX25519PublicKey"`
@@ -21,6 +22,7 @@ type ServiceConfig struct {
2122
const (
2223
customS3EndpointEnvVar = "CUSTOM_S3_ENDPOINT"
2324
bucketEnvVar = "BUCKET"
25+
regionEnvVar = "AWS_REGION"
2426
s3PrefixEnvVar = "S3_PREFIX"
2527
clusterNameEnvVar = "CLUSTER_NAME"
2628
ageX25519PublicKeyEnvVar = "AGE_X25519_PUBLIC_KEY"
@@ -31,6 +33,7 @@ func GetServiceConfig() *ServiceConfig {
3133
return &ServiceConfig{
3234
CustomS3Endpoint: os.Getenv(customS3EndpointEnvVar),
3335
Bucket: os.Getenv(bucketEnvVar),
36+
Region: os.Getenv(regionEnvVar),
3437
S3Prefix: os.Getenv(s3PrefixEnvVar),
3538
ClusterName: os.Getenv(clusterNameEnvVar),
3639
AgeX25519PublicKey: os.Getenv(ageX25519PublicKeyEnvVar),

pkg/s3/s3.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,19 @@ func CreateClient(ctx context.Context, conf buconfig.S3Info) (*s3.Client, error)
3333

3434
// CreateClientWithCustomEndpoint returns an S3 client that loads the default AWS configuration.
3535
// You may optionally specify `customS3Endpoint` for a custom S3 API endpoint.
36-
func CreateClientWithCustomEndpoint(ctx context.Context, customS3Endpoint string) (*s3.Client, error) {
37-
cfg, err := config.LoadDefaultConfig(ctx)
36+
func CreateClientWithCustomEndpoint(ctx context.Context, svcConf *buconfig.ServiceConfig) (*s3.Client, error) {
37+
cfg, err := config.LoadDefaultConfig(ctx, config.WithRegion(svcConf.Region))
3838
if err != nil {
3939
return nil, fmt.Errorf("failed to load AWS configuration: %w", err)
4040
}
4141

42-
if customS3Endpoint != "" {
42+
if svcConf.CustomS3Endpoint != "" {
4343
cfg.EndpointResolverWithOptions = aws.EndpointResolverWithOptionsFunc(func(service, region string, options ...interface{}) (aws.Endpoint, error) {
4444
if true {
4545
return aws.Endpoint{
46-
URL: customS3Endpoint,
46+
URL: svcConf.CustomS3Endpoint,
4747
HostnameImmutable: true,
48+
SigningRegion: svcConf.Region,
4849
}, nil
4950
}
5051

0 commit comments

Comments
 (0)