Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@timerring
Copy link

@timerring timerring commented Sep 12, 2025

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
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
Author

Wait a moment. I will revise the corresponding document.

@timerring
Copy link
Author

All done, request for review. Thanks @ncw

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

1 participant