Search code examples
spring-bootspring-boot-maven-pluginbuildpack

How to embed CA-certificates with spring-boot:build-image?


I need to add self-signed certificates to a spring-boot docker image using spring-boot:build-image and paketo-buildpacks/ca-certificates but couldn't get it working.

So:

  • where to put the certificates to add?
  • in which format?
  • how to define paketo-buildpacks/ca-certificates bindings?
  • should any additional argument be provided to mvn spring-boot:build-image?

What I tried with no success so far: update pom.xml spring-boot-maven-plugin:

    <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <configuration>
            <image>
                <bindings>
                    <binding>${basedir}/bindings/ca-certificates:/platform/bindings/ca-certificates</binding>
                </bindings>
            </image>
        </configuration>
        <executions>
            <execution>
                <goals>
                    <goal>build-image</goal>
                </goals>
            </execution>
        </executions>
    </plugin>

from ${basedir} folder:

mkdir bindings
mkdir bindings/ca-certificates
echo "ca-certificates" > bindings/ca-certificates/type
cp ~/.ssh/mycert.pem bindings/ca-certificates/
mvn spring-boot:build-image

Edit: moved image bindings configuration directly under boot-plugin (rather than inside a specific execution) as suggested by @nick-valanos and solved the problem.


Solution

  • I got it. Maven configuration above is for maven package target, not spring-boot:build-image.

    Here is the complete procedure:

    • create bindings/ca-certificates folder at maven project root and add to it:
      • type file containing just ca-certificates
      • CA certificatates you want to be embedded (in PEM format)
    • in pom.xml, add a build-image execution to spring-boot-maven-plugin with ${basedir}/bindings/ca-certificates:/platform/bindings/ca-certificates image binding as configured in my question
    • run mvn clean package