Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

drive, gcs: fix service account authentication - fixes #2279

Nick Craig-Wooda3bf6b9c2c78
diff --git a/backend/drive/drive.go b/backend/drive/drive.go
index 5f733f9e3..14b24da27 100644
--- a/backend/drive/drive.go
+++ b/backend/drive/drive.go
@@ -464,8 +464,8 @@ func createOAuthClient(name string) (*http.Client, error) {
// try loading service account credentials from env variable, then from a file
serviceAccountCreds := []byte(config.FileGet(name, "service_account_credentials"))
- if len(serviceAccountCreds) == 0 {
- serviceAccountPath := config.FileGet(name, "service_account_file")
+ serviceAccountPath := config.FileGet(name, "service_account_file")
+ if len(serviceAccountCreds) == 0 && serviceAccountPath != "" {
loadedCreds, err := ioutil.ReadFile(os.ExpandEnv(serviceAccountPath))
if err != nil {
return nil, errors.Wrap(err, "error opening service account credentials file")
diff --git a/backend/googlecloudstorage/googlecloudstorage.go b/backend/googlecloudstorage/googlecloudstorage.go
index 0b77eb68b..c18cab6cb 100644
--- a/backend/googlecloudstorage/googlecloudstorage.go
+++ b/backend/googlecloudstorage/googlecloudstorage.go
@@ -293,8 +293,8 @@ func NewFs(name, root string) (fs.Fs, error) {
// try loading service account credentials from env variable, then from a file
serviceAccountCreds := []byte(config.FileGet(name, "service_account_credentials"))
- if len(serviceAccountCreds) == 0 {
- serviceAccountPath := config.FileGet(name, "service_account_file")
+ serviceAccountPath := config.FileGet(name, "service_account_file")
+ if len(serviceAccountCreds) == 0 && serviceAccountPath != "" {
loadedCreds, err := ioutil.ReadFile(os.ExpandEnv(serviceAccountPath))
if err != nil {
return nil, errors.Wrap(err, "error opening service account credentials file")