Skip to content
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

Remove subprocess-environment allow list. #11743

Merged

Conversation

jsirois
Copy link
Contributor

@jsirois jsirois commented Mar 19, 2021

Now [subprocess-environment] env_vars can be used to selectively
allow arbitrary environment variables to be propagated to subprocesses.

[ci skip-rust]
[ci skip-build-wheels]

# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
@jsirois
Copy link
Contributor Author

jsirois commented Mar 19, 2021

This was motivated by a need to propagate ARCHFLAGS to work around giampaolo/psutil#1832 in #11733.

@jsirois jsirois merged commit d46197d into pantsbuild:master Mar 19, 2021
@jsirois jsirois deleted the SubprocessEnvironment/remove_allow_list branch March 19, 2021 16:23
Copy link
Contributor

@Eric-Arellano Eric-Arellano left a comment

Choose a reason for hiding this comment

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

Hm, I think this should probably have a blocklist, particularly with PATH in it? Otherwise users can break things. Ditto on PYTHONPATH probably

@jsirois
Copy link
Contributor Author

jsirois commented Mar 19, 2021

@Eric-Arellano I don't follow. We already need PATH to even support binary discovery at all. PYTHONPATH is sealed off by Pex unless you configure it in with Pex knobs - some (all?) exposed by Pants. You or Stu should take this up if I'm missing something because I really haven't followed the handwringing around env vars well.

@stuhood
Copy link
Member

stuhood commented Mar 19, 2021

I missed the discussion when the "allowlist" was initially added... but given that there is no way to wildcard env vars from the environment (and probably never will be...?), anything in this list has been explicitly added by a user, and I don't think it makes sense to limit things that have been explicitly added.

Aside:

If `allowed` is specified, the requested variable names must be in that list, or an error
will be raised.
is probably dead code now.

@Eric-Arellano
Copy link
Contributor

We already need PATH to even support binary discovery at all.

Yes, but Pants sets PATH and we do not want to allow the user to configure that one. The behavior would depend on our merge strategy: if the user overrides Pants, then things will almost certainly break. If Pants overrides the user, the user setting will do nothing and people will be confused. An eager blocklist and good error message is better UX. Does that make sense? If so, I can put up a patch.

You're right on PYTHONPATH - I think PATH is the only one we need to block.

@stuhood
Copy link
Member

stuhood commented Mar 19, 2021

Yes, but Pants sets PATH and we do not want to allow the user to configure that one.

Mm. Yea, that probably makes sense... although dogfooding remote caching in the next few days will likely further shape this.

If all we're trying to do is prevent someone from adding it to the list, I think that

If `allowed` is specified, the requested variable names must be in that list, or an error
will be raised.
can be made much simpler... no need to wait to see if it is set to fail.

@jsirois
Copy link
Contributor Author

jsirois commented Mar 19, 2021

Where does Pants set PATH? But otherwise agreed and there is actually no question. The general principle being you only need to block configuration of things you yourself set to avoid trampling - this has nothing really to do with env cars in particular.

@Eric-Arellano
Copy link
Contributor

Where does Pants set PATH?

FindBinary, for example:

Process(
description=f"Searching for `{request.binary_name}` on PATH={search_path}",
level=LogLevel.DEBUG,
input_digest=script_digest,
argv=[script_path, request.binary_name],
env={"PATH": search_path},
cache_scope=ProcessCacheScope.PER_RESTART,
),

@jsirois
Copy link
Contributor Author

jsirois commented Mar 19, 2021

Aha. If that's the only example, then it's not a great one. We can be doing that (bootstrapping finding bash) differently.

@jsirois
Copy link
Contributor Author

jsirois commented Mar 19, 2021

In fact, if that's the only example, it's a bad one. We should use a user specified PATH if present to find bash.

@stuhood
Copy link
Member

stuhood commented Mar 19, 2021

In fact, if that's the only example, it's a bad one. We should use a user specified PATH if present to find bash.

Probably. But this gets to the fact that "subprocess environment PATH" is probably too coarse a setting. I'm skeptical that someone will want to set the same PATH for all tools, although they might want to set it for FindBinary. FindBinary scans a PATH for tools so that we don't need the entire PATH set later, in general.

Allowing a different PATH to be set for FindBinary might be a usecase for #7735, but it might also be the case that FindBinary needs to become more of a native operation, a la #10769 and #10526. We'll be dogfooding remote caching soon (cc @tdyas), but getting back to dogfooding remote execution is what will really shake these issues out.

stuhood pushed a commit to stuhood/pants that referenced this pull request Mar 24, 2021
stuhood pushed a commit to stuhood/pants that referenced this pull request Mar 24, 2021
[ci skip-rust]

[ci skip-build-wheels]
stuhood added a commit that referenced this pull request Mar 24, 2021
Kill SETTABLE_ENV_VARS allow list.

Fixes #11790.

[ci skip-rust]
[ci skip-build-wheels]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants