Skip to content
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

[#1185] feat(server-common): Server supports Kerberos authentication #1614

Merged
merged 36 commits into from
Jan 25, 2024

Conversation

qqqttt123
Copy link
Contributor

@qqqttt123 qqqttt123 commented Jan 19, 2024

What changes were proposed in this pull request?

Server supports Kerberos authentication. I referred to the implementation of Hadoop.
I will submit another pr about the client.

Why are the changes needed?

Fix: #1185.

Does this PR introduce any user-facing change?

Added the document.

How was this patch tested?

Add a new UT.

@qqqttt123 qqqttt123 marked this pull request as draft January 19, 2024 08:04
@qqqttt123 qqqttt123 marked this pull request as ready for review January 19, 2024 10:57
@qqqttt123 qqqttt123 requested review from jerryshao, FANNG1, xunliu, diqiu50, yuqi1129, mchades and Clearvive and removed request for jerryshao January 19, 2024 10:57
@mchades
Copy link
Contributor

mchades commented Jan 22, 2024

openapi.yaml should also be modified

@qqqttt123
Copy link
Contributor Author

qqqttt123 commented Jan 22, 2024

openapi.yaml should also be modified

Added.

Heng Qin added 2 commits January 22, 2024 15:24
@qqqttt123 qqqttt123 added this to the Gravitino 0.4.0 milestone Jan 24, 2024
@qqqttt123 qqqttt123 self-assigned this Jan 24, 2024
@qqqttt123
Copy link
Contributor Author

@mchades @jerryshao @yuqi1129 @diqiu50 @FANNG1 @Clearvive Could you help me review this pr?

String challenge = AuthConstants.AUTHORIZATION_NEGOTIATE_HEADER + authenticateToken;
throw new UnauthorizedException("GssContext isn't established", challenge);
}
// Usually principal names are in the form 'user/instance@REALM' or 'user@REALM'.
Copy link
Contributor Author

@qqqttt123 qqqttt123 Jan 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I simplify the logic of convertion from principal to user.

@Override
public void initialize(Config config) throws RuntimeException {
try {
String principal = config.get(KerberosConfig.PRINCIPAL);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't support * principal.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add this to the comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

if (!keytabFile.exists()) {
throw new IllegalArgumentException("Keytab doesn't exist: " + keytab);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We remove the validation of rule names.

docs/security.md Outdated
| `gravitino.authenticator.oauth.tokenPath` | The path for token of the default OAuth server. | (none) | Yes if use `oauth` as the authenticator | 0.3.0 |
| Configuration item | Description | Default value | Required | Since version |
|---------------------------------------------------|-----------------------------------------------------------------------------|-------------------|--------------------------------------------|---------------|
| `gravitino.authenticator` | The authenticator which Gravitino uses, setting as `simple` or `oauth`. | `simple` | No | 0.3.0 |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need to update this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

for (String challenge : ue.getChallenges()) {
resp.setHeader(AuthConstants.HTTP_CHALLENGE_HEADER, challenge);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add more comment here about the reason of this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@Override
public void initialize(Config config) throws RuntimeException {
try {
String principal = config.get(KerberosConfig.PRINCIPAL);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add this to the comment.

@@ -78,7 +78,8 @@ project.extra["extraJvmArgs"] = if (extra["jdkVersion"] in listOf("8", "11")) {
"--add-opens", "java.base/sun.nio.ch=ALL-UNNAMED",
"--add-opens", "java.base/sun.nio.cs=ALL-UNNAMED",
"--add-opens", "java.base/sun.security.action=ALL-UNNAMED",
"--add-opens", "java.base/sun.util.calendar=ALL-UNNAMED"
"--add-opens", "java.base/sun.util.calendar=ALL-UNNAMED",
"--add-opens", "java.security.jgss/sun.security.krb5=ALL-UNNAMED"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should also update the start script under "bin".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

// Referred from Apache Hadoop KerberosTestUtils.java
// hadoop-common-project/hadoop-auth/src/test/java/org/apache/hadoop/security/\
// authentication/KerberosTestUtils.java
public class KerberosUtils {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still the same thing here, please point out which part did you modify for what purpose.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Subject subject = new Subject(false, principals, new HashSet<>(), new HashSet<>());
loginContext =
new LoginContext("", subject, null, new KerberosConfiguration(principal, keyTabFile));
loginContext.login();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have to login everytime, is it a typical implementation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Split this into two methods.

String principal = config.get(KerberosConfig.PRINCIPAL);
String keytab = config.get(KerberosConfig.KEYTAB);
File keytabFile = new File(keytab);
if (!keytabFile.exists()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should also check the permission file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

new PrivilegedExceptionAction<Principal>() {
@Override
public Principal run() throws Exception {
return validClientToken(serverPrincipal, clientToken);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

validateClientToken?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.


// Referred from Apache Hadoop KerberosUtil.java
// hadoop-common-project/hadoop-auth/src/main/java/org/apache/hadoop/\
// security/authentication/util/KerberosUtil.java
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also here, please point out which part did you modify for what purpose?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@qqqttt123 qqqttt123 requested a review from jerryshao January 25, 2024 09:55
getNumericOidInstance("1.2.840.113554.1.2.2.1");

// numeric oids will never generate a GSSException for a malformed oid.
// use to initialize statics.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capitalize the first letter.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

}
}

public static LoginContext login(String principal, String keyTabFile) throws LoginException {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need a logout method?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will call LoginContext.logout

}
}

private Principal validateClientToken(String serverPrincipal, byte[] clientToken)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method doesn't only validate the token, but also return the user principal if the check is passed. I would suggest use a better method name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about retrievePrincipalFromToken?

@qqqttt123 qqqttt123 requested a review from jerryshao January 25, 2024 11:10
@jerryshao jerryshao merged commit 173dd07 into apache:main Jan 25, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Improvement] Server supports the authentication of Kerberos
3 participants