Skip to content

ak-sysd: read managed preferences via CFPreferences, not defaults(1) - #1361

Merged
BeryJu merged 1 commit into
mainfrom
fix/sysd-managed-prefs
Aug 12, 2026
Merged

ak-sysd: read managed preferences via CFPreferences, not defaults(1)#1361
BeryJu merged 1 commit into
mainfrom
fix/sysd-managed-prefs

Conversation

@PeshekDotDev

Copy link
Copy Markdown
Contributor

Details

What does this PR change?

load_managed_config on macOS no longer shells out to defaults read io.goauthentik.platform. It calls CFPreferencesCopyAppValue, gated on CFPreferencesAppValueIsForced.

Why is this change needed?

defaults read <app-id> does not resolve the MDM-managed preferences layer. On a host with the profile installed:

$ sudo defaults read io.goauthentik.platform URL
Domain io.goauthentik.platform does not exist

$ sudo defaults read "/Library/Managed Preferences/io.goauthentik.platform" URL
https://authentik.connorpeshek.me/

So load_managed_config returned None and load_managed bailed on its first line — MDM-driven enrollment has been a silent no-op on macOS since the migration to Rust. There is no error; the machine simply never enrolls.

The existing comment anticipated this:

defaults read resolves the same preferences domain that Go's CFPreferencesCopyAppValue call reads from. […] if strict merging of the MDM-managed preferences layer (as opposed to this host's local preferences) turns out to matter, replace this with a direct CFPreferencesCopyAppValue call instead.

It turns out to matter. CFPreferencesCopyAppValue consults the managed layer; defaults read by app-id does not.

The IsForced guard is deliberate. CopyAppValue returns the effective value, which can come from ordinary user defaults. This value decides which authentik instance a root daemon enrolls against, so only MDM-delivered values are accepted.

core-foundation was already vendored via ak-platform-keyring, and core-foundation-sys already ships both bindings, so no hand-written FFI is needed.

How was this tested?

cargo check -p ak-sysd. Both functions were exercised against the live managed profile on a macOS 26.6 host via ctypes, as connor and as root:

URL                  IsForced=True  value=https://authentik.connorpeshek.me/
RegistrationToken    IsForced=True  value=<60 chars>

Both resolve, and both report as forced — where defaults read reports the domain does not exist.

Ordering note

This should land after #1359. Once managed enrollment starts working again, machines that also have a user-enrolled domain will have two, and #1359 is what makes the choice between them deterministic (managed wins) and cleans up stale managed domains. Merging this first would turn a silent no-op into a nondeterministic choice of authentik instance.

Linked issues

One of several macOS regressions found alongside the Rust migration (#1262), with #1358, #1359 and #1360.

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 33.33333% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 42.84%. Comparing base (bb7fd33) to head (a8f817c).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
ak-sysd/src/cfg/managed.rs 33.33% 13 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1361      +/-   ##
==========================================
- Coverage   42.84%   42.84%   -0.01%     
==========================================
  Files         161      161              
  Lines       14706    14715       +9     
  Branches     9721     9730       +9     
==========================================
+ Hits         6301     6304       +3     
- Misses       8270     8277       +7     
+ Partials      135      134       -1     
Flag Coverage Δ
rs-e2e 36.30% <ø> (+0.02%) ⬆️
rs-macos-26-ak-agent 33.81% <ø> (ø)
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.76% <33.33%> (-0.14%) ⬇️
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 35.00% <ø> (ø)
rs-ubuntu-24.04-arm-ak-agent 33.81% <ø> (+2.10%) ⬆️
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 35.00% <ø> (ø)
rs-windows-2025-ak-agent 33.81% <ø> (ø)
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.61% <ø> (ø)
rs-windows-2025-ak-sysd 33.18% <ø> (ø)
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-1361--authentik-pkg.netlify.app

@authentik-automation
authentik-automation Bot temporarily deployed to pull request August 12, 2026 00:37 Inactive
@PeshekDotDev
PeshekDotDev force-pushed the fix/sysd-managed-prefs branch from 703950d to a8f817c Compare August 12, 2026 06:10
@authentik-automation
authentik-automation Bot temporarily deployed to pull request August 12, 2026 06:47 Inactive
@BeryJu
BeryJu merged commit 39194a9 into main Aug 12, 2026
90 of 91 checks passed
@BeryJu
BeryJu deleted the fix/sysd-managed-prefs branch August 12, 2026 10:23
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.

2 participants