loki-scope-proxy

by KvalitetsIT

Helm chartv0.4.0App 0.4.0Verified publisher

JWT-aware reverse proxy that injects X-Scope-OrgID into Loki queries based on Keycloak group claims. Admin groups receive all tenant IDs (discovered from namespace labels); tenant users receive only their matching tenant ID.

About this chart

loki-scope-proxy

JWT-aware reverse proxy that injects X-Scope-OrgID into Loki queries based on Keycloak group claims. Admin groups receive all tenant IDs (discovered from namespace labels); tenant users receive only their matching tenant ID.

Homepage: https://github.com/KvalitetsIT

Maintainers

NameEmailUrl
KvalitetsIT[email protected]https://github.com/KvalitetsIT/helm-repo

Source Code

Requirements

RepositoryNameVersion
https://raw.githubusercontent.com/KvalitetsIT/helm-repo/master/kitapp1.1.0
https://raw.githubusercontent.com/KvalitetsIT/helm-repo/master/templates2.2.0

Values

General

KeyTypeDefaultDescription
fullnameOverridestring""Fullname override (overrides the default <name>-<release> convention used in labels and selectors).
upstream.urlstring""Full URL of the upstream Loki instance, e.g. http://loki.logging.svc.cluster.local:3100.

Keycloak

KeyTypeDefaultDescription
keycloak.urlstring""Base URL of the Keycloak instance, e.g. https://keycloak.example.com.
keycloak.realmstring""Realm name.
keycloak.audiencestring""Expected aud claim (Keycloak client ID). Required when proxy.authMode=istio. Optional in jwt mode - leave empty to skip audience validation.

Proxy

KeyTypeDefaultDescription
proxy.authModestring"jwt"Authentication mode. jwt validates the Bearer token directly; istio trusts the groups header injected by Istio's RequestAuthentication.
proxy.logLevelstring"info"Log level. One of debug, info, warn, error.
proxy.adminGroupsstring"cluster-admin,cluster-readonly"Comma-separated Keycloak group names that grant access to all tenants.
proxy.tenantLabelstring"tenant.kitkube.dk/name"Kubernetes namespace label whose value is the Loki tenant ID.
proxy.defaultTenantIdstring"kit-admin"Tenant ID always included in the admin scope (covers namespaces without the tenant label).
proxy.caCert.secretNamestring""Name of an existing Secret containing a custom CA certificate to trust for outbound HTTPS calls to Loki and Keycloak (e.g. a client's internal or self-signed root). Leave empty to disable. When set, you must also mount this Secret via kitapp.extraVolumes at proxy.caCert.mountPath - see the "Custom CA" section in the chart README for the exact snippet to copy.
proxy.caCert.secretKeystring"ca.crt"Key within the Secret holding the PEM-encoded CA certificate.
proxy.caCert.mountPathstring"/etc/loki-scope-proxy/ca"Path the CA cert is mounted at inside the container. Must match the mountPath used in the corresponding kitapp.extraVolumes entry.

Istio configuration

KeyTypeDefaultDescription
proxy.istio.groupsHeaderstring"x-auth-groups"HTTP header that Istio injects the groups claim into via outputClaimToHeaders.
proxy.istio.requestAuthenticationobject{"enabled":true}Deploy a RequestAuthentication resource targeting this proxy. Requires proxy.authMode=istio.
proxy.istio.requestAuthentication.enabledbooltrueEnable the RequestAuthentication resource.
proxy.istio.authorizationPolicyobject{"enabled":true}Deploy an AuthorizationPolicy that rejects requests without a validated JWT principal. Must be deployed alongside requestAuthentication - without it, Istio validates tokens only when present; unauthenticated requests reach the proxy and can forge the groups header.
proxy.istio.authorizationPolicy.enabledbooltrueEnable the AuthorizationPolicy resource. Disabling this leaves the proxy exposed to groups-header injection from unauthenticated callers that can reach the pod without a JWT.

KIT App

KeyTypeDefaultDescription
kitappobjectSee values.yamlkitapp base chart - controls the Deployment, Service, and ServiceAccount. See kitapp values for all options.
kitapp.image.repositorystring"kvalitetsit/loki-scope-proxy"Full image repository.
kitapp.image.tagstring"0.4.0"Image tag
kitapp.image.digeststring""Image digest (overrides tag when set)
kitapp.extraEnvFromlist[{"configMapRef":{"name":"loki-scope-proxy-env"}}]envFrom pointing at the env ConfigMap generated by this chart. Override this name per release when deploying multiple proxies in the same namespace.

Network policies

KeyTypeDefaultDescription
networkPolicyFallbackobjectSee values.yamlSettings used by the native NetworkPolicy fallback when Cilium is unavailable.
networkPolicyFallback.kubeApiServerCIDRstring"10.96.0.1/32"Kubernetes API server service CIDR for native NetworkPolicy egress fallback. Override this to the kubernetes.default service ClusterIP in clusters where it differs.
networkPoliciesobjectSee values.yamlKubernetes NetworkPolicy resources rendered by this chart. Entries with the same key as ciliumNetworkPolicies are treated as fallbacks and are rendered only when Cilium is unavailable. Entries without a matching Cilium policy are always rendered.
networkPolicies.loki-scope-proxy-ingressobjectSee values.yamlNative ingress policy for Grafana and Prometheus access to the proxy. Always rendered.
networkPolicies.loki-scope-proxy-egressobjectSee values.yamlNative egress fallback used when Cilium is unavailable.
networkPolicies.loki-scope-proxy-keycloakobjectSee values.yamlOptional native Keycloak egress fallback for clusters without Cilium. Native NetworkPolicy cannot match FQDNs, so enable this only with explicit IP blocks or pod/namespace selectors.
ciliumNetworkPoliciesobjectSee values.yamlCiliumNetworkPolicy resources rendered by this chart when the cilium.io/v2 API is available. A same-named networkPolicies entry is used as the native Kubernetes fallback when Cilium is unavailable.
ciliumNetworkPolicies.loki-scope-proxy-egressobjectSee values.yamlCilium egress policy for DNS and kube-apiserver access.

Deployment

This chart is designed to deploy to the logging namespace alongside Loki. All chart resources are namespace-agnostic (they use Release.Namespace), so the deploy namespace is set by the ArgoCD Application resource in your environment repo.

ArgoCD Application example

applications:
  loki-scope-proxy:
    namespace: argocd
    project: infrastructure
    sources:
      - repoURL: https://github.com/KvalitetsIT/k8s-components.git
        targetRevision: <repo-tag>
        path: loki-scope-proxy
        helm:
          valueFiles:
            - $values/deployment/loki-scope-proxy/values-test.yaml
      - ref: values
        repoURL: https://github.com/KvalitetsIT/<env-repo>.git
        targetRevision: main
    destination:
      server: https://kubernetes.default.svc
      namespace: logging
    syncPolicy:
      automated:
        prune: true
        selfHeal: true
      syncOptions:
        - CreateNamespace=true
        - ServerSideApply=true

Multiple proxy instances

When deploying multiple proxies in the same namespace, give each proxy a unique env ConfigMap name. The chart uses kitapp.extraEnvFrom[0].configMapRef.name as the single source of truth for both the generated ConfigMap and the KitApp Deployment envFrom reference:

kitapp:
  extraEnvFrom:
    - configMapRef:
        name: <name-of-this-proxy-instance>-env

Set this in the environment/release values file for each proxy instance.

Custom CA

If Loki or Keycloak present a certificate signed by an internal or self-signed CA (common in client-managed clusters), create a Secret with the CA certificate and point the proxy at it.

First create the Secret (a CA certificate is public - it has no private key - so plain text is fine):

kubectl create secret generic loki-scope-proxy-ca \
  --from-file=ca.crt=/path/to/client-ca.pem \
  -n logging

Then set both proxy.caCert.secretName and a matching kitapp.extraVolumes entry - Helm fails fast at render time if they don't match, since one drives the CA_CERT_FILE env var and the other drives the actual Secret mount on the Deployment (rendered by different charts, so one value can't derive the other). A YAML anchor keeps the secret name in one place:

upstream:
  url: http://loki.logging.svc.cluster.local:3100

keycloak:
  url: https://keycloak.example.com
  realm: infrastructure

proxy:
  caCert:
    secretName: &caCertSecretName loki-scope-proxy-ca

kitapp:
  extraVolumes:
    - name: ca-cert
      mountPath: /etc/loki-scope-proxy/ca
      readOnly: true
      volumeSpec:
        secret:
          secretName: *caCertSecretName

Network policies

The chart always renders a native Kubernetes NetworkPolicy for ingress from Grafana and Prometheus. For egress to DNS and the Kubernetes API server, it follows the same Cilium/native fallback pattern as the tenant project chart:

  • if the cilium.io/v2 API is available, render ciliumNetworkPolicies.loki-scope-proxy-egress
  • otherwise, render the same-named networkPolicies.loki-scope-proxy-egress fallback

[!IMPORTANT] Egress to Loki is not opened by default - deployments typically target multiple instances (e.g. loki and loki-audit) whose namespaces vary. Add the required egress rules in your k8s-components values.

[!WARNING] In jwt auth mode, Keycloak egress uses a Cilium FQDN policy (keycloak-egress-cilium-networkpolicy). If Cilium is not installed, you must configure networkPolicies.loki-scope-proxy-keycloak with explicit IP blocks or pod/namespace selectors - native NetworkPolicy cannot match hostnames. Otherwise Helm fails during rendering to avoid deploying a proxy that cannot reach Keycloak.

Example native Keycloak fallback using an IP/CIDR allowlist:

networkPolicies:
  loki-scope-proxy-keycloak:
    enabled: true
    egress:
      - to:
          - ipBlock:
              cidr: 203.0.113.10/32
        ports:
          - port: 443
            protocol: TCP

To disable the built-in policies:

networkPolicies:
  loki-scope-proxy-ingress:
    enabled: false
  loki-scope-proxy-egress:
    enabled: false
ciliumNetworkPolicies:
  loki-scope-proxy-egress:
    enabled: false

JWT auth mode (default)

upstream:
  url: http://loki.logging.svc.cluster.local:3100

keycloak:
  url: https://keycloak.example.com
  realm: infrastructure

Istio auth mode

upstream:
  url: http://loki.logging.svc.cluster.local:3100

keycloak:
  url: https://keycloak.example.com
  realm: infrastructure
  audience: loki-scope-proxy

proxy:
  authMode: "istio"

Multiple proxy instances (custom env ConfigMap name)

upstream:
  url: http://loki.logging.svc.cluster.local:3100

keycloak:
  url: https://keycloak.example.com
  realm: infrastructure

kitapp:
  extraEnvFrom:
    - configMapRef:
        name: loki-scope-proxy-audit-env

Protocols: HTTP/1.1, HTTP/2 and gRPC

The proxy accepts HTTP/1.1 and HTTP/2 without TLS (h2c) on port 8080:

RequestClient to proxyProxy to an http:// upstreamProxy to an https:// upstream
Normal API callHTTP/1.1 or h2cHTTP/1.1HTTP/2 if offered, otherwise HTTP/1.1
gRPC, e.g. Tempo's streaming APIh2cHTTP/2 (h2c)HTTP/2

No chart settings are needed for this, except in Istio mode. There, the sidecar talks HTTP/1.1 to the proxy when the port is named http, so gRPC fails. Name the port http2 so Istio forwards HTTP/2, and point the probes at the new name:

kitapp:
  applicationPort:
    name: http2
    port: 8080
  livenessProbe:
    httpGet:
      port: http2
  readinessProbe:
    httpGet:
      port: http2

gRPC clients also need Tempo to have stream_over_http_enabled: true.

Grafana's Tempo streaming does not work through this proxy yet: the Tempo plugin does not forward the user's OAuth token on streaming requests, so they are rejected with UNAUTHENTICATED. Keep streaming off on Tempo datasources that point at the proxy:

jsonData:
  oauthPassThru: true
  streamingEnabled:
    search: false
    metrics: false

Multi-tenancy with Grafana

Configure the admin Grafana org's Loki datasource to point at this proxy and enable forwardOAuthIdentity. The proxy reads the user's Keycloak JWT, maps groups to Loki tenant IDs, and injects X-Scope-OrgID automatically.

# GrafanaOrgDatasource for the main/admin org
spec:
  url: http://loki-scope-proxy.logging.svc.cluster.local:8080
  jsonData:
    forwardOAuthIdentity: true

Tenant orgs continue pointing directly at Loki with a hardcoded X-Scope-OrgID - no changes needed.


Autogenerated from chart metadata using helm-docs v1.14.2

Deploy loki-scope-proxy with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has loki-scope-proxy on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.

  1. Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
  2. Place the chartloki-scope-proxy is pinned at v0.4.0 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
  3. ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below
opentenant validate opentenant.yaml
terraform init && terraform apply