Skip to content

Commit

Permalink
Fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
domhanak committed Apr 3, 2024
1 parent 61cfcd9 commit ff38b15
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
== Adding a custom CA Certificate to a Container Running Java
= Adding a custom CA Certificate to a Container Running Java
:compat-mode!:
:keywords: kogito, sonataflow, workflow, serverless, operator, kubernetes, minikube, openshift, containers
:keytool-docs: https://docs.oracle.com/en/java/javase/21/docs/specs/man/keytool.html
Expand All @@ -8,20 +8,20 @@ If you're working with containers running Java applications and need to add a CA
:toc:


=== Problem Space
== Problem Space

If you have a containerized Java application that connects to an SSL endpoint with a certificate signed by an internal authority (like SSL terminated routes on a cluster) you need to make sure Java can read the CA Authority certificate and verify it. Java unfortunately doesn't load certificates directly, but rather store them in a {keytool-docs}[keystore].

The default trust store under `$JAVA_HOME/lib/security/cacerts` contains only CA's which are shipped with the Java distribution and there's the `keytool` tool that knows how manipulate those key stores.
The containerized application may not know the CA certificate in build time, and so we need to add it to the trust-store in deployment. To automate that we can a combination of an init-container and a shared directory to pass the mutated trust store to the container before it runs. Let's run this step by step:

==== Step 1: Obtain the CA Certificate
=== Step 1: Obtain the CA Certificate

Before proceeding, ensure you have the CA certificate file (in PEM format) that you want to add to the Java container. If you don't have it, you may need to obtain it from your system administrator or certificate provider.

For the purpose of this guide we would take the k8s cluster root CA that is automatically deployed into every container under `/var/run/secrets/kubernetes.io/serviceaccount/ca.crt`

==== Step 2: Prepare a trust store in an init-container
=== Step 2: Prepare a trust store in an init-container

Add or amend this volumes and init-container snippet to your pod spec or podTemplate in a deployment:

Expand All @@ -47,7 +47,7 @@ spec:

The default keystore under $JAVA_HOME is part of the container image and is not mutable. We have to create the mutated copy to a shared volume, hence the 'new-cacerts' one.

## Step 3: Configure Java to load the new keystore
=== Step 3: Configure Java to load the new keystore

Here we would just mount the new, modified cacerts into the default location where the JVM looks at.
The example main uses the standard http client so alternative we could mount the cacerts to a different location and
Expand Down Expand Up @@ -77,7 +77,7 @@ Note that libraries like resteasy don't respect that flag and may need to progra
Notice the volume mount of the previously mutate keystore.


==== Full working example
=== Full working example

```yaml
apiVersion: v1
Expand Down Expand Up @@ -133,7 +133,7 @@ spec:
=== Serverless Workflow Example

Similar to a deployment spec a serverless workflow has a spec.podTemplate , with minor differences, but the change is almost identical.
In this case we are mounting some ingress ca bundle because we want our workflow to reach the `.apps.{custer-name}.{cluster-domain}` SSL endpoint.
In this case we are mounting some ingress ca bundle because we want our workflow to reach the `.apps.my-cluster-name.my-cluster-domain` SSL endpoint.
Here is the relevant spec section of a workflow with the changes:

```yaml
Expand Down

0 comments on commit ff38b15

Please sign in to comment.