Skip to content

feat: add CosmosDB read-only query endpoint to the admin API - #6168

Draft
bennerv wants to merge 1 commit into
Azure:mainfrom
bennerv:bvesel/admin-api-cosmosdb-queries
Draft

feat: add CosmosDB read-only query endpoint to the admin API#6168
bennerv wants to merge 1 commit into
Azure:mainfrom
bennerv:bvesel/admin-api-cosmosdb-queries

Conversation

@bennerv

@bennerv bennerv commented Jul 20, 2026

Copy link
Copy Markdown
Member

Summary

  • Adds POST /admin/v1/cosmos/query endpoint to the admin API for direct CosmosDB read access in production environments
  • Validates queries against mutating keywords (UPDATE, DELETE, INSERT, CREATE, etc.) with string-literal-aware word-boundary matching
  • Accepts container name, SQL query, optional partition key, and max items limit; returns raw JSON documents
  • MISE-gated via the existing Istio AuthorizationPolicy — no additional config needed

Test plan

  • Unit tests for keyword validation (35 cases covering edge cases: string literals, field name substrings, case insensitivity)
  • E2E tests verified locally against dev environment:
    • Valid SELECT query returns results from Resources container
    • Mutating keywords are rejected with 400
    • Partition key scoping works
    • Empty result sets return correctly
  • CI passes

🤖 Generated with Claude Code

Add a MISE-gated admin API endpoint for direct CosmosDB read access
in production environments where the data dumper controller doesn't
cover all troubleshooting scenarios.

- POST /admin/v1/cosmos/query: accepts a container name, SQL query,
  optional partition key, and max items limit
- Validates queries don't contain mutating keywords (UPDATE, DELETE,
  INSERT, CREATE, etc.) using word-boundary regex after stripping
  string literals to avoid false positives
- Returns results as raw JSON documents

Includes unit tests for keyword validation and E2E tests that verify
queries against the Resources and Fleet containers.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@openshift-ci

openshift-ci Bot commented Jul 20, 2026

Copy link
Copy Markdown

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@bennerv

bennerv commented Jul 20, 2026

Copy link
Copy Markdown
Member Author

This PR was mostly AI-authored. I'll take it out of draft once I've fully reviewed it.

@openshift-ci

openshift-ci Bot commented Jul 20, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: bennerv

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

var mutatingKeywordPattern *regexp.Regexp

func init() {
keywords := []string{

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

todo: figure out if the query client we use actually allows mutating records. if it doesn't no need to filter out key words here.

Count: len(results),
}

_, err = arm.WriteJSONResponse(w, http.StatusOK, resp)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

todo: we should stream the result instead of limiting max items so we can see the full response from the client side?

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant