Skip to content

fix(config): also error when env var in config is prefixed or suffixed#1500

Open
jonaskuske wants to merge 6 commits intoprometheus:mainfrom
jonaskuske:fix/missing-env-error-when-env-is-substring
Open

fix(config): also error when env var in config is prefixed or suffixed#1500
jonaskuske wants to merge 6 commits intoprometheus:mainfrom
jonaskuske:fix/missing-env-error-when-env-is-substring

Conversation

@jonaskuske
Copy link

This PR fixes two issues:

  1. The documentation claimed that the config would be used as-is if an env var is not found in the environment, but that's not how snmp_exporter behaves: if an env var is missing while --config.expand-environment-variables, it errors while loading the config.

I've updated the README to reflect that.

  1. If an env var was part of a larger string, snmp_exporter would neither error nor leave the string as-is. Instead, os.Expand would silently replace the env vars found within the string with "".

I've updated the implementation to also error when the (missing) env var is found within a larger string. A common failure scenario is having a password like abcd$geh==1 in the config: with --config.expand-environment-variables, this password would silently be changed to abcd==1 (stripping the env var), so authentication against targets would fail despite having correct auths in the config.
Now, snmp_exporter errors and complains about the missing variable geh.

@jonaskuske jonaskuske force-pushed the fix/missing-env-error-when-env-is-substring branch 3 times, most recently from 0dccf1a to 8109533 Compare September 12, 2025 09:01
Signed-off-by: Jonas Kuske <mail@jonaskuske.com>
@jonaskuske jonaskuske force-pushed the fix/missing-env-error-when-env-is-substring branch from 8109533 to 978af4a Compare September 12, 2025 09:11
@bastischubert
Copy link
Member

@jonaskuske do you mind fixing the findings of the linter and gofmt in order to get this merged?

Signed-off-by: Jonas Kuske <mail@jonaskuske.com>
@jonaskuske jonaskuske force-pushed the fix/missing-env-error-when-env-is-substring branch from 005971b to a82e1ea Compare March 20, 2026 16:50
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.

2 participants