rclone: Can't use onedrive on business SharePoint doc library if I don't have read access to the document root

The associated forum post URL from https://forum.rclone.org

As per previous discussion: https://forum.rclone.org/t/cant-ls-onedrive-business-shared-folder-not-in-root-of-drive/19559

What is your current rclone version (output from rclone version)?

v1.57.0

What problem are you are trying to solve?

I’m trying to access a document library of a SharePoint site in my org. The doc library is set up so I don’t have access to list the root folder, only a special folder just for me a few levels deep. This is the same situation as described by someone else in the linked thread.

I can set it up ok, but I can’t list it with rclone: rclone lsd 'MySite:General/akdorsSpecialFolder' first tries to get MySite:General, which is the one I don’t have access to:

rclone -vvv --dump requests lsd 'MySite:General/akdorsSpecialFolder'
<7>DEBUG : GET /v1.0/drives/b!-[CENSORED]/root HTTP/1.1
Host: graph.microsoft.com
User-Agent: rclone/v1.57.0
Authorization: XXXX
Accept-Encoding: gzip

<7>DEBUG : >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
<7>DEBUG : <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
<7>DEBUG : HTTP RESPONSE (req 0xc000630200)
<7>DEBUG : HTTP/1.1 200 OK
Transfer-Encoding: chunked
Cache-Control: no-cache
Client-Request-Id: [CENSORED]
Content-Type: application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8
Date: Tue, 25 Jan 2022 08:44:38 GMT
Odata-Version: 4.0
Request-Id: [CENSORED]
Strict-Transport-Security: max-age=31536000
Vary: Accept-Encoding
X-Ms-Ags-Diagnostic: {"ServerInfo":{"DataCenter":"Australia Southeast","Slice":"E","Ring":"4","ScaleUnit":"002","RoleInstance":"[CENSORED]"}}

<7>DEBUG : <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
<7>DEBUG : >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
<7>DEBUG : HTTP REQUEST (req 0xc000576200)
<7>DEBUG : GET /v1.0/drives/b!-[CENSORED]/items/01[CENSORED]Z:/General: HTTP/1.1
Host: graph.microsoft.com
User-Agent: rclone/v1.57.0
Authorization: XXXX
Accept-Encoding: gzip

<7>DEBUG : >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
<7>DEBUG : <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
<7>DEBUG : HTTP RESPONSE (req 0xc000576200)
<7>DEBUG : HTTP/1.1 404 Not Found
Transfer-Encoding: chunked
Cache-Control: no-cache
Client-Request-Id: [CENSORED]
Content-Type: application/json
Date: Tue, 25 Jan 2022 08:44:37 GMT
Request-Id: [CENSORED]
Strict-Transport-Security: max-age=31536000
Vary: Accept-Encoding
X-Ms-Ags-Diagnostic: {"ServerInfo":{"DataCenter":"Australia Southeast","Slice":"E","Ring":"4","ScaleUnit":"001","RoleInstance":"[CENSORED]"}}

How do you think rclone should be changed to solve that?

In the linked forum thread, and in comments in the source, it was explained that the traversal design was necessary to find children, as the graph API doesn’t allow getting the id of a driveitem directly by path. While this may have been true at the time, it sems to no longer be the case: I can use the Graph Explorer (https://developer.microsoft.com/en-us/graph/graph-explorer) to call

https://graph.microsoft.com/v1.0/drives/b!-[CENSORED]/root:/General/akdorsSpecialFolder

and I get a 200 response. So, maybe rclone doesn’t need to get children at every level from the root anymore? <-- hence, feature request 😃

How to use GitHub

  • Please use the 👍 reaction to show that you are affected by the same issue.
  • Please don’t comment if you have no relevant information to add. It’s just extra noise for everyone subscribed to this issue.
  • Subscribe to receive notifications on status change and new comments.

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Comments: 15 (7 by maintainers)

Commits related to this issue

Most upvoted comments

@akdor1154

(For future googlers: finding the ID is kind of difficult - if you want to find the ID of /folder/target, I got it by going to /folder in sharepoint with browser dev tools open, finding the RenderListDataAsStream network request, finding the children in the response, finding the child item that is target, finding the .spItemUrl property, and extracting the bit of that url after /item/. It looks like a big 32 char hex string. There is also a UUID-format ID for the folder - this is all over the place in network requests, but it doesn’t work, you don’t want it 😦. )

Note that finding the directory IDs is probably easiest done with rclone.

You can use rclone lsjson on the directory above, or for a slightly more human readable version do this on the directory above (so the directory containing the directory that you want the ID of).

$ rclone lsf --dirs-only --format ip --csv onedrive:test
71a96798e7b1d253#71A96798E7B1D253!153770,anothertest/
71a96798e7b1d253#71A96798E7B1D253!153769,a/
71a96798e7b1d253#71A96798E7B1D253!125212,sync/

So 71a96798e7b1d253#71A96798E7B1D253!125212 would be the ID of the test/sync directory.

@ncw I’ve followed a recipe posted by @akdor1154 somewhere above in that thread: https://github.com/rclone/rclone/issues/5948#issuecomment-1030976537

In my case I’ve extracted following URL: https://ifjedupl-my.sharepoint.com:443/_api/v2.0/drives/b!iyyUEFMz_kWTKjWfSP5ndNq_WW0CwMdIvttUlRwXsgsdVV6DxHKpT6aD8sXU1zSZ/items/016RGUGOWSHGSXEHLSIZGKWSVETOVWJIZA?version=Published Then I’ve extracted the part after items according to the recipe, obtaining 016RGUGOWSHGSXEHLSIZGKWSVETOVWJIZA

On the other hand running rclone lsf --dirs-only --format ip --csv as @ncw suggested gives a bit different result:

PS C:\Users\Legion\workspace\rclone> .\rclone.exe lsf --dirs-only  --format ip --csv onedriveifj:LMP_foils
b!iyyUEFMz_kWTKjWfSP5ndNq_WW0CwMdIvttUlRwXsgsdVV6DxHKpT6aD8sXU1zSZ#016RGUGOWSHGSXEHLSIZGKWSVETOVWJIZA,interim/
b!iyyUEFMz_kWTKjWfSP5ndNq_WW0CwMdIvttUlRwXsgsdVV6DxHKpT6aD8sXU1zSZ#016RGUGOS6WEFRB72OGBEKYOW76K3KRGOM,raw/

Switching from id 016RGUGOWSHGSXEHLSIZGKWSVETOVWJIZA to b!iyyUEFMz_kWTKjWfSP5ndNq_WW0CwMdIvttUlRwXsgsdVV6DxHKpT6aD8sXU1zSZ#016RGUGOWSHGSXEHLSIZGKWSVETOVWJIZA makes rclone to work as expected:

PS C:\Users\Legion\workspace\rclone> .\rclone.exe ls ifjonedrive_interim:
  1924302 rclone.1
        0 this_is_empty_folder.txt
  1924302 target/rclone.1
PS C:\Users\Legion\workspace\rclone> ls


    Directory: C:\Users\Legion\workspace\rclone


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----        24.11.2022     12:54                target_folder
d-----        24.11.2022     12:54                target_folder2
-a----        18.11.2022     18:47           7880 git-log.txt
-a----        24.11.2022     18:45              3 HELLO.txt
-a----        24.11.2022     18:54           7996 issue-5948-ls.log
-a----        24.11.2022     18:48          11325 issue-5948.log
-a----        18.11.2022     18:47        1924302 rclone.1
-a----        18.11.2022     18:47       47673344 rclone.exe
-a----        18.11.2022     18:47        2069115 README.html
-a----        18.11.2022     18:47        1703283 README.txt


PS C:\Users\Legion\workspace\rclone> .\rclone.exe copy .\rclone.1 ifjonedrive_interim:
PS C:\Users\Legion\workspace\rclone> .\rclone.exe ls ifjonedrive_interim:
  1924302 rclone.1
PS C:\Users\Legion\workspace\rclone> .\rclone.exe copy .\HELLO.txt ifjonedrive_interim:
PS C:\Users\Legion\workspace\rclone> .\rclone.exe ls ifjonedrive_interim:
        3 HELLO.txt
  1924302 rclone.1
PS C:\Users\Legion\workspace\rclone> ls


    Directory: C:\Users\Legion\workspace\rclone


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----        18.11.2022     18:47           7880 git-log.txt
-a----        24.11.2022     18:45              3 HELLO.txt
-a----        24.11.2022     18:54           7996 issue-5948-ls.log
-a----        24.11.2022     18:48          11325 issue-5948.log
-a----        18.11.2022     18:47        1924302 rclone.1
-a----        18.11.2022     18:47       47673344 rclone.exe
-a----        18.11.2022     18:47        2069115 README.html
-a----        18.11.2022     18:47        1703283 README.txt


PS C:\Users\Legion\workspace\rclone> .\rclone.exe copy ifjonedrive_interim:HELLO.txt target_folder/
PS C:\Users\Legion\workspace\rclone> ls


    Directory: C:\Users\Legion\workspace\rclone


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----        25.11.2022     17:35                target_folder
-a----        18.11.2022     18:47           7880 git-log.txt
-a----        24.11.2022     18:45              3 HELLO.txt
-a----        24.11.2022     18:54           7996 issue-5948-ls.log
-a----        24.11.2022     18:48          11325 issue-5948.log
-a----        18.11.2022     18:47        1924302 rclone.1
-a----        18.11.2022     18:47       47673344 rclone.exe
-a----        18.11.2022     18:47        2069115 README.html
-a----        18.11.2022     18:47        1703283 README.txt


PS C:\Users\Legion\workspace\rclone> ls .\target_folder\


    Directory: C:\Users\Legion\workspace\rclone\target_folder


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----        24.11.2022     18:45              3 HELLO.txt

Maybe the instruction on how to obtain id of the folder in OneDrive should go somewhere into documentation ?

That seems to work, thankyou! Tested with recursive lsd and sync.

(For future googlers: finding the ID is kind of difficult - if you want to find the ID of /folder/target, I got it by going to /folder in sharepoint with browser dev tools open, finding the RenderListDataAsStream network request, finding the children in the response, finding the child item that is target, finding the .spItemUrl property, and extracting the bit of that url after /item/. It looks like a big 32 char hex string. There is also a UUID-format ID for the folder - this is all over the place in network requests, but it doesn’t work, you don’t want it 😦. )

Would probably still consider this a feature request from user perspective, but the above does work as a workaround for this scenario. Thanks!

Do you know the ID of your folder?

It would be possible to get rclone to use the folder ID directly to access it.

In the linked forum thread, and in comments in the source, it was explained that the traversal design was necessary to find children, as the graph API doesn’t allow getting the id of a driveitem directly by path. While this may have been true at the time, it sems to no longer be the case: I can use the Graph Explorer (https://developer.microsoft.com/en-us/graph/graph-explorer) to call

https://graph.microsoft.com/v1.0/drives/b!-[CENSORED]/root:/General/akdorsSpecialFolder

and I get a 200 response. So, maybe rclone doesn’t need to get children at every level from the root anymore? <-- hence, feature request 😃

Hmm, that is a potential speedup for all onedrive users

In theory a change like this would work

https://github.com/rclone/rclone/blob/0eb7b716d9a52af8859c85370465009af119644b/backend/onedrive/onedrive.go#L854-L863

diff --git a/backend/onedrive/onedrive.go b/backend/onedrive/onedrive.go
index 14269f443..887ed7ca6 100644
--- a/backend/onedrive/onedrive.go
+++ b/backend/onedrive/onedrive.go
@@ -852,7 +852,7 @@ func NewFs(ctx context.Context, name, root string, m configmap.Mapper) (fs.Fs, e
 	})
 
 	// Get rootID
-	rootInfo, _, err := f.readMetaDataForPath(ctx, "")
+	rootInfo, _, err := f.readMetaDataForPath(ctx, root)
 	if err != nil {
 		return nil, fmt.Errorf("failed to get root: %w", err)
 	}

Then the directory cache could be initialised with the root found directly rather than traversing the path.

https://github.com/rclone/rclone/blob/0eb7b716d9a52af8859c85370465009af119644b/backend/onedrive/onedrive.go#L694-L695

However readMetaDataForPath uses the directory cache and I don’t think it will work as-is. It’s quite complicated too as it has to deal with shared folders and the differences between…

@Cnly any thoughts about this?