Skip to content

fix(entitlement): validate namespace ownership on writes - #4995

Merged
GAlexIHU merged 1 commit into
mainfrom
codex/entitlement-namespace-integrity
Aug 25, 2026
Merged

GAlexIHU merged 1 commit into
mainfrom
codex/entitlement-namespace-integrity

Conversation

@GAlexIHU

@GAlexIHU GAlexIHU commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • validate feature identity within the entitlement namespace during creation
  • reject cross-namespace entitlement owners when writing grants, usage resets, and balance snapshots
  • prevent current-period upserts from updating an entitlement outside the requested namespace
  • keep the hardening scoped to write paths

Testing

  • POSTGRES_HOST=127.0.0.1 go test -tags=dynamic ./openmeter/entitlement/... ./openmeter/credit/...
  • go vet -tags=dynamic ./openmeter/entitlement/... ./openmeter/credit/...

Greptile Summary

The PR hardens entitlement and credit write paths so referenced features and entitlement owners must belong to the requested namespace.

  • Validates feature namespace, ID, and key before entitlement creation.
  • Validates entitlement ownership before grants, usage resets, and balance snapshots are persisted.
  • Prevents current-period upserts from modifying an entitlement in another namespace.
  • Adds database-backed coverage for cross-namespace write attempts.

Confidence Score: 5/5

The PR appears safe to merge because the namespace checks consistently reject mismatched references before persistence and no actionable regression was identified.

The changed write paths preserve namespace ownership for feature references, entitlement period updates, grants, usage resets, and balance snapshots, with database-backed tests covering the rejected cross-namespace cases.

Important Files Changed

Filename Overview
openmeter/entitlement/adapter/entitlement.go Validates feature identity during creation and checks namespace ownership before current-period upserts.
openmeter/credit/adapter/owner.go Introduces the shared namespace-aware entitlement-owner existence check used by credit repositories.
openmeter/credit/adapter/grant.go Rejects grant creation when the entitlement owner does not exist in the supplied namespace.
openmeter/credit/adapter/balance_snapshot.go Skips empty snapshot batches and validates the namespaced entitlement owner before bulk persistence.
openmeter/entitlement/adapter/usage_reset.go Validates the namespaced entitlement reference before persisting a usage reset.
openmeter/entitlement/adapter/namespace_test.go Covers foreign customers, features, owners, mismatched feature identity, and protected write paths.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  Write[Entitlement or credit write] --> Resolve[Resolve referenced resource by namespace and ID]
  Resolve -->|Not found or mismatched| Reject[Return not-found error]
  Resolve -->|Valid owner| Persist[Persist namespace-scoped write]
  Persist --> Protected[Cross-namespace state remains unchanged]
Loading

Reviews (1): Last reviewed commit: "fix(entitlement): validate namespace own..." | Re-trigger Greptile

@GAlexIHU
GAlexIHU requested a review from a team as a code owner August 24, 2026 14:15
@GAlexIHU GAlexIHU added the release-note/bug-fix Release note: Bug Fixes label Aug 24, 2026
@GAlexIHU
GAlexIHU merged commit eccbdba into main Aug 25, 2026
27 of 29 checks passed
@GAlexIHU
GAlexIHU deleted the codex/entitlement-namespace-integrity branch August 25, 2026 08:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note/bug-fix Release note: Bug Fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants