Label-based access control in Loki 4.0

Label-based access control limits what each Loki tenant can query to streams matching label selectors. This page covers policy design, the proxy headers it depends on and the model's limits.

On this page

What label-based access control in Loki 4.0 restricts

Label-based access control (LBAC) in Loki restricts what a tenant can query to streams that match one or more Prometheus label selectors, and multiple selectors are combined with OR. It is generally available from Loki 4.0 and requires multi-tenant mode, so it only makes sense once a shared cluster serves several groups that must not see each other's logs. Teams usually need it when a single Loki serves separate business units, regulated and unregulated workloads, or a platform team and application teams that should only see their own namespaces or services. If your groups can already be separated by tenant ID alone, LBAC adds a second, finer layer on top of that separation rather than a replacement for it.

The control works on stream labels such as app, namespace or env, so the policy must match labels your log pipeline actually sets. A reader who selects on a label that is inconsistent across agents will either expose too much or hide logs the team needs, so the first check is to inventory the labels each source emits and confirm that they are stable. Confirm the exact policy syntax and header behavior against the Loki label-based access control docs for your Loki version before writing any rules.

LBAC does not replace authentication. Loki has no built-in login layer, so the reverse proxy in front of it must authenticate users and set the tenant and policy information that LBAC reads. If that proxy is misconfigured or bypassable, the label policy has nothing trustworthy to enforce. The model also does not cover every isolation need: it does not separate storage, retention or per-tenant limits, and it is not the same feature set as Grafana Enterprise Logs, which adds token authorization, label-based access control and cross-tenant queries. Decide early which controls you need beyond label selectors and confirm with the vendor which of them your chosen edition provides.

Policy and configuration options and when each fits

This table compares three ways to write LBAC policies: one broad selector per tenant, one selector per team or environment, and several OR-combined selectors for shared streams. Read each row against your administration effort, how easily an auditor can trace access, and how much damage an over-broad selector could do. The main takeaway is that narrower, separately named policies cost more to maintain but make access easier to review.

OptionAdministrationAuditability and over-broad access riskWhen it fits
One broad selector per tenantLowest number of policy entries to maintainHardest to review, since one selector can expose many teams' streams if a label is shared or missingSmall single-team tenants where all users may read every stream
One selector per team or environmentMore entries, one per team or environment, each mapped to a clear ownerEasier to audit because each selector states exactly which streams a group can readShared clusters where teams or environments must not see each other's logs
Multiple OR-combined selectors for shared streamsNeeds careful ordering and review as stream sets changeHighest risk of drift, because each added selector widens access and the union is harder to predictShared platform streams, such as ingress or audit logs, that several teams legitimately need
Selectors on environment labels onlySimple to express if environment labels are consistentDepends entirely on label hygiene; a missing or wrong environment label can grant unintended readsClusters where environment is reliably set by the log shipper
Selectors on team or owner labelsRequires every shipper to attach the owner labelStrong separation when labels are enforced at ingestion, weak if producers can set any valueOrganizations with team-owned services and a labeling standard
Narrow selectors plus periodic reviewRecurring effort to confirm the selectors still match current servicesGood evidence trail if reviews are recorded, weaker if policies change without recordsRegulated environments that need documented access decisions

How the proxy, tenant header and policy reach Loki

The request starts with a user or Grafana sending a query to an authenticating reverse proxy, which checks who the user is. The proxy then sets the X-Scope-OrgID tenant header and the policy information, and passes the request to Loki across the trust boundary. Loki applies the label selectors and returns only matching streams. Check that Loki is reachable only through the proxy, because it has no authentication layer of its own.

Authenticating proxy sets tenant and policy headers before Loki enforces label selectors.

How to set up LBAC behind an authenticating proxy

This sequence takes a multi-tenant Loki cluster from open access to a state where the proxy alone decides which tenant and which label selectors each identity can reach. The result is a tested path where each team sees only its own streams.

  1. Enable multi-tenant mode in Loki

    Set auth_enabled: true in the Loki configuration so that every request must carry a tenant identifier in the X-Scope-OrgID header. Restart the Loki components, then send a test push and a test query with and without the header. Requests without a tenant should be rejected, and requests with a tenant should succeed. This confirms that tenancy is enforced before any access rules are added. Confirm the exact configuration keys for your Loki version in the Loki multi-tenancy docs.

  2. Confirm Loki accepts traffic only from the proxy

    Loki has no authentication layer of its own, so any client that can reach its HTTP port can set any tenant header. Place Loki on a private network or behind firewall rules so that only the reverse proxy, the ingestion agents and the Grafana service can connect. Test from a workstation outside that allowed set and confirm the connection fails. Also check that the ingestion path from Alloy or other shippers still works through its allowed route. Do not treat this step as optional, because LBAC is only as strong as the network path to Loki.

  3. Define tenant IDs and label policies

    Decide the tenant IDs for each team, customer or environment, and write the label selector policy each identity group should receive. Selectors are Prometheus-style label matchers, and multiple selectors combine with OR, so a group can read several slices of data. Record the mapping in a version-controlled file that names each tenant, its owner and its selectors. Review it with the data owners, and confirm the selector syntax and policy field names in the Loki LBAC docs. The output is an approved policy table that the proxy configuration will mirror.

  4. Configure the proxy to set tenant and policy headers

    Configure the authenticating proxy, such as nginx, HAProxy, OAuth2 Proxy or Pomerium, to validate the user's session with your identity provider, read the group claims, and map each group to a tenant ID and a policy. The proxy then sets the X-Scope-OrgID header and the policy header that Loki expects, and it must strip any identical headers supplied by the client. Check the exact header names and the expected policy format in the LBAC docs before writing rules. The proxy should be the only component that writes these headers.

  5. Check that the proxy overrides client-supplied headers

    Send requests through the proxy with a user who belongs to one group while manually adding a different tenant header and a broader policy header. The proxy must replace or drop both values before they reach Loki. Then query through the proxy and inspect the Loki response or logs to confirm the applied tenant and policy match the user's group. If a client-supplied header ever reaches Loki unchanged, fix the proxy rules before continuing, because this is the most common way LBAC is bypassed.

  6. Verify access with test users in each group

    Create one test account per identity group in your identity provider and run the same set of queries for each one, through Grafana and through the API. Each test user should see streams that match their selectors and receive no results or an error for streams outside them. Include a query that uses a label outside the policy and one that uses a regular expression that could match more than intended. Keep the results with the policy version so that a later change can be compared against the same test set.

  7. Record the policy and retest after changes

    Store the final tenant map, proxy configuration and test results in your change management system, and attach the owner of each policy. Any change to identity groups, selectors or proxy rules should trigger the same verification queries before rollout. Confirm the limits of the model in the LBAC docs and in your own environment, including which parts of your stack, such as the ruler or other APIs, need matching rules. The output is a repeatable check that shows the access model still works after each change.

Security risks of relying on the proxy for access control

Loki's label-based access control trusts whatever the proxy in front of it tells Loki about the caller. The cards below cover the places that trust can break, and each names a control to apply and an item to verify before go-live.

Clients setting their own headers

Loki identifies the tenant from the X-Scope-OrgID header and receives policy information from the proxy. If the proxy forwards headers from the client without overwriting them, a user can claim another tenant or drop the policy. Configure the proxy to strip any inbound tenant and policy headers and set them only after authentication succeeds. Verify this with a test request that sends a forged header and confirms the query is still limited to the caller's own tenant and selectors.

LBAC docs

Direct access to Loki

If Loki's HTTP port is reachable from user networks, clients can skip the proxy entirely and send their own headers to Loki. Place Loki on a private network or behind a firewall rule so that only the proxy can reach its listener, and block direct access from workstations, CI runners and application subnets. Verify by connecting to Loki's port from a client network and confirming the connection is refused.

Overly broad selectors

An LBAC policy is only as narrow as its label selectors. A selector such as one that matches every stream, or a team label that many services share, gives a tenant more logs than its owners intended. Write selectors against the labels your ingestion path sets reliably, and keep the policy list short enough to review. Verify by running each tenant's queries across a sample of known streams and confirming that streams outside its scope never appear.

Credential handling at the proxy

The proxy holds the authentication step, so its session cookies, OIDC client secrets and any token-to-tenant mapping are the new high-value targets. Store secrets outside configuration files, restrict who can edit the proxy routing and policy mapping, and rotate client credentials on a schedule your security team sets. Verify that proxy logs do not record bearer tokens or full request headers, and that a removed user loses access once the identity provider revokes their session.

Audit logging of queries

Loki's own logs show ingestion and query errors but do not record which user ran which query under which policy. Have the proxy write an audit record for each request that includes the authenticated identity, the tenant, the query text, the time range and the response status. Ship those records to a store the Loki tenants cannot query. Verify by running a query as a test user and confirming that the audit record exists with the identity attached.

Where LBAC in Loki 4.0 stops and what to confirm

LBAC in Loki 4.0 is only as strong as the layer in front of it. It requires multi-tenant mode, which means auth_enabled must be true and every request must carry a tenant identity in the X-Scope-OrgID header. Loki does not authenticate users itself, so the authenticating reverse proxy is part of the security boundary. That proxy must verify the caller, set the tenant header and attach the correct policy information for the caller. If a client can reach Loki directly, or can set headers the proxy passes through, the label selectors you defined can be bypassed. Treat the proxy configuration, its header handling and the network path to Loki as in-scope for your security review, not as plumbing.

LBAC also does not cover everything a user can reach through Loki. Confirm with the Loki LBAC documentation which query paths, endpoints and admin APIs the policy applies to, and which are outside it. Check how Grafana data sources are configured, since the tenant and policy headers must be forwarded correctly for every data source a team uses, and a data source that bypasses the proxy or uses a shared service identity can widen access. Also confirm how label selectors interact with structured metadata and with stream labels that users can influence at ingestion, because a label a sender can set freely is a weak basis for access decisions.

Version-specific gaps need a check in your own environment before you rely on the model. Confirm the exact Loki release you plan to run, since the topic facts only establish general availability from v4.0, and confirm which deployment mode you use, because the simple scalable mode is deprecated and removed with the 4.0 release. Then write tests that run as each role: allowed queries, denied queries, queries that mix permitted and forbidden selectors, and requests with missing or forged tenant headers. Repeat these tests after every upgrade and proxy change, and record the results as evidence for your access review.

Limits to confirm in your environment before rollout

Label-based access control only works when the layers around Loki behave as expected. The cards below cover what Loki does not do for you, where the proxy and label design carry the weight, and where Grafana Enterprise Logs offers features this open-source model does not include.

No built-in authentication

Loki has no authentication layer of its own, so every request reaches it as whatever the front door allows. Loki's documentation says to run an authenticating reverse proxy such as nginx, HAProxy, OAuth2 Proxy or Pomerium in front of it. Confirm that no path to Loki bypasses the proxy, including internal service addresses, Grafana data source settings and direct port access on the network. The platform or security team that owns the network design should verify this with a failed-login test from every client network.

Loki authentication docs

Proxy header integrity

LBAC depends on the proxy setting the tenant and policy information correctly on every request. If a client can send its own tenant or policy header and the proxy passes it through, the policy can be overridden. Confirm that the proxy strips any incoming tenant and policy headers before it sets its own, and that the header names match the Loki configuration. The team that operates the proxy should prove this with crafted requests during testing.

Label design sets the boundary

Selectors can only restrict what labels describe. If a team, customer or environment is not present as a stable label on its streams, a policy cannot separate it from others. Review which labels are set at ingestion, whether they are consistent across Alloy, OpenTelemetry and other shippers, and whether any sensitive value is used as a label. Confirm the label schema with the platform owners and the log source owners before writing policies that depend on it.

Query paths that may bypass policy

Teams often query Loki through Grafana, the HTTP API, the command line, the ruler and recording rules, and custom dashboards. Each path must send the same tenant and policy information, or a query can return data the policy should hide. Build a list of every client and automation that reads Loki and test each one with a restricted identity. Confirm this inventory with the owners of each dashboard, rule and script.

Enterprise features not in this model

Grafana Enterprise Logs adds token authorization, label-based access control and cross-tenant queries on top of Loki. Open-source LBAC in Loki 4.0 is a different feature set, so an access requirement that depends on token management or cross-tenant reads needs its own design. Confirm the required features with your Grafana Labs contact or the product documentation before you commit to the open-source model for those use cases.

Enterprise Logs docs

Multi-tenancy as a precondition

LBAC requires Loki to run in multi-tenant mode, with tenant identification enabled on every request. A single-tenant or unauthenticated setup cannot enforce these policies, and changing tenant identifiers later means a data migration. Confirm with the platform owner that auth is enabled and the tenant model is settled before any policy is written, since retrofitting it after data has been ingested is costly.

Questions teams ask before enabling label-based access control

What drives the effort and cost of a label-based access control rollout?

The main drivers are how many teams need different views, how cleanly your log labels already separate them, and how many identity groups must map to policies. A small set of clearly labeled streams with a few groups is much smaller work than hundreds of overlapping label sets. Costs fall into one-time design and build work (policy design, proxy configuration, testing) and recurring work (adding teams, reviewing policies, upgrades). Ask any provider to price the policy design, the proxy and identity integration, the testing, and the handover separately, so you can see which parts scale with your environment.

How long does enabling label-based access control take?

Duration depends less on Loki itself and more on the reverse proxy and identity provider in front of it. Loki does not authenticate users, so the proxy must verify identity and set the tenant and policy information on each request. If your proxy already handles single sign-on and group claims, the work is mostly policy design and testing. If you must add a proxy, define group-to-policy mappings from scratch, or agree label ownership across teams first, expect the schedule to grow. Confirm the timeline against your identity provider's group model and your change process before agreeing on dates.

What must our team provide before the work starts?

You need to provide a few inputs that are specific to your environment:

  • The labels your log streams carry today, with the values that identify each team, service or environment.
  • The identity groups in your directory and which team members belong to each.
  • The environments that need separate policies, such as production, staging and development.
  • The tenant IDs already in use, and whether any data must be kept separate from others.
  • Access rules agreed by data owners, including who may query audit or security logs.

Missing label consistency is the most common blocker, so review your label set before the project begins.

Can an internal platform team enable label-based access control alone?

Yes, if the team already runs Loki in multi-tenant mode, operates an authenticating reverse proxy and understands its identity provider. The configuration itself is not unusual, but errors in policy selectors can expose logs or hide them, so testing matters. Your team should verify that each identity group sees only the expected streams, that unauthenticated requests are refused, and that the proxy cannot be bypassed on the Loki port. A partner can run the design and test phases alongside your staff, which often shortens the learning curve without transferring ownership. Confirm which of these skills exist internally before deciding.

How do we know the proxy cannot be bypassed?

Loki trusts the tenant and policy headers it receives, so the proxy must be the only path into Loki. Restrict network access so that clients reach Loki only through the proxy, and make sure the proxy strips any client-supplied X-Scope-OrgID header before setting its own. Test by sending requests directly to Loki and through the proxy with altered headers, then confirm the results are refused or limited. Record these tests as part of your security evidence.

What are the limits of label-based access control in Loki?

Label-based access control restricts which streams a tenant can query, using one or more Prometheus label selectors combined with OR. It works well when team or environment boundaries are expressed as labels. It does not replace good labeling discipline: a log line that carries sensitive data under a shared label is still visible to anyone whose selector matches that stream. Field-level redaction and per-user audit trails are outside what the open-source model provides, so confirm those requirements before you commit to the design.

When is Grafana Enterprise Logs the better path?

Grafana Enterprise Logs is the better path when you need features the open-source model does not cover, such as token authorization, label-based access control in its own product, or cross-tenant queries. It is also relevant when you want a commercial support arrangement and a long-term support line. Grafana Enterprise Logs entered long-term support with version 3.6 and reaches end of life on February 1, 2029, so check that date against your planning horizon. Compare the licensing terms and feature list directly with your requirements before choosing.

How DeployOpen scopes and delivers LBAC in your Loki

DeployOpen treats label-based access control in Loki 4.0 as a design and proxy problem before it is a configuration task. We scope the policy model with your security and platform owners, build the authenticating proxy that sets tenant and policy headers, test the result against real access attempts, and hand over documentation your team can operate. Engagements are fixed-scope and agreed in writing before work starts.

How we scope

  • Inventory which teams, customers or environments share the Loki cluster and which tenant IDs each one uses
  • Map each group's required streams to Prometheus label selectors and agree which selectors combine with OR
  • Confirm your Loki version, multi-tenant mode and the identity provider that will feed the proxy
  • Record the written scope, deliverables and timeline before any build work begins

How we build

  • Build or configure the authenticating reverse proxy in front of Loki so it sets X-Scope-OrgID and the policy header
  • Write the label selector policies as versioned configuration reviewed by your security team
  • Configure Loki for multi-tenant mode and connect Grafana so queries pass through the proxy only
  • Harden proxy routes so direct access to Loki ports and unauthenticated paths are blocked

How we hand over

  • Test policy enforcement with a matrix of users, tenants and selectors, including attempts to bypass the proxy
  • Document the policy model, header contract, onboarding steps for new teams and known limits of the model
  • Deliver the access test results and fixes in a written report with a retest of the findings
  • Train the operators who will change policies, rotate proxy credentials and review access logs

How we support

  • Offer ongoing support, Loki upgrades and continuous access testing as a retainer after handover
  • Review proxy and policy changes when Loki versions, identity providers or team structures change
  • Confirm with your own team which features your Loki edition provides before committing to a design
  • Plan periodic access reviews so policies stay aligned with who should see which logs

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.