OpenLiberty / ci.docker

Eclipse Public License 1.0
43 stars 59 forks source link

Enhance the generation and handling of keystore and truststore #312

Open leochr opened 2 years ago

leochr commented 2 years ago

There are various ways to inject keystore and truststore for the application. In some cases, some conflicts could prevent the application from working as expected. Re-evaluate the generation and handling of keystore and truststore and improve as possible.

Open Liberty runtime also supports providing certificates as env var to establish trust. Switch to this mechanism if possible: https://openliberty.io/docs/latest/reference/feature/transportSecurity-1.0.html#_provide_certificates_from_an_environment_variable_or_a_file

leochr commented 10 months ago

@idlewis please add your analysis of truststore handling in Liberty container here. Thank you

idlewis commented 10 months ago

I think I can see two issues with the trust store handling in docker-server.sh

  1. The script uses 'keytool -import' to add certificates to the default trust store in 2 situations (ca.crt exists in /etc/x509/certs or SEC_IMPORT_K8S_CERTS=true). If there is an existing trust store, this command will fail, as the passwords won't match
  2. If a trust store exists in the default location, then the script will add its own config to config overrides. If there was an existing trust store before the script ran, this config will cause a password mismatch, and an error on Liberty startup.

The fix for 2 is pretty simple (only add config if docker-server.sh created the truststore)

For 1, we need to decide what to do in the case of an existing trust store.

justin-fleming commented 7 months ago

Summary

The docker-server.sh script shipped with Liberty does not import .crt files that are missing a newline at the end of the file in the /var/run/secrets/kubernetes.io/serviceaccount dir.

The problem is on this line where we are cating *.crt and attempting to iterate over the certs to import them: https://github.com/OpenLiberty/ci.docker/blob/main/releases/latest/full/helpers/runtime/docker-server.sh#L62

Steps to recreate

Setup:

Without newlines at the end of the cert files, no truststore is generated (even though the certs are mounted):

With newlines, the certs are imported into the truststore: