Skip to content

honor containers.conf http_proxy and env settings during build - #6996

Open
unlimitedsola wants to merge 1 commit into
podman-container-tools:mainfrom
sola-contrib:honor-containers-conf
Open

honor containers.conf http_proxy and env settings during build#6996
unlimitedsola wants to merge 1 commit into
podman-container-tools:mainfrom
sola-contrib:honor-containers-conf

Conversation

@unlimitedsola

@unlimitedsola unlimitedsola commented Jul 26, 2026

Copy link
Copy Markdown

What type of PR is this?

/kind bug

What this PR does / why we need it

This PR resolves an issue where podman build ignored containers.conf settings (http_proxy = false and [containers] env). Please also see the linked issue for more context.

  1. Binds the --http-proxy CLI flag default in pkg/cli/common.go to Containers.HTTPProxy from containers.conf instead of hardcoding true. This makes build proxy flag defaults consistent with podman run, allowing http_proxy = false in containers.conf to disable host environment proxy passthrough by default.
  2. Updates configureEnvironment() in run_common.go to inject environment variables defined under [containers] env in containers.conf into the transient container process spec (g.AddProcessEnv) during RUN steps. This fixes the regression from pre-6.0.x where containers.conf environment settings applied to build execution commands (e.g. package management and network requests).

How to verify it

  1. Configure containers.conf:

    [containers]
    http_proxy = false
    env = [
      "http_proxy=http://host.containers.internal:1080",
    ]
  2. Export host shell environment variables:

    export http_proxy=http://127.0.0.1:1080
  3. Run build:

    podman build --no-cache -f - . << 'EOF'
    FROM alpine
    RUN env | grep -i proxy
    EOF
  4. Verify output contains http_proxy=http://host.containers.internal:1080 instead of http://127.0.0.1:1080.

Which issue(s) this PR fixes

podman-container-tools/podman#29299

Special notes for your reviewer

g.AddProcessEnv in configureEnvironment() sets the process spec environment (g.Config.Process.Env) for transient container execution during RUN steps. It does not touch builder.OCIv1.Config.Env, ensuring that environment variables configured in containers.conf apply to build execution without polluting committed image layers.

Does this PR introduce a user-facing change?

Not sure if a release note is needed for regressions, but this does contain user-facing change:

Honor `containers.conf` `http_proxy` and `env` settings during image builds, aligning the behavior with `podman run` and fixed regression introduced in 6.0.x.

Comment thread run_common.go Outdated
}
}

if conf, err := config.Default(); err == nil {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I would suggest against silently ignoring the error, similarly to other calls of config.Default in the file.

if err != nil {
	return nil, fmt.Errorf("failed to get container config: %w", err)
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks for the feedback! I changed the function signature so that the error can now bubble up instead of silently ignored.

Comment thread run_common.go

@nalind nalind left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, but I expect you'll need to run make fmt to fix the linter formatter warning.

@TomSweeneyRedHat

Copy link
Copy Markdown
Contributor

LGTM
once the gofmt issue on line 87 in the test is made happy

@nalind

nalind commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Please squash your commits before merging. Thanks!

@unlimitedsola
unlimitedsola force-pushed the honor-containers-conf branch 2 times, most recently from fb9edc4 to 0b2dad6 Compare July 28, 2026 21:35
@packit-as-a-service

Copy link
Copy Markdown

Ephemeral COPR build failed. @containers/packit-build please check.

@unlimitedsola

Copy link
Copy Markdown
Author

Ephemeral COPR build failed. @containers/packit-build please check.

I've squashed and rebased my commits. I think this was caused by me force-pushed twice too quickly?

@unlimitedsola
unlimitedsola force-pushed the honor-containers-conf branch from 0b2dad6 to 96d1c94 Compare August 8, 2026 03:56
@unlimitedsola

Copy link
Copy Markdown
Author

The CI failure seems unrelated to the code change. Let me know if there is anything that I can help to move this forward.

@simonbrauner simonbrauner left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I added a few more comments. Otherwise, LGTM

Don't worry about unrelated test failures, somebody who has the permissions can rerun the tests later.

Comment thread run_freebsd.go Outdated
@@ -123,7 +123,9 @@ func (b *Builder) Run(command []string, options RunOptions) error {
}

// hardwire the environment to match docker build to avoid subtle and hard-to-debug differences due to containers.conf

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This comment implies that containers.conf won't be used at all, while the PR introduces the possibility of loading proxy variables from containers.conf.

I would propose updating it with something like this:

Suggested change
// hardwire the environment to match docker build to avoid subtle and hard-to-debug differences due to containers.conf
// Pass a fixed environment to match docker build because passing the whole containers.conf instead would cause
// subtle and hard-to-debug differences. Proxy variables are the exception, as they are read from containers.conf in configureEnvironment.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Appreciate your feedback! I've updated the comment as you suggested.

Comment thread run_linux.go Outdated
@@ -230,7 +230,9 @@ func (b *Builder) Run(command []string, options RunOptions) error {
}

// hardwire the environment to match docker build to avoid subtle and hard-to-debug differences due to containers.conf

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

also updated as suggested

Comment thread run_common_test.go
`
err := os.WriteFile(confPath, []byte(confContent), 0o644)
require.NoError(t, err)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

As far as I can tell, the t.Setenv followed by config.New(&config.Options{SetDefault: true}) overwrites the config cache there https://github.com/podman-container-tools/container-libs/blob/16d801f1d5b2e615f9eb11f34ce007e428a294a6/common/pkg/config/new.go#L93C1-L96C3 and does not revert the change, which could cause problems later in the tests.

I'd propose running config.New(&config.Options{SetDefault: true}) on clean up (registered before the t.Setenvs because they call Cleanup internally and the clean up happens in the LIFO order), after the environment change of t.Setenv is restored already, so that we have the initial state again:

Suggested change
t.Cleanup(func() { _, _ = config.New(&config.Options{SetDefault: true}) })

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Interesting, I wasn't aware that the config cache would persist across tests. I now registered the cleanup callback before the set envs and added comments to explain what it is for.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'd improve the wording of the comment. It is not the cause that t.Cleanup before t.Setenv causes t.Cleanup run in LIFO order, but rather than cleanups always run in LIFO order, which is the reason why we need to register the reset function before t.Setenv register their own.

// Reset the default container config cache on test cleanup. Register before t.Setenv so that
// the cleanups caused by `t.Setenv` calls run before it (because cleanup happens in LIFO order).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This is indeed less ambiguous. I've updated both comments as suggested.

Comment thread run_common_test.go
`
err := os.WriteFile(confPath, []byte(confContent), 0o644)
require.NoError(t, err)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Added the same cleanup and comment as above.

@unlimitedsola
unlimitedsola force-pushed the honor-containers-conf branch from 96d1c94 to aea385c Compare August 12, 2026 06:53
Default the `--http-proxy` CLI flag to `Containers.HTTPProxy` from
`containers.conf` instead of hardcoding `true`. This ensures the
behavior is consistent with `podman run`, allowing `http_proxy = false`
in `containers.conf` to disable host proxy passthrough by default.

Additionally, update `configureEnvironment()` to inject proxy environment
variables defined under `[containers] env` in `containers.conf` into the
transient container process environment during `RUN` steps.
This restores the pre-6.0.x behavior where `containers.conf` environment
settings applied to build execution steps, while ensuring runtime proxy
settings do not leak `ENV` directives into committed image metadata.

Signed-off-by: Sola <dev@sola.love>
@unlimitedsola
unlimitedsola force-pushed the honor-containers-conf branch from aea385c to aee594d Compare August 12, 2026 12:31
@simonbrauner

Copy link
Copy Markdown

My comments were addressed.

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