Skip to content

Fix: Allow /etc/srv/kubernetes/ and /etc/srv/ paths in token validation#1220

Merged
JeffLuoo merged 1 commit into
GoogleCloudPlatform:masterfrom
courageJ:fix-token-path-validation
Jun 26, 2026
Merged

Fix: Allow /etc/srv/kubernetes/ and /etc/srv/ paths in token validation#1220
JeffLuoo merged 1 commit into
GoogleCloudPlatform:masterfrom
courageJ:fix-token-path-validation

Conversation

@courageJ

Copy link
Copy Markdown
Contributor

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.

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.
@JeffLuoo JeffLuoo merged commit 6f1bde1 into GoogleCloudPlatform:master Jun 26, 2026
19 checks passed
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