Java and the JVM
Build the application in CI or on the server, and deploy the dependency jars as files in a directory such as lib/ or libs/. Jars are copied from the repository unchanged, so each jar's SHA-256 must be one the build pinned. The attesterThe program on each server. It collects facts and reports them as evidence; it never decides whether the server passes. hashes every jar in each dependency directory and reads its Maven coordinates, and inspects each JVM process. The verifierThe program in CI that sends a nonce, fetches references itself, compares, and writes the report. compares each jar's hash with Gradle's dependency verification metadata or a Maven lockfile at the deployed commit. The application's own jar is build output: compare it with a build the verifier runs, or deploy it in an attested release.
What gets verified#
| What | Reference | Check |
|---|---|---|
| Tracked files | The deployed commit, on the audited branch | source |
| Each dependency jar | The SHA-256 pinned for that file name in gradle/verification-metadata.xml (sha256 and also-trust) or in lockfile.json from maven-lockfile | packages:maven |
| Jars the build does not pin | The jar Maven Central serves for the coordinates in the jar's META-INF/maven/.../pom.properties (policy.unpinnedPackages, default warn) | packages:maven |
| The application jar | A build of the same commit (build), or an attested release (binaries) | build or artifact |
| Each process | JAVA_TOOL_OPTIONS, JDK_JAVA_OPTIONS, _JAVA_OPTIONS; -javaagent, -agentpath and -agentlib; JDWP; -Xbootclasspath/a: and /p:; -Djava.system.class.loader; JMX remote; attach settings and an active attach listener; -XX:OnError; CLASSPATH without -cp; memory maps | process |
Requirements#
- Commit pinned hashes for every dependency:
- Gradle:
./gradlew --write-verification-metadata sha256writesgradle/verification-metadata.xml. - Maven: generate
lockfile.jsonwith maven-lockfile, using SHA-256 checksums.
- Gradle:
- Deploy dependencies as separate jar files in one of the directories the attester looks in:
lib/orlibs/in the service rootbuild/install/<app>/lib(GradleinstallDist)target/libortarget/dependency(Maven copy and assembly plugins)target/<app>/WEB-INF/liborbuild/libs/<app>/WEB-INF/lib(unpacked wars)
- For another directory, such as an unpacked Spring Boot
BOOT-INF/lib, list it underinstallsin the attester configuration. - Keep the application's own jar outside the dependency directory, for example in
build/libs/, and compare it throughbuild. - Keep other files out of the dependency directory.
Attester configuration#
version: 2
services:
- name: app
root: /srv/app/current
user: app
ecosystems: [maven]For a directory the attester does not look in:
installs:
- ecosystem: maven
dir: BOOT-INF/libA relative dir is resolved against the service root.
Verifier configuration#
version: 2
services:
- name: app
repository:
url: https://github.com/example/app.git
branch: main
# The application jar itself is built by CI: attest its manifest, or
# rebuild it here:
# build:
# command: ./gradlew --no-daemon bootJar
# outputs: [build/libs/*.jar]
servers:
- name: app1
host: app1.example.comSet lockfiles.maven when the metadata is not at its usual path, and references.registries.maven for a Maven Central mirror. See configuration.
Build and deploy#
The tested setup pins commons-lang3-3.17.0.jar in gradle/verification-metadata.xml, ignores lib/ in .gitignore, copies the jar into lib/ after the checkout, and runs:
java -cp lib/commons-lang3-3.17.0.jar Main.java- A reproduced build must give the same bytes. For Gradle, turn on reproducible archives (
preserveFileTimestamps = false,reproducibleFileOrder = trueon archive tasks); for Maven, setproject.build.outputTimestamp. - A Spring Boot fat jar holds its dependencies inside the jar, where they are not scanned one by one. Either compare the whole jar as build output, or unpack it and list
BOOT-INF/libunderinstalls. - Restart the JVM after each deploy. A tracked file or build output changed after the process started fails (
policy.modifiedAfterStart).
Common findings#
| Finding | Cause and fix |
|---|---|
Jars the build does not pin were compared with Maven Central | Write verification metadata or a Maven lockfile and commit it. |
the jar differs from the one the build pinned | A different or modified jar was deployed. Deploy the jars the build resolved. |
the build pins no jar of this name, and the jar names no Maven coordinates | A jar with no pin and no pom.properties, often the application jar in the dependency directory. Move it out, and compare it through build. |
the jar differs from Maven Central's for its coordinates | An unpinned jar that is not the published one. Pin it, and deploy the published jar. |
Links or other entries named like jars, which the JVM may load, that are not regular files | A link named *.jar in the directory. Replace it with the file. |
Other files next to the jars | Non-jar files in the dependency directory. Move them. |
No lockfile at the deployed commit pins these packages | No verification metadata or Maven lockfile at the commit. |
jvm-javaagent, jvm-native-agent, debugger (process) | An agent or JDWP in the JVM options or JAVA_TOOL_OPTIONS. Remove it in production. |
Limits#
- Dependencies inside a fat jar are not checked one by one.
- A jar is matched by file name in the Gradle metadata and in maven-lockfile, not by group.
- The JDK is explained as code only when a distribution package owns it or its hash is pinned under
executables; see the verifier guide.
See how it works for the overall flow.