Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wip] codesigning on Darwin #38624

Closed
wants to merge 21 commits into from

Conversation

matthewbauer
Copy link
Member

@matthewbauer matthewbauer commented Apr 8, 2018

This is the start on my quest to get codesign working on macOS. In the end this should close #37838, #18420, #17406 and maybe #15889 and #36223 (lots of other gatekeeper issues especially with jamf and other AVs).

The main thing is packaging "security_systemkeychain" which contains the source for codesign. There is some difficulty here in how Apple has left out a few important packages. We can kind of hack through it with @samdmarshall's OSXPrivateSDK. Probably can't/shouldn't redistribute "codesign" but hopefully still usable in "nativeBuildInputs".

Eventually, I want Hydra to start signing binaries for certain executables. Some that are definitely needed: (it might be useful for others too)

- git (for use with credentials-osxkeychain)
- gdb
- darwin.dtrace
- lldb

For this to work we will need to run codesign on certain binaries probably in a setup-hook. This is the man for codesign:

codesign -s identity [-i identifier] [-r requirements] [-fv] [path ...]

We will need an "identity" provided as a config option to Nixpkgs (default to "$CODE_SIGN_IDENTITY"). I'm not sure how we would get the identities on the Hydra machines but I think it would be useful for lots of users (although this would obviously break reproducibility).

To use this right now follow the steps 1-9 here https://gist.github.com/hlissner/898b7dfc0a3b63824a70e15cd0180154 giving the certificate the name "nixpkgs". Now you can use darwin.gdb and darwin.lldb.

Usage

You can start using this right now. Configuration is a little tricky so I will take a step by step approach.

  1. Open Keychain Access
  2. File -> New Keychain....
  3. Save keychain in your home directory with the name "nixpkgs".
  4. Choose a password that you are okay with leaving plaintext.
  5. In the menu, open Keychain Access > Certificate Assistant > Create a certificate
  6. Enter name "nixpkgs", Identity type "self-signed root" and Certificate type "Code signing". (Also check "Let me override defaults")
  7. Click continue until the "Specify a Location for the Certificate" opens. Select the "nixpkgs" keychain from the drop down.
  8. Find the created certificate and right click "Get Info".
  9. Under "Trust" select "Always Trust" (this part is optional)
  10. Add the following to the file at "$HOME/.config/nixpkgs/config.nix":
{
  keychain = {
    file = /Users/<USER>/nixpkgs.keychain;
    identity = "nixpkgs";
    password = "<PASSWORD>";
  };
}

@GrahamcOfBorg GrahamcOfBorg added the 6.topic: darwin Running or building packages on Darwin label Apr 8, 2018
@matthewbauer matthewbauer changed the title [preview] Darwin hacking [preview] codesigning on Darwin Apr 8, 2018
@GrahamcOfBorg
Copy link

Success on x86_64-linux (full log)

Attempted: antlr, pbzx, xcbuild

Partial log (click to expand)

checking for references to /tmp/nix-build-pbzx-1.0.2.drv-0 in /nix/store/rxgb0ci2f86sz0ymvx9572k84vwnjkf9-pbzx-1.0.2...
building path(s) ‘/nix/store/6m62s8qxkic44d9312ymgvym820fvjmm-MacOSX.platform’
building path(s) ‘/nix/store/20q5npx4zchlm4znzmlr86n3c3zkhbkf-xcbuild-wrapper-0.1.2-pre’
installing
post-installation fixup
shrinking RPATHs of ELF executables and libraries in /nix/store/20q5npx4zchlm4znzmlr86n3c3zkhbkf-xcbuild-wrapper-0.1.2-pre
strip is /nix/store/fzcs0fn6bb04m82frhlb78nc03ny3w55-binutils-2.28.1/bin/strip
stripping (with command strip and flags -S) in /nix/store/20q5npx4zchlm4znzmlr86n3c3zkhbkf-xcbuild-wrapper-0.1.2-pre/bin
patching script interpreter paths in /nix/store/20q5npx4zchlm4znzmlr86n3c3zkhbkf-xcbuild-wrapper-0.1.2-pre
checking for references to /tmp/nix-build-xcbuild-wrapper-0.1.2-pre.drv-0 in /nix/store/20q5npx4zchlm4znzmlr86n3c3zkhbkf-xcbuild-wrapper-0.1.2-pre...

@GrahamcOfBorg
Copy link

Success on aarch64-linux (full log)

Attempted: pbzx, xcbuild

The following builds were skipped because they don't evaluate on aarch64-linux: antlr

Partial log (click to expand)

building '/nix/store/r2wqaif8xr61hqqgg22lli2dv395w7md-xcbuild-wrapper-0.1.2-pre.drv'...
installing
post-installation fixup
shrinking RPATHs of ELF executables and libraries in /nix/store/wbwrwbwilp98wcpz8cnmh2s9fakdwc0i-xcbuild-wrapper-0.1.2-pre
strip is /nix/store/3zq400fri5dv7d30lpxlqm2v9y1iis6j-binutils-2.28.1/bin/strip
stripping (with command strip and flags -S) in /nix/store/wbwrwbwilp98wcpz8cnmh2s9fakdwc0i-xcbuild-wrapper-0.1.2-pre/bin
patching script interpreter paths in /nix/store/wbwrwbwilp98wcpz8cnmh2s9fakdwc0i-xcbuild-wrapper-0.1.2-pre
checking for references to /build in /nix/store/wbwrwbwilp98wcpz8cnmh2s9fakdwc0i-xcbuild-wrapper-0.1.2-pre...
/nix/store/apdz1inay8js5lir4n0iwypvvvxq6nhp-pbzx-1.0.2
/nix/store/wbwrwbwilp98wcpz8cnmh2s9fakdwc0i-xcbuild-wrapper-0.1.2-pre

@GrahamcOfBorg
Copy link

Success on x86_64-darwin (full log)

Attempted: antlr, pbzx, xcbuild

Partial log (click to expand)

/bin/echo "installation done"
installation done
post-installation fixup
strip is /nix/store/0fzpxnsanc02i4jsb1yhchjp4p62b2n3-cctools-binutils-darwin/bin/strip
stripping (with command strip and flags -S) in /nix/store/cp4m9h5r7y0npzgsizah0q4p94k5xmix-antlr-2.7.7/lib  /nix/store/cp4m9h5r7y0npzgsizah0q4p94k5xmix-antlr-2.7.7/bin  /nix/store/cp4m9h5r7y0npzgsizah0q4p94k5xmix-antlr-2.7.7/sbin
patching script interpreter paths in /nix/store/cp4m9h5r7y0npzgsizah0q4p94k5xmix-antlr-2.7.7
/nix/store/cp4m9h5r7y0npzgsizah0q4p94k5xmix-antlr-2.7.7/bin/antlr: interpreter directive changed from "/bin/sh" to "/nix/store/x030a63qdilnv02pkivfjg44pdxsh5km-bash-4.4-p19/bin/sh"
/nix/store/cp4m9h5r7y0npzgsizah0q4p94k5xmix-antlr-2.7.7/bin/antlr-config: interpreter directive changed from "/bin/sh" to "/nix/store/x030a63qdilnv02pkivfjg44pdxsh5km-bash-4.4-p19/bin/sh"
/nix/store/cp4m9h5r7y0npzgsizah0q4p94k5xmix-antlr-2.7.7/sbin/pyantlr.sh: interpreter directive changed from "/usr/bin/env python" to "/nix/store/fqsrb5whxc3w7cvvk4yw6z8pralx2q5l-python-2.7.14/bin/python"
moving /nix/store/cp4m9h5r7y0npzgsizah0q4p94k5xmix-antlr-2.7.7/sbin/* to /nix/store/cp4m9h5r7y0npzgsizah0q4p94k5xmix-antlr-2.7.7/bin

@matthewbauer matthewbauer changed the title [preview] codesigning on Darwin codesigning on Darwin Apr 9, 2018
@matthewbauer matthewbauer requested review from copumpkin and LnL7 April 9, 2018 03:52
@GrahamcOfBorg
Copy link

Success on x86_64-linux (full log)

Attempted: antlr, gdb, lldb, pbzx, xcbuild

Partial log (click to expand)

shrinking /nix/store/rxgb0ci2f86sz0ymvx9572k84vwnjkf9-pbzx-1.0.2/bin/pbzx
strip is /nix/store/fzcs0fn6bb04m82frhlb78nc03ny3w55-binutils-2.28.1/bin/strip
stripping (with command strip and flags -S) in /nix/store/rxgb0ci2f86sz0ymvx9572k84vwnjkf9-pbzx-1.0.2/bin
patching script interpreter paths in /nix/store/rxgb0ci2f86sz0ymvx9572k84vwnjkf9-pbzx-1.0.2
checking for references to /build in /nix/store/rxgb0ci2f86sz0ymvx9572k84vwnjkf9-pbzx-1.0.2...
/nix/store/fm1dhr4l0114hlh2izsw71d5r4bvinbc-antlr-2.7.7
/nix/store/4pfpq8k5rfh0ylhr4v0dfqjasyl1kwjb-gdb-8.1
/nix/store/640cc5nngpnb9p90vni74cd6wvc86j90-lldb-5.0.1
/nix/store/rxgb0ci2f86sz0ymvx9572k84vwnjkf9-pbzx-1.0.2
/nix/store/b0rmdvjiknmf2bqr525w9892zpirvn4k-xcbuild-wrapper-0.1.2-pre

@GrahamcOfBorg
Copy link

Success on x86_64-darwin (full log)

Attempted: antlr, gdb, lldb, pbzx, xcbuild

Partial log (click to expand)

post-installation fixup
strip is /nix/store/0fzpxnsanc02i4jsb1yhchjp4p62b2n3-cctools-binutils-darwin/bin/strip
stripping (with command strip and flags -S) in /nix/store/fxsvbmnr7zd7vbd7h9cm4wzj0z7pa36a-xcbuild-wrapper-0.1.2-pre/bin
patching script interpreter paths in /nix/store/fxsvbmnr7zd7vbd7h9cm4wzj0z7pa36a-xcbuild-wrapper-0.1.2-pre
copying path '/nix/store/4rk52w4kpnivna3xx7mygp8ghac28g2i-lldb-5.0.1' from 'https://cache.nixos.org'...
/nix/store/cp4m9h5r7y0npzgsizah0q4p94k5xmix-antlr-2.7.7
/nix/store/42p7z9i09qxk5d94rd6lwm06wd61l2ap-gdb-8.1
/nix/store/4rk52w4kpnivna3xx7mygp8ghac28g2i-lldb-5.0.1
/nix/store/d33rq2isnn060hhvm1d09kyczrvkiydn-pbzx-1.0.2
/nix/store/fxsvbmnr7zd7vbd7h9cm4wzj0z7pa36a-xcbuild-wrapper-0.1.2-pre

@GrahamcOfBorg
Copy link

Success on aarch64-linux (full log)

Attempted: gdb, lldb, pbzx, xcbuild

The following builds were skipped because they don't evaluate on aarch64-linux: antlr

Partial log (click to expand)

post-installation fixup
shrinking RPATHs of ELF executables and libraries in /nix/store/w38vaa3rhn0ikq5g2s1dvr7cxp3c09ci-xcbuild-wrapper-0.1.2-pre
strip is /nix/store/3zq400fri5dv7d30lpxlqm2v9y1iis6j-binutils-2.28.1/bin/strip
stripping (with command strip and flags -S) in /nix/store/w38vaa3rhn0ikq5g2s1dvr7cxp3c09ci-xcbuild-wrapper-0.1.2-pre/bin
patching script interpreter paths in /nix/store/w38vaa3rhn0ikq5g2s1dvr7cxp3c09ci-xcbuild-wrapper-0.1.2-pre
checking for references to /build in /nix/store/w38vaa3rhn0ikq5g2s1dvr7cxp3c09ci-xcbuild-wrapper-0.1.2-pre...
/nix/store/9wp8kivp1yp8x9gkzx7r4mry9gksn0ak-gdb-8.1
/nix/store/pi9bxcsx5m2jfgn2q2m6zkvijw7dfsb6-lldb-5.0.1
/nix/store/apdz1inay8js5lir4n0iwypvvvxq6nhp-pbzx-1.0.2
/nix/store/w38vaa3rhn0ikq5g2s1dvr7cxp3c09ci-xcbuild-wrapper-0.1.2-pre

@Mic92
Copy link
Member

Mic92 commented Apr 9, 2018

Without code signing applications are not allowed to use the ptrace() system call?

@LnL7
Copy link
Member

LnL7 commented Apr 9, 2018

@Mic92 yes and SIP adds even more restrictions.

@matthewbauer
Copy link
Member Author

I'm having trouble at dealing with macOS keychains in multi-user mode. Single-user mode would probably just work out of the box though.

So we probably will need to import the private key into the builder (might be unsafe given NixOS/nix#8). Anyway this is kind of blocked on #38633.

@matthewbauer
Copy link
Member Author

@GrahamcOfBorg build darwin.gdb

@GrahamcOfBorg
Copy link

No attempt on x86_64-linux (full log)

The following builds were skipped because they don't evaluate on x86_64-linux: darwin.gdb

Partial log (click to expand)


a) For `nixos-rebuild` you can set
  { nixpkgs.config.allowBroken = true; }
in configuration.nix to override this.

b) For `nix-env`, `nix-build`, `nix-shell` or any other Nix command you can add
  { allowBroken = true; }
to ~/.config/nixpkgs/config.nix.


@GrahamcOfBorg
Copy link

No attempt on aarch64-linux (full log)

The following builds were skipped because they don't evaluate on aarch64-linux: darwin.gdb

Partial log (click to expand)


a) For `nixos-rebuild` you can set
  { nixpkgs.config.allowBroken = true; }
in configuration.nix to override this.

b) For `nix-env`, `nix-build`, `nix-shell` or any other Nix command you can add
  { allowBroken = true; }
to ~/.config/nixpkgs/config.nix.


@GrahamcOfBorg
Copy link

Failure on x86_64-darwin (full log)

Attempted: darwin.gdb

Partial log (click to expand)

configuring
no configure script, doing nothing
building
unpacking source archive /nix/store/ij29adpy36ma06kcxs4hicg1gb1rc5lg-Security-55471.14.18.tar.gz
xcode-select: error: no developer tools were found at '/Applications/Xcode.app', and no install could be requested (perhaps no UI is present), please install manually from 'developer.apple.com'.
dtrace: failed to compile script lib/security_codesigning.d: Preprocessor failed to process input program
builder for '/nix/store/1gz94zcgrb6vlzf0qi9pa19d283xdmr3-libsecurity_codesigning-osx-10.7.5.drv' failed with exit code 1
cannot build derivation '/nix/store/q3i5r8m5qa004ivsr0ffc9a1x01nl5aj-security_systemkeychain-osx-10.10.5.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/057ysarrh0iaxj23gvfkw4v0cvkvkiap-codesign.drv': 1 dependencies couldn't be built
�[31;1merror:�[0m build of '/nix/store/057ysarrh0iaxj23gvfkw4v0cvkvkiap-codesign.drv' failed

@copumpkin
Copy link
Member

copumpkin commented Apr 9, 2018

Hmm, I'll have to look carefully at this. I didn't think it was really possible to do codesigning in a principled/secure manner in Nix so I'll be happy to be proven wrong, but am also a bit apprehensive 😄 unless you see this purely as a "we give Hydra signing keys and you only get signatures if you get your binaries from the binary cache" deal.

@matthewbauer
Copy link
Member Author

unless you see this purely as a "we give Hydra signing keys and you only get signatures if you get your binaries from the binary cache" deal

That's mostly what I want. Everything should be done in config options though so you could also self-sign everything. Basically we want to be able to do something like:

nix-build --arg config "{ keychain = { file = /Users/user/nixpkgs.keychain; password = "secret"; identity = "nixpkgs"; }; }" -A gdb

And automatically have a signed GDB. I believe this is actually fairly similar to how binary cache signatures work.

Copy link
Member

@LnL7 LnL7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great! But I'm not sure if it makes sense to sign binaries from inside a build. It's an impurity and allowing any untrusted user to sign binaries doesn't sound safe to me (if that's even possible).

@GrahamcOfBorg GrahamcOfBorg added the 2.status: merge conflict This PR has merge conflicts with the target branch label Apr 9, 2018
@GrahamcOfBorg
Copy link

Success on x86_64-linux (full log)

Attempted: gdb, lldb, xcbuild

Partial log (click to expand)

copying path '/nix/store/hcbgk6mcyp2q08mqr0swdi3ny6qll4yg-hook' from 'https://cache.nixos.org'...
copying path '/nix/store/cha99i1akava1c2filasrx0gn5jpla9q-lldb-5.0.1' from 'https://cache.nixos.org'...
copying path '/nix/store/w8c8szci956bi10m6fh8ad802qij6w3h-binutils-wrapper-2.30' from 'https://cache.nixos.org'...
copying path '/nix/store/nz60fx1vyva1a2rsw0jp0qsrjq91xhbw-clang-5.0.1' from 'https://cache.nixos.org'...
copying path '/nix/store/9vgm81xw5z9psmizacwbi83c88xabam8-clang-wrapper-5.0.1' from 'https://cache.nixos.org'...
copying path '/nix/store/28miz9kiry1166bc1j5zd51vczqihfsd-nixpkgs.xctoolchain' from 'https://cache.nixos.org'...
copying path '/nix/store/669xmxd5qfj2fawk67smr4789r800nba-xcbuild-wrapper-0.1.2-pre' from 'https://cache.nixos.org'...
/nix/store/xcvbwflwll9nknj8rz1k0972xzh2wpgv-gdb-8.1
/nix/store/cha99i1akava1c2filasrx0gn5jpla9q-lldb-5.0.1
/nix/store/669xmxd5qfj2fawk67smr4789r800nba-xcbuild-wrapper-0.1.2-pre

@matthewbauer
Copy link
Member Author

So this is now basically blocked on #39308.

@matthewbauer
Copy link
Member Author

I think the big problem with this is we can't really store secrets in the Nix store. The key will be publicly available to anyone who can access the .drv file. I don't think it would be a good idea to do this on Hydra until Nix can support some sort of private key impurity.

@matthewbauer matthewbauer changed the title codesigning on Darwin [wip] codesigning on Darwin Jul 28, 2018
matthewbauer referenced this pull request Sep 9, 2018
This actually makes it useful to the Darwin stdenv, which I'll soon be
adjusting to use this library
@ElvishJerricco
Copy link
Contributor

Hm... It's too bad there's not a way to tell macOS that a binary should be trusted without altering it. Currently, if we wanted to sign binaries from Nix, it would be impure and it would produce binaries that can't be nix copy'd over to other machines. If macOS just had a DB of signatures separate from the binaries themselves, then we could have unaltered builds and just add their signatures to such a DB after the fact with a Nix plugin.

@ElvishJerricco
Copy link
Contributor

Welp, I guess I should have read the manual before commenting, because it appears that exactly that is possible:

     -D, --detached filename
             When signing, designates that a detached signature should be written to the specified file. The code being
             signed is not modified and need not be writable.  When verifying, designates a file containing a detached sig-
             nature to be used for verification. Any embedded signature in the code is ignored.

     --detached-database
             When signing, specifies that a detached signature should be generated as with the --detached option, but that
             the resulting signature should be written into a system database, from where it is made automatically available
             whenever apparently unsigned code is validated on the system.
             Writing to this system database requires elevated process privileges that are not available to ordinary users.

@ElvishJerricco
Copy link
Contributor

ElvishJerricco commented Sep 10, 2018

Just tested. Seems to partially work:

$ nix-env -f "<nixpkgs>" -iA gdb
$ sudo codesign -s "$signing-identity" --detached-database $(readlink $(which gdb))
$ codesign --verify $(readlink $(which gdb)) && echo success
success

However, GDB still does not work... Still suggests that it's not codesigned. So for some reason, codesign --verify is not quite the same thing. Anyone have any thoughts?

EDIT: Oh, also, just to show that the binary was unaltered:

$ nix verify $(readlink $(which gdb))
[1 paths verified]

@copumpkin
Copy link
Member

Pretty sure {LL,G}DB need not only a signature but an entitlement (com.apple.security.cs.debugger) allowing them to do their dastardly debugging duties

@ElvishJerricco
Copy link
Contributor

@copumpkin Ah. Also, I'm guessing all the dynamic libraries gdb depends on need to be signed.

@copumpkin
Copy link
Member

Yup

@ElvishJerricco
Copy link
Contributor

Ah ha! Got it working. Had to sign all the dylibs it used, and I had to open the "Get Info" page for the certificate, open the "Trust" section, and set "Code Signing" to "Always Trust". Once I'd done that, I could use gdb normally.

Does this seem like a viable path forward? Simply making zero changes in nixpkgs and instead finding some way to automate the detached signing of binaries?

@copumpkin
Copy link
Member

@ElvishJerricco I think the detached signatures will be helpful but still don't address most of what I wrote in my longer comment above, which I don't think is really easily addressable. We could have a special case to cover the common case and have Hydra sign a handful of binaries in some ad-hoc way, which would get most of us a working gdb/lldb/dtrace/git, but the local signing story is still pretty unclear to me, fundamentally. We can work around it but it would basically be negating the value of one security control Apple deliberately put in place, and I don't want to be known as "the package manager that makes your computer less secure" unless we give people a very loud option for opting into it.

@ElvishJerricco
Copy link
Contributor

@copumpkin I don't think we need Hydra to provide macOS signatures in any way. I see two possible paths forward, both using local signing:

  • Provide automated tooling for letting users do detached signing of paths manually. A Nix command, or something, that adds detached signatures for all the binaries in the runtime closure of a path.
  • Add a macos-signing-identity option to Nix. Whenever a store path is realized, iff it has a trusted Nix signature, automatically perform the signing described above. The issue here is revoking Nix keys; you'd want to keep each Nix key in correspondence with a codesigning key, so they can be revoked in tandem.

The issue is that it'll prompt the user for every binary we try to sign, but we can maybe work around that with with some kind of TTL / caching.

@ElvishJerricco
Copy link
Contributor

Hydra could in theory also provide detached macOS signatures, if there's a way to add a pre-computed detached signature to this magic database. Maybe Nix should have a more pluggable concept of metadata, so that we can ship arbitrary kinds of signatures with a path, and just use Nix plugins to verify them properly?

@copumpkin
Copy link
Member

No, my point is that the notion of "local signing" is actively working against a security mechanism that Apple put in place, and I don't want that to be our default stance/policy unless you actively opt in.

Basically, Apple added code signatures and entitlements to make it harder for local code to escalate privileges. If we then go add a local trusted codesigning certificate and private key accessible to the local box, then malicious local code could use that key as well as we could and circumvent the mechanism.

That's what I meant by "I don't want Nix to be known as the package manager that disables macOS security mechanisms". I'm not 100% on board with the value of code signing here, but as a matter of policy I'd rather not go against the prevailing grain of the OS we're running on either. This is why I was suggesting that Hydra do it, and not enable local signing unless someone very explicitly allows it.

@ElvishJerricco
Copy link
Contributor

Then it sounds like option 1 would be ok. Nix does not have to sign anything; users can just sign things themselves when they want. One way or another, their gdb has to be signed for it to work, and that signature isn't going to come from apple if gdb comes from nix. So sure, make it something they have to do themselves. But maybe automate it so they can do so easily.

@matthewbauer
Copy link
Member Author

This doesn't on its own effect Apple's security. It just gives you a way of knowing the identity of who built your binary. It will all depend on what certificate you use to sign things. If its locally generated, then you will need to manually "trust" that certificate. Otherwise you can use a real one from the developer program.

The main issue is that you can't really keep a file a secret in Nix. I would be interested if anyone has ideas for alternatives to this. Your private key should never be made publicly available through the Nix store.

@ElvishJerricco
Copy link
Contributor

@matthewbauer I would suggest that you shouldn't sign binaries within a Nix expression. That should be left to external tooling, like codesign --detached-database

qrlex pushed a commit to qrlex/nixpkgs that referenced this pull request Oct 9, 2023
Summary:

  vscode-lldb has been broken on Darwin due to a build-time issue:

    * on Darwin, the vscode-lldb build scripts expect $HOME to exist and be
      writable, NixOS#202507

  and several runtime-issues:

    * codelldb can't find its dynamic libraries (NixOS#160874)

    * lldb-server from nixpkgs doesn't work due to missing the

        "com.apple.security.cs.debugger"

      macOS codesigning entitlement, (NixOS#38624), also with the symptom that
      tccd, the macOS "Transparency, Consent, and Control" daemon, denies
      requests it receives from vscode/codium with log messages like:

	  "AUTHREQ_CTX: msgID=..., function=<private>, service=kTCCServiceDeveloperTool, preflight=yes, query=1,"
          "Service kTCCServiceDeveloperTool does not allow prompting; returning denied."
          "AUTHREQ_RESULT: msgID=..., authValue=0, authReason=5, authVersion=1, error=(null),", etc.

    * lldb-server from nixpkgs may also provide a different CLI interface than
      codelldb expects on macOS.

    * vscode-lldb directs lldb to load rust pretty-printing scripts which need
      to be preserved through the build process in nixpkgs

Solution:

  * The build problem can be fixed by setting HOME="$(pwd)/home", as suggested
    in NixOS#202507.

  * The dynamic libraries issue can be fixed by setting LD_LIBRARY_PATH while
    wrapping codelldb

  * The permissions issue and CLI interface issue can both be fixed by using
    Xcode's debugserver,

      /Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Versions/A/Resources/debugserver

    on macOS, since it has the required entitlement and the expected interface.

  * Finally, the script-loading issue can be fixed by copying the required
    scripts to the location that vscode-lldb expects to find them in.

Fixes:

  * NixOS#148946: Error failed to get reply to handshake packet on x86_64-darwin
    with vscode-extensions.vadimcn.vscode-lldb

  * NixOS#160874: codelldb inside of vscode-lldb extension doesn't work

  * NixOS#202507: vscode-extensions.vadimcn.vscode-lldb fails to build on aarch64-darwin

(cherry picked from commit fa70e7499b08524a4a02e7ce9e39847b9d3c95df)
wegank pushed a commit to mstone/nixpkgs that referenced this pull request Apr 10, 2024
Summary:

  vscode-lldb has been broken on Darwin due to a build-time issue:

    * on Darwin, the vscode-lldb build scripts expect $HOME to exist and be
      writable, NixOS#202507

  and several runtime-issues:

    * codelldb can't find its dynamic libraries (NixOS#160874)

    * lldb-server from nixpkgs doesn't work due to missing the

        "com.apple.security.cs.debugger"

      macOS codesigning entitlement, (NixOS#38624), also with the symptom that
      tccd, the macOS "Transparency, Consent, and Control" daemon, denies
      requests it receives from vscode/codium with log messages like:

	  "AUTHREQ_CTX: msgID=..., function=<private>, service=kTCCServiceDeveloperTool, preflight=yes, query=1,"
          "Service kTCCServiceDeveloperTool does not allow prompting; returning denied."
          "AUTHREQ_RESULT: msgID=..., authValue=0, authReason=5, authVersion=1, error=(null),", etc.

    * lldb-server from nixpkgs may also provide a different CLI interface than
      codelldb expects on macOS.

    * vscode-lldb directs lldb to load rust pretty-printing scripts which need
      to be preserved through the build process in nixpkgs

Solution:

  * The build problem can be fixed by setting HOME="$(pwd)/home", as suggested
    in NixOS#202507.

  * The dynamic libraries issue can be fixed by setting LD_LIBRARY_PATH while
    wrapping codelldb

  * The permissions issue and CLI interface issue can both be fixed by using
    Xcode's debugserver,

      /Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Versions/A/Resources/debugserver

    on macOS, since it has the required entitlement and the expected interface.

  * Finally, the script-loading issue can be fixed by copying the required
    scripts to the location that vscode-lldb expects to find them in.

Fixes:

  * NixOS#148946: Error failed to get reply to handshake packet on x86_64-darwin
    with vscode-extensions.vadimcn.vscode-lldb

  * NixOS#160874: codelldb inside of vscode-lldb extension doesn't work

  * NixOS#202507: vscode-extensions.vadimcn.vscode-lldb fails to build on aarch64-darwin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Package "codesign" on Darwin
6 participants