This is an automated email from the ASF dual-hosted git repository.
wgtmac pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-cpp.git
The following commit(s) were added to refs/heads/main by this push:
new a9dace15 fix(rest): prevent OAuth client secret redirection during
refresh (#1138)
a9dace15 is described below
commit a9dace15624a2eba49ba410753c1da952a6415c0
Author: Manu Zhang <[email protected]>
AuthorDate: Tue Nov 17 23:05:36 2026 +0800
fix(rest): prevent OAuth client secret redirection during refresh (#1138)
Server-provided catalog configuration could override the OAuth token
endpoint or catalog base URI and redirect a retained client secret during token
refresh.
Disable trust in server-selected OAuth endpoints by default. When client
credentials are configured, require an explicit absolute HTTP(S) token endpoint
before any I/O and preserve the client endpoint and trust policy after merging
server configuration.
Keep server endpoint overrides available through explicit opt-in, preserve
token-only and unauthenticated behavior, and update regression tests to verify
the refresh destination and client-secret submission.
---
src/iceberg/catalog/rest/catalog_properties.h | 5 +++--
src/iceberg/catalog/rest/rest_catalog.cc | 9 ++++++---
src/iceberg/test/rest_catalog_unit_test.cc | 15 +++++++++------
3 files changed, 18 insertions(+), 11 deletions(-)
diff --git a/src/iceberg/catalog/rest/catalog_properties.h
b/src/iceberg/catalog/rest/catalog_properties.h
index 0b24af58..b4a3f459 100644
--- a/src/iceberg/catalog/rest/catalog_properties.h
+++ b/src/iceberg/catalog/rest/catalog_properties.h
@@ -80,9 +80,10 @@ class ICEBERG_REST_EXPORT RestCatalogProperties
/// \brief Whether server configuration may select the OAuth2 token endpoint.
/// When false, the client must explicitly configure an absolute http:// or
https://
- /// oauth2-server-uri. This setting is read from client configuration only.
+ /// oauth2-server-uri when using a client credential. This setting is read
from
+ /// client configuration only.
inline static Entry<bool>
kTrustServerOAuth2Uri{"rest.auth.oauth2.trust-server-uri",
- true};
+ false};
/// \brief Create a default RestCatalogProperties instance.
static RestCatalogProperties default_properties();
diff --git a/src/iceberg/catalog/rest/rest_catalog.cc
b/src/iceberg/catalog/rest/rest_catalog.cc
index a25d28eb..5f7e726b 100644
--- a/src/iceberg/catalog/rest/rest_catalog.cc
+++ b/src/iceberg/catalog/rest/rest_catalog.cc
@@ -470,7 +470,10 @@ Result<std::shared_ptr<RestCatalog>> RestCatalog::Make(
config.Get(RestCatalogProperties::kTrustServerOAuth2Uri);
const auto endpoint =
config.configs().find(auth::AuthProperties::kOAuth2ServerUri.key());
- if (!trust_server_oauth2_uri) {
+ const auto credential =
config.configs().find(auth::AuthProperties::kCredential.key());
+ const bool has_client_credential =
+ credential != config.configs().end() && !credential->second.empty();
+ if (!trust_server_oauth2_uri && has_client_credential) {
ICEBERG_PRECHECK(
endpoint != config.configs().end() &&
(endpoint->second.starts_with("https://") ||
endpoint->second.starts_with("http://")),
@@ -499,9 +502,9 @@ Result<std::shared_ptr<RestCatalog>> RestCatalog::Make(
RestCatalogProperties final_config = RestCatalogProperties::FromMap(
MergeConfigs(server_config.defaults, config.configs(),
server_config.overrides));
// The server cannot change the client's endpoint trust policy or, when
disabled,
- // move the OAuth endpoint directly or through an override of the catalog
URI.
+ // move a client credential directly or through an override of the catalog
URI.
final_config.Set(RestCatalogProperties::kTrustServerOAuth2Uri,
trust_server_oauth2_uri);
- if (!trust_server_oauth2_uri) {
+ if (!trust_server_oauth2_uri && has_client_credential) {
final_config.mutable_configs().insert_or_assign(endpoint->first,
endpoint->second);
}
diff --git a/src/iceberg/test/rest_catalog_unit_test.cc
b/src/iceberg/test/rest_catalog_unit_test.cc
index 1b162763..b1fc9fad 100644
--- a/src/iceberg/test/rest_catalog_unit_test.cc
+++ b/src/iceberg/test/rest_catalog_unit_test.cc
@@ -341,6 +341,7 @@ TEST_F(RestCatalogLoadTableTest,
OAuthRefreshRunsOnAuthExecutorWhenEnabled) {
{{"uri", "http://test-server"},
{"io-impl", "rest-catalog-unit-test-noop"},
{"credential", "client:secret"},
+ {"oauth2-server-uri", "http://test-server/v1/oauth/tokens"},
{"token-refresh-enabled", refresh ? "true" : "false"}});
auto& tokens =
EXPECT_CALL(*mock_client_, PostForm(_, _, _, _, _)).Times(refresh ? 2
: 1);
@@ -669,7 +670,8 @@ class RestCatalogOAuth2UriTest : public
RestCatalogLoadTableTest {
int factory_calls_ = 0;
};
-TEST_F(RestCatalogOAuth2UriTest, TrustsServerOverridesByDefault) {
+TEST_F(RestCatalogOAuth2UriTest, TrustsServerOverridesWhenExplicitlyEnabled) {
+ properties_["rest.auth.oauth2.trust-server-uri"] = "true";
ExpectInit({.overrides = {{"uri", "HTTPS://other-catalog.example/base/"},
{"oauth2-server-uri", "oauth/token///"},
{"rest.auth.oauth2.trust-server-uri", "false"}}});
@@ -678,8 +680,7 @@ TEST_F(RestCatalogOAuth2UriTest,
TrustsServerOverridesByDefault) {
auth::AuthProperties::kIdTokenType);
}
-TEST_F(RestCatalogOAuth2UriTest,
RequiresAbsoluteClientEndpointBeforeAnyIoWhenUntrusted) {
- properties_["rest.auth.oauth2.trust-server-uri"] = "false";
+TEST_F(RestCatalogOAuth2UriTest, RequiresAbsoluteClientEndpointByDefault) {
properties_.erase("oauth2-server-uri");
EXPECT_THAT(MakeOAuth2Catalog(), IsError(ErrorKind::kInvalidArgument));
for (const auto* endpoint :
@@ -692,7 +693,7 @@ TEST_F(RestCatalogOAuth2UriTest,
RequiresAbsoluteClientEndpointBeforeAnyIoWhenUn
EXPECT_EQ(factory_calls_, 0);
}
-TEST_F(RestCatalogOAuth2UriTest, RefreshUsesTheClientEndpointWhenUntrusted) {
+TEST_F(RestCatalogOAuth2UriTest, RefreshUsesTheClientEndpointByDefault) {
test::MockExecutor executor;
std::promise<ExecutorTask> queued;
auto ready = queued.get_future();
@@ -700,13 +701,15 @@ TEST_F(RestCatalogOAuth2UriTest,
RefreshUsesTheClientEndpointWhenUntrusted) {
queued.set_value(std::move(task));
return {};
});
- properties_["rest.auth.oauth2.trust-server-uri"] = "false";
properties_["token-refresh-enabled"] = "true";
ExpectInit({.overrides = {{"uri", "https://other-catalog.example"},
{"oauth2-server-uri",
"https://server-auth.example/token"},
{"rest.auth.oauth2.trust-server-uri", "true"}}},
R"({"access_token":"expired","token_type":"bearer","expires_in":0})");
- EXPECT_CALL(*mock_client_, PostForm("https://auth.example/token/", _, _, _,
_))
+ EXPECT_CALL(
+ *mock_client_,
+ PostForm("https://auth.example/token/",
+ ::testing::Contains(::testing::Pair("client_secret",
"secret")), _, _, _))
.WillOnce(Return(
HttpResponse(200,
R"({"access_token":"refreshed","token_type":"bearer"})")));
ICEBERG_UNWRAP_OR_FAIL(auto root, MakeOAuth2Catalog(&executor));