Skip to content

Commit e545f1a

Browse files
authored
[feature](fe) Support OIDC session credentials for Iceberg REST catalog (#63068)
This PR supports Iceberg REST catalog user-session authentication with delegated credentials from Doris authentication. access could fail or use non-user credentials. This PR adds a connection-scoped datasource session context, forwards it across FE-to-master execution, and uses Iceberg `SessionCatalog` when `iceberg.rest.session = user` is enabled. #### Overview The full flow is: 1. Client logs in with OAuth/OIDC/JWT/SAML credential. 2. Doris authentication validates the credential. 3. Doris stores a delegated datasource credential in the connection `ConnectContext`. 4. If execution is forwarded to master FE, the credential and session id are carried in `TMasterOpRequest`. 5. Iceberg REST user-session catalogs use the delegated credential through Iceberg `SessionCatalog`. 6. Doris bypasses shared Iceberg metadata caches for user-session metadata paths. ```mermaid flowchart TD Client["Client login credential"] Auth["Doris authentication validates credential"] Resp["Authentication success"] DC["DelegatedCredential"] SC["SessionContext in ConnectContext"] SQL["SQL, SHOW, or DDL"] Check{"Use Iceberg REST user session?"} Normal["Existing non-session catalog path"] Cache["Existing shared metadata caches"] IcebergSC["Iceberg SessionCatalog SessionContext"] SessionCatalog["Iceberg REST SessionCatalog"] Rest["Iceberg REST server authorizes request"] Result["Return metadata or query result"] Client --> Auth Auth --> Resp Resp --> DC DC --> SC SC --> SQL SQL --> Check Check -->|No| Normal Normal --> Cache Cache --> Result Check -->|Yes| IcebergSC IcebergSC --> SessionCatalog SessionCatalog --> Rest Rest --> Result ``` #### Goals - Capture authenticated user credentials as datasource delegated credentials. - Keep delegated credentials connection-scoped and in-memory only. - Preserve delegated credentials when statements are forwarded between FEs. - Use Iceberg REST `SessionCatalog` for user-session metadata operations. - Support both table and view metadata paths. - Avoid sharing user-authenticated metadata through global Doris metadata caches. - Keep existing behavior unchanged unless `iceberg.rest.session = user` is configured. #### Non-goals - This PR does not change Doris privilege checking. - This PR does not persist delegated credentials. - This PR does not change BE scan execution. - This PR does not implement Doris-side token refresh. - This PR does not enable user-session mode for non-OAuth2 Iceberg REST security. #### Configuration User-session mode is enabled with: ```sql 'iceberg.rest.security.type' = 'oauth2', 'iceberg.rest.session' = 'user', 'iceberg.rest.oauth2.delegated-token-mode' = 'access_token' ``` `iceberg.rest.oauth2.delegated-token-mode` supports: - `access_token`: pass the delegated credential as Iceberg OAuth bearer token. - `token_exchange`: pass the original token type to Iceberg REST OAuth so Iceberg can perform token exchange. Rules: - `iceberg.rest.session = user` requires `iceberg.rest.security.type = oauth2`. - If user-session mode is disabled, Doris uses the existing non-session Iceberg REST path. - If no delegated credential exists, Doris uses the existing non-session path. #### Authentication Flow Doris introduces two runtime objects: - `DelegatedCredential`: credential type, token, and optional expiration. - `SessionContext`: datasource-facing session state stored in `ConnectContext`. ```mermaid sequenceDiagram participant Client participant AuthPlugin as Doris Auth Plugin participant AuthMgr as AuthenticatorManager participant Ctx as ConnectContext Client->>AuthPlugin: Login credential AuthPlugin-->>AuthMgr: Authentication success AuthMgr->>AuthMgr: Build DelegatedCredential AuthMgr->>Ctx: Set SessionContext Note over Ctx: In-memory and connection-scoped only ``` Supported delegated credential types: - OAuth access token - OIDC id token - JWT token - SAML assertion The delegated credential is not persisted to edit log or catalog metadata. #### FE Forwarding A client may connect to follower/observer FE while execution is forwarded to master FE. The master FE must restore the same datasource session context before planning and execution. ```mermaid sequenceDiagram participant Client participant ObserverFE participant MasterFE participant IcebergREST Client->>ObserverFE: SQL with authenticated session MasterFE->>MasterFE: Restore SessionContext before execution MasterFE->>IcebergREST: Metadata request with user credential IcebergREST-->>MasterFE: Metadata response MasterFE-->>ObserverFE: Query result ObserverFE-->>Client: Query result ``` New optional thrift fields are added to `TMasterOpRequest`: - `delegated_credential_type` - `delegated_credential_token` - `delegated_credential_expires_at_millis` - `delegated_credential_session_id` The session id is required because Iceberg `SessionCatalog.SessionContext.sessionId()` is used as a session-scoped auth/cache key. Normal FE forwarding preserves the original session id. The fallback random id only exists for compatibility with old or manually constructed forwarded requests that carry a delegated token without a session id. #### Iceberg SessionCatalog Integration Doris normally keeps an Iceberg `Catalog` instance. Iceberg REST also provides an internal `SessionCatalog` that can create a session-bound catalog from `SessionCatalog.SessionContext`. `IcebergSessionCatalogAdapter` bridges Doris `SessionContext` to Iceberg `SessionCatalog.SessionContext`. ```mermaid flowchart TD DorisSC["Doris SessionContext"] Mode{"delegated-token-mode"} Access["credentials token equals delegated token"] Exchange["credentials id token jwt or saml equals delegated token"] IcebergSC["Iceberg SessionCatalog SessionContext"] BaseSessionCatalog["Iceberg BaseSessionCatalog"] ActiveCatalog["Session-bound Catalog or ViewCatalog"] DorisSC --> Mode Mode -->|access_token| Access Mode -->|token_exchange| Exchange Access --> IcebergSC Exchange --> IcebergSC IcebergSC --> BaseSessionCatalog BaseSessionCatalog --> ActiveCatalog ``` Mapping behavior: - `access_token`: Doris maps the delegated credential to Iceberg OAuth `token`. - `token_exchange`: Doris maps the delegated credential to the matching Iceberg token type key, such as id token, JWT, or SAML. #### Metadata Operation Routing When user-session mode is active, Doris routes Iceberg metadata operations through session-aware methods. ```mermaid flowchart TD Op["Iceberg metadata operation"] UseSession{"Use session catalog?"} Shared["Existing global metadata cache"] Direct["Direct session-aware load"] CatalogOps["Catalog operations"] ViewOps["View operations"] NamespaceOps["Namespace operations"] UseSession -->|Yes| Direct Direct --> CatalogOps Direct --> ViewOps Direct --> NamespaceOps ``` Session-aware paths include: - `listDatabaseNames` - `listTableNames` - `tableExist` - `loadTable` - `listViewNames` - `viewExists` - `loadView` - view schema loading - snapshot/schema paths that depend on a user-session loaded Iceberg table #### Cache Isolation The existing Doris Iceberg metadata cache is shared by catalog/table metadata. That is correct for static catalog credentials, but unsafe for user-session access because the Iceberg REST server may return different metadata for different users. For user-session mode, Doris bypasses shared metadata caches for credential-dependent metadata. ```mermaid flowchart TD Request["Metadata request"] UserSession{"REST user session with delegated credential?"} GlobalCache["Use shared Doris metadata cache"] DirectLoad["Load with current SessionContext"] UserA["User A authorized metadata"] UserB["User B authorized metadata"] Risk["Cross-user metadata reuse risk"] Request --> UserSession UserSession -->|No| GlobalCache UserSession -->|Yes| DirectLoad DirectLoad --> UserA DirectLoad --> UserB GlobalCache -.-> Risk ``` This avoids reusing user A's authenticated Iceberg table/view metadata for user B. #### Table And View Coverage Both table and view metadata paths use the same session context. Table paths include: - table existence check - table loading - table list - snapshot/schema loading based on session-loaded table View paths include: - view existence check - view loading - view list - view schema loading This is necessary because Iceberg REST user-session authorization may apply to both tables and views. #### Token Expiration Authentication may return optional credential expiration metadata. Doris preserves this metadata in `DelegatedCredential` and forwards it between FEs with the session context. The Iceberg REST server remains the authority for whether the delegated credential is valid for an external metadata request. Doris should not reject every SQL statement only because the datasource delegated credential is expired, because many SQL statements do not access that external Iceberg REST catalog. #### Compatibility All new thrift fields are optional. Existing behavior is preserved for: - catalogs without `iceberg.rest.session = user` - non-Iceberg catalogs - Iceberg non-REST catalogs - Iceberg REST catalogs using static OAuth credential or static OAuth token - requests without delegated credentials
1 parent a6ab604 commit e545f1a

42 files changed

Lines changed: 2625 additions & 136 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.gitleaks.toml‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ regexTarget = "line"
3434
paths = ['''^tools/release-tools/release\.env$''']
3535
regexes = ['''SIGNING_KEY="[A-F0-9]{40}"''']
3636

37+
[[rules]]
38+
id = "jwt"
39+
40+
[[rules.allowlists]]
41+
description = "Ignore the fake JWT fixture in DelegatedCredentialTest"
42+
condition = "AND"
43+
regexTarget = "line"
44+
paths = ['''^fe/fe-core/src/test/java/org/apache/doris/datasource/DelegatedCredentialTest\.java$''']
45+
regexes = ['''"eyJhbGciOiJub25lIn0\.eyJleHAiOjE3MDAwMDAwMDB9\."''']
46+
3747
[[rules]]
3848
id = "private-key"
3949

‎fe/fe-authentication/fe-authentication-api/README.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ Authentication result is state-driven:
6767

6868
```java
6969
AuthenticationResult ok = AuthenticationResult.success(principal);
70+
AuthenticationResult okWithCredentialExpiration = AuthenticationResult.success(principal, expiresAtMillis);
71+
AuthenticationResult okWithoutCredentialExpiration =
72+
AuthenticationResult.success(principal, AuthenticationResult.NO_CREDENTIAL_EXPIRATION);
7073
AuthenticationResult needMore = AuthenticationResult.continueWith(state, challenge);
7174
AuthenticationResult failed = AuthenticationResult.failure("Invalid credential");
7275
```

‎fe/fe-authentication/fe-authentication-api/src/main/java/org/apache/doris/authentication/AuthenticationResult.java‎

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.LinkedHashSet;
2222
import java.util.Objects;
2323
import java.util.Optional;
24+
import java.util.OptionalLong;
2425
import java.util.Set;
2526

2627
/**
@@ -52,6 +53,7 @@
5253
* }</pre>
5354
*/
5455
public final class AuthenticationResult {
56+
public static final long NO_CREDENTIAL_EXPIRATION = -1L;
5557

5658
/**
5759
* Authentication result status.
@@ -82,20 +84,23 @@ public enum Status {
8284
private final byte[] challengeData;
8385
private final AuthenticationException exception;
8486
private final Set<String> grantedRoles;
87+
private final Long credentialExpiresAtMillis;
8588

8689
private AuthenticationResult(
8790
Status status,
8891
Principal principal,
8992
Object nextState,
9093
byte[] challengeData,
9194
AuthenticationException exception,
92-
Set<String> grantedRoles) {
95+
Set<String> grantedRoles,
96+
Long credentialExpiresAtMillis) {
9397
this.status = Objects.requireNonNull(status, "status is required");
9498
this.principal = principal;
9599
this.nextState = nextState;
96100
this.challengeData = challengeData;
97101
this.exception = exception;
98102
this.grantedRoles = immutableGrantedRoles(grantedRoles);
103+
this.credentialExpiresAtMillis = credentialExpiresAtMillis;
99104
}
100105

101106
/**
@@ -119,7 +124,37 @@ public static AuthenticationResult success(Principal principal) {
119124
*/
120125
public static AuthenticationResult success(Principal principal, Set<String> grantedRoles) {
121126
Objects.requireNonNull(principal, "principal is required for success");
122-
return new AuthenticationResult(Status.SUCCESS, principal, null, null, null, grantedRoles);
127+
return new AuthenticationResult(Status.SUCCESS, principal, null, null, null, grantedRoles, null);
128+
}
129+
130+
/**
131+
* Creates a successful authentication result with credential expiration.
132+
*
133+
* @param principal the authenticated principal
134+
* @param credentialExpiresAtMillis credential expiration time in milliseconds since epoch,
135+
* or {@link #NO_CREDENTIAL_EXPIRATION} when no expiration is available
136+
* @return success result
137+
* @throws NullPointerException if principal is null
138+
*/
139+
public static AuthenticationResult success(Principal principal, long credentialExpiresAtMillis) {
140+
return success(principal, Collections.emptySet(), credentialExpiresAtMillis);
141+
}
142+
143+
/**
144+
* Creates a successful authentication result with granted roles and credential expiration.
145+
*
146+
* @param principal the authenticated principal
147+
* @param grantedRoles the roles granted during authentication handling
148+
* @param credentialExpiresAtMillis credential expiration time in milliseconds since epoch,
149+
* or {@link #NO_CREDENTIAL_EXPIRATION} when no expiration is available
150+
* @return success result
151+
* @throws NullPointerException if principal or grantedRoles is null
152+
*/
153+
public static AuthenticationResult success(Principal principal, Set<String> grantedRoles,
154+
long credentialExpiresAtMillis) {
155+
Objects.requireNonNull(principal, "principal is required for success");
156+
return new AuthenticationResult(Status.SUCCESS, principal, null, null, null, grantedRoles,
157+
normalizeCredentialExpiresAtMillis(credentialExpiresAtMillis));
123158
}
124159

125160
/**
@@ -130,7 +165,7 @@ public static AuthenticationResult success(Principal principal, Set<String> gran
130165
* @return continue result
131166
*/
132167
public static AuthenticationResult continueWith(Object state, byte[] challenge) {
133-
return new AuthenticationResult(Status.CONTINUE, null, state, challenge, null, Collections.emptySet());
168+
return new AuthenticationResult(Status.CONTINUE, null, state, challenge, null, Collections.emptySet(), null);
134169
}
135170

136171
/**
@@ -142,7 +177,7 @@ public static AuthenticationResult continueWith(Object state, byte[] challenge)
142177
*/
143178
public static AuthenticationResult failure(AuthenticationException exception) {
144179
Objects.requireNonNull(exception, "exception is required for failure");
145-
return new AuthenticationResult(Status.FAILURE, null, null, null, exception, Collections.emptySet());
180+
return new AuthenticationResult(Status.FAILURE, null, null, null, exception, Collections.emptySet(), null);
146181
}
147182

148183
/**
@@ -220,6 +255,17 @@ public Set<String> getGrantedRoles() {
220255
return grantedRoles;
221256
}
222257

258+
/**
259+
* Returns when the credential used for this authentication expires.
260+
*
261+
* @return expiration time in milliseconds since epoch, or empty if the plugin does not expose one
262+
*/
263+
public OptionalLong getCredentialExpiresAtMillis() {
264+
return credentialExpiresAtMillis == null
265+
? OptionalLong.empty()
266+
: OptionalLong.of(credentialExpiresAtMillis);
267+
}
268+
223269
/**
224270
* Returns the exception if authentication failed.
225271
*
@@ -270,6 +316,10 @@ private static Set<String> immutableGrantedRoles(Set<String> grantedRoles) {
270316
return Collections.unmodifiableSet(new LinkedHashSet<>(grantedRoles));
271317
}
272318

319+
private static Long normalizeCredentialExpiresAtMillis(long credentialExpiresAtMillis) {
320+
return credentialExpiresAtMillis == NO_CREDENTIAL_EXPIRATION ? null : credentialExpiresAtMillis;
321+
}
322+
273323
@Override
274324
public String toString() {
275325
switch (status) {

‎fe/fe-authentication/fe-authentication-api/src/test/java/org/apache/doris/authentication/AuthenticationResultTest.java‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,39 @@ void testCreateSuccess_WithGrantedRoles() {
6868
Assertions.assertEquals(Set.of("admin", "analyst"), result.getGrantedRoles());
6969
}
7070

71+
@Test
72+
@DisplayName("UT-API-AR-001B: Create success result with credential expiration")
73+
void testCreateSuccess_WithCredentialExpiration() {
74+
Principal principal = BasicPrincipal.builder()
75+
.name("alice")
76+
.authenticator("oidc")
77+
.build();
78+
long expiresAtMillis = 1_700_000_000_000L;
79+
80+
AuthenticationResult result = AuthenticationResult.success(principal, Set.of("admin"), expiresAtMillis);
81+
82+
Assertions.assertTrue(result.isSuccess());
83+
Assertions.assertEquals(Set.of("admin"), result.getGrantedRoles());
84+
Assertions.assertTrue(result.getCredentialExpiresAtMillis().isPresent());
85+
Assertions.assertEquals(expiresAtMillis, result.getCredentialExpiresAtMillis().getAsLong());
86+
}
87+
88+
@Test
89+
@DisplayName("UT-API-AR-001C: No credential expiration sentinel returns empty expiration")
90+
void testCreateSuccess_WithNoCredentialExpirationSentinel() {
91+
Principal principal = BasicPrincipal.builder()
92+
.name("alice")
93+
.authenticator("oidc")
94+
.build();
95+
96+
AuthenticationResult result = AuthenticationResult.success(principal, Set.of("admin"),
97+
AuthenticationResult.NO_CREDENTIAL_EXPIRATION);
98+
99+
Assertions.assertTrue(result.isSuccess());
100+
Assertions.assertEquals(Set.of("admin"), result.getGrantedRoles());
101+
Assertions.assertTrue(result.getCredentialExpiresAtMillis().isEmpty());
102+
}
103+
71104
@Test
72105
@DisplayName("UT-API-AR-002: Create failure result with message")
73106
void testCreateFailure_WithMessage() {

‎fe/fe-authentication/fe-authentication-handler/src/main/java/org/apache/doris/authentication/handler/AuthenticationService.java‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import java.util.LinkedHashSet;
3232
import java.util.List;
3333
import java.util.Objects;
34+
import java.util.OptionalLong;
3435
import java.util.Set;
3536

3637
/**
@@ -232,7 +233,11 @@ private AuthenticationOutcome toOutcome(AuthenticationIntegration integration, A
232233
Principal principal = Objects.requireNonNull(result.getPrincipal(), "principal is required for success");
233234
Set<String> grantedRoles = mergeGrantedRoles(
234235
result.getGrantedRoles(), roleMappingEvaluator.evaluate(integration, principal));
235-
return AuthenticationOutcome.of(integration, AuthenticationResult.success(principal, grantedRoles));
236+
OptionalLong credentialExpiresAtMillis = result.getCredentialExpiresAtMillis();
237+
AuthenticationResult mappedResult = credentialExpiresAtMillis.isPresent()
238+
? AuthenticationResult.success(principal, grantedRoles, credentialExpiresAtMillis.getAsLong())
239+
: AuthenticationResult.success(principal, grantedRoles);
240+
return AuthenticationOutcome.of(integration, mappedResult);
236241
}
237242

238243
private static Set<String> mergeGrantedRoles(Set<String> existingGrantedRoles, Set<String> evaluatedGrantedRoles) {

‎fe/fe-authentication/fe-authentication-handler/src/test/java/org/apache/doris/authentication/handler/AuthenticationServiceTest.java‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ void testAuthenticate_Success() throws AuthenticationException {
154154
.authenticator("test_integration")
155155
.build();
156156

157-
AuthenticationResult successResult = AuthenticationResult.success(principal);
157+
long expiresAtMillis = 1_700_000_000_000L;
158+
AuthenticationResult successResult = AuthenticationResult.success(principal, expiresAtMillis);
158159

159160
Mockito.when(bindingResolver.resolveCandidates(Mockito.eq("alice"), Mockito.any()))
160161
.thenReturn(Collections.singletonList(testIntegration));
@@ -181,7 +182,8 @@ void testAuthenticate_SuccessEvaluatesGrantedRoles() throws AuthenticationExcept
181182
.authenticator("test_integration")
182183
.build();
183184

184-
AuthenticationResult successResult = AuthenticationResult.success(principal);
185+
long expiresAtMillis = 1_700_000_000_000L;
186+
AuthenticationResult successResult = AuthenticationResult.success(principal, expiresAtMillis);
185187

186188
Mockito.when(bindingResolver.resolveCandidates(Mockito.eq("alice"), Mockito.any()))
187189
.thenReturn(Collections.singletonList(testIntegration));
@@ -194,6 +196,8 @@ void testAuthenticate_SuccessEvaluatesGrantedRoles() throws AuthenticationExcept
194196

195197
Assertions.assertTrue(result.isSuccess());
196198
Assertions.assertEquals(Set.of("admin", "analyst"), result.getGrantedRoles());
199+
Assertions.assertTrue(result.getCredentialExpiresAtMillis().isPresent());
200+
Assertions.assertEquals(expiresAtMillis, result.getCredentialExpiresAtMillis().getAsLong());
197201
Mockito.verify(roleMappingEvaluator).evaluate(testIntegration, principal);
198202
}
199203

‎fe/fe-core/src/main/java/org/apache/doris/authentication/AuthenticationIntegrationRuntime.java‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import java.util.List;
3838
import java.util.Map;
3939
import java.util.Objects;
40+
import java.util.OptionalLong;
4041
import java.util.Set;
4142
import java.util.concurrent.ConcurrentHashMap;
4243

@@ -251,7 +252,11 @@ private AuthenticationOutcome toOutcome(AuthenticationIntegration integration, A
251252

252253
LinkedHashSet<String> grantedRoles = new LinkedHashSet<>(result.getGrantedRoles());
253254
grantedRoles.addAll(mappedRoles);
254-
return AuthenticationOutcome.of(integration, AuthenticationResult.success(principal, grantedRoles));
255+
OptionalLong credentialExpiresAtMillis = result.getCredentialExpiresAtMillis();
256+
AuthenticationResult mappedResult = credentialExpiresAtMillis.isPresent()
257+
? AuthenticationResult.success(principal, grantedRoles, credentialExpiresAtMillis.getAsLong())
258+
: AuthenticationResult.success(principal, grantedRoles);
259+
return AuthenticationOutcome.of(integration, mappedResult);
255260
}
256261

257262
private ResolvedAuthenticationPlugin resolvePluginForAuthentication(AuthenticationIntegrationMeta requestedMeta)
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.apache.doris.datasource;
19+
20+
import java.util.Objects;
21+
import java.util.OptionalLong;
22+
23+
public class DelegatedCredential {
24+
private final Type type;
25+
private final String token;
26+
private final Long expiresAtMillis;
27+
28+
public DelegatedCredential(Type type, String token) {
29+
this(type, token, OptionalLong.empty());
30+
}
31+
32+
public DelegatedCredential(Type type, String token, OptionalLong expiresAtMillis) {
33+
this.type = Objects.requireNonNull(type, "type is required");
34+
this.token = Objects.requireNonNull(token, "token is required");
35+
Objects.requireNonNull(expiresAtMillis, "expiresAtMillis is required");
36+
this.expiresAtMillis = expiresAtMillis.isPresent() ? expiresAtMillis.getAsLong() : null;
37+
}
38+
39+
public Type getType() {
40+
return type;
41+
}
42+
43+
public String getToken() {
44+
return token;
45+
}
46+
47+
public OptionalLong getExpiresAtMillis() {
48+
return expiresAtMillis == null ? OptionalLong.empty() : OptionalLong.of(expiresAtMillis);
49+
}
50+
51+
public boolean isExpired(long currentTimeMillis) {
52+
// Use inclusive comparison (>=) on purpose: at the exact expiration instant the credential is
53+
// already considered expired. Treating the boundary as still-valid would risk handing a token
54+
// to the downstream REST server right as it stops being accepted, so we fail closed here.
55+
return expiresAtMillis != null && currentTimeMillis >= expiresAtMillis;
56+
}
57+
58+
@Override
59+
public String toString() {
60+
return "DelegatedCredential{"
61+
+ "type=" + type
62+
+ ", token=<redacted>"
63+
+ ", expiresAtMillis=" + expiresAtMillis
64+
+ '}';
65+
}
66+
67+
public enum Type {
68+
ACCESS_TOKEN,
69+
ID_TOKEN,
70+
JWT,
71+
SAML
72+
}
73+
}

‎fe/fe-core/src/main/java/org/apache/doris/datasource/ExternalCatalog.java‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,19 @@ public final List<String> listTableNames(SessionContext ctx, String dbName) {
364364
*/
365365
protected abstract List<String> listTableNamesFromRemote(SessionContext ctx, String dbName);
366366

367+
/**
368+
* Returns whether the shared table-name cache should be skipped for the current session.
369+
*
370+
* Catalogs whose remote list result depends on session credentials should bypass the cache so one user's
371+
* visible table set is not reused for another user.
372+
*
373+
* @param ctx session context for the current request
374+
* @return true if table names must be fetched from the remote source for this session
375+
*/
376+
protected boolean shouldBypassTableNameCache(SessionContext ctx) {
377+
return false;
378+
}
379+
367380
/**
368381
* check if the specified table exist.
369382
*

0 commit comments

Comments
 (0)