Skip to content

backend: add region option in iCloud Drive to fix #8257 - #8818

Closed
timerring wants to merge 2 commits into
rclone:masterfrom
timerring:region-icloud-8257
Closed

timerring wants to merge 2 commits into
rclone:masterfrom
timerring:region-icloud-8257

Conversation

@timerring

@timerring timerring commented Sep 12, 2025 •

Copy link
Copy Markdown

What is the purpose of this change?

The purpose of this change is to officially add support for iCloud Drive accounts in Mainland China (GCBD) to rclone’s iCloud Drive backend.

Previously, rclone’s iCloud Drive integration only hardcoded URLs for global iCloud servers (e.g., https://www.icloud.com), which caused fatal HTTP 302 errors when users with Mainland China Apple IDs attempted to connect—since Mainland China iCloud relies on independent .cn-suffixed servers (e.g., https://www.icloud.com.cn).

Was the change discussed in an issue or in the forum before?

Fixes #8257

As discussed in Issue, given the maintainer’s limited environment, I followed the instruction to add a new region option for iCloud Drive and test it. This option now works for users in Mainland China, and the relevant logs are attached below.

Checklist

  • I have read the contribution guidelines.
  • I have added tests for all changes in this PR if appropriate.
  • I have added documentation for the changes if appropriate.
  • All commit messages are in house style.
  • I'm done, this Pull Request is ready for review :-)

@timerring

Copy link
Copy Markdown
Author

It works for users who are using icloud in Mainland China. And I keep the same style of cli option and corresponding config.

~/Repo/rclone region-icloud-8257* ⇣
base ❯ go build -o /Users/jh/Repo/rclone/rclone-gcbd .   

~/Repo/rclone region-icloud-8257* ⇣ 14s
base ❯ ./rclone-gcbd --config /tmp/rclone-cn/rclone.conf config
No remotes found, make a new one?
n) New remote
s) Set configuration password
q) Quit config
n/s/q> n

Enter name for new remote.
name> icloudcn

Option Storage.
Type of storage to configure.
Choose a number from below, or type in your own value.
 1 / 1Fichier
   \ (fichier)
 2 / Akamai NetStorage
   \ (netstorage)
 3 / Alias for an existing remote
   \ (alias)
 4 / Amazon S3 Compliant Storage Providers including AWS, Alibaba, ArvanCloud, Ceph, ChinaMobile, Cloudflare, DigitalOcean, Dreamhost, Exaba, FlashBlade, GCS, HuaweiOBS, IBMCOS, IDrive, Intercolo, IONOS, LyveCloud, Leviia, Liara, Linode, Magalu, Mega, Minio, Netease, Outscale, OVHcloud, Petabox, RackCorp, Rclone, Scaleway, SeaweedFS, Selectel, SpectraLogic, StackPath, Storj, Synology, TencentCOS, Wasabi, Qiniu, Zata and others
   \ (s3)
 5 / Backblaze B2
   \ (b2)
 6 / Better checksums for other remotes
   \ (hasher)
 7 / Box
   \ (box)
 8 / Cache a remote
   \ (cache)
 9 / Citrix Sharefile
   \ (sharefile)
10 / Cloudinary
   \ (cloudinary)
11 / Combine several remotes into one
   \ (combine)
12 / Compress a remote
   \ (compress)
13 / DOI datasets
   \ (doi)
14 / Dropbox
   \ (dropbox)
15 / Encrypt/Decrypt a remote
   \ (crypt)
16 / Enterprise File Fabric
   \ (filefabric)
17 / FTP
   \ (ftp)
18 / FileLu Cloud Storage
   \ (filelu)
19 / Files.com
   \ (filescom)
20 / Gofile
   \ (gofile)
21 / Google Cloud Storage (this is not Google Drive)
   \ (google cloud storage)
22 / Google Drive
   \ (drive)
23 / Google Photos
   \ (google photos)
24 / HTTP
   \ (http)
25 / Hadoop distributed file system
   \ (hdfs)
26 / HiDrive
   \ (hidrive)
27 / ImageKit.io
   \ (imagekit)
28 / In memory object storage system.
   \ (memory)
29 / Internet Archive
   \ (internetarchive)
30 / Jottacloud
   \ (jottacloud)
31 / Koofr, Digi Storage and other Koofr-compatible storage providers
   \ (koofr)
32 / Linkbox
   \ (linkbox)
33 / Local Disk
   \ (local)
34 / Mail.ru Cloud
   \ (mailru)
35 / Mega
   \ (mega)
36 / Microsoft Azure Blob Storage
   \ (azureblob)
37 / Microsoft Azure Files
   \ (azurefiles)
38 / Microsoft OneDrive
   \ (onedrive)
39 / OpenDrive
   \ (opendrive)
40 / OpenStack Swift (Rackspace Cloud Files, Blomp Cloud Storage, Memset Memstore, OVH)
   \ (swift)
41 / Oracle Cloud Infrastructure Object Storage
   \ (oracleobjectstorage)
42 / Pcloud
   \ (pcloud)
43 / PikPak
   \ (pikpak)
44 / Pixeldrain Filesystem
   \ (pixeldrain)
45 / Proton Drive
   \ (protondrive)
46 / Put.io
   \ (putio)
47 / QingCloud Object Storage
   \ (qingstor)
48 / Quatrix by Maytech
   \ (quatrix)
49 / SMB / CIFS
   \ (smb)
50 / SSH/SFTP
   \ (sftp)
51 / Sia Decentralized Cloud
   \ (sia)
52 / Storj Decentralized Cloud Storage
   \ (storj)
53 / Sugarsync
   \ (sugarsync)
54 / Transparently chunk/split large files
   \ (chunker)
55 / Uloz.to
   \ (ulozto)
56 / Union merges the contents of several upstream fs
   \ (union)
57 / Uptobox
   \ (uptobox)
58 / WebDAV
   \ (webdav)
59 / Yandex Disk
   \ (yandex)
60 / Zoho
   \ (zoho)
61 / iCloud Drive
   \ (iclouddrive)
62 / premiumize.me
   \ (premiumizeme)
63 / seafile
   \ (seafile)
Storage> iclouddrive

Option region.
Region for iCloud endpoints.
Choose a number from below, or type in an existing value of type string.
Press Enter for the default (global).
 1 / Global (default)
   \ (global)
 2 / China Mainland
   \ (chinamainland)
region> 2

Option apple_id.
Apple ID.
Enter a value.
apple_id> 86xxxxxxxxxxx

Option password.
Password.
Choose an alternative below.
y) Yes, type in my own password
g) Generate random password
y/g> y
Enter the password:
password:
Confirm the password:
password:

Edit advanced config?
y) Yes
n) No (default)
y/n> n

Option config_2fa.
Two-factor authentication: please enter your 2FA code
Enter a value.
config_2fa> xxxxxx

Configuration complete.
Options:
- type: iclouddrive
- region: chinamainland
- apple_id: 86xxxxxxxxxxx
- password: *** ENCRYPTED ***
- cookies: X-APPLE-WEBAUTH-HSA-TRUST=xxxxxxxxxx;
- trust_token: XXXXXXXX
Keep this "icloudcn" remote?
y) Yes this is OK (default)
e) Edit this remote
d) Delete this remote
y/e/d> y

Current remotes:

Name                 Type
====                 ====
icloudcn             iclouddrive

e) Edit existing remote
n) New remote
d) Delete remote
r) Rename remote
c) Copy remote
s) Set configuration password
q) Quit config
e/n/d/r/c/s/q> q

~/Repo/rclone region-icloud-8257* ⇣ 1m 12s
base ❯ ./rclone-gcbd --config /tmp/rclone-cn/rclone.conf lsd icloudcn:
    23024227 2000-01-01 08:00:00        -1 Downloads
~/Repo/rclone region-icloud-8257* ⇣
base ❯ ./rclone-gcbd --config /tmp/rclone-cn/rclone.conf copy notes.txt icloudcn:Downloads/

~/Repo/rclone region-icloud-8257* ⇣
base ❯ ./rclone-gcbd --config /tmp/rclone-cn/rclone.conf cat icloudcn:Downloads/notes.txt    
Change lsd command so it doesn't show -1
  * Make sure all Fses show -1 for objects Zero for dates, etc.
  * Make test?

Put the TestRemote names into the Fs description
Make fs/test_all.go use the TestRemote name automatically

Get rid of Storable?

Todo
  * FIXME: More -dry-run checks for object transfer
  * Might be quicker to check md5sums first? for swift <-> swift certainly, and maybe for small files
  * FIXME Make NewFs to return err.IsAnObject so can put the LimitedFs
    creation in common code? Or try for as much as possible?
  * FIXME Account all the transactions (ls, etc.) using a different
    Roundtripper wrapper which wraps the transactions?

Ideas
  * could do encryption - put IV into metadata?
  * optimise remote copy container to another container using remote
    copy if local is same as remote - use an optional Copier interface
  * support
      * sftp
      * scp
      * rsync over ssh
  * control times sync (which is slow with some remotes) with -a --archive flag?
  * Copy a glob pattern - could do with LimitedFs

Make an encryption layer.

This would layer over the source FS to
    * decrypt all gets
    * encrypt all puts
    * encrypt file names in list
    * decrypt them in list

Would like to be able to see unencrypted file names in remote though? How?  Or is that two encryption layers..?

Bugs
  * Non verbose - not sure number transferred got counted up? CHECK
  * When doing copy it recurses the whole of the destination FS which isn't necessary

~/Repo/rclone region-icloud-8257* ⇣
base ❯ vi /tmp/rclone-cn/rclone.conf



[icloudcn]
type = iclouddrive
region = chinamainland
apple_id = 86XXXXXXXXXXx
password = xxxxxxxxxxxxx
cookies = X-APPLE-WEBAUTH-HSA-TRUST=XXXXXX
trust_token = XXXXXX

@timerring

Copy link
Copy Markdown
Author

Wait a moment. I will revise the corresponding document.

@timerring

Copy link
Copy Markdown
Author

All done, request for review. Thanks @ncw

mikegillan pushed a commit to mikegillan/rclone that referenced this pull request Mar 31, 2026
This fixes China mainland iCloud authentication by deriving the Origin
and Referer headers from authEndpoint instead of hardcoding idmsa.apple.com.

Fixes compatibility with PR rclone#8818 (China region support) and PR rclone#9209
(SRP authentication).

Signed-off-by: Xiangzhe <[email protected]>
ncw pushed a commit to mikegillan/rclone that referenced this pull request Apr 2, 2026
This fixes China mainland iCloud authentication by deriving the Origin
and Referer headers from authEndpoint instead of hardcoding idmsa.apple.com.

Fixes compatibility with PR rclone#8818 (China region support) and PR rclone#9209
(SRP authentication).

Signed-off-by: Xiangzhe <[email protected]>
ncw pushed a commit that referenced this pull request Apr 2, 2026
This fixes China mainland iCloud authentication by deriving the Origin
and Referer headers from authEndpoint instead of hardcoding idmsa.apple.com.

Fixes compatibility with PR #8818 (China region support) and PR #9209
(SRP authentication).

Signed-off-by: Xiangzhe <[email protected]>
@xz-dev

xz-dev commented May 3, 2026

Copy link
Copy Markdown
Contributor

I had create a PR for fix the conflicts

ferferga pushed a commit to ferferga/rclone that referenced this pull request Oct 6, 2026
This fixes China mainland iCloud authentication by deriving the Origin
and Referer headers from authEndpoint instead of hardcoding idmsa.apple.com.

Fixes compatibility with PR rclone#8818 (China region support) and PR rclone#9209
(SRP authentication).

Signed-off-by: Xiangzhe <[email protected]>
@ncw

ncw commented Oct 14, 2026

Copy link
Copy Markdown
Member

Thanks for this PR, and sorry it sat so long without a reply.

There are now three PRs for China Mainland iCloud (#8257), and we're going to take #9995 forward. It detects the China domain automatically from Apple's login redirect, so no manual option is needed, and it switches every endpoint, including the OAuth redirect URI. This PR switches the endpoints by changing package globals. That would break a China remote and a global remote used in the same rclone process.

So I'm going to close this one. If you have a China account, testing #9995 would be a big help. Thanks again!

@ncw ncw closed this Oct 14, 2026
@timerring

Copy link
Copy Markdown
Author

Thanks for explaining the reasoning. I’m glad the project will improve, regardless of which implementation is chosen.

Btw, receiving substantive feedback after more than a year was a little disappointing. Timely communication would have been very much appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add iCloud GCBD (China Mainland) Option in iCloud Drive backend

3 participants