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

[GR-44320] Unable to make Kerberos Authenticated http calls due to GSSManager Oid issue #5950

Open
louis2845 opened this issue Feb 10, 2023 · 23 comments

Comments

@louis2845
Copy link

louis2845 commented Feb 10, 2023

Issue is caused by #4700

GraalVM and environment:

OS: Linux RHEL 8
GraalVM version 22.3.1 EE
JDK: 17

GSSException: Unsupported mechanism requested: 1.2.840.113554.1.2.2
at java.security.jgss@17.0.6/sun.security.jgss.ProviderList.getMechFactory(ProviderList.java:199)
at java.security.jgss@17.0.6/sun.security.jgss.ProviderList.getMechFactory(ProviderList.java:166)
at java.security.jgss@17.0.6/sun.security.jgss.GSSManagerImpl.getNameElement(GSSManagerImpl.java:183)
at java.security.jgss@17.0.6/sun.security.jgss.GSSNameImpl.getElement(GSSNameImpl.java:469)
at java.security.jgss@17.0.6/sun.security.jgss.GSSNameImpl.init(GSSNameImpl.java:202)
at java.security.jgss@17.0.6/sun.security.jgss.GSSNameImpl.(GSSNameImpl.java:171)
at java.security.jgss@17.0.6/sun.security.jgss.GSSNameImpl.(GSSNameImpl.java:152)
at java.security.jgss@17.0.6/sun.security.jgss.GSSManagerImpl.createName(GSSManagerImpl.java:109)
at java.security.jgss@17.0.6/sun.net.www.protocol.http.spnego.NegotiatorImpl.init(NegotiatorImpl.java:95)
at java.security.jgss@17.0.6/sun.net.www.protocol.http.spnego.NegotiatorImpl.(NegotiatorImpl.java:123)
at java.base@17.0.6/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
at java.base@17.0.6/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
at java.base@17.0.6/sun.net.www.protocol.http.Negotiator.getNegotiator(Negotiator.java:65)
at java.base@17.0.6/sun.net.www.protocol.http.NegotiateAuthentication.isSupported(NegotiateAuthentication.java:120)
at java.base@17.0.6/sun.net.www.protocol.http.AuthenticationHeader.parse(AuthenticationHeader.java:201)
at java.base@17.0.6/sun.net.www.protocol.http.AuthenticationHeader.(AuthenticationHeader.java:144)
at java.base@17.0.6/sun.net.www.protocol.http.AuthenticationHeader.(AuthenticationHeader.java:124)
at java.base@17.0.6/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1818)
at java.base@17.0.6/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1589)
at java.base@17.0.6/java.net.URLConnection.getContent(URLConnection.java:753)
at java.base@17.0.6/sun.net.www.protocol.https.HttpsURLConnectionImpl.getContent(HttpsURLConnectionImpl.java:404)

Like the attached issue it is difficult to recreate the environment due to needing to set up an entire Active Directory / Kerberos environment - but the code in the attached issue should recreate the problem

Seems like the code below should populate providers but it doesn't

    public GSSManagerImpl(GSSCaller caller) {
        list = new ProviderList(caller, USE_NATIVE);
    }
@oubidar-Abderrahim
Copy link
Member

Hi, Thank you for reporting this issue, please share a complete reproducer of this issue. with steps to reproduce. Thank you

@louis2845
Copy link
Author

I think I commented on #4700 that there should be all you need there to recreate the problem. There is a java class and steps to compile it into native. Is there anything else you'd like me to provide?

@oubidar-Abderrahim
Copy link
Member

Running the Sample class shared on #4700 throws the following

Exception in thread "main" GSSException: Invalid name provided (Mechanism level: KrbException: Cannot locate default realm)
	at java.security.jgss/sun.security.jgss.krb5.Krb5NameElement.getInstance(Krb5NameElement.java:127)
	at java.security.jgss/sun.security.jgss.krb5.Krb5MechFactory.getNameElement(Krb5MechFactory.java:99)
	at java.security.jgss/sun.security.jgss.GSSManagerImpl.getNameElement(GSSManagerImpl.java:184)
	at java.security.jgss/sun.security.jgss.GSSNameImpl.getElement(GSSNameImpl.java:469)
	at java.security.jgss/sun.security.jgss.GSSNameImpl.init(GSSNameImpl.java:202)
	at java.security.jgss/sun.security.jgss.GSSNameImpl.<init>(GSSNameImpl.java:171)
	at java.security.jgss/sun.security.jgss.GSSNameImpl.<init>(GSSNameImpl.java:152)
	at java.security.jgss/sun.security.jgss.GSSManagerImpl.createName(GSSManagerImpl.java:109)
	at Sample.main(Sample.java:7)

which doesn't seem to be a bug on GraalVM.

@louis2845
Copy link
Author

I see, I think you may need to specify the krb5 config. Sorry for this, I will get back to you later today

@louis2845
Copy link
Author

It seems as though you've actually gotten past the point which is causing an issue for me:

me - > at java.security.jgss/sun.security.jgss.GSSManagerImpl.getNameElement(GSSManagerImpl.java:183)
you -> at java.security.jgss/sun.security.jgss.GSSManagerImpl.getNameElement(GSSManagerImpl.java:184)

Looking at the code provided in the previous ticket:

javac Sample.java
java -agentlib:native-image-agent=config-output-dir=META-INF/native-image Sample
native-image --no-fallback Sample

The middle java call should fail where you are seeing an exception without proper Kerberos configuration.

Were you definitely running the native image?

javac Sample.java
native-image --no-fallback Sample
./sample

I've just tried the above and am still seeing:

Exception in thread "main" GSSException: Unsupported mechanism requested: 1.2.840.113554.1.2.2
at java.security.jgss@17.0.6/sun.security.jgss.ProviderList.getMechFactory(ProviderList.java:199)
at java.security.jgss@17.0.6/sun.security.jgss.ProviderList.getMechFactory(ProviderList.java:166)
at java.security.jgss@17.0.6/sun.security.jgss.GSSManagerImpl.getNameElement(GSSManagerImpl.java:183)
at java.security.jgss@17.0.6/sun.security.jgss.GSSNameImpl.getElement(GSSNameImpl.java:469)
at java.security.jgss@17.0.6/sun.security.jgss.GSSNameImpl.init(GSSNameImpl.java:202)
at java.security.jgss@17.0.6/sun.security.jgss.GSSNameImpl.(GSSNameImpl.java:171)
at java.security.jgss@17.0.6/sun.security.jgss.GSSNameImpl.(GSSNameImpl.java:152)
at java.security.jgss@17.0.6/sun.security.jgss.GSSManagerImpl.createName(GSSManagerImpl.java:109)
at Sample.main(Sample.java:9)

@oubidar-Abderrahim
Copy link
Member

Tracked internally on GR 44320

@vjovanov
Copy link
Member

vjovanov commented Oct 4, 2023

Thank you for a great reproducer! To make this work you need to add the flag -H:AdditionalSecurityProviders=sun.security.jgss.SunProvider the image build.

We will work to provide a better user experience around this feature.

@autodidacticon
Copy link

autodidacticon commented Nov 7, 2023

Thank you for a great reproducer! To make this work you need to add the flag -H:AdditionalSecurityProviders=sun.security.jgss.SunProvider the image build.

We will work to provide a better user experience around this feature.

Where can we find definitive reference to this flag?

@vjovanov
Copy link
Member

What is a definitive reference? We will document this better in the upcoming releases, but first, we need to revisit the defaults. I feel this one should be included by default.

@autodidacticon
Copy link

@vjovanov Where is the documentation to the flag -H:AdditionalSecurityProviders?

@vjovanov
Copy link
Member

I wish I had a good answer. We will be improving this feature for JDK 23. Until then the best I can say is that this is the list of possible values in the JDK is:

['sun.security.provider.Sun', 'sun.security.rsa.SunRsaSign', 'sun.security.ec.SunEC', 'sun.security.ssl.SunJSSE', 'com.sun.crypto.provider.SunJCE', 'sun.security.jgss.SunProvider', 'com.sun.security.sasl.Provider', 'org.jcp.xml.dsig.internal.dom.XMLDSigRI', 'sun.security.smartcardio.SunPCSC', 'sun.security.provider.certpath.ldap.JdkLDAP', 'com.sun.security.sasl.gsskerb.JdkSASL']

I got this by running sun.security.jca.Providers.getProviderList() and inspecting class names.

@oubidar-Abderrahim oubidar-Abderrahim changed the title Unable to make Kerberos Authenticated http calls due to GSSManager Oid issue [GR-44320] Unable to make Kerberos Authenticated http calls due to GSSManager Oid issue Mar 12, 2024
@aanavaneeth
Copy link

aanavaneeth commented Apr 1, 2024

In my case, graalvm is not respecting sun.security.jgss.native=true. (ref: native gss)

I tried buildArgs.add('-J-Dsun.security.jgss.native=true') and buildArgs.add('-Dsun.security.jgss.native=true') as well.

Logged #8674 for this with more details

@vjovanov
Copy link
Member

vjovanov commented Apr 1, 2024

Thank you very much for reporting the issue! We will look into it and see why it happens.

@yogeshkumargeek
Copy link

yogeshkumargeek commented Oct 8, 2024

Hey @vjovanov , Facing same issue REF while implementing kerberos auth with native image in micronaut.
Can you please here ?
It's been quite some time for this issue .Please expedite this

@aanavaneeth
Copy link

If we have a way to create the instance of gssmanager by passing the "native" as parameter rather than using jvm arguments can help I guess. That would be a jdk change rather than graalvm. However, graalvm handling this also works. I wish they prioritise this. This is blocking a lot of enterprise software from using graalvm native compilation feature.

@vjovanov vjovanov assigned jovanstevanovic and unassigned vjovanov Oct 9, 2024
@vjovanov
Copy link
Member

vjovanov commented Oct 9, 2024

@jovanstevanovic is working in this area now so we should be able to provide a fix in the next release.

@aanavaneeth
Copy link

Wow that's a great news!! Thank you so much!!

@jovanstevanovic
Copy link
Member

No worries. I can have a look.

@yogeshkumar-1234
Copy link

Hey @vjovanov , is there any alternative present at the moment for this kerberos auth issue in native image ?

@jovanstevanovic
Copy link
Member

@yogeshkumar-1234 the solution in the comment does not help you?

@aanavaneeth
Copy link

I tried it sometimes back. It didn't work for me. I can check once again.

@yogeshkumar-1234
Copy link

yogeshkumar-1234 commented Oct 15, 2024

@jovanstevanovic It didn't work for me > @yogeshkumar-1234 the solution in the comment does not help you?

@jovanstevanovic
Copy link
Member

Okay, just to double-check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants