Repository navigation
RFC: Project-Scoped API Endpoints #9899
Replies: 2 comments 1 reply
This seems like it should be a MUST use instead of a may use. Having a projectId in the request context that isn't authoratative feels like an invitation for confusion.
Having sharding on the brain so much, I tend to think they should become canonical. Having the constraint of a known projectId would be strong.
Can you expand on what "project consistency" means here? |
|
I agree with treating the URL project scope as authoritative once it is present. I would make that a router-level invariant rather than letting each authentication mechanism decide whether to use it:
That keeps project selection separate from authorization while preventing a credential valid for project A from being replayed against a project-B route. The project identifier should ideally be opaque, and unknown, unauthorized, and mismatched scopes should have a deliberately uniform external response so the mount does not become a project-enumeration surface. For OAuth/OIDC, I would strongly prefer project-scoped issuer and audience values when the scoped endpoints are used. Discovery documents, authorization URLs, token URLs, JWKS references, and the resulting token validation rules should all describe the same security domain. If one global issuer is retained, the token still needs an immutable project binding that is validated against both the route and audience; otherwise the URL is carrying security-relevant state that the token does not confirm. The same consistency rule seems useful for CDS Hooks: project-scope There are also a few non-authentication boundaries worth including in the invariant tests: cache and idempotency keys, rate-limit buckets, audit events, and request tracing should all include the resolved project scope. Those are common places for an otherwise correct multi-tenant routing change to leak behavior across tenants. My rollout preference would be: keep scoped URLs as an advanced external surface initially, make scoped context canonical inside the router, and migrate individual protocols only when their discovery metadata and validation rules can be scoped end to end. Would a single |
Uh oh!
There was an error while loading. Please reload this page.
Background
As part of the CMS-0057-F (Electronic Prior Authorization) implementation, we encountered an architectural limitation in Medplum's current authentication model.
Today, Medplum is a multi-tenant system where all tenants share the same base URLs (e.g.
https://api.medplum.com). Tenant selection occurs after authentication by resolving the authenticated identity into aProjectMembership.This works well for OAuth/OIDC and normal Medplum access tokens because the access token itself uniquely identifies the user and project.
However, it breaks down for certain external authentication protocols where the incoming credential authenticates the caller, but does not identify the intended Medplum project.
Problem
The CMS-0057-F CRD specification allows CDS Hooks requests to be authenticated using direct JWT bearer tokens.
The Inferno Test Kit generates JWTs with essentially the following characteristics:
issis a fixed value.audis the CDS Services base URL.projectId,client_id,sub, etc.) that can be used to determine which Medplum project should process the request.As a result, if multiple Medplum projects expose the same CDS endpoint:
there is no way to determine which project should receive the request.
The only stable routing information is the endpoint URL itself.
Current Workaround
To pass the Inferno Server Test Kit, I implemented a global mapping:
This allows a single configured project to authenticate successfully.
However, it does not scale to multiple projects using the same issuer.
Proposal
Introduce a project-scoped API mount:
Examples:
Internally, the router would:
Individual authentication mechanisms may choose to use this project context when needed.
For example:
Why a Global Mount?
This proposal is motivated by CRD, but it solves a more general architectural problem.
Today we have several situations where Medplum needs to know the target project before authentication has completed.
Examples include:
Rather than solving each independently, a project-scoped API provides a consistent mechanism for selecting project context early in request processing.
Backwards Compatibility
Existing endpoints remain fully supported.
The new project-scoped endpoints are an additional API surface intended for advanced integration scenarios where project selection cannot be derived from the credential itself.
Applications that already authenticate using standard Medplum access tokens would not need to change.
Alternatives Considered
Project-specific CDS paths
This solves the immediate CRD problem, but introduces a CDS-specific routing convention that is unlikely to generalize to other APIs.
Customer-specific subdomains
This provides similar functionality and may ultimately be the preferred external experience.
However, it introduces additional DNS, TLS, and load-balancer complexity while solving the same underlying routing problem.
A project-scoped API mount could later serve as the implementation behind customer-specific subdomains.
Open Questions
Summary
The immediate motivation is CMS-0057-F compliance, but the underlying issue is broader: some authentication mechanisms authenticate the caller without identifying the target Medplum project.
Introducing a project-scoped API mount provides a simple, general solution that enables project selection before authentication while remaining fully backwards compatible with existing APIs.
All reactions