Skip to content

SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.

fix(gcs): resolve credential conflict in remote storage mount (#8013)

Chris Lu269092c8c348
diff --git a/weed/remote_storage/gcs/gcs_storage_client.go b/weed/remote_storage/gcs/gcs_storage_client.go
index 8e8a97a1c4..b92f81b0fa 100644
--- a/weed/remote_storage/gcs/gcs_storage_client.go
+++ b/weed/remote_storage/gcs/gcs_storage_client.go
@@ -14,6 +14,8 @@ import (
"github.com/seaweedfs/seaweedfs/weed/pb/remote_pb"
"github.com/seaweedfs/seaweedfs/weed/remote_storage"
"github.com/seaweedfs/seaweedfs/weed/util"
+ "golang.org/x/oauth2"
+ "golang.org/x/oauth2/google"
"google.golang.org/api/iterator"
"google.golang.org/api/option"
)
@@ -54,7 +56,27 @@ func (s gcsRemoteStorageMaker) Make(conf *remote_pb.RemoteConf) (remote_storage.
googleApplicationCredentials = util.ResolvePath(googleApplicationCredentials)
- c, err := storage.NewClient(context.Background(), option.WithCredentialsFile(googleApplicationCredentials))
+ var clientOpts []option.ClientOption
+ if googleApplicationCredentials != "" {
+ var data []byte
+ var err error
+ if strings.HasPrefix(googleApplicationCredentials, "{") {
+ data = []byte(googleApplicationCredentials)
+ } else {
+ data, err = os.ReadFile(googleApplicationCredentials)
+ if err != nil {
+ return nil, fmt.Errorf("failed to read credentials file %s: %w", googleApplicationCredentials, err)
+ }
+ }
+ creds, err := google.CredentialsFromJSON(context.Background(), data, storage.ScopeFullControl)
+ if err != nil {
+ return nil, fmt.Errorf("failed to parse credentials: %w", err)
+ }
+ httpClient := oauth2.NewClient(context.Background(), creds.TokenSource)
+ clientOpts = append(clientOpts, option.WithHTTPClient(httpClient), option.WithoutAuthentication())
+ }
+
+ c, err := storage.NewClient(context.Background(), clientOpts...)
if err != nil {
return nil, fmt.Errorf("failed to create client: %w", err)
}