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
Using codesigning flags still results in "no cdhash, completely unsigned?" errors (with --onedir executable or app bundle executable) #8029
Comments
When (re)signing manually, did you (re)sign every binary (dylib, executable, .framework bundle) in the PyInstaller-generated onedir application? For the time being, you should replace your actual PyInstaller-frozen application with a basic Does it work with PyInstaller 6.x and hello-world program? What if you switch to PyInstaller 5.13.2? In 6.x, we are preserving the structure of .framework bundles from which we collect dylibs (so in the hello-world, that would be Python.framework at least), but in POSIX builds, we do not (re)sign the collected .framework bundle (only the dylib in it). When generating .app bundles, we can sort of get away with it because we force recursive (re)signing of the whole .app via |
@rokm Minor update: I can confirm that the basic "hello world" application works, and I do (re)sign every binary. Thank you for your help. I've narrowed the issue to an import statement ( (Revealed by Open Files and Ports in Activity Monitor, for reference):
Side note: I double-checked and believe that I've already modified all dynamic links of libtorch_cpu.dylib (among others, with install_name_tool) to link locally. However, again, the issue is apparently linked to something not codesigned. I'm uncertain if the non-signed source is within my directories (or the PyInstaller executable) or if the source isn't signed because it might be dynamically created/loaded from another location. I switched to 5.13.2, to be sure, and had the same issue. I plan to test with an .app bundle if no other solution arises. I'd appreciate any further insights on how to tackle this issue. I'll post back with any progress. |
Could be that |
Shortly after my initial post, I updated it to display my "Main app entitlements" rather than just the 'inherit' entitlements. To be clear, I've continued to use both the 'allow-jit' and 'unsigned memory' entitlements (based on some posts I've come across). I wasn't aware of the Hopefully using an app bundle will solve it (if the POSIX approach is why something wasn't being signed - whether due to JIT or otherwise). If not, it appears I may need to figure out how to use a static build of libtorch_cpu. |
To conclude my previous comment:
|
For .app bundles, v6 is actually recommended as it improves the bundle layout for codesigning compliance.
Indeed. "Additional hooks" are involved only during analysis (designating what needs to be collected and where). Built-in signing is performed during actual collection (for individual binaries) and then also once the whole .app bundle is assembled (this part is recursive, in an attempt to ensure that everything is signed). Any manual re-signing must be done in post-processing, outside of PyInstaller. |
Results from testing with an app bundle: In the codesigning phase, an error occurs, which may or may not relate to the main issue: ''' 347338 WARNING: You will need to sign the bundle manually! I proceed to remove all .DS_Store files and codesign everything manually (iterating directories root-first):
In a separate test, I also tried signing just the app file (with "--deep", etc). As the same "cdhash, completely unsigned?" issue persists: Hopefully the issue is simply that the manual codesigning can't reach the PyInstaller executable contents (as the executable is already compiled at the time of manual codesigning), where the solution might then just be to solve the DS_Store files error in the PyInstaller process. |
Where did the |
That doesn't seem to be the case to me. If you removed So if the "cdhash, completely unsigned?" issue persists, you will have to figure out which part is unsigned and is causing issues. Maybe you could try packaging |
Similarly, you could try enabling sandbox on the .app bundle and see if stand-alone .app bundle runs as expected after signing it (i.e., to see if issues also occur without the sandbox inheritance). |
One other thing - you never mentioned what packages your application is using nor what your python environment is (anaconda, python.org+pypi, homebrew)... Can you run |
|
.DS_Store locations:app_name.app/Contents/Resources/pyphen Python environmentI created my virtual Python environment using the standard Python installation from python.org. I am currently using Python version 3.10.6, which was compiled with Clang 13.0.0. Some Python packages of the application:whisperx, whisper (just as whisperx, triggers the same issue: on import in the python script, the process (shown as libtorch_cpu.dylib in Open Files and Ports) continually tries to load some temporary element and is continually denied, so it doesn't move beyond that import statement), torch, ffmpeg, among some unrelated others. Other PyInstaller command details, if useful to know:
Regarding the All works well until signing the executable with the sandboxing/inherit entitlements. It also works if all associated binaries are signed as long as the executable isn't signed (last I checked).
Side note: If of any use, at your request I could also post the full list of signed/validated binaries (printed from |
I see those are created by Finder when you navigate the package directories, and we shouldn't really be collecting them at all (#8042).
Can you capture/copy/retrieve that temporary element somehow, so we can look at what it is? Coming from
Hmmm, I'd expect Either way, #8043 will add a warning about potentially problematic libraries.
It is unclear what exactly you are testing with right now - are you still testing with PyInstaller-generated .app bundle as a helper application to another application? So, does PyInstaller .app bundle still inherit sandbox from the main application? My suggestion was to test PyInstaller .app bundle as a stand-alone application, with its own sandbox (and thus no entitlements inheritance, but rather its own set of entitlements) - just to make sure that this is not some sort of issue with entitlements inheritance.
I don't think that would help at this point. |
The temporary elementsI'm pleased to report (in hopes that the issue is much simpler than first deemed) that 'hanging at the
My system and what I'm testing withAll is built from a 2019 MacBook Pro ( Side note: The virtual environment was created in the standard way using Python (Not sure that was clear). It is indeed a helper executable and the bundle inherits the sandbox, used as follows from a Swift-based application:
Next stepsIf/when you deem the following a priority given the latest info: I want to ensure the issue doesn't relate to some sort of inconsistent signature detection. Side notes (Feel free to ignore until ever apt):
|
If problem was related to |
Good points to reflect on, thank you. To clarify (if I understand upon further reflection), and to your point on the hello-world app, I don't believe the problem is inherent to *In contrast to full entitlement signing (testing with the app directly) - Because that bifurcated approach (manually signing what I can after PyInstaller partially signs, stopped by .DS_Store error) works in that case. [1] That is, to the extent my signature process may diverge from PyInstaller's, such as:
Again, this feels like good news [2] after the apparent successful test without inheritance entitlements - instead, using the exact entitlements the parent app uses and testing directly [3] rather than as a helper process.
If after a test with no .DS_Store errors in the PyInstaller codesigning process yields the same result, and it's still unclear where the codesigning discrepancy is, I will prepare to contact Apple developers directly (after gathering any questions, statements, or insights you might want to impart). Side note:
|
I doubt .DS_Store files are the issue here, but you can check with |
Good reminder, I would just maintain skepticism with respect to any lateral differences of manual codesigning and that which I can't sign (compiled in the executable). However, if I can actually prevent the .DS_Store error by removing files before compilation so I don't need to manually sign:
I will try the pre-removal of .DS_Store files and post an update. Appreciate your input and analyses – it's helping me navigate through a critical phase. Best regards, Phillip |
(Message 2) Quick update: I'm not certain, but (answering my own question) it may be crucial to place the executable in Executables rather than the default Resources in the Copy Files phase. I'll report back soon. |
|
P2: Quick update:Sleeping before importing anything in Python, to test whether entitlements weren't inherited in time, may have prevented the current error! I'll report back with any other key updates (I still need to test further), and not to forget some comments in my previous message (if needed) Side note: Today I replaced the utils.py in the develop branch's "building" folder after seeing the update, but that's likely not the cause of the solution based on my current understanding, just full disclosure |
P3: Update n2:Waiting before importing apparently wasn't necessary. I don't know what else changed besides replacing the Further verification to come (to ensure the sandbox is indeed being implemented)... |
I'm pleased to report that it appears that both testing and notarization have appeared to be successful with the App Sandbox
Thank you for your time and input. Best regards, Phillip |
Updateregarding: [1]. a seemingly outdated dylib that Apple requires to be up-to-date (when submitting to the Mac App Store) [2]. an issue apparently to do with Quick screenshot and full file attached [1]. ''' Contents/MacOS/app_name.app/Contents/Frameworks/libtk8.6.dylib The use of non-public or deprecated APIs is not permitted on the App Store, as they can lead to a poor user experience should these APIs change and are otherwise not supported on Apple platforms. [2]. After submitting the current version to Apple (after successfully codesigning and running on my device), it was reported that the app crashed when attempting to run the software referred to in this post. After reviewing some of the link you attached, where the thread ended, it's unclear to me what I might consider trying first, so if you have any specific insight or advice, it would be much appreciated. Shot in the dark I don't have an ARM device to test on, so I'm not sure whether running certain entitlements with the codesignature could prevent the issue (e.g. dyld-related, unsigned memory, or JIT-related) |
[1] If you're not using [2] Yeah, the x86_64 PyPI wheel for scikit-learn contains out-dated/problematic build of |
I made a mistake. Earlier I had temporarily disabled SIP (for a separate purpose), which now seems to be why the eponymous error was averted. Your latest comments are helpful, and the eponymous error didn't occur for the Apple reviewer (but perhaps it would be their next error, not sure). So it looks like the current status remains (at this comment) |
Hmmm... if I understand correclty, https://developer.apple.com/forums/thread/120647 implies that entitlements are not inherited by the child process when it inherits the sanbox. Could this be the problem here? I.e., your child program requires If you go back to the "stand-alone" version of the child program, i.e., launched on its own and with its own sandbox - does it work without any additional entitlements or not? |
FWIW, in #8099 we established that one possible source of error messages like these
are binaries that are generated by CFFI on-the-fly (and are thus lacking signature), in combination with lack of proper entitlements that would allow them to be loaded. Which further reinforces my suspicion that in your case, the problem is that entitlements from the parent/inherited sandbox are not properly inherited by the child process, where they are required. |
I really appreciate you finding/providing that link - The solutions therein might directly align with my requirements. As per that info, I'm now considering the potential "CFMessagePort" approach (rather than something like an XPC service), if that makes sense. I'll soon look at the #8099 info as well. Current testing notes (before testing any structural changes to the launch approach, such as CFMessagePort): When providing a more comprehensive set of entitlements (detailed below) in testing the "stand-alone" version, the process passes the library validation (and does not pass when less entitlements are used). [less entitlements]
[more entitlements]
I haven't yet isolated which entitlement/s enable the validation to pass (Doing so is currently lower priority) But to confirm, using [more entitlements] didn't work when attempting to inherit them from the parent app (The same issue arises.), hence the apparent need for the another approach like 'CFMessagePort'. If that approach doesn't work for the purpose of avoiding having to inherit, it would be key to understand why inheritance isn't working here. I plan to work toward that approach tomorrow |
After researching similar issues extensively for a few days without a solution, I would be grateful to receive any level of guidance.
My use case:
macOS Ventura 13.6
In Swift, invoke the (6.1.0) PyInstaller-generated executable with Process()
- Hangs since the executable has been signed (Error details posted below)
- Side note: An Info.plist file is not currently associated with the executable, as these tests haven't been with a PyInstaller-generated app bundle.
Codesigning flags used:
"--codesign-identity", identity # "Apple Development: My Name (..........)"
"--osx-entitlements-file", entitlements_path # "/path/to/app_entitlements.entitlements"
"--osx-bundle-identifier", bundleID # "com.appname.macos"
Command structure (via Python script):
Entitlements to inherit:
Main app entitlements:
com.apple.security.app-sandbox, com.apple.security.cs.disable-library-validation, among others (at least temporarily, such as com.apple.security.cs.allow-unsigned-executable-memory, com.apple.security.cs.allow-dyld-environment-variables, and com.apple.security.cs.allow-jit)
Error samples from the Console app:
error 19:42:36.217483-0500 kernel Sandbox: app_name(22883) deny(1) ipc-posix-sem-create /joblib-22883-aagrqso7
...
error 19:42:37.498106-0500 kernel Sandbox: app_name(22883) deny(1) network-bind local:*:0
error 19:42:37.614221-0500 kernel Library Validation failed: Rejecting '/private/var/folders/z4/snz0v2gd3z1__qglgqc09bm00000gn/T/com.appname.macos/ffiMINHOs' (Team ID: none, platform: no) for process 'app_name(22883)' (Team ID: MyTeamID, platform: no), reason: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.
...
error 19:42:37.614737-0500 syspolicyd Disallowing load of in 22883,
error 19:42:37.615163-0500 kernel Sandbox: app_name(22883) deny(1) file-write-create /private/tmp/ffikQWqG4
error 19:42:37.615228-0500 kernel Sandbox: app_name(22883) deny(1) file-write-create /private/var/tmp/ffipjwZqi
What I've tried
e.g. when signing manually:
What I'm considering
*(from Swift: launching the executable within the app bundle instead of the --onedir executable)
If anyone has faced similar issues, or has insights into why the codesigning flags might not be working, I'd greatly appreciate any advice.
The text was updated successfully, but these errors were encountered: