Skip to content

[Cherry-pick to branch-1.3] Feature/trino connector oauth2 user forwarding (#12045) - #12698

Merged
diqiu50 merged 2 commits into
apache:branch-1.3from
diqiu50:cherry-pick-12045-to-branch-1.3
Aug 31, 2026
Merged

[Cherry-pick to branch-1.3] Feature/trino connector oauth2 user forwarding (#12045)#12698
diqiu50 merged 2 commits into
apache:branch-1.3from
diqiu50:cherry-pick-12045-to-branch-1.3

Conversation

@diqiu50

@diqiu50 diqiu50 commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Cherry-pick Information:

  • Original commit: 16db87b
  • Target branch: branch-1.3
  • Status: ✅ Clean cherry-pick (no conflicts)

### Summary
Adds per-user authorization and credential vending support to the
Gravitino Trino connector for Iceberg catalogs backed by the Iceberg
REST Catalog (IRC).
Changes
Two commits:

* oauth2 per-user token forwarding — Extends the connector's session
forwarding (forwardUser=true) to support authType=oauth2, not just
simple. When enabled, the end user's forwarded IdP token is presented to
the Gravitino server, so authorization runs against the real end user
instead of a shared service identity. Adds StaticUserTokenProvider,
widens the auth guards in GravitinoConnector and GravitinoAuthProvider,
and keys the per-user client cache by auth type.
* per-user credential vending for IRC-backed Iceberg — Configures the
generated Trino Iceberg REST catalog so that an IRC-backed Gravitino
catalog requests per-user, per-table vended credentials. Sets
security=OAUTH2, session=USER, and vended-credentials-enabled=true, and
maps the warehouse through, so Trino's Iceberg REST client forwards the
end-user token to the IRC and obtains scoped storage credentials over
the REST protocol.

### Testing
Unit tests added for the oauth2 forwarding path
(TestGravitinoAuthProvider) and the REST backend config mapping
(TestIcebergCatalogPropertyConverter). End-to-end verification against a
live IRC is in progress.

### Motivation
Trino is a primary query engine for enterprise customers who require
real per-user authorization and scoped credentials rather than a shared
service identity.

---------

Co-authored-by: Mark Hoerth <mark@datastrato.com>
Co-authored-by: yuhui <hui@datastrato.com>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit 16db87b)
Copilot AI lite review requested due to automatic review settings August 28, 2026 02:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This cherry-pick extends the Gravitino Trino connector’s session user-forwarding support to authType=oauth2, enabling per-query authentication using the end user’s forwarded OAuth2 access token (when the Trino coordinator provides it). It also improves Iceberg REST-catalog property conversion and adds additional debug logging for authentication/cache behavior.

Changes:

  • Add OAuth2-aware per-session client building and per-user session cache keying (including token rotation behavior).
  • Introduce StaticUserTokenProvider to present a forwarded end-user token directly to the Gravitino client.
  • Extend Iceberg REST backend property conversion (optional warehouse) and expand docs/tests accordingly.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/GravitinoConnector.java Implements per-session metadata resolution for forwarded users, including token-aware cache keying and improved error mapping.
trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/security/GravitinoAuthProvider.java Adds OAuth2 session-forwarding support (token extraction from extra-credentials) and config key for token credential name.
trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/security/StaticUserTokenProvider.java New token provider that returns a pre-fetched user token for OAuth2 forwarding.
trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/catalog/iceberg/IcebergCatalogPropertyConverter.java Adds optional warehouse propagation for REST-backed Iceberg catalogs.
trino-connector/trino-connector/src/test/java/org/apache/gravitino/trino/connector/TestGravitinoConnectorForwardUser.java Updates/expands tests to validate OAuth2 forwarding construction, cache key behavior, token rotation, and error mapping.
trino-connector/trino-connector/src/test/java/org/apache/gravitino/trino/connector/security/TestGravitinoAuthProvider.java Adds tests for OAuth2 buildForSession, custom credential key, and missing-token behavior.
trino-connector/trino-connector/src/test/java/org/apache/gravitino/trino/connector/catalog/iceberg/TestIcebergCatalogPropertyConverter.java Adds REST-backend property conversion test coverage including optional warehouse and missing-uri case.
server-common/src/main/java/org/apache/gravitino/server/authentication/AuthenticationFilter.java Adds debug logging for request URI/auth header presence/principal resolution.
iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/IcebergCatalogWrapperManager.java Adds debug logging for catalog wrapper cache hit/miss.
docs/trino-connector/authentication.md Documents OAuth2 session credential forwarding requirements/limitations and reorganizes auth sections.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +301 to +305
static String sessionCacheKey(String authType, String user, String token) {
String tokenPart =
StringUtils.isBlank(token) ? "" : ":" + Integer.toHexString(token.hashCode());
return authType + ":" + user + tokenPart;
}
Comment on lines +81 to +85
Assertions.assertThrows(
TrinoException.class,
() -> propertyConverter.gravitinoToEngineProperties(wrongMap),
"Missing required property for Rest backend: [uri]");
}
Comment on lines +317 to +319
assertThrows(
TrinoException.class, () -> GravitinoAuthProvider.buildForSession(config, session));
}
@github-actions

github-actions Bot commented Aug 28, 2026

Copy link
Copy Markdown

Code Coverage Report

Overall Project 67.79% +0.17% 🟢
Files changed 82.12% 🟢

Module Coverage
aliyun 1.72% 🔴
api 47.73% +0.11% 🟢
authorization-common 85.96% 🟢
aws 42.04% 🟢
azure 2.47% 🔴
catalog-common 10.4% 🔴
catalog-fileset 80.23% 🟢
catalog-glue 68.95% 🟢
catalog-hive 79.42% 🟢
catalog-jdbc-clickhouse 81.78% 🟢
catalog-jdbc-common 45.48% 🟢
catalog-jdbc-doris 82.36% 🟢
catalog-jdbc-hologres 54.03% 🟢
catalog-jdbc-mysql 79.33% 🟢
catalog-jdbc-oceanbase 78.6% 🟢
catalog-jdbc-postgresql 83.39% 🟢
catalog-jdbc-starrocks 79.16% 🟢
catalog-kafka 77.01% 🟢
catalog-lakehouse-generic 59.18% 🟢
catalog-lakehouse-hudi 79.1% 🟢
catalog-lakehouse-iceberg 85.86% 🟢
catalog-lakehouse-paimon 82.14% 🟢
catalog-model 77.72% 🟢
cli 44.51% 🟢
client-java 77.99% +1.29% 🟢
common 50.75% 🟢
core 82.88% +0.06% 🟢
filesystem-hadoop3 77.3% 🟢
flink 0.0% 🔴
flink-common 47.12% 🟢
flink-runtime 0.0% 🔴
gcp 14.12% 🔴
hadoop-common 10.88% 🔴
hive-metastore-common 53.77% 🟢
iceberg-aliyun-bundle 0.0% 🔴
iceberg-common 58.15% 🟢
iceberg-rest-server 73.87% -0.05% 🟢
idp-basic 86.02% 🟢
integration-test-common 0.0% 🔴
jobs 66.17% 🟢
lance-common 24.42% 🔴
lance-rest-server 60.13% 🟢
lineage 53.02% 🟢
optimizer 82.87% 🟢
optimizer-api 21.95% 🔴
server 86.46% 🟢
server-common 76.09% -0.08% 🟢
spark 28.57% 🔴
spark-common 41.66% 🟢
trino-connector 42.19% +2.75% 🟢
Files
Module File Coverage
api View.java 84.62% 🟢
Function.java 0.0% 🔴
client-java RelationalCatalog.java 93.06% 🟢
FunctionCatalogOperations.java 87.76% 🟢
core TagMetadataObjectRelBaseSQLProvider.java 100.0% 🟢
TagMetadataObjectRelPostgreSQLProvider.java 100.0% 🟢
FunctionMetaService.java 100.0% 🟢
TagManager.java 83.68% 🟢
iceberg-rest-server IcebergCatalogWrapperManager.java 70.49% 🟢
server-common AuthenticationFilter.java 72.86% 🟢
trino-connector IcebergCatalogPropertyConverter.java 86.11% 🟢
StaticUserTokenProvider.java 83.33% 🟢
GravitinoAuthProvider.java 82.54% 🟢
GravitinoConnector.java 53.23% 🔴

…o-branch-1.3

# Conflicts:
#	trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/GravitinoConnector.java
#	trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/security/GravitinoAuthProvider.java
@diqiu50
diqiu50 merged commit 505598b into apache:branch-1.3 Aug 31, 2026
35 checks passed
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.

3 participants