Skip to content

feat(loki): add strict fail-closed query guardrails - #1198

Open
rshn20 wants to merge 2 commits into
grafana:mainfrom
apolloio:loki-strict-query-guardrails
Open

rshn20 wants to merge 2 commits into
grafana:mainfrom
apolloio:loki-strict-query-guardrails

Conversation

@rshn20

@rshn20 rshn20 commented Sep 17, 2026 •

Copy link
Copy Markdown

What this changes

Adds an opt-in strict mode to the existing Loki query guardrail for autonomous MCP clients.

Grafana Cloud does not apply maxQueryBytesRead to filterless log queries. Strict mode closes that gap by:

  • requiring a non-empty line filter for native Loki queries
  • restricting queries to an explicit datasource allowlist
  • rejecting queries that cannot be parsed or cost-estimated
  • enforcing byte and time-range limits before execution
  • preventing access through unguarded API, rendering, and panel-query paths
  • disabling Loki query paths whose byte-limit behavior cannot be verified

Strict mode remains read-only by default. update_dashboard can be selectively restored with --enable-write-tools=update_dashboard without enabling datasource writes or other write tools.

Existing off, shadow, and enforce behavior is unchanged.

How you tested it

  • go test -tags=unit ./...
  • go vet ./...
  • JSON schema linter
  • OpenAPI context linter
  • gofmt and git diff --check
  • Tests cover filterless queries, datasource allowlisting, byte and range limits, incomplete estimates, unsafe startup configurations, query rewriting, and the isolated dashboard-write override

Checklist

  • make lint and make test-unit pass locally
  • Commits are signed
  • CLA signed
  • README tool table updated, with RBAC permissions and scopes, if this adds a tool
  • Any write operation respects --disable-write
  • Any datasource query execution respects --disable-query and --disable-write where applicable

@rshn20
rshn20 requested a review from a team as a code owner September 17, 2026 11:05
@cla-assistant

cla-assistant Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@cla-assistant

cla-assistant Bot commented Sep 17, 2026

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want higher recall? High effort reviews run extra passes and find more bugs. A team admin can switch effort levels in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit eeed5f5. Configure here.

Comment thread cmd/mcp-grafana/main.go

This branch has not been deployed

No deployments
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.

1 participant