-
Notifications
You must be signed in to change notification settings - Fork 1k
Initial support for Kerberos auth #7211
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
dagnir
merged 3 commits into
feature/master/netty-kerberos-proxy-auth
from
dongie/netty-kerberos-proxy-auth
Aug 3, 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
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
45 changes: 45 additions & 0 deletions
45
...netty-nio-client/src/main/java/software/amazon/awssdk/http/nio/netty/ProxyAuthScheme.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,45 @@ | ||
| /* | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"). | ||
| * You may not use this file except in compliance with the License. | ||
| * A copy of the License is located at | ||
| * | ||
| * http://aws.amazon.com/apache2.0 | ||
| * | ||
| * or in the "license" file accompanying this file. This file 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 software.amazon.awssdk.http.nio.netty; | ||
|
|
||
| import software.amazon.awssdk.annotations.SdkPublicApi; | ||
|
|
||
| /** | ||
| * Supported auth schemes for authentication with a proxy. | ||
| */ | ||
| @SdkPublicApi | ||
| public enum ProxyAuthScheme { | ||
| /** | ||
| * Basic authentication. | ||
| */ | ||
| BASIC("Basic"), | ||
|
|
||
| /** | ||
| * Kerberos authentication. | ||
| */ | ||
| NEGOTIATE("Negotiate"), | ||
| ; | ||
|
|
||
| private final String value; | ||
|
|
||
| ProxyAuthScheme(String value) { | ||
| this.value = value; | ||
| } | ||
|
|
||
| public String value() { | ||
| return value; | ||
| } | ||
| } | ||
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
43 changes: 43 additions & 0 deletions
43
...src/main/java/software/amazon/awssdk/http/nio/netty/internal/BasicProxyAuthGenerator.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,43 @@ | ||
| /* | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"). | ||
| * You may not use this file except in compliance with the License. | ||
| * A copy of the License is located at | ||
| * | ||
| * http://aws.amazon.com/apache2.0 | ||
| * | ||
| * or in the "license" file accompanying this file. This file 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 software.amazon.awssdk.http.nio.netty.internal; | ||
|
|
||
| import io.netty.handler.codec.http.HttpRequest; | ||
| import io.netty.util.CharsetUtil; | ||
| import java.net.URI; | ||
| import java.util.Base64; | ||
| import software.amazon.awssdk.http.nio.netty.ProxyAuthScheme; | ||
|
|
||
| public class BasicProxyAuthGenerator implements ProxyAuthGenerator { | ||
| private final String username; | ||
| private final String password; | ||
|
|
||
| public BasicProxyAuthGenerator(String username, String password) { | ||
| this.username = username; | ||
| this.password = password; | ||
| } | ||
|
|
||
| @Override | ||
| public ProxyAuthScheme scheme() { | ||
| return ProxyAuthScheme.BASIC; | ||
| } | ||
|
|
||
| @Override | ||
| public String generateAuthParams(URI proxyEndpoint) { | ||
| String authToken = String.format("%s:%s", this.username, this.password); | ||
| return Base64.getEncoder().encodeToString(authToken.getBytes(CharsetUtil.UTF_8)); | ||
| } | ||
| } |
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
131 changes: 131 additions & 0 deletions
131
...main/java/software/amazon/awssdk/http/nio/netty/internal/NegotiateProxyAuthGenerator.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,131 @@ | ||
| /* | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"). | ||
| * You may not use this file except in compliance with the License. | ||
| * A copy of the License is located at | ||
| * | ||
| * http://aws.amazon.com/apache2.0 | ||
| * | ||
| * or in the "license" file accompanying this file. This file 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 software.amazon.awssdk.http.nio.netty.internal; | ||
|
|
||
| import com.sun.security.auth.module.Krb5LoginModule; | ||
| import io.netty.handler.codec.http.HttpRequest; | ||
| import java.net.URI; | ||
| import java.security.PrivilegedActionException; | ||
| import java.security.PrivilegedExceptionAction; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import javax.security.auth.Subject; | ||
| import javax.security.auth.login.AppConfigurationEntry; | ||
| import javax.security.auth.login.Configuration; | ||
| import javax.security.auth.login.LoginContext; | ||
| import javax.security.auth.login.LoginException; | ||
| import org.ietf.jgss.GSSContext; | ||
| import org.ietf.jgss.GSSException; | ||
| import org.ietf.jgss.GSSManager; | ||
| import org.ietf.jgss.GSSName; | ||
| import org.ietf.jgss.Oid; | ||
| import software.amazon.awssdk.annotations.SdkInternalApi; | ||
| import software.amazon.awssdk.annotations.SdkTestInternalApi; | ||
| import software.amazon.awssdk.http.SdkHttpRequest; | ||
| import software.amazon.awssdk.http.nio.netty.ProxyAuthScheme; | ||
| import software.amazon.awssdk.utils.BinaryUtils; | ||
|
|
||
| /** | ||
| * Auth generator for Kerberos. This does not login/authentication to Kerberos. It expects the ticket cache to be present and | ||
| * simply reads that to generate the token. | ||
|
dagnir marked this conversation as resolved.
|
||
| */ | ||
| @SdkInternalApi | ||
| public class NegotiateProxyAuthGenerator implements ProxyAuthGenerator { | ||
| // SPNEGO pseudo-mechanism OID. Lets the proxy negotiate Kerberos over HTTP "Negotiate". | ||
| // See https://www.ietf.org/rfc/rfc4178.txt for more info | ||
| private static final String OID = "1.3.6.1.5.5.2"; | ||
|
dagnir marked this conversation as resolved.
|
||
| private static final String SERVICE_NAME = "HTTP"; | ||
| private final Configuration config; | ||
|
|
||
| public NegotiateProxyAuthGenerator() { | ||
| this(createDefaultConfig()); | ||
| } | ||
|
|
||
| @SdkTestInternalApi | ||
| NegotiateProxyAuthGenerator(Configuration config) { | ||
| this.config = config; | ||
| } | ||
|
|
||
| @Override | ||
| public ProxyAuthScheme scheme() { | ||
| return ProxyAuthScheme.NEGOTIATE; | ||
| } | ||
|
|
||
| @Override | ||
| public String generateAuthParams(URI proxyEndpoint) { | ||
| try { | ||
| Subject subject = getSubject(); | ||
|
|
||
| byte[] token = Subject.doAs(subject, (PrivilegedExceptionAction<byte[]>) () -> { | ||
| GSSContext ctx = createGSSContext(getManager(), proxyEndpoint); | ||
| ctx.requestMutualAuth(true); | ||
| return ctx.initSecContext(new byte[0], 0, 0); | ||
| }); | ||
|
|
||
| return BinaryUtils.toBase64(token); | ||
| } catch (PrivilegedActionException e) { | ||
| throw new RuntimeException("Unable to generate token", e); | ||
| } | ||
| } | ||
|
|
||
| private Subject getSubject() { | ||
| try { | ||
| LoginContext loginContext = new LoginContext("dummy", null, null, config); | ||
| loginContext.login(); | ||
| return loginContext.getSubject(); | ||
| } catch (LoginException e) { | ||
| throw new RuntimeException("Unable to perform login", e); | ||
| } | ||
| } | ||
|
|
||
| private GSSContext createGSSContext(GSSManager manager, URI endpoint) { | ||
| try { | ||
| String name = String.format("%s@%s", SERVICE_NAME, endpoint.getHost()); | ||
| GSSName serverName = manager.createName(name, GSSName.NT_HOSTBASED_SERVICE); | ||
| Oid spnegoOid = new Oid(OID); | ||
| return manager.createContext(serverName, spnegoOid, null, | ||
| GSSContext.DEFAULT_LIFETIME); | ||
| } catch (GSSException e) { | ||
| throw new RuntimeException("Unable to create GSSContext", e); | ||
| } | ||
| } | ||
|
|
||
| private static GSSManager getManager() { | ||
| return GSSManager.getInstance(); | ||
| } | ||
|
|
||
| /** | ||
| * Create a generic {@link Configuration} that instructs the Kerberos login module to simply look in the ticket cache, and | ||
| * not to prompt for passwords. | ||
| * <p> | ||
| * See javadoc for {@link Krb5LoginModule} for additional info on the configuration options. | ||
| */ | ||
| private static Configuration createDefaultConfig() { | ||
| return new Configuration() { | ||
| @Override | ||
| public AppConfigurationEntry[] getAppConfigurationEntry(String name) { | ||
| Map<String, String> opts = new HashMap<>(); | ||
| opts.put("useTicketCache", "true"); | ||
| opts.put("doNotPrompt", "true"); | ||
| return new AppConfigurationEntry[] { | ||
| new AppConfigurationEntry( | ||
| "com.sun.security.auth.module.Krb5LoginModule", | ||
| AppConfigurationEntry.LoginModuleControlFlag.REQUIRED, opts) | ||
| }; | ||
| } | ||
| }; | ||
| } | ||
| } | ||
37 changes: 37 additions & 0 deletions
37
...ient/src/main/java/software/amazon/awssdk/http/nio/netty/internal/ProxyAuthGenerator.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,37 @@ | ||
| /* | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"). | ||
| * You may not use this file except in compliance with the License. | ||
| * A copy of the License is located at | ||
| * | ||
| * http://aws.amazon.com/apache2.0 | ||
| * | ||
| * or in the "license" file accompanying this file. This file 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 software.amazon.awssdk.http.nio.netty.internal; | ||
|
|
||
| import io.netty.handler.codec.http.HttpRequest; | ||
| import java.net.URI; | ||
| import software.amazon.awssdk.annotations.SdkInternalApi; | ||
| import software.amazon.awssdk.http.nio.netty.ProxyAuthScheme; | ||
|
|
||
| /** | ||
| * Generates the auth params for an {@code Authorization} HTTP header. | ||
| */ | ||
| @SdkInternalApi | ||
| public interface ProxyAuthGenerator { | ||
| /** | ||
| * The name of the auth scheme this generator supports. | ||
| */ | ||
| ProxyAuthScheme scheme(); | ||
|
|
||
| /** | ||
| * Generate the auth params for this request. | ||
| */ | ||
| String generateAuthParams(URI proxyEndpoint); | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.