@@ -22,7 +22,7 @@ use stackable_operator::{
2222} ;
2323
2424use crate :: crd:: {
25- DruidRole , STACKABLE_TRUST_STORE , STACKABLE_TRUST_STORE_PASSWORD ,
25+ DruidRole , STACKABLE_TRUST_STORE_PASSWORD ,
2626 authentication:: { self , AuthenticationClassesResolved } ,
2727 v1alpha1,
2828} ;
@@ -81,15 +81,16 @@ const SERVER_HTTPS_CERT_ALIAS: &str = "druid.server.https.certAlias";
8181const SERVER_HTTPS_VALIDATE_HOST_NAMES : & str = "druid.server.https.validateHostnames" ;
8282const SERVER_HTTPS_KEY_MANAGER_PASSWORD : & str = "druid.server.https.keyManagerPassword" ;
8383const SERVER_HTTPS_REQUIRE_CLIENT_CERTIFICATE : & str = "druid.server.https.requireClientCertificate" ;
84- const TLS_ALIAS_NAME : & str = "tls" ;
84+ /// The alias of the certificate in the keystore used for TLS stuff.
85+ /// All secret-op generated keystores have one entry with the alias "1".
86+ /// (side node: I think technically they don't have an alias and the JVm counts them, but not sure)
87+ const TLS_ALIAS_NAME : & str = "1" ;
8588pub const AUTH_TRUST_STORE_PATH : & str = "druid.auth.basic.ssl.trustStorePath" ;
8689pub const AUTH_TRUST_STORE_TYPE : & str = "druid.auth.basic.ssl.trustStoreType" ;
8790pub const AUTH_TRUST_STORE_PASSWORD : & str = "druid.auth.basic.ssl.trustStorePassword" ;
8891// Misc TLS
8992pub const TLS_STORE_PASSWORD : & str = "changeit" ;
9093pub const TLS_STORE_TYPE : & str = "pkcs12" ;
91- const SYSTEM_TRUST_STORE : & str = "/etc/pki/java/cacerts" ;
92- const SYSTEM_TRUST_STORE_PASSWORD : & str = "changeit" ;
9394
9495// directories
9596const STACKABLE_MOUNT_TLS_DIR : & str = "/stackable/mount_tls" ;
@@ -432,12 +433,13 @@ impl DruidTlsSecurity {
432433 }
433434
434435 vec ! [
435- // Copy system truststore to empty dir and convert to PKCS12
436- import_system_truststore( STACKABLE_TLS_DIR ) ,
437- // Import secret-op truststore to copied system trust store
438- import_truststore( STACKABLE_MOUNT_TLS_DIR , STACKABLE_TLS_DIR ) ,
439- // Import / Copy secret-op keystore to empty dir and set required alias
440- import_keystore( STACKABLE_MOUNT_TLS_DIR , STACKABLE_TLS_DIR ) ,
436+ // FIXME: *Technically* we should only add the system truststore in case any webPki usage is detected,
437+ // wether that's in S3, LDAP, OIDC, FTE or whatnot.
438+ format!(
439+ "cert-tools generate-pkcs12-truststore --pkcs12 '{STACKABLE_MOUNT_TLS_DIR}/truststore.p12:{TLS_STORE_PASSWORD}' --pem /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem --out {STACKABLE_TLS_DIR}/truststore.p12 --out-password '{TLS_STORE_PASSWORD}'"
440+ ) ,
441+ // We can copy the keystore as is.
442+ format!( "cp {STACKABLE_MOUNT_TLS_DIR}/keystore.p12 {STACKABLE_TLS_DIR}/keystore.p12" ) ,
441443 ]
442444 }
443445
@@ -468,66 +470,19 @@ impl DruidTlsSecurity {
468470 }
469471}
470472
471- /// Generate a script to add a CA to a truststore
473+ /// Generate a bash command to add a CA to a truststore
472474pub fn add_cert_to_trust_store_cmd (
473- cert : & str ,
474- trust_store_directory : & str ,
475- alias_name : & str ,
475+ cert_file : & str ,
476+ destination_directory : & str ,
476477 store_password : & str ,
477478) -> String {
479+ let truststore = format ! ( "{destination_directory}/truststore.p12" ) ;
478480 format ! (
479- "keytool -importcert -file {cert} -keystore {trust_store_directory}/truststore.p12 -storetype pkcs12 -alias {alias_name } -storepass {store_password} -noprompt "
481+ "cert-tools generate-pkcs12-truststore --pkcs12 {truststore}:{store_password} --pem {cert_file} --out {truststore } --out-password {store_password}"
480482 )
481483}
482484
483- pub fn add_cert_to_jvm_trust_store_cmd ( cert : & str , alias_name : & str ) -> String {
484- format ! (
485- "keytool -importcert -file {cert} -keystore {STACKABLE_TRUST_STORE} -storetype pkcs12 -alias {alias_name} -storepass {STACKABLE_TRUST_STORE_PASSWORD} -noprompt"
486- )
487- }
488-
489- /// Import the system truststore to a truststore named `truststore.p12` in `destination_directory`.
490- fn import_system_truststore ( destination_directory : & str ) -> String {
491- let dest_truststore_path = format ! ( "{destination_directory}/truststore.p12" ) ;
492- format ! (
493- "keytool -importkeystore -srckeystore {SYSTEM_TRUST_STORE} -srcstoretype jks -srcstorepass {SYSTEM_TRUST_STORE_PASSWORD} -destkeystore {dest_truststore_path} -deststoretype pkcs12 -deststorepass {TLS_STORE_PASSWORD} -noprompt"
494- )
495- }
496-
497- /// Generates the shell script to import a secret operator provided truststore without password
498- /// into a new truststore with password in a writeable empty dir
499- ///
500- /// # Arguments
501- /// - `source_directory`: The directory of the source truststore. Should usually be a secret
502- /// operator volume mount.
503- /// - `destination_directory`: The directory of the destination truststore. Should usually be an
504- /// empty dir.
505- fn import_truststore ( source_directory : & str , destination_directory : & str ) -> String {
506- let source_truststore_path = format ! ( "{source_directory}/truststore.p12" ) ;
507- let dest_truststore_path = format ! ( "{destination_directory}/truststore.p12" ) ;
508- // The source directory is a secret-op mount and we do not want to write / add anything in there
509- // Therefore we import all the contents to a truststore in "writeable" empty dirs.
510- // Keytool is only barking if a password is not set for the destination truststore (which we set)
511- // and do provide an empty password for the source truststore coming from the secret-operator.
512- // Using no password will result in a warning.
513- // All secret-op generated truststores have one entry with alias "1". We generate a UUID for
514- // the destination truststore to avoid conflicts when importing multiple secret-op generated
515- // truststores. We do not use the UUID rust crate since this will continuously change the STS... and
516- // leads to never-ending reconciles.
517- format ! (
518- "keytool -importkeystore -srckeystore {source_truststore_path} -srcstoretype PKCS12 -srcstorepass {TLS_STORE_PASSWORD} -srcalias 1 -destkeystore {dest_truststore_path} -deststoretype PKCS12 -deststorepass {TLS_STORE_PASSWORD} -destalias $(cat /proc/sys/kernel/random/uuid) -noprompt"
519- )
520- }
521-
522- /// Generate a script to import a mounted keystore to an empty dir and set an alias
523- fn import_keystore ( source_directory : & str , destination_directory : & str ) -> String {
524- let source_keystore_path = format ! ( "{source_directory}/keystore.p12" ) ;
525- let dest_keystore_path = format ! ( "{destination_directory}/keystore.p12" ) ;
526- // The source directory is a secret-op mount and we do not want to write / add anything in there
527- // Therefore we import all the contents to a keystore in "writeable" empty dirs.
528- // Using no password will result in a warning.
529- // All secret-op generated keystores have one entry with alias "1".
530- format ! (
531- "keytool -importkeystore -srckeystore {source_keystore_path} -srcstoretype PKCS12 -srcstorepass {TLS_STORE_PASSWORD} -srcalias 1 -destkeystore {dest_keystore_path} -deststoretype PKCS12 -deststorepass {TLS_STORE_PASSWORD} -destalias {TLS_ALIAS_NAME} -noprompt"
532- )
485+ /// Generate a bash command to add a CA to the truststore that is passed to the JVM
486+ pub fn add_cert_to_jvm_trust_store_cmd ( cert_file : & str ) -> String {
487+ add_cert_to_trust_store_cmd ( cert_file, "/stackable" , STACKABLE_TRUST_STORE_PASSWORD )
533488}
0 commit comments