Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions python/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,26 @@ def _python_repository_impl(rctx):
rctx.file(distutils_path, rctx.attr.distutils_content)

# Make the Python installation read-only.
if "windows" not in rctx.os.name:
exec_result = rctx.execute(["chmod", "-R", "ugo-w", "lib"])
if exec_result.return_code:
fail_msg = "Failed to make interpreter installation read-only. 'chmod' error msg: {}".format(
exec_result.stderr,
)
fail(fail_msg)
if not rctx.attr.ignore_root_user_error:
if "windows" not in rctx.os.name:
exec_result = rctx.execute(["chmod", "-R", "ugo-w", "lib"])
if exec_result.return_code != 0:
fail_msg = "Failed to make interpreter installation read-only. 'chmod' error msg: {}".format(
exec_result.stderr,
)
fail(fail_msg)
exec_result = rctx.execute(["touch", "lib/.test"])
if exec_result.return_code == 0:
exec_result = rctx.execute(["id", "-u"])
if exec_result.return_code != 0:
fail("Could not determine current user ID. 'id -u' error msg: {}".format(
exec_result.stderr,
))
uid = int(exec_result.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.")
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps a comment with https://man7.org/linux/man-pages/man7/capabilities.7.html for developers would be helpful.


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

Expand Down Expand Up @@ -227,6 +240,11 @@ python_repository = repository_rule(
"Either distutils or distutils_content can be specified, but not both.",
mandatory = False,
),
"ignore_root_user_error": attr.bool(
default = False,
doc = "Whether the check for root should be ignored or not. This causes cache misses with .pyc files.",
mandatory = False,
),
"platform": attr.string(
doc = "The platform name for the Python interpreter tarball.",
mandatory = True,
Expand Down