-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
do not leak PATH, LD_LIBRARY_PATH, and TMPDIR into the shell environment by default #2574
Comments
@gregestren can you take a look at this? Thanks. |
This is definitely on our todo list, but I'm not sure when we'll get to it. Adding 1.0 as the expected milestone, because it needs to be fixed by then (although earlier would be better). |
There's a pretty easy workaround. Modify //tools/bazel in your repo to set the environment when it executes Bazel. We do something like:
That lets us control which version of bazel is in use for each revision of the repository, and the environment. That makes it easy to handle compatibility. |
Ugh, this could be a problem... |
@ulfjack Why would this be a problem? |
We have some users who are very eager to use remote caching, and we've been trying to get all the necessary changes into 0.5.2, so this bug could be a problem for them. |
I confirm that I see cache misses on changes to PATH in combination with bazel server restarts. :-( |
I've started on adding a flag for migration. We can't just remove the env variables, since that is a breaking change. |
- --experimental_strict_action_env makes Bazel not forward PATH, LD_LIBRARY_PATH, and TMPDIR to all actions. This is intended to be a transitional flag; as part of rollout, we'll need to update all users that rely on the current behavior to specify their needs explicitly (with --action_env). But note that action_env is not yet applied to all actions, which also needs to be fixed. - --shell_executable can be used to explicitly set the shell executable to use in actions. On Windows, if --experimental_strict_action_env is unset, then the PATH is computed to include the path to the shell executable. Progress on #2574. PiperOrigin-RevId: 161652996
I'd suggest setting --experimental_strict_action_env. It requires Bazel 0.5.3 or higher. |
Yep, that option seems do precisely the right thing for me. Thanks. Why does the option description mention |
Sorry about that. That was from an earlier version of the change where I set LANG, which I decided not to do after all. |
@mboes : No, because Bazel uses different output directories for these workspaces, plus the workspace-relative file names (of the output files) are different. |
There are multiple caches here. You can get a cache hit on the local or remote spawn cache, but not on the action cache, which is workspace-local, or on the in-memory cache, which is also workspace-local. If the two rules are in different locations (say //foo and //bar, then the names of the output files are likely different, in which case you can't get a cache hit either. |
@ulfjack thanks. Is there any place you can point me to, to understand the difference between the spawn cache and the action cache? Does the (local or remote) spawn cache cache action outputs, or is that the action cache? Being able to cache action outputs is pretty important for our use case. Haskell packages are notoriously slow to build. Many of them have source code (but not binary artifacts) published in a central location (called Hackage). We're considering running a remote cache that obviates the need for developers to have to rebuild these centrally published open source package every time they create a new project that uses them. |
The spawn caches cache action outputs, the action cache works with outputs in the output tree (it doesn't cache files separately). |
Gotcha. So IIUC, in the use case envisioned above, we should be able to avoid package rebuilds even across multiple (differently named) workspaces. |
Yes, absolutely. |
Ulf,
Any chance for a writeup (blog post?) about how and when the shell
environment and its paths effect the cache?
…On Mon, Jan 22, 2018 at 12:15 PM Ulf Adams ***@***.***> wrote:
Yes, absolutely.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#2574 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABUIF7zh_-cBC5EjIBDD7x6V9Xz1ool0ks5tNF_PgaJpZM4MJl2z>
.
|
qq: is there an ETA for when --experimental_strict_action_env=true will be the default ? |
I've just fixed a number of cases where --action_env did not properly apply. I think we might want to wait for another release before we flip the default. |
I see - makes sense, thank you! |
Will it become the default after 0.16.0? I too am pretty keen on this. :) |
See bazelbuild#2574. For a while, many actions did not respect the --action_env command line option, but those have been fixed now. So, I think it's time to flip on this flag for greater hermeticity by default.
See bazelbuild#2574. For a while, many actions did not respect the --action_env command line option, but those have been fixed now. So, I think it's time to flip on this flag for greater hermeticity by default.
See bazelbuild#2574. For a while, many actions did not respect the --action_env command line option, but those have been fixed now. So, I think it's time to flip on this flag for greater hermeticity by default.
See bazelbuild#2574. For a while, many actions did not respect the --action_env command line option, but those have been fixed now. So, I think it's time to flip on this flag for greater hermeticity by default.
See bazelbuild#2574. For a while, many actions did not respect the --action_env command line option, but those have been fixed now. So, I think it's time to flip on this flag for greater hermeticity by default.
See bazelbuild#2574. For a while, many actions did not respect the --action_env command line option, but those have been fixed now. So, I think it's time to flip on this flag for greater hermeticity by default.
See bazelbuild#2574. For a while, many actions did not respect the --action_env command line option, but those have been fixed now. So, I think it's time to flip on this flag for greater hermeticity by default. RELNOTES: The --experimental_strict_action_env option is now on by default. This means Bazel will no longer use the client's PATH and LD_LIBRARY_PATH environmental variables in the default action environment. If the old behavior is desired, pass --action_env=PATH and --action_env=LD_LIBRARY_PATH. --noexperimental_strict_action_env will also temporarily restore the old behavior. However, as --action_env is a more general and explicit way to pass client environmental variables into actions, --noexperimental_strict_action_env will eventually be deprecated and removed.
Also rename it to --incompatible_strict_action_env. See #6648 and #2574. For a while, many actions did not respect the --action_env command line option, but those have been fixed now. So, I think it's time to flip on this flag for greater hermeticity by default. Closes #6263. RELNOTES: The --experimental_strict_action_env option has been renamed to --incompatible_strict_action_env and is now on by default. This means Bazel will no longer use the client's PATH and LD_LIBRARY_PATH environmental variables in the default action environment. If the old behavior is desired, pass --action_env=PATH and --action_env=LD_LIBRARY_PATH. --noincompatible_strict_action_env will also temporarily restore the old behavior. However, as --action_env is a more general and explicit way to pass client environmental variables into actions, --noincompatible_strict_action_env will eventually be deprecated and removed. See #6648 for more details. PiperOrigin-RevId: 222053105
This has been enabled in Bazel 0.22 |
This requires both updating the version of rules_oci used as well as patching the zot launcher since TMPDIR is not set when using remote execution (likely due to bazelbuild/bazel#2574). Bug: 321291571 Change-Id: If6a7b8b7afbcee1e34bb8233edeb623db00d86c1
BazelConfiguration.setupShellEnvironement
makes the default shell environment inherit thePATH
,LD_LIBRARY_PATH
, andTMPDIR
environmental variables from the server environment (i.e., what they are at server startup time). I can see why this might be useful, but I don't think it should be the default behavior. I observed that this behavior was a source of indeterminism when building the same code on different machines; the build products were the same, but as environment affects the action key, remote caching across the machines didn't work. Why not be hermetic by default and have users who need to change these variables pass, e.g.,--action_env=PATH
?If the behavior can't be changed, I would at least like a way to unset those environmental variables in the shell environment from the command line. AFAICT, with
--action_env
currently, the best you can do is set them to an empty string.The text was updated successfully, but these errors were encountered: