Skip to content

Inconsistent HTTP_PROXY/HTTPS_PROXY Environment Variable Passthrough Behavior #1654

Open
@golixp

Description

@golixp

Problem Description:

In the current implementation of DockerCommandExt (located in src/docker/shared.rs), the environment variables http_proxy, https_proxy, and HTTPS_PROXY are explicitly passed through to containers via the other list. However, the uppercase HTTP_PROXY is missing from this list, leading to inconsistent behavior. This omission prevents users from controlling the passthrough of HTTP_PROXY when using cross, even if it is explicitly configured in Cross.toml.

Furthermore, the hardcoded passthrough logic for these variables takes precedence over the passthrough field in Cross.toml. For example, the following configuration fails to override the proxy settings because the code prioritizes its internal list:

In Cross.toml:

[build.env]
passthrough = [
    "HTTP_PROXY=http://172.17.0.1:7897",
    "HTTPS_PROXY=http://172.17.0.1:7897",
    "http_proxy=http://172.17.0.1:7897",
    "https_proxy=http://172.17.0.1:7897",
]

In /etc/environment:

# other
HTTPS_PROXY=http://127.0.0.1:7897
HTTP_PROXY=http://127.0.0.1:7897
# other

In cross build container, docker inspect <container_id>:

"Env": [
    "HTTPS_PROXY=http://127.0.0.1:7897",
    "HTTP_PROXY=http://172.17.0.1:7897",
    // other
],

This creates confusion for users who expect the configuration file to take precedence.

Feature Request:

  1. Add a Switch for Proxy Variables:
    Introduce a configuration option (e.g., in Cross.toml) to enable/disable the passthrough of all four proxy-related environment variables:
    http_proxy, https_proxy, HTTP_PROXY, and HTTPS_PROXY.
    This would allow users to explicitly opt-in or opt-out of their propagation to containers.

  2. Document the Passthrough Logic:
    Update the documentation to clearly explain:
    • Which environment variables are passed through by default.
    • How the passthrough field in Cross.toml interacts with the hardcoded list (e.g., whether it appends to or overrides the defaults).
    • How to use the new switch to control proxy variable behavior.


Additional Notes:

• Link to code snippet: shared.rs
• Cross Version: 0.2.5
• OS: EndeavourOS


Note:
This issue description was initially generated by an LLM (language model) and subsequently edited by me for accuracy and clarity, as my native English proficiency is limited. The core problem and proposed solution reflect my actual observations and needs while using cross.

Original Prompt:

我现在发现rust的交叉编译工具cross中的问题, 在源码src/docker/shared.rs下, 有:

    fn add_configuration_envvars(&mut self) {
        let other = &[
            "http_proxy",
            "TERM",
            "RUSTDOCFLAGS",
            "RUSTFLAGS",
            "BROWSER",
            "HTTPS_PROXY",
            "HTTP_TIMEOUT",
            "https_proxy",
            "QEMU_STRACE",
        ];
        let cargo_prefix_skip = &[
            "CARGO_HOME",
            "CARGO_TARGET_DIR",
            "CARGO_BUILD_TARGET_DIR",
            "CARGO_BUILD_RUSTC",
            "CARGO_BUILD_RUSTC_WRAPPER",
            "CARGO_BUILD_RUSTC_WORKSPACE_WRAPPER",
            "CARGO_BUILD_RUSTDOC",
        ];
        let cross_prefix_skip = &[
            "CROSS_RUNNER",
            "CROSS_RUSTC_MAJOR_VERSION",
            "CROSS_RUSTC_MINOR_VERSION",
            "CROSS_RUSTC_PATCH_VERSION",
        ];
        let is_passthrough = |key: &str| -> bool {
            other.contains(&key)
                || key.starts_with("CARGO_") && !cargo_prefix_skip.contains(&key)
                || key.starts_with("CROSS_") && !cross_prefix_skip.contains(&key)
        };

        // also need to accept any additional flags used to configure
        // cargo or cross, but only pass what's actually present.
        for (key, _) in env::vars() {
            if is_passthrough(&key) {
                self.args(["-e", &key]);
            }
        }
    }

可以看到http_proxy/https_proxy/HTTPS_PROXY三个变量会被透传到容器中, 但是HTTP_PROXY不会被传递, 而且这里的优先级比Cross.toml的配置文件更高:

[build.env]
passthrough = [
    "HTTP_PROXY=http://172.17.0.1:7897",
    "HTTPS_PROXY=http://172.17.0.1:7897",
    "http_proxy=http://172.17.0.1:7897",
    "https_proxy=http://172.17.0.1:7897",
]

如上配置不会覆盖这几个代码中写死的变量, 我向在官方issues中提出功能请求:

  1. 增加控制http_proxy/https_proxy/HTTP_PROXY/HTTPS_PROXY四个环境变量是否传递到容器的开关
  2. 在文档中写明相关环境变量传递的逻辑

用英文编写, 描述详细的问题

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions