stack: tenant-scoped admin usage API (working copy of #88) - #90
Closed
eliteprox wants to merge 3 commits into
Closed
stack: tenant-scoped admin usage API (working copy of #88)#90eliteprox wants to merge 3 commits into
eliteprox wants to merge 3 commits into
Conversation
Closes #12. Substantially closes #10 (usage querying and entitlement management; plan config and subscription provisioning follow separately). One shared OpenMeter organization with the admin API as the sole tenant boundary. Includes Konnect-compatible meter query (POST + ULID), customer key→id resolution for access/grants, USAGE.md, and corrected AUTH0_SIGNER_M2M_* env names in TENANT-ISOLATION.md. Replaces the prematurely merged #81 (reverted on main) so review comments are addressed before merge.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
4 tasks
There was a problem hiding this comment.
Pull request overview
Adds a tenant-scoped “admin” API surface to openmeter-collector/builder-api, enforcing per-tenant isolation while talking to a single shared Konnect/OpenMeter organization.
Changes:
- Introduces tenant-aware Basic-auth principal/authentication (
internal/tenantauth) and wires it through the HTTP server. - Adds admin endpoints for tenant-scoped usage queries plus per-user access/grants, including defense-in-depth row filtering and bounded scans.
- Updates docs, OpenAPI spec, and runtime wiring/env config (
TENANT_ADMIN_KEYS, admin OpenMeter client).
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| openmeter-collector/builder-api/README.md | Documents the new admin surface and routes. |
| openmeter-collector/builder-api/internal/tenantauth/tenantauth.go | New tenant/platform principal auth + authorization helper. |
| openmeter-collector/builder-api/internal/tenantauth/tenantauth_test.go | Unit tests for tenant/platform authentication behavior. |
| openmeter-collector/builder-api/internal/openmeter/usage.go | Adds Konnect meter query + bounded customer-key listing helpers. |
| openmeter-collector/builder-api/internal/openmeter/usage_test.go | Tests for subject scoping, bounded scans, and query shape. |
| openmeter-collector/builder-api/internal/openmeter/customer.go | Exposes customer lookup-by-key needed by access/grants. |
| openmeter-collector/builder-api/internal/httpapi/token_test.go | Updates server constructor usage after dependency injection changes. |
| openmeter-collector/builder-api/internal/httpapi/server.go | Wires new admin routes and switches create-user auth to tenant authorization. |
| openmeter-collector/builder-api/internal/httpapi/boundary_test.go | End-to-end tests asserting tenant boundary holds across routes. |
| openmeter-collector/builder-api/internal/httpapi/admin.go | Implements usage/access/grants handlers and tenant authorization helpers. |
| openmeter-collector/builder-api/internal/config/config.go | Adds TENANT_ADMIN_KEYS to loaded config. |
| openmeter-collector/builder-api/docs/USAGE.md | New operator/integrator guide for usage/access/grants. |
| openmeter-collector/builder-api/docs/TENANT-ISOLATION.md | New boundary model + operational prerequisites documentation. |
| openmeter-collector/builder-api/cmd/builder-api/openapi.json | Adds admin endpoints and tenantBasic security scheme. |
| openmeter-collector/builder-api/cmd/builder-api/main.go | Wires tenant auth + optional admin OpenMeter client from env. |
| .env.example | Documents TENANT_ADMIN_KEYS configuration. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+214
to
+216
| q := req.URL.Query() | ||
| q.Set("pageSize", "100") | ||
| req.URL.RawQuery = q.Encode() |
Comment on lines
+84
to
+86
| // Authenticate resolves credentials to a Principal, returning a zero Principal | ||
| // when they match nothing. Both branches use constant-time comparison. | ||
| func (a *Authenticator) Authenticate(clientID, secret string) Principal { |
Comment on lines
106
to
110
| func (s *Server) handleCreateUser(w http.ResponseWriter, r *http.Request) { | ||
| clientID := strings.TrimSpace(r.PathValue("clientId")) | ||
| if clientID == "" { | ||
| writeAPIError(w, http.StatusBadRequest, "clientId is required") | ||
| return | ||
| } | ||
| if !M2MAuth(r, s.cfg.SignerM2MClientID, s.cfg.SignerM2MSecret) { | ||
| writeAPIError(w, http.StatusUnauthorized, "Unauthorized") | ||
| clientID, ok := s.authorizeTenant(w, r) | ||
| if !ok { | ||
| return | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
stack/admin-usage-boundary(snapshotted frombackup/feat-admin-usage-boundary).Relationship to other PRs
feat/admin-usage-boundary)backup/feat-admin-usage-boundarystack/jwt-scoped-usageTest plan
go test ./...inopenmeter-collector/builder-apifeat/admin-usage-boundarytip unchanged