-
Notifications
You must be signed in to change notification settings - Fork 906
[#10741] fix(hive): Fix keytab symlink TOCTOU race in FetchFileUtils #10742
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
yuqi1129
merged 3 commits into
apache:main
from
diqiu50:upstream/hive-keytab-toctou-fix
Apr 15, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
65 changes: 0 additions & 65 deletions
65
catalogs/catalog-hive/src/main/java/org/apache/gravitino/catalog/hive/FetchFileUtils.java
This file was deleted.
Oops, something went wrong.
95 changes: 0 additions & 95 deletions
95
...logs/catalog-hive/src/test/java/org/apache/gravitino/catalog/hive/TestFetchFileUtils.java
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
...metastore-common/src/test/java/org/apache/gravitino/hive/kerberos/TestFetchFileUtils.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| /* | ||
| * 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.hive.kerberos; | ||
|
|
||
| import java.io.File; | ||
| import java.nio.file.Files; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.concurrent.CyclicBarrier; | ||
| import java.util.concurrent.ExecutorService; | ||
| import java.util.concurrent.Executors; | ||
| import java.util.concurrent.Future; | ||
| import java.util.concurrent.TimeUnit; | ||
| import org.apache.hadoop.conf.Configuration; | ||
| import org.junit.jupiter.api.Assertions; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.io.TempDir; | ||
|
|
||
| public class TestFetchFileUtils { | ||
|
|
||
| @TempDir File tempDir; | ||
|
|
||
| @Test | ||
| public void testLinkLocalFile() throws Exception { | ||
| File srcFile = new File(tempDir, "source"); | ||
| Assertions.assertTrue(srcFile.createNewFile()); | ||
| File destFile = new File(tempDir, "dest"); | ||
|
|
||
| FetchFileUtils.fetchFileFromUri(srcFile.toURI().toString(), destFile, 10, new Configuration()); | ||
| Assertions.assertTrue(Files.isSymbolicLink(destFile.toPath())); | ||
| Assertions.assertEquals(srcFile.toPath(), Files.readSymbolicLink(destFile.toPath())); | ||
| } | ||
|
|
||
| @Test | ||
| public void testConcurrentSymlinkCreation() throws Exception { | ||
| File srcFile = new File(tempDir, "source_concurrent"); | ||
| Assertions.assertTrue(srcFile.createNewFile()); | ||
| File destFile = new File(tempDir, "dest_concurrent"); | ||
|
|
||
| int threadCount = 10; | ||
| CyclicBarrier barrier = new CyclicBarrier(threadCount); | ||
| ExecutorService executor = Executors.newFixedThreadPool(threadCount); | ||
| List<Future<?>> futures = new ArrayList<>(); | ||
|
diqiu50 marked this conversation as resolved.
|
||
| try { | ||
| for (int i = 0; i < threadCount; i++) { | ||
| futures.add( | ||
| executor.submit( | ||
| () -> { | ||
| try { | ||
| barrier.await(30, TimeUnit.SECONDS); | ||
| FetchFileUtils.fetchFileFromUri( | ||
| srcFile.toURI().toString(), destFile, 10, new Configuration()); | ||
|
diqiu50 marked this conversation as resolved.
|
||
| } catch (Exception e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| })); | ||
| } | ||
| for (Future<?> future : futures) { | ||
| future.get(30, TimeUnit.SECONDS); | ||
| } | ||
|
diqiu50 marked this conversation as resolved.
|
||
| } finally { | ||
| executor.shutdownNow(); | ||
| } | ||
|
|
||
| Assertions.assertTrue(Files.isSymbolicLink(destFile.toPath())); | ||
| Assertions.assertEquals(srcFile.toPath(), Files.readSymbolicLink(destFile.toPath())); | ||
| } | ||
|
|
||
| @Test | ||
| public void testIdempotentSymlinkCreation() throws Exception { | ||
| File srcFile = new File(tempDir, "source_idempotent"); | ||
| Assertions.assertTrue(srcFile.createNewFile()); | ||
| File destFile = new File(tempDir, "dest_idempotent"); | ||
|
|
||
| Configuration conf = new Configuration(); | ||
| String uri = srcFile.toURI().toString(); | ||
|
|
||
| FetchFileUtils.fetchFileFromUri(uri, destFile, 10, conf); | ||
| Assertions.assertTrue(Files.isSymbolicLink(destFile.toPath())); | ||
|
|
||
| // Second call to the same dest should succeed without error | ||
| FetchFileUtils.fetchFileFromUri(uri, destFile, 10, conf); | ||
| Assertions.assertTrue(Files.isSymbolicLink(destFile.toPath())); | ||
| Assertions.assertEquals(srcFile.toPath(), Files.readSymbolicLink(destFile.toPath())); | ||
| } | ||
|
|
||
| @Test | ||
| public void testSymlinkReplacedWithDifferentTarget() throws Exception { | ||
| File srcFileA = new File(tempDir, "source_a"); | ||
| File srcFileB = new File(tempDir, "source_b"); | ||
| Assertions.assertTrue(srcFileA.createNewFile()); | ||
| Assertions.assertTrue(srcFileB.createNewFile()); | ||
| File destFile = new File(tempDir, "dest_replace"); | ||
|
|
||
| Configuration conf = new Configuration(); | ||
|
|
||
| FetchFileUtils.fetchFileFromUri(srcFileA.toURI().toString(), destFile, 10, conf); | ||
| Assertions.assertEquals(srcFileA.toPath(), Files.readSymbolicLink(destFile.toPath())); | ||
|
|
||
| FetchFileUtils.fetchFileFromUri(srcFileB.toURI().toString(), destFile, 10, conf); | ||
| Assertions.assertEquals(srcFileB.toPath(), Files.readSymbolicLink(destFile.toPath())); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When will it be clear?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Close at the Kerberos client closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not see related close logic on it. As it's a static field, I believe it will only be clear when the classloader is closed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a function removeLock, which is called when the Kerberos client closes.