Skip to content

ak-sysd: keep the file fallback unless the keyring token reads back - #1360

Open
PeshekDotDev wants to merge 1 commit into
mainfrom
fix/sysd-keychain-readback
Open

ak-sysd: keep the file fallback unless the keyring token reads back#1360
PeshekDotDev wants to merge 1 commit into
mainfrom
fix/sysd-keychain-readback

Conversation

@PeshekDotDev

Copy link
Copy Markdown
Contributor

Details

What does this PR change?

save_domain cleared fallback_token whenever the keyring write returned Ok. It now also reads the value back, and only drops the on-disk copy if the read succeeds and matches.

Why is this change needed?

On macOS the write succeeds from a launchd daemon but the read fails with errSecInteractionNotAllowed — retrieving the item wants an ACL prompt and a root daemon has no UI session to show one:

failed load domain token from keyring, falling back to file:
    Other(User interaction is not allowed. ak-platform-keyring/src/macos.rs:72:47)

Because the write looked fine, fallback_token was blanked, so resolve_token fell back to an empty string. Every request then went out as Bearer+agent and came back:

403 {"detail":"Authentication credentials were not provided."}

The effect is that any successful ak-sysd domains join leaves the device token somewhere sysd can never read, and authentication breaks on the next restart. Observed repeatedly on macOS 26.6; the token had to be written into domains/<name>.json by hand each time to recover.

DomainConfig::fallback_token is documented as "Only present in the JSON file if the keyring is unavailable" — a keyring that can be written but not read is unavailable for this purpose, so this restores the intended behaviour rather than adding a new one.

How was this tested?

cargo check -p ak-sysd. Verified against a live macOS 26.6 host: domains join succeeds, the keychain item is created, and the read-back fails — with this change the token stays in the JSON file and sysd authenticates after a restart instead of 403ing.

Linked issues

Found alongside two other macOS regressions from the Rust migration (#1262): the PSSO :authority rejection and active() selecting a token-less domain.

Checklist

  • The project has been linted, built, and tested (make all)
  • The documentation has been updated and formatted (make docs)

@codecov

codecov Bot commented Aug 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 42.81%. Comparing base (bb7fd33) to head (1bf3f35).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
ak-sysd/src/cfg/domain.rs 0.00% 12 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1360      +/-   ##
==========================================
- Coverage   42.84%   42.81%   -0.04%     
==========================================
  Files         161      161              
  Lines       14706    14717      +11     
  Branches     9721     9732      +11     
==========================================
  Hits         6301     6301              
- Misses       8270     8281      +11     
  Partials      135      135              
Flag Coverage Δ
rs-e2e 36.23% <0.00%> (-0.04%) ⬇️
rs-macos-26-ak-agent 31.70% <ø> (-2.11%) ⬇️
rs-macos-26-ak-agent-desktop 0.00% <ø> (ø)
rs-macos-26-ak-api-cli-gen 66.71% <ø> (ø)
rs-macos-26-ak-browser-support 24.19% <ø> (ø)
rs-macos-26-ak-cli 11.92% <ø> (ø)
rs-macos-26-ak-platform 0.29% <ø> (ø)
rs-macos-26-ak-platform-facts 83.96% <ø> (ø)
rs-macos-26-ak-sysd 34.73% <0.00%> (-0.17%) ⬇️
rs-ubuntu-24.04-ak-agent 33.81% <ø> (ø)
rs-ubuntu-24.04-ak-agent-desktop 0.00% <ø> (ø)
rs-ubuntu-24.04-ak-api-cli-gen 66.71% <ø> (ø)
rs-ubuntu-24.04-ak-browser-support 24.19% <ø> (ø)
rs-ubuntu-24.04-ak-cli 11.92% <ø> (ø)
rs-ubuntu-24.04-ak-nss 77.37% <ø> (ø)
rs-ubuntu-24.04-ak-pam 0.00% <ø> (ø)
rs-ubuntu-24.04-ak-platform 0.29% <ø> (ø)
rs-ubuntu-24.04-ak-platform-facts 83.14% <ø> (ø)
rs-ubuntu-24.04-ak-sysd 34.84% <0.00%> (-0.17%) ⬇️
rs-ubuntu-24.04-arm-ak-agent 31.70% <ø> (ø)
rs-ubuntu-24.04-arm-ak-agent-desktop 0.00% <ø> (ø)
rs-ubuntu-24.04-arm-ak-api-cli-gen 66.71% <ø> (ø)
rs-ubuntu-24.04-arm-ak-browser-support 24.19% <ø> (ø)
rs-ubuntu-24.04-arm-ak-cli 11.92% <ø> (ø)
rs-ubuntu-24.04-arm-ak-nss 77.37% <ø> (ø)
rs-ubuntu-24.04-arm-ak-pam 0.00% <ø> (ø)
rs-ubuntu-24.04-arm-ak-platform 0.29% <ø> (ø)
rs-ubuntu-24.04-arm-ak-platform-facts 83.14% <ø> (ø)
rs-ubuntu-24.04-arm-ak-sysd 34.84% <0.00%> (-0.17%) ⬇️
rs-windows-2025-ak-agent 31.70% <ø> (-2.11%) ⬇️
rs-windows-2025-ak-agent-desktop 0.00% <ø> (ø)
rs-windows-2025-ak-api-cli-gen 66.71% <ø> (ø)
rs-windows-2025-ak-browser-support 24.19% <ø> (ø)
rs-windows-2025-ak-cli 11.92% <ø> (ø)
rs-windows-2025-ak-platform 0.30% <ø> (ø)
rs-windows-2025-ak-platform-facts 79.37% <ø> (-0.24%) ⬇️
rs-windows-2025-ak-sysd 33.03% <0.00%> (-0.16%) ⬇️
swift 3.41% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@authentik-automation

Copy link
Copy Markdown
Contributor

🚀 Deployed on https://pr-1360--authentik-pkg.netlify.app

@PeshekDotDev
PeshekDotDev force-pushed the fix/sysd-keychain-readback branch from 75d0914 to 1bf3f35 Compare August 12, 2026 06:09
@authentik-automation
authentik-automation Bot temporarily deployed to pull request August 12, 2026 06:44 Inactive
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.

1 participant