Skip to content

Commit

Permalink
Fix validating non-AWS S3-compatible stores (#1021)
Browse files Browse the repository at this point in the history
* Fix validating non-AWS S3-compatible stores
  • Loading branch information
sgalsaleh authored Aug 21, 2024
1 parent 7f7de2b commit 4a23eaf
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions cmd/embedded-cluster/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
_ "embed"
"encoding/json"
"fmt"
"net/url"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -269,13 +270,19 @@ func newS3BackupStore() *s3BackupStore {
// validateS3BackupStore validates the S3 backup store configuration.
// It tries to list objects in the bucket and prefix to ensure that the bucket exists and has backups.
func validateS3BackupStore(s *s3BackupStore) error {
u, err := url.Parse(s.endpoint)
if err != nil {
return fmt.Errorf("parse endpoint: %v", err)
}
isAWS := strings.HasSuffix(u.Hostname(), ".amazonaws.com")
sess, err := session.NewSession(&aws.Config{
Region: aws.String(s.region),
Endpoint: aws.String(s.endpoint),
Credentials: credentials.NewStaticCredentials(s.accessKeyID, s.secretAccessKey, ""),
Region: aws.String(s.region),
Endpoint: aws.String(s.endpoint),
Credentials: credentials.NewStaticCredentials(s.accessKeyID, s.secretAccessKey, ""),
S3ForcePathStyle: aws.Bool(!isAWS),
})
if err != nil {
return fmt.Errorf("unable to create s3 session: %v", err)
return fmt.Errorf("create s3 session: %v", err)
}
input := &s3.ListObjectsV2Input{
Bucket: aws.String(s.bucket),
Expand All @@ -285,7 +292,7 @@ func validateS3BackupStore(s *s3BackupStore) error {
svc := s3.New(sess)
result, err := svc.ListObjectsV2(input)
if err != nil {
return fmt.Errorf("unable to list objects: %v", err)
return fmt.Errorf("list objects: %v", err)
}
if len(result.CommonPrefixes) == 0 {
return fmt.Errorf("no backups found in %s", filepath.Join(s.bucket, s.prefix))
Expand Down Expand Up @@ -883,6 +890,12 @@ var restoreCommand = &cli.Command{
Usage: "Skip host preflight checks. This is not recommended.",
Value: false,
},
&cli.BoolFlag{
Name: "skip-store-validation",
Usage: "Skip validation of the backup store. This is not recommended.",
Value: false,
Hidden: true,
},
},
)),
Before: func(c *cli.Context) error {
Expand Down Expand Up @@ -951,9 +964,11 @@ var restoreCommand = &cli.Command{
logrus.Info("Enter information to configure access to your backup storage location.\n")
s3Store := newS3BackupStore()

logrus.Debugf("validating backup store configuration")
if err := validateS3BackupStore(s3Store); err != nil {
return fmt.Errorf("unable to validate backup store: %w", err)
if !c.Bool("skip-store-validation") {
logrus.Debugf("validating backup store configuration")
if err := validateS3BackupStore(s3Store); err != nil {
return fmt.Errorf("unable to validate backup store: %w", err)
}
}

logrus.Debugf("configuring network manager")
Expand Down

0 comments on commit 4a23eaf

Please sign in to comment.