From 2df30a83cb2ed9426a2407c099ca99aa89d5c6e1 Mon Sep 17 00:00:00 2001 From: Alexander Merkle Date: Thu, 10 Jul 2025 07:45:43 +0200 Subject: [PATCH] build,add: add support for corporate proxies Use the Proxy Environment http_proxy/HTTPS_PROXY/NO_PROXY to handle the http request. Signed-off-by: Alexander Merkle --- add.go | 5 ++++- tests/bud.bats | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/add.go b/add.go index 9a937944da3..683ee68de3a 100644 --- a/add.go +++ b/add.go @@ -141,7 +141,10 @@ func getURL(src string, chown *idtools.IDPair, mountpoint, renameTarget string, } tlsClientConfig.InsecureSkipVerify = insecureSkipTLSVerify == types.OptionalBoolTrue - tr := &http.Transport{TLSClientConfig: tlsClientConfig} + tr := &http.Transport{ + TLSClientConfig: tlsClientConfig, + Proxy: http.ProxyFromEnvironment, + } httpClient := &http.Client{Transport: tr} response, err := httpClient.Get(src) if err != nil { diff --git a/tests/bud.bats b/tests/bud.bats index 84d22e36418..9c4c2dd0ba4 100644 --- a/tests/bud.bats +++ b/tests/bud.bats @@ -7272,6 +7272,15 @@ _EOF fi } +@test "build proxy - ADD URL" { + _prefetch alpine + target=alpine-image + http_proxy=http://127.0.0.1:47 HTTPS_PROXY=http://127.0.0.1:47 \ + run_buildah 125 build $WITH_POLICY_JSON -t alpine-image -f $BUDFILES/add-checksum/Containerfile $BUDFILES/add-checksum + expect_output --substring "127.0.0.1:47" "connection to fake proxy must fail" + expect_output --substring "connection refused" "connection to fake proxy must fail" +} + @test "bud-with-mount-bind-from-like-buildkit" { skip_if_no_runtime skip_if_in_container