Skip to content

feat: add Doris-backed OAuth authentication#90

Open
catpineapple wants to merge 2 commits into
apache:masterfrom
catpineapple:feature/doris-oauth-rbac
Open

feat: add Doris-backed OAuth authentication#90
catpineapple wants to merge 2 commits into
apache:masterfrom
catpineapple:feature/doris-oauth-rbac

Conversation

@catpineapple
Copy link
Copy Markdown
Member

Doris OAuth Implementation Notes and Limitations

This PR adds a Doris-backed OAuth mode. In this mode, the MCP server
acts as the OAuth provider. Users sign in with their Doris username
and password; the server validates those credentials against Doris and
creates a dedicated per-user Doris connection pool. Subsequent MCP
requests are bound to that user pool, and data/metadata authorization
is ultimately enforced by Doris RBAC.

Relationship With Existing OAuth

doris-oauth is mutually exclusive with the existing external OAuth/
OIDC mode. External OAuth/OIDC delegates identity to a third-party
identity provider, while Doris OAuth uses Doris itself as the
authentication and authorization backend. They cannot be enabled at
the same time to avoid mismatches between MCP identity and Doris
execution identity.

Token Lifetime

Doris OAuth access and refresh token lifetimes are configurable:

  • DORIS_OAUTH_ACCESS_TOKEN_EXPIRE_SECONDS, default 900
  • DORIS_OAUTH_REFRESH_TOKEN_EXPIRE_SECONDS, default 86400

When an access token expires, the client must refresh it with a valid
refresh token. When the refresh token expires or is revoked, the user
must sign in again.

Connection Pool Lifecycle

A per-user Doris connection pool is created after successful login.
Doris OAuth requests must execute through that bound user pool. If a
token is valid but the corresponding user pool is missing, the request
fails closed and never falls back to the global Doris service account.

The current implementation closes Doris OAuth user pools during server
shutdown and covers revoke-related paths. However, automatic pool
disposal when access/refresh tokens naturally expire is not yet a
complete capability. The following configuration is reserved:

  • DORIS_OAUTH_GC_INTERVAL_SECONDS
  • DORIS_OAUTH_IDLE_TIMEOUT_SECONDS

These options should not be interpreted as full token-expiry-driven
pool cleanup yet.

DCR Limitations

Basic Dynamic Client Registration support is included, with the
following configuration:

  • DORIS_OAUTH_DYNAMIC_CLIENT_REGISTRATION_MODE
  • DORIS_OAUTH_DCR_MAX_CLIENTS
  • DORIS_OAUTH_DCR_CLIENT_TTL_SECONDS
  • DORIS_OAUTH_DCR_RATE_LIMIT_PER_IP

DCR clients, authorization codes, access tokens, and refresh tokens
are currently memory-only and process-local. They are not shared
across workers, processes, or nodes.

Multi-Worker and Multi-Node Limitations

Doris OAuth is not currently a stateless horizontal-scaling
implementation. Token state, DCR client state, authorization code
state, and per-user Doris connection pools are all process-local.

For this reason, the recommended deployment shape for Doris OAuth is:

WORKERS=1

True multi-worker or multi-node deployment requires a future shared
token store, shared DCR client store, shared authorization code store,
and either per-user pool reconstruction or sticky-session routing.

### Resource Cache and Metadata Isolation

Doris OAuth must avoid cross-tenant metadata leakage. For example,
database/table metadata visible to user A must not be cached and later
exposed to user B. This PR adds safeguards around resource metadata
caching so Doris OAuth resource and tool access remains scoped to the
current Doris user, with final visibility controlled by Doris RBAC.

Add Doris OAuth mode backed by Doris RBAC and make it mutually exclusive with the existing OAuth provider.

Bind MCP requests to authenticated Doris users with per-user connection pools and operation policy enforcement.

Add Doris OAuth token handling, redirect validation, rate limiting, MCP auth middleware, and resource metadata cache safeguards.

Document token TTL configuration, static client behavior, and current token/pool lifecycle semantics.

Add tests for OAuth routes and store behavior, auth context propagation, operation policy checks, resource cache safety, user pool management, and guarded tool execution.
Merge upstream master into the Doris OAuth branch.

Resolve the HTTP transport conflict by preserving MCP authentication middleware while applying CORS handling to MCP preflight, auth errors, authorization errors, and normal session responses.

Add shared MCP CORS helpers for single-worker and multi-worker HTTP routes.

Replace the Doris OAuth smoke test runtime-file dependency with an inline environment fixture.
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.

1 participant