Skip to content

iclouddrive: add iCloud Photos support and SRP authentication - #9234

Merged
ncw merged 13 commits into
rclone:masterfrom
Lyapsus:icloud-photos
Apr 27, 2026
Merged

ncw merged 13 commits into
rclone:masterfrom
Lyapsus:icloud-photos

Conversation

@Lyapsus

@Lyapsus Lyapsus commented Mar 5, 2026 •

Copy link
Copy Markdown
Contributor

What is the purpose of this change?

Add read-only iCloud Photos support to the existing iclouddrive backend via service = photos config option. Also includes auth improvements on top of #9209's SRP authentication.

Photos features:

  • 3-level hierarchy: libraries (Personal + Shared Photo Library) → albums → photos/videos
  • 14 server-side smart albums (All Photos, Videos, Favorites, Screenshots, Live, Bursts, Panoramas, Slo-mo, Time-lapse, Portrait, Long Exposure, Animated, Hidden, Recently Deleted)
  • User-created albums and nested album folders
  • Live Photo .MOV companions as first-class entries
  • Edited photo versions (-edited suffix) and RAW alternatives
  • Duplicate filename dedup for camera counter wrap collisions
  • Parallel cold listing for large albums
  • Delta sync via CloudKit changes/zone — warm listings near-instant from disk cache
  • Disk cache (libraries, albums, photos) with atomic writes for crash safety
  • ChangeNotify support for FUSE mounts via changes/zone polling
  • ListR support for --fast-list and recursive operations
  • --metadata support — width, height, added-time, favorite, hidden
  • Fresh download URLs per file — no stale URL failures on long copies
  • FUSE mount documentation with recommended flags

Auth improvements over #9209:

  • SMS 2FA fallback for users without trusted Apple devices
  • Explicit push notification request — fixes iOS/macOS 26.4+ where 409 no longer auto-pushes
  • Thread safety for concurrent FUSE callers (mutexes on session and client state)
  • Session endpoint caching — skips ~5s /validate round-trip on warm start
  • Disconnect support — clears auth state + disk cache
  • PCS cookie support for Advanced Data Protection accounts, including trusted-device approval for PCS cookies

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

Credits

Built on @coughlanio's Photos PoC (#8734) and @mikegillan's SRP auth (#9209).

Test plan

  • golangci-lint run — 0 issues
  • go build / go vet / gofmt — clean
  • Unit tests: SRP crypto, Photos backend, CloudKit API — smart album classification, delta sync parsing, disk cache, dedup, metadata, SRP error paths
  • 36-check live smoke test against my own iCloud account:
    • Libraries: PrimarySync + SharedSync listed
    • Albums: 207 albums, smart albums verified, album folders
    • Photos: 708 videos listed, byte-identical download
    • Live Photos: 548 entries (269 MOV companions), MOV download verified
    • Edited photos: 609 -edited entries, JPEG + MOV edited downloads
    • RAW: 52k entries, RAW+JPEG and RAW+HEIC pairs, DNG download verified
    • Shared library: albums listed, photo downloaded, delta sync cached
    • Delta sync: disk cache used, session endpoints cached
  • Tested by 5 users:
    • @stv0g — 100k photos, confirmed push 2FA fix works on macOS 26.4
    • @MatthewIsHere — 500GB synced to Immich
    • @Unbounded6106 — SMS 2FA confirmed working
    • @PinkSerenity — reconnect fix confirmed, relies on SMS 2FA
    • @clouedoc — ADP/PCS tested, cookie and album cache bugs reported and fixed

Known limitations

  • No Shared Albums support (legacy invite-style, different API — future work)
  • Cross-zone album merging: albums are per-zone in CloudKit. "Both Libraries" merging is a client-side Apple Photos feature. Users see separate album listings per library (workaround: union backend)

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 :-)

@Lyapsus Lyapsus mentioned this pull request Mar 7, 2026
4 of 5 tasks
@JoshPaterson

Copy link
Copy Markdown

Hi @Lyapsus, you asked me to look at this PR. I don't have any relationship with the Rclone project, are you looking for someone to test it?

@Lyapsus

Lyapsus commented Mar 11, 2026

Copy link
Copy Markdown
Contributor Author

Good evening @JoshPaterson, sorry for delay! Yes, would be helpful to have a bit of testing if you have time.
Primary commands would be:

  • rclone lsd remote:
  • rclone lsd remote:PrimarySync/
  • rclone ls remote:PrimarySync/<album>/
  • rclone copy remote:PrimarySync/<album>/<file> .

If you have Shared Photo Library enabled, these would be also interesting:

  • rclone lsd remote:SharedSync-.../
  • rclone ls remote:SharedSync-.../"All Photos"/
  • rclone copy remote:SharedSync-.../"All Photos"/<file> .

@MatthewIsHere

Copy link
Copy Markdown

Hi! I've been testing this for a few hours, and it works fantastic! All the features work well, but FUSE mounts are pretty sluggish. Excellent work :)

@Lyapsus

Lyapsus commented Mar 19, 2026

Copy link
Copy Markdown
Contributor Author

Glad to hear, thank you for trying! Regarding FUSE: the web API sadly has no way to query photos by name, so full album enumeration is unavoidable on first access (I feel it too with my 75k library). After that, rclone's VFS dir cache should keep it fast for 5 minutes by default

@Lyapsus
Lyapsus force-pushed the icloud-photos branch 2 times, most recently from 1eede77 to ceee858 Compare March 20, 2026 13:07
@Lyapsus

Lyapsus commented Mar 20, 2026

Copy link
Copy Markdown
Contributor Author

@ncw @stv0g @poolpOrg @lifenautjoe - you may want to look

@stv0g

stv0g commented Mar 23, 2026

Copy link
Copy Markdown

Hi @Lyapsus,

Thanks! This is working great so far for me :)

My observations:

  • All basic functionality works ✅
    • I test both my personal as well as a shared library.
    • I have around 100k photos in my library and it is able to handle them.
    • Also corner cases such as a / in an album name seems to be supported well.
  • Many operations are fairly slow ⚠️
    • Looking at the debug trace, it appears to me that the initial validation of the session takes about 5 seconds, before any subsequent request is performed?
    • As there are no albums in the shared library, listing all photos in the shared library can be painfully slow.. But it still works :)
  • I did not had any luck with accessing albums which are grouped in an folder ❌
    • The folder appears as a directory in the directory structure
    • But this folder is simply empty.

@Lyapsus

Lyapsus commented Mar 26, 2026

Copy link
Copy Markdown
Contributor Author

@stv0g Thank you very much for looking into it. I think everything must be much snappier now and albums in folders are now accessible too

@Lyapsus

Lyapsus commented Mar 26, 2026

Copy link
Copy Markdown
Contributor Author

@MatthewIsHere thank you again! You may want to try FUSE again - warm listings should be much faster now. Also recommended to use --vfs-refresh --dir-cache-time 1h --vfs-cache-mode full with it. The cold initial listings of very large albums are still fairly slow but from now on it will happen only once per album and cache will handle the rest

@MatthewIsHere

Copy link
Copy Markdown

Yeah I notice a significant improvement. This is fantastic!! I've already used it to sync a half terabyte of photos and videos to an Immich photo server.

The only issue I've had with it is using Rclone sync to download the entire photos main directory causes X number of duplicates of a photo/video stored in multiple albums. I'm not sure if that's solvable on Rclone's side, but I currently use a script to recursively hard link any photos with the same exact filename (I think it's unique right?)

@Lyapsus

Lyapsus commented Mar 26, 2026

Copy link
Copy Markdown
Contributor Author

Hmm sounds like smart albums to me? Like one video can be in All photos, Videos and Favorites at the same time, for example

@MatthewIsHere

Copy link
Copy Markdown

Yes, it was partly smart albums, but I believe it also happens when a photo is in All Photos and another (non shared) album.

@Lyapsus

Lyapsus commented Mar 26, 2026

Copy link
Copy Markdown
Contributor Author

That's how it works in original Photos app and web version of Photos I believe. I use Google Photos backend as a reference and I see them doing nothing with the same behavior so I'm a bit hesitant about adding some kind of config for alternative behavior and how it would look. Ideas?

@MatthewIsHere

MatthewIsHere commented Mar 26, 2026 •

Copy link
Copy Markdown

That's just fine. The only thing I could think of would be a folder that contained all images pulled from the database, so that you could sync that folder and then run a script to symlink all the other folders of images to the main synced directory. That's how I use All Photos now. I think the only exception for All Photos on iCloud is that Hidden is not included.

@stv0g

stv0g commented Mar 27, 2026

Copy link
Copy Markdown

@Lyapsus thanks for the improvements!

I can confirm that albums in folders now also properly work! And overall speed also improved thanks to the additional caching. I love it!

@ncw Do you see any other blockers to get this merged? We now have two testers who provided feedback and testing.

@stv0g

stv0g commented Mar 27, 2026

Copy link
Copy Markdown

@Lyapsus @MatthewIsHere I am planning to use this new backend together with git-annex which performs hash-based deduplication via symlinks for me. So its quite similar to your hardlink-based approach.

Still its a bit sub optimal to fetch those photos multiple times :-/
I assume rclone's backend API does not allow for creating hardlinks directly?

@Lyapsus
Lyapsus force-pushed the icloud-photos branch 4 times, most recently from a93691d to 04320da Compare March 28, 2026 19:12
@Unbounded6106

Copy link
Copy Markdown

@Lyapsus

Thanks, I tested again on the latest #9234 head.

Built on Windows for Linux amd64, then tested on Unraid with:

./rclone config reconnect icloud: -vv

Relevant log:

2026/03/28 10:28:30 DEBUG : rclone: Version "v1.74.0-DEV-pr9234-latest" starting with parameters ["./rclone" "config" "reconnect" "icloud:" "-vv"]
2026/03/28 10:28:30 DEBUG : Using config file from "/mnt/user/appdata/rclone/rclone.conf"
2026/03/28 10:28:30 DEBUG : icloud: config in: state="", result=""
2026/03/28 10:28:30 DEBUG : iclouddrive: authenticating as
2026/03/28 10:28:31 DEBUG : iclouddrive: SRP sign in requires 2FA
2026/03/28 10:28:31 DEBUG : Saving config "cookies" in section "icloud" of the config file
2026/03/28 10:28:31 DEBUG : icloud: config out: out=&{State:2fa_do Option: OAuth: Error: Result:}, err=
2026/03/28 10:28:31 DEBUG : icloud: config: reading config parameter "config_2fa"
Option config_2fa.
Two-factor authentication: enter your 2FA code or type 'sms' for a text message
Enter a value.
config_2fa> sms

2026/03/28 10:28:38 DEBUG : icloud: config in: state="2fa_do", result="sms"
2026/03/28 10:28:39 DEBUG : iclouddrive: SRP sign in requires 2FA
2026/03/28 10:28:39 DEBUG : icloud: config out: out=, err=no trusted phone numbers on this account
Error: no trusted phone numbers on this account
2026/03/28 10:28:39 NOTICE: Fatal error: no trusted phone numbers on this account

Additional note:

my Apple account does have a trusted phone number configured
if I try normal Apple/iCloud web sign-in, my account behaves normally
I still do not receive the verification code automatically on my trusted iPhone during this rclone flow

Let me know what you want me to test next.

@Lyapsus

Lyapsus commented Mar 29, 2026

Copy link
Copy Markdown
Contributor Author

@Unbounded6106, a bit strange, what’s your git log --oneline -1 ?
I’m extremely sorry, I believe it’s was a stale build. Could you try the latest commit again?

@Lyapsus
Lyapsus force-pushed the icloud-photos branch 2 times, most recently from c4cff25 to 624bfd6 Compare March 29, 2026 04:50
@Lyapsus

Lyapsus commented Apr 6, 2026 •

Copy link
Copy Markdown
Contributor Author

@clouedoc, could you try this one please?

@mburget

mburget commented Apr 6, 2026

Copy link
Copy Markdown

@Lyapsus : worked for me on macos 26.4 (25E246).
I was struggling to get icloud to work. #8587 (comment) helped to go one step further but still not getting the 2FA code. Your branch made it.

@Lyapsus

Lyapsus commented Apr 7, 2026 •

Copy link
Copy Markdown
Contributor Author

@ncw, sorry for delay. One can never be sure enough but that’s that reviews are for, right? I’ll be happy to address anything you are not happy with

Lyapsus added 10 commits April 9, 2026 18:19
Persist session state after initial SRP sign-in and restore it when
validating the 2FA code, instead of calling SignIn() again. Eliminates
a redundant SRP roundtrip (~5s) and an extra push notification on
pre-26.4 accounts.
Eliminate dead struct fields, conversion layers, and duplicated code.
Album uses direct Library pointer instead of PhotosService back-pointer.
GetPhotos serves from in-memory cache when populated, skipping disk I/O.
CloudKit stores album names verbatim without Unicode normalization.
Albums created from macOS (APFS/NSString) use NFD, while Linux
terminals send NFC, causing lookup misses on accented names.
@clouedoc

Copy link
Copy Markdown

@Lyapsus It's working for me now! Thanks a lot.

@Lyapsus

Lyapsus commented Apr 20, 2026

Copy link
Copy Markdown
Contributor Author

@clouedoc pleasure to me haha

@ncw

ncw commented Apr 24, 2026

Copy link
Copy Markdown
Member

@Lyapsus do you want to try to get this merged for v1.74? Is it ready to merge now?

Do you think this also fixes #9359

@Lyapsus

Lyapsus commented Apr 24, 2026

Copy link
Copy Markdown
Contributor Author

@ncw looks similar to after-party of #8587 to me at the first glance, would love to see how it goes with my version and surely wouldn't mind to get it merged if #9359 guys appear to be happy with it

@Lyapsus

Lyapsus commented Apr 27, 2026

Copy link
Copy Markdown
Contributor Author

@ncw, seems to fix it: #9359 (comment)

@ncw ncw left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've spent some time reviewing this and it looks very good indeed.

I shall merge this for v1.74 which should make the icloud users very happy to have working 2FA and photos access.

Thank you for your hard work @Lyapsus

@Lyapsus

Lyapsus commented Apr 27, 2026

Copy link
Copy Markdown
Contributor Author

Honor to me

@ncw
ncw merged commit d0c469c into rclone:master Apr 27, 2026
9 checks passed
@ryanwise

Copy link
Copy Markdown

Hi @Lyapsus, I've been watching this PR with baited breath and gleefully downloaded the latest merge (doc469c) to try it out. The setup proceeds as expected, my password and 2FA codes are accepted and the new config appears ready to use. However, trying a simple "rclone ls iphoto:" returns the following:

NOTICE: Failed to ls: query user albums for zone "CMM-4799B27A-3307-4C67-8CF3-A820E6275CFD": HTTP error 400 (400 Bad Request) returned body: "{\n \"uuid\" : \"4801965d-9a5b-418e-a974-20846e495f59\",\n \"serverErrorCode\" : \"BAD_REQUEST\",\n \"reason\" : \"Index has invalid data\",\n \"errorClass\" : \"BAD_REQUEST\",\n \"error\" : \"BAD_REQUEST\"\n}"

is this something with my iphoto account, or something with rclone? apologies if this is vague or not enough info, i'm fairly new to rclone.

@ryanwise

Copy link
Copy Markdown

update: looking like something with my iphoto account, maybe?. I can do "rclone lsd iphoto:" and get two directories listed, the CNM-4799B27A... one and one named "Primary Sync". it looks like i can access photos from Primary Sync, but any attempt to interact with the other one results in the error above. any ideas what's going on here? Thanks again for the PR, it's very helpful.

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.