Skip to content

stack: tenant-scoped admin usage API (working copy of #88) - #90

Closed
eliteprox wants to merge 3 commits into
mainfrom
stack/admin-usage-boundary
Closed

stack: tenant-scoped admin usage API (working copy of #88)#90
eliteprox wants to merge 3 commits into
mainfrom
stack/admin-usage-boundary

Conversation

@eliteprox

Copy link
Copy Markdown
Collaborator

Summary

  • Working copy of #88 on stack/admin-usage-boundary (snapshotted from backup/feat-admin-usage-boundary).
  • #88 remains open and untouched; this branch is the mutable stack vehicle.
  • Same tenant-scoped admin usage / access / grants API against shared OpenMeter/Konnect.

Relationship to other PRs

Test plan

eliteprox and others added 3 commits August 17, 2026 18:02
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>
Copilot AI lite review requested due to automatic review settings August 18, 2026 17:13

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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
}
@eliteprox eliteprox closed this Aug 20, 2026
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.

2 participants