-
Notifications
You must be signed in to change notification settings - Fork 406
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
[#3432] improvement(test): Add kerberos authentication IT for HDFS cluster #3435
Merged
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
fd390d0
Add kerberos IT
yuqi1129 780e375
Fix
yuqi1129 9c0a2ed
Fix test error
yuqi1129 3a6a31b
Merge branch 'main' of github.com:datastrato/graviton into issue_3432
yuqi1129 3f06416
Add fix.
yuqi1129 85e6b73
fix
yuqi1129 66640fc
fix
yuqi1129 01dbf60
Fix
yuqi1129 d6960c8
Merge branch 'main' into issue_3432
yuqi1129 e71dde3
Remove unused code.
yuqi1129 5a26aa1
Merge remote-tracking branch 'me/issue_3432' into issue_3432
yuqi1129 6488d03
Merge branch 'main' into issue_3432
yuqi1129 8aa9b4d
optimize code.
yuqi1129 4609efb
Merge remote-tracking branch 'me/issue_3432' into issue_3432
yuqi1129 30d4c60
Fix mistake
yuqi1129 965f63a
Revert the code that check status of `show databases` for Hive contai…
yuqi1129 0f8051c
Merge branch 'main' into issue_3432
yuqi1129 6919203
Merge main and rebase the code.
yuqi1129 ac82116
Merge remote-tracking branch 'me/issue_3432' into issue_3432
yuqi1129 2cb6eb6
Resolve comments
yuqi1129 cea7331
Merge main and resolve conflicts
yuqi1129 83d661a
Remove used environment
yuqi1129 64dbfc4
Fix style
yuqi1129 3f3fd1f
Merge branch 'main' into issue_3432
yuqi1129 7a2b2a3
Increase retry number.
yuqi1129 b7b06a7
Merge remote-tracking branch 'me/issue_3432' into issue_3432
yuqi1129 2089149
fix
yuqi1129 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
This file contains 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
120 changes: 120 additions & 0 deletions
120
...rc/test/java/com/datastrato/gravitino/catalog/hadoop/integration/test/HDFSKerberosIT.java
This file contains 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,120 @@ | ||
/* | ||
* Copyright 2024 Datastrato Pvt Ltd. | ||
* This software is licensed under the Apache License version 2. | ||
*/ | ||
|
||
package com.datastrato.gravitino.catalog.hadoop.integration.test; | ||
|
||
import com.datastrato.gravitino.integration.test.container.ContainerSuite; | ||
import com.datastrato.gravitino.integration.test.container.HiveContainer; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Files; | ||
import java.security.PrivilegedAction; | ||
import org.apache.commons.io.FileUtils; | ||
import org.apache.hadoop.conf.Configuration; | ||
import org.apache.hadoop.fs.FileSystem; | ||
import org.apache.hadoop.fs.Path; | ||
import org.apache.hadoop.security.AccessControlException; | ||
import org.apache.hadoop.security.UserGroupInformation; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Tag; | ||
import org.junit.jupiter.api.Test; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
@Tag("gravitino-docker-it") | ||
public class HDFSKerberosIT { | ||
private static final Logger LOG = LoggerFactory.getLogger(HDFSKerberosIT.class); | ||
|
||
private static final ContainerSuite containerSuite = ContainerSuite.getInstance(); | ||
private static final String CLIENT_PRINCIPAL = "cli@HADOOPKRB"; | ||
private static UserGroupInformation clientUGI; | ||
|
||
private static String keytabPath; | ||
|
||
@BeforeAll | ||
public static void setup() throws IOException { | ||
containerSuite.startKerberosHiveContainer(); | ||
|
||
File baseDir = new File(System.getProperty("java.io.tmpdir")); | ||
File file = Files.createTempDirectory(baseDir.toPath(), "test").toFile(); | ||
file.deleteOnExit(); | ||
|
||
// Copy the keytab and krb5.conf from the container | ||
keytabPath = file.getAbsolutePath() + "/client.keytab"; | ||
containerSuite | ||
.getKerberosHiveContainer() | ||
.getContainer() | ||
.copyFileFromContainer("/etc/admin.keytab", keytabPath); | ||
|
||
String krb5TmpPath = file.getAbsolutePath() + "/krb5.conf_tmp"; | ||
String krb5Path = file.getAbsolutePath() + "/krb5.conf"; | ||
containerSuite | ||
.getKerberosHiveContainer() | ||
.getContainer() | ||
.copyFileFromContainer("/etc/krb5.conf", krb5TmpPath); | ||
|
||
// Modify the krb5.conf and change the kdc and admin_server to the container IP | ||
String ip = containerSuite.getKerberosHiveContainer().getContainerIpAddress(); | ||
String content = FileUtils.readFileToString(new File(krb5TmpPath), StandardCharsets.UTF_8); | ||
content = content.replace("kdc = localhost:88", "kdc = " + ip + ":88"); | ||
content = content.replace("admin_server = localhost", "admin_server = " + ip + ":749"); | ||
FileUtils.write(new File(krb5Path), content, StandardCharsets.UTF_8); | ||
|
||
LOG.info("Kerberos kdc config:\n{}", content); | ||
|
||
System.setProperty("java.security.krb5.conf", krb5Path); | ||
System.setProperty("sun.security.krb5.debug", "true"); | ||
} | ||
|
||
@AfterAll | ||
public static void tearDown() { | ||
// Reset the UGI | ||
UserGroupInformation.reset(); | ||
|
||
// Clean up the kerberos configuration | ||
System.clearProperty("java.security.krb5.conf"); | ||
System.clearProperty("sun.security.krb5.debug"); | ||
} | ||
|
||
@Test | ||
public void testKerberosHDFS() throws IOException { | ||
Configuration conf = new Configuration(); | ||
conf.set("fs.defaultFS", defaultBaseLocation()); | ||
conf.setBoolean("fs.hdfs.impl.disable.cache", true); | ||
conf.set("hadoop.security.authentication", "kerberos"); | ||
|
||
UserGroupInformation.setConfiguration(conf); | ||
clientUGI = UserGroupInformation.loginUserFromKeytabAndReturnUGI(CLIENT_PRINCIPAL, keytabPath); | ||
PrivilegedAction<?> action = | ||
(PrivilegedAction) | ||
() -> { | ||
try { | ||
FileSystem fs = FileSystem.get(conf); | ||
Path path = new Path("/"); | ||
Assertions.assertTrue(fs.exists(path)); | ||
return null; | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
}; | ||
|
||
clientUGI.doAs(action); | ||
|
||
// Clear UGI, It will throw exception | ||
UserGroupInformation.reset(); | ||
Exception e = Assertions.assertThrows(Exception.class, action::run); | ||
Assertions.assertInstanceOf(AccessControlException.class, e.getCause()); | ||
} | ||
|
||
private static String defaultBaseLocation() { | ||
return String.format( | ||
"hdfs://%s:%d/user/", | ||
containerSuite.getKerberosHiveContainer().getContainerIpAddress(), | ||
HiveContainer.HDFS_DEFAULTFS_PORT); | ||
} | ||
} |
This file contains 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 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 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
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.
You need to create a file and check the file owner to see if it is expected.
If kerberos is enabled, the user should be "cli" from my understanding.