Skip to content
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

Accept Multi Values in One Header When Using byHttpHeader #219

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

Conversation

Kirchen99
Copy link

Description

This PR extends the feature in #104. With a "separator" in the config the header value can be split.

e.g.

"authorization":
  "resourceAttributes":
    "apiVersion": "metrics.k8s.io/v1beta1"
    "namespace": "{{ .Value }}"
    "resource": "pods"
  "rewrites":
    "byHttpHeader":
      "name": "X-Scope-OrgID"
      "separator": "|"

Motivation

We also put kube-rbac-proxy in front of Loki (https://grafana.com/docs/loki/latest/). And Loki 2.6 enabled multi-tenant queries: https://grafana.com/blog/2022/07/27/grafana-loki-2.6-release/

The required format from loki is like this:

curl -H 'X-Scope-OrgID:Tenant1|Tenant2|Tenant3' \
  -G -s "http://localhost:3100/loki/api/v1/query" \
  --data-urlencode \
  'query=sum(rate({job="varlogs"}[10m])) by (level)' | jq

Signed-off-by: Kirchen99 <latias_latios@126.com>
Signed-off-by: Kirchen99 <latias_latios@126.com>
@ibihim
Copy link
Collaborator

ibihim commented Apr 5, 2023

Hi,

this commit that is merged into kube-rbac-proxy enables to specify the same header several times and all of them should be taken into consideration:

9fd649a

Is this enough to satisfy your needs?

@Kirchen99
Copy link
Author

Hi,

this commit that is merged into kube-rbac-proxy enables to specify the same header several times and all of them should be taken into consideration:

9fd649a

Is this enough to satisfy your needs?

Not really. We use kube-rbac-proxy for Grafana Loki. Grafana Loki accepts only one header value and separating their names by the | character.

Maybe I should have a look at Grafana Loki, if it is possible to make a PR to let it accept same header several times.

Here is the document from Grafana Loki:

Here is a standard LogQL query to Tenant1:

curl -H 'X-Scope-OrgID:Tenant1 -G -s  "http://localhost:3100/loki/api/v1/query" \
  --data-urlencode \
  'query=sum(rate({job="varlogs"}[10m])) by (level)' | jq

Getting to a multi-tenant query is simple! Just make a small change to the X-Scope-OrgID header, which identifies the tenants you want to query. Specify as many tenants as you need, separating their names by the | character.

In this example, this cross-tenant query is written to target Tenant1, Tenant2, and Tenant3 for the requested data:

curl -H 'X-Scope-OrgID:Tenant1|Tenant2|Tenant3' \
  -G -s "http://localhost:3100/loki/api/v1/query" \
  --data-urlencode \
  'query=sum(rate({job="varlogs"}[10m])) by (level)' | jq

@dbluxo
Copy link

dbluxo commented Jul 5, 2023

Hi @ibihim, we would also find this feature super helpful, could you maybe look at this PR again?

@@ -53,6 +53,7 @@ type QueryParameterRewriteConfig struct {
// be used to rewrite a SubjectAccessReview on a given request.
type HTTPHeaderRewriteConfig struct {
Name string `json:"name,omitempty"`
Sep string `json:"separator,omitempty"`
Copy link

Choose a reason for hiding this comment

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

Suggested change
Sep string `json:"separator,omitempty"`
Separator string `json:"separator,omitempty"`

NB: I'm not a reviewer here, just adding a suggestion.

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.

None yet

4 participants