Fix: Allow /etc/srv/kubernetes/ and /etc/srv/ paths in token validation#1220
Merged
JeffLuoo merged 1 commit intoJun 26, 2026
Merged
Conversation
Some Kubernetes environments mount token files under /etc/srv/kubernetes/ or /etc/srv/. This change adds these prefixes to the allowlist of valid token file paths to support these deployments.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR updates the token path validation in prometheus-to-sd to allowlist /etc/srv/kubernetes/ and /etc/srv/ as valid prefixes for token files.
Context
Recent security hardening introduced strict path validation for token files. However, some Kubernetes deployments and environments mount service account tokens or credential files under /etc/srv/kubernetes/ (or more generally /etc/srv/). Without these paths in the allowlist, prometheus-to-sd fails to authenticate in these environments.
This change restores compatibility for these deployments while maintaining the security benefits of path validation against other unauthorized paths.
Changes
prometheus-to-sd/config/common_config.go: Added /etc/srv/kubernetes/ and /etc/srv/ to the allowed prefixes in isValidTokenFile.
prometheus-to-sd/config/common_config_test.go: Added a unit test case to verify that a token path under /etc/srv/kubernetes/ is successfully validated.
Testing
Ran unit tests in the config package:
bash
go test -v ./config/...
All tests passed, including the new test case.