JVM-wide SSL truststore configuration versus DNS TTL tuning for Liquibase remote changelog loading
0 reputation · 13 Jan 2023, 16:15 UTC
0 reputation · 13 Jan 2023, 16:15 UTC
The goal is to allow Liquibase to retrieve remote changelog files via HTTPS when the server uses a self‑signed certificate and the underlying DNS records change frequently.
Two documented levers exist: adding a custom truststore via the JVM system properties javax.net.ssl.trustStore and javax.net.ssl.trustStorePassword, or reducing the DNS cache TTL with the security property networkaddress.cache.ttl. However, the truststore change is JVM‑wide and may broaden the attack surface if overly permissive CAs are added, while a low TTL raises DNS query volume and can expose the service to DNS‑based attacks.
Which approach offers a better balance of security and operational flexibility for Liquibase? How can the side‑effects on other Java applications be minimized when using a custom truststore? Is there a threshold for networkaddress.cache.ttl that mitigates DNS load without sacrificing responsiveness?
33275 reputation · 13 Jan 2023, 16:30 UTC
The two settings solve orthogonal problems: javax.net.ssl.trustStore controls which server certificates the JVM accepts, while networkaddress.cache.ttl controls how long InetAddress caches DNS answers. When you have both a self‑signed certificate and frequently changing DNS records, you need both levers—neither replaces the other.
Prefer a narrowly scoped truststore in an isolated JVM (or container) and align the JVM DNS cache TTL with the authoritative DNS zone TTL rather than treating either setting as a universal fix.
keytool -importcert -alias liquibase-remote -file selfsigned.crt -keystore liquibase-truststore.jks -storepass changeitjava -Djavax.net.ssl.trustStore=liquibase-truststore.jks \
-Djavax.net.ssl.trustStorePassword=changeit \
-jar liquibase.jar ...keytool -list -keystore liquibase-truststore.jks -storepass changeitIf Liquibase must share a JVM, programmatic SSLSocketFactory or SSLContext injection is safer than global system properties—but only if the Liquibase HTTP client exposes that hook.
There is no universal threshold. A practical compromise is to set the JVM positive cache TTL no higher than the DNS record TTL. For moderately dynamic records, 30–60 seconds often balances lookup volume and responsiveness. Also configure networkaddress.cache.negative.ttl (default 10 s) to avoid caching NXDOMAIN responses too long.
Set via security properties (preferred) or system property fallback:
# java.security or -Djava.security.properties==/path/override
networkaddress.cache.ttl=30
networkaddress.cache.negative.ttl=10Remember: JVM settings do not override OS or container resolver caching.
jshell> import java.security.Security;
jshell> Security.getProperty("networkaddress.cache.ttl")
jshell> Security.getProperty("networkaddress.cache.negative.ttl")for i in {1..5}; do java -cp . ResolveTest example.com; sleep 10; donewhere ResolveTest calls InetAddress.getAllByName and prints addresses.
What is the authoritative DNS record TTL for the hostname Liquibase contacts? That value should drive the networkaddress.cache.ttl setting; without it, any number is a guess.
Use comments to ask for clarification. Post a solution as an answer.
33,275 reputation · 13 Jan 2023, 23:23 UTC
Liquibase inherits DNS caching from the JDK's InetAddress resolver, and the effective TTL is not reliably overridden with a system property on modern JDKs. networkaddress.cache.ttl is read from $JAVA_HOME/conf/security/java.security; the older -Dsun.net.inetaddr.ttl variant is ignored on current releases.
That means editing java.security changes every application that uses that JDK installation, not just Liquibase. If you need a different TTL for Liquibase only, scope it by using a dedicated JDK directory or container for the Liquibase invocation rather than a global file edit.
Verify which JDK is actually used: java -XshowSettings:properties -version and confirm java.home before applying changes.