Attention when using SCRAM in PostgreSQL

Symptom

When monitoring PostgreSQL that uses SCRAM instead of the MD5 authentication method the following data collection and monitor outage will occur.

Unexpected exception while polling PollableService[location=FUL, interface=PollableInterface [PollableNode [1226]:10.10.5.101], svcName=PostgreSQL]. java.util.concurrent.ExecutionException: org.opennms.core.rpc.api.RemoteExecutionException: java.util.concurrent.CompletionException: java.lang.NoClassDefFoundError: javax/security/sasl/SaslException at java.base/java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:314) at java.base/java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:319) at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1702) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) at java.base/java.lang.Thread.run(Thread.java:834) Caused by: java.lang.NoClassDefFoundError: javax/security/sasl/SaslException at java.base/java.lang.ClassLoader.defineClass1(Native Method) at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1016) at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.defineClass(BundleWiringImpl.java:2410) at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.findClass(BundleWiringImpl.java:2194) at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1607) at org.apache.felix.framework.BundleWiringImpl.access$200(BundleWiringImpl.java:80) at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:2053) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521) at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:659) at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:141) at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:192) at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49) at org.postgresql.jdbc.PgConnection.(PgConnection.java:195) at org.postgresql.Driver.makeConnection(Driver.java:454) at org.postgresql.Driver.connect(Driver.java:256) at org.opennms.netmgt.poller.monitors.JDBCMonitor.poll(JDBCMonitor.java:149) at Proxy7bc82e31_d8c9_4727_8fec_bb14aa59a36b.poll(Unknown Source) at org.opennms.netmgt.poller.client.rpc.PollerClientRpcModule$1.get(PollerClientRpcModule.java:77) at org.opennms.netmgt.poller.client.rpc.PollerClientRpcModule$1.get(PollerClientRpcModule.java:71) at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1700) ā€¦ 3 more Caused by: java.lang.ClassNotFoundException: javax.security.sasl.SaslException not found by org.postgresql.jdbc42 [382] at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1639) at org.apache.felix.framework.BundleWiringImpl.access$200(BundleWiringImpl.java:80) at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:2053) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521) ā€¦ 23 more

Solution

OpenNMS v.27.0.0 uses 42.2.5 library. But at least 42.2.7 is required to support SCRAM.

Newer drivers can be obtained here: https://jdbc.postgresql.org/download.html

Default OpenNMS installation

Just delete the postgresql-42.2.5.jar file in folder /opt/opennms/lib/ and copy the newer one into this folder. OpenNMS requires a restart to load the library.

Docker OpenNMS installation

Here it is a little bit more tricky since the OpenNMS Docker images always provide postgresql-42.2.5.jar when creating the container. Also, it is not possible to have 2 versions in the lib folder.

The only approach that worked for me (easily | ugly) is, to mount the new library file as a volume into the old one in my docker-compose.yaml.

....
    volumes:
       - ./postgresql-42.2.18.jar:/opt/opennms/lib/postgresql-42.2.5.jar
....

Jira Issue Tracker


:woman_facepalming: You can fix me, Iā€™m a wiki post.

1 Like

It turned out that the JDBC driver is not the cause in this case. SCRAM does also work with 42.2.5.
The issue seems to be caused by a Minion. Corresponding issue tracker.

1 Like