使用 root 权限部署应用程序

发布于 2024-10-07 06:00:06 字数 240 浏览 0 评论 0原文

我编写了一个 Cocoa 应用程序,它使用 libpcap 来监视网络流量。由于 libpcap 需要 root 权限,我想知道授予它 root 权限的最佳方法是什么(例如使用 Package Maker?)。我是否能够使用拖放安装程序来部署它,或者 Package Maker 是我唯一的选择吗?

此外,我想知道授予我的应用程序根权限所带来的安全风险。该应用程序还写入磁盘(sqlite 数据库),我读到给予应用程序写入磁盘根权限并不是一个好主意。

I have written a Cocoa app which uses libpcap to monitor network traffic. Since libpcap requires root privileges I was wondering what's the best way to give it root privileges (e.g. using Package Maker?). Would I be able to deploy it using a drag-and-drop installer or is Package Maker my only option?

Additionally I would like to know of the security risks posed by giving my app root permissions. The app also writes to disk (sqlite database) and I read that giving an app that writes to disk root privileges is not a good idea.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

妄司 2024-10-14 06:00:06

推荐的 Apple 方法如下:

  • 将需要特权操作的内容分解为单独的可执行文件(即为您使用 libpcap 的内容)。
  • 当应用程序需要启动特权exe时,它会创建一个授权引用并检查用户是否可以授权(称为预授权),并将授权的外部引用传递给特权exe。
  • 当它第一次启动时,特权 exe 在尝试执行特权操作之前会再次获得授权。

为了使上述工作正常进行,特权 exe 必须安装为 root 拥有并设置了 setuid 位。您可以使用软件包制作工具来执行此操作,也可以创建 Apple 术语 自我修复帮助工具。这是一个工具,用于检查它是否以 root 身份运行,如果不是,则通过 AuthorizationExecuteWithPrivileges 来修复其 setuid 位和所有权。然后它对操作进行授权并执行操作。

如果您使用自我修复工具,则可以将其与您的应用程序捆绑在一起,并使用拖放安装过程。

我强烈建议您阅读整个 授权编程指南。它更详细地讨论了所有这些内容,并包含一些示例代码。

The recommended Apple way to do what you want is as follows:

  • factor out the stuff that requires privileged operation into a separate executable (that's the stuff that uses libpcap for you).
  • when the application needs to start the privileged exe, it creates an authorization reference and checks the user can authorize (known as pre-authorization) and passes an external reference to the authorization to the privileged exe.
  • when it first starts, the privileged exe gains authorization again before attempting to do the privileged stuff.

For the above to work, the privileged exe has to be installed as owned by root with the setuid bit set. You can either do this with package maker or you can create what Apple terms a self repairing helper tool. This is a tool that checks if it is running as root and if not calls itself via AuthorizationExecuteWithPrivileges to repair its setuid bit and ownership. Then it does the authorization for the operation and performs the operation.

If you use the self repairing tool, you can bundle it in with your application and use a drag and drop installation process.

I strongly advise you to read the whole of the Authorization Programming Guide. It talks about all this stuff in more detail and includes some example code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文