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

[macOS] codesign native assets during embed #148310

Merged
merged 4 commits into from
May 16, 2024

Conversation

knopp
Copy link
Member

@knopp knopp commented May 14, 2024

Fixes #148051

Currently only the "embed" phase, which is run during the Runner target build have access to code-signing identity. The flutter assemble target, which does the main build (and also builds native assets) does not have access to the code-signing identity.

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact "@test-exemption-reviewer" in the #hackers channel in Chat (don't just cc them here, they won't see it! Use Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@github-actions github-actions bot added the tool Affects the "flutter" command-line tool. See also t: labels. label May 14, 2024
@knopp
Copy link
Member Author

knopp commented May 14, 2024

@dcharkes, any idea if this is testable (and how)? Also this PR leaves all the dart codesigning paths unchanged. Those are not really used (the code-signing identity define is never set).

@dcharkes
Copy link
Contributor

@dcharkes, any idea if this is testable (and how)? Also this PR leaves all the dart codesigning paths unchanged. Those are not really used (the code-signing identity define is never set).

We can only test this with an integration test. A test that actually runs flutter build and/or flutter run. And then we need to look in the app bundle to see if the framework/dylib is signed.

expectDylibIsBundledWithFrameworks(exampleDirectory, buildMode, add2appBuildSubcommand.replaceAll('-framework', ''));

We should probably use some kind of commandline tool to inspect what signature the dylib is signed with and check that it's the right one (or the same one as the flutter framework).

@knopp
Copy link
Member Author

knopp commented May 14, 2024

The problem here is that the dylibs are already codesigned through codesignDylib with adhoc certificate. There are two issues with this

a) the codesigning is performed twice (second time actual identity replacing the first signature),
b) unless the test is run with an real code-signing identity (i don't know if and how we can do this), it will simply resign the binaries with another adhoc signature so we can't really verify this.

Possible option would be to disable codesigning of macOS native assets in code and only do it in the script, in which case we should be able to verify the signature in tests.

@knopp
Copy link
Member Author

knopp commented May 14, 2024

The annoying part about this is that this diverges the macOS / iOS implementation even further. On iOS codesigning through code should work, since it's part of the Runner target and thus has access to identity.

@jmagman, do you know why on macOS Flutter assemble is handled as a separate Xcode target? It would be much easier if everything was handled in the Runner target, but pragmatically, even if doable, that'd be a pretty big change and just the migration itself would likely require some significant xcode project surgery.

@github-actions github-actions bot added the a: desktop Running on desktop label May 14, 2024
@knopp
Copy link
Member Author

knopp commented May 14, 2024

@dcharkes, I disabled adhoc code-signing of macOS dylib in dart code (_copyNativeAssetsMacOS) unless actual identity is provided and added test that will fail when macos_assemble.sh doesn't codesign native assets.

Note that as far as I can tell there is currently no way to provide code-signing identity in a way that would reach _copyNativeAssetsMacOS. There however might be in future, for example if the BuildFrameworkCommand is amended to parse dCodesignIdentity, which right now it doesn't seem to.

@knopp knopp requested a review from dcharkes May 14, 2024 15:40
@knopp knopp force-pushed the codesign_native_assets_during_embed branch from 6724801 to 6f06402 Compare May 14, 2024 15:44
@jmagman
Copy link
Member

jmagman commented May 14, 2024

@jmagman, do you know why on macOS Flutter assemble is handled as a separate Xcode target? It would be much easier if everything was handled in the Runner target, but pragmatically, even if doable, that'd be a pretty big change and just the migration itself would likely require some significant xcode project surgery.

I totally agree, the divergence has been completely annoying and added so much work over the years.
I would love if someone undertook the work to converge the iOS and macOS projects (xcode_backend.dart vs sh, extensive target/build phase Xcode project file surgery, or even combining the iOS/macOS project directories into a single darwin Xcode project). The macOS tooling implementation has lagged so far behind iOS in the last 5 years, for example #94747, all the macOS spew that gets logged to stderr, etc

@dcharkes
Copy link
Contributor

@dcharkes, I disabled adhoc code-signing of macOS dylib in dart code (_copyNativeAssetsMacOS) unless actual identity is provided and added test that will fail when macos_assemble.sh doesn't codesign native assets.

👍

The test is failing on the CI atm.

@knopp knopp force-pushed the codesign_native_assets_during_embed branch 3 times, most recently from c8b54c7 to 74cf7a6 Compare May 15, 2024 08:56
@knopp
Copy link
Member Author

knopp commented May 15, 2024

@dcharkes, the tests are passing now.

Copy link
Contributor

@dcharkes dcharkes left a comment

Choose a reason for hiding this comment

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

LGTM!

Thanks @knopp! 🙏

@knopp knopp force-pushed the codesign_native_assets_during_embed branch from 74cf7a6 to 1bd47bc Compare May 16, 2024 13:05
@knopp knopp merged commit c719f03 into flutter:master May 16, 2024
129 checks passed
@knopp knopp deleted the codesign_native_assets_during_embed branch May 16, 2024 16:12
knopp added a commit to superlistapp/flutter that referenced this pull request May 17, 2024
Fixes flutter#148051

Currently only the "embed" phase, which is run during the Runner target
build have access to code-signing identity. The flutter assemble target,
which does the main build (and also builds native assets) does not have
access to the code-signing identity.

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#overview
[Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene
[test-exempt]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes
[Discord]: https://github.com/flutter/flutter/wiki/Chat
[Data Driven Fixes]:
https://github.com/flutter/flutter/wiki/Data-driven-Fixes
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 17, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 17, 2024
auto-submit bot pushed a commit to flutter/packages that referenced this pull request May 17, 2024
flutter/flutter@0d22d91...00425ef

2024-05-17 engine-flutter-autoroll@skia.org Roll Flutter Engine from d575e511f9e5 to a19d3722922d (2 revisions) (flutter/flutter#148534)
2024-05-17 engine-flutter-autoroll@skia.org Roll Flutter Engine from 8d1a1d8d7b48 to d575e511f9e5 (5 revisions) (flutter/flutter#148529)
2024-05-17 engine-flutter-autoroll@skia.org Manual roll Flutter Engine from 6fa734d68688 to 8d1a1d8d7b48 (8 revisions) (flutter/flutter#148528)
2024-05-17 32538273+ValentinVignal@users.noreply.github.com Add test for material_banner.0.dart and material_banner.1.dart (flutter/flutter#148452)
2024-05-17 nate.w5687@gmail.com `switch` statement cleanup (flutter/flutter#148382)
2024-05-16 goderbauer@google.com const vs. non-const widget build benchmark (flutter/flutter#148261)
2024-05-16 49699333+dependabot[bot]@users.noreply.github.com Bump actions/checkout from 4.1.5 to 4.1.6 (flutter/flutter#148516)
2024-05-16 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Roll Flutter Engine from 6fa734d68688 to 1850def2ccff (1 revision) (#148507)" (flutter/flutter#148517)
2024-05-16 stuartmorgan@google.com Add PrivacyInfo.xcprivacy to plugin template (flutter/flutter#148485)
2024-05-16 stuartmorgan@google.com Fix iOS reference in macOS Cocoapods error (flutter/flutter#148506)
2024-05-16 engine-flutter-autoroll@skia.org Roll Flutter Engine from 6fa734d68688 to 1850def2ccff (1 revision) (flutter/flutter#148507)
2024-05-16 engine-flutter-autoroll@skia.org Roll Flutter Engine from 460df6caef0e to 6fa734d68688 (4 revisions) (flutter/flutter#148500)
2024-05-16 nate.w5687@gmail.com Enhanced enum features for `AnimationStatus` (flutter/flutter#147801)
2024-05-16 matej.knopp@gmail.com [macOS] codesign native assets during embed (flutter/flutter#148310)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC rmistry@google.com,stuartmorgan@google.com on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
TecHaxter pushed a commit to TecHaxter/flutter_packages that referenced this pull request May 22, 2024
…r#6753)

flutter/flutter@0d22d91...00425ef

2024-05-17 engine-flutter-autoroll@skia.org Roll Flutter Engine from d575e511f9e5 to a19d3722922d (2 revisions) (flutter/flutter#148534)
2024-05-17 engine-flutter-autoroll@skia.org Roll Flutter Engine from 8d1a1d8d7b48 to d575e511f9e5 (5 revisions) (flutter/flutter#148529)
2024-05-17 engine-flutter-autoroll@skia.org Manual roll Flutter Engine from 6fa734d68688 to 8d1a1d8d7b48 (8 revisions) (flutter/flutter#148528)
2024-05-17 32538273+ValentinVignal@users.noreply.github.com Add test for material_banner.0.dart and material_banner.1.dart (flutter/flutter#148452)
2024-05-17 nate.w5687@gmail.com `switch` statement cleanup (flutter/flutter#148382)
2024-05-16 goderbauer@google.com const vs. non-const widget build benchmark (flutter/flutter#148261)
2024-05-16 49699333+dependabot[bot]@users.noreply.github.com Bump actions/checkout from 4.1.5 to 4.1.6 (flutter/flutter#148516)
2024-05-16 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Roll Flutter Engine from 6fa734d68688 to 1850def2ccff (1 revision) (#148507)" (flutter/flutter#148517)
2024-05-16 stuartmorgan@google.com Add PrivacyInfo.xcprivacy to plugin template (flutter/flutter#148485)
2024-05-16 stuartmorgan@google.com Fix iOS reference in macOS Cocoapods error (flutter/flutter#148506)
2024-05-16 engine-flutter-autoroll@skia.org Roll Flutter Engine from 6fa734d68688 to 1850def2ccff (1 revision) (flutter/flutter#148507)
2024-05-16 engine-flutter-autoroll@skia.org Roll Flutter Engine from 460df6caef0e to 6fa734d68688 (4 revisions) (flutter/flutter#148500)
2024-05-16 nate.w5687@gmail.com Enhanced enum features for `AnimationStatus` (flutter/flutter#147801)
2024-05-16 matej.knopp@gmail.com [macOS] codesign native assets during embed (flutter/flutter#148310)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC rmistry@google.com,stuartmorgan@google.com on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a: desktop Running on desktop tool Affects the "flutter" command-line tool. See also t: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[macOS] Code-signing native assets
3 participants