Skip to content

[VPA] Add prometheus bearer auth support #8263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

yalosev
Copy link
Contributor

@yalosev yalosev commented Jun 21, 2025

What type of PR is this?

/kind feature

What this PR does / why we need it:

This PR adds several flags for the Prometheus historical provider:

  • prometheus-insecure – Skip TLS verification. Prometheus may use a TLS certificate, and accessing it over https:// could result in an unknown CA certificate error if the certificate is self-signed or untrusted.
  • prometheus-bearer-token – Use a bearer token for authentication.
  • prometheus-bearer-token-file – Read the bearer token from a file. This is useful when using kube-rbac-proxy and a service account token is mounted into the pod.

Bearer token authentication and basic authentication are mutually exclusive, as both use the Authorization header. Only one of the following combinations should be set: username + password, bearer-token, or bearer-token-file.

Additionally, the authentication middleware logic was updated to follow best practices by cloning the request rather than modifying the original one.

Which issue(s) this PR fixes:

Fixes N/A

Special notes for your reviewer:

Does this PR introduce a user-facing change?

NONE

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added kind/feature Categorizes issue or PR as related to a new feature. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Jun 21, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: yalosev
Once this PR has been reviewed and has the lgtm label, please assign omerap12 for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jun 21, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @yalosev. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added area/vertical-pod-autoscaler size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jun 21, 2025
@yalosev yalosev force-pushed the feature/prometheus-bearer branch from ea4d11f to 751c5b9 Compare June 22, 2025 14:14
Signed-off-by: Yuriy Losev <[email protected]>
@yalosev yalosev force-pushed the feature/prometheus-bearer branch from 05c38de to ef07fa1 Compare June 22, 2025 14:28
@adrianmoisey
Copy link
Member

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jun 22, 2025
Comment on lines 88 to 89
bearerToken = flag.String("bearer-token", "", "The bearer token used in the Prometheus server bearer token auth")
bearerTokenFile = flag.String("bearer-token-file", "", "Path to the bearer token file used for authentication by the Prometheus server")
Copy link
Member

Choose a reason for hiding this comment

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

Could these both be prepended with prometheus?
That way all the Prometheus options are bundled together when sorted alphabetically

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, sure. Changed.
I'm actually was surprised that not all prometheus options have this prefix. For example username / password are not linked with prometheus at all, as well as all -label options

@yalosev yalosev requested a review from adrianmoisey June 23, 2025 06:49
@omerap12
Copy link
Member

/label tide/merge-method-squash

@k8s-ci-robot k8s-ci-robot added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Jun 23, 2025
rt = http.DefaultTransport
}

// Clone the request to avoid modifying the original
Copy link
Member

Choose a reason for hiding this comment

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

This comment says what the code is doing, but not why the code is doing it. Could you add a comment linking to the best practise?

Copy link
Contributor Author

@yalosev yalosev Jun 26, 2025

Choose a reason for hiding this comment

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

Well, it's a good point. It's more a self-control comment that I didn't remove. The main link is in the Golang source code. Also we have an example in the ReverseProxy.
I have changed the comment, is it ok for you?

While this code likely won’t cause undefined behavior now, I think we can avoid keeping it in such a risky state for future modifications.

Copy link
Member

Choose a reason for hiding this comment

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

That new comment is great, thank you!
It's the kind of thing that I imagine someone may come refactor later, and decide to remove. The new comment will at least give them the context to know why it's like that (if they didn't know before hand).

Comment on lines 88 to 89
bearerToken = flag.String("prometheus-bearer-token", "", "The bearer token used in the Prometheus server bearer token auth")
bearerTokenFile = flag.String("prometheus-bearer-token-file", "", "Path to the bearer token file used for authentication by the Prometheus server")
Copy link
Member

Choose a reason for hiding this comment

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

More nits: can the variable also start with prometheus? In case we need a bearer token and bearer token file in the future for other purposes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@yalosev yalosev requested a review from adrianmoisey June 26, 2025 14:55
Copy link
Member

Choose a reason for hiding this comment

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

Could you add another test that specifies the token and a username/password, and verifies that the bearer token is used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We have a check in the main.go to make these flags exclusive.
But no problems, I have added the test.

Don't we want to move an error from the main.go to the HistoryProvider constructor. And check this condition here?

Copy link
Member

Choose a reason for hiding this comment

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

I think it's fine as is. I figured the test was worth adding to ensure that the behaviour doesn't change over time.

Signed-off-by: Yuriy Losev <[email protected]>
@adrianmoisey
Copy link
Member

/lgtm
/assign @omerap12

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/vertical-pod-autoscaler cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants