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: add --drive-impersonate for service accounts #1491

Nick Craig-Wood8a25ca786c2e
diff --git a/backend/drive/drive.go b/backend/drive/drive.go
index 8c88b9898..e3f9c571e 100644
--- a/backend/drive/drive.go
+++ b/backend/drive/drive.go
@@ -63,6 +63,7 @@ var (
driveExtensions = flags.StringP("drive-formats", "", defaultExtensions, "Comma separated list of preferred formats for downloading Google docs.")
driveUseCreatedDate = flags.BoolP("drive-use-created-date", "", false, "Use created date instead of modified date.")
driveListChunk = flags.Int64P("drive-list-chunk", "", 1000, "Size of listing chunk 100-1000. 0 to disable.")
+ driveImpersonate = flags.StringP("drive-impersonate", "", "", "Impersonate this user when using a service account.")
// chunkSize is the size of the chunks created during a resumable upload and should be a power of two.
// 1<<18 is the minimum size supported by the Google uploader, and there is no maximum.
chunkSize = fs.SizeSuffix(8 * 1024 * 1024)
@@ -455,6 +456,9 @@ func getServiceAccountClient(keyJsonfilePath string) (*http.Client, error) {
if err != nil {
return nil, errors.Wrap(err, "error processing credentials")
}
+ if *driveImpersonate != "" {
+ conf.Subject = *driveImpersonate
+ }
ctxWithSpecialClient := oauthutil.Context(fshttp.NewClient(fs.Config))
return oauth2.NewClient(ctxWithSpecialClient, conf.TokenSource(ctxWithSpecialClient)), nil
}
diff --git a/docs/content/drive.md b/docs/content/drive.md
index cd6ecc8f7..c16e46903 100644
--- a/docs/content/drive.md
+++ b/docs/content/drive.md
@@ -343,6 +343,10 @@ Here are the possible extensions with their corresponding mime types.
| xlsx | application/vnd.openxmlformats-officedocument.spreadsheetml.sheet | Microsoft Office Spreadsheet |
| zip | application/zip | A ZIP file of HTML, Images CSS |
+#### --drive-impersonate user ####
+
+When using a service account, this instructs rclone to impersonate the user passed in.
+
#### --drive-list-chunk int ####
Size of listing chunk 100-1000. 0 to disable. (default 1000)