Skip to content

[BUG]Container crashes on startup with Missing apple_id field when no session exists #482

Closed

Description

@inboxcda

🐛 Container crashes on startup with Missing apple_id field when no session exists

📝 Description

When running mandarons/icloud-docker, the container consistently crashes during startup authentication with the following error:

P.s. Thank you for all your work on this. When it worked/works... I loved it!

icloudpy.exceptions.ICloudPyFailedLoginException:
('Invalid authentication token.', ICloudPyAPIResponseException('Missing apple_id field'))

This happens even in a completely clean environment where no session file exists.

The logs show:

Session file does not exist
Missing apple_id field
Invalid authentication token

🔁 Steps to reproduce

  1. Use a fresh Docker setup with persistent volumes:
volumes:
  - /config:/config
  - /icloud:/icloud
  1. Configure credentials:
app:
  credentials:
    username: "your_apple_id@email.com"
  1. Ensure no prior session exists:
rm -rf /config/session_data
rm -rf /home/abc/.local/*
  1. Start the container:
docker compose up

❌ Actual behavior

The container crashes immediately and loops:

Session file does not exist
Missing apple_id field
Invalid authentication token

The process restarts continuously.


✅ Expected behavior

When no session exists, the container should:

  • Fall back to username/password authentication
  • Trigger fresh Apple login flow (2FA prompt)
  • Create a new session file after successful login

🔍 Observations / possible root cause

It appears the application always attempts token authentication first:

_authenticate_with_token()

even when:

  • No session file exists
  • No valid token is available

This leads to a failure inside icloudpy:

ICloudPyAPIResponseException('Missing apple_id field')

It looks like an unhandled or invalid token state is being passed into the authentication flow, causing a crash before fallback authentication can occur.


🧪 Environment

  • Image: mandarons/icloud-drive:latest
  • Docker version: Docker version 29.6.0, build fb59821
  • OS: Linux Debian
  • UID/GID: 1000:1000
Image

Activity

  1. mandarons commented on Jul 17, 2026

    @mandarons
    Owner

    Please try the latest v1.26.0 release in clean environment.

  2. gerhardmayer-1974 commented on Jul 25, 2026

    @gerhardmayer-1974

    I hab the same problem a few days ago an also didnt find an error. Before it worked for weeks.
    My failure was the apple password. i changed it last week and i also changed it in the yaml, but didn't copypaste it - i typed it letter by letter and so i got one false. right one is I - false one is l .... big-i and little-L ... with the wrong password the docker crashes. as it corrected it i could do the 2FA without trouble

  3. epheterson commented on Sep 30, 2026

    @epheterson
    Contributor

    Since #529 (merged, in the next release), a rejected sign-in, like the mistyped password found above, no longer crashes the container into a restart loop. It logs the error, sends a notification, and retries with a backoff.

  4. mandarons commented on Oct 1, 2026

    @mandarons
    Owner

    Closed as fixed by #529 (merged 2026-09-24).

    The crash/restart loop is gone: sign-in failures no longer escape the sync loop. ICloudPyFailedLoginException — the wrapper icloudpy raises for exactly this response (Invalid authentication token. / Missing apple_id field) — is now caught and routed to an auth-error handler that logs the error, sends a notification, and retries with a backoff (30-minute floor, independent of retry_login_interval). The process no longer exits, so restart: unless-stopped can't produce the crash loop seen in the logs.

    The recovery path works as the issue's "expected behavior" describes: each retry re-attempts password sign-in, a successful login creates the session file, and 2FA runs when required — as confirmed in this thread once the mistyped password was corrected. If the sign-in is rejected (wrong password, throttling), the container now stays up, reports the error, and keeps retrying instead of restarting every few seconds.

    Same PR also fixed the sibling restart loop from an unreadable/missing config.yaml (the loop waits for the file instead of exiting).

  5. danwelcome commented on Oct 12, 2026

    @danwelcome

    FYI, for anyone else who has seen the Missing apple_id field error message recently, I saw this error message because my account was locked. I signed into icloud.com in my browser and unlocked my account and I was able to reauthenticate using the webui without any issues.

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

Metadata

Metadata

Assignees

Labels

awaiting-infoAwaiting more information to proceedbugSomething isn't working

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions