Skip to content

Commit 55d7887

Browse files
MonkeyCanCodeebyhr
authored andcommitted
Add support for token exchange in Iceberg REST catalog
1 parent 836515d commit 55d7887

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

docs/src/main/sphinx/object-storage/metastores.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,9 @@ following properties:
509509
* - `iceberg.rest-catalog.oauth2.token-refresh-enabled`
510510
- Controls whether a token should be refreshed if information about its expiration time is available.
511511
Defaults to `true`
512+
* - `iceberg.rest-catalog.oauth2.token-exchange-enabled`
513+
- Controls whether to use the token exchange flow to acquire new tokens.
514+
Defaults to `true`
512515
* - `iceberg.rest-catalog.vended-credentials-enabled`
513516
- Use credentials provided by the REST backend for file system access.
514517
Defaults to `false`.

plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/catalog/rest/OAuth2SecurityConfig.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public class OAuth2SecurityConfig
2929
private String token;
3030
private URI serverUri;
3131
private boolean tokenRefreshEnabled = OAuth2Properties.TOKEN_REFRESH_ENABLED_DEFAULT;
32+
private boolean tokenExchangeEnabled = OAuth2Properties.TOKEN_EXCHANGE_ENABLED_DEFAULT;
3233

3334
public Optional<String> getCredential()
3435
{
@@ -97,6 +98,19 @@ public OAuth2SecurityConfig setTokenRefreshEnabled(boolean tokenRefreshEnabled)
9798
return this;
9899
}
99100

101+
public boolean isTokenExchangeEnabled()
102+
{
103+
return tokenExchangeEnabled;
104+
}
105+
106+
@Config("iceberg.rest-catalog.oauth2.token-exchange-enabled")
107+
@ConfigDescription("Controls whether to use the token exchange flow to acquire new tokens")
108+
public OAuth2SecurityConfig setTokenExchangeEnabled(boolean tokenExchangeEnabled)
109+
{
110+
this.tokenExchangeEnabled = tokenExchangeEnabled;
111+
return this;
112+
}
113+
100114
@AssertTrue(message = "OAuth2 requires a credential or token")
101115
public boolean credentialOrTokenPresent()
102116
{

plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/catalog/rest/OAuth2SecurityProperties.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public OAuth2SecurityProperties(OAuth2SecurityConfig securityConfig)
4545
securityConfig.getServerUri().ifPresent(
4646
value -> propertiesBuilder.put(OAuth2Properties.OAUTH2_SERVER_URI, value.toString()));
4747
propertiesBuilder.put(OAuth2Properties.TOKEN_REFRESH_ENABLED, String.valueOf(securityConfig.isTokenRefreshEnabled()));
48+
propertiesBuilder.put(OAuth2Properties.TOKEN_EXCHANGE_ENABLED, String.valueOf(securityConfig.isTokenExchangeEnabled()));
4849

4950
this.securityProperties = propertiesBuilder.buildOrThrow();
5051
}

plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/catalog/rest/TestOAuth2SecurityConfig.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ public void testDefaults()
3535
.setToken(null)
3636
.setScope(null)
3737
.setServerUri(null)
38-
.setTokenRefreshEnabled(OAuth2Properties.TOKEN_REFRESH_ENABLED_DEFAULT));
38+
.setTokenRefreshEnabled(OAuth2Properties.TOKEN_REFRESH_ENABLED_DEFAULT)
39+
.setTokenExchangeEnabled(OAuth2Properties.TOKEN_EXCHANGE_ENABLED_DEFAULT));
3940
}
4041

4142
@Test
@@ -47,14 +48,16 @@ public void testExplicitPropertyMappings()
4748
.put("iceberg.rest-catalog.oauth2.scope", "scope")
4849
.put("iceberg.rest-catalog.oauth2.server-uri", "http://localhost:8080/realms/iceberg/protocol/openid-connect/token")
4950
.put("iceberg.rest-catalog.oauth2.token-refresh-enabled", "false")
51+
.put("iceberg.rest-catalog.oauth2.token-exchange-enabled", "false")
5052
.buildOrThrow();
5153

5254
OAuth2SecurityConfig expected = new OAuth2SecurityConfig()
5355
.setCredential("credential")
5456
.setToken("token")
5557
.setScope("scope")
5658
.setServerUri(URI.create("http://localhost:8080/realms/iceberg/protocol/openid-connect/token"))
57-
.setTokenRefreshEnabled(false);
59+
.setTokenRefreshEnabled(false)
60+
.setTokenExchangeEnabled(false);
5861
assertThat(expected.credentialOrTokenPresent()).isTrue();
5962
assertThat(expected.scopePresentOnlyWithCredential()).isFalse();
6063
assertFullMapping(properties, expected);

0 commit comments

Comments
 (0)