-
-
Notifications
You must be signed in to change notification settings - Fork 640
fix: Downgrade "running as root" error to a warning by default #2636
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5a55602
fix: Downgrade "running as root" error to a warning by default
Wyverald 04513e5
Apply suggestions from code review
rickeylev 9eec15e
mark the ignore_root_user_error override deprecated
Wyverald 472734c
Merge branch 'main' into wyv-noroot
Wyverald File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -127,37 +127,36 @@ def _python_repository_impl(rctx): | |
| # pycs being generated at runtime: | ||
| # * The pycs are not deterministic (they contain timestamps) | ||
| # * Multiple processes trying to write the same pycs can result in errors. | ||
| if not rctx.attr.ignore_root_user_error: | ||
| if "windows" not in platform: | ||
| lib_dir = "lib" if "windows" not in platform else "Lib" | ||
| if "windows" not in platform: | ||
| repo_utils.execute_checked( | ||
| rctx, | ||
| op = "python_repository.MakeReadOnly", | ||
| arguments = [repo_utils.which_checked(rctx, "chmod"), "-R", "ugo-w", "lib"], | ||
| logger = logger, | ||
| ) | ||
|
|
||
| repo_utils.execute_checked( | ||
| rctx, | ||
| op = "python_repository.MakeReadOnly", | ||
| arguments = [repo_utils.which_checked(rctx, "chmod"), "-R", "ugo-w", lib_dir], | ||
| logger = logger, | ||
| ) | ||
| exec_result = repo_utils.execute_unchecked( | ||
| fail_or_warn = print if rctx.attr.ignore_root_user_error else fail | ||
|
||
| exec_result = repo_utils.execute_unchecked( | ||
| rctx, | ||
| op = "python_repository.TestReadOnly", | ||
| arguments = [repo_utils.which_checked(rctx, "touch"), "lib/.test"], | ||
| logger = logger, | ||
| ) | ||
|
|
||
| # The issue with running as root is the installation is no longer | ||
| # read-only, so the problems due to pyc can resurface. | ||
| if exec_result.return_code == 0: | ||
| stdout = repo_utils.execute_checked_stdout( | ||
| rctx, | ||
| op = "python_repository.TestReadOnly", | ||
| arguments = [repo_utils.which_checked(rctx, "touch"), "{}/.test".format(lib_dir)], | ||
| op = "python_repository.GetUserId", | ||
| arguments = [repo_utils.which_checked(rctx, "id"), "-u"], | ||
| logger = logger, | ||
| ) | ||
|
|
||
| # The issue with running as root is the installation is no longer | ||
| # read-only, so the problems due to pyc can resurface. | ||
| if exec_result.return_code == 0: | ||
| stdout = repo_utils.execute_checked_stdout( | ||
| rctx, | ||
| op = "python_repository.GetUserId", | ||
| arguments = [repo_utils.which_checked(rctx, "id"), "-u"], | ||
| logger = logger, | ||
| ) | ||
| uid = int(stdout.strip()) | ||
| if uid == 0: | ||
| fail("The current user is root, please run as non-root when using the hermetic Python interpreter. See https://github.com/bazelbuild/rules_python/pull/713.") | ||
| else: | ||
| fail("The current user has CAP_DAC_OVERRIDE set, please drop this capability when using the hermetic Python interpreter. See https://github.com/bazelbuild/rules_python/pull/713.") | ||
| uid = int(stdout.strip()) | ||
| if uid == 0: | ||
| fail_or_warn("The current user is root, which can cause spurious cache misses or build failures with the hermetic Python interpreter. See https://github.com/bazelbuild/rules_python/pull/713.") | ||
| else: | ||
| fail_or_warn("The current user has CAP_DAC_OVERRIDE set, which can cause spurious cache misses or build failures with the hermetic Python interpreter. See https://github.com/bazelbuild/rules_python/pull/713.") | ||
|
|
||
| python_bin = "python.exe" if ("windows" in platform) else "bin/python3" | ||
|
|
||
|
|
@@ -294,7 +293,7 @@ For more information see {attr}`py_runtime.coverage_tool`. | |
| mandatory = False, | ||
| ), | ||
| "ignore_root_user_error": attr.bool( | ||
| default = False, | ||
| default = True, | ||
| doc = "Whether the check for root should be ignored or not. This causes cache misses with .pyc files.", | ||
| mandatory = False, | ||
| ), | ||
|
|
||
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.