@@ -16,7 +16,7 @@ use crate::{
1616 RW_CONFIG_DIR_NAME , SPOOLING_MANAGER_PROPERTIES , STACKABLE_CLIENT_TLS_DIR ,
1717 STACKABLE_INTERNAL_TLS_DIR , STACKABLE_MOUNT_INTERNAL_TLS_DIR ,
1818 STACKABLE_MOUNT_SERVER_TLS_DIR , STACKABLE_SERVER_TLS_DIR , STACKABLE_TLS_STORE_PASSWORD ,
19- SYSTEM_TRUST_STORE , SYSTEM_TRUST_STORE_PASSWORD , TrinoRole , v1alpha1,
19+ TrinoRole , v1alpha1,
2020 } ,
2121} ;
2222
@@ -45,38 +45,25 @@ pub fn container_prepare_args(
4545 ) ) ;
4646 }
4747
48+ // Create truststore that will be used when talking to external tools like S3
49+ // It will be populated from the system truststore so that connections against public services like AWS S3 are still possible
50+ // FIXME: *Technically* we should only add the system truststore in case any webPki usage is detected, whether that's in
51+ // S3, LDAP, OIDC, FTE or whatnot.
52+ args. push ( format ! ( "cert-tools generate-pkcs12-truststore --pem /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem --out {STACKABLE_CLIENT_TLS_DIR}/truststore.p12 --out-password {STACKABLE_TLS_STORE_PASSWORD}" ) ) ;
53+
4854 if trino. tls_enabled ( ) {
49- args. extend ( import_truststore (
50- STACKABLE_MOUNT_SERVER_TLS_DIR ,
51- STACKABLE_SERVER_TLS_DIR ,
52- ) ) ;
53- args. extend ( import_keystore (
54- STACKABLE_MOUNT_SERVER_TLS_DIR ,
55- STACKABLE_SERVER_TLS_DIR ,
56- ) ) ;
55+ args. push ( format ! ( "cp {STACKABLE_MOUNT_SERVER_TLS_DIR}/truststore.p12 {STACKABLE_SERVER_TLS_DIR}/truststore.p12" ) ) ;
56+ args. push ( format ! ( "cp {STACKABLE_MOUNT_SERVER_TLS_DIR}/keystore.p12 {STACKABLE_SERVER_TLS_DIR}/keystore.p12" ) ) ;
5757 }
5858
5959 if trino. get_internal_tls ( ) . is_some ( ) {
60- args. extend ( import_truststore (
61- STACKABLE_MOUNT_INTERNAL_TLS_DIR ,
62- STACKABLE_INTERNAL_TLS_DIR ,
63- ) ) ;
64- args. extend ( import_keystore (
65- STACKABLE_MOUNT_INTERNAL_TLS_DIR ,
66- STACKABLE_INTERNAL_TLS_DIR ,
67- ) ) ;
60+ args. push ( format ! ( "cp {STACKABLE_MOUNT_INTERNAL_TLS_DIR}/truststore.p12 {STACKABLE_INTERNAL_TLS_DIR}/truststore.p12" ) ) ;
61+ args. push ( format ! ( "cp {STACKABLE_MOUNT_INTERNAL_TLS_DIR}/keystore.p12 {STACKABLE_INTERNAL_TLS_DIR}/keystore.p12" ) ) ;
6862 if trino. tls_enabled ( ) {
69- args. extend ( import_truststore (
70- STACKABLE_MOUNT_SERVER_TLS_DIR ,
71- STACKABLE_INTERNAL_TLS_DIR ,
72- ) )
63+ args. push ( format ! ( "cert-tools generate-pkcs12-truststore --pkcs12 {STACKABLE_MOUNT_SERVER_TLS_DIR}/truststore.p12:{STACKABLE_TLS_STORE_PASSWORD} --pkcs12 {STACKABLE_INTERNAL_TLS_DIR}/truststore.p12:{STACKABLE_TLS_STORE_PASSWORD} --out {STACKABLE_INTERNAL_TLS_DIR}/truststore.p12 --out-password {STACKABLE_TLS_STORE_PASSWORD}" ) ) ;
7364 }
7465 }
7566
76- // Create truststore that will be used when talking to external tools like S3
77- // It will be populated from the system truststore so that connections against public services like AWS S3 are still possible
78- args. extend ( import_system_truststore ( STACKABLE_CLIENT_TLS_DIR ) ) ;
79-
8067 // Add the commands that are needed to set up the catalogs
8168 catalogs. iter ( ) . for_each ( |catalog| {
8269 args. extend_from_slice ( & catalog. init_container_extra_start_commands ) ;
@@ -159,77 +146,11 @@ wait_for_termination $!
159146 args
160147}
161148
162- /// Adds a CA file from `cert_file` into a truststore named `truststore.p12` in `destination_directory`
163- /// under the alias `alias_name`.
164- pub fn add_cert_to_truststore (
165- cert_file : & str ,
166- destination_directory : & str ,
167- alias_name : & str ,
168- ) -> Vec < String > {
169- vec ! [
170- format!(
171- "echo Adding cert from {cert_file} to truststore {destination_directory}/truststore.p12"
172- ) ,
173- format!(
174- "keytool -importcert -file {cert_file} -keystore {destination_directory}/truststore.p12 -storetype pkcs12 -noprompt -alias {alias_name} -storepass {STACKABLE_TLS_STORE_PASSWORD}"
175- ) ,
176- ]
177- }
178-
179- /// Generates the shell script to import a secret operator provided keystore without password
180- /// into a new keystore with password in a writeable empty dir
181- ///
182- /// # Arguments
183- /// - `source_directory`: The directory of the source keystore. Should usually be a secret operator volume mount.
184- /// - `destination_directory`: The directory of the destination keystore. Should usually be an empty dir.
185- fn import_keystore ( source_directory : & str , destination_directory : & str ) -> Vec < String > {
186- vec ! [
187- // The source directory is a secret-op mount and we do not want to write / add anything in there
188- // Therefore we import all the contents to a keystore in "writeable" empty dirs.
189- // Keytool is only barking if a password is not set for the destination keystore (which we set)
190- // and do provide an empty password for the source keystore coming from the secret-operator.
191- // Using no password will result in a warning.
192- format!(
193- "echo Importing {source_directory}/keystore.p12 to {destination_directory}/keystore.p12"
194- ) ,
195- format!(
196- "keytool -importkeystore -srckeystore {source_directory}/keystore.p12 -srcstoretype PKCS12 -srcstorepass \" \" -destkeystore {destination_directory}/keystore.p12 -deststoretype PKCS12 -deststorepass {STACKABLE_TLS_STORE_PASSWORD} -noprompt"
197- ) ,
198- ]
199- }
200-
201- /// Generates the shell script to import a secret operator provided truststore without password
202- /// into a new truststore with password in a writeable empty dir
203- ///
204- /// # Arguments
205- /// - `source_directory`: The directory of the source truststore. Should usually be a secret operator volume mount.
206- /// - `destination_directory`: The directory of the destination truststore. Should usually be an empty dir.
207- fn import_truststore ( source_directory : & str , destination_directory : & str ) -> Vec < String > {
208- vec ! [
209- // The source directory is a secret-op mount and we do not want to write / add anything in there
210- // Therefore we import all the contents to a truststore in "writeable" empty dirs.
211- // Keytool is only barking if a password is not set for the destination truststore (which we set)
212- // and do provide an empty password for the source truststore coming from the secret-operator.
213- // Using no password will result in a warning.
214- // All secret-op generated truststores have one entry with alias "1". We generate a UUID for
215- // the destination truststore to avoid conflicts when importing multiple secret-op generated
216- // truststores. We do not use the UUID rust crate since this will continuously change the STS... and
217- // leads to never-ending reconciles.
218- format!(
219- "echo Importing {source_directory}/truststore.p12 to {destination_directory}/truststore.p12"
220- ) ,
221- format!(
222- "keytool -importkeystore -srckeystore {source_directory}/truststore.p12 -srcstoretype PKCS12 -srcstorepass \" \" -srcalias 1 -destkeystore {destination_directory}/truststore.p12 -deststoretype PKCS12 -deststorepass {STACKABLE_TLS_STORE_PASSWORD} -destalias $(cat /proc/sys/kernel/random/uuid) -noprompt"
223- ) ,
224- ]
225- }
226-
227- /// Import the system truststore to a truststore named `truststore.p12` in `destination_directory`.
228- fn import_system_truststore ( destination_directory : & str ) -> Vec < String > {
229- vec ! [
230- format!( "echo Importing {SYSTEM_TRUST_STORE} to {destination_directory}/truststore.p12" ) ,
231- format!(
232- "keytool -importkeystore -srckeystore {SYSTEM_TRUST_STORE} -srcstoretype jks -srcstorepass {SYSTEM_TRUST_STORE_PASSWORD} -destkeystore {destination_directory}/truststore.p12 -deststoretype pkcs12 -deststorepass {STACKABLE_TLS_STORE_PASSWORD} -noprompt"
233- ) ,
234- ]
149+ /// Adds a PEM file to configured PKCS12 truststore (using the [`STACKABLE_TLS_STORE_PASSWORD`]
150+ /// password)
151+ pub fn add_cert_to_truststore ( cert_file : & str , destination_directory : & str ) -> Vec < String > {
152+ let truststore = format ! ( "{destination_directory}/truststore.p12" ) ;
153+ vec ! [ format!(
154+ "cert-tools generate-pkcs12-truststore --pkcs12 {truststore}:{STACKABLE_TLS_STORE_PASSWORD} --pem {cert_file} --out {truststore} --out-password {STACKABLE_TLS_STORE_PASSWORD}"
155+ ) ]
235156}
0 commit comments