Retry networksetup commands with root privileges#376
Open
ccarstens wants to merge 1 commit intoZenPrivacy:masterfrom
Open
Retry networksetup commands with root privileges#376ccarstens wants to merge 1 commit intoZenPrivacy:masterfrom
ccarstens wants to merge 1 commit intoZenPrivacy:masterfrom
Conversation
anfragment
reviewed
Jun 24, 2025
Comment on lines
+81
to
+84
| cmd = elevate.WithPrompt("System changes required to activate proxy").Command("sh", "-c", strings.Join(retryCommands, " ")) | ||
| if out, err := cmd.CombinedOutput(); err != nil { | ||
| return fmt.Errorf("network setup with root privileges: %w (%q)", err, out) | ||
| } |
Member
There was a problem hiding this comment.
It looks like unfortunately elevate doesn't allow executing networksetup commands when "Require an administrator password to access system-wide settings" is on. Instead of setting uid to 0 like sudo does, elevate only sets euid to 0, which is apparently not enough for networksetup.
Here are two ideas on how to move forward:
- Run the commands via AppleScript with
osascript -e "do shell script "<;-separated commands>" with administrator privileges with prompt "Authorize Zen to modify system proxy settings". This works, however the displayed prompt shows osascript in the title, which might confuse some users:
- Another solution that may work is to just call
networksetup -setautoproxyurlwithout the other two commands. I'm struggling to find any official documentation on this, but local testing suggests that "automatic proxy configuration" (PAC) takes precedence over "web proxy" and "secure web proxy", which probably makes setting their state to "off" redundant.
@ccarstens @AitakattaSora thoughts on this?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Adds retry of the networksetup commands when macOS requires an admin password for system wide changes.
How did you verify your code works?
I activated System Settings -> Privacy & Security -> Advanced -> Require...
What are the relevant issues?
Closes #311