You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@polaris.apache.org by yu...@apache.org on 2026/04/16 17:51:58 UTC
(polaris) branch main updated: Core: enforce single expiration timestamp per credential bundle (#4173)
This is an automated email from the ASF dual-hosted git repository.
yufei pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/polaris.git
The following commit(s) were added to refs/heads/main by this push:
new 7339ea114e Core: enforce single expiration timestamp per credential bundle (#4173)
7339ea114e is described below
commit 7339ea114ed4353ce195fa643a08cb63f2c3b952
Author: Prathyush Shankar <pr...@gmail.com>
AuthorDate: Thu Apr 16 13:51:53 2026 -0400
Core: enforce single expiration timestamp per credential bundle (#4173)
---
CHANGELOG.md | 1 +
.../connection/ConnectionCredentials.java | 13 +++++
.../connection/ConnectionCredentialsTest.java | 60 ++++++++++++++++++++++
3 files changed, 74 insertions(+)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a5c2c07f71..fa7e1fe6a1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -44,6 +44,7 @@ request adding CHANGELOG notes for breaking (!) changes and possibly other secti
- The ExternalCatalogFactory interface has been renamed to FederatedCatalogFactory. Its createCatalog() and createGenericCatalog() method signatures have been extended to include a `catalogProperties` parameter of type `Map<String, String>` for passing through proxy and timeout settings to federated catalog HTTP clients.
- Metrics reporting now requires the `TABLE_READ_DATA` privilege on the target table for read (scan) metrics and `TABLE_WRITE_DATA` for write (commit) metrics.
- The `REVOKE_CATALOG_ROLE_FROM_PRINCIPAL_ROLE` operation no longer requires the `PRINCIPAL_ROLE_MANAGE_GRANTS_FOR_GRANTEE` privilege. Only `CATALOG_ROLE_MANAGE_GRANTS_ON_SECURABLE` on the catalog role is now required, making revoke symmetric with assign. This allows catalog administrators to fully manage catalog role assignments without requiring elevated privileges on principal roles.
+- The `ConnectionCredentials.of()` method now throws an exception when more than one expiration timestamp property is present in the credentials map. Only a single expiration timestamp is allowed per credentials bundle.
### New Features
diff --git a/polaris-core/src/main/java/org/apache/polaris/core/credentials/connection/ConnectionCredentials.java b/polaris-core/src/main/java/org/apache/polaris/core/credentials/connection/ConnectionCredentials.java
index 06d0a54466..d7b1dc64b8 100644
--- a/polaris-core/src/main/java/org/apache/polaris/core/credentials/connection/ConnectionCredentials.java
+++ b/polaris-core/src/main/java/org/apache/polaris/core/credentials/connection/ConnectionCredentials.java
@@ -41,14 +41,27 @@ public record ConnectionCredentials(Map<String, String> credentials, Optional<In
/**
* Creates ConnectionCredentials from a map of catalog access properties. Expiration timestamps
* are extracted and stored separately; credential properties are stored in the credentials map.
+ *
+ * <p>Only a single expiration timestamp is supported per credentials bundle. If multiple
+ * expiration timestamp properties are present, an {@link IllegalArgumentException} is thrown.
*/
public static ConnectionCredentials of(Map<CatalogAccessProperty, String> properties) {
Map<String, String> credentials = new HashMap<>();
Instant expiresAt = null;
+ CatalogAccessProperty expiresAtKey = null;
for (var entry : properties.entrySet()) {
CatalogAccessProperty key = entry.getKey();
if (key.isExpirationTimestamp()) {
+ if (expiresAtKey != null) {
+ throw new IllegalArgumentException(
+ "Multiple expiration timestamp properties found while building ConnectionCredentials: "
+ + expiresAtKey.getPropertyName()
+ + " and "
+ + key.getPropertyName()
+ + ". Only a single expiration timestamp is allowed per credentials bundle.");
+ }
expiresAt = Instant.ofEpochMilli(Long.parseLong(entry.getValue()));
+ expiresAtKey = key;
}
if (key.isCredential()) {
credentials.put(key.getPropertyName(), entry.getValue());
diff --git a/polaris-core/src/test/java/org/apache/polaris/core/credentials/connection/ConnectionCredentialsTest.java b/polaris-core/src/test/java/org/apache/polaris/core/credentials/connection/ConnectionCredentialsTest.java
new file mode 100644
index 0000000000..06d0c8fdc6
--- /dev/null
+++ b/polaris-core/src/test/java/org/apache/polaris/core/credentials/connection/ConnectionCredentialsTest.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.polaris.core.credentials.connection;
+
+import static org.apache.polaris.core.credentials.connection.CatalogAccessProperty.AWS_ACCESS_KEY_ID;
+import static org.apache.polaris.core.credentials.connection.CatalogAccessProperty.AWS_SESSION_TOKEN_EXPIRES_AT_MS;
+import static org.apache.polaris.core.credentials.connection.CatalogAccessProperty.EXPIRES_AT_MS;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import java.time.Instant;
+import java.util.HashMap;
+import java.util.Map;
+import org.junit.jupiter.api.Test;
+
+public class ConnectionCredentialsTest {
+
+ @Test
+ public void testMultipleExpirationTsThrows() {
+ Map<CatalogAccessProperty, String> properties = new HashMap<>();
+ properties.put(
+ AWS_SESSION_TOKEN_EXPIRES_AT_MS, String.valueOf(Instant.ofEpochMilli(1).toEpochMilli()));
+ properties.put(EXPIRES_AT_MS, String.valueOf(Instant.ofEpochMilli(1).toEpochMilli()));
+
+ assertThatThrownBy(() -> ConnectionCredentials.of(properties))
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessageContaining("Multiple expiration timestamp properties")
+ .hasMessageContaining("rest.session-token-expires-at-ms")
+ .hasMessageContaining("rest.expires-at-ms");
+ }
+
+ @Test
+ public void testSingleExpirationTs() {
+ Instant expireAt = Instant.ofEpochMilli(1);
+ ConnectionCredentials credentials =
+ ConnectionCredentials.of(
+ Map.of(
+ AWS_SESSION_TOKEN_EXPIRES_AT_MS,
+ String.valueOf(expireAt.toEpochMilli()),
+ AWS_ACCESS_KEY_ID,
+ "test-key"));
+ assertThat(credentials.expiresAt()).hasValue(expireAt);
+ }
+}