Skip to content

feat(prometheus_exporter sink): add SAR auth strategy#25412

Open
jcantrill wants to merge 1 commit into
vectordotdev:masterfrom
jcantrill:feat_25409_sar_prometheus_exp
Open

feat(prometheus_exporter sink): add SAR auth strategy#25412
jcantrill wants to merge 1 commit into
vectordotdev:masterfrom
jcantrill:feat_25409_sar_prometheus_exp

Conversation

@jcantrill
Copy link
Copy Markdown

Add Subject Access Review (SAR) authentication strategy to the prometheus_exporter sink. fixes #25409

Summary

This PR:

  • Adds auth.strategy 'sar' (SubjectAccessReview) to the prometheus export sink
  • Allows the sink to be protected by a well-known kubernetes pattern

Vector configuration

    [sinks.prometheus_output.auth]
    strategy = "sar"
    path = "/metrics"
    verb = "get"

How did you test this PR?

  • Deploy the collector as a pod on an OpenShift cluster
  • Bound the pod serviceaccount to the following role
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
    name: vector-token-validator
rules:
- apiGroups: ["authentication.k8s.io"]
 resources: ["tokenreviews"]
 verbs: ["create"]
 - apiGroups: ["authorization.k8s.io"]
   resources: ["subjectaccessreviews"]
    verbs: ["create"]
  • Inspect prometheus or create a serviceaccount and bind it to a cluster role that can "get /metrics"

Change Type

  • Bug fix
  • [x ] New feature
  • Dependencies
  • Non-functional (chore, refactoring, docs)
  • Performance

Is this a breaking change?

  • Yes
  • [ x] No

Does this PR include user facing changes?

No

  • Yes. Please add a changelog fragment based on our guidelines.
  • No. A maintainer will apply the no-changelog label to this PR.

References

Notes

  • Please read our Vector contributor resources.
  • Do not hesitate to use @vectordotdev/vector to reach out to us regarding this PR.
  • Some CI checks run only after we manually approve them.
    • We recommend adding a pre-push hook, please see this template.
    • Alternatively, we recommend running the following locally before pushing to the remote branch:
      • make fmt
      • make check-clippy (if there are failures it's possible some of them can be fixed with make clippy-fix)
      • make test
  • After a review is requested, please avoid force pushes to help us review incrementally.
    • Feel free to push as many commits as you want. They will be squashed into one before merging.
    • For example, you can run git merge origin master and git push.
  • If this PR introduces changes Vector dependencies (modifies Cargo.lock), please
    run make build-licenses to regenerate the license inventory and commit the changes (if any). More details on the dd-rust-license-tool.

Add Subject Access Review (SAR) authentication strategy to the
prometheus_exporter sink. fixes vectordotdev#25409
@jcantrill jcantrill requested a review from a team as a code owner May 11, 2026 18:12
@github-actions
Copy link
Copy Markdown
Contributor

Thank you for your contribution! Before we can merge this PR, please sign our Contributor License Agreement.

To sign, copy and post the phrase below as a new comment on this PR.

Note: If the bot says your username was not found, the email used in your git commit may not be linked to your GitHub account. Fix this at github.com/settings/emails, then comment recheck to retry.


I have read the CLA Document and I hereby sign the CLA


You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

@jcantrill
Copy link
Copy Markdown
Author

cc @vparfonov

@github-actions github-actions Bot added the domain: sinks Anything related to the Vector's sinks label May 11, 2026
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0e8f2bbf67

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +709 to +712
// Check authorization - SAR takes precedence over basic auth when both token and SAR config present
let is_authorized = self.check_authorization(&req).await;

match (is_authorized, req.method(), req.uri().path()) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Short-circuit non-metrics routes before SAR checks

In Handler::handle, authorization is awaited before route matching, so with auth.strategy = "sar" every request (including POST /, health probes, and random 404 paths) triggers TokenReview + SubjectAccessReview calls. This turns invalid-path traffic into Kubernetes API load even though only GET /metrics can succeed, making it easy to amplify load on the API server from outside. Please gate SAR evaluation to the /metrics route (and method) so non-metrics requests return immediately.

Useful? React with 👍 / 👎.

Comment on lines +605 to +607
_ => {
return Err("Must specify either 'path' or 'resource', not both or neither".into());
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Fail fast on invalid SAR one-of path/resource settings

The path/resource exclusivity is enforced only at request time, where invalid combinations return an error from validate_token_with_sar. That means a sink configured with strategy = "sar" but with both fields set (or neither set) still starts, then denies all scrapes at runtime. This should be validated during config/build so misconfiguration is surfaced immediately instead of silently breaking metrics after deployment.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

domain: sinks Anything related to the Vector's sinks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(sink/prometheus_exporter) Restrict access by SubjectAccessReview to authorized clients in Kubernetes environment

1 participant