Skip to content

Codesigning the apphost on macOS should preserve entitlements #113707

Closed as not planned

Description

@akoeplinger

I noticed this today after an internal discussion on Teams related to dotnet/cli-lab#346.

When you publish a self-contained app on macOS today the apphost in the output directory doesn't contain any entitlements:

$ dotnet new console -o signtest
$ dotnet publish --self-contained

$ codesign -d --entitlements - --xml bin/Release/net9.0/osx-x64/publish/signtest
Executable=/Users/alexander/dev/test/signtest/bin/Release/net9.0/osx-x64/publish/signtest

contrast this to the apphost in the apphost pack:

$ codesign -d --entitlements - --xml /Users/alexander/.nuget/packages/microsoft.netcore.app.host.osx-x64/9.0.2/runtimes/osx-x64/native/apphost
Executable=/Users/alexander/.nuget/packages/microsoft.netcore.app.host.osx-x64/9.0.2/runtimes/osx-x64/native/apphost
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "https://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0"><dict><key>com.apple.security.cs.allow-dyld-environment-variables</key><true/><key>com.apple.security.cs.allow-jit</key><true/><key>com.apple.security.cs.debugger</key><true/><key>com.apple.security.cs.disable-library-validation</key><true/><key>com.apple.security.get-task-allow</key><true/></dict></plist>

This has the entitlements we embed during the runtime build from https://github.com/dotnet/runtime/blob/main/eng/native/entitlements.plist

It looks like the code in HostWriter.cs which gets invoked by the CreateAppHost msbuild task in the dotnet sdk to ad-hoc sign the binary doesn't preserve the entitlements.

This means that developers who want to sign the apphost using a real certificate and enable the hardened runtime option need to re-add the entitlements again which is not obvious, see dotnet/sdk#24337 which now also uses outdated entitlements compared to what we use nowadays. The list on the public docs page is outdated too: https://learn.microsoft.com/en-us/dotnet/core/install/macos-notarization-issues#default-entitlements

Activity

  1. dotnet-policy-service commented on Mar 19, 2025

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @vitek-karas, @agocke
    See info in area-owners.md if you want to be subscribed.

  2. agocke commented on Mar 20, 2025

    @agocke
    Member

    I believe this is supposed to be identical to what comes out of macOS ad-hoc codesign. Is that true? Or are they different?

  3. akoeplinger commented on Mar 20, 2025

    @akoeplinger
    MemberAuthor

    it depends on the option, codesign has --preserve-metadata=entitlements which does that

  4. added this to the 10.0.0 milestone on Mar 20, 2025
  5. removed
    untriagedNew issue has not been triaged by the area owner
    on Mar 20, 2025
  6. am11 commented on Mar 26, 2025

    @am11
    Member

    It looks like the code in HostWriter.cs which gets invoked by the CreateAppHost msbuild task in the dotnet sdk to ad-hoc sign the binary doesn't preserve the entitlements.

    Is it a regression from .NET 9? The code you are referring to was added in .NET 10: #108992, and the second part is in progress #110417.

    cc @jtschuster @filipnavara

  7. akoeplinger commented on Mar 26, 2025

    @akoeplinger
    MemberAuthor

    no it's not a regression. in net9 we used the codesign tool directly but didn't pass the --preserve-metadata=entitlements either

  8. modified the milestones: 10.0.0, Future on Mar 31, 2025
  9. jtschuster commented on May 15, 2025

    @jtschuster
    Member

    Investigated an issue today that wound up being due to this. I'll look into how much this would take to implement in the manager signer.

  10. linked a pull request that will close this issuePreserve entitlements in MacOS signer #115800on Jun 3, 2025
  11. modified the milestones: Future, 11.0.0 on Sep 22, 2025
  12. agocke commented on Nov 20, 2025

    @agocke
    Member

    We've decided not to implement this. For local development we want to enable debugging entitlements, but those entitlements are not desirable for release. Instead, we've created documentation on which entitlements are needed for minimal .NET functionality at https://learn.microsoft.com/en-us/dotnet/core/deploying/macos

  13. locked and limited conversation to collaborators on Dec 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions