@@ -14,8 +14,7 @@ use crate::{
1414 CONFIG_DIR_NAME , Container , LOG_PROPERTIES , RW_CONFIG_DIR_NAME , STACKABLE_CLIENT_TLS_DIR ,
1515 STACKABLE_INTERNAL_TLS_DIR , STACKABLE_MOUNT_INTERNAL_TLS_DIR ,
1616 STACKABLE_MOUNT_SERVER_TLS_DIR , STACKABLE_SERVER_TLS_DIR , STACKABLE_TLS_STORE_PASSWORD ,
17- SYSTEM_TRUST_STORE , SYSTEM_TRUST_STORE_PASSWORD , TrinoRole ,
18- fault_tolerant_execution:: ResolvedFaultTolerantExecutionConfig , v1alpha1,
17+ TrinoRole , fault_tolerant_execution:: ResolvedFaultTolerantExecutionConfig , v1alpha1,
1918 } ,
2019} ;
2120
@@ -43,38 +42,23 @@ pub fn container_prepare_args(
4342 ) ) ;
4443 }
4544
45+ // Create truststore that will be used when talking to external tools like S3
46+ // It will be populated from the system truststore so that connections against public services like AWS S3 are still possible
47+ args. push ( format ! ( "truststore-merger --pem /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem --out {STACKABLE_CLIENT_TLS_DIR}/truststore.p12 --out-password {STACKABLE_TLS_STORE_PASSWORD}" ) ) ;
48+
4649 if trino. tls_enabled ( ) {
47- args. extend ( import_truststore (
48- STACKABLE_MOUNT_SERVER_TLS_DIR ,
49- STACKABLE_SERVER_TLS_DIR ,
50- ) ) ;
51- args. extend ( import_keystore (
52- STACKABLE_MOUNT_SERVER_TLS_DIR ,
53- STACKABLE_SERVER_TLS_DIR ,
54- ) ) ;
50+ args. push ( format ! ( "cp {STACKABLE_MOUNT_SERVER_TLS_DIR}/truststore.p12 {STACKABLE_SERVER_TLS_DIR}/truststore.p12" ) ) ;
51+ args. push ( format ! ( "cp {STACKABLE_MOUNT_SERVER_TLS_DIR}/keystore.p12 {STACKABLE_SERVER_TLS_DIR}/keystore.p12" ) ) ;
5552 }
5653
5754 if trino. get_internal_tls ( ) . is_some ( ) {
58- args. extend ( import_truststore (
59- STACKABLE_MOUNT_INTERNAL_TLS_DIR ,
60- STACKABLE_INTERNAL_TLS_DIR ,
61- ) ) ;
62- args. extend ( import_keystore (
63- STACKABLE_MOUNT_INTERNAL_TLS_DIR ,
64- STACKABLE_INTERNAL_TLS_DIR ,
65- ) ) ;
55+ args. push ( format ! ( "cp {STACKABLE_MOUNT_INTERNAL_TLS_DIR}/truststore.p12 {STACKABLE_INTERNAL_TLS_DIR}/truststore.p12" ) ) ;
56+ args. push ( format ! ( "cp {STACKABLE_MOUNT_INTERNAL_TLS_DIR}/keystore.p12 {STACKABLE_INTERNAL_TLS_DIR}/keystore.p12" ) ) ;
6657 if trino. tls_enabled ( ) {
67- args. extend ( import_truststore (
68- STACKABLE_MOUNT_SERVER_TLS_DIR ,
69- STACKABLE_INTERNAL_TLS_DIR ,
70- ) )
58+ args. push ( format ! ( "truststore-merger --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}" ) ) ;
7159 }
7260 }
7361
74- // Create truststore that will be used when talking to external tools like S3
75- // It will be populated from the system truststore so that connections against public services like AWS S3 are still possible
76- args. extend ( import_system_truststore ( STACKABLE_CLIENT_TLS_DIR ) ) ;
77-
7862 // Add the commands that are needed to set up the catalogs
7963 catalogs. iter ( ) . for_each ( |catalog| {
8064 args. extend_from_slice ( & catalog. init_container_extra_start_commands ) ;
@@ -148,77 +132,11 @@ wait_for_termination $!
148132 args
149133}
150134
151- /// Adds a CA file from `cert_file` into a truststore named `truststore.p12` in `destination_directory`
152- /// under the alias `alias_name`.
153- pub fn add_cert_to_truststore (
154- cert_file : & str ,
155- destination_directory : & str ,
156- alias_name : & str ,
157- ) -> Vec < String > {
158- vec ! [
159- format!(
160- "echo Adding cert from {cert_file} to truststore {destination_directory}/truststore.p12"
161- ) ,
162- format!(
163- "keytool -importcert -file {cert_file} -keystore {destination_directory}/truststore.p12 -storetype pkcs12 -noprompt -alias {alias_name} -storepass {STACKABLE_TLS_STORE_PASSWORD}"
164- ) ,
165- ]
166- }
167-
168- /// Generates the shell script to import a secret operator provided keystore without password
169- /// into a new keystore with password in a writeable empty dir
170- ///
171- /// # Arguments
172- /// - `source_directory`: The directory of the source keystore. Should usually be a secret operator volume mount.
173- /// - `destination_directory`: The directory of the destination keystore. Should usually be an empty dir.
174- fn import_keystore ( source_directory : & str , destination_directory : & str ) -> Vec < String > {
175- vec ! [
176- // The source directory is a secret-op mount and we do not want to write / add anything in there
177- // Therefore we import all the contents to a keystore in "writeable" empty dirs.
178- // Keytool is only barking if a password is not set for the destination keystore (which we set)
179- // and do provide an empty password for the source keystore coming from the secret-operator.
180- // Using no password will result in a warning.
181- format!(
182- "echo Importing {source_directory}/keystore.p12 to {destination_directory}/keystore.p12"
183- ) ,
184- format!(
185- "keytool -importkeystore -srckeystore {source_directory}/keystore.p12 -srcstoretype PKCS12 -srcstorepass \" \" -destkeystore {destination_directory}/keystore.p12 -deststoretype PKCS12 -deststorepass {STACKABLE_TLS_STORE_PASSWORD} -noprompt"
186- ) ,
187- ]
188- }
189-
190- /// Generates the shell script to import a secret operator provided truststore without password
191- /// into a new truststore with password in a writeable empty dir
192- ///
193- /// # Arguments
194- /// - `source_directory`: The directory of the source truststore. Should usually be a secret operator volume mount.
195- /// - `destination_directory`: The directory of the destination truststore. Should usually be an empty dir.
196- fn import_truststore ( source_directory : & str , destination_directory : & str ) -> Vec < String > {
197- vec ! [
198- // The source directory is a secret-op mount and we do not want to write / add anything in there
199- // Therefore we import all the contents to a truststore in "writeable" empty dirs.
200- // Keytool is only barking if a password is not set for the destination truststore (which we set)
201- // and do provide an empty password for the source truststore coming from the secret-operator.
202- // Using no password will result in a warning.
203- // All secret-op generated truststores have one entry with alias "1". We generate a UUID for
204- // the destination truststore to avoid conflicts when importing multiple secret-op generated
205- // truststores. We do not use the UUID rust crate since this will continuously change the STS... and
206- // leads to never-ending reconciles.
207- format!(
208- "echo Importing {source_directory}/truststore.p12 to {destination_directory}/truststore.p12"
209- ) ,
210- format!(
211- "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"
212- ) ,
213- ]
214- }
215-
216- /// Import the system truststore to a truststore named `truststore.p12` in `destination_directory`.
217- fn import_system_truststore ( destination_directory : & str ) -> Vec < String > {
218- vec ! [
219- format!( "echo Importing {SYSTEM_TRUST_STORE} to {destination_directory}/truststore.p12" ) ,
220- format!(
221- "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"
222- ) ,
223- ]
135+ /// Adds a PEM file to configured PKCS12 truststore (using the [`STACKABLE_TLS_STORE_PASSWORD`]
136+ /// password)
137+ pub fn add_cert_to_truststore ( cert_file : & str , destination_directory : & str ) -> Vec < String > {
138+ let truststore = format ! ( "{destination_directory}/truststore.p12" ) ;
139+ vec ! [ format!(
140+ "truststore-merger --pkcs12 {truststore}:{STACKABLE_TLS_STORE_PASSWORD} --pem {cert_file} --out {truststore} --out-password {STACKABLE_TLS_STORE_PASSWORD}"
141+ ) ]
224142}
0 commit comments