Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e67e7dd

Browse filesBrowse files
authored
fix: fail if the user is root (bazel-contrib#749)
1 parent 07ead72 commit e67e7dd
Copy full SHA for e67e7dd

File tree

Expand file treeCollapse file tree

1 file changed

+25
-7
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+25
-7
lines changed

‎python/repositories.bzl

Copy file name to clipboardExpand all lines: python/repositories.bzl
+25-7Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,26 @@ def _python_repository_impl(rctx):
108108
rctx.file(distutils_path, rctx.attr.distutils_content)
109109

110110
# Make the Python installation read-only.
111-
if "windows" not in rctx.os.name:
112-
exec_result = rctx.execute(["chmod", "-R", "ugo-w", "lib"])
113-
if exec_result.return_code:
114-
fail_msg = "Failed to make interpreter installation read-only. 'chmod' error msg: {}".format(
115-
exec_result.stderr,
116-
)
117-
fail(fail_msg)
111+
if not rctx.attr.ignore_root_user_error:
112+
if "windows" not in rctx.os.name:
113+
exec_result = rctx.execute(["chmod", "-R", "ugo-w", "lib"])
114+
if exec_result.return_code != 0:
115+
fail_msg = "Failed to make interpreter installation read-only. 'chmod' error msg: {}".format(
116+
exec_result.stderr,
117+
)
118+
fail(fail_msg)
119+
exec_result = rctx.execute(["touch", "lib/.test"])
120+
if exec_result.return_code == 0:
121+
exec_result = rctx.execute(["id", "-u"])
122+
if exec_result.return_code != 0:
123+
fail("Could not determine current user ID. 'id -u' error msg: {}".format(
124+
exec_result.stderr,
125+
))
126+
uid = int(exec_result.stdout.strip())
127+
if uid == 0:
128+
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.")
129+
else:
130+
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.")
118131

119132
python_bin = "python.exe" if ("windows" in platform) else "bin/python3"
120133

@@ -227,6 +240,11 @@ python_repository = repository_rule(
227240
"Either distutils or distutils_content can be specified, but not both.",
228241
mandatory = False,
229242
),
243+
"ignore_root_user_error": attr.bool(
244+
default = False,
245+
doc = "Whether the check for root should be ignored or not. This causes cache misses with .pyc files.",
246+
mandatory = False,
247+
),
230248
"platform": attr.string(
231249
doc = "The platform name for the Python interpreter tarball.",
232250
mandatory = True,

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.