Skip to content

machine: escape % as %% in proxy values written to systemd unit conf#28820

Open
crawfordxx wants to merge 1 commit into
podman-container-tools:mainfrom
crawfordxx:fix-escape-percent-in-systemd-proxy-conf
Open

machine: escape % as %% in proxy values written to systemd unit conf#28820
crawfordxx wants to merge 1 commit into
podman-container-tools:mainfrom
crawfordxx:fix-escape-percent-in-systemd-proxy-conf

Conversation

@crawfordxx
Copy link
Copy Markdown
Contributor

Problem

systemd treats % as a specifier character in unit configuration files
(e.g. %H → hostname, %40@ in percent-encoded strings).
When proxy environment variables contain URL-percent-encoded characters
(common in credentials: http://user%40example.com@proxy:3128), the
generated /etc/systemd/system.conf.d/default-env.conf contains
bare % sequences that systemd tries to expand as specifiers, leading to:

system.conf.d/default-env.conf:2: Failed to resolve specifiers in
HTTP_PROXY=http://user%40example.com@proxy:3128

Fix

Introduce a bash variable substitution ${proxy//%/%%} that doubles
every % to %% before writing to the systemd-specific conf files.
The %% is then decoded by systemd back to a literal %, preserving
the original value.

The /etc/profile.d/default-env.sh and /etc/environment.d/default-env.conf
destinations do not perform specifier expansion, so they continue to use the
original value without escaping.

A new test case covering a proxy value with a percent-encoded character
is added alongside the update to the existing expected output.

Fixes #28698

@packit-as-a-service
Copy link
Copy Markdown

[NON-BLOCKING] Packit jobs failed. @containers/packit-build please check. Everyone else, feel free to ignore.

Copy link
Copy Markdown
Contributor

@Honny1 Honny1 left a comment

Choose a reason for hiding this comment

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

I did, just a high-level review. Can you please add tests for this PR?

@crawfordxx
Copy link
Copy Markdown
Contributor Author

Thanks for the review, @Honny1! A test case covering the percent-sign escaping is already included in the PR: the "percent sign in proxy value is escaped for systemd" case in pkg/machine/proxyenv/env_test.go verifies that http://user%40example.com@proxy:3128 is rewritten to http://user%%40example.com@proxy:3128 in the systemd conf, while envd and profile.d retain the original value unchanged.

Copy link
Copy Markdown
Contributor

@Honny1 Honny1 left a comment

Choose a reason for hiding this comment

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

LGTM, please rebase on upstream main to run new CI. Thanks.

@crawfordxx crawfordxx force-pushed the fix-escape-percent-in-systemd-proxy-conf branch from c1d5158 to c2a2c72 Compare June 3, 2026 04:03
systemd interprets % as specifier characters in unit configuration files
(e.g. %H, %u, %40). Proxy environment variable values that contain
percent-encoded URL characters (such as %40 for @ in usernames) cause
systemd to emit warnings and fail to parse the generated
/etc/systemd/system.conf.d/default-env.conf:

  system.conf.d/default-env.conf:2: Failed to resolve specifiers in
  HTTP_PROXY=http://user%40example.com@proxy:3128

Fix by adding a bash variable substitution that doubles every % to %%
before writing to the systemd unit conf files. The profile.d and
environment.d destinations do not need this escaping and continue to
use the original value.

Fixes podman-container-tools#28698

Signed-off-by: crawfordxx <crawfordxx@users.noreply.github.com>
@crawfordxx crawfordxx force-pushed the fix-escape-percent-in-systemd-proxy-conf branch from c2a2c72 to e250df5 Compare June 4, 2026 04:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Forwarded env vars not escaped in /etc/systemd/system.conf.d/proxy-default-environment.conf

2 participants