Suddenly getting googleapi: Error 401: Invalid Credentials, authError

i use gdrive service accounts and never used that with root_folder_id.

for testing, please remove it and let's see what happens.

I'm just trying to make sure I have your flow here.

I can see gdrive-crypt-sa in your rclone.conf you shared, but not gdrive-crypt.

What is gdrive-crypt? I am trying to recreate but missing pieces.

Oh, Yes, sorry. I can see that's confusing. It's a typo/mistake on my part. I've been juggling between testing with my regular account (non sa) gdrive-crypt remote, and the sa remote gdrive-crypt-sa. They behave exactly the same.

If you want to recreate without any mixups from me, look at this one (the last one posted)

ref. root_folder_id I just searched and saw people used in their config files. I can't really see I'm using it any different/special?

It's late here now, and I need to go to bed. Tomorrow I'll try without root_folder_id since both of you are insisting (I still don't think that would do anything, but we'll see. :slight_smile:).

Another thing I'm going to try, is to create a new service account and see.

I'm not able to not use root_folder_id, since the root folder is encrypted, and rclone don't seem to be able to mix paths.

The path is gdrive-crypt-sa:/_backup/rclone/, but using crypt, it "translates" _backup/rclone/ to encrypted text, and that does not exist. And not using crypt, makes the content unreadable for syncing, and I can't recreate the issue.

But I don't see an issue using root_folder_id.

Here is excerpt from the earlier log using dump headers where the issue is. I included one successful, and then the denied one:

2021/11/01 22:34:38 DEBUG : <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
2021/11/01 22:34:39 DEBUG : >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
2021/11/01 22:34:39 DEBUG : HTTP REQUEST (req 0xc006727100)
2021/11/01 22:34:39 DEBUG : GET /drive/v3/files?alt=json&fields=files%28id%2Cname%2Csize%2Cmd5Checksum%2Ctrashed%2CexplicitlyTrashed%2CmodifiedTime%2CcreatedTime%2CmimeType%2Cparents%2CwebViewLink%2CshortcutDetails%2CexportLinks%29%2CnextPageToken%2CincompleteSearch&includeItemsFromAllDrives=true&pageSize=1000&prettyPrint=false&q=trashed%3Dfalse+and+%28%271QG_wkHUQ2HJyK8fN566f5Vm2deBKtJe8%27+in+parents%29&supportsAllDrives=true HTTP/1.1
Host: www.googleapis.com
User-Agent: A2122pkPYkLUR7ttBYUuTnPDz4P223D21NACs
Authorization: XXXX
X-Goog-Api-Client: gl-go/1.17.2 gdcl/20210812
Accept-Encoding: gzip

2021/11/01 22:34:39 DEBUG : >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
2021/11/01 22:34:39 DEBUG : <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
2021/11/01 22:34:39 DEBUG : HTTP RESPONSE (req 0xc006727100)
2021/11/01 22:34:39 DEBUG : HTTP/1.1 200 OK
Transfer-Encoding: chunked
Alt-Svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Content-Security-Policy: frame-ancestors 'self'
Content-Type: application/json; charset=UTF-8
Date: Mon, 01 Nov 2021 21:34:39 GMT
Expires: Mon, 01 Jan 1990 00:00:00 GMT
Pragma: no-cache
Server: GSE
Vary: Origin
Vary: X-Origin
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-Xss-Protection: 1; mode=block

4b3
{"incompleteSearch":false,"files":[{"id":"<removed>","name":"<removed>","mimeType":"application/vnd.google-apps.folder","trashed":false,"explicitlyTrashed":false,"parents":["<removed>"],"webViewLink":"https://drive.google.com/drive/folders/<removed>","createdTime":"2019-10-29T19:45:41.339Z","modifiedTime":"2019-10-29T19:45:41.339Z"},{"id":"<removed>","name":"<removed>","mimeType":"application/vnd.google-apps.folder","trashed":false,"explicitlyTrashed":false,"parents":["<removed>"],"webViewLink":"https://drive.google.com/drive/folders/<removed>","createdTime":"2018-03-27T16:50:56.292Z","modifiedTime":"2018-03-27T16:50:56.292Z"},{"id":"<removed>","name":"<removed>","mimeType":"application/vnd.google-apps.folder","trashed":false,"explicitlyTrashed":false,"parents":["<removed>"],"webViewLink":"https://drive.google.com/drive/folders/<removed>","createdTime":"2018-03-27T16:48:32.561Z","modifiedTime":"2018-03-27T16:48:32.561Z"}]}
0

2021/11/01 22:34:39 DEBUG : <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
2021/11/01 22:34:40 DEBUG : >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
2021/11/01 22:34:40 DEBUG : HTTP REQUEST (req 0xc0017bbc00)
2021/11/01 22:34:40 DEBUG : GET /drive/v3/files?alt=json&fields=files%28id%2Cname%2Csize%2Cmd5Checksum%2Ctrashed%2CexplicitlyTrashed%2CmodifiedTime%2CcreatedTime%2CmimeType%2Cparents%2CwebViewLink%2CshortcutDetails%2CexportLinks%29%2CnextPageToken%2CincompleteSearch&includeItemsFromAllDrives=true&pageSize=1000&prettyPrint=false&q=trashed%3Dfalse+and+%28%271Ske5M6erSb2dHvHMa2Otdls-Fi5HKDpx%27+in+parents%29&supportsAllDrives=true HTTP/1.1
Host: www.googleapis.com
User-Agent: A2122pkPYkLUR7ttBYUuTnPDz4P223D21NACs
Authorization: XXXX
X-Goog-Api-Client: gl-go/1.17.2 gdcl/20210812
Accept-Encoding: gzip

2021/11/01 22:34:40 DEBUG : >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
2021/11/01 22:34:40 DEBUG : <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
2021/11/01 22:34:40 DEBUG : HTTP RESPONSE (req 0xc0017bbc00)
2021/11/01 22:34:40 DEBUG : HTTP/1.1 200 OK
Transfer-Encoding: chunked
Alt-Svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Content-Security-Policy: frame-ancestors 'self'
Content-Type: application/json; charset=UTF-8
Date: Mon, 01 Nov 2021 21:34:40 GMT
Expires: Mon, 01 Jan 1990 00:00:00 GMT
Pragma: no-cache
Server: GSE
Vary: Origin
Vary: X-Origin
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-Xss-Protection: 1; mode=block

25
{"incompleteSearch":false,"files":[]}
0

2021/11/01 22:34:40 DEBUG : <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
2021/11/01 22:34:41 DEBUG : >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
2021/11/01 22:34:41 DEBUG : HTTP REQUEST (req 0xc000738400)
2021/11/01 22:34:41 DEBUG : GET /drive/v3/files?alt=json&fields=files%28id%2Cname%2Csize%2Cmd5Checksum%2Ctrashed%2CexplicitlyTrashed%2CmodifiedTime%2CcreatedTime%2CmimeType%2Cparents%2CwebViewLink%2CshortcutDetails%2CexportLinks%29%2CnextPageToken%2CincompleteSearch&includeItemsFromAllDrives=true&pageSize=1000&prettyPrint=false&q=trashed%3Dfalse+and+%28%271f4uqLMtOfN3gMzyt6mYGHjSCua7NS07N%27+in+parents%29&supportsAllDrives=true HTTP/1.1
Host: www.googleapis.com
User-Agent: A2122pkPYkLUR7ttBYUuTnPDz4P223D21NACs
Authorization: XXXX
X-Goog-Api-Client: gl-go/1.17.2 gdcl/20210812
Accept-Encoding: gzip

2021/11/01 22:34:41 DEBUG : >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
2021/11/01 22:34:41 DEBUG : <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
2021/11/01 22:34:41 DEBUG : HTTP RESPONSE (req 0xc000738400)
2021/11/01 22:34:41 DEBUG : HTTP/1.1 401 Unauthorized
Transfer-Encoding: chunked
Alt-Svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"
Cache-Control: private, max-age=0
Content-Security-Policy: frame-ancestors 'self'
Content-Type: application/json; charset=UTF-8
Date: Mon, 01 Nov 2021 21:34:41 GMT
Expires: Mon, 01 Nov 2021 21:34:41 GMT
Server: GSE
Vary: Origin
Vary: X-Origin
Www-Authenticate: Bearer realm="https://accounts.google.com/", error=invalid_token
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-Xss-Protection: 1; mode=block

bd
{"error":{"errors":[{"domain":"global","reason":"authError","message":"Invalid Credentials","locationType":"header","location":"Authorization"}],"code":401,"message":"Invalid Credentials"}}
0

(…)

2021/11/01 22:34:45 DEBUG : <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
2021/11/01 22:34:46 DEBUG : >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
2021/11/01 22:34:46 DEBUG : HTTP REQUEST (req 0xc007c1b500)
2021/11/01 22:34:46 DEBUG : GET /drive/v3/files?alt=json&fields=files%28id%2Cname%2Csize%2Cmd5Checksum%2Ctrashed%2CexplicitlyTrashed%2CmodifiedTime%2CcreatedTime%2CmimeType%2Cparents%2CwebViewLink%2CshortcutDetails%2CexportLinks%29%2CnextPageToken%2CincompleteSearch&includeItemsFromAllDrives=true&pageSize=1000&prettyPrint=false&q=trashed%3Dfalse+and+%28%271lgxOgYok5rRehrlQwBNU-4dPhw8DYfO8%27+in+parents%29&supportsAllDrives=true HTTP/1.1
Host: www.googleapis.com
User-Agent: A2122pkPYkLUR7ttBYUuTnPDz4P223D21NACs
Authorization: XXXX
X-Goog-Api-Client: gl-go/1.17.2 gdcl/20210812
Accept-Encoding: gzip

2021/11/01 22:34:46 DEBUG : >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
2021/11/01 22:34:46 DEBUG : <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
2021/11/01 22:34:46 DEBUG : HTTP RESPONSE (req 0xc007c1b500)
2021/11/01 22:34:46 DEBUG : HTTP/1.1 401 Unauthorized
Transfer-Encoding: chunked
Alt-Svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"
Cache-Control: private, max-age=0
Content-Security-Policy: frame-ancestors 'self'
Content-Type: application/json; charset=UTF-8
Date: Mon, 01 Nov 2021 21:34:46 GMT
Expires: Mon, 01 Nov 2021 21:34:46 GMT
Server: GSE
Vary: Origin
Vary: X-Origin
Www-Authenticate: Bearer realm="https://accounts.google.com/", error=invalid_token
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-Xss-Protection: 1; mode=block

bd
{"error":{"errors":[{"domain":"global","reason":"authError","message":"Invalid Credentials","locationType":"header","location":"Authorization"}],"code":401,"message":"Invalid Credentials"}}
0

Does this seem to mirror your setup?

[TEST]
type = drive
scope = drive
use_trash = false
client_id = clientid.apps.googleusercontent.com
client_secret = clientsecret
chunk_size = 1024M
impersonate = felix@joe.us
root_folder_id = myonefolderrootidinmygoogledrive
service_account_file = /opt/rclone/service.json
team_drive =

[TESTC]
type = crypt
remote = TEST:crypt
filename_encryption = standard
password = password
password2 = password
directory_name_encryption = true

I have a folder in my drive called crypt which is in a folder called test. I use that 'crypt' folder's rootID:

I ran through a few syncs and deleted files and I can see they move server side:

felix@gemini:~$ rclone sync /home/felix/test TESTC:/last_snapshot --backup-dir TESTC:/archive/20211105 -vv
2021/11/02 07:57:13 DEBUG : Setting --config "/opt/rclone/rclone.conf" from environment variable RCLONE_CONFIG="/opt/rclone/rclone.conf"
2021/11/02 07:57:13 DEBUG : Setting --user-agent "animosityapp" from environment variable RCLONE_USER_AGENT="animosityapp"
2021/11/02 07:57:13 DEBUG : Setting --rc-user "felix" from environment variable RCLONE_RC_USER="felix"
2021/11/02 07:57:13 DEBUG : Setting --rc-pass "felix" from environment variable RCLONE_RC_PASS="felix"
2021/11/02 07:57:13 DEBUG : Setting default for drive-pacer-min-sleep="10ms" from environment variable RCLONE_DRIVE_PACER_MIN_SLEEP
2021/11/02 07:57:13 DEBUG : Setting default for drive-pacer-burst="1000" from environment variable RCLONE_DRIVE_PACER_BURST
2021/11/02 07:57:13 DEBUG : rclone: Version "v1.57.0" starting with parameters ["rclone" "sync" "/home/felix/test" "TESTC:/last_snapshot" "--backup-dir" "TESTC:/archive/20211105" "-vv"]
2021/11/02 07:57:13 DEBUG : Creating backend with remote "/home/felix/test"
2021/11/02 07:57:13 DEBUG : Using config file from "/opt/rclone/rclone.conf"
2021/11/02 07:57:13 DEBUG : Creating backend with remote "TESTC:/last_snapshot"
2021/11/02 07:57:13 DEBUG : Creating backend with remote "TEST:crypt/lrak4favmei0j55g20imrj7it4"
2021/11/02 07:57:13 DEBUG : Setting drive_pacer_min_sleep="10ms" from environment variable RCLONE_DRIVE_PACER_MIN_SLEEP
2021/11/02 07:57:13 DEBUG : Setting drive_pacer_burst="1000" from environment variable RCLONE_DRIVE_PACER_BURST
2021/11/02 07:57:13 DEBUG : TEST: detected overridden config - adding "{TKSWb}" suffix to name
2021/11/02 07:57:13 DEBUG : Setting drive_pacer_min_sleep="10ms" from environment variable RCLONE_DRIVE_PACER_MIN_SLEEP
2021/11/02 07:57:13 DEBUG : Setting drive_pacer_burst="1000" from environment variable RCLONE_DRIVE_PACER_BURST
2021/11/02 07:57:14 DEBUG : fs cache: renaming cache item "TEST:crypt/lrak4favmei0j55g20imrj7it4" to be canonical "TEST{TKSWb}:crypt/lrak4favmei0j55g20imrj7it4"
2021/11/02 07:57:14 DEBUG : fs cache: switching user supplied name "TEST:crypt/lrak4favmei0j55g20imrj7it4" for canonical name "TEST{TKSWb}:crypt/lrak4favmei0j55g20imrj7it4"
2021/11/02 07:57:14 DEBUG : Creating backend with remote "TESTC:/archive/20211105"
2021/11/02 07:57:14 DEBUG : Creating backend with remote "TEST:crypt/s9g4p1ep8mu3hgstqj76c911c4/f6pam00n460kqhi1gp0r79o004"
2021/11/02 07:57:14 DEBUG : Setting drive_pacer_min_sleep="10ms" from environment variable RCLONE_DRIVE_PACER_MIN_SLEEP
2021/11/02 07:57:14 DEBUG : Setting drive_pacer_burst="1000" from environment variable RCLONE_DRIVE_PACER_BURST
2021/11/02 07:57:14 DEBUG : TEST: detected overridden config - adding "{TKSWb}" suffix to name
2021/11/02 07:57:14 DEBUG : Setting drive_pacer_min_sleep="10ms" from environment variable RCLONE_DRIVE_PACER_MIN_SLEEP
2021/11/02 07:57:14 DEBUG : Setting drive_pacer_burst="1000" from environment variable RCLONE_DRIVE_PACER_BURST
2021/11/02 07:57:15 DEBUG : fs cache: renaming cache item "TEST:crypt/s9g4p1ep8mu3hgstqj76c911c4/f6pam00n460kqhi1gp0r79o004" to be canonical "TEST{TKSWb}:crypt/s9g4p1ep8mu3hgstqj76c911c4/f6pam00n460kqhi1gp0r79o004"
2021/11/02 07:57:15 DEBUG : fs cache: switching user supplied name "TEST:crypt/s9g4p1ep8mu3hgstqj76c911c4/f6pam00n460kqhi1gp0r79o004" for canonical name "TEST{TKSWb}:crypt/s9g4p1ep8mu3hgstqj76c911c4/f6pam00n460kqhi1gp0r79o004"
2021/11/02 07:57:15 DEBUG : Encrypted drive 'TESTC:/last_snapshot': Waiting for checks to finish
2021/11/02 07:57:15 DEBUG : one: Size and modification time the same (differ by -285.481µs, within tolerance 1ms)
2021/11/02 07:57:15 DEBUG : one: Unchanged skipping
2021/11/02 07:57:15 DEBUG : two: Size and modification time the same (differ by -320.042µs, within tolerance 1ms)
2021/11/02 07:57:15 DEBUG : two: Unchanged skipping
2021/11/02 07:57:15 DEBUG : Encrypted drive 'TESTC:/last_snapshot': Waiting for transfers to finish
2021/11/02 07:57:15 DEBUG : Waiting for deletions to finish
2021/11/02 07:57:16 INFO  : four: Moved (server-side)
2021/11/02 07:57:16 INFO  : four: Moved into backup dir
2021/11/02 07:57:17 INFO  : three: Moved (server-side)
2021/11/02 07:57:17 INFO  : three: Moved into backup dir
2021/11/02 07:57:17 INFO  : There was nothing to transfer
2021/11/02 07:57:17 INFO  :
Transferred:   	          0 B / 0 B, -, 0 B/s, ETA -
Checks:                 6 / 6, 100%
Deleted:                2 (files), 0 (dirs)
Renamed:                2
Elapsed time:         3.4s

2021/11/02 07:57:17 DEBUG : 12 go routines active

and my backup dirs I tested with have some files:

felix@gemini:~$ rclone ls TESTC:
        0 last_snapshot/two
        0 last_snapshot/one
      165 archive/20211103/blah
1504953150 archive/20211104/Copy of jellyfish-400-mbps-4k-uhd-hevc-10bit.mkv
      165 archive/20211104/hosts
        0 archive/20211105/four
        0 archive/20211105/three

I just want to make sure I translated what you had on my side for testing as everything I've done works.

The last piece is translating your permissions that you made as my service account has full blown rights.

Is your Drive a GSuite or a personal account? You granted permissions not by allowing site wide delegation on the GSuite side?

Can you also test with disabling server side moves?

 --disable copy

I feel pretty good your root ID isn't the issue but something along permissions.

Thanks for testing this. And yes, that's identical as far as I can see.

Other than that, I've created service accounts, added them to a group, and given the group access to the directory. I also have given the SA accounts Domain-wide Delegation to the Google Drive API (this to be able to impersonate on a users directory).

It's a GSuite (or Workspaces), and I'm the admin.

I've just tested with a brand new service account, but that gives the same errors.

What throws me off is that my account seems to have the correct permissions. It can both read and write without issues. So most of it works, but it's just halting on moving files to the backup drive afaik.

Also – the only thing I have changed on my end (rclone wise) is upgrading and changing the tps-limit against dropbox.

I'm also thinking permissions, maybe regarding something very specific. I have not made any changes to the permissions. Could Google have changed something (but then again, you should think other users would experience something similar).

I'll give it a go with --disable copy

If they have domain wide delegation, what's the purpose of sharing and adding them to a group? Does that stop access to something?

It's to be able to impersonate my main user in that user's directory, making all files owned by the main user.

I didn't do that and when I had files move, I see:

image

Which looks like everything is owned properly on the few files I sampled. Did you see something else prior to doing that?

Yes, as far as I can remember. It's been a while now.

When I first set it up (transferring multiple TB from a local server) – the files were owned by the individual service account, which in turn messed up when you wanted to manipulate (i.e delete) files later on via a different user/service account.

This was not an issue using Team Drives, but was an issue using a regular users drive (where I had to put it due to the file limit on Team Drives).

The only way to get around that, was to give domain-wide delegation (I got the info from this post).

EDIT:
Just to make sure again, I did a test:

Config (just using non-crypt, does not matter):

[gdrive-sa2]
type = drive
client_id = <clientid>
client_secret = <clientsecret>
impersonate = user@domain.tld
scope = drive
root_folder_id = <folder id>
service_account_file = /home/<removed>/rclone/sa/rc05.json

Running with a newly created service account:

➜  rclone rclone lsd gdrive-sa2: -vv
2021/11/02 13:56:10 DEBUG : rclone: Version "v1.57.0" starting with parameters ["rclone" "lsd" "gdrive-sa2:" "-vv"]
2021/11/02 13:56:10 DEBUG : Creating backend with remote "gdrive-sa2:"                                                            2021/11/02 13:56:10 DEBUG : Using config file from "/home/<user>/.config/rclone/rclone.conf"                                        2021/11/02 13:56:11 ERROR : : error listing: couldn't list directory: Get "https://www.googleapis.com/drive/v3/files?alt=json&fields=files%28id%2Cname%2Csize%2Cmd5Checksum%2Ctrashed%2CexplicitlyTrashed%2CmodifiedTime%2CcreatedTime%2CmimeType%2Cparents%2CwebViewLink%2CshortcutDetails%2CexportLinks%29%2CnextPageToken%2CincompleteSearch&includeItemsFromAllDrives=true&pageSize=1000&prettyPrint=false&q=trashed%3Dfalse+and+%28%271odGMeeHbKre4D8-O65Z-UDOwEyAokilI%27+in+parents%29&supportsAllDrives=true": oauth2: cannot fetch token: 401 Unauthorized
Response: {                                                                                                                         "error": "unauthorized_client",
  "error_description": "Client is unauthorized to retrieve access tokens using this method, or client not authorized for any of th
e scopes requested."
}
2021/11/02 13:56:11 DEBUG : 4 go routines active
2021/11/02 13:56:11 Failed to lsd with 2 errors: last error was: couldn't list directory: Get "https://www.googleapis.com/drive/v3
/files?alt=json&fields=files%28id%2Cname%2Csize%2Cmd5Checksum%2Ctrashed%2CexplicitlyTrashed%2CmodifiedTime%2CcreatedTime%2CmimeType%2Cparents%2CwebViewLink%2CshortcutDetails%2CexportLinks%29%2CnextPageToken%2CincompleteSearch&includeItemsFromAllDrives=true&pageSize=1000&prettyPrint=false&q=trashed%3Dfalse+and+%28%271odGMeeHbKre4D8-O65Z-UDOwEyAokilI%27+in+parents%29&supportsAllDrives=true": oauth2: cannot fetch token: 401 Unauthorized                                                                                   Response: {
  "error": "unauthorized_client",
  "error_description": "Client is unauthorized to retrieve access tokens using this method, or client not authorized for any of the scopes requested."                                                                                                              }

Running with new service account given domain-wide delegation to the google drive API:

➜  rclone rclone lsd gdrive-sa2: -vv
2021/11/02 13:56:54 DEBUG : rclone: Version "v1.57.0" starting with parameters ["rclone" "lsd" "gdrive-sa2:" "-vv"]
2021/11/02 13:56:54 DEBUG : Creating backend with remote "gdrive-sa2:"
2021/11/02 13:56:54 DEBUG : Using config file from "/home/<user>/.config/rclone/rclone.conf"
2021/11/02 13:56:54 ERROR : : error listing: couldn't list directory: Get "https://www.googleapis.com/drive/v3/files?alt=json&fields=files%28id%2Cname%2Csize%2Cmd5Checksum%2Ctrashed%2CexplicitlyTrashed%2CmodifiedTime%2CcreatedTime%2CmimeType%2Cparents%2CwebVie
wLink%2CshortcutDetails%2CexportLinks29%2CnextPageToken%2CincompleteSearch&includeItemsFromAllDrives=true&pageSize=1000&prettyPrint=false&q=trashed%3Dfalse+and+%28%271odGMeeHbKre4D8-O65Z-UDOwEyAokilI%27+in+parents%29&supportsAllDrives=true": oauth2: cannot fetch token: 401 Unauthorized
Response: {
  "error": "unauthorized_client",
  "error_description": "Client is unauthorized to retrieve access tokens using this method, or client not authorized for any of the scopes requested."
}
2021/11/02 13:56:54 DEBUG : 4 go routines active
2021/11/02 13:56:54 Failed to lsd with 2 errors: last error was: couldn't list directory: Get "https://www.googleapis.com/drive/v3
/files?alt=json&fields=files%28id%2Cname%2Csize%2Cmd5Checksum%2Ctrashed%2CexplicitlyTrashed%2CmodifiedTime%2CcreatedTime%2CmimeType%2Cparents%2CwebViewLink%2CshortcutDetails%2CexportLinks%29%2CnextPageToken%2CincompleteSearch&includeItemsFromAllDrives=true&pageSize=1000&prettyPrint=false&q=trashed%3Dfalse+and+%28%271odGMeeHbKre4D8-O65Z-UDOwEyAokilI%27+in+parents%29&supportsAllDrives=true": oauth2: cannot fetch token: 401 Unauthorized
Response: {
  "error": "unauthorized_client",
  "error_description": "Client is unauthorized to retrieve access tokens using this method, or client not authorized for any of the scopes requested."
}

Running SA with domain-wide delegation, and added to the group (that is added to the directory):

➜  rclone rclone lsd gdrive-sa2: -vv
2021/11/02 13:57:39 DEBUG : rclone: Version "v1.57.0" starting with parameters ["rclone" "lsd" "gdrive-sa2:" "-vv"]
2021/11/02 13:57:39 DEBUG : Creating backend with remote "gdrive-sa2:"
2021/11/02 13:57:39 DEBUG : Using config file from "/home/<user>/.config/rclone/rclone.conf"
          -1 2021-11-01 13:23:55        -1 bio0l83s1stlol81sgujc8lhn2ig
          -1 2018-03-25 01:02:32        -1 d4g7fbatdddhi2k49f7b59alv9t8
          -1 2018-04-30 13:21:42        -1 erqd5fvaus2135q91v162n2gp3sfs
          -1 2020-10-06 10:36:47        -1 l9qr7vlm2ivssehc0cbnqi22q1r4
2021/11/02 13:57:39 DEBUG : 6 go routines active

So afaik, all steps are needed.

Do you have a token line in there?

My test rclone.conf as token is for a service account setup:

[TEST]
type = drive
scope = drive
use_trash = false
client_id = clientid.apps.googleusercontent.com
client_secret = secret
impersonate = felix@joe.us
service_account_file = /opt/rclone/service.json
chunk_size = 1024M
root_folder_id = 1eNNNZIXQcC_SHp7Nr2D2BMiWLhQG69Cf

My mistake, It's not needed. It's "a leftover" from when I copied and started using service accounts. The token is not used, it has not been updated since 2020 (as expected).

When removed, do you get the same results?

I am not using any groups at all and my service account works.

You seem to have something unique going on.

Yes, works fine. It's not used.

But you did have to give the SA access to the directory, or no?

From my reading, changing the root ID doesn't require any permissions as it's a logical change.

You've already given SA wide delegation so that account has full access to everything.

I have a test folder I made and use that root ID in my rclone.conf above:

image

and the rlcone command:

image

Works fine with that a different root ID. Adding the root ID to the rcloneconf at the actual root just saves a bit of time as it fetches the root ID first and saves it. You can override the root location as you've done but none of that should impact any access as you already have full access domain wide.

As far as I understand, it's not the root ID that is the issue, it's the impersonation.

Running with the impersonation commented out it gives:
Config:

[gdrive-sa2]
type = drive
client_id = <clientid>
client_secret = <clientsecret>
#impersonate = user@domain.tld
scope = drive
root_folder_id = <folder id>
service_account_file = /home/<removed>/rclone/sa/rc05.json
➜  rclone rclone lsd gdrive-sa2: -vv
2021/11/02 13:55:35 DEBUG : rclone: Version "v1.57.0" starting with parameters ["rclone" "lsd" "gdrive-sa2:" "-vv"]
2021/11/02 13:55:35 DEBUG : Creating backend with remote "gdrive-sa2:"
2021/11/02 13:55:35 DEBUG : Using config file from "/home/<removed>/.config/rclone/rclone.conf"
2021/11/02 13:55:35 DEBUG : 6 go routines active

No errors, but it does not see any files.

Right. If you don't impersonate, you won't see anything as that's the delegation in play:

felix@gemini:/opt/rclone$ rclone ls TEST: --drive-impersonate felix@joe.us
      165 hosts
felix@gemini:/opt/rclone$ rclone ls TEST:
felix@gemini:/opt/rclone$

If I give the SA access via sharing the directory to the group or individual SA account, I can list, upload, and whatever, but the owner of the file is the SA account.

Ok, I think I got it now.

My issue was I was using existing files which were server side copying and I got the original owner permissions which was 'me' and not the service account.

If I cleaned out everything, I can make a new file (fresh copy) and that shows the service account owner:

image

When you share that folder, what email are you putting in there?

I share it with the group email I have for the service accounts. It's an easy way to have access control, you just add the group e-mail, and can administer the access from the group settings (instead of adding x-numbers of email – also easier to remember).

(This is a non issue for me, since this is a more "set'n'forget" type of deal.)

Group screenshot:

Sharing: