Conversation
5830642 to
7a71c56
Compare
chmod/id/touch` hermeticchmod/id/touch hermetic
7a71c56 to
42fcb8e
Compare
python/repositories.bzl
Outdated
| if "windows" not in platform: | ||
| lib_dir = "lib" if "windows" not in platform else "Lib" | ||
|
|
||
| python = _get_host_python_interpreter(rctx) |
There was a problem hiding this comment.
I think we should use the python_bin var that is defined below instead of using the host_python. And we should do the read-only fix only if the host platform the same as the platform of the toolchain.
Could we recursively change this for windows as well? Right now we are calling this only if it is not Windows, but do the scripts work on Windows?
There was a problem hiding this comment.
os.chmod says:
Although Windows supports chmod(), you can only set the file’s read-only flag with it (via the
stat.S_IWRITEandstat.S_IREADconstants or a corresponding integer value). All other bits are ignored.
So, yes, it would remove write access on Windows.
os.getuid is not available on Windows but I can find a fallback for that.
There was a problem hiding this comment.
The chmod.py does set the folders and files to read-only on Windows, but does not prevent new files being created in the directories. So the same behaviour as Unix is not present. We would have to look into Windows permissions to restrict that.
The getuid could return the Window Security ID for the user but that doesn't really help much. I've removed the touch check by checking platform.
We now run the scripts on Windows, but they don't really do much and actually fail to prevent .pyc files being written. Which is no different to before this patch.
There was a problem hiding this comment.
One can prevent writing files into directories on Windows with security permissions. That could be done by calling out to icacls.exe (in leiu of the win32security dependency). That will likely take significant extra testing as I'm not a Windows expert.
There was a problem hiding this comment.
@aignas would you like me to continue figuring out truely read-only directories on Windows or does this PR move the needle enough to be considered for merge? I'd be happy to raise follow up issues/PRs, if necessary.
e9b91f5 to
126abef
Compare
|
@rickeylev, what do you think about this? How do we move with this forward? Should we just start ignoring the I am thinking that having the |
So, correctness wise, there are two things we're constrained by:
(1) can be accomplished by any of:
I think we should do (a) regardless -- its just defense in depth. For the case of Windows (or other failures) we should just be OK with leaving things writable. It's the best we can do, and users will just bypass it entirely with ignore_root_error=True anyways (they are given the choice between "guaranteed pedantic failure" and "probably works, but flaky"; they'll always choose the latter). I think (b) is better than (c), but it's out of scope for this PR and we already have (c) in place. (2) throws a wrench into what this PR is doing -- using the downloaded runtime itself to run commands to make things read only. So I'm not really keen on that overall. I don't mind having an alternative implementation of chmod for OP's case where coreutils aren't available. Ideally, we'd either have a repo-phase reference to a host-compatible Python, or a repo-phase reference to a host-compatible chmod tool. So, more concretely, I ask for the following changes:
|
126abef to
b2dfc27
Compare
Uses `uutils/coreutils` on most platforms, falls backto host `chmod` otherwise. Removes failure checking[1] as we now "trust" that things are OK. [1]: bazel-contrib#2024 (comment)
chmod/id/touch hermeticchmod hermetic
Uses `uutils/coreutils` on most platforms, falls backto host `chmod` otherwise. Removes failure checking[1] as we now "trust" that things are OK. [1]: bazel-contrib#2024 (comment)
b2dfc27 to
632807f
Compare
Uses `uutils/coreutils` on most platforms, falls backto host `chmod` otherwise. Removes failure checking[1] as we now "trust" that things are OK. [1]: bazel-contrib#2024 (comment)
632807f to
02d980c
Compare
Uses `uutils/coreutils` on most platforms, falls backto host `chmod` otherwise. Removes failure checking[1] as we now "trust" that things are OK. [1]: bazel-contrib#2024 (comment)
02d980c to
29c61fa
Compare
Uses `uutils/coreutils` on most platforms, falls backto host `chmod` otherwise. Removes failure checking[1] as we now "trust" that things are OK. [1]: bazel-contrib#2024 (comment)
29c61fa to
14cc4b5
Compare
Uses `uutils/coreutils` on most platforms, falls backto host `chmod` otherwise. Removes failure checking[1] as we now "trust" that things are OK. [1]: bazel-contrib#2024 (comment)
14cc4b5 to
444ebe0
Compare
Uses `uutils/coreutils` on most platforms, falls backto host `chmod` otherwise. Removes failure checking[1] as we now "trust" that things are OK. [1]: bazel-contrib#2024 (comment)
444ebe0 to
b9b43d6
Compare
Uses `uutils/coreutils` on most platforms, falls backto host `chmod` otherwise. Removes failure checking[1] as we now "trust" that things are OK. [1]: bazel-contrib#2024 (comment)
b9b43d6 to
38bd001
Compare
Uses `uutils/coreutils` on most platforms, falls backto host `chmod` otherwise. Removes failure checking[1] as we now "trust" that things are OK. [1]: bazel-contrib#2024 (comment)
38bd001 to
b004e22
Compare
|
I've updated to use |
| logger = logger, | ||
| ).return_code == 0 | ||
|
|
||
| def _chmod(rctx, platform = None): |
There was a problem hiding this comment.
Speculation, that needs to be measured: The way this is implemented it would fetch and extract the chmod binary for each python version. It would use the bazel repository cache, but having the chmod in a separate repository might be better from the performance point of view?
In general, using the chmod that is hermetic is an interesting idea, but I wonder if we should use the system chmod if it exists and if it doesn't, download the hermetic chmod. That would also satisfy the ask to support your usecase where system chmod is not available. All of this could be done in a separate host_chmod repository, we could even switch the behaviour to default to the hermetic chmod if an env var is set to a particular value.
|
I'm keen to work through getting this landed. I can rework the branch to current Could I get some hints on how to implement this so that it has the best chance to get accepted, please? |
|
I think there are multiple options here: option 1 - use this chmodIn this case I think it would be best to create a separate repository rule maybe something called We register this somewhere in option 2 - trust our glob and remove chmodRemove the chmoding. This would solve the following:
Drawback:
option 3 - do nothingRequires on system proposalI would actually propose option 2, @rickeylev, @mattyclarkson, what do you think? cc: @arrdem |
|
Option 2 is fine with me. @rickeylev? |
|
Option 2 SGTM |
|
Option 1 seems bad, option 3 I don't follow the downsides of. I'm leaning 2 by default but I don't feel like I have an informed opinion here. |
|
So I'd propose us to go with the option 2 moving forward. |
As discussed in the #2024 messaged we decided to remove the chmoding and simplify the setup for all of our users. This in effect unifies how the toolchains are created across all of the platforms reducing the need for some of the integration tests. Summary: - `python_repository`: stop chmoding - `python_repository`: make `ignore_root_user_error` noop - `python(bzlmod)`: stop using `ignore_root_user_error`. - `tests`: remove `ignore_root_user_error` tests. Fixes #2016 Fixes #2053 Closes #2024
Removes the need for system binaries to make the Python interpreter library directories/files read-only.
Fixes #2016