You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gravitino.apache.org by "yuqi1129 (via GitHub)" <gi...@apache.org> on 2026/06/02 08:55:52 UTC
[PR] [MINOR] improvement(core): validate remote URI host in JobManager before download [gravitino]
yuqi1129 opened a new pull request, #11354:
URL: https://github.com/apache/gravitino/pull/11354
### What changes were proposed in this pull request?
Add host validation in `JobManager.fetchFileFromUri()` before issuing
HTTP/HTTPS/FTP downloads. The new `validateRemoteUri()` method resolves
the target hostname and rejects addresses in the following ranges:
- Loopback (127.0.0.0/8, ::1)
- Link-local (169.254.0.0/16, fe80::/10)
- RFC-1918 private (10.x, 172.16-31.x, 192.168.x)
- Multicast / unspecified
- Cloud metadata endpoint 100.100.100.200 (Alibaba Cloud / Oracle Cloud)
### Why are the changes needed?
`fetchFileFromUri()` previously passed user-supplied URIs directly to
`FileUtils.copyURLToFile()` without inspecting the resolved IP. This
allowed the server to be directed to fetch content from addresses it
should never reach, such as internal services or cloud metadata
endpoints.
### Does this PR introduce _any_ user-facing change?
No. This only affects URIs that point to internal/private addresses,
which were never a valid use case.
### How was this patch tested?
Added `testFetchFileFromUriSsrfBlocked()` and `testValidateRemoteUri()`
in `TestJobManager`, covering loopback, link-local, RFC-1918 private,
localhost, and the Alibaba Cloud metadata endpoint.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MINOR] improvement(core): validate remote URI host in JobManager before download [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #11354:
URL: https://github.com/apache/gravitino/pull/11354#discussion_r3380320883
##########
core/src/test/java/org/apache/gravitino/job/TestJobManager.java:
##########
@@ -914,6 +933,71 @@ public void testFetchFileFromUriWithMissingLocalFileShouldFail() throws IOExcept
RuntimeException.class, () -> JobManager.fetchFileFromUri(uri, stagingDir, 1000));
}
+ @Test
+ public void testFetchFileFromUriSsrfBlocked() {
+ File stagingDir = new File(testStagingDir);
+ Assertions.assertTrue(stagingDir.mkdirs() || stagingDir.exists());
+
+ // Loopback address
+ RuntimeException e1 =
+ Assertions.assertThrows(
+ RuntimeException.class,
+ () -> JobManager.fetchFileFromUri("http://127.0.0.1:8090/configs", stagingDir, 1000));
+ assertRemoteUriBlockedMessage(e1);
+
+ // AWS / GCP / Azure cloud-metadata endpoint (link-local 169.254.x.x)
+ RuntimeException e2 =
+ Assertions.assertThrows(
+ RuntimeException.class,
+ () ->
+ JobManager.fetchFileFromUri(
+ "http://169.254.169.254/latest/meta-data/", stagingDir, 1000));
+ assertRemoteUriBlockedMessage(e2);
+
+ // RFC-1918 private range
+ RuntimeException e3 =
+ Assertions.assertThrows(
+ RuntimeException.class,
+ () -> JobManager.fetchFileFromUri("http://192.168.1.1/", stagingDir, 1000));
+ assertRemoteUriBlockedMessage(e3);
+
+ // Alibaba Cloud / Oracle Cloud metadata endpoint
+ RuntimeException e4 =
+ Assertions.assertThrows(
+ RuntimeException.class,
+ () -> JobManager.fetchFileFromUri("http://100.100.100.200/", stagingDir, 1000));
+ assertRemoteUriBlockedMessage(e4);
+ }
+
+ @Test
+ public void testFetchFileFromUriShouldAllowLocalhostWhenBlockingDisabled() throws Exception {
+ File stagingDir = new File(testStagingDir);
+ Assertions.assertTrue(stagingDir.mkdirs() || stagingDir.exists());
+ HttpServer server = createLoopbackHttpServer("job artifact");
+
+ try {
+ server.start();
+ int port = server.getAddress().getPort();
+
+ String fetchedFile =
+ JobManager.fetchFileFromUri(
+ String.format("http://127.0.0.1:%d/artifact.jar", port), stagingDir, 1000, false);
+
+ Assertions.assertEquals("job artifact", Files.readString(Path.of(fetchedFile)));
+ } finally {
+ server.stop(0);
+ }
+ }
Review Comment:
Updated the PR description to reference `TestRemoteUriValidator` for URI validation coverage and `TestJobManager` for JobManager download behavior. The description now also reflects the shared `FetchFileUtils` consolidation and configuration changes.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MINOR] improvement(core): validate remote URI host in JobManager before download [gravitino]
Posted by "roryqi (via GitHub)" <gi...@apache.org>.
roryqi commented on code in PR #11354:
URL: https://github.com/apache/gravitino/pull/11354#discussion_r3395698726
##########
common/src/main/java/org/apache/gravitino/utils/FetchFileUtils.java:
##########
@@ -0,0 +1,161 @@
+/*
+ * 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.utils;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardCopyOption;
+import java.util.Optional;
+import javax.annotation.Nullable;
+import org.apache.commons.io.FileUtils;
+
+/**
+ * Fetches a file referenced by a URI to a local destination. Supports {@code file}, {@code http},
+ * {@code https}, {@code ftp} and {@code hdfs} schemes. This is the single shared implementation
+ * used by the job manager and the Kerberos clients of the Hive, Iceberg, Hadoop and Paimon
+ * catalogs.
+ *
+ * <p>The {@code hdfs} scheme is resolved reflectively against {@code
+ * org.apache.hadoop.fs.FileSystem} so that this class can live in the {@code common} module, which
+ * does not declare a compile-time dependency on Hadoop. Callers that never use {@code hdfs} URIs
+ * (for example the job manager and the Paimon catalog) simply pass {@code null} for the Hadoop
+ * configuration.
+ */
+public final class FetchFileUtils {
+
+ /** The server configuration that controls unsafe remote URI blocking. */
+ public static final String BLOCK_UNSAFE_REMOTE_URI_CONFIG =
+ "gravitino.fetchFile.blockUnsafeRemoteUri";
+
+ private static volatile boolean blockUnsafeRemoteUri = true;
+
+ private FetchFileUtils() {}
+
+ /**
+ * Sets whether remote URIs that resolve to unsafe addresses should be blocked.
+ *
+ * @param blockUnsafeRemoteUri whether to block unsafe remote URIs
+ */
+ public static void setBlockUnsafeRemoteUri(boolean blockUnsafeRemoteUri) {
+ FetchFileUtils.blockUnsafeRemoteUri = blockUnsafeRemoteUri;
+ }
+
+ /**
+ * Fetches the file referenced by {@code fileUri} into {@code destFile}.
+ *
+ * @param fileUri the source URI; a missing scheme is treated as {@code file}
+ * @param destFile the local destination file
+ * @param timeoutMs the connect/read timeout in milliseconds, applied to remote (http/https/ftp)
+ * downloads
+ * @param hadoopConf an {@code org.apache.hadoop.conf.Configuration} instance, required only for
+ * the {@code hdfs} scheme; may be {@code null} when no {@code hdfs} URI is fetched
+ * @return the absolute path of {@code destFile}
+ * @throws IOException if the file cannot be fetched
+ */
+ public static String fetchFileFromUri(
Review Comment:
You can put it to GravitinoEnv? It is weird now.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MINOR] improvement(core): validate remote URI host in JobManager before download [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #11354:
URL: https://github.com/apache/gravitino/pull/11354#discussion_r3400225442
##########
catalogs/catalog-fileset/src/main/java/org/apache/gravitino/catalog/fileset/FilesetCatalogOperations.java:
##########
@@ -1386,7 +1386,10 @@ FileSystem getFileSystem(Path path, Map<String, String> config) throws IOExcepti
() -> {
if (scheme.equals(SCHEME_HDFS)) {
return new ImpersonationHDFSFileSystemProxy(
- path, config, PrincipalUtils::getCurrentUserName)
+ path,
+ config,
+ PrincipalUtils::getCurrentUserName,
+ GravitinoEnv.getInstance().blockUnsafeRemoteUri())
Review Comment:
`GravitinoEnv` is now a singleton instance, and it may be quite similar to what you mentioned.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MINOR] improvement(core): validate remote URI host in JobManager before download [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #11354:
URL: https://github.com/apache/gravitino/pull/11354#discussion_r3373261037
##########
catalogs/catalog-common/src/main/java/org/apache/gravitino/catalog/hive/HiveConstants.java:
##########
@@ -30,6 +30,8 @@ public class HiveConstants {
public static final String PRINCIPAL = "kerberos.principal";
public static final String CHECK_INTERVAL_SEC = "kerberos.check-interval-sec";
public static final String FETCH_TIMEOUT_SEC = "kerberos.keytab-fetch-timeout-sec";
+ public static final String KEYTAB_FETCH_ALLOW_LOCAL_ADDRESS =
Review Comment:
Renamed it to `keytab-fetch-block-unsafe-address` (and `blockUnsafeAddress` for the server config). The validator also blocks multicast, unspecified, and cloud metadata addresses, so `unsafe address` reflects the complete set better than `local` or `private`. The blocking option now defaults to `true`; users can explicitly set it to `false` for trusted URIs.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MINOR] improvement(core): validate remote URI host in JobManager before download [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #11354:
URL: https://github.com/apache/gravitino/pull/11354#discussion_r3379276899
##########
catalogs/hive-metastore-common/src/main/java/org/apache/gravitino/hive/kerberos/FetchFileUtils.java:
##########
Review Comment:
Let me verify it locally, and it's not a minor change considering the release is approaching.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MINOR] improvement(core): validate remote URI host in JobManager before download [gravitino]
Posted by "roryqi (via GitHub)" <gi...@apache.org>.
roryqi commented on PR #11354:
URL: https://github.com/apache/gravitino/pull/11354#issuecomment-4668097220
> > one question: Should it be a catalog property or a server configuration option?
>
> Some catalogs used the method to fetch files, and the same goes for the Gravitino server, so both catalog properties and server configurations exist.
For me, server config option is enough. I don't wanna make it complex.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MINOR] improvement(core): validate remote URI host in JobManager before download [gravitino]
Posted by "roryqi (via GitHub)" <gi...@apache.org>.
roryqi commented on code in PR #11354:
URL: https://github.com/apache/gravitino/pull/11354#discussion_r3400138101
##########
catalogs/catalog-fileset/src/main/java/org/apache/gravitino/catalog/fileset/FilesetCatalogOperations.java:
##########
@@ -1386,7 +1386,10 @@ FileSystem getFileSystem(Path path, Map<String, String> config) throws IOExcepti
() -> {
if (scheme.equals(SCHEME_HDFS)) {
return new ImpersonationHDFSFileSystemProxy(
- path, config, PrincipalUtils::getCurrentUserName)
+ path,
+ config,
+ PrincipalUtils::getCurrentUserName,
+ GravitinoEnv.getInstance().blockUnsafeRemoteUri())
Review Comment:
Rarely see a Utils class with a state.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MINOR] improvement(core): validate remote URI host in JobManager before download [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #11354:
URL: https://github.com/apache/gravitino/pull/11354#discussion_r3379997679
##########
core/src/main/java/org/apache/gravitino/Configs.java:
##########
@@ -551,6 +551,19 @@ private Configs() {}
.checkValue(value -> value > 0, ConfigConstants.POSITIVE_NUMBER_ERROR_MSG)
.createWithDefault(5 * 60 * 1000L); // Default is 5 minutes
+ public static final String JOB_REMOTE_URI_BLOCK_UNSAFE_ADDRESS_KEY =
+ "gravitino.job.remoteUri.blockUnsafeAddress";
Review Comment:
changed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MINOR] improvement(core): validate remote URI host in JobManager before download [gravitino]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #11354:
URL: https://github.com/apache/gravitino/pull/11354#discussion_r3378346336
##########
core/src/main/java/org/apache/gravitino/job/JobManager.java:
##########
@@ -808,6 +854,10 @@ static String fetchFileFromUri(String uri, File stagingDir, int timeoutInMs) {
case "http":
case "https":
case "ftp":
+ RemoteUriValidator.validate(
+ fileUri,
+ blockUnsafeAddressForRemoteUri,
+ String.format("'%s' to false", Configs.JOB_REMOTE_URI_BLOCK_UNSAFE_ADDRESS_KEY));
FileUtils.copyURLToFile(fileUri.toURL(), destFile, timeoutInMs, timeoutInMs);
break;
Review Comment:
`fetchFileFromUri()` validates the hostname and then calls `FileUtils.copyURLToFile(fileUri.toURL(), ...)`, which will typically perform its own DNS resolution again. This leaves a DNS-rebinding/TOCTOU gap: a hostname can resolve to a public IP during validation and then rebind to a private/loopback IP when the connection is opened.
##########
common/src/main/java/org/apache/gravitino/utils/RemoteUriValidator.java:
##########
@@ -0,0 +1,92 @@
+/*
+ * 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.utils;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.URI;
+
+/** Validates remote URI hosts before server-side downloads. */
+public final class RemoteUriValidator {
+
+ private RemoteUriValidator() {}
+
+ /**
+ * Resolves the host in the given URI and rejects unsafe addresses when blocking is enabled.
+ *
+ * @param uri The remote URI to validate.
+ * @param blockUnsafeAddress Whether unsafe addresses should be blocked.
+ * @param blockUnsafeAddressHint The configuration hint that disables unsafe address blocking.
+ * @throws IOException If host resolution fails.
+ * @throws IllegalArgumentException If the URI has no host or resolves to an unsafe address.
+ */
+ public static void validate(URI uri, boolean blockUnsafeAddress, String blockUnsafeAddressHint)
+ throws IOException {
+ String host = uri.getHost();
+ if (host == null) {
+ throw new IllegalArgumentException("URI has no host: " + uri);
+ }
+
+ if (!blockUnsafeAddress) {
+ return;
+ }
+
+ InetAddress[] addresses = InetAddress.getAllByName(host);
+ for (InetAddress address : addresses) {
+ if (isUnsafeAddress(address)) {
+ throw new IllegalArgumentException(
+ String.format(
+ "URI '%s' resolves to blocked address %s from the Gravitino server side. "
+ + "Access to local, private, link-local, multicast, unspecified, and cloud "
+ + "metadata addresses is disabled by default to prevent SSRF. If this URI is "
+ + "trusted and this access is required, set %s.",
+ uri, address.getHostAddress(), blockUnsafeAddressHint));
+ }
Review Comment:
`RemoteUriValidator.validate()` performs a DNS lookup and then callers open a fresh connection via `FileUtils.copyURLToFile(uri.toURL(), ...)`, which will resolve DNS again. This creates a TOCTOU/DNS-rebinding window where an attacker can pass validation and then rebind the hostname to a blocked address before the actual connection, bypassing the SSRF protection.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MINOR] improvement(core): validate remote URI host in JobManager before download [gravitino]
Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on code in PR #11354:
URL: https://github.com/apache/gravitino/pull/11354#discussion_r3392236212
##########
common/src/main/java/org/apache/gravitino/utils/FetchFileUtils.java:
##########
@@ -0,0 +1,184 @@
+/*
+ * 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.utils;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardCopyOption;
+import java.util.Optional;
+import java.util.concurrent.ConcurrentHashMap;
+import javax.annotation.Nullable;
+import org.apache.commons.io.FileUtils;
+
+/**
+ * Fetches a file referenced by a URI to a local destination. Supports {@code file}, {@code http},
+ * {@code https}, {@code ftp} and {@code hdfs} schemes. This is the single shared implementation
+ * used by the job manager and the Kerberos clients of the Hive, Iceberg, Hadoop and Paimon
+ * catalogs.
+ *
+ * <p>The {@code hdfs} scheme is resolved reflectively against {@code
+ * org.apache.hadoop.fs.FileSystem} so that this class can live in the {@code common} module, which
+ * does not declare a compile-time dependency on Hadoop. Callers that never use {@code hdfs} URIs
+ * (for example the job manager and the Paimon catalog) simply pass {@code null} for the Hadoop
+ * configuration.
+ */
+public final class FetchFileUtils {
+
+ /** The server configuration that controls unsafe remote URI blocking. */
+ public static final String BLOCK_UNSAFE_REMOTE_URI_CONFIG = "gravitino.blockUnsafeRemoteUri";
Review Comment:
"gravitino.fetchFile.blockUnsageRemoteUri"
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MINOR] improvement(core): validate remote URI host in JobManager before download [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 merged PR #11354:
URL: https://github.com/apache/gravitino/pull/11354
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MINOR] improvement(core): validate remote URI host in JobManager before download [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #11354:
URL: https://github.com/apache/gravitino/pull/11354#discussion_r3396030216
##########
common/src/main/java/org/apache/gravitino/utils/FetchFileUtils.java:
##########
@@ -0,0 +1,161 @@
+/*
+ * 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.utils;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardCopyOption;
+import java.util.Optional;
+import javax.annotation.Nullable;
+import org.apache.commons.io.FileUtils;
+
+/**
+ * Fetches a file referenced by a URI to a local destination. Supports {@code file}, {@code http},
+ * {@code https}, {@code ftp} and {@code hdfs} schemes. This is the single shared implementation
+ * used by the job manager and the Kerberos clients of the Hive, Iceberg, Hadoop and Paimon
+ * catalogs.
+ *
+ * <p>The {@code hdfs} scheme is resolved reflectively against {@code
+ * org.apache.hadoop.fs.FileSystem} so that this class can live in the {@code common} module, which
+ * does not declare a compile-time dependency on Hadoop. Callers that never use {@code hdfs} URIs
+ * (for example the job manager and the Paimon catalog) simply pass {@code null} for the Hadoop
+ * configuration.
+ */
+public final class FetchFileUtils {
+
+ /** The server configuration that controls unsafe remote URI blocking. */
+ public static final String BLOCK_UNSAFE_REMOTE_URI_CONFIG =
+ "gravitino.fetchFile.blockUnsafeRemoteUri";
+
+ private static volatile boolean blockUnsafeRemoteUri = true;
+
+ private FetchFileUtils() {}
+
+ /**
+ * Sets whether remote URIs that resolve to unsafe addresses should be blocked.
+ *
+ * @param blockUnsafeRemoteUri whether to block unsafe remote URIs
+ */
+ public static void setBlockUnsafeRemoteUri(boolean blockUnsafeRemoteUri) {
+ FetchFileUtils.blockUnsafeRemoteUri = blockUnsafeRemoteUri;
+ }
+
+ /**
+ * Fetches the file referenced by {@code fileUri} into {@code destFile}.
+ *
+ * @param fileUri the source URI; a missing scheme is treated as {@code file}
+ * @param destFile the local destination file
+ * @param timeoutMs the connect/read timeout in milliseconds, applied to remote (http/https/ftp)
+ * downloads
+ * @param hadoopConf an {@code org.apache.hadoop.conf.Configuration} instance, required only for
+ * the {@code hdfs} scheme; may be {@code null} when no {@code hdfs} URI is fetched
+ * @return the absolute path of {@code destFile}
+ * @throws IOException if the file cannot be fetched
+ */
+ public static String fetchFileFromUri(
Review Comment:
done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MINOR] improvement(core): validate remote URI host in JobManager before download [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #11354:
URL: https://github.com/apache/gravitino/pull/11354#discussion_r3371793718
##########
catalogs/hive-metastore-common/src/main/java/org/apache/gravitino/hive/kerberos/FetchFileUtils.java:
##########
Review Comment:
I have used https://github.com/apache/gravitino/issues/11486 to track this issue, as different modules require Hadoop with different versions, and extracting a common module with Hadoop compile-only is risky and it's a major change, so I'm hesitant to move it forward.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MINOR] improvement(core): validate remote URI host in JobManager before download [gravitino]
Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on code in PR #11354:
URL: https://github.com/apache/gravitino/pull/11354#discussion_r3378323182
##########
core/src/main/java/org/apache/gravitino/Configs.java:
##########
@@ -551,6 +551,19 @@ private Configs() {}
.checkValue(value -> value > 0, ConfigConstants.POSITIVE_NUMBER_ERROR_MSG)
.createWithDefault(5 * 60 * 1000L); // Default is 5 minutes
+ public static final String JOB_REMOTE_URI_BLOCK_UNSAFE_ADDRESS_KEY =
+ "gravitino.job.remoteUri.blockUnsafeAddress";
Review Comment:
It is better to make this 3-level name for configuration.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MINOR] improvement(core): validate remote URI host in JobManager before download [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #11354:
URL: https://github.com/apache/gravitino/pull/11354#discussion_r3395449688
##########
common/src/main/java/org/apache/gravitino/utils/FetchFileUtils.java:
##########
@@ -0,0 +1,161 @@
+/*
+ * 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.utils;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardCopyOption;
+import java.util.Optional;
+import javax.annotation.Nullable;
+import org.apache.commons.io.FileUtils;
+
+/**
+ * Fetches a file referenced by a URI to a local destination. Supports {@code file}, {@code http},
+ * {@code https}, {@code ftp} and {@code hdfs} schemes. This is the single shared implementation
+ * used by the job manager and the Kerberos clients of the Hive, Iceberg, Hadoop and Paimon
+ * catalogs.
+ *
+ * <p>The {@code hdfs} scheme is resolved reflectively against {@code
+ * org.apache.hadoop.fs.FileSystem} so that this class can live in the {@code common} module, which
+ * does not declare a compile-time dependency on Hadoop. Callers that never use {@code hdfs} URIs
+ * (for example the job manager and the Paimon catalog) simply pass {@code null} for the Hadoop
+ * configuration.
+ */
+public final class FetchFileUtils {
+
+ /** The server configuration that controls unsafe remote URI blocking. */
+ public static final String BLOCK_UNSAFE_REMOTE_URI_CONFIG =
+ "gravitino.fetchFile.blockUnsafeRemoteUri";
+
+ private static volatile boolean blockUnsafeRemoteUri = true;
+
+ private FetchFileUtils() {}
+
+ /**
+ * Sets whether remote URIs that resolve to unsafe addresses should be blocked.
+ *
+ * @param blockUnsafeRemoteUri whether to block unsafe remote URIs
+ */
+ public static void setBlockUnsafeRemoteUri(boolean blockUnsafeRemoteUri) {
+ FetchFileUtils.blockUnsafeRemoteUri = blockUnsafeRemoteUri;
+ }
+
+ /**
+ * Fetches the file referenced by {@code fileUri} into {@code destFile}.
+ *
+ * @param fileUri the source URI; a missing scheme is treated as {@code file}
+ * @param destFile the local destination file
+ * @param timeoutMs the connect/read timeout in milliseconds, applied to remote (http/https/ftp)
+ * downloads
+ * @param hadoopConf an {@code org.apache.hadoop.conf.Configuration} instance, required only for
+ * the {@code hdfs} scheme; may be {@code null} when no {@code hdfs} URI is fetched
+ * @return the absolute path of {@code destFile}
+ * @throws IOException if the file cannot be fetched
+ */
+ public static String fetchFileFromUri(
+ String fileUri, File destFile, int timeoutMs, @Nullable Object hadoopConf)
+ throws IOException {
+ try {
+ URI uri = new URI(fileUri);
+ String scheme = Optional.ofNullable(uri.getScheme()).orElse("file");
+
+ switch (scheme) {
+ case "http":
+ case "https":
+ case "ftp":
+ RemoteUriValidator.validate(
+ uri,
+ blockUnsafeRemoteUri,
+ String.format("'%s' to false", BLOCK_UNSAFE_REMOTE_URI_CONFIG));
+ FileUtils.copyURLToFile(uri.toURL(), destFile, timeoutMs, timeoutMs);
+ break;
+
+ case "file":
+ linkLocalFile(uri, destFile);
+ break;
+
+ case "hdfs":
+ copyHdfsFileToLocal(uri, destFile, hadoopConf);
+ break;
+
+ default:
+ throw new IllegalArgumentException(
+ String.format("The scheme '%s' is not supported", scheme));
+ }
+
+ return destFile.getAbsolutePath();
+ } catch (URISyntaxException ue) {
+ throw new IllegalArgumentException("The uri of file has the wrong format", ue);
+ }
+ }
+
+ private static synchronized void linkLocalFile(URI uri, File destFile) throws IOException {
+ Path srcPath = new File(uri.getPath()).toPath().normalize();
+ if (!Files.exists(srcPath)) {
+ throw new IOException(
+ String.format("Source file does not exist: %s", srcPath.toAbsolutePath()));
+ }
+
+ Path destPath = destFile.toPath().toAbsolutePath().normalize();
+ // Skip if the symlink already points to the correct target.
+ if (Files.isSymbolicLink(destPath)
+ && Files.readSymbolicLink(destPath).normalize().equals(srcPath)) {
+ return;
+ }
+ // Replace via a temporary symlink + rename to minimize the window where the destination path
+ // is absent (which could otherwise cause a concurrent reader, e.g. loginUserFromKeytab, to
+ // fail). REPLACE_EXISTING is used here; on common local filesystems (ext4, xfs, APFS) a
+ // same-directory rename is effectively atomic at the OS level.
+ Path tmpPath = destPath.resolveSibling(destPath.getFileName() + ".symlink.tmp");
+ Files.deleteIfExists(tmpPath);
+ Files.createSymbolicLink(tmpPath, srcPath);
+ Files.move(tmpPath, destPath, StandardCopyOption.REPLACE_EXISTING);
+ }
+
+ /**
+ * Copies an {@code hdfs} file to the local destination reflectively, so that this class does not
+ * require a compile-time dependency on Hadoop.
+ */
+ private static void copyHdfsFileToLocal(URI uri, File destFile, @Nullable Object hadoopConf)
Review Comment:
It can. Both is okay for me.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MINOR] improvement(core): validate remote URI host in JobManager before download [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #11354:
URL: https://github.com/apache/gravitino/pull/11354#discussion_r3395478245
##########
common/src/main/java/org/apache/gravitino/utils/FetchFileUtils.java:
##########
@@ -0,0 +1,161 @@
+/*
+ * 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.utils;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardCopyOption;
+import java.util.Optional;
+import javax.annotation.Nullable;
+import org.apache.commons.io.FileUtils;
+
+/**
+ * Fetches a file referenced by a URI to a local destination. Supports {@code file}, {@code http},
+ * {@code https}, {@code ftp} and {@code hdfs} schemes. This is the single shared implementation
+ * used by the job manager and the Kerberos clients of the Hive, Iceberg, Hadoop and Paimon
+ * catalogs.
+ *
+ * <p>The {@code hdfs} scheme is resolved reflectively against {@code
+ * org.apache.hadoop.fs.FileSystem} so that this class can live in the {@code common} module, which
+ * does not declare a compile-time dependency on Hadoop. Callers that never use {@code hdfs} URIs
+ * (for example the job manager and the Paimon catalog) simply pass {@code null} for the Hadoop
+ * configuration.
+ */
+public final class FetchFileUtils {
+
+ /** The server configuration that controls unsafe remote URI blocking. */
+ public static final String BLOCK_UNSAFE_REMOTE_URI_CONFIG =
+ "gravitino.fetchFile.blockUnsafeRemoteUri";
+
+ private static volatile boolean blockUnsafeRemoteUri = true;
+
+ private FetchFileUtils() {}
+
+ /**
+ * Sets whether remote URIs that resolve to unsafe addresses should be blocked.
+ *
+ * @param blockUnsafeRemoteUri whether to block unsafe remote URIs
+ */
+ public static void setBlockUnsafeRemoteUri(boolean blockUnsafeRemoteUri) {
+ FetchFileUtils.blockUnsafeRemoteUri = blockUnsafeRemoteUri;
+ }
+
+ /**
+ * Fetches the file referenced by {@code fileUri} into {@code destFile}.
+ *
+ * @param fileUri the source URI; a missing scheme is treated as {@code file}
+ * @param destFile the local destination file
+ * @param timeoutMs the connect/read timeout in milliseconds, applied to remote (http/https/ftp)
+ * downloads
+ * @param hadoopConf an {@code org.apache.hadoop.conf.Configuration} instance, required only for
+ * the {@code hdfs} scheme; may be {@code null} when no {@code hdfs} URI is fetched
+ * @return the absolute path of {@code destFile}
+ * @throws IOException if the file cannot be fetched
+ */
+ public static String fetchFileFromUri(
Review Comment:
I won't include it in the PR since the content is the same as the previous one. If it indeed a problem, I would rather we use another PR to solve concurrent problem all.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MINOR] improvement(core): validate remote URI host in JobManager before download [gravitino]
Posted by "roryqi (via GitHub)" <gi...@apache.org>.
roryqi commented on code in PR #11354:
URL: https://github.com/apache/gravitino/pull/11354#discussion_r3395639401
##########
common/src/main/java/org/apache/gravitino/utils/FetchFileUtils.java:
##########
@@ -0,0 +1,161 @@
+/*
+ * 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.utils;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardCopyOption;
+import java.util.Optional;
+import javax.annotation.Nullable;
+import org.apache.commons.io.FileUtils;
+
+/**
+ * Fetches a file referenced by a URI to a local destination. Supports {@code file}, {@code http},
+ * {@code https}, {@code ftp} and {@code hdfs} schemes. This is the single shared implementation
+ * used by the job manager and the Kerberos clients of the Hive, Iceberg, Hadoop and Paimon
+ * catalogs.
+ *
+ * <p>The {@code hdfs} scheme is resolved reflectively against {@code
+ * org.apache.hadoop.fs.FileSystem} so that this class can live in the {@code common} module, which
+ * does not declare a compile-time dependency on Hadoop. Callers that never use {@code hdfs} URIs
+ * (for example the job manager and the Paimon catalog) simply pass {@code null} for the Hadoop
+ * configuration.
+ */
+public final class FetchFileUtils {
+
+ /** The server configuration that controls unsafe remote URI blocking. */
+ public static final String BLOCK_UNSAFE_REMOTE_URI_CONFIG =
+ "gravitino.fetchFile.blockUnsafeRemoteUri";
+
+ private static volatile boolean blockUnsafeRemoteUri = true;
+
+ private FetchFileUtils() {}
+
+ /**
+ * Sets whether remote URIs that resolve to unsafe addresses should be blocked.
+ *
+ * @param blockUnsafeRemoteUri whether to block unsafe remote URIs
+ */
+ public static void setBlockUnsafeRemoteUri(boolean blockUnsafeRemoteUri) {
+ FetchFileUtils.blockUnsafeRemoteUri = blockUnsafeRemoteUri;
+ }
+
+ /**
+ * Fetches the file referenced by {@code fileUri} into {@code destFile}.
+ *
+ * @param fileUri the source URI; a missing scheme is treated as {@code file}
+ * @param destFile the local destination file
+ * @param timeoutMs the connect/read timeout in milliseconds, applied to remote (http/https/ftp)
+ * downloads
+ * @param hadoopConf an {@code org.apache.hadoop.conf.Configuration} instance, required only for
+ * the {@code hdfs} scheme; may be {@code null} when no {@code hdfs} URI is fetched
+ * @return the absolute path of {@code destFile}
+ * @throws IOException if the file cannot be fetched
+ */
+ public static String fetchFileFromUri(
Review Comment:
This is weird for me to use a static variable.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MINOR] improvement(core): validate remote URI host in JobManager before download [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on PR #11354:
URL: https://github.com/apache/gravitino/pull/11354#issuecomment-4667689067
> one question: Should it be a catalog property or a server configuration option?
Some catalogs used the method to fetch files, and the same goes for the Gravitino server, so both catalog properties and server configurations exist.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MINOR] improvement(core): validate remote URI host in JobManager before download [gravitino]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #11354:
URL: https://github.com/apache/gravitino/pull/11354#discussion_r3380143232
##########
core/src/test/java/org/apache/gravitino/job/TestJobManager.java:
##########
@@ -914,6 +933,71 @@ public void testFetchFileFromUriWithMissingLocalFileShouldFail() throws IOExcept
RuntimeException.class, () -> JobManager.fetchFileFromUri(uri, stagingDir, 1000));
}
+ @Test
+ public void testFetchFileFromUriSsrfBlocked() {
+ File stagingDir = new File(testStagingDir);
+ Assertions.assertTrue(stagingDir.mkdirs() || stagingDir.exists());
+
+ // Loopback address
+ RuntimeException e1 =
+ Assertions.assertThrows(
+ RuntimeException.class,
+ () -> JobManager.fetchFileFromUri("http://127.0.0.1:8090/configs", stagingDir, 1000));
+ assertRemoteUriBlockedMessage(e1);
+
+ // AWS / GCP / Azure cloud-metadata endpoint (link-local 169.254.x.x)
+ RuntimeException e2 =
+ Assertions.assertThrows(
+ RuntimeException.class,
+ () ->
+ JobManager.fetchFileFromUri(
+ "http://169.254.169.254/latest/meta-data/", stagingDir, 1000));
+ assertRemoteUriBlockedMessage(e2);
+
+ // RFC-1918 private range
+ RuntimeException e3 =
+ Assertions.assertThrows(
+ RuntimeException.class,
+ () -> JobManager.fetchFileFromUri("http://192.168.1.1/", stagingDir, 1000));
+ assertRemoteUriBlockedMessage(e3);
+
+ // Alibaba Cloud / Oracle Cloud metadata endpoint
+ RuntimeException e4 =
+ Assertions.assertThrows(
+ RuntimeException.class,
+ () -> JobManager.fetchFileFromUri("http://100.100.100.200/", stagingDir, 1000));
+ assertRemoteUriBlockedMessage(e4);
+ }
+
+ @Test
+ public void testFetchFileFromUriShouldAllowLocalhostWhenBlockingDisabled() throws Exception {
+ File stagingDir = new File(testStagingDir);
+ Assertions.assertTrue(stagingDir.mkdirs() || stagingDir.exists());
+ HttpServer server = createLoopbackHttpServer("job artifact");
+
+ try {
+ server.start();
+ int port = server.getAddress().getPort();
+
+ String fetchedFile =
+ JobManager.fetchFileFromUri(
+ String.format("http://127.0.0.1:%d/artifact.jar", port), stagingDir, 1000, false);
+
+ Assertions.assertEquals("job artifact", Files.readString(Path.of(fetchedFile)));
+ } finally {
+ server.stop(0);
+ }
+ }
Review Comment:
PR description says `testValidateRemoteUri()` was added to `TestJobManager`, but this file only adds `testFetchFileFromUriSsrfBlocked()` / `testFetchFileFromUriShouldAllowLocalhostWhenBlockingDisabled()` (and URI validation coverage appears to live in `common/src/test/.../TestRemoteUriValidator`). Please update the PR description or add the mentioned test to avoid confusion for reviewers and release notes.
##########
common/src/main/java/org/apache/gravitino/utils/FetchFileUtils.java:
##########
@@ -0,0 +1,175 @@
+/*
+ * 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.utils;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardCopyOption;
+import java.util.Optional;
+import java.util.concurrent.ConcurrentHashMap;
+import javax.annotation.Nullable;
+import org.apache.commons.io.FileUtils;
+
+/**
+ * Fetches a file referenced by a URI to a local destination. Supports {@code file}, {@code http},
+ * {@code https}, {@code ftp} and {@code hdfs} schemes. This is the single shared implementation
+ * used by the job manager and the Kerberos clients of the Hive, Iceberg, Hadoop and Paimon
+ * catalogs.
+ *
+ * <p>The {@code hdfs} scheme is resolved reflectively against {@code
+ * org.apache.hadoop.fs.FileSystem} so that this class can live in the {@code common} module, which
+ * does not declare a compile-time dependency on Hadoop. Callers that never use {@code hdfs} URIs
+ * (for example the job manager and the Paimon catalog) simply pass {@code null} for the Hadoop
+ * configuration.
+ */
+public final class FetchFileUtils {
+
+ /**
+ * Per-destination lock map used to serialize concurrent symlink creation for the same destination
+ * file. Keyed by the normalized absolute destination path string to avoid races caused by
+ * different path spellings referring to the same file. Entries should be removed via {@link
+ * #removeLock(File)} when the destination file is deleted, so the map size stays bounded by the
+ * number of live consumers.
+ */
+ private static final ConcurrentHashMap<String, Object> SYMLINK_LOCKS = new ConcurrentHashMap<>();
+
+ private FetchFileUtils() {}
+
+ /**
+ * Removes the per-destination lock entry for the given file. Should be called when the
+ * destination file is deleted (for example on a Kerberos client {@code close()}) to prevent
+ * unbounded map growth.
+ *
+ * @param destFile the destination file whose lock entry should be removed
+ */
+ public static void removeLock(File destFile) {
+ SYMLINK_LOCKS.remove(destFile.toPath().toAbsolutePath().normalize().toString());
+ }
+
+ /**
+ * Fetches the file referenced by {@code fileUri} into {@code destFile}.
+ *
+ * @param fileUri the source URI; a missing scheme is treated as {@code file}
+ * @param destFile the local destination file
+ * @param timeoutMs the connect/read timeout in milliseconds, applied to remote (http/https/ftp)
+ * downloads
+ * @param hadoopConf an {@code org.apache.hadoop.conf.Configuration} instance, required only for
+ * the {@code hdfs} scheme; may be {@code null} when no {@code hdfs} URI is fetched
+ * @param blockUnsafeAddress whether to reject remote URIs that resolve to unsafe addresses
+ * @param blockUnsafeAddressHint the configuration hint appended to the validation error message
+ * to tell the caller how to disable unsafe-address blocking
+ * @return the absolute path of {@code destFile}
+ * @throws IOException if the file cannot be fetched
+ */
+ public static String fetchFileFromUri(
+ String fileUri,
+ File destFile,
+ int timeoutMs,
+ @Nullable Object hadoopConf,
+ boolean blockUnsafeAddress,
+ String blockUnsafeAddressHint)
+ throws IOException {
+ try {
+ URI uri = new URI(fileUri);
+ String scheme = Optional.ofNullable(uri.getScheme()).orElse("file");
+
+ switch (scheme) {
+ case "http":
+ case "https":
+ case "ftp":
+ RemoteUriValidator.validate(uri, blockUnsafeAddress, blockUnsafeAddressHint);
+ FileUtils.copyURLToFile(uri.toURL(), destFile, timeoutMs, timeoutMs);
+ break;
Review Comment:
SSRF validation can be bypassed because `copyURLToFile()` may follow HTTP redirects and will perform a fresh DNS resolution at connection time. Currently the code validates only the originally-supplied URI, so a redirect (or DNS rebinding between validation and connection) can still reach blocked/private/metadata IPs.
To make the protection effective, consider implementing the remote download with explicit redirect handling (disable automatic redirects, validate each `Location` hop, and cap redirect count) and/or pin the connection to the validated `InetAddress` instead of re-resolving the hostname during the fetch.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MINOR] improvement(core): validate remote URI host in JobManager before download [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #11354:
URL: https://github.com/apache/gravitino/pull/11354#discussion_r3392606025
##########
common/src/main/java/org/apache/gravitino/utils/RemoteUriValidator.java:
##########
@@ -0,0 +1,92 @@
+/*
+ * 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.utils;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.URI;
+
+/** Validates remote URI hosts before server-side downloads. */
+public final class RemoteUriValidator {
+
+ private RemoteUriValidator() {}
+
+ /**
+ * Resolves the host in the given URI and rejects unsafe addresses when blocking is enabled.
+ *
+ * @param uri The remote URI to validate.
+ * @param blockUnsafeAddress Whether unsafe addresses should be blocked.
+ * @param blockUnsafeAddressHint The configuration hint that disables unsafe address blocking.
+ * @throws IOException If host resolution fails.
+ * @throws IllegalArgumentException If the URI has no host or resolves to an unsafe address.
+ */
+ public static void validate(URI uri, boolean blockUnsafeAddress, String blockUnsafeAddressHint)
+ throws IOException {
+ String host = uri.getHost();
+ if (host == null) {
+ throw new IllegalArgumentException("URI has no host: " + uri);
+ }
+
+ if (!blockUnsafeAddress) {
+ return;
+ }
+
+ InetAddress[] addresses = InetAddress.getAllByName(host);
+ for (InetAddress address : addresses) {
+ if (isUnsafeAddress(address)) {
+ throw new IllegalArgumentException(
+ String.format(
+ "URI '%s' resolves to blocked address %s from the Gravitino server side. "
+ + "Access to local, private, link-local, multicast, unspecified, and cloud "
+ + "metadata addresses is disabled by default to prevent SSRF. If this URI is "
+ + "trusted and this access is required, set %s.",
+ uri, address.getHostAddress(), blockUnsafeAddressHint));
+ }
+ }
+ }
+
+ private static boolean isUnsafeAddress(InetAddress address) {
+ if (address.isLoopbackAddress()
+ || address.isLinkLocalAddress()
+ || address.isSiteLocalAddress()
+ || address.isMulticastAddress()
+ || address.isAnyLocalAddress()) {
+ return true;
+ }
+
+ byte[] bytes = address.getAddress();
+ if (isCloudMetadataAddress(bytes)) {
+ return true;
+ }
+
+ return isIpv6UniqueLocalAddress(bytes);
+ }
Review Comment:
I will postpone this change later.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MINOR] improvement(core): validate remote URI host in JobManager before download [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #11354:
URL: https://github.com/apache/gravitino/pull/11354#discussion_r3395453027
##########
common/src/main/java/org/apache/gravitino/utils/FetchFileUtils.java:
##########
@@ -0,0 +1,161 @@
+/*
+ * 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.utils;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardCopyOption;
+import java.util.Optional;
+import javax.annotation.Nullable;
+import org.apache.commons.io.FileUtils;
+
+/**
+ * Fetches a file referenced by a URI to a local destination. Supports {@code file}, {@code http},
+ * {@code https}, {@code ftp} and {@code hdfs} schemes. This is the single shared implementation
+ * used by the job manager and the Kerberos clients of the Hive, Iceberg, Hadoop and Paimon
+ * catalogs.
+ *
+ * <p>The {@code hdfs} scheme is resolved reflectively against {@code
+ * org.apache.hadoop.fs.FileSystem} so that this class can live in the {@code common} module, which
+ * does not declare a compile-time dependency on Hadoop. Callers that never use {@code hdfs} URIs
+ * (for example the job manager and the Paimon catalog) simply pass {@code null} for the Hadoop
+ * configuration.
+ */
+public final class FetchFileUtils {
+
+ /** The server configuration that controls unsafe remote URI blocking. */
+ public static final String BLOCK_UNSAFE_REMOTE_URI_CONFIG =
+ "gravitino.fetchFile.blockUnsafeRemoteUri";
+
+ private static volatile boolean blockUnsafeRemoteUri = true;
+
+ private FetchFileUtils() {}
+
+ /**
+ * Sets whether remote URIs that resolve to unsafe addresses should be blocked.
+ *
+ * @param blockUnsafeRemoteUri whether to block unsafe remote URIs
+ */
+ public static void setBlockUnsafeRemoteUri(boolean blockUnsafeRemoteUri) {
Review Comment:
No. We used this method to set it as false(The default is true)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MINOR] improvement(core): validate remote URI host in JobManager before download [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #11354:
URL: https://github.com/apache/gravitino/pull/11354#discussion_r3395716238
##########
common/src/main/java/org/apache/gravitino/utils/FetchFileUtils.java:
##########
@@ -0,0 +1,161 @@
+/*
+ * 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.utils;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardCopyOption;
+import java.util.Optional;
+import javax.annotation.Nullable;
+import org.apache.commons.io.FileUtils;
+
+/**
+ * Fetches a file referenced by a URI to a local destination. Supports {@code file}, {@code http},
+ * {@code https}, {@code ftp} and {@code hdfs} schemes. This is the single shared implementation
+ * used by the job manager and the Kerberos clients of the Hive, Iceberg, Hadoop and Paimon
+ * catalogs.
+ *
+ * <p>The {@code hdfs} scheme is resolved reflectively against {@code
+ * org.apache.hadoop.fs.FileSystem} so that this class can live in the {@code common} module, which
+ * does not declare a compile-time dependency on Hadoop. Callers that never use {@code hdfs} URIs
+ * (for example the job manager and the Paimon catalog) simply pass {@code null} for the Hadoop
+ * configuration.
+ */
+public final class FetchFileUtils {
+
+ /** The server configuration that controls unsafe remote URI blocking. */
+ public static final String BLOCK_UNSAFE_REMOTE_URI_CONFIG =
+ "gravitino.fetchFile.blockUnsafeRemoteUri";
+
+ private static volatile boolean blockUnsafeRemoteUri = true;
+
+ private FetchFileUtils() {}
+
+ /**
+ * Sets whether remote URIs that resolve to unsafe addresses should be blocked.
+ *
+ * @param blockUnsafeRemoteUri whether to block unsafe remote URIs
+ */
+ public static void setBlockUnsafeRemoteUri(boolean blockUnsafeRemoteUri) {
+ FetchFileUtils.blockUnsafeRemoteUri = blockUnsafeRemoteUri;
+ }
+
+ /**
+ * Fetches the file referenced by {@code fileUri} into {@code destFile}.
+ *
+ * @param fileUri the source URI; a missing scheme is treated as {@code file}
+ * @param destFile the local destination file
+ * @param timeoutMs the connect/read timeout in milliseconds, applied to remote (http/https/ftp)
+ * downloads
+ * @param hadoopConf an {@code org.apache.hadoop.conf.Configuration} instance, required only for
+ * the {@code hdfs} scheme; may be {@code null} when no {@code hdfs} URI is fetched
+ * @return the absolute path of {@code destFile}
+ * @throws IOException if the file cannot be fetched
+ */
+ public static String fetchFileFromUri(
Review Comment:
> You can put it to GravitinoEnv? It is weird now.
Okay, let me take a try.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MINOR] improvement(core): validate remote URI host in JobManager before download [gravitino]
Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on code in PR #11354:
URL: https://github.com/apache/gravitino/pull/11354#discussion_r3397645225
##########
core/src/main/java/org/apache/gravitino/GravitinoEnv.java:
##########
@@ -545,6 +545,15 @@ public boolean cacheEnabled() {
return config == null || config.get(Configs.CACHE_ENABLED);
}
+ /**
+ * Returns whether remote URIs that resolve to unsafe addresses should be blocked.
+ *
+ * @return whether unsafe remote URIs should be blocked
+ */
+ public boolean blockUnsafeRemoteUri() {
+ return config == null || !Boolean.FALSE.equals(config.get(Configs.BLOCK_UNSAFE_REMOTE_URI));
Review Comment:
I'm curious why can't we use `return config == null || config.get(Configs.BLOCK_UNSAFE_REMOTE_URI);`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MINOR] improvement(core): validate remote URI host in JobManager before download [gravitino]
Posted by "roryqi (via GitHub)" <gi...@apache.org>.
roryqi commented on code in PR #11354:
URL: https://github.com/apache/gravitino/pull/11354#discussion_r3400167077
##########
catalogs/catalog-fileset/src/main/java/org/apache/gravitino/catalog/fileset/FilesetCatalogOperations.java:
##########
@@ -1386,7 +1386,10 @@ FileSystem getFileSystem(Path path, Map<String, String> config) throws IOExcepti
() -> {
if (scheme.equals(SCHEME_HDFS)) {
return new ImpersonationHDFSFileSystemProxy(
- path, config, PrincipalUtils::getCurrentUserName)
+ path,
+ config,
+ PrincipalUtils::getCurrentUserName,
+ GravitinoEnv.getInstance().blockUnsafeRemoteUri())
Review Comment:
Maybe we can change this to singleton factory.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MINOR] improvement(core): validate remote URI host in JobManager before download [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #11354:
URL: https://github.com/apache/gravitino/pull/11354#discussion_r3395447356
##########
docs/apache-hive-catalog.md:
##########
@@ -29,19 +29,19 @@ The Hive catalog supports creating, updating, and deleting databases and tables
Besides the [common catalog properties](./gravitino-server-config.md#catalog-properties-configuration), the Hive catalog has the following properties:
-| Property Name | Description | Default Value | Required | Since Version |
-|------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------|------------------------------|---------------|
-| `metastore.uris` | The Hive metastore service URIs, separate multiple addresses with commas. Such as `thrift://127.0.0.1:9083` | (none) | Yes | 0.2.0 |
-| `client.pool-size` | The maximum number of Hive metastore clients in the pool for Gravitino. | 1 | No | 0.2.0 |
-| `gravitino.bypass.` | Property name with this prefix passed down to the underlying HMS client for use. Such as `gravitino.bypass.hive.metastore.failure.retries = 3` indicate 3 times of retries upon failure of Thrift metastore calls | (none) | No | 0.2.0 |
-| `client.pool-cache.eviction-interval-ms` | The cache pool eviction interval. | 300000 | No | 0.4.0 |
-| `impersonation-enable` | Enable user impersonation for Hive catalog. | false | No | 0.4.0 |
-| `kerberos.principal` | The Kerberos principal for the catalog. You should configure `gravitino.bypass.hadoop.security.authentication`, `gravitino.bypass.hive.metastore.kerberos.principal` and `gravitino.bypass.hive.metastore.sasl.enabled`if you want to use Kerberos. | (none) | required if you use kerberos | 0.4.0 |
-| `kerberos.keytab-uri` | The uri of key tab for the catalog. Now supported protocols are `https`, `http`, `ftp`, `file`. | (none) | required if you use kerberos | 0.4.0 |
-| `kerberos.check-interval-sec` | The interval to check validness of the principal | 60 | No | 0.4.0 |
-| `kerberos.keytab-fetch-timeout-sec` | The timeout to fetch key tab | 60 | No | 0.4.0 |
-| `list-all-tables` | Whether to list all tables in a database, including non-Hive tables such as Iceberg, Paimon, and Hudi. When false, non-Hive tables are filtered out on a best-effort basis; see the note below for known limitations. | false | No | 0.5.1 |
-| `default.catalog` | The default catalog name for the Hive3 metastore backend; this configuration is ignored when using a Hive2 metastore. | hive | No | 1.1.0 |
+| Property Name | Description | Default Value | Required | Since Version |
Review Comment:
I removed some empty lines in the table by the way.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MINOR] improvement(core): validate remote URI host in JobManager before download [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #11354:
URL: https://github.com/apache/gravitino/pull/11354#discussion_r3392623764
##########
common/src/main/java/org/apache/gravitino/utils/FetchFileUtils.java:
##########
@@ -0,0 +1,184 @@
+/*
+ * 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.utils;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardCopyOption;
+import java.util.Optional;
+import java.util.concurrent.ConcurrentHashMap;
+import javax.annotation.Nullable;
+import org.apache.commons.io.FileUtils;
+
+/**
+ * Fetches a file referenced by a URI to a local destination. Supports {@code file}, {@code http},
+ * {@code https}, {@code ftp} and {@code hdfs} schemes. This is the single shared implementation
+ * used by the job manager and the Kerberos clients of the Hive, Iceberg, Hadoop and Paimon
+ * catalogs.
+ *
+ * <p>The {@code hdfs} scheme is resolved reflectively against {@code
+ * org.apache.hadoop.fs.FileSystem} so that this class can live in the {@code common} module, which
+ * does not declare a compile-time dependency on Hadoop. Callers that never use {@code hdfs} URIs
+ * (for example the job manager and the Paimon catalog) simply pass {@code null} for the Hadoop
+ * configuration.
+ */
+public final class FetchFileUtils {
+
+ /** The server configuration that controls unsafe remote URI blocking. */
+ public static final String BLOCK_UNSAFE_REMOTE_URI_CONFIG = "gravitino.blockUnsafeRemoteUri";
+
+ /**
+ * Per-destination lock map used to serialize concurrent symlink creation for the same destination
+ * file. Keyed by the normalized absolute destination path string to avoid races caused by
+ * different path spellings referring to the same file. Entries should be removed via {@link
+ * #removeLock(File)} when the destination file is deleted, so the map size stays bounded by the
+ * number of live consumers.
+ */
+ private static final ConcurrentHashMap<String, Object> SYMLINK_LOCKS = new ConcurrentHashMap<>();
+
+ private static volatile boolean blockUnsafeRemoteUri = true;
+
+ private FetchFileUtils() {}
+
+ /**
+ * Sets whether remote URIs that resolve to unsafe addresses should be blocked.
+ *
+ * @param blockUnsafeRemoteUri whether to block unsafe remote URIs
+ */
+ public static void setBlockUnsafeRemoteUri(boolean blockUnsafeRemoteUri) {
+ FetchFileUtils.blockUnsafeRemoteUri = blockUnsafeRemoteUri;
+ }
+
+ /**
+ * Removes the per-destination lock entry for the given file. Should be called when the
+ * destination file is deleted (for example on a Kerberos client {@code close()}) to prevent
+ * unbounded map growth.
+ *
+ * @param destFile the destination file whose lock entry should be removed
+ */
+ public static void removeLock(File destFile) {
+ SYMLINK_LOCKS.remove(destFile.toPath().toAbsolutePath().normalize().toString());
+ }
+
+ /**
+ * Fetches the file referenced by {@code fileUri} into {@code destFile}.
+ *
+ * @param fileUri the source URI; a missing scheme is treated as {@code file}
+ * @param destFile the local destination file
+ * @param timeoutMs the connect/read timeout in milliseconds, applied to remote (http/https/ftp)
+ * downloads
+ * @param hadoopConf an {@code org.apache.hadoop.conf.Configuration} instance, required only for
+ * the {@code hdfs} scheme; may be {@code null} when no {@code hdfs} URI is fetched
+ * @return the absolute path of {@code destFile}
+ * @throws IOException if the file cannot be fetched
+ */
+ public static String fetchFileFromUri(
+ String fileUri, File destFile, int timeoutMs, @Nullable Object hadoopConf)
+ throws IOException {
+ try {
+ URI uri = new URI(fileUri);
+ String scheme = Optional.ofNullable(uri.getScheme()).orElse("file");
+
+ switch (scheme) {
+ case "http":
+ case "https":
+ case "ftp":
+ RemoteUriValidator.validate(
+ uri,
+ blockUnsafeRemoteUri,
+ String.format("'%s' to false", BLOCK_UNSAFE_REMOTE_URI_CONFIG));
+ FileUtils.copyURLToFile(uri.toURL(), destFile, timeoutMs, timeoutMs);
+ break;
+
+ case "file":
+ linkLocalFile(uri, destFile);
+ break;
+
+ case "hdfs":
+ copyHdfsFileToLocal(uri, destFile, hadoopConf);
+ break;
+
+ default:
+ throw new IllegalArgumentException(
+ String.format("The scheme '%s' is not supported", scheme));
+ }
+
+ return destFile.getAbsolutePath();
+ } catch (URISyntaxException ue) {
+ throw new IllegalArgumentException("The uri of file has the wrong format", ue);
+ }
+ }
+
+ private static void linkLocalFile(URI uri, File destFile) throws IOException {
+ Path srcPath = new File(uri.getPath()).toPath().normalize();
+ if (!Files.exists(srcPath)) {
+ throw new IOException(
+ String.format("Source file does not exist: %s", srcPath.toAbsolutePath()));
+ }
+
+ Path destPath = destFile.toPath().toAbsolutePath().normalize();
+ Object lock = SYMLINK_LOCKS.computeIfAbsent(destPath.toString(), k -> new Object());
+ synchronized (lock) {
+ // Skip if the symlink already points to the correct target.
+ if (Files.isSymbolicLink(destPath)
+ && Files.readSymbolicLink(destPath).normalize().equals(srcPath)) {
+ return;
+ }
+ // Replace via a temporary symlink + rename to minimize the window where the destination path
+ // is absent (which could otherwise cause a concurrent reader, e.g. loginUserFromKeytab, to
+ // fail). REPLACE_EXISTING is used here; on common local filesystems (ext4, xfs, APFS) a
+ // same-directory rename is effectively atomic at the OS level.
+ Path tmpPath = destPath.resolveSibling(destPath.getFileName() + ".symlink.tmp");
+ Files.deleteIfExists(tmpPath);
+ Files.createSymbolicLink(tmpPath, srcPath);
+ Files.move(tmpPath, destPath, StandardCopyOption.REPLACE_EXISTING);
+ }
+ }
Review Comment:
Changed as suggested.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MINOR] improvement(core): validate remote URI host in JobManager before download [gravitino]
Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on code in PR #11354:
URL: https://github.com/apache/gravitino/pull/11354#discussion_r3392230193
##########
common/src/main/java/org/apache/gravitino/utils/FetchFileUtils.java:
##########
@@ -0,0 +1,184 @@
+/*
+ * 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.utils;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardCopyOption;
+import java.util.Optional;
+import java.util.concurrent.ConcurrentHashMap;
+import javax.annotation.Nullable;
+import org.apache.commons.io.FileUtils;
+
+/**
+ * Fetches a file referenced by a URI to a local destination. Supports {@code file}, {@code http},
+ * {@code https}, {@code ftp} and {@code hdfs} schemes. This is the single shared implementation
+ * used by the job manager and the Kerberos clients of the Hive, Iceberg, Hadoop and Paimon
+ * catalogs.
+ *
+ * <p>The {@code hdfs} scheme is resolved reflectively against {@code
+ * org.apache.hadoop.fs.FileSystem} so that this class can live in the {@code common} module, which
+ * does not declare a compile-time dependency on Hadoop. Callers that never use {@code hdfs} URIs
+ * (for example the job manager and the Paimon catalog) simply pass {@code null} for the Hadoop
+ * configuration.
+ */
+public final class FetchFileUtils {
+
+ /** The server configuration that controls unsafe remote URI blocking. */
+ public static final String BLOCK_UNSAFE_REMOTE_URI_CONFIG = "gravitino.blockUnsafeRemoteUri";
+
+ /**
+ * Per-destination lock map used to serialize concurrent symlink creation for the same destination
+ * file. Keyed by the normalized absolute destination path string to avoid races caused by
+ * different path spellings referring to the same file. Entries should be removed via {@link
+ * #removeLock(File)} when the destination file is deleted, so the map size stays bounded by the
+ * number of live consumers.
+ */
+ private static final ConcurrentHashMap<String, Object> SYMLINK_LOCKS = new ConcurrentHashMap<>();
+
+ private static volatile boolean blockUnsafeRemoteUri = true;
+
+ private FetchFileUtils() {}
+
+ /**
+ * Sets whether remote URIs that resolve to unsafe addresses should be blocked.
+ *
+ * @param blockUnsafeRemoteUri whether to block unsafe remote URIs
+ */
+ public static void setBlockUnsafeRemoteUri(boolean blockUnsafeRemoteUri) {
+ FetchFileUtils.blockUnsafeRemoteUri = blockUnsafeRemoteUri;
+ }
+
+ /**
+ * Removes the per-destination lock entry for the given file. Should be called when the
+ * destination file is deleted (for example on a Kerberos client {@code close()}) to prevent
+ * unbounded map growth.
+ *
+ * @param destFile the destination file whose lock entry should be removed
+ */
+ public static void removeLock(File destFile) {
+ SYMLINK_LOCKS.remove(destFile.toPath().toAbsolutePath().normalize().toString());
+ }
Review Comment:
Who will call this method, I don't see any code calling this method.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MINOR] improvement(core): validate remote URI host in JobManager before download [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #11354:
URL: https://github.com/apache/gravitino/pull/11354#discussion_r3392556293
##########
common/src/main/java/org/apache/gravitino/utils/FetchFileUtils.java:
##########
@@ -0,0 +1,184 @@
+/*
+ * 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.utils;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardCopyOption;
+import java.util.Optional;
+import java.util.concurrent.ConcurrentHashMap;
+import javax.annotation.Nullable;
+import org.apache.commons.io.FileUtils;
+
+/**
+ * Fetches a file referenced by a URI to a local destination. Supports {@code file}, {@code http},
+ * {@code https}, {@code ftp} and {@code hdfs} schemes. This is the single shared implementation
+ * used by the job manager and the Kerberos clients of the Hive, Iceberg, Hadoop and Paimon
+ * catalogs.
+ *
+ * <p>The {@code hdfs} scheme is resolved reflectively against {@code
+ * org.apache.hadoop.fs.FileSystem} so that this class can live in the {@code common} module, which
+ * does not declare a compile-time dependency on Hadoop. Callers that never use {@code hdfs} URIs
+ * (for example the job manager and the Paimon catalog) simply pass {@code null} for the Hadoop
+ * configuration.
+ */
+public final class FetchFileUtils {
+
+ /** The server configuration that controls unsafe remote URI blocking. */
+ public static final String BLOCK_UNSAFE_REMOTE_URI_CONFIG = "gravitino.blockUnsafeRemoteUri";
+
+ /**
+ * Per-destination lock map used to serialize concurrent symlink creation for the same destination
+ * file. Keyed by the normalized absolute destination path string to avoid races caused by
+ * different path spellings referring to the same file. Entries should be removed via {@link
+ * #removeLock(File)} when the destination file is deleted, so the map size stays bounded by the
+ * number of live consumers.
+ */
+ private static final ConcurrentHashMap<String, Object> SYMLINK_LOCKS = new ConcurrentHashMap<>();
+
+ private static volatile boolean blockUnsafeRemoteUri = true;
+
+ private FetchFileUtils() {}
+
+ /**
+ * Sets whether remote URIs that resolve to unsafe addresses should be blocked.
+ *
+ * @param blockUnsafeRemoteUri whether to block unsafe remote URIs
+ */
+ public static void setBlockUnsafeRemoteUri(boolean blockUnsafeRemoteUri) {
+ FetchFileUtils.blockUnsafeRemoteUri = blockUnsafeRemoteUri;
+ }
+
+ /**
+ * Removes the per-destination lock entry for the given file. Should be called when the
+ * destination file is deleted (for example on a Kerberos client {@code close()}) to prevent
+ * unbounded map growth.
+ *
+ * @param destFile the destination file whose lock entry should be removed
+ */
+ public static void removeLock(File destFile) {
+ SYMLINK_LOCKS.remove(destFile.toPath().toAbsolutePath().normalize().toString());
+ }
Review Comment:
The `close` method in class `KerberosClient` will call it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MINOR] improvement(core): validate remote URI host in JobManager before download [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #11354:
URL: https://github.com/apache/gravitino/pull/11354#discussion_r3400460295
##########
catalogs/catalog-fileset/src/main/java/org/apache/gravitino/catalog/fileset/FilesetCatalogOperations.java:
##########
@@ -1386,7 +1386,10 @@ FileSystem getFileSystem(Path path, Map<String, String> config) throws IOExcepti
() -> {
if (scheme.equals(SCHEME_HDFS)) {
return new ImpersonationHDFSFileSystemProxy(
- path, config, PrincipalUtils::getCurrentUserName)
+ path,
+ config,
+ PrincipalUtils::getCurrentUserName,
+ GravitinoEnv.getInstance().blockUnsafeRemoteUri())
Review Comment:
OK, that means it won't be a utils class but a singleton instance.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MINOR] improvement(core): validate remote URI host in JobManager before download [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #11354:
URL: https://github.com/apache/gravitino/pull/11354#discussion_r3354196409
##########
core/src/main/java/org/apache/gravitino/job/JobManager.java:
##########
@@ -830,6 +832,57 @@ static String fetchFileFromUri(String uri, File stagingDir, int timeoutInMs) {
}
}
+ /**
+ * Resolves the host in the given URI and rejects addresses that should not be reachable from the
+ * server (loopback, link-local, RFC-1918 private ranges, IPv6 ULA, cloud metadata endpoints).
+ * This is a defence-in-depth measure against Server-Side Request Forgery (SSRF).
+ *
+ * <p><b>Note on DNS TOCTOU:</b> This method resolves the hostname once at validation time. {@code
+ * FileUtils.copyURLToFile()} will re-resolve it when opening the connection, so a precisely-timed
+ * DNS-rebinding attack could theoretically bypass this check. Complete protection against DNS
+ * rebinding requires network-level egress controls (e.g. firewall rules) in addition to this
+ * application-layer validation.
+ */
+ @VisibleForTesting
+ static void validateRemoteUri(URI uri) throws IOException {
+ String host = uri.getHost();
+ if (host == null) {
+ throw new IllegalArgumentException("URI has no host: " + uri);
+ }
+ InetAddress[] addresses = InetAddress.getAllByName(host);
+ for (InetAddress address : addresses) {
+ if (isBlockedAddress(address)) {
+ throw new IllegalArgumentException(
+ String.format(
+ "URI '%s' resolves to blocked address %s, access denied (SSRF prevention)",
+ uri, address.getHostAddress()));
+ }
+ }
+ }
+
+ private static boolean isBlockedAddress(InetAddress address) {
+ // Covers loopback (127.x.x.x / ::1), link-local (169.254.x.x / fe80::/10 — includes AWS/GCP/
+ // Azure metadata), RFC-1918 private (10.x / 172.16-31.x / 192.168.x), multicast, unspecified.
+ if (address.isLoopbackAddress()
+ || address.isLinkLocalAddress()
+ || address.isSiteLocalAddress()
+ || address.isMulticastAddress()
+ || address.isAnyLocalAddress()) {
+ return true;
Review Comment:
The main risk is SSRF. `localhost` or a private IP is resolved from the Gravitino server side, not from the user's machine.
So if a user passes `http://127.0.0.1:xxx` or `http://192.168.x.x`, Gravitino will try to access services on the Gravitino server itself or inside the server's internal network. This may expose local admin services, internal APIs, or cloud metadata endpoints.
I agree that some deployments may want to fetch files from a local HTTP/FTP server. But I think this should be disabled by default, and only enabled explicitly by an admin, for example with an allowlist/configuration. If we reach an agreement on this point, I can do as it is.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MINOR] improvement(core): validate remote URI host in JobManager before download [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #11354:
URL: https://github.com/apache/gravitino/pull/11354#discussion_r3354200858
##########
core/src/main/java/org/apache/gravitino/job/JobManager.java:
##########
@@ -808,6 +809,7 @@ static String fetchFileFromUri(String uri, File stagingDir, int timeoutInMs) {
case "http":
case "https":
case "ftp":
+ validateRemoteUri(fileUri);
Review Comment:
Got it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MINOR] improvement(core): validate remote URI host in JobManager before download [gravitino]
Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on code in PR #11354:
URL: https://github.com/apache/gravitino/pull/11354#discussion_r3370694089
##########
catalogs/hive-metastore-common/src/main/java/org/apache/gravitino/hive/kerberos/FetchFileUtils.java:
##########
Review Comment:
Can we dedup this java class file into one?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MINOR] improvement(core): validate remote URI host in JobManager before download [gravitino]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #11354:
URL: https://github.com/apache/gravitino/pull/11354#issuecomment-4602830448
<!-- coverage-report -->
### Code Coverage Report
|Overall Project|66.81% **`+0.12%`**|:green_circle:|
|:-|:-|:-:|
|Files changed|85.93%|:green_circle:|
<br>
|Module|Coverage||
|:-|:-|:-:|
|aliyun|1.72%|:red_circle:|
|api|46.82%|:green_circle:|
|authorization-common|85.96%|:green_circle:|
|aws|3.66%|:red_circle:|
|azure|2.47%|:red_circle:|
|catalog-common|10.04%|:red_circle:|
|catalog-fileset|80.33%|:green_circle:|
|catalog-glue|66.08%|:green_circle:|
|catalog-hive|79.55%|:green_circle:|
|catalog-jdbc-clickhouse|80.02%|:green_circle:|
|catalog-jdbc-common|45.31%|:green_circle:|
|catalog-jdbc-doris|80.28%|:green_circle:|
|catalog-jdbc-hologres|54.03%|:green_circle:|
|catalog-jdbc-mysql|79.23%|:green_circle:|
|catalog-jdbc-oceanbase|78.38%|:green_circle:|
|catalog-jdbc-postgresql|82.29%|:green_circle:|
|catalog-jdbc-starrocks|78.51%|:green_circle:|
|catalog-kafka|77.01%|:green_circle:|
|catalog-lakehouse-generic|44.89%|:green_circle:|
|catalog-lakehouse-hudi|79.1%|:green_circle:|
|catalog-lakehouse-iceberg|85.66%|:green_circle:|
|catalog-lakehouse-paimon|79.29%|:green_circle:|
|catalog-model|77.72%|:green_circle:|
|cli|44.51%|:green_circle:|
|client-java|77.91%|:green_circle:|
|common|49.99%|:green_circle:|
|core|82.49% **`+0.07%`**|:green_circle:|
|filesystem-hadoop3|76.97%|:green_circle:|
|flink|0.0%|:red_circle:|
|flink-common|41.2%|:green_circle:|
|flink-runtime|0.0%|:red_circle:|
|gcp|14.12%|:red_circle:|
|hadoop-common|10.39%|:red_circle:|
|hive-metastore-common|53.26%|:green_circle:|
|iceberg-common|56.75%|:green_circle:|
|iceberg-rest-server|72.42%|:green_circle:|
|idp-basic|85.99%|:green_circle:|
|integration-test-common|0.0%|:red_circle:|
|jobs|66.17%|:green_circle:|
|lance-common|20.83%|:red_circle:|
|lance-rest-server|60.27%|:green_circle:|
|lineage|53.02%|:green_circle:|
|optimizer|82.95%|:green_circle:|
|optimizer-api|21.95%|:red_circle:|
|server|85.73%|:green_circle:|
|server-common|73.13%|:green_circle:|
|spark|32.79%|:red_circle:|
|spark-common|39.75%|:red_circle:|
|trino-connector|39.44%|:red_circle:|
<details>
<summary>Files</summary>
|Module|File|Coverage||
|:-|:-|:-|:-:|
|core|[JobManager.java](https://github.com/yuqi1129/gravitino/blob/a245be193d018f63efe6ac85cafa5de6465d7e61/core/src/main/java/org/apache/gravitino/job/JobManager.java)|85.93%|:green_circle:|
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MINOR] improvement(core): validate remote URI host in JobManager before download [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #11354:
URL: https://github.com/apache/gravitino/pull/11354#discussion_r3392608361
##########
common/src/main/java/org/apache/gravitino/utils/FetchFileUtils.java:
##########
@@ -0,0 +1,184 @@
+/*
+ * 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.utils;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardCopyOption;
+import java.util.Optional;
+import java.util.concurrent.ConcurrentHashMap;
+import javax.annotation.Nullable;
+import org.apache.commons.io.FileUtils;
+
+/**
+ * Fetches a file referenced by a URI to a local destination. Supports {@code file}, {@code http},
+ * {@code https}, {@code ftp} and {@code hdfs} schemes. This is the single shared implementation
+ * used by the job manager and the Kerberos clients of the Hive, Iceberg, Hadoop and Paimon
+ * catalogs.
+ *
+ * <p>The {@code hdfs} scheme is resolved reflectively against {@code
+ * org.apache.hadoop.fs.FileSystem} so that this class can live in the {@code common} module, which
+ * does not declare a compile-time dependency on Hadoop. Callers that never use {@code hdfs} URIs
+ * (for example the job manager and the Paimon catalog) simply pass {@code null} for the Hadoop
+ * configuration.
+ */
+public final class FetchFileUtils {
+
+ /** The server configuration that controls unsafe remote URI blocking. */
+ public static final String BLOCK_UNSAFE_REMOTE_URI_CONFIG = "gravitino.blockUnsafeRemoteUri";
+
+ /**
+ * Per-destination lock map used to serialize concurrent symlink creation for the same destination
+ * file. Keyed by the normalized absolute destination path string to avoid races caused by
+ * different path spellings referring to the same file. Entries should be removed via {@link
+ * #removeLock(File)} when the destination file is deleted, so the map size stays bounded by the
+ * number of live consumers.
+ */
+ private static final ConcurrentHashMap<String, Object> SYMLINK_LOCKS = new ConcurrentHashMap<>();
+
+ private static volatile boolean blockUnsafeRemoteUri = true;
+
+ private FetchFileUtils() {}
+
+ /**
+ * Sets whether remote URIs that resolve to unsafe addresses should be blocked.
+ *
+ * @param blockUnsafeRemoteUri whether to block unsafe remote URIs
+ */
+ public static void setBlockUnsafeRemoteUri(boolean blockUnsafeRemoteUri) {
+ FetchFileUtils.blockUnsafeRemoteUri = blockUnsafeRemoteUri;
+ }
+
+ /**
+ * Removes the per-destination lock entry for the given file. Should be called when the
+ * destination file is deleted (for example on a Kerberos client {@code close()}) to prevent
+ * unbounded map growth.
+ *
+ * @param destFile the destination file whose lock entry should be removed
+ */
+ public static void removeLock(File destFile) {
+ SYMLINK_LOCKS.remove(destFile.toPath().toAbsolutePath().normalize().toString());
+ }
+
+ /**
+ * Fetches the file referenced by {@code fileUri} into {@code destFile}.
+ *
+ * @param fileUri the source URI; a missing scheme is treated as {@code file}
+ * @param destFile the local destination file
+ * @param timeoutMs the connect/read timeout in milliseconds, applied to remote (http/https/ftp)
+ * downloads
+ * @param hadoopConf an {@code org.apache.hadoop.conf.Configuration} instance, required only for
+ * the {@code hdfs} scheme; may be {@code null} when no {@code hdfs} URI is fetched
+ * @return the absolute path of {@code destFile}
+ * @throws IOException if the file cannot be fetched
+ */
+ public static String fetchFileFromUri(
+ String fileUri, File destFile, int timeoutMs, @Nullable Object hadoopConf)
+ throws IOException {
+ try {
+ URI uri = new URI(fileUri);
+ String scheme = Optional.ofNullable(uri.getScheme()).orElse("file");
+
+ switch (scheme) {
+ case "http":
+ case "https":
+ case "ftp":
+ RemoteUriValidator.validate(
+ uri,
+ blockUnsafeRemoteUri,
+ String.format("'%s' to false", BLOCK_UNSAFE_REMOTE_URI_CONFIG));
+ FileUtils.copyURLToFile(uri.toURL(), destFile, timeoutMs, timeoutMs);
Review Comment:
This case is rather rare, and I will leave it unchanged.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MINOR] improvement(core): validate remote URI host in JobManager before download [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #11354:
URL: https://github.com/apache/gravitino/pull/11354#discussion_r3392582660
##########
common/src/main/java/org/apache/gravitino/utils/FetchFileUtils.java:
##########
@@ -0,0 +1,184 @@
+/*
+ * 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.utils;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardCopyOption;
+import java.util.Optional;
+import java.util.concurrent.ConcurrentHashMap;
+import javax.annotation.Nullable;
+import org.apache.commons.io.FileUtils;
+
+/**
+ * Fetches a file referenced by a URI to a local destination. Supports {@code file}, {@code http},
+ * {@code https}, {@code ftp} and {@code hdfs} schemes. This is the single shared implementation
+ * used by the job manager and the Kerberos clients of the Hive, Iceberg, Hadoop and Paimon
+ * catalogs.
+ *
+ * <p>The {@code hdfs} scheme is resolved reflectively against {@code
+ * org.apache.hadoop.fs.FileSystem} so that this class can live in the {@code common} module, which
+ * does not declare a compile-time dependency on Hadoop. Callers that never use {@code hdfs} URIs
+ * (for example the job manager and the Paimon catalog) simply pass {@code null} for the Hadoop
+ * configuration.
+ */
+public final class FetchFileUtils {
+
+ /** The server configuration that controls unsafe remote URI blocking. */
+ public static final String BLOCK_UNSAFE_REMOTE_URI_CONFIG = "gravitino.blockUnsafeRemoteUri";
+
+ /**
+ * Per-destination lock map used to serialize concurrent symlink creation for the same destination
+ * file. Keyed by the normalized absolute destination path string to avoid races caused by
+ * different path spellings referring to the same file. Entries should be removed via {@link
+ * #removeLock(File)} when the destination file is deleted, so the map size stays bounded by the
+ * number of live consumers.
+ */
+ private static final ConcurrentHashMap<String, Object> SYMLINK_LOCKS = new ConcurrentHashMap<>();
+
+ private static volatile boolean blockUnsafeRemoteUri = true;
+
+ private FetchFileUtils() {}
+
+ /**
+ * Sets whether remote URIs that resolve to unsafe addresses should be blocked.
+ *
+ * @param blockUnsafeRemoteUri whether to block unsafe remote URIs
+ */
+ public static void setBlockUnsafeRemoteUri(boolean blockUnsafeRemoteUri) {
+ FetchFileUtils.blockUnsafeRemoteUri = blockUnsafeRemoteUri;
+ }
+
+ /**
+ * Removes the per-destination lock entry for the given file. Should be called when the
+ * destination file is deleted (for example on a Kerberos client {@code close()}) to prevent
+ * unbounded map growth.
+ *
+ * @param destFile the destination file whose lock entry should be removed
+ */
+ public static void removeLock(File destFile) {
+ SYMLINK_LOCKS.remove(destFile.toPath().toAbsolutePath().normalize().toString());
+ }
Review Comment:
I will remove it as you suggested using the `synchronized ` keyword below.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MINOR] improvement(core): validate remote URI host in JobManager before download [gravitino]
Posted by "roryqi (via GitHub)" <gi...@apache.org>.
roryqi commented on code in PR #11354:
URL: https://github.com/apache/gravitino/pull/11354#discussion_r3395320978
##########
docs/apache-hive-catalog.md:
##########
@@ -29,19 +29,19 @@ The Hive catalog supports creating, updating, and deleting databases and tables
Besides the [common catalog properties](./gravitino-server-config.md#catalog-properties-configuration), the Hive catalog has the following properties:
-| Property Name | Description | Default Value | Required | Since Version |
-|------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------|------------------------------|---------------|
-| `metastore.uris` | The Hive metastore service URIs, separate multiple addresses with commas. Such as `thrift://127.0.0.1:9083` | (none) | Yes | 0.2.0 |
-| `client.pool-size` | The maximum number of Hive metastore clients in the pool for Gravitino. | 1 | No | 0.2.0 |
-| `gravitino.bypass.` | Property name with this prefix passed down to the underlying HMS client for use. Such as `gravitino.bypass.hive.metastore.failure.retries = 3` indicate 3 times of retries upon failure of Thrift metastore calls | (none) | No | 0.2.0 |
-| `client.pool-cache.eviction-interval-ms` | The cache pool eviction interval. | 300000 | No | 0.4.0 |
-| `impersonation-enable` | Enable user impersonation for Hive catalog. | false | No | 0.4.0 |
-| `kerberos.principal` | The Kerberos principal for the catalog. You should configure `gravitino.bypass.hadoop.security.authentication`, `gravitino.bypass.hive.metastore.kerberos.principal` and `gravitino.bypass.hive.metastore.sasl.enabled`if you want to use Kerberos. | (none) | required if you use kerberos | 0.4.0 |
-| `kerberos.keytab-uri` | The uri of key tab for the catalog. Now supported protocols are `https`, `http`, `ftp`, `file`. | (none) | required if you use kerberos | 0.4.0 |
-| `kerberos.check-interval-sec` | The interval to check validness of the principal | 60 | No | 0.4.0 |
-| `kerberos.keytab-fetch-timeout-sec` | The timeout to fetch key tab | 60 | No | 0.4.0 |
-| `list-all-tables` | Whether to list all tables in a database, including non-Hive tables such as Iceberg, Paimon, and Hudi. When false, non-Hive tables are filtered out on a best-effort basis; see the note below for known limitations. | false | No | 0.5.1 |
-| `default.catalog` | The default catalog name for the Hive3 metastore backend; this configuration is ignored when using a Hive2 metastore. | hive | No | 1.1.0 |
+| Property Name | Description | Default Value | Required | Since Version |
Review Comment:
Do we need to change this document?
##########
common/src/main/java/org/apache/gravitino/utils/FetchFileUtils.java:
##########
@@ -0,0 +1,161 @@
+/*
+ * 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.utils;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardCopyOption;
+import java.util.Optional;
+import javax.annotation.Nullable;
+import org.apache.commons.io.FileUtils;
+
+/**
+ * Fetches a file referenced by a URI to a local destination. Supports {@code file}, {@code http},
+ * {@code https}, {@code ftp} and {@code hdfs} schemes. This is the single shared implementation
+ * used by the job manager and the Kerberos clients of the Hive, Iceberg, Hadoop and Paimon
+ * catalogs.
+ *
+ * <p>The {@code hdfs} scheme is resolved reflectively against {@code
+ * org.apache.hadoop.fs.FileSystem} so that this class can live in the {@code common} module, which
+ * does not declare a compile-time dependency on Hadoop. Callers that never use {@code hdfs} URIs
+ * (for example the job manager and the Paimon catalog) simply pass {@code null} for the Hadoop
+ * configuration.
+ */
+public final class FetchFileUtils {
+
+ /** The server configuration that controls unsafe remote URI blocking. */
+ public static final String BLOCK_UNSAFE_REMOTE_URI_CONFIG =
+ "gravitino.fetchFile.blockUnsafeRemoteUri";
+
+ private static volatile boolean blockUnsafeRemoteUri = true;
+
+ private FetchFileUtils() {}
+
+ /**
+ * Sets whether remote URIs that resolve to unsafe addresses should be blocked.
+ *
+ * @param blockUnsafeRemoteUri whether to block unsafe remote URIs
+ */
+ public static void setBlockUnsafeRemoteUri(boolean blockUnsafeRemoteUri) {
Review Comment:
Is this test only?
##########
common/src/main/java/org/apache/gravitino/utils/FetchFileUtils.java:
##########
@@ -0,0 +1,161 @@
+/*
+ * 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.utils;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardCopyOption;
+import java.util.Optional;
+import javax.annotation.Nullable;
+import org.apache.commons.io.FileUtils;
+
+/**
+ * Fetches a file referenced by a URI to a local destination. Supports {@code file}, {@code http},
+ * {@code https}, {@code ftp} and {@code hdfs} schemes. This is the single shared implementation
+ * used by the job manager and the Kerberos clients of the Hive, Iceberg, Hadoop and Paimon
+ * catalogs.
+ *
+ * <p>The {@code hdfs} scheme is resolved reflectively against {@code
+ * org.apache.hadoop.fs.FileSystem} so that this class can live in the {@code common} module, which
+ * does not declare a compile-time dependency on Hadoop. Callers that never use {@code hdfs} URIs
+ * (for example the job manager and the Paimon catalog) simply pass {@code null} for the Hadoop
+ * configuration.
+ */
+public final class FetchFileUtils {
+
+ /** The server configuration that controls unsafe remote URI blocking. */
+ public static final String BLOCK_UNSAFE_REMOTE_URI_CONFIG =
+ "gravitino.fetchFile.blockUnsafeRemoteUri";
+
+ private static volatile boolean blockUnsafeRemoteUri = true;
+
+ private FetchFileUtils() {}
+
+ /**
+ * Sets whether remote URIs that resolve to unsafe addresses should be blocked.
+ *
+ * @param blockUnsafeRemoteUri whether to block unsafe remote URIs
+ */
+ public static void setBlockUnsafeRemoteUri(boolean blockUnsafeRemoteUri) {
+ FetchFileUtils.blockUnsafeRemoteUri = blockUnsafeRemoteUri;
+ }
+
+ /**
+ * Fetches the file referenced by {@code fileUri} into {@code destFile}.
+ *
+ * @param fileUri the source URI; a missing scheme is treated as {@code file}
+ * @param destFile the local destination file
+ * @param timeoutMs the connect/read timeout in milliseconds, applied to remote (http/https/ftp)
+ * downloads
+ * @param hadoopConf an {@code org.apache.hadoop.conf.Configuration} instance, required only for
+ * the {@code hdfs} scheme; may be {@code null} when no {@code hdfs} URI is fetched
+ * @return the absolute path of {@code destFile}
+ * @throws IOException if the file cannot be fetched
+ */
+ public static String fetchFileFromUri(
Review Comment:
We can add a parameter `blockUnsafeAddress`?
##########
common/src/main/java/org/apache/gravitino/utils/FetchFileUtils.java:
##########
@@ -0,0 +1,161 @@
+/*
+ * 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.utils;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardCopyOption;
+import java.util.Optional;
+import javax.annotation.Nullable;
+import org.apache.commons.io.FileUtils;
+
+/**
+ * Fetches a file referenced by a URI to a local destination. Supports {@code file}, {@code http},
+ * {@code https}, {@code ftp} and {@code hdfs} schemes. This is the single shared implementation
+ * used by the job manager and the Kerberos clients of the Hive, Iceberg, Hadoop and Paimon
+ * catalogs.
+ *
+ * <p>The {@code hdfs} scheme is resolved reflectively against {@code
+ * org.apache.hadoop.fs.FileSystem} so that this class can live in the {@code common} module, which
+ * does not declare a compile-time dependency on Hadoop. Callers that never use {@code hdfs} URIs
+ * (for example the job manager and the Paimon catalog) simply pass {@code null} for the Hadoop
+ * configuration.
+ */
+public final class FetchFileUtils {
+
+ /** The server configuration that controls unsafe remote URI blocking. */
+ public static final String BLOCK_UNSAFE_REMOTE_URI_CONFIG =
+ "gravitino.fetchFile.blockUnsafeRemoteUri";
+
+ private static volatile boolean blockUnsafeRemoteUri = true;
+
+ private FetchFileUtils() {}
+
+ /**
+ * Sets whether remote URIs that resolve to unsafe addresses should be blocked.
+ *
+ * @param blockUnsafeRemoteUri whether to block unsafe remote URIs
+ */
+ public static void setBlockUnsafeRemoteUri(boolean blockUnsafeRemoteUri) {
+ FetchFileUtils.blockUnsafeRemoteUri = blockUnsafeRemoteUri;
+ }
+
+ /**
+ * Fetches the file referenced by {@code fileUri} into {@code destFile}.
+ *
+ * @param fileUri the source URI; a missing scheme is treated as {@code file}
+ * @param destFile the local destination file
+ * @param timeoutMs the connect/read timeout in milliseconds, applied to remote (http/https/ftp)
+ * downloads
+ * @param hadoopConf an {@code org.apache.hadoop.conf.Configuration} instance, required only for
+ * the {@code hdfs} scheme; may be {@code null} when no {@code hdfs} URI is fetched
+ * @return the absolute path of {@code destFile}
+ * @throws IOException if the file cannot be fetched
+ */
+ public static String fetchFileFromUri(
+ String fileUri, File destFile, int timeoutMs, @Nullable Object hadoopConf)
+ throws IOException {
+ try {
+ URI uri = new URI(fileUri);
+ String scheme = Optional.ofNullable(uri.getScheme()).orElse("file");
+
+ switch (scheme) {
+ case "http":
+ case "https":
+ case "ftp":
+ RemoteUriValidator.validate(
+ uri,
+ blockUnsafeRemoteUri,
+ String.format("'%s' to false", BLOCK_UNSAFE_REMOTE_URI_CONFIG));
+ FileUtils.copyURLToFile(uri.toURL(), destFile, timeoutMs, timeoutMs);
+ break;
+
+ case "file":
+ linkLocalFile(uri, destFile);
+ break;
+
+ case "hdfs":
+ copyHdfsFileToLocal(uri, destFile, hadoopConf);
+ break;
+
+ default:
+ throw new IllegalArgumentException(
+ String.format("The scheme '%s' is not supported", scheme));
+ }
+
+ return destFile.getAbsolutePath();
+ } catch (URISyntaxException ue) {
+ throw new IllegalArgumentException("The uri of file has the wrong format", ue);
+ }
+ }
+
+ private static synchronized void linkLocalFile(URI uri, File destFile) throws IOException {
+ Path srcPath = new File(uri.getPath()).toPath().normalize();
+ if (!Files.exists(srcPath)) {
+ throw new IOException(
+ String.format("Source file does not exist: %s", srcPath.toAbsolutePath()));
+ }
+
+ Path destPath = destFile.toPath().toAbsolutePath().normalize();
+ // Skip if the symlink already points to the correct target.
+ if (Files.isSymbolicLink(destPath)
+ && Files.readSymbolicLink(destPath).normalize().equals(srcPath)) {
+ return;
+ }
+ // Replace via a temporary symlink + rename to minimize the window where the destination path
+ // is absent (which could otherwise cause a concurrent reader, e.g. loginUserFromKeytab, to
+ // fail). REPLACE_EXISTING is used here; on common local filesystems (ext4, xfs, APFS) a
+ // same-directory rename is effectively atomic at the OS level.
+ Path tmpPath = destPath.resolveSibling(destPath.getFileName() + ".symlink.tmp");
+ Files.deleteIfExists(tmpPath);
+ Files.createSymbolicLink(tmpPath, srcPath);
+ Files.move(tmpPath, destPath, StandardCopyOption.REPLACE_EXISTING);
+ }
+
+ /**
+ * Copies an {@code hdfs} file to the local destination reflectively, so that this class does not
+ * require a compile-time dependency on Hadoop.
+ */
+ private static void copyHdfsFileToLocal(URI uri, File destFile, @Nullable Object hadoopConf)
Review Comment:
Should we use `Optional` here?
##########
common/src/main/java/org/apache/gravitino/utils/FetchFileUtils.java:
##########
@@ -0,0 +1,161 @@
+/*
+ * 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.utils;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardCopyOption;
+import java.util.Optional;
+import javax.annotation.Nullable;
+import org.apache.commons.io.FileUtils;
+
+/**
+ * Fetches a file referenced by a URI to a local destination. Supports {@code file}, {@code http},
+ * {@code https}, {@code ftp} and {@code hdfs} schemes. This is the single shared implementation
+ * used by the job manager and the Kerberos clients of the Hive, Iceberg, Hadoop and Paimon
+ * catalogs.
+ *
+ * <p>The {@code hdfs} scheme is resolved reflectively against {@code
+ * org.apache.hadoop.fs.FileSystem} so that this class can live in the {@code common} module, which
+ * does not declare a compile-time dependency on Hadoop. Callers that never use {@code hdfs} URIs
+ * (for example the job manager and the Paimon catalog) simply pass {@code null} for the Hadoop
+ * configuration.
+ */
+public final class FetchFileUtils {
+
+ /** The server configuration that controls unsafe remote URI blocking. */
+ public static final String BLOCK_UNSAFE_REMOTE_URI_CONFIG =
+ "gravitino.fetchFile.blockUnsafeRemoteUri";
+
+ private static volatile boolean blockUnsafeRemoteUri = true;
+
+ private FetchFileUtils() {}
+
+ /**
+ * Sets whether remote URIs that resolve to unsafe addresses should be blocked.
+ *
+ * @param blockUnsafeRemoteUri whether to block unsafe remote URIs
+ */
+ public static void setBlockUnsafeRemoteUri(boolean blockUnsafeRemoteUri) {
+ FetchFileUtils.blockUnsafeRemoteUri = blockUnsafeRemoteUri;
+ }
+
+ /**
+ * Fetches the file referenced by {@code fileUri} into {@code destFile}.
+ *
+ * @param fileUri the source URI; a missing scheme is treated as {@code file}
+ * @param destFile the local destination file
+ * @param timeoutMs the connect/read timeout in milliseconds, applied to remote (http/https/ftp)
+ * downloads
+ * @param hadoopConf an {@code org.apache.hadoop.conf.Configuration} instance, required only for
+ * the {@code hdfs} scheme; may be {@code null} when no {@code hdfs} URI is fetched
+ * @return the absolute path of {@code destFile}
+ * @throws IOException if the file cannot be fetched
+ */
+ public static String fetchFileFromUri(
Review Comment:
Do we need to consider thread safety?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MINOR] improvement(core): validate remote URI host in JobManager before download [gravitino]
Posted by "roryqi (via GitHub)" <gi...@apache.org>.
roryqi commented on PR #11354:
URL: https://github.com/apache/gravitino/pull/11354#issuecomment-4667546289
one question:
Should it be a catalog property or a server configuration option?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MINOR] improvement(core): validate remote URI host in JobManager before download [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on PR #11354:
URL: https://github.com/apache/gravitino/pull/11354#issuecomment-4668726482
> > > one question: Should it be a catalog property or a server configuration option?
> >
> >
> > Some catalogs used the method to fetch files, and the same goes for the Gravitino server, so both catalog properties and server configurations exist.
>
> For me, server config option is enough. I don't wanna make it complex.
modified.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MINOR] improvement(core): validate remote URI host in JobManager before download [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #11354:
URL: https://github.com/apache/gravitino/pull/11354#discussion_r3400037540
##########
catalogs/catalog-fileset/src/main/java/org/apache/gravitino/catalog/fileset/FilesetCatalogOperations.java:
##########
@@ -1386,7 +1386,10 @@ FileSystem getFileSystem(Path path, Map<String, String> config) throws IOExcepti
() -> {
if (scheme.equals(SCHEME_HDFS)) {
return new ImpersonationHDFSFileSystemProxy(
- path, config, PrincipalUtils::getCurrentUserName)
+ path,
+ config,
+ PrincipalUtils::getCurrentUserName,
+ GravitinoEnv.getInstance().blockUnsafeRemoteUri())
Review Comment:
@jerryshao
The initial code is what you suggested. see https://github.com/apache/gravitino/pull/11354#discussion_r3395339830
@roryqi He would like to make `blockUnsafeRemoteUri` a method and believes using a static field to store it is not a good idea. Frankly, these two are also acceptable to me; the current option( method parameter) is consistent with other configurations like `cacheEnabled`, but it seems to be tedious. The option to make it as `static` field is not so elegant, but it did make the code simple.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MINOR] improvement(core): validate remote URI host in JobManager before download [gravitino]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #11354:
URL: https://github.com/apache/gravitino/pull/11354#discussion_r3392202184
##########
common/src/main/java/org/apache/gravitino/utils/FetchFileUtils.java:
##########
@@ -0,0 +1,184 @@
+/*
+ * 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.utils;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardCopyOption;
+import java.util.Optional;
+import java.util.concurrent.ConcurrentHashMap;
+import javax.annotation.Nullable;
+import org.apache.commons.io.FileUtils;
+
+/**
+ * Fetches a file referenced by a URI to a local destination. Supports {@code file}, {@code http},
+ * {@code https}, {@code ftp} and {@code hdfs} schemes. This is the single shared implementation
+ * used by the job manager and the Kerberos clients of the Hive, Iceberg, Hadoop and Paimon
+ * catalogs.
+ *
+ * <p>The {@code hdfs} scheme is resolved reflectively against {@code
+ * org.apache.hadoop.fs.FileSystem} so that this class can live in the {@code common} module, which
+ * does not declare a compile-time dependency on Hadoop. Callers that never use {@code hdfs} URIs
+ * (for example the job manager and the Paimon catalog) simply pass {@code null} for the Hadoop
+ * configuration.
+ */
+public final class FetchFileUtils {
+
+ /** The server configuration that controls unsafe remote URI blocking. */
+ public static final String BLOCK_UNSAFE_REMOTE_URI_CONFIG = "gravitino.blockUnsafeRemoteUri";
+
+ /**
+ * Per-destination lock map used to serialize concurrent symlink creation for the same destination
+ * file. Keyed by the normalized absolute destination path string to avoid races caused by
+ * different path spellings referring to the same file. Entries should be removed via {@link
+ * #removeLock(File)} when the destination file is deleted, so the map size stays bounded by the
+ * number of live consumers.
+ */
+ private static final ConcurrentHashMap<String, Object> SYMLINK_LOCKS = new ConcurrentHashMap<>();
+
+ private static volatile boolean blockUnsafeRemoteUri = true;
+
+ private FetchFileUtils() {}
+
+ /**
+ * Sets whether remote URIs that resolve to unsafe addresses should be blocked.
+ *
+ * @param blockUnsafeRemoteUri whether to block unsafe remote URIs
+ */
+ public static void setBlockUnsafeRemoteUri(boolean blockUnsafeRemoteUri) {
+ FetchFileUtils.blockUnsafeRemoteUri = blockUnsafeRemoteUri;
+ }
+
+ /**
+ * Removes the per-destination lock entry for the given file. Should be called when the
+ * destination file is deleted (for example on a Kerberos client {@code close()}) to prevent
+ * unbounded map growth.
+ *
+ * @param destFile the destination file whose lock entry should be removed
+ */
+ public static void removeLock(File destFile) {
+ SYMLINK_LOCKS.remove(destFile.toPath().toAbsolutePath().normalize().toString());
+ }
+
+ /**
+ * Fetches the file referenced by {@code fileUri} into {@code destFile}.
+ *
+ * @param fileUri the source URI; a missing scheme is treated as {@code file}
+ * @param destFile the local destination file
+ * @param timeoutMs the connect/read timeout in milliseconds, applied to remote (http/https/ftp)
+ * downloads
+ * @param hadoopConf an {@code org.apache.hadoop.conf.Configuration} instance, required only for
+ * the {@code hdfs} scheme; may be {@code null} when no {@code hdfs} URI is fetched
+ * @return the absolute path of {@code destFile}
+ * @throws IOException if the file cannot be fetched
+ */
+ public static String fetchFileFromUri(
+ String fileUri, File destFile, int timeoutMs, @Nullable Object hadoopConf)
+ throws IOException {
+ try {
+ URI uri = new URI(fileUri);
+ String scheme = Optional.ofNullable(uri.getScheme()).orElse("file");
+
+ switch (scheme) {
+ case "http":
+ case "https":
+ case "ftp":
+ RemoteUriValidator.validate(
+ uri,
+ blockUnsafeRemoteUri,
+ String.format("'%s' to false", BLOCK_UNSAFE_REMOTE_URI_CONFIG));
+ FileUtils.copyURLToFile(uri.toURL(), destFile, timeoutMs, timeoutMs);
Review Comment:
Remote URI validation is performed using DNS resolution in `RemoteUriValidator.validate(...)`, but the actual download uses `FileUtils.copyURLToFile(uri.toURL(), ...)`, which will resolve the hostname again at connect time. This leaves a DNS rebinding/TOCTOU gap where the validated hostname can later resolve to a blocked address.
##########
common/src/main/java/org/apache/gravitino/utils/RemoteUriValidator.java:
##########
@@ -0,0 +1,92 @@
+/*
+ * 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.utils;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.URI;
+
+/** Validates remote URI hosts before server-side downloads. */
+public final class RemoteUriValidator {
+
+ private RemoteUriValidator() {}
+
+ /**
+ * Resolves the host in the given URI and rejects unsafe addresses when blocking is enabled.
+ *
+ * @param uri The remote URI to validate.
+ * @param blockUnsafeAddress Whether unsafe addresses should be blocked.
+ * @param blockUnsafeAddressHint The configuration hint that disables unsafe address blocking.
+ * @throws IOException If host resolution fails.
+ * @throws IllegalArgumentException If the URI has no host or resolves to an unsafe address.
+ */
+ public static void validate(URI uri, boolean blockUnsafeAddress, String blockUnsafeAddressHint)
+ throws IOException {
+ String host = uri.getHost();
+ if (host == null) {
+ throw new IllegalArgumentException("URI has no host: " + uri);
+ }
+
+ if (!blockUnsafeAddress) {
+ return;
+ }
+
+ InetAddress[] addresses = InetAddress.getAllByName(host);
+ for (InetAddress address : addresses) {
+ if (isUnsafeAddress(address)) {
+ throw new IllegalArgumentException(
+ String.format(
+ "URI '%s' resolves to blocked address %s from the Gravitino server side. "
+ + "Access to local, private, link-local, multicast, unspecified, and cloud "
+ + "metadata addresses is disabled by default to prevent SSRF. If this URI is "
+ + "trusted and this access is required, set %s.",
+ uri, address.getHostAddress(), blockUnsafeAddressHint));
+ }
+ }
+ }
+
+ private static boolean isUnsafeAddress(InetAddress address) {
+ if (address.isLoopbackAddress()
+ || address.isLinkLocalAddress()
+ || address.isSiteLocalAddress()
+ || address.isMulticastAddress()
+ || address.isAnyLocalAddress()) {
+ return true;
+ }
+
+ byte[] bytes = address.getAddress();
+ if (isCloudMetadataAddress(bytes)) {
+ return true;
+ }
+
+ return isIpv6UniqueLocalAddress(bytes);
+ }
Review Comment:
`isUnsafeAddress` does not account for IPv4-mapped / IPv4-compatible IPv6 literals (e.g. `http://[::ffff:127.0.0.1]/`). For such addresses, `InetAddress` loopback/site-local checks may not trigger, allowing localhost/private ranges to bypass SSRF blocking.
##########
docs/apache-hive-catalog.md:
##########
@@ -29,19 +29,19 @@ The Hive catalog supports creating, updating, and deleting databases and tables
Besides the [common catalog properties](./gravitino-server-config.md#catalog-properties-configuration), the Hive catalog has the following properties:
-| Property Name | Description | Default Value | Required | Since Version |
-|------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------|------------------------------|---------------|
-| `metastore.uris` | The Hive metastore service URIs, separate multiple addresses with commas. Such as `thrift://127.0.0.1:9083` | (none) | Yes | 0.2.0 |
-| `client.pool-size` | The maximum number of Hive metastore clients in the pool for Gravitino. | 1 | No | 0.2.0 |
-| `gravitino.bypass.` | Property name with this prefix passed down to the underlying HMS client for use. Such as `gravitino.bypass.hive.metastore.failure.retries = 3` indicate 3 times of retries upon failure of Thrift metastore calls | (none) | No | 0.2.0 |
-| `client.pool-cache.eviction-interval-ms` | The cache pool eviction interval. | 300000 | No | 0.4.0 |
-| `impersonation-enable` | Enable user impersonation for Hive catalog. | false | No | 0.4.0 |
-| `kerberos.principal` | The Kerberos principal for the catalog. You should configure `gravitino.bypass.hadoop.security.authentication`, `gravitino.bypass.hive.metastore.kerberos.principal` and `gravitino.bypass.hive.metastore.sasl.enabled`if you want to use Kerberos. | (none) | required if you use kerberos | 0.4.0 |
-| `kerberos.keytab-uri` | The uri of key tab for the catalog. Now supported protocols are `https`, `http`, `ftp`, `file`. | (none) | required if you use kerberos | 0.4.0 |
-| `kerberos.check-interval-sec` | The interval to check validness of the principal | 60 | No | 0.4.0 |
-| `kerberos.keytab-fetch-timeout-sec` | The timeout to fetch key tab | 60 | No | 0.4.0 |
-| `list-all-tables` | Whether to list all tables in a database, including non-Hive tables such as Iceberg, Paimon, and Hudi. When false, non-Hive tables are filtered out on a best-effort basis; see the note below for known limitations. | false | No | 0.5.1 |
-| `default.catalog` | The default catalog name for the Hive3 metastore backend; this configuration is ignored when using a Hive2 metastore. | hive | No | 1.1.0 |
+| Property Name | Description | Default Value | Required | Since Version |
+|------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------|------------------------------|---------------|
+| `metastore.uris` | The Hive metastore service URIs, separate multiple addresses with commas. Such as `thrift://127.0.0.1:9083` | (none) | Yes | 0.2.0 |
+| `client.pool-size` | The maximum number of Hive metastore clients in the pool for Gravitino. | 1 | No | 0.2.0 |
+| `gravitino.bypass.` | Property name with this prefix passed down to the underlying HMS client for use. Such as `gravitino.bypass.hive.metastore.failure.retries = 3` indicate 3 times of retries upon failure of Thrift metastore calls | (none) | No | 0.2.0 |
+| `client.pool-cache.eviction-interval-ms` | The cache pool eviction interval. | 300000 | No | 0.4.0 |
+| `impersonation-enable` | Enable user impersonation for Hive catalog. | false | No | 0.4.0 |
+| `kerberos.principal` | The Kerberos principal for the catalog. You should configure `gravitino.bypass.hadoop.security.authentication`, `gravitino.bypass.hive.metastore.kerberos.principal` and `gravitino.bypass.hive.metastore.sasl.enabled`if you want to use Kerberos. | (none) | required if you use kerberos | 0.4.0 |
+| `kerberos.keytab-uri` | The uri of key tab for the catalog. Now supported protocols are `https`, `http`, `ftp`, `file`. | (none) | required if you use kerberos | 0.4.0 |
+| `kerberos.check-interval-sec` | The interval to check validness of the principal | 60 | No | 0.4.0 |
Review Comment:
Wording/grammar: "validness" is nonstandard; prefer "validity" (and consider capitalizing "URI" / using "keytab" consistently).
##########
docs/iceberg-rest-service.md:
##########
@@ -394,15 +396,15 @@ Refer to [HTTPS Configuration](./security/how-to-use-https.md#apache-iceberg-res
For JDBC backend, you can use the `gravitino.iceberg-rest.jdbc-user` and `gravitino.iceberg-rest.jdbc-password` to authenticate the JDBC connection. For Hive backend, you can use the `gravitino.iceberg-rest.authentication.type` to specify the authentication type, and use the `gravitino.iceberg-rest.authentication.kerberos.principal` and `gravitino.iceberg-rest.authentication.kerberos.keytab-uri` to authenticate the Kerberos connection.
The detailed configuration items are as follows:
-| Configuration item | Description | Default value | Required | Since Version |
-|---------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------|
-| `gravitino.iceberg-rest.authentication.type` | The type of authentication for Iceberg rest catalog backend. This configuration only applicable for for Hive backend, and only supports `Kerberos`, `simple` currently. As for JDBC backend, only username/password authentication was supported now. | `simple` | No | 0.7.0-incubating |
-| `gravitino.iceberg-rest.authentication.impersonation-enable` | Whether to enable impersonation for the Iceberg catalog | `false` | No | 0.7.0-incubating |
-| `gravitino.iceberg-rest.hive.metastore.sasl.enabled` | Whether to enable SASL authentication protocol when connect to Kerberos Hive metastore. | `false` | No, This value should be true in most case(Some will use SSL protocol, but it rather rare) if the value of `gravitino.iceberg-rest.authentication.type` is Kerberos. | 0.7.0-incubating |
-| `gravitino.iceberg-rest.authentication.kerberos.principal` | The principal of the Kerberos authentication | (none) | required if the value of `gravitino.iceberg-rest.authentication.type` is Kerberos. | 0.7.0-incubating |
-| `gravitino.iceberg-rest.authentication.kerberos.keytab-uri` | The URI of The keytab for the Kerberos authentication. | (none) | required if the value of `gravitino.iceberg-rest.authentication.type` is Kerberos. | 0.7.0-incubating |
-| `gravitino.iceberg-rest.authentication.kerberos.check-interval-sec` | The check interval of Kerberos credential for Iceberg catalog. | 60 | No | 0.7.0-incubating |
-| `gravitino.iceberg-rest.authentication.kerberos.keytab-fetch-timeout-sec` | The fetch timeout of retrieving Kerberos keytab from `authentication.kerberos.keytab-uri`. | 60 | No | 0.7.0-incubating |
+| Configuration item | Description | Default value | Required | Since Version |
+|---------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------|
+| `gravitino.iceberg-rest.authentication.type` | The type of authentication for Iceberg rest catalog backend. This configuration only applicable for for Hive backend, and only supports `Kerberos`, `simple` currently. As for JDBC backend, only username/password authentication was supported now. | `simple` | No | 0.7.0-incubating |
Review Comment:
Grammar: "only applicable for for Hive backend" has a duplicated "for".
##########
docs/lakehouse-hudi-catalog.md:
##########
@@ -44,14 +44,14 @@ Tested and verified with Apache Hudi `0.15.0`.
Users can use the following properties to configure the security of the catalog backend if needed. For example, if you are using a Kerberos Hive catalog backend, you must set `authentication.type` to `Kerberos` and provide `authentication.kerberos.principal` and `authentication.kerberos.keytab-uri`.
-| Property name | Description | Default value | Required | Since Version |
-|----------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------|-------------------------------------------------------------|-------------------|
-| `authentication.type` | The type of authentication for hudi catalog backend. This configuration only applicable for for hms backend, and only supports `kerberos`, `simple` currently. | `simple` | No | 1.0.0 |
-| `authentication.impersonation-enable` | Whether to enable impersonation for the hudi catalog | `false` | No | 1.0.0 |
-| `authentication.kerberos.principal` | The principal of the Kerberos authentication | (none) | required if the value of `authentication.type` is kerberos. | 1.0.0 |
-| `authentication.kerberos.keytab-uri` | The URI of The keytab for the Kerberos authentication. | (none) | required if the value of `authentication.type` is kerberos. | 1.0.0 |
-| `authentication.kerberos.check-interval-sec` | The check interval of Kerberos credential for hudi catalog. | 60 | No | 1.0.0 |
-| `authentication.kerberos.keytab-fetch-timeout-sec` | The fetch timeout of retrieving Kerberos keytab from `authentication.kerberos.keytab-uri`. | 60 | No | 1.0.0 |
+| Property name | Description | Default value | Required | Since Version |
+|----------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------|--------------------------------------------------------------|----------------|
+| `authentication.type` | The type of authentication for hudi catalog backend. This configuration only applicable for for hms backend, and only supports `kerberos`, `simple` currently. | `simple` | No | 1.0.0 |
Review Comment:
Grammar: "only applicable for for hms backend" has a duplicated "for".
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MINOR] improvement(core): validate remote URI host in JobManager before download [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #11354:
URL: https://github.com/apache/gravitino/pull/11354#discussion_r3371538669
##########
catalogs/hive-metastore-common/src/main/java/org/apache/gravitino/hive/kerberos/FetchFileUtils.java:
##########
Review Comment:
This file depends on `Hadoop` jars, which can't be shared between modules like `Paimon`, `Iceberg`, `fileset`. Making `Hadoop` compile-only is optional; let me give it a try.
##########
catalogs/catalog-common/src/main/java/org/apache/gravitino/catalog/hive/HiveConstants.java:
##########
@@ -30,6 +30,8 @@ public class HiveConstants {
public static final String PRINCIPAL = "kerberos.principal";
public static final String CHECK_INTERVAL_SEC = "kerberos.check-interval-sec";
public static final String FETCH_TIMEOUT_SEC = "kerberos.keytab-fetch-timeout-sec";
+ public static final String KEYTAB_FETCH_ALLOW_LOCAL_ADDRESS =
Review Comment:
sure
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MINOR] improvement(core): validate remote URI host in JobManager before download [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #11354:
URL: https://github.com/apache/gravitino/pull/11354#discussion_r3395504943
##########
common/src/main/java/org/apache/gravitino/utils/FetchFileUtils.java:
##########
@@ -0,0 +1,161 @@
+/*
+ * 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.utils;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardCopyOption;
+import java.util.Optional;
+import javax.annotation.Nullable;
+import org.apache.commons.io.FileUtils;
+
+/**
+ * Fetches a file referenced by a URI to a local destination. Supports {@code file}, {@code http},
+ * {@code https}, {@code ftp} and {@code hdfs} schemes. This is the single shared implementation
+ * used by the job manager and the Kerberos clients of the Hive, Iceberg, Hadoop and Paimon
+ * catalogs.
+ *
+ * <p>The {@code hdfs} scheme is resolved reflectively against {@code
+ * org.apache.hadoop.fs.FileSystem} so that this class can live in the {@code common} module, which
+ * does not declare a compile-time dependency on Hadoop. Callers that never use {@code hdfs} URIs
+ * (for example the job manager and the Paimon catalog) simply pass {@code null} for the Hadoop
+ * configuration.
+ */
+public final class FetchFileUtils {
+
+ /** The server configuration that controls unsafe remote URI blocking. */
+ public static final String BLOCK_UNSAFE_REMOTE_URI_CONFIG =
+ "gravitino.fetchFile.blockUnsafeRemoteUri";
+
+ private static volatile boolean blockUnsafeRemoteUri = true;
+
+ private FetchFileUtils() {}
+
+ /**
+ * Sets whether remote URIs that resolve to unsafe addresses should be blocked.
+ *
+ * @param blockUnsafeRemoteUri whether to block unsafe remote URIs
+ */
+ public static void setBlockUnsafeRemoteUri(boolean blockUnsafeRemoteUri) {
+ FetchFileUtils.blockUnsafeRemoteUri = blockUnsafeRemoteUri;
+ }
+
+ /**
+ * Fetches the file referenced by {@code fileUri} into {@code destFile}.
+ *
+ * @param fileUri the source URI; a missing scheme is treated as {@code file}
+ * @param destFile the local destination file
+ * @param timeoutMs the connect/read timeout in milliseconds, applied to remote (http/https/ftp)
+ * downloads
+ * @param hadoopConf an {@code org.apache.hadoop.conf.Configuration} instance, required only for
+ * the {@code hdfs} scheme; may be {@code null} when no {@code hdfs} URI is fetched
+ * @return the absolute path of {@code destFile}
+ * @throws IOException if the file cannot be fetched
+ */
+ public static String fetchFileFromUri(
Review Comment:
Passing `blockUnsafeAddress` explicitly would make `FetchFileUtils` stateless. However, the catalog Kerberos clients currently have no direct access to this server-level configuration, and I do not think each caller should read `ServerConfig` directly. Supporting this cleanly would require propagating the value through the catalog initialization path and storing it in each owning component. Since this option is process-wide and initialized once during server startup, I prefer keeping the current approach in this PR unless we want to include that broader configuration plumbing.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MINOR] improvement(core): validate remote URI host in JobManager before download [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #11354:
URL: https://github.com/apache/gravitino/pull/11354#discussion_r3395702242
##########
common/src/main/java/org/apache/gravitino/utils/FetchFileUtils.java:
##########
@@ -0,0 +1,161 @@
+/*
+ * 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.utils;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardCopyOption;
+import java.util.Optional;
+import javax.annotation.Nullable;
+import org.apache.commons.io.FileUtils;
+
+/**
+ * Fetches a file referenced by a URI to a local destination. Supports {@code file}, {@code http},
+ * {@code https}, {@code ftp} and {@code hdfs} schemes. This is the single shared implementation
+ * used by the job manager and the Kerberos clients of the Hive, Iceberg, Hadoop and Paimon
+ * catalogs.
+ *
+ * <p>The {@code hdfs} scheme is resolved reflectively against {@code
+ * org.apache.hadoop.fs.FileSystem} so that this class can live in the {@code common} module, which
+ * does not declare a compile-time dependency on Hadoop. Callers that never use {@code hdfs} URIs
+ * (for example the job manager and the Paimon catalog) simply pass {@code null} for the Hadoop
+ * configuration.
+ */
+public final class FetchFileUtils {
+
+ /** The server configuration that controls unsafe remote URI blocking. */
+ public static final String BLOCK_UNSAFE_REMOTE_URI_CONFIG =
+ "gravitino.fetchFile.blockUnsafeRemoteUri";
+
+ private static volatile boolean blockUnsafeRemoteUri = true;
+
+ private FetchFileUtils() {}
+
+ /**
+ * Sets whether remote URIs that resolve to unsafe addresses should be blocked.
+ *
+ * @param blockUnsafeRemoteUri whether to block unsafe remote URIs
+ */
+ public static void setBlockUnsafeRemoteUri(boolean blockUnsafeRemoteUri) {
+ FetchFileUtils.blockUnsafeRemoteUri = blockUnsafeRemoteUri;
+ }
+
+ /**
+ * Fetches the file referenced by {@code fileUri} into {@code destFile}.
+ *
+ * @param fileUri the source URI; a missing scheme is treated as {@code file}
+ * @param destFile the local destination file
+ * @param timeoutMs the connect/read timeout in milliseconds, applied to remote (http/https/ftp)
+ * downloads
+ * @param hadoopConf an {@code org.apache.hadoop.conf.Configuration} instance, required only for
+ * the {@code hdfs} scheme; may be {@code null} when no {@code hdfs} URI is fetched
+ * @return the absolute path of {@code destFile}
+ * @throws IOException if the file cannot be fetched
+ */
+ public static String fetchFileFromUri(
Review Comment:
This is a process-wide server configuration. The Gravitino server sets it once before initializing components, while the standalone Iceberg REST server runs in a separate JVM. Therefore, no components with different values compete in the same process. To clarify my previous comment, the configuration is initialized once; `fetchFileFromUri` itself may be called multiple times by `JobManager` and Kerberos credential refreshes.
Making `FetchFileUtils` stateless would require propagating this server-level option through the catalog initialization path because the Kerberos clients currently receive only catalog properties. I think that broader dependency-injection change should be handled separately rather than partially adding a parameter here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MINOR] improvement(core): validate remote URI host in JobManager before download [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #11354:
URL: https://github.com/apache/gravitino/pull/11354#discussion_r3395656882
##########
common/src/main/java/org/apache/gravitino/utils/FetchFileUtils.java:
##########
@@ -0,0 +1,161 @@
+/*
+ * 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.utils;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardCopyOption;
+import java.util.Optional;
+import javax.annotation.Nullable;
+import org.apache.commons.io.FileUtils;
+
+/**
+ * Fetches a file referenced by a URI to a local destination. Supports {@code file}, {@code http},
+ * {@code https}, {@code ftp} and {@code hdfs} schemes. This is the single shared implementation
+ * used by the job manager and the Kerberos clients of the Hive, Iceberg, Hadoop and Paimon
+ * catalogs.
+ *
+ * <p>The {@code hdfs} scheme is resolved reflectively against {@code
+ * org.apache.hadoop.fs.FileSystem} so that this class can live in the {@code common} module, which
+ * does not declare a compile-time dependency on Hadoop. Callers that never use {@code hdfs} URIs
+ * (for example the job manager and the Paimon catalog) simply pass {@code null} for the Hadoop
+ * configuration.
+ */
+public final class FetchFileUtils {
+
+ /** The server configuration that controls unsafe remote URI blocking. */
+ public static final String BLOCK_UNSAFE_REMOTE_URI_CONFIG =
+ "gravitino.fetchFile.blockUnsafeRemoteUri";
+
+ private static volatile boolean blockUnsafeRemoteUri = true;
+
+ private FetchFileUtils() {}
+
+ /**
+ * Sets whether remote URIs that resolve to unsafe addresses should be blocked.
+ *
+ * @param blockUnsafeRemoteUri whether to block unsafe remote URIs
+ */
+ public static void setBlockUnsafeRemoteUri(boolean blockUnsafeRemoteUri) {
+ FetchFileUtils.blockUnsafeRemoteUri = blockUnsafeRemoteUri;
+ }
+
+ /**
+ * Fetches the file referenced by {@code fileUri} into {@code destFile}.
+ *
+ * @param fileUri the source URI; a missing scheme is treated as {@code file}
+ * @param destFile the local destination file
+ * @param timeoutMs the connect/read timeout in milliseconds, applied to remote (http/https/ftp)
+ * downloads
+ * @param hadoopConf an {@code org.apache.hadoop.conf.Configuration} instance, required only for
+ * the {@code hdfs} scheme; may be {@code null} when no {@code hdfs} URI is fetched
+ * @return the absolute path of {@code destFile}
+ * @throws IOException if the file cannot be fetched
+ */
+ public static String fetchFileFromUri(
Review Comment:
`fetchFileFromUri` will only be called once at start. If this is not so elegant, let me try to optimize it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MINOR] improvement(core): validate remote URI host in JobManager before download [gravitino]
Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on code in PR #11354:
URL: https://github.com/apache/gravitino/pull/11354#discussion_r3397787460
##########
common/src/main/java/org/apache/gravitino/utils/FetchFileUtils.java:
##########
@@ -0,0 +1,161 @@
+/*
+ * 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.utils;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardCopyOption;
+import java.util.Optional;
+import javax.annotation.Nullable;
+import org.apache.commons.io.FileUtils;
+
+/**
+ * Fetches a file referenced by a URI to a local destination. Supports {@code file}, {@code http},
+ * {@code https}, {@code ftp} and {@code hdfs} schemes. This is the single shared implementation
+ * used by the job manager and the Kerberos clients of the Hive, Iceberg, Hadoop and Paimon
+ * catalogs.
+ *
+ * <p>The {@code hdfs} scheme is resolved reflectively against {@code
+ * org.apache.hadoop.fs.FileSystem} so that this class can live in the {@code common} module, which
+ * does not declare a compile-time dependency on Hadoop. Callers that never use {@code hdfs} URIs
+ * (for example the job manager and the Paimon catalog) simply pass {@code null} for the Hadoop
+ * configuration.
+ */
+public final class FetchFileUtils {
+
+ /** The server configuration that controls unsafe remote URI blocking. */
+ public static final String BLOCK_UNSAFE_REMOTE_URI_CONFIG =
+ "gravitino.fetchFile.blockUnsafeRemoteUri";
+
+ private static volatile boolean blockUnsafeRemoteUri = true;
+
+ private FetchFileUtils() {}
+
+ /**
+ * Sets whether remote URIs that resolve to unsafe addresses should be blocked.
+ *
+ * @param blockUnsafeRemoteUri whether to block unsafe remote URIs
+ */
+ public static void setBlockUnsafeRemoteUri(boolean blockUnsafeRemoteUri) {
+ FetchFileUtils.blockUnsafeRemoteUri = blockUnsafeRemoteUri;
+ }
+
+ /**
+ * Fetches the file referenced by {@code fileUri} into {@code destFile}.
+ *
+ * @param fileUri the source URI; a missing scheme is treated as {@code file}
+ * @param destFile the local destination file
+ * @param timeoutMs the connect/read timeout in milliseconds, applied to remote (http/https/ftp)
+ * downloads
+ * @param hadoopConf an {@code org.apache.hadoop.conf.Configuration} instance, required only for
+ * the {@code hdfs} scheme; may be {@code null} when no {@code hdfs} URI is fetched
+ * @return the absolute path of {@code destFile}
+ * @throws IOException if the file cannot be fetched
+ */
+ public static String fetchFileFromUri(
+ String fileUri, File destFile, int timeoutMs, @Nullable Object hadoopConf)
+ throws IOException {
+ try {
+ URI uri = new URI(fileUri);
+ String scheme = Optional.ofNullable(uri.getScheme()).orElse("file");
+
+ switch (scheme) {
+ case "http":
+ case "https":
+ case "ftp":
+ RemoteUriValidator.validate(
+ uri,
+ blockUnsafeRemoteUri,
+ String.format("'%s' to false", BLOCK_UNSAFE_REMOTE_URI_CONFIG));
+ FileUtils.copyURLToFile(uri.toURL(), destFile, timeoutMs, timeoutMs);
+ break;
+
+ case "file":
+ linkLocalFile(uri, destFile);
+ break;
+
+ case "hdfs":
+ copyHdfsFileToLocal(uri, destFile, hadoopConf);
+ break;
+
+ default:
+ throw new IllegalArgumentException(
+ String.format("The scheme '%s' is not supported", scheme));
+ }
+
+ return destFile.getAbsolutePath();
+ } catch (URISyntaxException ue) {
+ throw new IllegalArgumentException("The uri of file has the wrong format", ue);
+ }
+ }
+
+ private static synchronized void linkLocalFile(URI uri, File destFile) throws IOException {
+ Path srcPath = new File(uri.getPath()).toPath().normalize();
+ if (!Files.exists(srcPath)) {
+ throw new IOException(
+ String.format("Source file does not exist: %s", srcPath.toAbsolutePath()));
+ }
+
+ Path destPath = destFile.toPath().toAbsolutePath().normalize();
+ // Skip if the symlink already points to the correct target.
+ if (Files.isSymbolicLink(destPath)
+ && Files.readSymbolicLink(destPath).normalize().equals(srcPath)) {
+ return;
+ }
+ // Replace via a temporary symlink + rename to minimize the window where the destination path
+ // is absent (which could otherwise cause a concurrent reader, e.g. loginUserFromKeytab, to
+ // fail). REPLACE_EXISTING is used here; on common local filesystems (ext4, xfs, APFS) a
+ // same-directory rename is effectively atomic at the OS level.
+ Path tmpPath = destPath.resolveSibling(destPath.getFileName() + ".symlink.tmp");
+ Files.deleteIfExists(tmpPath);
+ Files.createSymbolicLink(tmpPath, srcPath);
+ Files.move(tmpPath, destPath, StandardCopyOption.REPLACE_EXISTING);
+ }
+
+ /**
+ * Copies an {@code hdfs} file to the local destination reflectively, so that this class does not
+ * require a compile-time dependency on Hadoop.
+ */
+ private static void copyHdfsFileToLocal(URI uri, File destFile, @Nullable Object hadoopConf)
Review Comment:
Please change it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MINOR] improvement(core): validate remote URI host in JobManager before download [gravitino]
Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on code in PR #11354:
URL: https://github.com/apache/gravitino/pull/11354#discussion_r3397783285
##########
catalogs/catalog-fileset/src/main/java/org/apache/gravitino/catalog/fileset/FilesetCatalogOperations.java:
##########
@@ -1386,7 +1386,10 @@ FileSystem getFileSystem(Path path, Map<String, String> config) throws IOExcepti
() -> {
if (scheme.equals(SCHEME_HDFS)) {
return new ImpersonationHDFSFileSystemProxy(
- path, config, PrincipalUtils::getCurrentUserName)
+ path,
+ config,
+ PrincipalUtils::getCurrentUserName,
+ GravitinoEnv.getInstance().blockUnsafeRemoteUri())
Review Comment:
`GravitinoEnv.getInstance().blockUnsafeRemoteUri()` will not be changed in the runtime, so I think we can call it once when FetchFileUtils is initialized. We don't have to pass this configuration each time when we call the method, WDYT?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MINOR] improvement(core): validate remote URI host in JobManager before download [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #11354:
URL: https://github.com/apache/gravitino/pull/11354#discussion_r3400483880
##########
catalogs/catalog-fileset/src/main/java/org/apache/gravitino/catalog/fileset/FilesetCatalogOperations.java:
##########
@@ -1386,7 +1386,10 @@ FileSystem getFileSystem(Path path, Map<String, String> config) throws IOExcepti
() -> {
if (scheme.equals(SCHEME_HDFS)) {
return new ImpersonationHDFSFileSystemProxy(
- path, config, PrincipalUtils::getCurrentUserName)
+ path,
+ config,
+ PrincipalUtils::getCurrentUserName,
+ GravitinoEnv.getInstance().blockUnsafeRemoteUri())
Review Comment:
This seems nicer than the current one.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MINOR] improvement(core): validate remote URI host in JobManager before download [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #11354:
URL: https://github.com/apache/gravitino/pull/11354#discussion_r3340535995
##########
core/src/main/java/org/apache/gravitino/job/JobManager.java:
##########
@@ -808,6 +809,7 @@ static String fetchFileFromUri(String uri, File stagingDir, int timeoutInMs) {
case "http":
case "https":
case "ftp":
+ validateRemoteUri(fileUri);
FileUtils.copyURLToFile(fileUri.toURL(), destFile, timeoutInMs, timeoutInMs);
break;
Review Comment:
Added comments.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MINOR] improvement(core): validate remote URI host in JobManager before download [gravitino]
Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on code in PR #11354:
URL: https://github.com/apache/gravitino/pull/11354#discussion_r3353430889
##########
core/src/main/java/org/apache/gravitino/job/JobManager.java:
##########
@@ -830,6 +832,57 @@ static String fetchFileFromUri(String uri, File stagingDir, int timeoutInMs) {
}
}
+ /**
+ * Resolves the host in the given URI and rejects addresses that should not be reachable from the
+ * server (loopback, link-local, RFC-1918 private ranges, IPv6 ULA, cloud metadata endpoints).
+ * This is a defence-in-depth measure against Server-Side Request Forgery (SSRF).
+ *
+ * <p><b>Note on DNS TOCTOU:</b> This method resolves the hostname once at validation time. {@code
+ * FileUtils.copyURLToFile()} will re-resolve it when opening the connection, so a precisely-timed
+ * DNS-rebinding attack could theoretically bypass this check. Complete protection against DNS
+ * rebinding requires network-level egress controls (e.g. firewall rules) in addition to this
+ * application-layer validation.
+ */
+ @VisibleForTesting
+ static void validateRemoteUri(URI uri) throws IOException {
+ String host = uri.getHost();
+ if (host == null) {
+ throw new IllegalArgumentException("URI has no host: " + uri);
+ }
+ InetAddress[] addresses = InetAddress.getAllByName(host);
+ for (InetAddress address : addresses) {
+ if (isBlockedAddress(address)) {
+ throw new IllegalArgumentException(
+ String.format(
+ "URI '%s' resolves to blocked address %s, access denied (SSRF prevention)",
+ uri, address.getHostAddress()));
+ }
+ }
+ }
+
+ private static boolean isBlockedAddress(InetAddress address) {
+ // Covers loopback (127.x.x.x / ::1), link-local (169.254.x.x / fe80::/10 — includes AWS/GCP/
+ // Azure metadata), RFC-1918 private (10.x / 172.16-31.x / 192.168.x), multicast, unspecified.
+ if (address.isLoopbackAddress()
+ || address.isLinkLocalAddress()
+ || address.isSiteLocalAddress()
+ || address.isMulticastAddress()
+ || address.isAnyLocalAddress()) {
+ return true;
Review Comment:
Why can't we support loopback or local address? Is there any issue using it? What if I have a local web server or ftp server? I think the requirement is quite fair.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MINOR] improvement(core): validate remote URI host in JobManager before download [gravitino]
Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on code in PR #11354:
URL: https://github.com/apache/gravitino/pull/11354#discussion_r3353385412
##########
core/src/main/java/org/apache/gravitino/job/JobManager.java:
##########
@@ -808,6 +809,7 @@ static String fetchFileFromUri(String uri, File stagingDir, int timeoutInMs) {
case "http":
case "https":
case "ftp":
+ validateRemoteUri(fileUri);
Review Comment:
There're several `FetchFileUtils` that have similar code. I think you should 1) Fix the similar issues for all of them; 2) Consolidate the similar code into one if possible.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MINOR] improvement(core): validate remote URI host in JobManager before download [gravitino]
Posted by "roryqi (via GitHub)" <gi...@apache.org>.
roryqi commented on PR #11354:
URL: https://github.com/apache/gravitino/pull/11354#issuecomment-4602344139
FTP maybe a private address. Should we forbid it?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MINOR] improvement(core): validate remote URI host in JobManager before download [gravitino]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #11354:
URL: https://github.com/apache/gravitino/pull/11354#discussion_r3340049543
##########
core/src/main/java/org/apache/gravitino/job/JobManager.java:
##########
@@ -808,6 +809,7 @@ static String fetchFileFromUri(String uri, File stagingDir, int timeoutInMs) {
case "http":
case "https":
case "ftp":
+ validateRemoteUri(fileUri);
FileUtils.copyURLToFile(fileUri.toURL(), destFile, timeoutInMs, timeoutInMs);
break;
Review Comment:
`validateRemoteUri()` resolves the hostname, but `FileUtils.copyURLToFile(fileUri.toURL(), ...)` will perform its own DNS resolution again. That means DNS rebinding/TOCTOU can bypass this check if the hostname’s A/AAAA records change between validation and connection. Consider connecting using the validated `InetAddress` (or otherwise pinning the resolved IP) to make the validation effective at request time.
##########
core/src/main/java/org/apache/gravitino/job/JobManager.java:
##########
@@ -830,6 +832,47 @@ static String fetchFileFromUri(String uri, File stagingDir, int timeoutInMs) {
}
}
+ /**
+ * Resolves the host in the given URI and rejects addresses that should not be reachable from the
+ * server (loopback, link-local, RFC-1918 private ranges, cloud metadata endpoints). This is a
+ * defence-in-depth measure against Server-Side Request Forgery (SSRF).
+ */
+ @VisibleForTesting
+ static void validateRemoteUri(URI uri) throws IOException {
+ String host = uri.getHost();
+ if (host == null) {
+ throw new IllegalArgumentException("URI has no host: " + uri);
+ }
+ InetAddress[] addresses = InetAddress.getAllByName(host);
+ for (InetAddress address : addresses) {
+ if (isBlockedAddress(address)) {
+ throw new IllegalArgumentException(
+ String.format(
+ "URI '%s' resolves to blocked address %s, access denied (SSRF prevention)",
+ uri, address.getHostAddress()));
+ }
+ }
+ }
+
+ private static boolean isBlockedAddress(InetAddress address) {
+ // Covers loopback (127.x.x.x / ::1), link-local (169.254.x.x / fe80::/10 — includes AWS/GCP/
+ // Azure metadata), RFC-1918 private (10.x / 172.16-31.x / 192.168.x), multicast, unspecified.
+ if (address.isLoopbackAddress()
+ || address.isLinkLocalAddress()
+ || address.isSiteLocalAddress()
+ || address.isMulticastAddress()
+ || address.isAnyLocalAddress()) {
+ return true;
+ }
+ // Alibaba Cloud / Oracle Cloud metadata endpoint: 100.100.100.200
+ byte[] b = address.getAddress();
+ return b.length == 4
+ && (b[0] & 0xFF) == 100
+ && (b[1] & 0xFF) == 100
+ && (b[2] & 0xFF) == 100
+ && (b[3] & 0xFF) == 200;
Review Comment:
`isBlockedAddress()` relies on `isSiteLocalAddress()` for “private” ranges, but that does not cover IPv6 Unique Local Addresses (RFC 4193, `fc00::/7`). As a result, URIs resolving to `fc00::/7` can still pass validation, which undermines the stated SSRF protection for private/internal networks.
##########
core/src/test/java/org/apache/gravitino/job/TestJobManager.java:
##########
@@ -914,6 +915,72 @@ public void testFetchFileFromUriWithMissingLocalFileShouldFail() throws IOExcept
RuntimeException.class, () -> JobManager.fetchFileFromUri(uri, stagingDir, 1000));
}
+ @Test
+ public void testFetchFileFromUriSsrfBlocked() {
+ File stagingDir = new File(testStagingDir);
+ Assertions.assertTrue(stagingDir.mkdirs() || stagingDir.exists());
+
+ // Loopback address
+ Assertions.assertThrows(
+ RuntimeException.class,
+ () -> JobManager.fetchFileFromUri("http://127.0.0.1:8090/configs", stagingDir, 1000));
+
+ // AWS / GCP / Azure cloud-metadata endpoint (link-local 169.254.x.x)
+ Assertions.assertThrows(
+ RuntimeException.class,
+ () ->
+ JobManager.fetchFileFromUri(
+ "http://169.254.169.254/latest/meta-data/", stagingDir, 1000));
+
Review Comment:
Same as above: this should verify the failure is due to SSRF validation (exception cause/message), not just that the fetch fails for any reason.
##########
core/src/test/java/org/apache/gravitino/job/TestJobManager.java:
##########
@@ -914,6 +915,72 @@ public void testFetchFileFromUriWithMissingLocalFileShouldFail() throws IOExcept
RuntimeException.class, () -> JobManager.fetchFileFromUri(uri, stagingDir, 1000));
}
+ @Test
+ public void testFetchFileFromUriSsrfBlocked() {
+ File stagingDir = new File(testStagingDir);
+ Assertions.assertTrue(stagingDir.mkdirs() || stagingDir.exists());
+
+ // Loopback address
+ Assertions.assertThrows(
+ RuntimeException.class,
+ () -> JobManager.fetchFileFromUri("http://127.0.0.1:8090/configs", stagingDir, 1000));
+
+ // AWS / GCP / Azure cloud-metadata endpoint (link-local 169.254.x.x)
+ Assertions.assertThrows(
+ RuntimeException.class,
+ () ->
+ JobManager.fetchFileFromUri(
+ "http://169.254.169.254/latest/meta-data/", stagingDir, 1000));
+
+ // RFC-1918 private range
+ Assertions.assertThrows(
+ RuntimeException.class,
+ () -> JobManager.fetchFileFromUri("http://192.168.1.1/", stagingDir, 1000));
+
+ // Alibaba Cloud / Oracle Cloud metadata endpoint
+ Assertions.assertThrows(
+ RuntimeException.class,
+ () -> JobManager.fetchFileFromUri("http://100.100.100.200/", stagingDir, 1000));
+ }
Review Comment:
Same issue: this should assert the fetch failed specifically due to SSRF prevention (cause/message), not simply because the endpoint is unreachable.
##########
core/src/test/java/org/apache/gravitino/job/TestJobManager.java:
##########
@@ -914,6 +915,72 @@ public void testFetchFileFromUriWithMissingLocalFileShouldFail() throws IOExcept
RuntimeException.class, () -> JobManager.fetchFileFromUri(uri, stagingDir, 1000));
}
+ @Test
+ public void testFetchFileFromUriSsrfBlocked() {
+ File stagingDir = new File(testStagingDir);
+ Assertions.assertTrue(stagingDir.mkdirs() || stagingDir.exists());
+
+ // Loopback address
+ Assertions.assertThrows(
+ RuntimeException.class,
+ () -> JobManager.fetchFileFromUri("http://127.0.0.1:8090/configs", stagingDir, 1000));
+
Review Comment:
This assertion only checks that *some* `RuntimeException` is thrown. Without inspecting the cause/message, the test could still pass if the HTTP request fails for an unrelated reason (e.g., connection refused) and would not actually prove SSRF blocking is enforced by `validateRemoteUri()`.
##########
core/src/test/java/org/apache/gravitino/job/TestJobManager.java:
##########
@@ -914,6 +915,72 @@ public void testFetchFileFromUriWithMissingLocalFileShouldFail() throws IOExcept
RuntimeException.class, () -> JobManager.fetchFileFromUri(uri, stagingDir, 1000));
}
+ @Test
+ public void testFetchFileFromUriSsrfBlocked() {
+ File stagingDir = new File(testStagingDir);
+ Assertions.assertTrue(stagingDir.mkdirs() || stagingDir.exists());
+
+ // Loopback address
+ Assertions.assertThrows(
+ RuntimeException.class,
+ () -> JobManager.fetchFileFromUri("http://127.0.0.1:8090/configs", stagingDir, 1000));
+
+ // AWS / GCP / Azure cloud-metadata endpoint (link-local 169.254.x.x)
+ Assertions.assertThrows(
+ RuntimeException.class,
+ () ->
+ JobManager.fetchFileFromUri(
+ "http://169.254.169.254/latest/meta-data/", stagingDir, 1000));
+
+ // RFC-1918 private range
+ Assertions.assertThrows(
+ RuntimeException.class,
+ () -> JobManager.fetchFileFromUri("http://192.168.1.1/", stagingDir, 1000));
Review Comment:
Same issue: this assertion should confirm the exception is thrown by the SSRF validation (cause/message) to avoid a false positive if the network call fails for unrelated reasons.
##########
core/src/test/java/org/apache/gravitino/job/TestJobManager.java:
##########
@@ -914,6 +915,72 @@ public void testFetchFileFromUriWithMissingLocalFileShouldFail() throws IOExcept
RuntimeException.class, () -> JobManager.fetchFileFromUri(uri, stagingDir, 1000));
}
+ @Test
+ public void testFetchFileFromUriSsrfBlocked() {
+ File stagingDir = new File(testStagingDir);
+ Assertions.assertTrue(stagingDir.mkdirs() || stagingDir.exists());
+
+ // Loopback address
+ Assertions.assertThrows(
+ RuntimeException.class,
+ () -> JobManager.fetchFileFromUri("http://127.0.0.1:8090/configs", stagingDir, 1000));
+
+ // AWS / GCP / Azure cloud-metadata endpoint (link-local 169.254.x.x)
+ Assertions.assertThrows(
+ RuntimeException.class,
+ () ->
+ JobManager.fetchFileFromUri(
+ "http://169.254.169.254/latest/meta-data/", stagingDir, 1000));
+
+ // RFC-1918 private range
+ Assertions.assertThrows(
+ RuntimeException.class,
+ () -> JobManager.fetchFileFromUri("http://192.168.1.1/", stagingDir, 1000));
+
+ // Alibaba Cloud / Oracle Cloud metadata endpoint
+ Assertions.assertThrows(
+ RuntimeException.class,
+ () -> JobManager.fetchFileFromUri("http://100.100.100.200/", stagingDir, 1000));
+ }
+
+ @Test
+ public void testValidateRemoteUri() throws Exception {
+ // Loopback
+ Assertions.assertThrows(
+ IllegalArgumentException.class,
+ () -> JobManager.validateRemoteUri(new URI("http://127.0.0.1/")));
+
+ // Link-local (cloud metadata)
+ Assertions.assertThrows(
+ IllegalArgumentException.class,
+ () -> JobManager.validateRemoteUri(new URI("http://169.254.169.254/")));
+
+ // RFC-1918 private 10.x.x.x
+ Assertions.assertThrows(
+ IllegalArgumentException.class,
+ () -> JobManager.validateRemoteUri(new URI("http://10.0.0.1/")));
+
+ // RFC-1918 private 172.16.x.x
+ Assertions.assertThrows(
+ IllegalArgumentException.class,
+ () -> JobManager.validateRemoteUri(new URI("http://172.16.0.1/")));
+
+ // RFC-1918 private 192.168.x.x
+ Assertions.assertThrows(
+ IllegalArgumentException.class,
+ () -> JobManager.validateRemoteUri(new URI("http://192.168.0.1/")));
+
Review Comment:
`validateRemoteUri()` is intended to block private/internal addresses, but the test suite doesn’t currently cover IPv6 Unique Local Addresses (`fc00::/7`). Adding a ULA case helps prevent regressions once IPv6 private-range blocking is implemented.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MINOR] improvement(core): validate remote URI host in JobManager before download [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #11354:
URL: https://github.com/apache/gravitino/pull/11354#discussion_r3392622300
##########
common/src/main/java/org/apache/gravitino/utils/FetchFileUtils.java:
##########
@@ -0,0 +1,184 @@
+/*
+ * 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.utils;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardCopyOption;
+import java.util.Optional;
+import java.util.concurrent.ConcurrentHashMap;
+import javax.annotation.Nullable;
+import org.apache.commons.io.FileUtils;
+
+/**
+ * Fetches a file referenced by a URI to a local destination. Supports {@code file}, {@code http},
+ * {@code https}, {@code ftp} and {@code hdfs} schemes. This is the single shared implementation
+ * used by the job manager and the Kerberos clients of the Hive, Iceberg, Hadoop and Paimon
+ * catalogs.
+ *
+ * <p>The {@code hdfs} scheme is resolved reflectively against {@code
+ * org.apache.hadoop.fs.FileSystem} so that this class can live in the {@code common} module, which
+ * does not declare a compile-time dependency on Hadoop. Callers that never use {@code hdfs} URIs
+ * (for example the job manager and the Paimon catalog) simply pass {@code null} for the Hadoop
+ * configuration.
+ */
+public final class FetchFileUtils {
+
+ /** The server configuration that controls unsafe remote URI blocking. */
+ public static final String BLOCK_UNSAFE_REMOTE_URI_CONFIG = "gravitino.blockUnsafeRemoteUri";
Review Comment:
changed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MINOR] improvement(core): validate remote URI host in JobManager before download [gravitino]
Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on code in PR #11354:
URL: https://github.com/apache/gravitino/pull/11354#discussion_r3392248131
##########
common/src/main/java/org/apache/gravitino/utils/FetchFileUtils.java:
##########
@@ -0,0 +1,184 @@
+/*
+ * 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.utils;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardCopyOption;
+import java.util.Optional;
+import java.util.concurrent.ConcurrentHashMap;
+import javax.annotation.Nullable;
+import org.apache.commons.io.FileUtils;
+
+/**
+ * Fetches a file referenced by a URI to a local destination. Supports {@code file}, {@code http},
+ * {@code https}, {@code ftp} and {@code hdfs} schemes. This is the single shared implementation
+ * used by the job manager and the Kerberos clients of the Hive, Iceberg, Hadoop and Paimon
+ * catalogs.
+ *
+ * <p>The {@code hdfs} scheme is resolved reflectively against {@code
+ * org.apache.hadoop.fs.FileSystem} so that this class can live in the {@code common} module, which
+ * does not declare a compile-time dependency on Hadoop. Callers that never use {@code hdfs} URIs
+ * (for example the job manager and the Paimon catalog) simply pass {@code null} for the Hadoop
+ * configuration.
+ */
+public final class FetchFileUtils {
+
+ /** The server configuration that controls unsafe remote URI blocking. */
+ public static final String BLOCK_UNSAFE_REMOTE_URI_CONFIG = "gravitino.blockUnsafeRemoteUri";
+
+ /**
+ * Per-destination lock map used to serialize concurrent symlink creation for the same destination
+ * file. Keyed by the normalized absolute destination path string to avoid races caused by
+ * different path spellings referring to the same file. Entries should be removed via {@link
+ * #removeLock(File)} when the destination file is deleted, so the map size stays bounded by the
+ * number of live consumers.
+ */
+ private static final ConcurrentHashMap<String, Object> SYMLINK_LOCKS = new ConcurrentHashMap<>();
+
+ private static volatile boolean blockUnsafeRemoteUri = true;
+
+ private FetchFileUtils() {}
+
+ /**
+ * Sets whether remote URIs that resolve to unsafe addresses should be blocked.
+ *
+ * @param blockUnsafeRemoteUri whether to block unsafe remote URIs
+ */
+ public static void setBlockUnsafeRemoteUri(boolean blockUnsafeRemoteUri) {
+ FetchFileUtils.blockUnsafeRemoteUri = blockUnsafeRemoteUri;
+ }
+
+ /**
+ * Removes the per-destination lock entry for the given file. Should be called when the
+ * destination file is deleted (for example on a Kerberos client {@code close()}) to prevent
+ * unbounded map growth.
+ *
+ * @param destFile the destination file whose lock entry should be removed
+ */
+ public static void removeLock(File destFile) {
+ SYMLINK_LOCKS.remove(destFile.toPath().toAbsolutePath().normalize().toString());
+ }
+
+ /**
+ * Fetches the file referenced by {@code fileUri} into {@code destFile}.
+ *
+ * @param fileUri the source URI; a missing scheme is treated as {@code file}
+ * @param destFile the local destination file
+ * @param timeoutMs the connect/read timeout in milliseconds, applied to remote (http/https/ftp)
+ * downloads
+ * @param hadoopConf an {@code org.apache.hadoop.conf.Configuration} instance, required only for
+ * the {@code hdfs} scheme; may be {@code null} when no {@code hdfs} URI is fetched
+ * @return the absolute path of {@code destFile}
+ * @throws IOException if the file cannot be fetched
+ */
+ public static String fetchFileFromUri(
+ String fileUri, File destFile, int timeoutMs, @Nullable Object hadoopConf)
+ throws IOException {
+ try {
+ URI uri = new URI(fileUri);
+ String scheme = Optional.ofNullable(uri.getScheme()).orElse("file");
+
+ switch (scheme) {
+ case "http":
+ case "https":
+ case "ftp":
+ RemoteUriValidator.validate(
+ uri,
+ blockUnsafeRemoteUri,
+ String.format("'%s' to false", BLOCK_UNSAFE_REMOTE_URI_CONFIG));
+ FileUtils.copyURLToFile(uri.toURL(), destFile, timeoutMs, timeoutMs);
+ break;
+
+ case "file":
+ linkLocalFile(uri, destFile);
+ break;
+
+ case "hdfs":
+ copyHdfsFileToLocal(uri, destFile, hadoopConf);
+ break;
+
+ default:
+ throw new IllegalArgumentException(
+ String.format("The scheme '%s' is not supported", scheme));
+ }
+
+ return destFile.getAbsolutePath();
+ } catch (URISyntaxException ue) {
+ throw new IllegalArgumentException("The uri of file has the wrong format", ue);
+ }
+ }
+
+ private static void linkLocalFile(URI uri, File destFile) throws IOException {
+ Path srcPath = new File(uri.getPath()).toPath().normalize();
+ if (!Files.exists(srcPath)) {
+ throw new IOException(
+ String.format("Source file does not exist: %s", srcPath.toAbsolutePath()));
+ }
+
+ Path destPath = destFile.toPath().toAbsolutePath().normalize();
+ Object lock = SYMLINK_LOCKS.computeIfAbsent(destPath.toString(), k -> new Object());
+ synchronized (lock) {
+ // Skip if the symlink already points to the correct target.
+ if (Files.isSymbolicLink(destPath)
+ && Files.readSymbolicLink(destPath).normalize().equals(srcPath)) {
+ return;
+ }
+ // Replace via a temporary symlink + rename to minimize the window where the destination path
+ // is absent (which could otherwise cause a concurrent reader, e.g. loginUserFromKeytab, to
+ // fail). REPLACE_EXISTING is used here; on common local filesystems (ext4, xfs, APFS) a
+ // same-directory rename is effectively atomic at the OS level.
+ Path tmpPath = destPath.resolveSibling(destPath.getFileName() + ".symlink.tmp");
+ Files.deleteIfExists(tmpPath);
+ Files.createSymbolicLink(tmpPath, srcPath);
+ Files.move(tmpPath, destPath, StandardCopyOption.REPLACE_EXISTING);
+ }
+ }
Review Comment:
If you wan this method thread-safe, why don't you simply add a synchronized keyword?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MINOR] improvement(core): validate remote URI host in JobManager before download [gravitino]
Posted by "roryqi (via GitHub)" <gi...@apache.org>.
roryqi commented on code in PR #11354:
URL: https://github.com/apache/gravitino/pull/11354#discussion_r3371299979
##########
catalogs/catalog-common/src/main/java/org/apache/gravitino/catalog/hive/HiveConstants.java:
##########
@@ -30,6 +30,8 @@ public class HiveConstants {
public static final String PRINCIPAL = "kerberos.principal";
public static final String CHECK_INTERVAL_SEC = "kerberos.check-interval-sec";
public static final String FETCH_TIMEOUT_SEC = "kerberos.keytab-fetch-timeout-sec";
+ public static final String KEYTAB_FETCH_ALLOW_LOCAL_ADDRESS =
Review Comment:
Could we give a better name? Local address means 127.0.0.1 only. Actually it should include the 192.16.0.0 sub network.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MINOR] improvement(core): validate remote URI host in JobManager before download [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #11354:
URL: https://github.com/apache/gravitino/pull/11354#discussion_r3380202553
##########
catalogs/hive-metastore-common/src/main/java/org/apache/gravitino/hive/kerberos/FetchFileUtils.java:
##########
Review Comment:
Removed all duplicated file `FetchFileUtils`. Other duplicated classes like `KerberosClient` can also be optimized, I would like to use https://github.com/apache/gravitino/issues/11486 to track them.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MINOR] improvement(core): validate remote URI host in JobManager before download [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on PR #11354:
URL: https://github.com/apache/gravitino/pull/11354#issuecomment-4668209775
> > > one question: Should it be a catalog property or a server configuration option?
> >
> >
> > Some catalogs used the method to fetch files, and the same goes for the Gravitino server, so both catalog properties and server configurations exist.
>
> For me, server config option is enough. I don't wanna make it complex.
I'm hesitant to do it, as configurations like download timeouts are separate. Unifying them did make things simple, and I have also thought about this point before.
If this does not matter, I will merge all configurations into one.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MINOR] improvement(core): validate remote URI host in JobManager before download [gravitino]
Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on code in PR #11354:
URL: https://github.com/apache/gravitino/pull/11354#discussion_r3378193490
##########
catalogs/hive-metastore-common/src/main/java/org/apache/gravitino/hive/kerberos/FetchFileUtils.java:
##########
Review Comment:
How about using reflection to get rid of hadoop dependency issue? We just use very common hadoop FS API, so it should be compatible across versions.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MINOR] improvement(core): validate remote URI host in JobManager before download [gravitino]
Posted by "roryqi (via GitHub)" <gi...@apache.org>.
roryqi commented on code in PR #11354:
URL: https://github.com/apache/gravitino/pull/11354#discussion_r3400452690
##########
catalogs/catalog-fileset/src/main/java/org/apache/gravitino/catalog/fileset/FilesetCatalogOperations.java:
##########
@@ -1386,7 +1386,10 @@ FileSystem getFileSystem(Path path, Map<String, String> config) throws IOExcepti
() -> {
if (scheme.equals(SCHEME_HDFS)) {
return new ImpersonationHDFSFileSystemProxy(
- path, config, PrincipalUtils::getCurrentUserName)
+ path,
+ config,
+ PrincipalUtils::getCurrentUserName,
+ GravitinoEnv.getInstance().blockUnsafeRemoteUri())
Review Comment:
Actually i mean that
```
FileFectcher fetcher = FileFetcher.get();
fetcher.initiailize();
```
##########
catalogs/catalog-fileset/src/main/java/org/apache/gravitino/catalog/fileset/FilesetCatalogOperations.java:
##########
@@ -1386,7 +1386,10 @@ FileSystem getFileSystem(Path path, Map<String, String> config) throws IOExcepti
() -> {
if (scheme.equals(SCHEME_HDFS)) {
return new ImpersonationHDFSFileSystemProxy(
- path, config, PrincipalUtils::getCurrentUserName)
+ path,
+ config,
+ PrincipalUtils::getCurrentUserName,
+ GravitinoEnv.getInstance().blockUnsafeRemoteUri())
Review Comment:
Actually i mean like
```
FileFectcher fetcher = FileFetcher.get();
fetcher.initiailize();
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org