I have a keycloak (docker) SSL system working with a certificate created by certbot, but upon renewing the certificate, the keycloak instance still show the invalid out of date certificate. I have checked using openssl that that certificate I created is valid and is in the /etc/x509/https folder. permissions on the files are fine. I even tried the following but nothing forced it to pickup the new certificate
- restarting keycloak
- signing into keycloak docker instance and running /opt/jboss/tools/x509.sh - it says it regenerated a new set of files but the date stamp seemed to imply it was still the old .jks and .pk12
- moved those file from /opt/jboss/keycloak/standalone/configuration/keystores into a new temporary folder and ran the x509.sh again and it created two new file. I restarted the docker instance - but again it still shows the old certificate dates
Anyone got any idea on why the old certificate is not being refreshed? I believe this is a keycloak question rather than certbot. Any help would be appreciated.
Note : Answer working for Keycloak 9 (2020).
The simplest solution is to drop the container but it's not always desirable. However, there is another way.
AFAIK, x509.sh is supposed to be run only once per container life. You can take a look at docker-entrypoint.sh on the repository to verify that x509.sh is just run on container initialization and never again. In previous versions of docker-entrypoint.sh, x509.sh was run at every startup but it was doing nothing despite the messages it was printing.
Current x509.sh version is achieving the following steps:
generating a random password:
creating a PKCS12 keystore with openssl:
creating a JKS keystore from the PKCS12 one with keytool:
configuring the JKS keystore for Keycloak:
If you modify x509.sh and remove all redirections to /dev/null, you should see something like this:
It failed to modify Keycloak configuration with jboss-cli.sh. If you just remove keystores, and run x509.sh, the new randomly generated password will be different from the one in Keycloak configuration file. Since x509-keystore.cli is trying to add parameters, not update them, password in keystores and password in configuration won't match.
Here is an alternative version of x509.sh for renewal only whose key points are exposed below:
extract currently used password from Keycloak configuration:
extract JKS keystore path from Keycloak configuration:
assume that PKCS12 keystore just differs by its extension:
now that you know the password and the keystore paths, update the PKCS12 keystore:
finally update the JKS one:
Complete script:
Name it x509-renewal.sh for example and copy it in your container:
then run it: