World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.
Java ai-catalogdata-catalogdatalakefederated-querylakehousemetadatametalakemodel-catalogopendatacatalogskycomputingstratosphere
[#15232] fix(authz): Omit static credential keys from getSecrets without INCLUDE_CREDENTIAL_SECRETS (#15233)
MaSaiad95f5e333f0
diff --git a/api/src/main/java/org/apache/gravitino/authorization/Privilege.java b/api/src/main/java/org/apache/gravitino/authorization/Privilege.javaindex 4c84eb78af..cdba25331f 100644--- a/api/src/main/java/org/apache/gravitino/authorization/Privilege.java+++ b/api/src/main/java/org/apache/gravitino/authorization/Privilege.java@@ -161,17 +161,20 @@ public interface Privilege {/** The privilege to list configured secrets providers. */VIEW_SECRET_PROVIDERS(0L, 1L << 36),/**- * The privilege required to call {@code getSecrets}. Without {@link- * #INCLUDE_CREDENTIAL_SECRETS}, cloud access-key pairs are omitted from the result. Both- * privileges are also required for catalog {@code getCredentials}, unless the caller owns the- * metalake.+ * Soft-authorizes {@code getSecrets}: without this privilege (and without metalake ownership)+ * the API returns an empty map rather than {@code 403}. Without {@link+ * #INCLUDE_CREDENTIAL_SECRETS}, canonical static credential keys are omitted from the result.+ * For catalog and fileset {@code getCredentials}, metadata access is enough for token+ * providers; static providers are omitted unless this privilege is held together with {@link+ * #INCLUDE_CREDENTIAL_SECRETS} (or the caller owns the metalake).*/USE_SECRETS(0L, 1L << 37),/**- * When held together with {@link #USE_SECRETS}, includes cloud access-key pairs and other- * credential secrets in the {@code getSecrets} result. Alone it does not authorize {@code- * getSecrets}. Both privileges are also required for catalog {@code getCredentials}, unless the- * caller owns the metalake.+ * When held together with {@link #USE_SECRETS} (or metalake ownership), includes canonical+ * static credential keys in the {@code getSecrets} result and allows static providers on+ * catalog and fileset {@code getCredentials}. Alone it does not unlock {@code getSecrets}.+ * Missing this privilege soft-filters static material (omit / dynamic-only); it does not return+ * {@code 403} when metadata access is already granted.*/INCLUDE_CREDENTIAL_SECRETS(0L, 1L << 38),/** The privilege to create a semantic model. */diff --git a/catalogs/catalog-common/src/main/java/org/apache/gravitino/storage/CloudStorageCredentialPropertyKeys.java b/catalogs/catalog-common/src/main/java/org/apache/gravitino/storage/CloudStorageCredentialPropertyKeys.javadeleted file mode 100644index cc86b1be25..0000000000--- a/catalogs/catalog-common/src/main/java/org/apache/gravitino/storage/CloudStorageCredentialPropertyKeys.java+++ /dev/null@@ -1,172 +0,0 @@-/*- * 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.gravitino.storage;--import com.google.common.collect.ImmutableMap;-import com.google.common.collect.ImmutableSet;-import java.util.HashMap;-import java.util.Map;-import java.util.Set;-import javax.annotation.Nullable;-import org.apache.gravitino.catalog.lakehouse.paimon.PaimonConstants;--/**- * Gravitino property keys for cloud static credentials (access-key pairs and related secrets).- *- * <p>GVFS must not consume these keys from REST catalog/schema/fileset {@code properties()}- * responses (which may be masked as {@code ******}). Plaintext for hidden static credentials,- * including {@code s3-access-key-id}, is recovered via {@code getSecrets()} when the caller holds- * {@code USE_SECRETS} and {@code INCLUDE_CREDENTIAL_SECRETS}, or via {@code getCredentials()}.- * Catalog credential vending requires both privileges or metalake ownership, in addition to- * metadata access; fileset credential vending uses path-based authorization. Masked placeholders- * are dropped by {@link #omitStaticCredentialProperties}. Callers with only {@code USE_SECRETS}- * receive {@code getSecrets()} with cloud access-key pairs omitted via {@link- * #omitCloudAccessKeyPairProperties}.- *- * <p>{@code azure-storage-account-name} is intentionally left non-hidden (and not listed here):- * unlike S3/OSS/COS access key IDs, the account name is already disclosed in ADLS URIs such as- * {@code abfss://[email protected]}, so masking it on load/list adds no- * confidentiality. Only {@code azure-storage-account-key} is treated as a secret half.- */-public final class CloudStorageCredentialPropertyKeys {-- /** Placeholder returned for masked hidden properties in REST responses. */- public static final String MASKED_PROPERTY_VALUE = "******";-- /**- * Static cloud credential property keys omitted from REST {@code properties()} merges for GVFS- * (alongside masked placeholders).- */- private static final Set<String> STATIC_CREDENTIAL_KEYS =- ImmutableSet.of(- S3Properties.GRAVITINO_S3_ACCESS_KEY_ID,- S3Properties.GRAVITINO_S3_SECRET_ACCESS_KEY,- OSSProperties.GRAVITINO_OSS_ACCESS_KEY_ID,- OSSProperties.GRAVITINO_OSS_ACCESS_KEY_SECRET,- AzureProperties.GRAVITINO_AZURE_STORAGE_ACCOUNT_KEY,- AzureProperties.GRAVITINO_AZURE_CLIENT_SECRET,- COSProperties.GRAVITINO_COS_ACCESS_KEY_ID,- COSProperties.GRAVITINO_COS_ACCESS_KEY_SECRET);-- /**- * Cloud access-key pair (and Azure static secret) keys omitted from {@code getSecrets()} when the- * caller has {@code USE_SECRETS} but not {@code INCLUDE_CREDENTIAL_SECRETS}. JDBC secrets are- * intentionally not listed so connectors can still recover them via {@code getSecrets()}.- */- private static final Set<String> CLOUD_ACCESS_KEY_PAIR_KEYS =- ImmutableSet.of(- S3Properties.GRAVITINO_S3_ACCESS_KEY_ID,- S3Properties.GRAVITINO_S3_SECRET_ACCESS_KEY,- OSSProperties.GRAVITINO_OSS_ACCESS_KEY_ID,- OSSProperties.GRAVITINO_OSS_ACCESS_KEY_SECRET,- COSProperties.GRAVITINO_COS_ACCESS_KEY_ID,- COSProperties.GRAVITINO_COS_ACCESS_KEY_SECRET,- AWSProperties.GRAVITINO_AWS_ACCESS_KEY_ID,- AWSProperties.GRAVITINO_AWS_SECRET_ACCESS_KEY,- AzureProperties.GRAVITINO_AZURE_STORAGE_ACCOUNT_KEY,- AzureProperties.GRAVITINO_AZURE_CLIENT_SECRET,- PaimonConstants.GRAVITINO_DLF_ACCESS_KEY_ID,- PaimonConstants.GRAVITINO_DLF_ACCESS_KEY_SECRET,- PaimonConstants.GRAVITINO_DLF_SECURITY_TOKEN);-- private CloudStorageCredentialPropertyKeys() {}-- /**- * Returns whether the property key holds a static cloud credential for GVFS.- *- * @param key the property key- * @return true when the key is a static credential property- */- public static boolean isStaticCredentialKey(@Nullable String key) {- return key != null && STATIC_CREDENTIAL_KEYS.contains(key);- }-- /**- * Returns whether the property key is a cloud access-key pair (or Azure static secret) that- * {@code USE_SECRETS} must not see via {@code getSecrets()} without {@code- * INCLUDE_CREDENTIAL_SECRETS}.- *- * @param key the property key- * @return true when the key must be omitted for use-secret-only callers- */- public static boolean isCloudAccessKeyPairKey(@Nullable String key) {- return key != null && CLOUD_ACCESS_KEY_PAIR_KEYS.contains(key);- }-- /**- * Returns a copy of {@code properties} with static credential keys and masked placeholders- * removed. Used when merging REST metadata into GVFS client configuration.- *- * @param properties source properties from REST metadata responses- * @return filtered properties safe to pass to the underlying HCFS client- */- public static Map<String, String> omitStaticCredentialProperties(- @Nullable Map<String, String> properties) {- if (properties == null || properties.isEmpty()) {- return ImmutableMap.of();- }- Map<String, String> filtered = new HashMap<>();- for (Map.Entry<String, String> entry : properties.entrySet()) {- String key = entry.getKey();- String value = entry.getValue();- if (key == null || value == null) {- continue;- }- if (isStaticCredentialKey(key) || MASKED_PROPERTY_VALUE.equals(value)) {- continue;- }- filtered.put(key, value);- }- return ImmutableMap.copyOf(filtered);- }-- /**- * Returns a copy of {@code secrets} with cloud access-key pair keys removed. Used when filtering- * {@code getSecrets()} for callers that hold {@code USE_SECRETS} but not {@code- * INCLUDE_CREDENTIAL_SECRETS}.- *- * @param secrets plaintext secrets map- * @return secrets without cloud access-key pairs- */- public static Map<String, String> omitCloudAccessKeyPairProperties(- @Nullable Map<String, String> secrets) {- if (secrets == null || secrets.isEmpty()) {- return ImmutableMap.of();- }- Map<String, String> filtered = new HashMap<>();- for (Map.Entry<String, String> entry : secrets.entrySet()) {- String key = entry.getKey();- if (key == null || isCloudAccessKeyPairKey(key)) {- continue;- }- filtered.put(key, entry.getValue());- }- return ImmutableMap.copyOf(filtered);- }-- /** Returns the static credential property keys. */- public static Set<String> staticCredentialKeys() {- return STATIC_CREDENTIAL_KEYS;- }-- /** Returns cloud access-key pair keys omitted for {@code USE_SECRETS} {@code getSecrets}. */- public static Set<String> cloudAccessKeyPairKeys() {- return CLOUD_ACCESS_KEY_PAIR_KEYS;- }-}diff --git a/catalogs/catalog-common/src/test/java/org/apache/gravitino/storage/TestCloudStorageCredentialPropertyKeys.java b/catalogs/catalog-common/src/test/java/org/apache/gravitino/storage/TestCloudStorageCredentialPropertyKeys.javadeleted file mode 100644index 09e25f1b64..0000000000--- a/catalogs/catalog-common/src/test/java/org/apache/gravitino/storage/TestCloudStorageCredentialPropertyKeys.java+++ /dev/null@@ -1,186 +0,0 @@-/*- * 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.gravitino.storage;--import static org.junit.jupiter.api.Assertions.assertEquals;-import static org.junit.jupiter.api.Assertions.assertFalse;-import static org.junit.jupiter.api.Assertions.assertTrue;--import java.util.Map;-import org.apache.gravitino.catalog.glue.GlueConstants;-import org.apache.gravitino.catalog.lakehouse.paimon.PaimonConstants;-import org.junit.jupiter.api.Test;--public class TestCloudStorageCredentialPropertyKeys {-- @Test- void testOmitStaticCredentialProperties() {- Map<String, String> input =- Map.of(- S3Properties.GRAVITINO_S3_ENDPOINT,- "https://s3.amazonaws.com",- S3Properties.GRAVITINO_S3_ACCESS_KEY_ID,- "AKIATEST",- S3Properties.GRAVITINO_S3_SECRET_ACCESS_KEY,- "secret",- OSSProperties.GRAVITINO_OSS_REGION,- "cn-hangzhou",- "masked-any-key",- CloudStorageCredentialPropertyKeys.MASKED_PROPERTY_VALUE);-- Map<String, String> filtered =- CloudStorageCredentialPropertyKeys.omitStaticCredentialProperties(input);-- assertEquals("https://s3.amazonaws.com", filtered.get(S3Properties.GRAVITINO_S3_ENDPOINT));- assertEquals("cn-hangzhou", filtered.get(OSSProperties.GRAVITINO_OSS_REGION));- // Access key IDs and secrets are stripped from properties(); recover via getSecrets /- // getCredentials.- assertFalse(filtered.containsKey(S3Properties.GRAVITINO_S3_ACCESS_KEY_ID));- assertFalse(filtered.containsKey(S3Properties.GRAVITINO_S3_SECRET_ACCESS_KEY));- assertFalse(filtered.containsKey("masked-any-key"));- }-- @Test- void testOmitMaskedAccessKeyIds() {- Map<String, String> input =- Map.of(- S3Properties.GRAVITINO_S3_ACCESS_KEY_ID,- CloudStorageCredentialPropertyKeys.MASKED_PROPERTY_VALUE,- S3Properties.GRAVITINO_S3_SECRET_ACCESS_KEY,- "secret");-- Map<String, String> filtered =- CloudStorageCredentialPropertyKeys.omitStaticCredentialProperties(input);-- assertFalse(filtered.containsKey(S3Properties.GRAVITINO_S3_ACCESS_KEY_ID));- assertFalse(filtered.containsKey(S3Properties.GRAVITINO_S3_SECRET_ACCESS_KEY));- }-- @Test- void testStaticCredentialKeyDetection() {- assertTrue(- CloudStorageCredentialPropertyKeys.isStaticCredentialKey(- COSProperties.GRAVITINO_COS_ACCESS_KEY_SECRET));- assertTrue(- CloudStorageCredentialPropertyKeys.isStaticCredentialKey(- COSProperties.GRAVITINO_COS_ACCESS_KEY_ID));- assertFalse(- CloudStorageCredentialPropertyKeys.isStaticCredentialKey(- COSProperties.GRAVITINO_COS_REGION));-- assertTrue(- CloudStorageCredentialPropertyKeys.isStaticCredentialKey(- AzureProperties.GRAVITINO_AZURE_CLIENT_SECRET));-- // Glue/Paimon-DLF secrets are catalog/metastore-connection credentials, not cloud-storage- // secrets in the fileset properties map this filter governs.- assertFalse(- CloudStorageCredentialPropertyKeys.isStaticCredentialKey(- GlueConstants.AWS_SECRET_ACCESS_KEY));- assertFalse(- CloudStorageCredentialPropertyKeys.isStaticCredentialKey(- PaimonConstants.GRAVITINO_DLF_ACCESS_KEY_SECRET));- assertFalse(- CloudStorageCredentialPropertyKeys.isStaticCredentialKey(- PaimonConstants.GRAVITINO_DLF_SECURITY_TOKEN));- assertFalse(- CloudStorageCredentialPropertyKeys.isStaticCredentialKey(GlueConstants.AWS_ACCESS_KEY_ID));- assertFalse(- CloudStorageCredentialPropertyKeys.isStaticCredentialKey(- PaimonConstants.GRAVITINO_DLF_ACCESS_KEY_ID));- }-- @Test- void testAzureClientSecretStrippedButGlueAccessKeyIdsSurvive() {- Map<String, String> input =- Map.of(- AzureProperties.GRAVITINO_AZURE_CLIENT_SECRET, "aad-secret",- GlueConstants.AWS_ACCESS_KEY_ID, "ak",- PaimonConstants.GRAVITINO_DLF_ACCESS_KEY_ID, "dlf-ak");-- Map<String, String> filtered =- CloudStorageCredentialPropertyKeys.omitStaticCredentialProperties(input);-- assertFalse(filtered.containsKey(AzureProperties.GRAVITINO_AZURE_CLIENT_SECRET));- // Glue/DLF IDs are not in the fileset static cloud set; unmasked values survive here.- assertEquals("ak", filtered.get(GlueConstants.AWS_ACCESS_KEY_ID));- assertEquals("dlf-ak", filtered.get(PaimonConstants.GRAVITINO_DLF_ACCESS_KEY_ID));- }-- @Test- void testOmitCloudAccessKeyPairProperties() {- Map<String, String> secrets =- Map.of(- S3Properties.GRAVITINO_S3_ACCESS_KEY_ID,- "AKIATEST",- S3Properties.GRAVITINO_S3_SECRET_ACCESS_KEY,- "secret",- "jdbc-password",- "db-pass",- "custom-token",- "tok");-- Map<String, String> filtered =- CloudStorageCredentialPropertyKeys.omitCloudAccessKeyPairProperties(secrets);-- assertEquals("db-pass", filtered.get("jdbc-password"));- assertEquals("tok", filtered.get("custom-token"));- assertFalse(filtered.containsKey(S3Properties.GRAVITINO_S3_ACCESS_KEY_ID));- assertFalse(filtered.containsKey(S3Properties.GRAVITINO_S3_SECRET_ACCESS_KEY));- }-- @Test- void testCloudAccessKeyPairKeyDetection() {- assertTrue(- CloudStorageCredentialPropertyKeys.isCloudAccessKeyPairKey(- S3Properties.GRAVITINO_S3_ACCESS_KEY_ID));- assertTrue(- CloudStorageCredentialPropertyKeys.isCloudAccessKeyPairKey(- AWSProperties.GRAVITINO_AWS_SECRET_ACCESS_KEY));- assertTrue(- CloudStorageCredentialPropertyKeys.isCloudAccessKeyPairKey(- PaimonConstants.GRAVITINO_DLF_ACCESS_KEY_SECRET));- assertTrue(- CloudStorageCredentialPropertyKeys.isCloudAccessKeyPairKey(- PaimonConstants.GRAVITINO_DLF_SECURITY_TOKEN));- assertFalse(CloudStorageCredentialPropertyKeys.isCloudAccessKeyPairKey("jdbc-password"));- }-- @Test- void testOmitCloudAccessKeyPairOmitsDlfSecurityToken() {- Map<String, String> secrets =- Map.of(- PaimonConstants.GRAVITINO_DLF_ACCESS_KEY_ID,- "dlf-ak",- PaimonConstants.GRAVITINO_DLF_ACCESS_KEY_SECRET,- "dlf-sk",- PaimonConstants.GRAVITINO_DLF_SECURITY_TOKEN,- "dlf-token",- "jdbc-password",- "db-pass");-- Map<String, String> filtered =- CloudStorageCredentialPropertyKeys.omitCloudAccessKeyPairProperties(secrets);-- assertEquals("db-pass", filtered.get("jdbc-password"));- assertFalse(filtered.containsKey(PaimonConstants.GRAVITINO_DLF_ACCESS_KEY_ID));- assertFalse(filtered.containsKey(PaimonConstants.GRAVITINO_DLF_ACCESS_KEY_SECRET));- assertFalse(filtered.containsKey(PaimonConstants.GRAVITINO_DLF_SECURITY_TOKEN));- }-}diff --git a/clients/filesystem-hadoop3/src/main/java/org/apache/gravitino/filesystem/hadoop/BaseGVFSOperations.java b/clients/filesystem-hadoop3/src/main/java/org/apache/gravitino/filesystem/hadoop/BaseGVFSOperations.javaindex 4b8e6e9b3d..5fe093f69f 100644--- a/clients/filesystem-hadoop3/src/main/java/org/apache/gravitino/filesystem/hadoop/BaseGVFSOperations.java+++ b/clients/filesystem-hadoop3/src/main/java/org/apache/gravitino/filesystem/hadoop/BaseGVFSOperations.java@@ -86,7 +86,6 @@ import org.apache.gravitino.file.Fileset;import org.apache.gravitino.file.FilesetCatalog;import org.apache.gravitino.secret.SupportsSecrets;import org.apache.gravitino.storage.AzureProperties;-import org.apache.gravitino.storage.CloudStorageCredentialPropertyKeys;import org.apache.gravitino.storage.OSSProperties;import org.apache.gravitino.storage.S3Properties;import org.apache.gravitino.utils.FilesetUtil;@@ -120,6 +119,10 @@ import org.slf4j.LoggerFactory;*/public abstract class BaseGVFSOperations implements Closeable {private static final Logger LOG = LoggerFactory.getLogger(BaseGVFSOperations.class);++ /** Placeholder returned for masked hidden properties in REST responses. */+ private static final String MASKED_PROPERTY_VALUE = "******";+private static final String SLASH = "/";private static final Set<String> CATALOG_NECESSARY_PROPERTIES_TO_KEEP =Sets.newHashSet(@@ -1115,13 +1118,36 @@ public abstract class BaseGVFSOperations implements Closeable {private static void putPropsAndSecrets(Map<String, String> target, Map<String, String> props, SupportsSecrets secrets) {if (props != null) {- target.putAll(CloudStorageCredentialPropertyKeys.omitStaticCredentialProperties(props));+ // Masked placeholders must not enter HCFS conf or overwrite later getSecrets/getCredentials+ // plaintext (same as Python GVFS). Static-credential key filtering is server-side only.+ target.putAll(omitMaskedProperties(props));}if (secrets != null) {target.putAll(secrets.getSecrets());}}+ /**+ * Returns a copy of {@code properties} with masked placeholders removed. Aligns with Python GVFS+ * {@code _omit_masked_properties}.+ */+ private static Map<String, String> omitMaskedProperties(+ @Nullable Map<String, String> properties) {+ if (properties == null || properties.isEmpty()) {+ return ImmutableMap.of();+ }+ Map<String, String> filtered = new HashMap<>();+ for (Map.Entry<String, String> entry : properties.entrySet()) {+ String key = entry.getKey();+ String value = entry.getValue();+ if (key == null || value == null || MASKED_PROPERTY_VALUE.equals(value)) {+ continue;+ }+ filtered.put(key, value);+ }+ return ImmutableMap.copyOf(filtered);+ }+/*** Merges static ({@code expireTimeInMs == 0}) {@link Credential#credentialInfo()} from catalog* {@code getCredentials} into GVFS configuration. Invoked when a filesystem is created, sodiff --git a/clients/filesystem-hadoop3/src/test/java/org/apache/gravitino/filesystem/hadoop/TestBaseGVFSOperationsSecrets.java b/clients/filesystem-hadoop3/src/test/java/org/apache/gravitino/filesystem/hadoop/TestBaseGVFSOperationsSecrets.javaindex 3d633e58f5..8ccc1e7ecf 100644--- a/clients/filesystem-hadoop3/src/test/java/org/apache/gravitino/filesystem/hadoop/TestBaseGVFSOperationsSecrets.java+++ b/clients/filesystem-hadoop3/src/test/java/org/apache/gravitino/filesystem/hadoop/TestBaseGVFSOperationsSecrets.java@@ -54,7 +54,6 @@ import org.apache.gravitino.exceptions.RESTException;import org.apache.gravitino.file.Fileset;import org.apache.gravitino.file.FilesetCatalog;import org.apache.gravitino.secret.SupportsSecrets;-import org.apache.gravitino.storage.CloudStorageCredentialPropertyKeys;import org.apache.gravitino.storage.S3Properties;import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.fs.FSDataInputStream;@@ -203,7 +202,7 @@ public class TestBaseGVFSOperationsSecrets {}@Test- public void testOmitsStaticCredentialKeysFromRestProperties() throws Exception {+ public void testOmitsMaskedPropertyValuesFromRestProperties() throws Exception {Configuration conf = new Configuration();conf.set(GravitinoVirtualFileSystemConfiguration.FS_GRAVITINO_CLIENT_METALAKE_KEY, "ml");conf.set(@@ -243,10 +242,12 @@ public class TestBaseGVFSOperationsSecrets {Map<String, String> all =ops.getAllProperties(NameIdentifier.of("ml", "catalog", "schema", "fs"));- assertFalse(all.containsKey(S3Properties.GRAVITINO_S3_SECRET_ACCESS_KEY));- assertEquals("http://s3.example.com", all.get("s3-endpoint"));+ // Masked placeholder dropped; local conf supplies the access key.assertEquals("local-access-key", all.get(S3Properties.GRAVITINO_S3_ACCESS_KEY_ID));assertFalse("******".equals(all.get(S3Properties.GRAVITINO_S3_ACCESS_KEY_ID)));+ // Plaintext in properties is kept (GVFS does not re-apply the server static-key denylist).+ assertEquals("secret-from-rest", all.get(S3Properties.GRAVITINO_S3_SECRET_ACCESS_KEY));+ assertEquals("http://s3.example.com", all.get("s3-endpoint"));}@Test@@ -260,9 +261,9 @@ public class TestBaseGVFSOperationsSecrets {mockCatalogWithCredentials(Map.of(S3Properties.GRAVITINO_S3_ACCESS_KEY_ID,- CloudStorageCredentialPropertyKeys.MASKED_PROPERTY_VALUE,+ "******",S3Properties.GRAVITINO_S3_SECRET_ACCESS_KEY,- CloudStorageCredentialPropertyKeys.MASKED_PROPERTY_VALUE,+ "******","s3-endpoint","http://s3.example.com"),credentials);diff --git a/clients/filesystem-hadoop3/src/test/java/org/apache/gravitino/filesystem/hadoop/integration/test/FilesetCatalogAuthorizationCredentialIT.java b/clients/filesystem-hadoop3/src/test/java/org/apache/gravitino/filesystem/hadoop/integration/test/FilesetCatalogAuthorizationCredentialIT.javaindex 52068c0efd..7fd1c772cb 100644--- a/clients/filesystem-hadoop3/src/test/java/org/apache/gravitino/filesystem/hadoop/integration/test/FilesetCatalogAuthorizationCredentialIT.java+++ b/clients/filesystem-hadoop3/src/test/java/org/apache/gravitino/filesystem/hadoop/integration/test/FilesetCatalogAuthorizationCredentialIT.java@@ -196,11 +196,12 @@ public class FilesetCatalogAuthorizationCredentialIT extends BaseIT {GravitinoMetalake normalUserMetalake = normalUserClient.loadMetalake(metalakeName);Catalog catalog = normalUserMetalake.loadCatalog(catalogName);MetadataObject object = MetadataObjects.of(null, catalogName, MetadataObject.Type.CATALOG);- assertThrows(ForbiddenException.class, () -> catalog.supportsCredentials().getCredentials());+ // Metadata access alone soft-filters static catalog credentials to empty (not 403).+ Assertions.assertEquals(0, catalog.supportsCredentials().getCredentials().length);try {metalake.grantPrivilegesToRole(ROLE_NAME, object, ImmutableSet.of(Privileges.UseSecrets.allow()));- assertThrows(ForbiddenException.class, () -> catalog.supportsCredentials().getCredentials());+ Assertions.assertEquals(0, catalog.supportsCredentials().getCredentials().length);metalake.grantPrivilegesToRole(ROLE_NAME, object, ImmutableSet.of(Privileges.IncludeCredentialSecrets.allow()));Assertions.assertTrue(catalog.supportsCredentials().getCredentials().length > 0);diff --git a/core/src/main/java/org/apache/gravitino/credential/CredentialOperationDispatcher.java b/core/src/main/java/org/apache/gravitino/credential/CredentialOperationDispatcher.javaindex 857f41b88c..b195433260 100644--- a/core/src/main/java/org/apache/gravitino/credential/CredentialOperationDispatcher.java+++ b/core/src/main/java/org/apache/gravitino/credential/CredentialOperationDispatcher.java@@ -54,16 +54,39 @@ public class CredentialOperationDispatcher extends OperationDispatcher {}public List<Credential> getCredentials(NameIdentifier identifier, CredentialPrivilege privilege) {+ return getCredentials(identifier, privilege, false /* dynamicProvidersOnly */);+ }++ /**+ * Returns credentials for {@code identifier}.+ *+ * @param identifier the metadata object+ * @param privilege read or write privilege for path-based contexts+ * @param dynamicProvidersOnly when {@code true}, only providers that implement {@link+ * SupportsDynamicCredential} are invoked+ * @return generated credentials; may be empty+ */+ public List<Credential> getCredentials(+ NameIdentifier identifier, CredentialPrivilege privilege, boolean dynamicProvidersOnly) {return doWithCatalog(NameIdentifierUtil.getCatalogIdentifier(identifier),catalogWrapper ->catalogWrapper.doWithCredentialOps(- baseCatalog -> getCredentials(baseCatalog, identifier, privilege)),+ baseCatalog ->+ getCredentials(baseCatalog, identifier, privilege, dynamicProvidersOnly)),NoSuchCatalogException.class);}List<Credential> getCredentials(BaseCatalog baseCatalog, NameIdentifier nameIdentifier, CredentialPrivilege privilege) {+ return getCredentials(baseCatalog, nameIdentifier, privilege, false);+ }++ List<Credential> getCredentials(+ BaseCatalog baseCatalog,+ NameIdentifier nameIdentifier,+ CredentialPrivilege privilege,+ boolean dynamicProvidersOnly) {Map<String, CredentialContext> contexts =getCredentialContexts(baseCatalog, nameIdentifier, privilege);List<Credential> credentials = new ArrayList<>();@@ -73,9 +96,13 @@ public class CredentialOperationDispatcher extends OperationDispatcher {if (!providerOptional.isPresent()) {continue;}+ CredentialProvider provider = providerOptional.get();+ if (dynamicProvidersOnly && !(provider instanceof SupportsDynamicCredential)) {+ continue;+ }Optional<CredentialContext> contextOptional =- filterContextByProvider(providerOptional.get(), entry.getValue());+ filterContextByProvider(provider, entry.getValue());if (!contextOptional.isPresent()) {continue;}diff --git a/core/src/main/java/org/apache/gravitino/secret/FallbackPropertiesMetadata.java b/core/src/main/java/org/apache/gravitino/secret/FallbackPropertiesMetadata.javaindex 1ba4872e58..30ae2c9cec 100644--- a/core/src/main/java/org/apache/gravitino/secret/FallbackPropertiesMetadata.java+++ b/core/src/main/java/org/apache/gravitino/secret/FallbackPropertiesMetadata.java@@ -32,9 +32,10 @@ import org.apache.gravitino.connector.PropertyEntry;* {@code credential-providers}, {@code s3-token-expire-in-secs}) are not fuzzy-recovered into* {@code getSecrets}. Undeclared sensitive-named keys still use fuzzy recovery. Declared hidden* cloud credential keys (for example {@code s3-access-key-id}, {@code s3-secret-access-key}) are- * recovered via {@code getSecrets} when the caller holds {@code USE_SECRETS} and {@code- * INCLUDE_CREDENTIAL_SECRETS} (or is metalake owner); callers with only {@code USE_SECRETS} get- * those cloud keys via {@code getCredentials} instead.+ * recovered into {@code getSecrets} only when the caller holds {@code USE_SECRETS} and {@code+ * INCLUDE_CREDENTIAL_SECRETS} (or is metalake owner). With only {@code USE_SECRETS} they are+ * omitted from {@code getSecrets}; catalog and fileset {@code getCredentials} likewise soft-filter+ * static providers unless both privileges (or metalake ownership) are present.** <p>Does not include the AWS access-key pair. That pair is a Glue catalog property merged only via* {@link org.apache.gravitino.connector.BaseCatalogPropertiesMetadata}, matching fileset and schemadiff --git a/core/src/main/java/org/apache/gravitino/secret/SecretPropertyOperationDispatcher.java b/core/src/main/java/org/apache/gravitino/secret/SecretPropertyOperationDispatcher.javaindex 2cb1fd0544..54e2de9943 100644--- a/core/src/main/java/org/apache/gravitino/secret/SecretPropertyOperationDispatcher.java+++ b/core/src/main/java/org/apache/gravitino/secret/SecretPropertyOperationDispatcher.java@@ -80,13 +80,27 @@ public class SecretPropertyOperationDispatcher extends OperationDispatcher {/*** Returns plaintext secret properties for the given metadata object.*+ * <p>When {@code includeStaticCredentials} is {@code false}, static credential keys that apply to+ * this object (declared in its {@link PropertiesMetadata} and/or used by an enabled static {@code+ * credential-providers} entry, including providers inferred by the catalog) are omitted. Other+ * secrets remain.+ ** @param identifier The entity name identifier.* @param entityType The entity type.+ * @param includeStaticCredentials whether to keep object-scoped static credential secrets* @return secret plaintext properties; never null*/- public Map<String, String> getSecrets(NameIdentifier identifier, Entity.EntityType entityType) {+ public Map<String, String> getSecrets(+ NameIdentifier identifier, Entity.EntityType entityType, boolean includeStaticCredentials) {RawPropertiesAndMetadata loaded = loadRawPropertiesAndMetadata(identifier, entityType);- return SecretPropertyUtils.buildSecrets(secretManager, loaded.rawProperties, loaded.metadata);+ Map<String, String> secrets =+ SecretPropertyUtils.buildSecrets(secretManager, loaded.rawProperties, loaded.metadata);+ if (!includeStaticCredentials) {+ secrets =+ SecretPropertyUtils.omitStaticCredentialSecrets(+ secrets, loaded.metadata, loaded.propertiesForStaticCredentialOmit);+ }+ return secrets;}/**@@ -108,10 +122,15 @@ public class SecretPropertyOperationDispatcher extends OperationDispatcher {identifier,wrapper -> {wrapper.catalog().checkMetalakeInUse();+ // buildSecrets uses entity raw properties (URNs intact). Omit uses the effective+ // provider list so inferred static providers (e.g. s3-secret-key when+ // credential-providers is absent) are covered even if PropertiesMetadata omits+ // those keys.return new RawPropertiesAndMetadata(wrapper.catalog().entity().getProperties(),resolvePropertiesMetadata(- wrapper, HasPropertyMetadata::catalogPropertiesMetadata));+ wrapper, HasPropertyMetadata::catalogPropertiesMetadata),+ wrapper.catalog().propertiesWithCredentialProviders());},NoSuchCatalogException.class);case SCHEMA:@@ -275,11 +294,26 @@ public class SecretPropertyOperationDispatcher extends OperationDispatcher {private static final class RawPropertiesAndMetadata {private final Map<String, String> rawProperties;private final PropertiesMetadata metadata;+ /**+ * Properties used to resolve static credential keys to omit (effective providers for catalogs).+ */+ private final Map<String, String> propertiesForStaticCredentialOmit;private RawPropertiesAndMetadata(@Nullable Map<String, String> rawProperties, PropertiesMetadata metadata) {+ this(rawProperties, metadata, rawProperties);+ }++ private RawPropertiesAndMetadata(+ @Nullable Map<String, String> rawProperties,+ PropertiesMetadata metadata,+ @Nullable Map<String, String> propertiesForStaticCredentialOmit) {this.rawProperties = rawProperties == null ? Map.of() : rawProperties;this.metadata = metadata;+ this.propertiesForStaticCredentialOmit =+ propertiesForStaticCredentialOmit == null+ ? this.rawProperties+ : propertiesForStaticCredentialOmit;}}}diff --git a/core/src/main/java/org/apache/gravitino/secret/SecretPropertyUtils.java b/core/src/main/java/org/apache/gravitino/secret/SecretPropertyUtils.javaindex a9dc4415f1..480a8d8bc9 100644--- a/core/src/main/java/org/apache/gravitino/secret/SecretPropertyUtils.java+++ b/core/src/main/java/org/apache/gravitino/secret/SecretPropertyUtils.java@@ -22,16 +22,17 @@ import static org.apache.gravitino.secret.SecretConstants.URN_PREFIX;import com.google.common.base.Preconditions;import java.util.HashMap;+import java.util.HashSet;import java.util.List;import java.util.Locale;import java.util.Map;+import java.util.Set;import javax.annotation.Nullable;import org.apache.commons.lang3.StringUtils;import org.apache.gravitino.Config;import org.apache.gravitino.Configs;import org.apache.gravitino.connector.PropertiesMetadata;import org.apache.gravitino.connector.PropertyEntry;-import org.apache.gravitino.storage.CloudStorageCredentialPropertyKeys;/*** Helpers for secret-related entity property handling and request validation.@@ -415,16 +416,49 @@ public final class SecretPropertyUtils {}/**- * Omits cloud access-key pair properties from a plaintext secrets map for {@code USE_SECRETS}- * callers. Delegates to {@link- * CloudStorageCredentialPropertyKeys#omitCloudAccessKeyPairProperties}.+ * Omits static credential properties that apply to this metadata object for {@code USE_SECRETS}+ * callers that lack {@code INCLUDE_CREDENTIAL_SECRETS}.+ *+ * <p>A key is omitted when it is in the static-credential key set and any of: declared in {@code+ * metadata}; used by a static {@code credential-providers} entry on {@code+ * propertiesWithProviders}; or present as a key on {@code propertiesWithProviders} (covers+ * leftover static pairs when providers list only tokens). When {@code metadata} is {@code null},+ * omits the full static-credential key set.+ *+ * <p>For catalogs, pass the effective property map (including inferred {@code+ * credential-providers} from {@code BaseCatalog#propertiesWithCredentialProviders}), not only the+ * raw entity map, so keys for inferred static providers are omitted even when undeclared in+ * {@code metadata}.** @param secrets plaintext secrets- * @return secrets without cloud AK/SK pairs+ * @param metadata properties metadata for the object, or null when unavailable+ * @param propertiesWithProviders properties that carry {@code credential-providers} (explicit or+ * inferred) and/or stored static credential keys, or null+ * @return secrets without object-scoped static credential properties*/- public static Map<String, String> omitCloudAccessKeyPairSecrets(- @Nullable Map<String, String> secrets) {- return CloudStorageCredentialPropertyKeys.omitCloudAccessKeyPairProperties(secrets);+ public static Map<String, String> omitStaticCredentialSecrets(+ @Nullable Map<String, String> secrets,+ @Nullable PropertiesMetadata metadata,+ @Nullable Map<String, String> propertiesWithProviders) {+ return StaticCredentialSecretKeys.omit(+ secrets, resolveStaticCredentialKeysToOmit(metadata, propertiesWithProviders));+ }++ private static Set<String> resolveStaticCredentialKeysToOmit(+ @Nullable PropertiesMetadata metadata,+ @Nullable Map<String, String> propertiesWithProviders) {+ if (metadata == null) {+ return StaticCredentialSecretKeys.allKeys();+ }+ Set<String> keys = new HashSet<>();+ for (String key : StaticCredentialSecretKeys.allKeys()) {+ if (metadata.containsProperty(key)) {+ keys.add(key);+ }+ }+ keys.addAll(StaticCredentialSecretKeys.keysForCredentialProviders(propertiesWithProviders));+ keys.addAll(StaticCredentialSecretKeys.keysPresentInProperties(propertiesWithProviders));+ return keys;}/**diff --git a/core/src/main/java/org/apache/gravitino/secret/StaticCredentialSecretKeys.java b/core/src/main/java/org/apache/gravitino/secret/StaticCredentialSecretKeys.javanew file mode 100644index 0000000000..2e92cea004--- /dev/null+++ b/core/src/main/java/org/apache/gravitino/secret/StaticCredentialSecretKeys.java@@ -0,0 +1,192 @@+/*+ * 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.gravitino.secret;++import com.google.common.collect.ImmutableMap;+import com.google.common.collect.ImmutableSet;+import java.util.HashMap;+import java.util.HashSet;+import java.util.Locale;+import java.util.Map;+import java.util.Set;+import javax.annotation.Nullable;+import org.apache.commons.lang3.StringUtils;+import org.apache.gravitino.catalog.lakehouse.paimon.PaimonConstants;+import org.apache.gravitino.credential.AwsSecretKeyCredential;+import org.apache.gravitino.credential.AzureAccountKeyCredential;+import org.apache.gravitino.credential.COSSecretKeyCredential;+import org.apache.gravitino.credential.CredentialConstants;+import org.apache.gravitino.credential.DlfSecretKeyCredential;+import org.apache.gravitino.credential.JdbcCredential;+import org.apache.gravitino.credential.OSSSecretKeyCredential;+import org.apache.gravitino.credential.S3SecretKeyCredential;+import org.apache.gravitino.storage.AWSProperties;+import org.apache.gravitino.storage.AzureProperties;+import org.apache.gravitino.storage.COSProperties;+import org.apache.gravitino.storage.OSSProperties;+import org.apache.gravitino.storage.S3Properties;++/**+ * Static credential type → property keys for {@code getSecrets} filtering when the caller has+ * {@code USE_SECRETS} but not {@code INCLUDE_CREDENTIAL_SECRETS}. Token providers are absent.+ *+ * <p>Also used by catalog {@code getCredentials} soft-filtering: without {@code+ * INCLUDE_CREDENTIAL_SECRETS}, drop credentials whose type is in this map.+ *+ * <p>Includes Glue AWS, Paimon DLF, JDBC, and cloud storage static keys. GVFS only drops masked+ * {@code properties()} placeholders in {@code BaseGVFSOperations}.+ */+public final class StaticCredentialSecretKeys {++ private static final Map<String, Set<String>> KEYS_BY_CREDENTIAL_TYPE =+ ImmutableMap.<String, Set<String>>builder()+ .put(+ S3SecretKeyCredential.S3_SECRET_KEY_CREDENTIAL_TYPE,+ ImmutableSet.of(+ S3Properties.GRAVITINO_S3_ACCESS_KEY_ID,+ S3Properties.GRAVITINO_S3_SECRET_ACCESS_KEY))+ .put(+ OSSSecretKeyCredential.OSS_SECRET_KEY_CREDENTIAL_TYPE,+ ImmutableSet.of(+ OSSProperties.GRAVITINO_OSS_ACCESS_KEY_ID,+ OSSProperties.GRAVITINO_OSS_ACCESS_KEY_SECRET))+ .put(+ COSSecretKeyCredential.COS_SECRET_KEY_CREDENTIAL_TYPE,+ ImmutableSet.of(+ COSProperties.GRAVITINO_COS_ACCESS_KEY_ID,+ COSProperties.GRAVITINO_COS_ACCESS_KEY_SECRET))+ .put(+ AwsSecretKeyCredential.AWS_SECRET_KEY_CREDENTIAL_TYPE,+ ImmutableSet.of(+ AWSProperties.GRAVITINO_AWS_ACCESS_KEY_ID,+ AWSProperties.GRAVITINO_AWS_SECRET_ACCESS_KEY))+ .put(+ AzureAccountKeyCredential.AZURE_ACCOUNT_KEY_CREDENTIAL_TYPE,+ ImmutableSet.of(AzureProperties.GRAVITINO_AZURE_STORAGE_ACCOUNT_KEY))+ .put(+ DlfSecretKeyCredential.DLF_SECRET_KEY_CREDENTIAL_TYPE,+ ImmutableSet.of(+ PaimonConstants.GRAVITINO_DLF_ACCESS_KEY_ID,+ PaimonConstants.GRAVITINO_DLF_ACCESS_KEY_SECRET,+ PaimonConstants.GRAVITINO_DLF_SECURITY_TOKEN))+ .put(+ JdbcCredential.JDBC_CREDENTIAL_TYPE,+ ImmutableSet.of(+ JdbcCredential.GRAVITINO_JDBC_USER, JdbcCredential.GRAVITINO_JDBC_PASSWORD))+ .build();++ /**+ * Union of all keys in {@link #KEYS_BY_CREDENTIAL_TYPE}, plus {@code azure-client-secret}+ * (catalog Azure AD config; no credential-provider type).+ */+ private static final Set<String> ALL_STATIC_CREDENTIAL_SECRET_KEYS;++ static {+ Set<String> all = new HashSet<>();+ for (Set<String> keys : KEYS_BY_CREDENTIAL_TYPE.values()) {+ all.addAll(keys);+ }+ all.add(AzureProperties.GRAVITINO_AZURE_CLIENT_SECRET);+ ALL_STATIC_CREDENTIAL_SECRET_KEYS = ImmutableSet.copyOf(all);+ }++ private StaticCredentialSecretKeys() {}++ /**+ * Returns whether {@code credentialType} is a known static (long-lived) credential-provider type.+ *+ * @param credentialType credential type string, or null+ * @return true for types in {@link #KEYS_BY_CREDENTIAL_TYPE}+ */+ public static boolean isStaticCredentialType(@Nullable String credentialType) {+ if (credentialType == null || credentialType.isEmpty()) {+ return false;+ }+ return KEYS_BY_CREDENTIAL_TYPE.containsKey(credentialType.toLowerCase(Locale.ROOT));+ }++ /** All static credential secret keys (conservative omit when metadata is unavailable). */+ static Set<String> allKeys() {+ return ALL_STATIC_CREDENTIAL_SECRET_KEYS;+ }++ /**+ * Static credential property keys implied by a comma-separated {@code credential-providers} value+ * on {@code properties}. Token providers are ignored.+ */+ static Set<String> keysForCredentialProviders(@Nullable Map<String, String> properties) {+ if (properties == null || properties.isEmpty()) {+ return ImmutableSet.of();+ }+ String credentialProviders = properties.get(CredentialConstants.CREDENTIAL_PROVIDERS);+ if (StringUtils.isBlank(credentialProviders)) {+ return ImmutableSet.of();+ }+ Set<String> keys = new HashSet<>();+ for (String provider : credentialProviders.split(",")) {+ String type = provider.trim();+ if (type.isEmpty()) {+ continue;+ }+ Set<String> forType = KEYS_BY_CREDENTIAL_TYPE.get(type.toLowerCase(Locale.ROOT));+ if (forType != null) {+ keys.addAll(forType);+ }+ }+ return keys;+ }++ /**+ * Known static credential secret keys that are present as keys on {@code properties}. Covers+ * leftover static pairs when {@code credential-providers} lists only token providers.+ */+ static Set<String> keysPresentInProperties(@Nullable Map<String, String> properties) {+ if (properties == null || properties.isEmpty()) {+ return ImmutableSet.of();+ }+ Set<String> keys = new HashSet<>();+ for (String key : ALL_STATIC_CREDENTIAL_SECRET_KEYS) {+ if (properties.containsKey(key)) {+ keys.add(key);+ }+ }+ return keys;+ }++ /** Returns a copy of {@code secrets} with keys in {@code keysToOmit} removed. */+ static Map<String, String> omit(+ @Nullable Map<String, String> secrets, @Nullable Set<String> keysToOmit) {+ if (secrets == null || secrets.isEmpty()) {+ return ImmutableMap.of();+ }+ Set<String> omit = keysToOmit == null ? ALL_STATIC_CREDENTIAL_SECRET_KEYS : keysToOmit;+ if (omit.isEmpty()) {+ return ImmutableMap.copyOf(secrets);+ }+ Map<String, String> filtered = new HashMap<>();+ for (Map.Entry<String, String> entry : secrets.entrySet()) {+ String key = entry.getKey();+ if (key == null || omit.contains(key)) {+ continue;+ }+ filtered.put(key, entry.getValue());+ }+ return ImmutableMap.copyOf(filtered);+ }+}diff --git a/core/src/test/java/org/apache/gravitino/catalog/TestSchemaOperationDispatcher.java b/core/src/test/java/org/apache/gravitino/catalog/TestSchemaOperationDispatcher.javaindex 2eedb0cc15..1a4b550255 100644--- a/core/src/test/java/org/apache/gravitino/catalog/TestSchemaOperationDispatcher.java+++ b/core/src/test/java/org/apache/gravitino/catalog/TestSchemaOperationDispatcher.java@@ -1048,7 +1048,7 @@ public class TestSchemaOperationDispatcher extends TestOperationDispatcher {Assertions.assertTrue(failure.getMessage().contains("property k2"));Assertions.assertFalse(entityStore.exists(copy, SCHEMA));Assertions.assertThrows(- NoSuchSchemaException.class, () -> secretDispatcher.getSecrets(copy, SCHEMA));+ NoSuchSchemaException.class, () -> secretDispatcher.getSecrets(copy, SCHEMA, true));Assertions.assertTrue(d.dropSchema(copy, false));Assertions.assertEquals("original-secret", secrets.readSecret(originalUrn));Assertions.assertEquals(diff --git a/core/src/test/java/org/apache/gravitino/credential/TestCredentialOperationDispatcher.java b/core/src/test/java/org/apache/gravitino/credential/TestCredentialOperationDispatcher.javaindex 60648b2c14..9f23aef956 100644--- a/core/src/test/java/org/apache/gravitino/credential/TestCredentialOperationDispatcher.java+++ b/core/src/test/java/org/apache/gravitino/credential/TestCredentialOperationDispatcher.java@@ -155,6 +155,65 @@ public class TestCredentialOperationDispatcher extends TestOperationDispatcher {Assertions.assertSame(validCredential, credentials.get(0));}+ @Test+ public void testGetCredentialsDynamicProvidersOnlySkipsStaticProvider() throws Exception {+ String staticType = "static-type";+ String dynamicType = "dynamic-type";++ CredentialProvider staticProvider = mockCredentialProvider(staticType);+ CredentialProvider dynamicProvider =+ Mockito.mock(+ CredentialProvider.class,+ Mockito.withSettings().extraInterfaces(SupportsDynamicCredential.class));+ Mockito.when(dynamicProvider.credentialType()).thenReturn(dynamicType);+ Mockito.when(dynamicProvider.supportsScheme(Mockito.anyString())).thenReturn(true);++ Credential dynamicCredential = Mockito.mock(Credential.class);+ Credential staticCredential = Mockito.mock(Credential.class);++ CatalogCredentialManager credentialManager = Mockito.mock(CatalogCredentialManager.class);+ Mockito.when(credentialManager.getCredentialProvider(staticType))+ .thenReturn(Optional.of(staticProvider));+ Mockito.when(credentialManager.getCredentialProvider(dynamicType))+ .thenReturn(Optional.of(dynamicProvider));+ Mockito.when(+ credentialManager.getCredential(+ Mockito.eq(staticType), Mockito.any(CredentialContext.class)))+ .thenReturn(Optional.of(staticCredential));+ Mockito.when(+ credentialManager.getCredential(+ Mockito.eq(dynamicType), Mockito.any(CredentialContext.class)))+ .thenReturn(Optional.of(dynamicCredential));++ CatalogOperations ops =+ Mockito.mock(+ CatalogOperations.class,+ Mockito.withSettings().extraInterfaces(SupportsPathBasedCredentials.class));+ Mockito.when(+ ((SupportsPathBasedCredentials) ops).getPathContext(Mockito.any(NameIdentifier.class)))+ .thenReturn(+ Arrays.asList(+ new PathContext("s3://bucket/a", staticType),+ new PathContext("s3://bucket/b", dynamicType)));++ BaseCatalog<?> baseCatalog = Mockito.mock(BaseCatalog.class);+ Mockito.when(baseCatalog.catalogCredentialManager()).thenReturn(credentialManager);+ Mockito.when(baseCatalog.ops()).thenReturn(ops);++ CredentialOperationDispatcher dispatcher =+ new CredentialOperationDispatcher(catalogManager, entityStore, idGenerator, secretManager);++ NameIdentifier fileset = NameIdentifier.of(metalake, catalog, "schema", "fileset");+ List<Credential> dynamicOnly =+ dispatcher.getCredentials(baseCatalog, fileset, CredentialPrivilege.READ, true);+ Assertions.assertEquals(1, dynamicOnly.size());+ Assertions.assertSame(dynamicCredential, dynamicOnly.get(0));++ List<Credential> allProviders =+ dispatcher.getCredentials(baseCatalog, fileset, CredentialPrivilege.READ, false);+ Assertions.assertEquals(2, allProviders.size());+ }+private static CredentialProvider mockCredentialProvider(String credentialType) {CredentialProvider provider = Mockito.mock(CredentialProvider.class);Mockito.when(provider.credentialType()).thenReturn(credentialType);diff --git a/core/src/test/java/org/apache/gravitino/secret/TestSecretPropertyOperationDispatcher.java b/core/src/test/java/org/apache/gravitino/secret/TestSecretPropertyOperationDispatcher.javaindex ca9b36197b..f7f8f5e55d 100644--- a/core/src/test/java/org/apache/gravitino/secret/TestSecretPropertyOperationDispatcher.java+++ b/core/src/test/java/org/apache/gravitino/secret/TestSecretPropertyOperationDispatcher.java@@ -18,6 +18,10 @@*/package org.apache.gravitino.secret;+import static org.apache.gravitino.TestBasePropertiesMetadata.TEST_REQUIRED_KEY;+import static org.apache.gravitino.TestCatalog.PROPERTY_KEY1;+import static org.apache.gravitino.TestCatalog.PROPERTY_KEY2;+import static org.apache.gravitino.TestCatalog.PROPERTY_KEY5_PREFIX;import static org.mockito.Mockito.doReturn;import static org.mockito.Mockito.mock;import static org.mockito.Mockito.when;@@ -28,6 +32,7 @@ import java.time.Instant;import java.util.Map;import java.util.function.Supplier;import org.apache.commons.lang3.reflect.FieldUtils;+import org.apache.gravitino.Catalog;import org.apache.gravitino.Config;import org.apache.gravitino.Configs;import org.apache.gravitino.Entity;@@ -51,6 +56,7 @@ import org.apache.gravitino.rel.Representation;import org.apache.gravitino.rel.SQLRepresentation;import org.apache.gravitino.rel.expressions.transforms.Transform;import org.apache.gravitino.rel.types.Types;+import org.apache.gravitino.storage.S3Properties;import org.apache.gravitino.utils.NameIdentifierUtil;import org.junit.jupiter.api.Assertions;import org.junit.jupiter.api.BeforeAll;@@ -103,6 +109,73 @@ public class TestSecretPropertyOperationDispatcher extends TestOperationDispatchNameIdentifier.of(metalake, catalog, SCHEMA), "comment", ImmutableMap.of("k1", "v1"));}+ /**+ * Catalog getSecrets with {@code includeStaticCredentials=false} omits S3 keys inferred from the+ * catalog property map while keeping other secrets.+ */+ @Test+ public void testGetCatalogSecretsOmitsStaticCredentialsWithoutInclude() {+ NameIdentifier catalogIdent = NameIdentifier.of(metalake, "secret_omit_catalog");+ Map<String, String> props =+ ImmutableMap.<String, String>builder()+ .put(PROPERTY_KEY1, "value1")+ .put(PROPERTY_KEY2, "value2")+ .put(PROPERTY_KEY5_PREFIX + "1", "value3")+ .put(S3Properties.GRAVITINO_S3_ACCESS_KEY_ID, "AKIA")+ .put(S3Properties.GRAVITINO_S3_SECRET_ACCESS_KEY, "secret")+ .put("custom-token", "keep-me")+ .build();+ catalogManager.createCatalog(catalogIdent, Catalog.Type.RELATIONAL, "test", "comment", props);+ try {+ Map<String, String> withInclude =+ secretDispatcher.getSecrets(catalogIdent, Entity.EntityType.CATALOG, true);+ Assertions.assertEquals("AKIA", withInclude.get(S3Properties.GRAVITINO_S3_ACCESS_KEY_ID));+ Assertions.assertEquals(+ "secret", withInclude.get(S3Properties.GRAVITINO_S3_SECRET_ACCESS_KEY));+ Assertions.assertEquals("keep-me", withInclude.get("custom-token"));++ Map<String, String> withoutInclude =+ secretDispatcher.getSecrets(catalogIdent, Entity.EntityType.CATALOG, false);+ Assertions.assertFalse(withoutInclude.containsKey(S3Properties.GRAVITINO_S3_ACCESS_KEY_ID));+ Assertions.assertFalse(+ withoutInclude.containsKey(S3Properties.GRAVITINO_S3_SECRET_ACCESS_KEY));+ Assertions.assertEquals("keep-me", withoutInclude.get("custom-token"));+ } finally {+ catalogManager.dropCatalog(catalogIdent, true);+ }+ }++ /**+ * Non-catalog objects omit canonical static credential keys present on their own property map+ * when {@code includeStaticCredentials=false}, without relying on catalog-inferred providers.+ */+ @Test+ public void testGetSchemaSecretsOmitStaticKeysWithoutInclude() {+ NameIdentifier schemaIdent = NameIdentifier.of(metalake, catalog, "secret_omit_schema");+ Map<String, String> staticAndCustom =+ ImmutableMap.of(+ TEST_REQUIRED_KEY,+ "v1",+ S3Properties.GRAVITINO_S3_ACCESS_KEY_ID,+ "AKIA",+ S3Properties.GRAVITINO_S3_SECRET_ACCESS_KEY,+ "secret",+ "custom-token",+ "keep-me");+ schemaOperationDispatcher.createSchema(schemaIdent, "comment", staticAndCustom);++ Map<String, String> withInclude =+ secretDispatcher.getSecrets(schemaIdent, Entity.EntityType.SCHEMA, true);+ Assertions.assertEquals("AKIA", withInclude.get(S3Properties.GRAVITINO_S3_ACCESS_KEY_ID));+ Assertions.assertEquals("keep-me", withInclude.get("custom-token"));++ Map<String, String> withoutInclude =+ secretDispatcher.getSecrets(schemaIdent, Entity.EntityType.SCHEMA, false);+ Assertions.assertFalse(withoutInclude.containsKey(S3Properties.GRAVITINO_S3_ACCESS_KEY_ID));+ Assertions.assertFalse(withoutInclude.containsKey(S3Properties.GRAVITINO_S3_SECRET_ACCESS_KEY));+ Assertions.assertEquals("keep-me", withoutInclude.get("custom-token"));+ }+@Testpublic void testGetSecretsForMetalake() throws IOException {BaseMetalake stored =@@ -121,7 +194,7 @@ public class TestSecretPropertyOperationDispatcher extends TestOperationDispatchentityStore.put(updated, true);Map<String, String> secrets =- secretDispatcher.getSecrets(NameIdentifier.of(metalake), Entity.EntityType.METALAKE);+ secretDispatcher.getSecrets(NameIdentifier.of(metalake), Entity.EntityType.METALAKE, true);Assertions.assertEquals("s3cr3t", secrets.get("custom-token"));Assertions.assertFalse(secrets.containsKey("visible"));}@@ -133,7 +206,8 @@ public class TestSecretPropertyOperationDispatcher extends TestOperationDispatchtableOperationDispatcher.createTable(tableIdent, columns, "comment", SECRET_PROPS, new Transform[0]);- Map<String, String> secrets = secretDispatcher.getSecrets(tableIdent, Entity.EntityType.TABLE);+ Map<String, String> secrets =+ secretDispatcher.getSecrets(tableIdent, Entity.EntityType.TABLE, true);Assertions.assertEquals("s3cr3t", secrets.get("custom-token"));Assertions.assertFalse(secrets.containsKey("visible"));}@@ -143,7 +217,8 @@ public class TestSecretPropertyOperationDispatcher extends TestOperationDispatchNameIdentifier topicIdent = NameIdentifier.of(metalake, catalog, SCHEMA, "secret_topic");topicOperationDispatcher.createTopic(topicIdent, "comment", null, SECRET_PROPS);- Map<String, String> secrets = secretDispatcher.getSecrets(topicIdent, Entity.EntityType.TOPIC);+ Map<String, String> secrets =+ secretDispatcher.getSecrets(topicIdent, Entity.EntityType.TOPIC, true);Assertions.assertEquals("s3cr3t", secrets.get("custom-token"));Assertions.assertFalse(secrets.containsKey("visible"));}@@ -158,7 +233,8 @@ public class TestSecretPropertyOperationDispatcher extends TestOperationDispatchviewOperationDispatcher.createView(viewIdent, "comment", new Column[0], representations, null, null, SECRET_PROPS);- Map<String, String> secrets = secretDispatcher.getSecrets(viewIdent, Entity.EntityType.VIEW);+ Map<String, String> secrets =+ secretDispatcher.getSecrets(viewIdent, Entity.EntityType.VIEW, true);Assertions.assertEquals("s3cr3t", secrets.get("custom-token"));Assertions.assertFalse(secrets.containsKey("visible"));}@@ -169,7 +245,8 @@ public class TestSecretPropertyOperationDispatcher extends TestOperationDispatchNameIdentifierUtil.ofModel(metalake, catalog, SCHEMA, "secret_model");modelOperationDispatcher.registerModel(modelIdent, "comment", SECRET_PROPS);- Map<String, String> secrets = secretDispatcher.getSecrets(modelIdent, Entity.EntityType.MODEL);+ Map<String, String> secrets =+ secretDispatcher.getSecrets(modelIdent, Entity.EntityType.MODEL, true);Assertions.assertEquals("s3cr3t", secrets.get("custom-token"));Assertions.assertFalse(secrets.containsKey("visible"));}diff --git a/core/src/test/java/org/apache/gravitino/secret/TestSecretPropertyUtils.java b/core/src/test/java/org/apache/gravitino/secret/TestSecretPropertyUtils.javaindex 14495e3b2b..006fc57155 100644--- a/core/src/test/java/org/apache/gravitino/secret/TestSecretPropertyUtils.java+++ b/core/src/test/java/org/apache/gravitino/secret/TestSecretPropertyUtils.java@@ -29,6 +29,7 @@ import org.apache.gravitino.Config;import org.apache.gravitino.Configs;import org.apache.gravitino.connector.PropertiesMetadata;import org.apache.gravitino.connector.PropertyEntry;+import org.apache.gravitino.credential.CredentialConstants;import org.apache.gravitino.secret.memory.InMemorySecretsProvider;import org.junit.jupiter.api.AfterEach;import org.junit.jupiter.api.Assertions;@@ -295,6 +296,123 @@ public class TestSecretPropertyUtils {Assertions.assertTrue(SecretPropertyUtils.mergeProperties(null, null).isEmpty());}+ @Test+ void testOmitStaticCredentialSecretsScopedByMetadata() {+ PropertiesMetadata jdbcMetadata =+ () ->+ Map.of(+ "jdbc-user",+ PropertyEntry.stringOptionalPropertyEntry("jdbc-user", "doc", false, null, false),+ "jdbc-password",+ PropertyEntry.stringOptionalPropertyEntry(+ "jdbc-password", "doc", false, null, true));+ PropertiesMetadata hiveMetadata = () -> Map.of();++ Map<String, String> secrets =+ Map.of(+ "jdbc-user",+ "db-user",+ "jdbc-password",+ "db-pass",+ "custom-secret",+ "keep",+ "s3-access-key-id",+ "AKIA");++ Map<String, String> jdbcFiltered =+ SecretPropertyUtils.omitStaticCredentialSecrets(secrets, jdbcMetadata, null);+ Assertions.assertEquals("keep", jdbcFiltered.get("custom-secret"));+ Assertions.assertEquals("AKIA", jdbcFiltered.get("s3-access-key-id"));+ Assertions.assertFalse(jdbcFiltered.containsKey("jdbc-user"));+ Assertions.assertFalse(jdbcFiltered.containsKey("jdbc-password"));++ Map<String, String> hiveFiltered =+ SecretPropertyUtils.omitStaticCredentialSecrets(secrets, hiveMetadata, null);+ Assertions.assertEquals("db-user", hiveFiltered.get("jdbc-user"));+ Assertions.assertEquals("db-pass", hiveFiltered.get("jdbc-password"));+ Assertions.assertEquals("keep", hiveFiltered.get("custom-secret"));+ Assertions.assertEquals("AKIA", hiveFiltered.get("s3-access-key-id"));+ }++ @Test+ void testOmitStaticCredentialSecretsFromCredentialProviders() {+ PropertiesMetadata emptyMetadata = () -> Map.of();+ Map<String, String> secrets =+ Map.of("jdbc-user", "u", "jdbc-password", "p", "custom-secret", "keep");+ Map<String, String> raw =+ Map.of(CredentialConstants.CREDENTIAL_PROVIDERS, "jdbc-user-password,s3-token");++ Map<String, String> filtered =+ SecretPropertyUtils.omitStaticCredentialSecrets(secrets, emptyMetadata, raw);+ Assertions.assertEquals("keep", filtered.get("custom-secret"));+ Assertions.assertFalse(filtered.containsKey("jdbc-user"));+ Assertions.assertFalse(filtered.containsKey("jdbc-password"));+ }++ /** Mixed token + static providers: only static provider keys are omitted. */+ @Test+ void testOmitStaticCredentialSecretsWithMixedTokenAndStaticProviders() {+ PropertiesMetadata emptyMetadata = () -> Map.of();+ Map<String, String> secrets =+ Map.of(+ "s3-access-key-id", "AKIA", "s3-secret-access-key", "secret", "custom-secret", "keep");+ Map<String, String> raw =+ Map.of(CredentialConstants.CREDENTIAL_PROVIDERS, "s3-token,s3-secret-key");++ Map<String, String> filtered =+ SecretPropertyUtils.omitStaticCredentialSecrets(secrets, emptyMetadata, raw);+ Assertions.assertEquals("keep", filtered.get("custom-secret"));+ Assertions.assertFalse(filtered.containsKey("s3-access-key-id"));+ Assertions.assertFalse(filtered.containsKey("s3-secret-access-key"));+ }++ /**+ * When metadata does not declare S3 keys, omit still drops the pair if those keys are present on+ * the property map (inferred providers or leftover static pairs beside a token-only list).+ */+ @Test+ void testOmitStaticCredentialSecretsWhenStaticKeysPresentOnProperties() {+ PropertiesMetadata emptyMetadata = () -> Map.of();+ Map<String, String> secrets =+ Map.of(+ "s3-access-key-id", "AKIA", "s3-secret-access-key", "secret", "custom-secret", "keep");++ Map<String, String> entityRawWithoutProviders =+ Map.of("s3-access-key-id", "AKIA", "s3-secret-access-key", "secret");+ Map<String, String> fromPresence =+ SecretPropertyUtils.omitStaticCredentialSecrets(+ secrets, emptyMetadata, entityRawWithoutProviders);+ Assertions.assertEquals("keep", fromPresence.get("custom-secret"));+ Assertions.assertFalse(fromPresence.containsKey("s3-access-key-id"));+ Assertions.assertFalse(fromPresence.containsKey("s3-secret-access-key"));++ Map<String, String> tokenOnlyWithLeftoverStatic =+ Map.of(+ "s3-access-key-id",+ "AKIA",+ "s3-secret-access-key",+ "secret",+ CredentialConstants.CREDENTIAL_PROVIDERS,+ "s3-token");+ Map<String, String> filtered =+ SecretPropertyUtils.omitStaticCredentialSecrets(+ secrets, emptyMetadata, tokenOnlyWithLeftoverStatic);+ Assertions.assertEquals("keep", filtered.get("custom-secret"));+ Assertions.assertFalse(filtered.containsKey("s3-access-key-id"));+ Assertions.assertFalse(filtered.containsKey("s3-secret-access-key"));+ }++ @Test+ void testIsStaticCredentialType() {+ Assertions.assertTrue(StaticCredentialSecretKeys.isStaticCredentialType("s3-secret-key"));+ Assertions.assertTrue(StaticCredentialSecretKeys.isStaticCredentialType("S3-SECRET-KEY"));+ Assertions.assertTrue(StaticCredentialSecretKeys.isStaticCredentialType("jdbc-user-password"));+ Assertions.assertFalse(StaticCredentialSecretKeys.isStaticCredentialType("s3-token"));+ Assertions.assertFalse(StaticCredentialSecretKeys.isStaticCredentialType("aws-irsa"));+ Assertions.assertFalse(StaticCredentialSecretKeys.isStaticCredentialType(null));+ Assertions.assertFalse(StaticCredentialSecretKeys.isStaticCredentialType(""));+ }+@Testvoid testAssembleWithNullTargetWhenNoSecrets() {try (SecretManager sm = memorySecretManager()) {diff --git a/docs/lakehouse-paimon-catalog.md b/docs/lakehouse-paimon-catalog.mdindex 256fe9d463..754e419899 100644--- a/docs/lakehouse-paimon-catalog.md+++ b/docs/lakehouse-paimon-catalog.md@@ -163,9 +163,9 @@ Refer to [Manage Catalogs and Schemas](./manage-catalogs-and-schemas.md#catalog-Sensitive catalog properties such as `jdbc-password` and DLF credential keys are hidden from the default load catalog response (`jdbc-user` is returned in plaintext). Recover JDBC / DLF credential fields via either path:- `getCredentials` / `JdbcCredential` / `DlfSecretKeyCredential` (requires catalog access plus both `USE_SECRETS` and `INCLUDE_CREDENTIAL_SECRETS`, or metalake ownership)-- `getSecrets` / `GET .../objects/{type}/{fullName}/secrets` with `USE_SECRETS` (DLF cloud access-key pairs also need `INCLUDE_CREDENTIAL_SECRETS`)+- `getSecrets` / `GET .../objects/{type}/{fullName}/secrets` with `USE_SECRETS` (declared JDBC login properties and DLF cloud access-key pairs on that catalog also need `INCLUDE_CREDENTIAL_SECRETS`)-Other non-credential secrets (secret-manager URNs, declared `hidden` properties, undeclared sensitive-named keys) use `getSecrets` only.+Other non-credential secrets (secret-manager URNs, declared `hidden` properties, undeclared sensitive-named keys that are not credential properties for the object) use `getSecrets` only.:::diff --git a/docs/open-api/credentials.yaml b/docs/open-api/credentials.yamlindex 3b11ebda64..aa8e03ffe3 100644--- a/docs/open-api/credentials.yaml+++ b/docs/open-api/credentials.yaml@@ -31,19 +31,22 @@ paths:operationId: getCredentialsdescription: >Retrieves credentials for a catalog or fileset. When authorization is enabled,- catalog credentials require metadata access. Unless every configured provider- explicitly implements SupportsDynamicCredential, the request additionally requires- both USE_SECRETS and INCLUDE_CREDENTIAL_SECRETS, or metalake ownership. Unmarked- providers retain these secret checks, including existing custom providers and- mixed dynamic and unmarked provider configurations. Catalog requests do not provide a- storage path: built-in path-only token providers return no catalog credentials,- so a token-only catalog probe succeeds with an empty credential list.- Static catalog credentials carry the source account's permissions and- are not scoped to individual Gravitino tables. Fileset credentials use- path-based authorization and supply the paths required to generate tokens.+ requests require metadata access (filesets use path-based read/write checks).+ That check alone is enough for SupportsDynamicCredential (token) providers.+ Static providers are included only when the caller also holds USE_SECRETS and+ INCLUDE_CREDENTIAL_SECRETS, or owns the metalake; otherwise only dynamic providers+ are invoked (static credentials omitted with HTTP 200, not 403). Unmarked custom+ providers are treated as static. Catalog requests do not provide a storage path:+ built-in path-only token providers return no catalog credentials, so a token-only+ catalog probe succeeds with an empty credential list. Static credentials carry the+ source account's permissions and are not scoped to individual Gravitino tables or+ fileset paths. Fileset requests supply the paths required to generate path-scoped+ tokens.responses:"200":- description: Returns the list of credential objects associated with specified metadata object.+ description: >+ Returns the credential list (possibly empty). Missing static-secret privileges+ soft-filter to token-only or empty results rather than 403.content:application/vnd.gravitino.v1+json:schema:@@ -54,7 +57,9 @@ paths:"400":$ref: "./openapi.yaml#/components/responses/BadRequestErrorResponse""403":- description: Forbidden - The caller lacks the required credential privileges.+ description: >+ Forbidden - The caller lacks metadata access (for example USE_CATALOG or+ READ_FILESET / WRITE_FILESET), not merely USE_SECRETS / INCLUDE_CREDENTIAL_SECRETS.content:application/vnd.gravitino.v1+json:schema:diff --git a/docs/open-api/secrets.yaml b/docs/open-api/secrets.yamlindex 7adbffecde..088e53282b 100644--- a/docs/open-api/secrets.yaml+++ b/docs/open-api/secrets.yaml@@ -90,10 +90,22 @@ paths:are not returned by this API. Clients must not treat a remaining ****** valueas a usable credential for those keys.+ When authorization is enabled, metadata access is required to reach this endpoint.+ Without USE_SECRETS (and without metalake ownership) the response is HTTP 200 with+ an empty map (not 403). With USE_SECRETS, canonical static credential keys on the+ object (declared in properties metadata, implied by a static credential-providers+ entry, or present under a known static key name such as s3-access-key-id) are+ omitted unless the caller also holds INCLUDE_CREDENTIAL_SECRETS (or is metalake+ owner). Non-canonical aliases and typos are not treated as static credential keys+ for this filter. Catalog filtering uses the effective provider list;+ schema/fileset/other types use that object's own properties only.+Supported types: metalake, catalog, schema, fileset, table, topic, view, model.responses:"200":- description: Returns the secrets map for the specified metadata object.+ description: >+ Returns the secrets map (possibly empty). Lack of USE_SECRETS or+ INCLUDE_CREDENTIAL_SECRETS soft-filters the map rather than returning 403.content:application/vnd.gravitino.v1+json:schema:diff --git a/docs/security/access-control.md b/docs/security/access-control.mdindex 026dd86dea..e4ec0d7da2 100755--- a/docs/security/access-control.md+++ b/docs/security/access-control.md@@ -205,8 +205,8 @@ sets the scope of the grant. Binding a privilege to a type not listed for it is| `REGISTER_MODEL` | Metalake, Catalog, Schema | Register models in any schema in scope || `LINK_MODEL_VERSION` | Metalake, Catalog, Schema, Model | Link versions to any model in scope || `USE_MODEL` | Metalake, Catalog, Schema, Model | Read the metadata of, and download versions of, any model in scope |-| `USE_SECRETS` | Metalake, Catalog, Schema, Table, View, Topic, Fileset, Model | Call `getSecrets` (cloud access-key pairs omitted unless also granted `INCLUDE_CREDENTIAL_SECRETS`); required with `INCLUDE_CREDENTIAL_SECRETS` for static catalog credentials |-| `INCLUDE_CREDENTIAL_SECRETS` | Metalake, Catalog, Schema, Table, View, Topic, Fileset, Model | With `USE_SECRETS`, include cloud access-key pairs in `getSecrets` and static credentials in catalog `getCredentials` |+| `USE_SECRETS` | Metalake, Catalog, Schema, Table, View, Topic, Fileset, Model | Soft-unlock `getSecrets` (empty map without it, not 403); static credential keys still omitted unless also granted `INCLUDE_CREDENTIAL_SECRETS`; with `INCLUDE_CREDENTIAL_SECRETS`, include static providers on catalog/fileset `getCredentials` |+| `INCLUDE_CREDENTIAL_SECRETS` | Metalake, Catalog, Schema, Table, View, Topic, Fileset, Model | With `USE_SECRETS`, include static credential properties in `getSecrets` and static providers on catalog/fileset `getCredentials` (token providers need only metadata access; missing privileges soft-filter, not 403) || `REGISTER_FUNCTION` | Metalake, Catalog, Schema | Register functions in any schema in scope || `EXECUTE_FUNCTION` | Metalake, Catalog, Schema, Function | Read the metadata of, and execute, any function in scope || `MODIFY_FUNCTION` | Metalake, Catalog, Schema, Function | Alter or drop any function in scope |@@ -293,26 +293,15 @@ ownership, the same as altering it, because the caller chooses what the server cTable statistics follow the table itself: reading them takes `SELECT_TABLE` or `MODIFY_TABLE`,writing them takes `MODIFY_TABLE`. Model versions follow the model: `USE_MODEL` to read, owner toalter or delete. Fetching plaintext secrets (`getSecrets`) requires owning the metalake or holding-`USE_SECRETS`. Cloud access-key pairs are included only when the caller is the metalake owner or also-holds `INCLUDE_CREDENTIAL_SECRETS`. Catalog credential vending (`getCredentials`) requires metadata-access. Unless every configured provider explicitly implements `SupportsDynamicCredential`, the-catalog request additionally requires both `USE_SECRETS` and `INCLUDE_CREDENTIAL_SECRETS`, or-metalake ownership. Unmarked providers retain these checks, including existing custom providers-and mixed dynamic and unmarked configurations. Catalog requests do not partially return credentials.-Catalog requests carry no storage path. Built-in path-only token providers therefore return no-catalog credentials, and a token-only catalog probe succeeds with an empty result. Tokens are-generated through the existing path-based fileset and Iceberg REST vending flows, with the-authorized paths and storage privileges. Catalogs with no credentials also return an empty result.-Callers who can load the object but lack `USE_SECRETS` receive an empty `getSecrets` result rather-than a forbidden error.--Credential providers that issue dynamic credentials without returning stored source credentials can-opt into metadata-only catalog access by implementing-`org.apache.gravitino.credential.SupportsDynamicCredential`. These providers must respect the-supplied authorization context. Built-in token providers implement this interface; custom dynamic-providers must explicitly add it to receive the same exemption. Existing providers without the marker-continue to load through the unchanged SPI and retain secret-privilege checks. Provider authorization-happens before credentials are generated, including for mixed-provider catalogs.+`USE_SECRETS`. Canonical static credential keys on that object (and catalog keys implied by+its effective providers) are included only when the caller is the metalake owner or also holds+`INCLUDE_CREDENTIAL_SECRETS`. Typos and non-canonical aliases are not treated as static+credential keys for this filter. Catalog and fileset credential vending (`getCredentials`)+always require metadata access (filesets keep path-based read/write checks). Static providers+also need both `USE_SECRETS` and `INCLUDE_CREDENTIAL_SECRETS`, or metalake ownership; token+providers do not. Without those privileges, the response includes only token credentials+(static ones are omitted). Callers who can load the object but lack `USE_SECRETS` receive an+empty `getSecrets` result rather than a forbidden error.The View row applies to metadata operations through both the native Gravitino REST API and theIceberg REST Catalog when authorization is enabled. Listing first requires access to the schema anddiff --git a/docs/security/credential-vending.md b/docs/security/credential-vending.mdindex dca36c9f8c..a593c91ff1 100755--- a/docs/security/credential-vending.md+++ b/docs/security/credential-vending.md@@ -143,18 +143,31 @@ The inferred provider list is returned as the catalog's `credential-providers` pFour providers have no inference rule and must always be set explicitly: `s3-token`, `oss-token`, `adls-token`, and `aws-irsa`. In particular, setting `s3-role-arn` without `credential-providers` does not enable `s3-token`. The catalog falls back to `s3-secret-key` and vends the static access key instead, which is long-lived and not scoped to the table path. Set `credential-providers` explicitly whenever you want token-based vending.-### Static providers and `getCredentials` privileges+### Catalog and fileset `getCredentials` privileges (token vs static)-Static providers return the configured source account's long-lived credentials. Catalog-level-`getCredentials` requires metadata access plus both `USE_SECRETS` and-`INCLUDE_CREDENTIAL_SECRETS`, or metalake ownership. Grant these privileges only to trusted-connectors/operators: the credentials carry all source-account permissions and do not enforce-Gravitino table-level grants or denies when used directly against the source.+Catalog and fileset `getCredentials` always require metadata access (for filesets, that is the+usual path-based read/write fileset check). Privilege rules then depend on provider kind:-Fileset credential authorization remains path-based. Static fileset credentials may still-have broader source access than the requested path, so prefer short-lived scoped providers-(`s3-token`, `oss-token`, `adls-token`, `gcs-token`, `cos-token`, `aws-irsa`) when available.-Do not grant fileset access backed by unrestricted static accounts to untrusted principals.+| Provider kind | Examples | Privileges |+|---------------|----------|------------|+| **Token** (short-lived / scoped) | `s3-token`, `oss-token`, `cos-token`, `adls-token`, `gcs-token`, `aws-irsa` | Metadata access is enough |+| **Static** (long-lived account) | `s3-secret-key`, `oss-secret-key`, `cos-secret-key`, `azure-account-key`, `aws-secret-key`, `dlf-secret-key`, `jdbc-user-password` | Also need `USE_SECRETS` and `INCLUDE_CREDENTIAL_SECRETS`, or metalake ownership |++When the caller lacks the static privileges, the response contains **only** token credentials+(possibly none). With both privileges (or metalake ownership), token and static credentials are+returned together. The same soft-filter applies to catalog and fileset requests.++Catalog `getCredentials` has no storage path. Path-scoped token providers such as `s3-token`+need a fileset or table location to mint a short-lived credential, so a catalog request with+`credential-providers` like `s3-token,s3-secret-key` typically returns only the static key even+when the caller holds both privileges. Callers that need a path-scoped token should use the+fileset credential API or the Iceberg REST credential endpoint instead.++Grant static privileges only to trusted connectors/operators: static credentials carry all+source-account permissions and do not enforce Gravitino table-level grants or denies when used+directly against the source. Prefer short-lived scoped providers for filesets when available —+even with static privileges, a static account may still have broader source access than the+requested path.## S3@@ -502,7 +515,7 @@ Bundle jars on Maven Central:## Upgrading From a Release Earlier Than 1.3.0-Sensitive catalog properties such as `s3-access-key-id`, `s3-secret-access-key`, `jdbc-password`, `aws-access-key-id` / `aws-secret-access-key` (Glue), and `dlf-access-key-id` / `dlf-access-key-secret` / `dlf-security-token` (Paimon DLF) are masked or excluded from the default `GET /api/metalakes/{metalake}/catalogs/{catalog}` response (`jdbc-user` and `azure-storage-account-name` are returned in plaintext when not hidden). Plaintext secrets are available via `getSecrets` when the caller holds `USE_SECRETS` (or is metalake owner); cloud access-key pairs are included only with `INCLUDE_CREDENTIAL_SECRETS` (or metalake owner). Connectors use both `USE_SECRETS` and `INCLUDE_CREDENTIAL_SECRETS` (or metalake ownership) with catalog-level `getCredentials` / `GET .../credentials` to recover S3/OSS/COS/Azure/JDBC cloud keys, as well as Glue AWS API keys (`AwsSecretKeyCredential`) and Paimon DLF pairs (`DlfSecretKeyCredential`). Vended-only fields such as `s3-session-token` are not catalog properties. Clients written against earlier releases that read those properties directly from the default load lose access to them.+Sensitive catalog properties such as `s3-access-key-id`, `s3-secret-access-key`, `jdbc-password`, `aws-access-key-id` / `aws-secret-access-key` (Glue), and `dlf-access-key-id` / `dlf-access-key-secret` / `dlf-security-token` (Paimon DLF) are masked or excluded from the default `GET /api/metalakes/{metalake}/catalogs/{catalog}` response (`jdbc-user` and `azure-storage-account-name` are returned in plaintext when not hidden). Plaintext non-static secrets are available via `getSecrets` when the caller holds `USE_SECRETS` (or is metalake owner). Static credential properties that apply to the metadata object — keys declared in that object's properties metadata, used by an enabled static `credential-providers` entry (`jdbc-user-password`, `s3-secret-key`, and similar), **or present on the object's own property map under a canonical static-credential key name** — are included in `getSecrets` only with `INCLUDE_CREDENTIAL_SECRETS` (or metalake owner). Catalog omit uses the effective provider list (including inferred providers). Schema, fileset, and other child objects are filtered from **their own** properties only; they do not inherit the parent catalog's inferred provider list. Only **canonical** key names (for example `s3-access-key-id`, not typos or aliases) participate in static omit. Other sensitive-named custom secrets remain visible with `USE_SECRETS` alone. Connectors use catalog-level `getCredentials` / `GET .../credentials` for vending. Static credentials (S3/OSS/COS/Azure/JDBC, Glue AWS API keys, Paimon DLF) need both `USE_SECRETS` and `INCLUDE_CREDENTIAL_SECRETS` (or metalake ownership); short-lived token providers need only metadata access. Vended-only fields such as `s3-session-token` are not catalog properties. Clients written against earlier releases that read those properties directly from the default load lose access to them.For a zero-downtime migration, set the following in `gravitino.conf`:@@ -513,16 +526,18 @@ gravitino.catalog.credential.backfillToProperties = trueThe Gravitino server then re-includes the hidden properties in its catalog GET responses. Turn it off once all clients use the Gravitino credential endpoint, since it exposes credentials in plaintext.-### Catalog credential access--With authorization enabled, catalog-level credential vending requires both `USE_SECRETS`-and `INCLUDE_CREDENTIAL_SECRETS`, or metalake ownership, in addition to metadata access.-`USE_CATALOG` alone does not allow retrieving the source account. Engine users that need-catalog credentials must receive these privileges explicitly. Catalog credentials are-unscoped: they carry the source account's privileges, including access beyond a single-Gravitino table. Fileset path-based credential authorization is unchanged. GVFS skips an optional catalog-credential lookup when it is forbidden, then uses the fileset credential endpoint; denial at-that fileset endpoint still prevents access.+### Catalog and fileset credential access++With authorization enabled, catalog and fileset credential vending always require metadata+access (for filesets, the usual path-based read/write fileset check). **Token** providers+(short-lived scoped credentials) need only that metadata access. **Static** providers are+included only with both `USE_SECRETS` and `INCLUDE_CREDENTIAL_SECRETS`, or metalake ownership+— without them the response is still `200` with token-only or empty credentials (soft-filter,+not `403`). Engine users that need static credentials must receive the secrets privileges+explicitly. Static credentials are unscoped: they carry the source account's privileges,+including access beyond a single Gravitino table or fileset path. GVFS skips an optional+catalog credential lookup when metadata access is denied, then uses the fileset credential+endpoint; denial at that fileset endpoint still prevents access.For relational JDBC catalogs, `jdbc-url` must not contain passwords, tokens, or inline userinformation. Move login credentials to `jdbc-user` and `jdbc-password` (or secret references)diff --git a/lance/lance-common/src/main/java/org/apache/gravitino/lance/common/ops/gravitino/GravitinoLanceNamespaceWrapper.java b/lance/lance-common/src/main/java/org/apache/gravitino/lance/common/ops/gravitino/GravitinoLanceNamespaceWrapper.javaindex b36ac200ef..899e2443d9 100644--- a/lance/lance-common/src/main/java/org/apache/gravitino/lance/common/ops/gravitino/GravitinoLanceNamespaceWrapper.java+++ b/lance/lance-common/src/main/java/org/apache/gravitino/lance/common/ops/gravitino/GravitinoLanceNamespaceWrapper.java@@ -144,19 +144,32 @@ public class GravitinoLanceNamespaceWrapper extends NamespaceWrapper {return props;}+ /**+ * Loads catalog secrets for in-process Lance storage config. Passes {@code true} for {@code+ * includeStaticCredentials}: this is a server-side operational path that must merge the full+ * secret map (including static credential keys) into properties so Lance can reach object+ * storage. Caller privilege filtering for static credentials belongs only on the REST {@code+ * getSecrets} boundary, not here. Lance does not use catalog {@code getCredentials} / credential+ * vending.+ */private Map<String, String> catalogSecrets(String catalogName) {SecretPropertyOperationDispatcher dispatcher = secretDispatcher();if (dispatcher != null) {return dispatcher.getSecrets(- NameIdentifierUtil.ofCatalog(metalakeName, catalogName), Entity.EntityType.CATALOG);+ NameIdentifierUtil.ofCatalog(metalakeName, catalogName), Entity.EntityType.CATALOG, true);}return loadCatalog(catalogName).supportsSecrets().getSecrets();}+ /**+ * Loads schema secrets for in-process Lance storage config. Same rationale as {@link+ * #catalogSecrets(String)}: always include static credentials for operational merge.+ */private Map<String, String> schemaSecrets(String catalogName, String schemaName) {SecretPropertyOperationDispatcher dispatcher = secretDispatcher();if (dispatcher != null) {- return dispatcher.getSecrets(schemaIdent(catalogName, schemaName), Entity.EntityType.SCHEMA);+ return dispatcher.getSecrets(+ schemaIdent(catalogName, schemaName), Entity.EntityType.SCHEMA, true);}return loadSchema(loadCatalog(catalogName), schemaName).supportsSecrets().getSecrets();}diff --git a/lance/lance-common/src/test/java/org/apache/gravitino/lance/common/ops/gravitino/TestGravitinoLanceNamespaceWrapper.java b/lance/lance-common/src/test/java/org/apache/gravitino/lance/common/ops/gravitino/TestGravitinoLanceNamespaceWrapper.javaindex 0b1eaec04c..39bbc68650 100644--- a/lance/lance-common/src/test/java/org/apache/gravitino/lance/common/ops/gravitino/TestGravitinoLanceNamespaceWrapper.java+++ b/lance/lance-common/src/test/java/org/apache/gravitino/lance/common/ops/gravitino/TestGravitinoLanceNamespaceWrapper.java@@ -394,7 +394,9 @@ public class TestGravitinoLanceNamespaceWrapper {new SecretPropertyOperationDispatcher(null, null, null, null) {@Overridepublic Map<String, String> getSecrets(- NameIdentifier identifier, Entity.EntityType entityType) {+ NameIdentifier identifier,+ Entity.EntityType entityType,+ boolean includeStaticCredentials) {if (catalogIdent.equals(identifier) && entityType == Entity.EntityType.CATALOG) {return Map.of("jdbc-password", "from-dispatcher");}diff --git a/server-common/src/main/java/org/apache/gravitino/server/authorization/expression/AuthorizationExpressionConstants.java b/server-common/src/main/java/org/apache/gravitino/server/authorization/expression/AuthorizationExpressionConstants.javaindex a2313e9486..d81880ae89 100644--- a/server-common/src/main/java/org/apache/gravitino/server/authorization/expression/AuthorizationExpressionConstants.java+++ b/server-common/src/main/java/org/apache/gravitino/server/authorization/expression/AuthorizationExpressionConstants.java@@ -306,7 +306,10 @@ public class AuthorizationExpressionConstants {ANY_INCLUDE_CREDENTIAL_SECRETS""";- /** Both secret privileges, or metalake ownership, required for static catalog credentials. */+ /**+ * Soft check: both secret privileges (or metalake ownership) to include static catalog/fileset+ * credentials; without them static providers are omitted rather than forbidden.+ */public static final String CATALOG_STATIC_CREDENTIALS_AUTHORIZATION_EXPRESSION ="("+ FILTER_USE_SECRET_AUTHORIZATION_EXPRESSIONdiff --git a/server/src/main/java/org/apache/gravitino/server/web/rest/MetadataObjectCredentialOperations.java b/server/src/main/java/org/apache/gravitino/server/web/rest/MetadataObjectCredentialOperations.javaindex ca413172d3..90d1081da5 100644--- a/server/src/main/java/org/apache/gravitino/server/web/rest/MetadataObjectCredentialOperations.java+++ b/server/src/main/java/org/apache/gravitino/server/web/rest/MetadataObjectCredentialOperations.java@@ -22,6 +22,7 @@ package org.apache.gravitino.server.web.rest;import com.codahale.metrics.annotation.ResponseMetered;import com.codahale.metrics.annotation.Timed;import com.google.common.collect.ImmutableSet;+import java.util.Collections;import java.util.List;import java.util.Locale;import java.util.Map;@@ -51,8 +52,6 @@ import org.apache.gravitino.server.authorization.annotations.AuthorizationExpresimport org.apache.gravitino.server.authorization.annotations.AuthorizationFullName;import org.apache.gravitino.server.authorization.annotations.AuthorizationMetadata;import org.apache.gravitino.server.authorization.annotations.AuthorizationObjectType;-import org.apache.gravitino.server.authorization.annotations.AuthorizationRequest;-import org.apache.gravitino.server.authorization.annotations.ExpressionCondition;import org.apache.gravitino.server.authorization.expression.AuthorizationExpressionConstants;import org.apache.gravitino.server.web.Utils;import org.apache.gravitino.utils.MetadataObjectUtil;@@ -83,18 +82,11 @@ public class MetadataObjectCredentialOperations {@Produces("application/vnd.gravitino.v1+json")@Timed(name = "get-credentials." + MetricNames.HTTP_PROCESS_DURATION, absolute = true)@ResponseMetered(name = "get-credentials", absolute = true)- @AuthorizationExpression(- expression = AuthorizationExpressionConstants.CAN_ACCESS_METADATA,- secondaryExpression =- AuthorizationExpressionConstants.CATALOG_STATIC_CREDENTIALS_AUTHORIZATION_EXPRESSION,- secondaryExpressionCondition = ExpressionCondition.CATALOG_CREDENTIALS)+ @AuthorizationExpression(expression = AuthorizationExpressionConstants.CAN_ACCESS_METADATA)public Response getCredentials(@PathParam("metalake") @AuthorizationMetadata(type = Entity.EntityType.METALAKE)String metalake,- @PathParam("type")- @AuthorizationObjectType- @AuthorizationRequest(type = AuthorizationRequest.RequestType.GET_CREDENTIALS)- String type,+ @PathParam("type") @AuthorizationObjectType String type,@PathParam("fullName") @AuthorizationFullName String fullName) {LOG.info("Received get credentials request for object type: {}, full name: {} under metalake: {}",@@ -117,6 +109,7 @@ public class MetadataObjectCredentialOperations {NameIdentifier identifier = MetadataObjectUtil.toEntityIdent(metalake, object);Entity.EntityType entityType = MetadataObjectUtil.toEntityType(object);+Map<String, String> filteredFilesetHeaders =Utils.filterFilesetCredentialHeaders(httpRequest);// set the fileset info into the thread local context@@ -135,9 +128,17 @@ public class MetadataObjectCredentialOperations {.FILTER_WRITE_FILESET_AUTHORIZATION_EXPRESSION)? CredentialPrivilege.WRITE: CredentialPrivilege.READ;+ // Catalog and fileset requests without static-secret privileges only invoke+ // SupportsDynamicCredential providers so unmarked custom providers cannot return+ // stored keys to metadata-only callers.+ boolean dynamicProvidersOnly = !canIncludeStaticCredentials(identifier, entityType);List<Credential> credentials =- credentialOperationDispatcher.getCredentials(identifier, privilege);+ credentialOperationDispatcher.getCredentials(+ identifier, privilege, dynamicProvidersOnly);if (credentials == null) {+ credentials = Collections.emptyList();+ }+ if (credentials.isEmpty()) {return Utils.ok(new CredentialResponse(new CredentialDTO[0]));}return Utils.ok(@@ -152,6 +153,23 @@ public class MetadataObjectCredentialOperations {}}+ /**+ * Returns whether the caller may receive static credentials ({@code USE_SECRETS} and {@code+ * INCLUDE_CREDENTIAL_SECRETS}, or metalake ownership).+ */+ private static boolean canIncludeStaticCredentials(+ NameIdentifier identifier, Entity.EntityType entityType) {+ return MetadataAuthzHelper.checkAccess(+ identifier,+ entityType,+ AuthorizationExpressionConstants.FILTER_USE_SECRET_AUTHORIZATION_EXPRESSION)+ && MetadataAuthzHelper.checkAccess(+ identifier,+ entityType,+ AuthorizationExpressionConstants+ .FILTER_INCLUDE_CREDENTIAL_SECRETS_AUTHORIZATION_EXPRESSION);+ }+private static boolean supportsCredentialOperations(MetadataObject metadataObject) {return supportsCredentialMetadataTypes.contains(metadataObject.type());}diff --git a/server/src/main/java/org/apache/gravitino/server/web/rest/MetadataObjectSecretOperations.java b/server/src/main/java/org/apache/gravitino/server/web/rest/MetadataObjectSecretOperations.javaindex 45689d3739..bc8f521be1 100644--- a/server/src/main/java/org/apache/gravitino/server/web/rest/MetadataObjectSecretOperations.java+++ b/server/src/main/java/org/apache/gravitino/server/web/rest/MetadataObjectSecretOperations.java@@ -41,7 +41,6 @@ import org.apache.gravitino.NameIdentifier;import org.apache.gravitino.dto.responses.SecretsResponse;import org.apache.gravitino.metrics.MetricNames;import org.apache.gravitino.secret.SecretPropertyOperationDispatcher;-import org.apache.gravitino.secret.SecretPropertyUtils;import org.apache.gravitino.server.authorization.MetadataAuthzHelper;import org.apache.gravitino.server.authorization.annotations.AuthorizationExpression;import org.apache.gravitino.server.authorization.annotations.AuthorizationFullName;@@ -125,10 +124,8 @@ public class MetadataObjectSecretOperations {AuthorizationExpressionConstants.FILTER_INCLUDE_CREDENTIAL_SECRETS_AUTHORIZATION_EXPRESSION);Map<String, String> secrets =- secretPropertyOperationDispatcher.getSecrets(identifier, entityType);- if (!canIncludeCredentialSecrets) {- secrets = SecretPropertyUtils.omitCloudAccessKeyPairSecrets(secrets);- }+ secretPropertyOperationDispatcher.getSecrets(+ identifier, entityType, canIncludeCredentialSecrets);return Utils.ok(new SecretsResponse(secrets));});} catch (Exception e) {diff --git a/server/src/test/java/org/apache/gravitino/server/web/filter/TestGravitinoInterceptionService.java b/server/src/test/java/org/apache/gravitino/server/web/filter/TestGravitinoInterceptionService.javaindex 9c43c2550a..9c4e0fc406 100644--- a/server/src/test/java/org/apache/gravitino/server/web/filter/TestGravitinoInterceptionService.java+++ b/server/src/test/java/org/apache/gravitino/server/web/filter/TestGravitinoInterceptionService.java@@ -23,13 +23,11 @@ import static org.apache.gravitino.server.authorization.expression.Authorizationimport static org.apache.gravitino.server.authorization.expression.AuthorizationExpressionConstants.TEST_CATALOG_CONNECTION_WITH_CHANGES_AUTHORIZATION_EXPRESSION;import static org.junit.jupiter.api.Assertions.assertEquals;import static org.mockito.ArgumentMatchers.any;-import static org.mockito.Mockito.atLeastOnce;import static org.mockito.Mockito.doThrow;import static org.mockito.Mockito.mock;import static org.mockito.Mockito.mockStatic;import static org.mockito.Mockito.never;import static org.mockito.Mockito.spy;-import static org.mockito.Mockito.times;import static org.mockito.Mockito.verify;import static org.mockito.Mockito.when;@@ -89,7 +87,6 @@ import org.apache.gravitino.dto.requests.TagsAssociateRequest;import org.apache.gravitino.dto.responses.ErrorConstants;import org.apache.gravitino.dto.responses.ErrorResponse;import org.apache.gravitino.exceptions.ForbiddenException;-import org.apache.gravitino.exceptions.NoSuchCatalogException;import org.apache.gravitino.exceptions.NoSuchMetalakeException;import org.apache.gravitino.exceptions.NoSuchTableException;import org.apache.gravitino.exceptions.NoSuchViewException;@@ -114,7 +111,6 @@ import org.apache.gravitino.server.authorization.annotations.AuthorizationFullNaimport org.apache.gravitino.server.authorization.annotations.AuthorizationMetadata;import org.apache.gravitino.server.authorization.annotations.AuthorizationObjectType;import org.apache.gravitino.server.authorization.annotations.AuthorizationRequest;-import org.apache.gravitino.server.authorization.expression.AuthorizationExpressionConstants;import org.apache.gravitino.server.web.ServerHealth;import org.apache.gravitino.server.web.Utils;import org.apache.gravitino.server.web.filter.authorization.AuthorizationExecutor;@@ -219,20 +215,22 @@ public class TestGravitinoInterceptionService {}/**- * Checks that a catalog containing any static provider requires both secret privileges.+ * Catalog {@code getCredentials} interception only requires metadata access. Static vs token+ * filtering is applied inside the REST method (soft filter), not as a secondary 403 gate.** @param providers the configured providers- * @param useSecrets whether the caller may use secrets- * @param includeSecrets whether the caller may receive static credential secrets+ * @param useSecrets whether the caller may use secrets (ignored at interception)+ * @param includeSecrets whether the caller may receive static credential secrets (ignored here)*/@ParameterizedTest@CsvSource({"custom-stored,false,false", "custom-stored,false,true","custom-stored,true,false", "custom-stored,true,true","'custom-session,custom-stored',false,false", "'custom-session,custom-stored',false,true",- "'custom-session,custom-stored',true,false", "'custom-session,custom-stored',true,true"+ "'custom-session,custom-stored',true,false", "'custom-session,custom-stored',true,true",+ "'',false,false", "custom-session,false,false"})- public void testCatalogCredentialExecutor(+ public void testCatalogCredentialInterceptionAllowsMetadataAccess(String providers, boolean useSecrets, boolean includeSecrets) throws Throwable {MethodInvocation invocation = credentialInvocation("catalog");GravitinoAuthorizer authorizer = credentialAuthorizer(useSecrets, includeSecrets);@@ -240,49 +238,17 @@ public class TestGravitinoInterceptionService {try (Response response =invokeWithAuthorizer(authorizer, mock(EventBus.class), invocation, credentialCatalogManager(providers))) {- assertEquals(useSecrets && includeSecrets ? 200 : 403, response.getStatus());- }- verify(invocation, times(useSecrets && includeSecrets ? 1 : 0)).proceed();- ArgumentCaptor<AuthorizationRequestContext> contexts =- ArgumentCaptor.forClass(AuthorizationRequestContext.class);- verify(authorizer, atLeastOnce()).authorize(any(), any(), any(), any(), contexts.capture());- for (AuthorizationRequestContext context : contexts.getAllValues()) {- Assertions.assertSame(contexts.getValue(), context);- }- }-- /**- * Checks that dynamic-only and empty catalogs retain metadata-only access.- *- * @param providers the configured providers- */- @ParameterizedTest- @ValueSource(strings = {"", "custom-session"})- public void testCatalogProbeWithoutStaticProviders(String providers) throws Throwable {- MethodInvocation invocation = credentialInvocation("catalog");- when(invocation.proceed()).thenReturn(Utils.ok("ok"));- try (Response response =- invokeWithAuthorizer(- credentialAuthorizer(false, false),- mock(EventBus.class),- invocation,- credentialCatalogManager(providers))) {assertEquals(200, response.getStatus());- verify(invocation).proceed();}+ verify(invocation).proceed();}/**- * Checks that a custom provider loaded through the unchanged SPI retains secret protection.- *- * @param useSecrets whether the caller may use secrets- * @param includeSecrets whether the caller may receive credential secrets- * @throws Throwable if the intercepted invocation fails unexpectedly+ * Legacy static providers still load through the SPI; interception lets metadata access through+ * so the REST soft filter can omit static credentials without forbidding the call.*/- @ParameterizedTest- @CsvSource({"false,false", "false,true", "true,false", "true,true"})- public void testLegacyStaticProviderRequiresBothSecretPrivileges(- boolean useSecrets, boolean includeSecrets) throws Throwable {+ @Test+ public void testLegacyStaticProviderProceedsWithMetadataAccess() throws Throwable {Map<String, String> properties =Map.of("credential-providers",@@ -316,40 +282,36 @@ public class TestGravitinoInterceptionService {Assertions.assertEquals("legacy-password", credential.jdbcPassword());return Utils.ok("ok");});- boolean authorized = useSecrets && includeSecrets;try (Response response =invokeWithAuthorizer(- credentialAuthorizer(useSecrets, includeSecrets),+ credentialAuthorizer(false, false),mock(EventBus.class),invocation,credentialCatalogManager(credentials))) {- assertEquals(authorized ? 200 : 403, response.getStatus());+ assertEquals(200, response.getStatus());}- verify(invocation, times(authorized ? 1 : 0)).proceed();- verify(credentials, times(authorized ? 1 : 0)).getCredential(any(), any());+ verify(invocation).proceed();+ verify(credentials).getCredential(any(), any());}}- /** Checks standard denial and audit handling for static-only credential requests. */+ /**+ * Static catalog credentials are not denied at the interception layer without secret privileges.+ */@Test- public void testStaticCredentialsDeniedBeforeInvocation() throws Throwable {+ public void testStaticCredentialsNotDeniedBeforeInvocationWithoutSecretPrivileges()+ throws Throwable {MethodInvocation invocation = credentialInvocation("catalog");- EventBus eventBus = mock(EventBus.class);+ when(invocation.proceed()).thenReturn(Utils.ok("ok"));try (Response response =invokeWithAuthorizer(credentialAuthorizer(false, false),- eventBus,+ mock(EventBus.class),invocation,credentialCatalogManager("custom-stored"))) {- assertEquals(403, response.getStatus());- verify(invocation, never()).proceed();+ assertEquals(200, response.getStatus());+ verify(invocation).proceed();}- ArgumentCaptor<AuthorizationDenialFailureEvent> denial =- ArgumentCaptor.forClass(AuthorizationDenialFailureEvent.class);- verify(eventBus).dispatchEvent(denial.capture());- assertEquals(- AuthorizationExpressionConstants.CATALOG_STATIC_CREDENTIALS_AUTHORIZATION_EXPRESSION,- denial.getValue().expression());}/** Checks that metalake ownership remains sufficient for static credentials. */@@ -372,30 +334,6 @@ public class TestGravitinoInterceptionService {verify(manager, never()).doWithCatalog(any(), any());}- /**- * Checks existing deny policies for the secondary secret privilege expression.- *- * @param privilege the denied secret privilege- */- @ParameterizedTest- @ValueSource(strings = {"USE_SECRETS", "INCLUDE_CREDENTIAL_SECRETS"})- public void testStaticCredentialDenyPolicy(String privilege) throws Throwable {- GravitinoAuthorizer authorizer = credentialAuthorizer(true, true);- when(authorizer.deny(- any(), any(), any(), ArgumentMatchers.eq(Privilege.Name.valueOf(privilege)), any()))- .thenReturn(true);- MethodInvocation invocation = credentialInvocation("catalog");- try (Response response =- invokeWithAuthorizer(- authorizer,- mock(EventBus.class),- invocation,- credentialCatalogManager("custom-stored"))) {- assertEquals(403, response.getStatus());- verify(invocation, never()).proceed();- }- }-/*** Checks that filesets and operation errors retain their existing behavior.*@@ -428,21 +366,6 @@ public class TestGravitinoInterceptionService {}}- /** Checks that a catalog disappearing during authorization is still reported as not found. */- @Test- public void testMissingCredentialCatalogReturnsNotFound() throws Throwable {- CatalogManager manager = mock(CatalogManager.class);- when(manager.doWithCatalog(any(), any()))- .thenThrow(new NoSuchCatalogException("Catalog missing"));- MethodInvocation invocation = credentialInvocation("catalog");- try (Response response =- invokeWithAuthorizer(- credentialAuthorizer(false, false), mock(EventBus.class), invocation, manager)) {- assertEquals(404, response.getStatus());- verify(invocation, never()).proceed();- }- }-@ParameterizedTest@ValueSource(strings = {"table", "view"})public void testDeniedSourceLookupDoesNotReachDispatcher(String type) throws Throwable {diff --git a/server/src/test/java/org/apache/gravitino/server/web/rest/TestMetadataObjectCredentialOperations.java b/server/src/test/java/org/apache/gravitino/server/web/rest/TestMetadataObjectCredentialOperations.javaindex cc66978266..db47ea6399 100644--- a/server/src/test/java/org/apache/gravitino/server/web/rest/TestMetadataObjectCredentialOperations.java+++ b/server/src/test/java/org/apache/gravitino/server/web/rest/TestMetadataObjectCredentialOperations.java@@ -19,30 +19,43 @@package org.apache.gravitino.server.web.rest;import static org.mockito.ArgumentMatchers.any;+import static org.mockito.ArgumentMatchers.anyBoolean;+import static org.mockito.ArgumentMatchers.eq;import static org.mockito.Mockito.mock;+import static org.mockito.Mockito.mockStatic;+import static org.mockito.Mockito.verify;import static org.mockito.Mockito.when;import java.io.IOException;import java.util.Arrays;+import java.util.Collections;import javax.servlet.http.HttpServletRequest;import javax.ws.rs.core.Application;import javax.ws.rs.core.MediaType;import javax.ws.rs.core.Response;+import org.apache.commons.lang3.reflect.FieldUtils;+import org.apache.gravitino.Entity;import org.apache.gravitino.MetadataObject;import org.apache.gravitino.MetadataObjects;+import org.apache.gravitino.NameIdentifier;import org.apache.gravitino.credential.Credential;import org.apache.gravitino.credential.CredentialOperationDispatcher;+import org.apache.gravitino.credential.CredentialPrivilege;import org.apache.gravitino.credential.S3SecretKeyCredential;+import org.apache.gravitino.credential.S3TokenCredential;import org.apache.gravitino.dto.responses.CredentialResponse;import org.apache.gravitino.dto.responses.ErrorResponse;import org.apache.gravitino.dto.util.DTOConverters;import org.apache.gravitino.rest.RESTUtils;+import org.apache.gravitino.server.authorization.MetadataAuthzHelper;+import org.apache.gravitino.server.authorization.expression.AuthorizationExpressionConstants;import org.glassfish.jersey.internal.inject.AbstractBinder;import org.glassfish.jersey.server.ResourceConfig;import org.glassfish.jersey.test.JerseyTest;import org.glassfish.jersey.test.TestProperties;import org.junit.jupiter.api.Assertions;import org.junit.jupiter.api.Test;+import org.mockito.MockedStatic;public class TestMetadataObjectCredentialOperations extends JerseyTest {@@ -84,6 +97,155 @@ public class TestMetadataObjectCredentialOperations extends JerseyTest {return resourceConfig;}+ /**+ * Without USE+INCLUDE, catalog and fileset requests invoke only dynamic providers ({@code+ * dynamicProvidersOnly=true}); static providers are never called.+ */+ @Test+ public void testUsesDynamicProvidersOnlyWithoutIncludePrivilege() throws Exception {+ S3TokenCredential token =+ new S3TokenCredential("ak", "sk", "session-token", System.currentTimeMillis() + 60_000);+ for (boolean useSecrets : new boolean[] {false, true}) {+ for (boolean includeCredentials : new boolean[] {false, true}) {+ boolean canInclude = useSecrets && includeCredentials;+ CredentialOperationDispatcher dispatcher = mock(CredentialOperationDispatcher.class);+ when(dispatcher.getCredentials(any(), any(), anyBoolean()))+ .thenAnswer(+ invocation -> {+ boolean dynamicOnly = invocation.getArgument(2);+ if (dynamicOnly) {+ return Collections.singletonList(token);+ }+ return Arrays.asList(new S3SecretKeyCredential("ak", "sk"), token);+ });+ MetadataObjectCredentialOperations operations =+ new MetadataObjectCredentialOperations(dispatcher);+ FieldUtils.writeField(operations, "httpRequest", mock(HttpServletRequest.class), true);+ try (MockedStatic<MetadataAuthzHelper> auth = mockStatic(MetadataAuthzHelper.class)) {+ stubSecretPrivilegeChecks(auth, useSecrets, includeCredentials);+ try (Response response = operations.getCredentials(metalake, "catalog", "catalog")) {+ Assertions.assertEquals(200, response.getStatus());+ CredentialResponse body = (CredentialResponse) response.getEntity();+ if (canInclude) {+ Assertions.assertEquals(2, body.getCredentials().length);+ } else {+ Assertions.assertEquals(1, body.getCredentials().length);+ Assertions.assertEquals(+ S3TokenCredential.S3_TOKEN_CREDENTIAL_TYPE,+ body.getCredentials()[0].credentialType());+ }+ }+ verify(dispatcher)+ .getCredentials(+ eq(NameIdentifier.of(metalake, "catalog")),+ eq(CredentialPrivilege.READ),+ eq(!canInclude));+ try (Response response =+ operations.getCredentials(metalake, "fileset", "catalog.schema.fileset")) {+ Assertions.assertEquals(200, response.getStatus());+ CredentialResponse body = (CredentialResponse) response.getEntity();+ if (canInclude) {+ Assertions.assertEquals(2, body.getCredentials().length);+ } else {+ Assertions.assertEquals(1, body.getCredentials().length);+ Assertions.assertEquals(+ S3TokenCredential.S3_TOKEN_CREDENTIAL_TYPE,+ body.getCredentials()[0].credentialType());+ }+ }+ verify(dispatcher)+ .getCredentials(+ eq(NameIdentifier.of(metalake, "catalog", "schema", "fileset")),+ eq(CredentialPrivilege.READ),+ eq(!canInclude));+ }+ }+ }+ }++ /** Token catalog credentials are returned when dynamic-only providers are used. */+ @Test+ public void testCatalogTokenCredentialsWithoutIncludePrivilege() throws Exception {+ S3TokenCredential token =+ new S3TokenCredential("ak", "sk", "session-token", System.currentTimeMillis() + 60_000);+ CredentialOperationDispatcher dispatcher = mock(CredentialOperationDispatcher.class);+ when(dispatcher.getCredentials(any(), any(), eq(true)))+ .thenReturn(Collections.singletonList(token));+ MetadataObjectCredentialOperations operations =+ new MetadataObjectCredentialOperations(dispatcher);+ FieldUtils.writeField(operations, "httpRequest", mock(HttpServletRequest.class), true);+ try (MockedStatic<MetadataAuthzHelper> auth = mockStatic(MetadataAuthzHelper.class)) {+ stubSecretPrivilegeChecks(auth, false, false);+ try (Response response = operations.getCredentials(metalake, "catalog", "catalog")) {+ Assertions.assertEquals(200, response.getStatus());+ CredentialResponse body = (CredentialResponse) response.getEntity();+ Assertions.assertEquals(1, body.getCredentials().length);+ Assertions.assertEquals(+ S3TokenCredential.S3_TOKEN_CREDENTIAL_TYPE, body.getCredentials()[0].credentialType());+ }+ verify(dispatcher).getCredentials(any(), eq(CredentialPrivilege.READ), eq(true));+ }+ }++ /** With USE+INCLUDE, all providers are invoked and both credential kinds are returned. */+ @Test+ public void testCatalogMixedCredentialsWithIncludeReturnsBoth() throws Exception {+ S3TokenCredential token =+ new S3TokenCredential("ak", "sk", "session-token", System.currentTimeMillis() + 60_000);+ S3SecretKeyCredential staticCredential = new S3SecretKeyCredential("static-ak", "static-sk");+ CredentialOperationDispatcher dispatcher = mock(CredentialOperationDispatcher.class);+ when(dispatcher.getCredentials(any(), any(), eq(false)))+ .thenReturn(Arrays.asList(staticCredential, token));+ MetadataObjectCredentialOperations operations =+ new MetadataObjectCredentialOperations(dispatcher);+ FieldUtils.writeField(operations, "httpRequest", mock(HttpServletRequest.class), true);+ try (MockedStatic<MetadataAuthzHelper> auth = mockStatic(MetadataAuthzHelper.class)) {+ stubSecretPrivilegeChecks(auth, true, true);+ try (Response response = operations.getCredentials(metalake, "catalog", "catalog")) {+ Assertions.assertEquals(200, response.getStatus());+ CredentialResponse body = (CredentialResponse) response.getEntity();+ Assertions.assertEquals(2, body.getCredentials().length);+ Assertions.assertEquals(+ S3SecretKeyCredential.S3_SECRET_KEY_CREDENTIAL_TYPE,+ body.getCredentials()[0].credentialType());+ Assertions.assertEquals(+ S3TokenCredential.S3_TOKEN_CREDENTIAL_TYPE, body.getCredentials()[1].credentialType());+ }+ verify(dispatcher).getCredentials(any(), eq(CredentialPrivilege.READ), eq(false));+ }+ }++ private static void stubSecretPrivilegeChecks(+ MockedStatic<MetadataAuthzHelper> auth, boolean useSecrets, boolean includeCredentials) {+ auth.when(+ () ->+ MetadataAuthzHelper.checkAccess(+ any(),+ any(Entity.EntityType.class),+ eq(+ AuthorizationExpressionConstants+ .FILTER_USE_SECRET_AUTHORIZATION_EXPRESSION)))+ .thenReturn(useSecrets);+ auth.when(+ () ->+ MetadataAuthzHelper.checkAccess(+ any(),+ any(Entity.EntityType.class),+ eq(+ AuthorizationExpressionConstants+ .FILTER_INCLUDE_CREDENTIAL_SECRETS_AUTHORIZATION_EXPRESSION)))+ .thenReturn(includeCredentials);+ auth.when(+ () ->+ MetadataAuthzHelper.checkAccess(+ any(),+ any(Entity.EntityType.class),+ eq(+ AuthorizationExpressionConstants+ .FILTER_WRITE_FILESET_AUTHORIZATION_EXPRESSION)))+ .thenReturn(false);+ }+/** Checks credential client errors identify the requested object. */@Testpublic void testUnsupportedObjectAndProviderErrorsIdentifyTheObject() {@@ -99,7 +261,7 @@ public class TestMetadataObjectCredentialOperations extends JerseyTest {String message = unsupported.readEntity(ErrorResponse.class).getMessage();Assertions.assertTrue(message.contains("catalog.schema.table"));Assertions.assertTrue(message.contains("TABLE"));- when(credentialOperationDispatcher.getCredentials(any(), any()))+ when(credentialOperationDispatcher.getCredentials(any(), any(), anyBoolean())).thenThrow(new IllegalArgumentException("Invalid provider"));Response invalid =target(basePath(metalake))@@ -128,7 +290,7 @@ public class TestMetadataObjectCredentialOperations extends JerseyTest {@Testpublic void testInvalidCredentialLocationResponse() {String path = "wasbs://[email protected]/warehouse/table";- when(credentialOperationDispatcher.getCredentials(any(), any()))+ when(credentialOperationDispatcher.getCredentials(any(), any(), anyBoolean())).thenThrow(new IllegalArgumentException("adls-token requires an abfs or abfss location; unsupported location: " + path));@@ -152,7 +314,7 @@ public class TestMetadataObjectCredentialOperations extends JerseyTest {S3SecretKeyCredential credential = new S3SecretKeyCredential("access-id", "secret-key");// Test return one credential- when(credentialOperationDispatcher.getCredentials(any(), any()))+ when(credentialOperationDispatcher.getCredentials(any(), any(), anyBoolean())).thenReturn(Arrays.asList(credential));Response response =target(basePath(metalake))@@ -175,7 +337,7 @@ public class TestMetadataObjectCredentialOperations extends JerseyTest {Assertions.assertEquals(0, credentialToTest.expireTimeInMs());// Test doesn't return credential- when(credentialOperationDispatcher.getCredentials(any(), any())).thenReturn(null);+ when(credentialOperationDispatcher.getCredentials(any(), any(), anyBoolean())).thenReturn(null);response =target(basePath(metalake)).path(metadataObject.type().toString())diff --git a/server/src/test/java/org/apache/gravitino/server/web/rest/TestMetadataObjectSecretOperations.java b/server/src/test/java/org/apache/gravitino/server/web/rest/TestMetadataObjectSecretOperations.javaindex abfbece364..c11bdb0326 100644--- a/server/src/test/java/org/apache/gravitino/server/web/rest/TestMetadataObjectSecretOperations.java+++ b/server/src/test/java/org/apache/gravitino/server/web/rest/TestMetadataObjectSecretOperations.java@@ -19,6 +19,7 @@package org.apache.gravitino.server.web.rest;import static org.mockito.ArgumentMatchers.any;+import static org.mockito.ArgumentMatchers.anyBoolean;import static org.mockito.ArgumentMatchers.eq;import static org.mockito.Mockito.mock;import static org.mockito.Mockito.mockStatic;@@ -133,7 +134,8 @@ public class TestMetadataObjectSecretOperations extends JerseyTest {public void testGetSecretsReturnsEmptyWithoutUseSecretss() throws Exception {MetadataObject metadataObject =MetadataObjects.parse("catalog.schema.fileset", MetadataObject.Type.FILESET);- when(secretPropertyOperationDispatcher.getSecrets(any(), any(Entity.EntityType.class)))+ when(secretPropertyOperationDispatcher.getSecrets(+ any(), any(Entity.EntityType.class), any(Boolean.class))).thenReturn(Map.of("custom-secret", "plaintext"));MetadataObjectSecretOperations operations =@@ -172,25 +174,106 @@ public class TestMetadataObjectSecretOperations extends JerseyTest {Assertions.assertEquals(0, secretResponse.getCode());Assertions.assertTrue(secretResponse.getSecrets().isEmpty());verify(secretPropertyOperationDispatcher, never())- .getSecrets(any(), any(Entity.EntityType.class));+ .getSecrets(any(), any(Entity.EntityType.class), any(Boolean.class));}}+ /**+ * Mixed static + non-static secrets: USE-only gets the omit result; USE+INCLUDE gets the full+ * map. Dispatcher return values mirror omitStaticCredentialSecrets for the include flag.+ */@Test- public void testGetSecretsFiltersCloudKeysWithUseSecretsOnly() throws Exception {+ public void testGetSecretsMixedStaticAndNonStaticRespectsIncludeFlag() throws Exception {MetadataObject metadataObject =MetadataObjects.parse("catalog.schema.fileset", MetadataObject.Type.FILESET);- when(secretPropertyOperationDispatcher.getSecrets(any(), any(Entity.EntityType.class)))- .thenReturn(- Map.of(- "s3-access-key-id",- "AKIA",- "s3-secret-access-key",- "secret",- "jdbc-password",- "db-pass",- "custom-secret",- "plaintext"));+ Map<String, String> withoutStatic = Map.of("custom-secret", "plaintext", "other-token", "tok");+ Map<String, String> withStatic =+ Map.of(+ "custom-secret",+ "plaintext",+ "other-token",+ "tok",+ "s3-access-key-id",+ "AKIA",+ "s3-secret-access-key",+ "secret");+ when(secretPropertyOperationDispatcher.getSecrets(+ any(), any(Entity.EntityType.class), anyBoolean()))+ .thenAnswer(+ invocation -> {+ boolean includeStatic = invocation.getArgument(2);+ return includeStatic ? withStatic : withoutStatic;+ });++ MetadataObjectSecretOperations operations =+ new MetadataObjectSecretOperations(secretPropertyOperationDispatcher);+ FieldUtils.writeField(operations, "httpRequest", mock(HttpServletRequest.class), true);++ try (MockedStatic<MetadataAuthzHelper> metadataAuthzHelper =+ mockStatic(MetadataAuthzHelper.class)) {+ metadataAuthzHelper+ .when(+ () ->+ MetadataAuthzHelper.checkAccess(+ any(),+ any(Entity.EntityType.class),+ eq(+ AuthorizationExpressionConstants+ .FILTER_USE_SECRET_AUTHORIZATION_EXPRESSION)))+ .thenReturn(true);+ metadataAuthzHelper+ .when(+ () ->+ MetadataAuthzHelper.checkAccess(+ any(),+ any(Entity.EntityType.class),+ eq(+ AuthorizationExpressionConstants+ .FILTER_INCLUDE_CREDENTIAL_SECRETS_AUTHORIZATION_EXPRESSION)))+ .thenReturn(false);++ Response withoutInclude =+ operations.getSecrets(metalake, metadataObject.type().name(), metadataObject.fullName());+ Assertions.assertEquals(Response.Status.OK.getStatusCode(), withoutInclude.getStatus());+ SecretsResponse omitted = (SecretsResponse) withoutInclude.getEntity();+ Assertions.assertEquals("plaintext", omitted.getSecrets().get("custom-secret"));+ Assertions.assertEquals("tok", omitted.getSecrets().get("other-token"));+ Assertions.assertFalse(omitted.getSecrets().containsKey("s3-access-key-id"));+ Assertions.assertFalse(omitted.getSecrets().containsKey("s3-secret-access-key"));+ verify(secretPropertyOperationDispatcher)+ .getSecrets(any(), any(Entity.EntityType.class), eq(false));++ metadataAuthzHelper+ .when(+ () ->+ MetadataAuthzHelper.checkAccess(+ any(),+ any(Entity.EntityType.class),+ eq(+ AuthorizationExpressionConstants+ .FILTER_INCLUDE_CREDENTIAL_SECRETS_AUTHORIZATION_EXPRESSION)))+ .thenReturn(true);++ Response withInclude =+ operations.getSecrets(metalake, metadataObject.type().name(), metadataObject.fullName());+ Assertions.assertEquals(Response.Status.OK.getStatusCode(), withInclude.getStatus());+ SecretsResponse full = (SecretsResponse) withInclude.getEntity();+ Assertions.assertEquals("plaintext", full.getSecrets().get("custom-secret"));+ Assertions.assertEquals("tok", full.getSecrets().get("other-token"));+ Assertions.assertEquals("AKIA", full.getSecrets().get("s3-access-key-id"));+ Assertions.assertEquals("secret", full.getSecrets().get("s3-secret-access-key"));+ verify(secretPropertyOperationDispatcher)+ .getSecrets(any(), any(Entity.EntityType.class), eq(true));+ }+ }++ @Test+ public void testGetSecretsPassesIncludeFlagFalseWithUseSecretsOnly() throws Exception {+ MetadataObject metadataObject =+ MetadataObjects.parse("catalog.schema.fileset", MetadataObject.Type.FILESET);+ when(secretPropertyOperationDispatcher.getSecrets(+ any(), any(Entity.EntityType.class), eq(false)))+ .thenReturn(Map.of("custom-secret", "plaintext"));MetadataObjectSecretOperations operations =new MetadataObjectSecretOperations(secretPropertyOperationDispatcher);@@ -225,19 +308,19 @@ public class TestMetadataObjectSecretOperations extends JerseyTest {Assertions.assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());SecretsResponse secretResponse = (SecretsResponse) response.getEntity();Assertions.assertEquals(0, secretResponse.getCode());- Assertions.assertEquals("db-pass", secretResponse.getSecrets().get("jdbc-password"));Assertions.assertEquals("plaintext", secretResponse.getSecrets().get("custom-secret"));- Assertions.assertFalse(secretResponse.getSecrets().containsKey("s3-access-key-id"));- Assertions.assertFalse(secretResponse.getSecrets().containsKey("s3-secret-access-key"));+ verify(secretPropertyOperationDispatcher)+ .getSecrets(any(), any(Entity.EntityType.class), eq(false));}}@Test- public void testGetSecretsIncludesCloudKeysWithUseSecretsAndIncludeCredentialSecretss()+ public void testGetSecretsPassesIncludeFlagTrueWithUseSecretsAndIncludeCredentialSecrets()throws Exception {MetadataObject metadataObject =MetadataObjects.parse("catalog.schema.fileset", MetadataObject.Type.FILESET);- when(secretPropertyOperationDispatcher.getSecrets(any(), any(Entity.EntityType.class)))+ when(secretPropertyOperationDispatcher.getSecrets(+ any(), any(Entity.EntityType.class), eq(true))).thenReturn(Map.of("s3-access-key-id",@@ -283,11 +366,14 @@ public class TestMetadataObjectSecretOperations extends JerseyTest {Assertions.assertEquals("AKIA", secretResponse.getSecrets().get("s3-access-key-id"));Assertions.assertEquals("secret", secretResponse.getSecrets().get("s3-secret-access-key"));Assertions.assertEquals("db-pass", secretResponse.getSecrets().get("jdbc-password"));+ verify(secretPropertyOperationDispatcher)+ .getSecrets(any(), any(Entity.EntityType.class), eq(true));}}private void testGetSecretsForObject(MetadataObject metadataObject) {- when(secretPropertyOperationDispatcher.getSecrets(any(), any(Entity.EntityType.class)))+ when(secretPropertyOperationDispatcher.getSecrets(+ any(), any(Entity.EntityType.class), any(Boolean.class))).thenReturn(Map.of("custom-secret", "plaintext"));Response response =@@ -304,7 +390,8 @@ public class TestMetadataObjectSecretOperations extends JerseyTest {Assertions.assertEquals(0, secretResponse.getCode());Assertions.assertEquals("plaintext", secretResponse.getSecrets().get("custom-secret"));- when(secretPropertyOperationDispatcher.getSecrets(any(), any(Entity.EntityType.class)))+ when(secretPropertyOperationDispatcher.getSecrets(+ any(), any(Entity.EntityType.class), any(Boolean.class))).thenReturn(Map.of());response =target(basePath(metalake))diff --git a/spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/integration/test/authorization/SparkAuthorizationIT.java b/spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/integration/test/authorization/SparkAuthorizationIT.javaindex c2b75fa105..ea1682c8fb 100644--- a/spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/integration/test/authorization/SparkAuthorizationIT.java+++ b/spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/integration/test/authorization/SparkAuthorizationIT.java@@ -40,7 +40,9 @@ import org.apache.gravitino.auth.AuthConstants;import org.apache.gravitino.authorization.Privileges;import org.apache.gravitino.authorization.SecurableObject;import org.apache.gravitino.authorization.SecurableObjects;+import org.apache.gravitino.client.GravitinoAdminClient;import org.apache.gravitino.client.GravitinoMetalake;+import org.apache.gravitino.credential.JdbcCredential;import org.apache.gravitino.exceptions.ForbiddenException;import org.apache.gravitino.integration.test.util.BaseIT;import org.apache.gravitino.integration.test.util.TestDatabaseName;@@ -158,7 +160,7 @@ public abstract class SparkAuthorizationIT extends BaseIT {Privileges.UseSchema.allow(),Privileges.SelectTable.allow(),Privileges.CreateTable.allow(),- // Spark JDBC needs both secret privileges to receive catalog credentials.+ // Spark JDBC needs both secret privileges to vend static catalog credentials.Privileges.UseSecrets.allow(),Privileges.IncludeCredentialSecrets.allow()));gravitinoMetalake.createRole(ROLE, new HashMap<>(), ImmutableList.of(securableObject));@@ -185,29 +187,41 @@ public abstract class SparkAuthorizationIT extends BaseIT {.getOrCreate();}- /** Verifies Spark cannot initialize a JDBC catalog with either secret privilege missing. */+ /**+ * Catalog {@code getCredentials} omits static JDBC credentials unless the caller holds both+ * secret privileges (metadata access alone is not forbidden).+ */@Test@Order(0)public void testCatalogRequiresBothCredentialPrivileges() {GravitinoMetalake metalake = client.loadMetalake(METALAKE);- MetadataObject catalog =+ MetadataObject catalogObject =MetadataObjects.of(ImmutableList.of(JDBC_CATALOG), MetadataObject.Type.CATALOG);+ GravitinoAdminClient normalUserClient =+ GravitinoAdminClient.builder(gravitinoUri).withSimpleAuth(NORMAL_USER).build();try {metalake.revokePrivilegesFromRole(- ROLE, catalog, ImmutableSet.of(Privileges.UseSecrets.allow()));- assertThrows(- ForbiddenException.class, () -> normalUserSparkSession.sql("USE " + JDBC_CATALOG));+ ROLE, catalogObject, ImmutableSet.of(Privileges.UseSecrets.allow()));+ Catalog withoutUseSecrets = normalUserClient.loadMetalake(METALAKE).loadCatalog(JDBC_CATALOG);+ Assertions.assertEquals(0, withoutUseSecrets.supportsCredentials().getCredentials().length);metalake.grantPrivilegesToRole(- ROLE, catalog, ImmutableList.of(Privileges.UseSecrets.allow()));+ ROLE, catalogObject, ImmutableList.of(Privileges.UseSecrets.allow()));metalake.revokePrivilegesFromRole(- ROLE, catalog, ImmutableSet.of(Privileges.IncludeCredentialSecrets.allow()));- assertThrows(- ForbiddenException.class, () -> normalUserSparkSession.sql("USE " + JDBC_CATALOG));+ ROLE, catalogObject, ImmutableSet.of(Privileges.IncludeCredentialSecrets.allow()));+ Catalog withoutInclude = normalUserClient.loadMetalake(METALAKE).loadCatalog(JDBC_CATALOG);+ Assertions.assertEquals(0, withoutInclude.supportsCredentials().getCredentials().length);++ metalake.grantPrivilegesToRole(+ ROLE, catalogObject, ImmutableList.of(Privileges.IncludeCredentialSecrets.allow()));+ Catalog withBoth = normalUserClient.loadMetalake(METALAKE).loadCatalog(JDBC_CATALOG);+ Assertions.assertEquals(1, withBoth.supportsCredentials().getCredentials().length);+ Assertions.assertInstanceOf(+ JdbcCredential.class, withBoth.supportsCredentials().getCredentials()[0]);} finally {metalake.grantPrivilegesToRole(ROLE,- catalog,+ catalogObject,ImmutableList.of(Privileges.UseSecrets.allow(), Privileges.IncludeCredentialSecrets.allow()));}diff --git a/spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/integration/test/authorization/SparkJwksAuthorizationIT.java b/spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/integration/test/authorization/SparkJwksAuthorizationIT.javaindex 2cd01398ee..0171bf6573 100644--- a/spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/integration/test/authorization/SparkJwksAuthorizationIT.java+++ b/spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/integration/test/authorization/SparkJwksAuthorizationIT.java@@ -254,9 +254,8 @@ public abstract class SparkJwksAuthorizationIT extends BaseIT {GravitinoMetalake bobMetalake = bobClient.loadMetalake(METALAKE);Catalog catalog = bobMetalake.loadCatalog(CATALOG);Assertions.assertNotNull(catalog);- // Metadata visibility does not grant Bob the source account's credentials.- Assertions.assertThrows(- ForbiddenException.class, () -> catalog.supportsCredentials().getCredentials());+ // Metadata visibility does not grant Bob static catalog credentials (soft-filtered to empty).+ Assertions.assertEquals(0, catalog.supportsCredentials().getCredentials().length);boolean tableExists =catalog.asTableCatalog().tableExists(NameIdentifier.of(SCHEMA, ALICE_TABLE));