allow setugid with sandbox-exec

I have an executable (Google Chrome) that apparently "is running setugid()". I cannot find a way to make it work when called from within a /usr/bin/sandbox-exec sandbox without sudo.

Given the following sandbox profile:

(version 1)
(allow process-exec
    (literal "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome")
    (literal "/usr/bin/sudo")
    (with no-sandbox)
)

The following two commands work:

  • /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome
  • /usr/bin/sandbox-exec -f ./profile.sb sudo /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome

(although the second one is really not smart) but this does not work:

$ /usr/bin/sandbox-exec -f ./profile.sb /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome
2022-06-07 23:06:50.267 Google Chrome[21533:679255] The application with bundle ID com.google.Chrome is running setugid(), which is not allowed. Exiting.

I'm not sure what's preventing chrome from "running setugid()". I've read somewhere that it's something called "AppKit", but I'm not sure how it gets involved here. Is there a way to have sandbox-exec allow the chrome process to do what it needs, without sudo?

Any help is appreciated.

What you’re trying to do is not supported:

  • We don’t support running applications as root.

  • We don’t documented the sandbox programming language for third-party use.

What’s your high-level goal here? With more background I might be able to point you a supported option.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

@eskimo left some comments on your reply but it looks like they disappeared. Thanks for the quick reply.

I'm trying to run a nodejs process in a sandbox so that it doesn't have access to the filesystem outside of its directory. The node process needs to spawn Chrome however, which I'm trying to run without the sandbox.

We don’t support running applications as root.

I'm not trying to run Chrome as root, I just noticed that when I started it with sudo, it worked.

We don’t documented the sandbox programming language for third-party use.

I understand, I was just hoping for pointers. :)

I'm trying to run a nodejs process in a sandbox so that it doesn't have access to the filesystem outside of its directory. The node process needs to spawn Chrome

I don’t think there’s any good way to achieve this goal. While you might reasonably be able to reverse engineer the sandbox and apply that to your Node.js code, it’s very unlikely that Chrome will tolerate being run in that sandbox. It’s way too big for that. Eventually you’ll fall into a hole where Chrome expects to be able to do something and can’t because of your sandbox.

If I were in your shoes I’d investigate running this stuff in a VM. That provides good isolation while allowing the code to run in the environment that it expects. And if a macOS VM is too ‘heavy’, you could use a Linux VM instead.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Accepted Answer

Ok, I found a way. If sandbox-exec calls Chrome directly, things break, but calling a wrapper that then calls Chrome is ok:

(version 1)
(allow default)
(allow network*)
(deny file* (subpath "/Users/nicolas"))
(allow file-read-metadata (subpath "/Users/nicolas"))
(deny file* (subpath "/Applications"))
(deny file* (subpath "/Users/nicolas/Applications"))
(allow file* (subpath "/Users/nicolas/Library/Application Support"))
(allow process-exec
    (literal "/bin/ps")
    (literal "/path/to/chrome-runner")
    (with no-sandbox)
    )

The "chrome runner":

#!/bin/sh
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome
$ /usr/bin/sandbox-exec -f ./profile.sb ./chrome-runner
... actually opens Chrome

I know this is a little unorthodox, but thanks for your patience Quinn!

allow setugid with sandbox-exec
 
 
Q