[Proposal] Application-Level Subscriptions for REST APIs in the API Platform #1290
Replies: 2 comments
-
Application-Level Subscriptions for REST APIs — Implementation Plan1. Executive SummaryProblem: REST APIs in the API Platform are not tied to Applications. Token validation only checks issuer/signature; it does not verify that the calling Application is subscribed to the invoked API. Any valid token can call any API. Solution: Introduce Application and Subscription entities, CRUD APIs in platform-api and gateway-controller, WebSocket sync of subscription data to gateways, and subscription validation in the gateway policy engine so requests are allowed only when the Application (identified from the token) is subscribed to the target API. 2. Current State (Findings from Codebase)2.1 Platform-API
2.2 Gateway-Controller
2.3 Policy Engine
3. Data Model3.1 Application Identifier
3.2 Platform-API: New Tablesapplications
subscriptions
Indexes: (api_uuid), (application_uuid), (organization_uuid), (status). 3.3 Gateway-Controller: New Tablesapplications (minimal, for FK and optional display)
subscriptions
Indexes: (api_id), (application_id), (gateway_id), (status) for fast “is this app subscribed to this API?” lookups. 4. API Design4.1 Platform-API: REST —
|
| Area | Action |
|---|---|
| platform-api | |
internal/database/schema*.sql |
Add applications, subscriptions; indexes. |
internal/model/ |
application.go, subscription.go. |
internal/repository/ |
application_repository.go, subscription_repository.go. |
internal/service/ |
application_service.go, subscription_service.go (and wire into api/gateway events). |
internal/handler/ |
subscription_handlers.go for rest-apis; optional application_handlers.go. |
resources/openapi.yaml |
Paths for /rest-apis/{apiId}/subscriptions, optional /applications. |
internal/service/gateway_events.go |
Emit subscription.created/updated/deleted; add internal GET subscriptions if needed. |
internal/websocket/ |
No change if events are JSON payloads; ensure payload size limits allow new events. |
| gateway-controller | |
pkg/storage/sqlite.go (and postgres) |
Migrations: applications, subscriptions tables. |
pkg/storage/interface.go, sql_store.go |
Subscription (and application) CRUD. |
pkg/models/ |
Subscription, Application structs. |
resources/openapi.yaml |
/apis/{id}/subscriptions CRUD. |
pkg/api/handlers/ |
Subscription handlers. |
pkg/controlplane/events.go |
Subscription event payload structs. |
pkg/controlplane/client.go |
Handle subscription.created/updated/deleted; resolve apiId → deployment id; persist. |
| xDS | New resource or extended config for subscription allow-list per API. |
| policy-engine | |
| New policy | e.g. policies/subscription-validation/ (policy.yaml + Go); read metadata + route; check allow-list; 403 if not subscribed. |
| xDS client / handler | Parse subscription validation config from xDS and build in-memory map. |
| Docs | How to enable subscription validation; required JWT claim for application id. |
9. Security & Consistency Notes
- Authorization: Platform subscription APIs must enforce org/project scope (only allow managing subscriptions for APIs and applications in the same organization).
- Gateway: Subscription REST API should be protected (e.g. same auth as existing admin API or gateway token). Internal GET subscriptions endpoint must require gateway token.
- Idempotency: Subscription create/update events should be idempotent (same subscriptionId → upsert) so duplicate or out-of-order WebSocket messages do not leave gateway inconsistent.
- API deletion: When an API is deleted (or undeployed), gateway should remove or invalidate its subscriptions for that API (cascade or on api.deleted event).
10. Open Points for Review
- Application ownership: Are applications created only in DevPortal/STS, or should platform-api host full Application CRUD? (Affects whether we add
/api/v1/applicationsor only reference applicationId in subscriptions.) - Mapping platform apiId → gateway deployment id: Platform uses API uuid; gateway uses deployment id (often same as api uuid when single deployment). Confirm convention (e.g. deployment id = platform api uuid for REST APIs).
- Subscription validation default: Should “subscription required” be opt-in per API (via policy attachment) or default on for all APIs? Plan assumes opt-in via policy.
- Bulk sync: Prefer adding GET /api/internal/v1/.../subscriptions for gateways vs. only relying on events (events simpler; bulk sync avoids gaps after reconnect).
Beta Was this translation helpful? Give feedback.
-
|
A few suggestions: 1. Use /subscriptions as a root-level resource What if we do use a root-level For example:
The same approach can be applied on the gateway-controller side as well. 2. +1 for a dedicated subscription validation policy (6.3 Option A). A dedicated policy can pick up the authentication state from the auth context and handle subscription validation in one place - keeping it cleanly separated from auth logic. 3. Handle gateway reconnection scenarios We need to account for cases where a gateway is offline when a subscription event is sent and reconnects later. There should be a mechanism to sync missed subscriptions upon reconnection - similar to the approach we're currently implementing for syncing API keys and API deployments. 4. Application deletion cascade When an application is deleted cascade-delete any existing subscriptions of that app. A couple of Questions. 1. How do we perform subscription validation for API Keys: We need to get the associated application for API key and we need a way for that. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Problem Statement
Currently, REST APIs deployed in the API Platform are not associated with specific Applications. Although access tokens are issued per Application, the gateway’s token validation flow does not verify whether the Application is actually subscribed to the invoked API.
As a result, any token with a valid issuer can successfully pass validation and invoke API resources, even if the originating Application is not subscribed to that API.
Proposed Solution
Introduce Application-level subscription validation for REST APIs in the API Platform.
Beta Was this translation helpful? Give feedback.
All reactions