-
Notifications
You must be signed in to change notification settings - Fork 9
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
PermissionsError when accessing some directories with os module #38
Comments
FYI @jaimergp |
I suspect this has to do with the XML configuration shipped in the shortcut. I'll look into this, thanks for the report! |
That's what I'm hoping; that should be relatively easy to fix. However, I've been unable to see any affect by adding the following values to Spyder's info.plist (from our additional info.plist <key>CFBundleVersion</key>
<string>0.0.0</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>py</string>
<string>pyw</string>
<string>ipy</string>
<string>pyx</string>
<string>pxd</string>
<string>pxi</string>
<string>c</string>
<string>h</string>
<string>cc</string>
<string>cpp</string>
<string>cxx</string>
<string>h</string>
<string>hh</string>
<string>hpp</string>
<string>hxx</string>
<string>cl</string>
<string>f</string>
<string>for</string>
<string>f77</string>
<string>f90</string>
<string>f95</string>
<string>f2k</string>
<string>f03</string>
<string>f08</string>
<string>pro</string>
<string>m</string>
<string>jl</string>
<string>yaml</string>
<string>yml</string>
<string>patch</string>
<string>diff</string>
<string>rej</string>
<string>bat</string>
<string>cmd</string>
<string>txt</string>
<string>txt</string>
<string>rst</string>
<string>po</string>
<string>pot</string>
<string>nsi</string>
<string>nsh</string>
<string>scss</string>
<string>css</string>
<string>htm</string>
<string>html</string>
<string>xml</string>
<string>js</string>
<string>json</string>
<string>ipynb</string>
<string>enaml</string>
<string>properties</string>
<string>session</string>
<string>ini</string>
<string>inf</string>
<string>reg</string>
<string>cfg</string>
<string>desktop</string>
<string>md</string>
</array>
<key>CFBundleTypeName</key>
<string>Text File</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
</dict>
</array>
<key>LSEnvironment</key>
<dict>
<key>SPY_BRANCH</key>
<string>(HEAD detached at pull/19485/merge)</string>
<key>SPY_COMMIT</key>
<string>f40da3195</string>
</dict>
<key>LSHasLocalizedDisplayName</key>
<false/>
<key>NSAppleScriptEnabled</key>
<false/>
<key>NSHumanReadableCopyright</key>
<string>Copyright not specified</string>
<key>NSMainNibFile</key>
<string>MainMenu</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>NSRequiresAquaSystemAppearance</key>
<false/>
<key>PyMainFileNames</key>
<array>
<string>__boot__</string>
</array>
<key>PyOptions</key>
<dict>
<key>alias</key>
<false/>
<key>argv_emulation</key>
<false/>
<key>emulate_shell_environment</key>
<true/>
<key>no_chdir</key>
<false/>
<key>prefer_ppc</key>
<false/>
<key>site_packages</key>
<false/>
<key>use_faulthandler</key>
<false/>
<key>use_pythonpath</key>
<false/>
<key>verbose</key>
<false/>
</dict>
<key>PyResourcePackages</key>
<array/>
<key>PyRuntimeLocations</key>
<array>
<string>@executable_path/../Frameworks/libpython3.9.dylib</string>
</array>
<key>PythonInfoDict</key>
<dict>
<key>PythonExecutable</key>
<string>/Users/runner/hostedtoolcache/Python/3.9.14/x64/bin/python</string>
<key>PythonLongVersion</key>
<string>3.9.14 (main, Sep 7 2022, 14:27:29)
[Clang 12.0.0 (clang-1200.0.32.29)]</string>
<key>PythonShortVersion</key>
<string>3.9</string>
<key>py2app</key>
<dict>
<key>alias</key>
<false/>
<key>template</key>
<string>app</string>
<key>version</key>
<string>0.28.2</string>
</dict>
</dict> I was hoping to affect some behavior, but it did not even break the application. 🤷🏼 |
So I've got some new information. I've been able to resolve this issue for Spyder in two independent ways:
$ brew install sch
$ mv ~/Applications/Spyder.app/Contents/MacOS/Spyder ~/Applications/Spyder.app/Contents/MacOS/Spyder.bak
$ shc -o ~/Applications/Spyder.app/Contents/MacOS/Spyder -f ~/Applications/Spyder.app/Contents/MacOS/Spyder.bak
I'm assuming, at this point, that issue has something to do with security policies in macOS. I only have macOS 12, so I don't know if this issue manifests on older systems. Perhaps something in the security policy distinguishes between scripts and executables? Perhaps there's an exception for So, the former solution seems impractical, as However, because I don't fully understand what is going on, I'm concerned that there may be a more fundamental security issue at play here that needs to be addressed properly. |
Intriguing. I found this thread, which points out that
Also from this guide:
So there's a chance we need to do something similar to what the Python launcher system for Windows does:
Possible launchers we can use:
Or borrow something from CPython itself. I found this bug report with related (but not too similar) problems. |
Some new development. So changing the shabang is not a general solution. I also think requiring users to manually add macOS is supposed alert the user to applications requesting disk access via a dialog: So a binary executable seems to be the most desirable way to be consistent with macOS disk access protocols and maintain convenience for the end user. The most elegant solution would be to have However, to avoid requiring a standalone Use a dummy binary executableA generic shell script can be compiled and pre-signed by the developer and included in the application's menu package repo (e.g. napari-menu), or perhaps signed at the
Where
Use
|
@jaimergp, looks I posted before I read your latest comment. It seems we are on the same page here.
I wonder if |
For Spyder, for now, I'm just doing the following:
It seems to me that two good features for
In fiddling around with this stuff I discovered that code signing the application executable does not appear to be necessary, and in fact does not work. I assumed that it would need to be code signed when included in the package installer in order for the package installer to be notarized. However, |
If the executable is coming from the feedstock (and hence the conda package), it might contain a hardcoded I think we can provide Btw, I know I said I will work on this (and I am, but I had to rebase a few branches first). Right now, I am juggling a few tasks before tackling the whole thing in this issue, but I am reading your progress! It's super welcome and rest assured we will make this easier. Thanks a lot! |
The feedstock
I'm not familiar with this or how the binary is compiled. But a path agnostic executable should work just as well; I think this is similar to the "dummy" executable in my previous comment.
👍🏼
This was simply the best solution I found so far for compiling a shell script to binary. I would certainly welcome better solutions.
Thank you for all your work! It has been indispensable for Spyder and I'm learning a lot. |
|
I have a working launcher written in C in this PR. I need to do some tests to see if this is enough to workaround the security limitations, but I am guessing it is? 🤞 |
The launcher alone did not work 🤷 |
Lovelly! |
OMG, finally. The latest artifacts in #42 correctly implement permissions for macOS. This will be closed as soon as the work in that PR is cleaned up. @mrclary, you can use the packages in The JSON files support new keys to address your concerns with environment variables, pre-activation logic and entitlements for correct permissions. Thank you so much for the report and constant feedback! |
@jaimergp, great! I'll take a look at implementing for Spyder. |
🐛 Bug
A
PermissionError
is raised when usingos.scandir
with the conda-based application bundle.I've noticed the same issue with Spyder as well with conda-based application bundle.
This issue only manifests with the three user directories
~/Desktop
,~/Documents
, and~/Downloads
(and anything therein). No other directories on the system produce the error.Interestingly, this issue does not manifest when launching the application executable directly.
I've observed identical behavior on two separate machines:
To Reproduce
Steps to reproduce the behavior:
napari (0.4.16rc7).app
from Finderos.scandir
for any of the three user directories~/Desktop
,~/Documents
, or~/Downloads
Environment
napari: 0.4.16rc7
Platform: macOS-12.5.1-x86_64-i386-64bit
System: MacOS 12.5.1
Python: 3.9.13 | packaged by conda-forge | (main, May 27 2022, 17:00:52) [Clang 13.0.1 ]
Qt: 5.15.3
PySide2: 5.15.4
NumPy: 1.22.4
SciPy: 1.8.1
Dask: 2022.05.2
VisPy: 0.9.6
OpenGL:
Screens:
Plugins:
The text was updated successfully, but these errors were encountered: