Disabling JNDI by default

420 views
Skip to first unread message

Stuart Douglas

unread,
Dec 13, 2021, 5:18:06 PM12/13/21
to Quarkus Development mailing list
Hi Everyone,

I have opened a PR that will effectively disable JNDI by default:


Basically as one of the first parts of startup a non-functional InitialContextFactoryBuilder is installed in the NamingManager, so any attempts to create an InitialContext will result in this disabled context being used.

I am pretty sure that the vast majority of Quarkus applications have no use for JNDI, so it seems like disabling it by default could be a nice safety measure, however I am curious to hear what others think.

Stuart

George Gastaldi

unread,
Dec 13, 2021, 5:22:48 PM12/13/21
to Stuart Douglas, Quarkus Development mailing list
+1, I think that makes sense but I am not sure how other extensions integrating external servers (artemis/infinispan/narayana) would behave with this change. 

--
You received this message because you are subscribed to the Google Groups "Quarkus Development mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to quarkus-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/quarkus-dev/CAD%2BL2cwdvUreP_he53Bo_eTRQm%3D1b0DnQM%2BLkJMvPLV2RoLAiw%40mail.gmail.com.

Stuart Douglas

unread,
Dec 13, 2021, 6:16:14 PM12/13/21
to George Gastaldi, Quarkus Development mailing list
It should be ok, as I have changed it to now just throw NamingException rather than UnsupportedOperationException. If there are any issues the test suite should pick them up.

Stuart

Sanne Grinovero

unread,
Dec 13, 2021, 6:31:56 PM12/13/21
to Stuart Douglas, George Gastaldi, Quarkus Development mailing list

clement escoffier

unread,
Dec 14, 2021, 3:33:59 AM12/14/21
to sanne.g...@gmail.com, George Gastaldi, Quarkus Development mailing list, Stuart Douglas
Hello,

That’s great, and yes, disabling it by default makes sense.

On top of my mind, it might break Mongo. To resolve mongo+srv URLs, the mongo client uses JNDI. This feature is not supported in native (explicitly) but worked in JVM. So, we may have to update the mongo documentation to re-enable JNDI when you need this feature.

Clement

Stuart Douglas

unread,
Dec 14, 2021, 4:19:08 AM12/14/21
to clement escoffier, Sanne Grinovero, George Gastaldi, Quarkus Development mailing list
I already found it will break elytron-ldap (which is no real surprise). The error message is very informatie and tells you exactly what you need to do to fix it, so I don't know if we even really need to update the docs if this is not something we are telling people to use.

Stuart

clement escoffier

unread,
Dec 14, 2021, 4:38:11 AM12/14/21
to Stuart Douglas, Sanne Grinovero, George Gastaldi, Quarkus Development mailing list
On 14 Dec 2021 at 10:18:45, Stuart Douglas <sdou...@redhat.com> wrote:
I already found it will break elytron-ldap (which is no real surprise). The error message is very informatie and tells you exactly what you need to do to fix it, so I don't know if we even really need to update the docs if this is not something we are telling people to use.

Agreed! 

Clement

Loïc MATHIEU

unread,
Dec 14, 2021, 4:50:41 AM12/14/21
to clement escoffier, Stuart Douglas, Sanne Grinovero, George Gastaldi, Quarkus Development mailing list
Well, instead of breaking Mongo and LDAP we can have a way to enable it from the extensions build.

Stuart Douglas

unread,
Dec 14, 2021, 4:53:44 AM12/14/21
to Loïc MATHIEU, clement escoffier, Sanne Grinovero, George Gastaldi, Quarkus Development mailing list
I have done that for LDAP. Is this a commonly used thing in mongo? If it is an edge case I think it is ok to require a property to enable it.

Stuart

Loïc MATHIEU

unread,
Dec 14, 2021, 5:27:45 AM12/14/21
to Stuart Douglas, clement escoffier, Sanne Grinovero, George Gastaldi, Quarkus Development mailing list
When using a replicaset, it's very common to configure it this way.
Using SAAS solution like Mongo Atlas, this is the default.

We can however detect it by parsing the MongoDB connection String.

Stuart Douglas

unread,
Dec 14, 2021, 5:39:35 AM12/14/21
to Loïc MATHIEU, clement escoffier, Sanne Grinovero, George Gastaldi, Quarkus Development mailing list
On Tue, 14 Dec 2021 at 21:27, Loïc MATHIEU <loik...@gmail.com> wrote:
When using a replicaset, it's very common to configure it this way.
Using SAAS solution like Mongo Atlas, this is the default.

We can however detect it by parsing the MongoDB connection String.

That is a runtime property though, and this is a build time thing. I guess we should just enable this if mongo is present as well.

I guess my concern is the more scenarios we enable it in, the less useful it is, but the more likely it is to give a false sense of security.

It may also be possible to have some kind of 'known good' support for both this and ldap, however it is not as simple as just delegating to a default InitialContextFactory because InitialContext acts differently based on if the factory is registered or not.

If we have multiple use cases for JNDI though the 'known good' option may be worth doing. I guess we also need to decide if we actually want to guard against this. Hopefully there is not another log4shell level issues anything soon, and JNDI is not the only issue the JDK has, but it is a potentially easy to exploit vector that is mostly unused by moderns apps, so it seems like a good tradeoff.

Stuart

Sanne Grinovero

unread,
Dec 14, 2021, 5:54:37 AM12/14/21
to Stuart Douglas, Loïc MATHIEU, clement escoffier, George Gastaldi, Quarkus Development mailing list
I wonder if Quarkus has now enough leverage so that by making such things inconvenient, people like the Mongodb maintainers can be persuaded to find a better alternative. Especially since it's already broken in native.

I'd say it's worth trying shutting down JNDI by default and try to stand our ground on such positions.

Stuart Douglas

unread,
Dec 14, 2021, 6:08:15 PM12/14/21
to Loïc MATHIEU, clement escoffier, Sanne Grinovero, George Gastaldi, Quarkus Development mailing list
The test suite passed for Mongo even without this change. Do you think it is worth adding tests for using mongo this way? It seems like testing the native support for this would be useful even without the JNDI issues.

Stuart

On Tue, 14 Dec 2021 at 21:27, Loïc MATHIEU <loik...@gmail.com> wrote:

Guillaume Smet

unread,
Dec 14, 2021, 6:13:52 PM12/14/21
to Stuart Douglas, Loïc MATHIEU, clement escoffier, Sanne Grinovero, George Gastaldi, Quarkus Development mailing list
On Tue, Dec 14, 2021 at 10:53 AM Stuart Douglas <sdou...@redhat.com> wrote:
I have done that for LDAP. Is this a commonly used thing in mongo? If it is an edge case I think it is ok to require a property to enable it

I'm not sure I like that.

You give a false sense of security by disabling JNDI by default if, someday, by adding an extension, it gets automatically enabled.

I'd rather go with an explicit configuration property that you HAVE TO enable to benefit from the feature. I know it looks counter intuitive for users but I seriously think this feature is dangerous if we enable JNDI ourselves for certain extensions.

--
Guillaume

Stuart Douglas

unread,
Dec 14, 2021, 6:25:56 PM12/14/21
to Guillaume Smet, Loïc MATHIEU, clement escoffier, Sanne Grinovero, George Gastaldi, Quarkus Development mailing list
I am not sure if I like it either :-)

The way I have justified it to myself is as follows:

- This is a 'best effort' to mitigate a vulnerability that may never happen
- Users of the quarkus-elytron-security-ldap extension will always need to add the property anyway, as the extension relies on JNDI, so the end result is the same

That said maybe it is worth the effort to create a special 'safe JNDI' implementation, so the factory will allow the creation of very specific things that we have pre-vetted.

Stuart
 

--
Guillaume

Loïc MATHIEU

unread,
Dec 15, 2021, 3:17:49 AM12/15/21
to Stuart Douglas, clement escoffier, Sanne Grinovero, George Gastaldi, Quarkus Development mailing list
Hi Stuart,

For MongoDB we don't use the mongo+srv protocol on our test suite as it'll require a specific installation that we cannot easily simulate in our test environment.
I can try to test your branch with a MongoDB Atlas cluster to see if it breaks, I can find some time to do this on Friday.

Guillaume Smet

unread,
Dec 15, 2021, 3:23:38 AM12/15/21
to Stuart Douglas, Loïc MATHIEU, clement escoffier, Sanne Grinovero, George Gastaldi, Quarkus Development mailing list
On Wed, Dec 15, 2021 at 12:25 AM Stuart Douglas <sdou...@redhat.com> wrote:
I am not sure if I like it either :-)

The way I have justified it to myself is as follows:

- This is a 'best effort' to mitigate a vulnerability that may never happen
- Users of the quarkus-elytron-security-ldap extension will always need to add the property anyway, as the extension relies on JNDI, so the end result is the same

The scenario I have in mind is the following:
1/ I create my Quarkus app
2/ I assume JNDI is disabled given that's what is documented
3/ There is a JNDI exploit but I don't feel that much concerned because of 2/
4/ 2 months later, I add LDAP authentication via elytron-ldap
5/ I'm screwed

If at 4/, I get an error saying JNDI is disabled by default and I need to enable it with proper warnings, 5/ might not happen.

--
Guillaume

Sanne Grinovero

unread,
Dec 15, 2021, 4:42:50 AM12/15/21
to Guillaume Smet, Stuart Douglas, Loïc MATHIEU, clement escoffier, George Gastaldi, Quarkus Development mailing list
On Wed, 15 Dec 2021 at 08:23, Guillaume Smet <guillau...@gmail.com> wrote:
On Wed, Dec 15, 2021 at 12:25 AM Stuart Douglas <sdou...@redhat.com> wrote:
I am not sure if I like it either :-)

The way I have justified it to myself is as follows:

- This is a 'best effort' to mitigate a vulnerability that may never happen
- Users of the quarkus-elytron-security-ldap extension will always need to add the property anyway, as the extension relies on JNDI, so the end result is the same

The scenario I have in mind is the following:
1/ I create my Quarkus app
2/ I assume JNDI is disabled given that's what is documented
3/ There is a JNDI exploit but I don't feel that much concerned because of 2/
4/ 2 months later, I add LDAP authentication via elytron-ldap
5/ I'm screwed

+1

Consistency is important, and neither us nor end users will have the resources to test for various random combinations of extensions.

Not meaning to change the subject, but that's the same reason for which I decided to hardcode relaxing some Java modularity rules in quarkus core when we fixed issues in native-image on JDK17. (We've had a debate about if this warranted a BuildItem and automatically enable things based on specific extension opt-in).

Regarding JNDI, as mentioned in a previous email I think it's perfectly understandable by our users - especially after the recent news - to be strict by default and require an explicit opt-in. And this could be a good reason for the MongoDB developers to address the problem otherwise.

And it's simpler :)

Thanks

Emmanuel Bernard

unread,
Dec 15, 2021, 5:48:09 AM12/15/21
to Sanne Grinovero, Guillaume Smet, Stuart Douglas, Loïc MATHIEU, clement escoffier, George Gastaldi, Quarkus Development mailing list
A thing we can do is make sure the mongo extension config code does raise an even more contextual exception. 

"mongo+srv is using this crazy scary attack vector, are you fine with it? enable it by setting this property."


--
You received this message because you are subscribed to the Google Groups "Quarkus Development mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to quarkus-dev...@googlegroups.com.

Loïc MATHIEU

unread,
Dec 15, 2021, 9:56:31 AM12/15/21
to Emmanuel Bernard, Sanne Grinovero, Guillaume Smet, Stuart Douglas, clement escoffier, George Gastaldi, Quarkus Development mailing list
Yeah, this can be done in a runtime init step.
I'll need to check first what it currently did, then I'll propose something.

Scott Stark

unread,
Dec 15, 2021, 11:00:47 AM12/15/21
to guillau...@gmail.com, Stuart Douglas, Loïc MATHIEU, clement escoffier, Sanne Grinovero, George Gastaldi, Quarkus Development mailing list
In between 4/5 we could also have the Quarkus JNDI implementation not resolve ObjectFactory bindings by default and require yet another flag to be enabled to do so. Without ObjectFactorys JNDI is much simpler and safer.

--
You received this message because you are subscribed to the Google Groups "Quarkus Development mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to quarkus-dev...@googlegroups.com.

Stuart Douglas

unread,
Dec 15, 2021, 7:12:50 PM12/15/21
to Scott Stark, Guillaume Smet, Loïc MATHIEU, clement escoffier, Sanne Grinovero, George Gastaldi, Quarkus Development mailing list
On Thu, 16 Dec 2021 at 03:00, Scott Stark <sst...@redhat.com> wrote:
In between 4/5 we could also have the Quarkus JNDI implementation not resolve ObjectFactory bindings by default and require yet another flag to be enabled to do so. Without ObjectFactorys JNDI is much simpler and safer.

While that would fix the remote execution part it would still allow for information disclosure (assuming a similar vulnerability).

Definitely better than nothing though.

Stuart
Reply all
Reply to author
Forward
0 new messages