macOS: Can an XPC audit token prove that a peer belongs to a specific launchd job instance?

I'm designing a security-sensitive macOS service using a protected launchd daemon and a separate bootstrap supervisor.

The daemon's executable and launchd plist are intended to be protected from modification by unprivileged users. The job uses a SpawnConstraint to restrict which signed executable launchd may start.

During the initial XPC handshake, the supervisor must determine whether the sender is the current process launched by one specific launchd job, rather than another independently started process running the same signed executable.

I understand that:

  • Spawn constraints restrict the executable that launchd may start.
  • XPC peer code-signing requirements can authenticate a sender's code identity.
  • A valid signature, Team ID, audit token or PID alone does not necessarily establish the sender's originating launchd job or current launch instance.

My question:

Is there a supported public macOS API or documented mechanism that allows a receiver to verify that the sender of an XPC message belongs to a specific launchd job label and its current launch instance, with OS-backed evidence rather than application-supplied claims?

If not, is this association intentionally unavailable through public APIs? What architecture does Apple recommend when the receiver must distinguish a launchd-managed daemon from another process running the same signed executable?

I'm particularly interested in avoiding PID-reuse races and avoiding the disclosure of authorization material before the peer is authenticated.

I'm looking for a supported design, not private APIs or undocumented launchctl behavior.

Thank you.

Answered by DTS Engineer in 917869022

It sounds like you’d be well served by Authorization Services:

  1. Define a custom authorisation right for this task, one that requires the user to enter admin credentials (AuthorizationRightSet).
  2. Have the supervisor request that right (AuthorizationCopyRights with kAuthorizationFlagInteractionAllowed and kAuthorizationFlagPreAuthorize).
  3. And then serialise their authorisation (AuthorizationMakeExternalForm) and pass it to your daemon.
  4. Have the daemon deserialise it (AuthorizationCreateFromExternalForm).
  5. And then confirm the authorisation (AuthorizationCopyRights again, this time without kAuthorizationFlagPreAuthorize and kAuthorizationFlagInteractionAllowed, but with kAuthorizationFlagExtendRights).

If that last steps succeeds, your daemon knows that the request came from a process that has received authorisation from the user.

Note that Authorization Services is not well covered by the standard documentation. You will have to dig into the Documentation Archive to find:

Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

I'm designing a security-sensitive macOS service using a protected launchd daemon and a separate bootstrap supervisor.

So these are both launchd daemons?

Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Thank you, Quinn.

No, not in the currently proposed architecture.

The protected Root service is intended to be a launchd-managed daemon with a SpawnConstraint.

The separate bootstrap supervisor is intended to be a protected, one-shot native executable invoked only after explicit owner authorization and macOS administrator authentication. It is not intended to be a second launchd daemon.

The supervisor would request that launchd start the specific protected Root job. This architecture is still a design proposal, not a deployed or verified implementation.

The unresolved question is how to establish an OS-backed association between the current launchd job instance and the XPC peer during the initial handshake, without relying solely on PID, code-signing identity, or application-supplied claims.

If that association is not available through supported public APIs, what architecture would Apple recommend for establishing a secure initial communication channel?

Thank you for your guidance.

The separate bootstrap supervisor is intended to be a protected, one-shot native executable invoked only after explicit owner authorization and macOS administrator authentication.

Invoked by who? Or what?

Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Thank you, Quinn.

The intended invoker is the human Mac owner, acting interactively from a local Terminal session after explicitly authorizing a single bootstrap operation.

The proposed bootstrap supervisor is a protected, one-shot native executable invoked through a standard macOS administrator authorization mechanism. The exact invocation mechanism has not yet been selected; sudo is only one option under consideration.

It is not intended to be a persistent daemon or another launchd-managed service.

The supervisor would then request launchd to start a specific, preconfigured system LaunchDaemon whose executable and configuration are protected against modification by unprivileged users.

The unresolved issue is establishing a trusted initial communication channel that binds the supervisor to the current instance of that specific launchd job, allowing an anonymous XPC endpoint to be transferred securely without introducing a named Mach service or persistent broker.

Is there a supported public macOS mechanism for this, or would Apple recommend a different bootstrap architecture?

Thank you for your guidance.

It sounds like you’d be well served by Authorization Services:

  1. Define a custom authorisation right for this task, one that requires the user to enter admin credentials (AuthorizationRightSet).
  2. Have the supervisor request that right (AuthorizationCopyRights with kAuthorizationFlagInteractionAllowed and kAuthorizationFlagPreAuthorize).
  3. And then serialise their authorisation (AuthorizationMakeExternalForm) and pass it to your daemon.
  4. Have the daemon deserialise it (AuthorizationCreateFromExternalForm).
  5. And then confirm the authorisation (AuthorizationCopyRights again, this time without kAuthorizationFlagPreAuthorize and kAuthorizationFlagInteractionAllowed, but with kAuthorizationFlagExtendRights).

If that last steps succeeds, your daemon knows that the request came from a process that has received authorisation from the user.

Note that Authorization Services is not well covered by the standard documentation. You will have to dig into the Documentation Archive to find:

Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Thank you, Quinn. Your Authorization Services recommendation is helpful.

I understand that the daemon's final AuthorizationCopyRights check verifies user authorization. However, it does not appear to authenticate the daemon itself to the supervisor.

AuthorizationMakeExternalForm requires securely transferring the authorization reference to the receiving process.

Our proposed architecture has:

  • A protected, one-shot supervisor invoked by the Mac owner.
  • A fixed system LaunchDaemon with a SpawnConstraint.
  • No named Mach service or persistent broker.

Before disclosing the external authorization form, how can the supervisor establish that its initial communication peer is the current instance of the intended launchd job, rather than another process running the same signed executable?

Is there a supported public macOS mechanism for this binding?

If not, does your recommended approach require changing our initial rendezvous architecture—for example, introducing a named Mach service or another system-supported communication mechanism?

I want to avoid transferring authorization material to an unauthenticated peer.

Thank you for your guidance.