Keg: treat codesigning exceptions as warnings#9040
Keg: treat codesigning exceptions as warnings#9040mistydemeo wants to merge 4 commits intoHomebrew:masterfrom
Conversation
6c10afb to
3e84dc1
Compare
This is an alternative to Homebrew#9040. In that case, we rely on ruby-macho to apply code signatures after changing ID or install_name. Here, we instead do that ourselves so that we can choose what OS to apply it on. Like in that PR, we swallow any failures so that we don't inadvertently break more exotic packages like OpenJDK (which caused issues in Homebrew#8922).
Library/Homebrew/os/mac/keg.rb
Outdated
There was a problem hiding this comment.
I think it would be ideal if this didn't do the code signing but it was done separately with MachO::Tools.codesign or similar. That allows us to catch the exception just for the code signing stage and generally separate the two. It'll also make it easier to have e.g. a DSL to enable/disable code-signing per-formula.
There was a problem hiding this comment.
I'm of two minds about this. Let me explain...
Ideally, I think ruby-macho shouldn't "break" binaries. That is, from the gem's perspective (and not Homebrew's perspective), if we make any changes to a binary it should leave at the same level of correctness as where we started. Today, that's not the case: if a mach-o binary is signed, and we then modify that binary with ruby-macho, we leave it with an invalid code signature and the OS will refuse to run or load it until it gets resigned later. install_name_tool and friends automatically apply an ad-hoc code signature when modifying binaries and that's the behaviour I was looking to replicate in ruby-macho.
On the other hand, some of the considerations around codesigning are helped if we have access to Homebrew's knowledge about the host OS and the target OS - things that ruby-macho isn't aware of. Based on that, I can see the argument for having ruby-macho leave the actual call to perform signing up to Homebrew, even if the utility function lives in ruby-macho.
cc @woodruffw - I'd love to get your call here.
There was a problem hiding this comment.
Yeh, that argument is convincing and I agree with it. I remove my objections, thanks @mistydemeo!
It'll also make it easier to have e.g. a DSL to enable/disable code-signing per-formula.
I think this would be nice but it does look like (please correct me if I'm wrong!) that codesign! is already a public API so we could call it directly if desired.
There was a problem hiding this comment.
I think this would be nice but it does look like (please correct me if I'm wrong!) that
codesign!is already a public API so we could call it directly if desired.
That is correct! It's already a public API and we can use it as desired.
3e84dc1 to
a2a6a4e
Compare
|
Now that we have ruby-macho 2.4.0 with the changes we rely on, I've incorporated it via |
a2a6a4e to
d26fc17
Compare
|
Tested and working as expected on ARM macOS 11 and Intel macOS 10.15. Here's what a codesigning failure looks like, using openjdk as an example: |
We've seen in the past that certain dylibs will cause the system codesign utility to trip. We don't need to consider this to be fatal in most cases, so we can downgrade these exceptions to warnings. cc Homebrew#8922.
d26fc17 to
2ee9aec
Compare
|
When that warning occurs: It still means that we created a corrupted file, do I understand that correctly? i.e., in that case, |
|
In this case the file is in the same state as we received it: it was not signed when it was built, and remains unsigned afterwards. |
|
@mistydemeo but would we also treat a code signing error on a codesigned file as a warning, not an error? That seems wrong, given that on ARM Big Sur a non-codesigned file will not be functional |
|
Also: I’d rather we be conservative with code-signing, and only sign things that were signed to begin with. Or sign only on ARM Big Sur, where we know signatures are required. Unless there is a clear benefit I don’t see, it seems quite invasive (and with potential for bugs, as we’re seeing) for no real gain |
|
I can confirm a failure while building Ruby with this PR applied: It seems ruby_macho fails to set the signature for The installed ruby is then nonfunctional, any attempt to run the binary will be killed. I think this highlights that codesigning exceptions should be errors, not warnings, when the original file was codesigned. |
|
I think you're right. That being the case, I think this is going to need a little refactoring:
cc @MikeMcQuaid - this is a reversal of your and my earlier decisions here, but given the circumstances I think this is going to be the more user-friendly option. We can revisit this if the |
This is fine with me. Can we please, then, make the conditional code-signing logic be in Homebrew/brew rather than ruby-macho and make it a two-pass process? It's much nicer and easier to be able to change this logic as we decide to experiment with different ways of doing code-signing, reporting it to users, enabling it sometimes and not others etc. |
Opened PR for part of this in Homebrew/ruby-macho#287 |
| rubocop-sorbet (0.5.1) | ||
| rubocop | ||
| ruby-macho (2.2.0) | ||
| ruby-macho (2.4.0) |
There was a problem hiding this comment.
| ruby-macho (2.4.0) | |
| ruby-macho (2.5.0) |
2.5.0 has just landed, thanks @woodruffw!
|
Closed by #9102. |
brew stylewith your changes locally?brew testswith your changes locally?brew manlocally and committed any changes?We've seen in the past that certain dylibs will cause the system codesign utility to trip. We don't need to consider this to be fatal in most cases, so we can downgrade these exceptions to warnings.
Requires Homebrew/ruby-macho#275 - we need to merge that and bump the ruby-macho version for this to be usable.
cc #8922.