Skip to content
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

sandbox: deny read access to HOMEBREW_PREFIX/{bin,include,lib} #2970

Closed
wants to merge 1 commit into from

Conversation

ilovezfs
Copy link
Contributor

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew tests with your changes locally?

See discussion in #2173.

@ilovezfs
Copy link
Contributor Author

CC @zmwangx @MikeMcQuaid

@zmwangx
Copy link
Contributor

zmwangx commented Jul 29, 2017

LGTM, but you probably won't find the breakages until you rebuild everything.

@zmwangx
Copy link
Contributor

zmwangx commented Jul 29, 2017

Tried a few random things. First breakage I caught:

$ brew postinstall --debug python
/usr/local/Homebrew/Library/Homebrew/brew.rb (Formulary::FormulaLoader): loading /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/python.rb
==> Postinstalling python
==> Using the sandbox
/usr/bin/sandbox-exec -f /tmp/homebrew20170729-5335-1qaxxnw.sb nice /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby -W0 -I /usr/local/Homebrew/Library/Homebrew -- /usr/local/Homebrew/Library/Homebrew/postinstall.rb /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/python.rb --debug
/usr/local/Homebrew/Library/Homebrew/postinstall.rb (Formulary::FromPathLoader): loading /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/python.rb
Error: File exists - /usr/local/lib
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/fileutils.rb:245:in `mkdir'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/fileutils.rb:245:in `fu_mkdir'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/fileutils.rb:219:in `block (2 levels) in mkdir_p'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/fileutils.rb:217:in `reverse_each'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/fileutils.rb:217:in `block in mkdir_p'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/fileutils.rb:203:in `each'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/fileutils.rb:203:in `mkdir_p'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/pathname.rb:559:in `mkpath'
/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/python.rb:243:in `post_install'
/usr/local/Homebrew/Library/Homebrew/formula.rb:974:in `block (2 levels) in run_post_install'
/usr/local/Homebrew/Library/Homebrew/formula.rb:832:in `with_logging'
/usr/local/Homebrew/Library/Homebrew/formula.rb:973:in `block in run_post_install'
/usr/local/Homebrew/Library/Homebrew/utils.rb:554:in `with_env'
/usr/local/Homebrew/Library/Homebrew/formula.rb:965:in `run_post_install'
/usr/local/Homebrew/Library/Homebrew/postinstall.rb:16:in `<main>'

@ilovezfs
Copy link
Contributor Author

Also, it somehow needs to exempt stdenv I think.

@zmwangx
Copy link
Contributor

zmwangx commented Jul 29, 2017

stdenv is still a thing? Wow.

@ilovezfs
Copy link
Contributor Author

@zmwangx yeah, the test blocks and anything depending on scons.

@DomT4
Copy link
Member

DomT4 commented Jul 29, 2017

Isn't the superenv change enough here without relying on the sandbox mechanism to enforce it?

@ilovezfs
Copy link
Contributor Author

@DomT4 it is when it works. Not so much, when it doesn't. See Homebrew/homebrew-core#15910, and #2173 as already mentioned.

Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is super awesome 👏 👍 🎉

@@ -162,6 +162,11 @@ class SandboxProfile
(regex #"^/dev/ttys?[0-9]*$")
)
(deny file-write*) ; deny non-whitelist file write operations
(deny file-read*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably want this in a def deny_write_homebrew_something method and then make it conditional on an environment variable being set.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could also use HOMEBREW_PREFIX/"lib", etc in that method rather than hardcoding /usr/local, if desired.

@@ -167,7 +167,7 @@ def determine_isystem_paths
end

def determine_include_paths
PATH.new(keg_only_deps.map(&:opt_include)).existing
PATH.new(deps.map(&:opt_include)).existing
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably want this conditional on an environment variable being set

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the same environment variable as in #2970 (comment)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aye.

@@ -176,8 +176,7 @@ def homebrew_extra_library_paths

def determine_library_paths
PATH.new(
keg_only_deps.map(&:opt_lib),
HOMEBREW_PREFIX/"lib",
deps.map(&:opt_lib),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably want this conditional on an environment variable being set

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aye.

@@ -162,6 +162,11 @@ class SandboxProfile
(regex #"^/dev/ttys?[0-9]*$")
)
(deny file-write*) ; deny non-whitelist file write operations
(deny file-read*
(regex #"^/usr/local/bin.*$")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth having a trailing / before .*$? Worth handling sbin?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing / still lets you see in the directory.

sbin

probably

@DomT4
Copy link
Member

DomT4 commented Jul 30, 2017

@ilovezfs Fair enough. Just seemed a strange mix of tools to achieve the goal, but I'm rarely one to object to expanding a sandbox 😉. You've already fixed something I was going to point out & Mike has suggested a couple others, so, I'll be quiet for now 😄.

@Homebrew Homebrew deleted a comment from Ellorah Jul 30, 2017
@stale stale bot added the stale No recent activity label Aug 20, 2017
@ilovezfs ilovezfs added the in progress Maintainers are working on this label Aug 26, 2017
@stale stale bot removed the stale No recent activity label Aug 26, 2017
@Homebrew Homebrew deleted a comment from stale bot Aug 26, 2017
@ilovezfs ilovezfs closed this Nov 10, 2017
@RandomDSdevel
Copy link
Contributor

RandomDSdevel commented Nov 11, 2017

Rises from lurking to ask @ilovezfs: What was the rationale for closing this? I don't see any mention of taking another stab at the part of #2173 that's relevant to this PR here as of late.

@MikeMcQuaid
Copy link
Member

@RandomDSdevel Basically: unfortunately this PR isn't going to be something that we're ever going to be able to roll out to users.

@RandomDSdevel
Copy link
Contributor

@MikeMcQuaid: OK, but can you refresh my memory on where that was pointed out? I can't seem to find why at the moment, at least in this discussion thread…though maybe I'm overlooking something obvious…? 🤷‍♂️

@MikeMcQuaid
Copy link
Member

@RandomDSdevel It was not a public conversation I'm afraid.

@RandomDSdevel
Copy link
Contributor

@MikeMcQuaid: Oh. Sorry to bother you about it, then.

@Homebrew Homebrew locked and limited conversation to collaborators May 4, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
in progress Maintainers are working on this
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants