Skip to content

Commit 4a23eaf

Browse files
authored
Fix validating non-AWS S3-compatible stores (#1021)
* Fix validating non-AWS S3-compatible stores
1 parent 7f7de2b commit 4a23eaf

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

cmd/embedded-cluster/restore.go

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
_ "embed"
66
"encoding/json"
77
"fmt"
8+
"net/url"
89
"os"
910
"path/filepath"
1011
"strings"
@@ -269,13 +270,19 @@ func newS3BackupStore() *s3BackupStore {
269270
// validateS3BackupStore validates the S3 backup store configuration.
270271
// It tries to list objects in the bucket and prefix to ensure that the bucket exists and has backups.
271272
func validateS3BackupStore(s *s3BackupStore) error {
273+
u, err := url.Parse(s.endpoint)
274+
if err != nil {
275+
return fmt.Errorf("parse endpoint: %v", err)
276+
}
277+
isAWS := strings.HasSuffix(u.Hostname(), ".amazonaws.com")
272278
sess, err := session.NewSession(&aws.Config{
273-
Region: aws.String(s.region),
274-
Endpoint: aws.String(s.endpoint),
275-
Credentials: credentials.NewStaticCredentials(s.accessKeyID, s.secretAccessKey, ""),
279+
Region: aws.String(s.region),
280+
Endpoint: aws.String(s.endpoint),
281+
Credentials: credentials.NewStaticCredentials(s.accessKeyID, s.secretAccessKey, ""),
282+
S3ForcePathStyle: aws.Bool(!isAWS),
276283
})
277284
if err != nil {
278-
return fmt.Errorf("unable to create s3 session: %v", err)
285+
return fmt.Errorf("create s3 session: %v", err)
279286
}
280287
input := &s3.ListObjectsV2Input{
281288
Bucket: aws.String(s.bucket),
@@ -285,7 +292,7 @@ func validateS3BackupStore(s *s3BackupStore) error {
285292
svc := s3.New(sess)
286293
result, err := svc.ListObjectsV2(input)
287294
if err != nil {
288-
return fmt.Errorf("unable to list objects: %v", err)
295+
return fmt.Errorf("list objects: %v", err)
289296
}
290297
if len(result.CommonPrefixes) == 0 {
291298
return fmt.Errorf("no backups found in %s", filepath.Join(s.bucket, s.prefix))
@@ -883,6 +890,12 @@ var restoreCommand = &cli.Command{
883890
Usage: "Skip host preflight checks. This is not recommended.",
884891
Value: false,
885892
},
893+
&cli.BoolFlag{
894+
Name: "skip-store-validation",
895+
Usage: "Skip validation of the backup store. This is not recommended.",
896+
Value: false,
897+
Hidden: true,
898+
},
886899
},
887900
)),
888901
Before: func(c *cli.Context) error {
@@ -951,9 +964,11 @@ var restoreCommand = &cli.Command{
951964
logrus.Info("Enter information to configure access to your backup storage location.\n")
952965
s3Store := newS3BackupStore()
953966

954-
logrus.Debugf("validating backup store configuration")
955-
if err := validateS3BackupStore(s3Store); err != nil {
956-
return fmt.Errorf("unable to validate backup store: %w", err)
967+
if !c.Bool("skip-store-validation") {
968+
logrus.Debugf("validating backup store configuration")
969+
if err := validateS3BackupStore(s3Store); err != nil {
970+
return fmt.Errorf("unable to validate backup store: %w", err)
971+
}
957972
}
958973

959974
logrus.Debugf("configuring network manager")

0 commit comments

Comments
 (0)