Skip to content

Commit 672303f

Browse files
committed
fix: fail if the user is root
Also, add a new attribute for the brave to ignore the check. Signed-off-by: Thulio Ferraz Assis <3149049+f0rmiga@users.noreply.github.com>
1 parent 35391d9 commit 672303f

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

python/repositories.bzl

Lines 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

@@ -219,6 +232,11 @@ python_repository = repository_rule(
219232
"Either distutils or distutils_content can be specified, but not both.",
220233
mandatory = False,
221234
),
235+
"ignore_root_user_error": attr.bool(
236+
default = False,
237+
doc = "Whether the check for root should be ignored or not. This causes cache misses with .pyc files.",
238+
mandatory = False,
239+
),
222240
"platform": attr.string(
223241
doc = "The platform name for the Python interpreter tarball.",
224242
mandatory = True,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy