How to sandbox a command line tool?

╄→гoц情女王★ 提交于 2019-11-30 00:50:17

I was having this exact problem, and it went away when I added an embedded Info.plist.

Try these clang flags (assuming you have info.plist in the build directory):

-Xlinker -sectcreate -Xlinker __TEXT -Xlinker __info_plist -Xlinker info.plist

Is the console application launched directly from console or is it called from a main sandboxed application? I received a similar error when trying to sandbox some binaries and I was just able to make it work by using only the below entitlements:

<dict>                                                                                                                                                                       
  <key>com.apple.security.app-sandbox</key>                                                                                                                                  
  <true/>                                                                                                                                                                    
  <key>com.apple.security.inherit</key>                                                                                                                                      
  <true/>                                                                                                                                                                    
</dict> 

Of course, after that you can only call the binary from a parent process that is already sandboxed (that is why I asked how your binary was called :)).

While @Nick Moore's answer is perfectly fine, there's an option for this in today's Xcode under Packaging - Create Info.plist Section in Binary (CREATE_INFOPLIST_SECTION_IN_BINARY). All that's needed is setting thue to Yes.

It seems if you sign an executable with com.apple.security.inherit it can only be called by another application that is already sandboxed. So you can't call it from cmdline anymore after you ran codesign.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!