@@ -3,7 +3,7 @@ use std::collections::BTreeMap;
33use snafu:: { ResultExt , Snafu } ;
44use stackable_operator:: {
55 client:: Client ,
6- commons:: tls_verification:: { CaCert , TlsServerVerification , TlsVerification } ,
6+ commons:: tls_verification:: { CaCert , TlsClientDetails , TlsServerVerification , TlsVerification } ,
77 crd:: s3,
88 k8s_openapi:: api:: core:: v1:: { Volume , VolumeMount } ,
99} ;
@@ -21,6 +21,37 @@ pub enum Error {
2121 S3TlsNoVerificationNotSupported ,
2222}
2323
24+ /// Returned by [`s3_tls_truststore_commands`] when an S3 connection disables TLS verification,
25+ /// which Trino does not support.
26+ #[ derive( Debug ) ]
27+ pub struct S3TlsVerificationDisabled ;
28+
29+ /// Build the init-container commands that add an S3 server's CA certificate to the client
30+ /// truststore.
31+ ///
32+ /// Returns an empty list when no extra trust setup is needed (TLS disabled, or WebPKI
33+ /// verification), and [`S3TlsVerificationDisabled`] when TLS verification is turned off (which
34+ /// Trino rejects). Shared by the spooling/exchange S3 config and the S3 catalog connection.
35+ pub fn s3_tls_truststore_commands (
36+ tls : & TlsClientDetails ,
37+ ) -> Result < Vec < String > , S3TlsVerificationDisabled > {
38+ let Some ( tls_config) = tls. tls . as_ref ( ) else {
39+ return Ok ( Vec :: new ( ) ) ;
40+ } ;
41+ match & tls_config. verification {
42+ TlsVerification :: None { } => Err ( S3TlsVerificationDisabled ) ,
43+ TlsVerification :: Server ( TlsServerVerification {
44+ ca_cert : CaCert :: WebPki { } ,
45+ } ) => Ok ( Vec :: new ( ) ) ,
46+ TlsVerification :: Server ( TlsServerVerification {
47+ ca_cert : CaCert :: SecretClass ( _) ,
48+ } ) => Ok ( tls
49+ . tls_ca_cert_mount_path ( )
50+ . map ( |ca_cert| command:: add_cert_to_truststore ( & ca_cert, STACKABLE_CLIENT_TLS_DIR ) )
51+ . unwrap_or_default ( ) ) ,
52+ }
53+ }
54+
2455pub struct ResolvedS3Config {
2556 /// Properties to add to config.properties
2657 pub properties : BTreeMap < String , String > ,
@@ -91,23 +122,10 @@ impl ResolvedS3Config {
91122 ] ) ;
92123 }
93124
94- if let Some ( tls) = s3_connection. tls . tls . as_ref ( ) {
95- match & tls. verification {
96- TlsVerification :: None { } => return S3TlsNoVerificationNotSupportedSnafu . fail ( ) ,
97- TlsVerification :: Server ( TlsServerVerification {
98- ca_cert : CaCert :: WebPki { } ,
99- } ) => { }
100- TlsVerification :: Server ( TlsServerVerification {
101- ca_cert : CaCert :: SecretClass ( _) ,
102- } ) => {
103- if let Some ( ca_cert) = s3_connection. tls . tls_ca_cert_mount_path ( ) {
104- resolved_config. init_container_extra_start_commands . extend (
105- command:: add_cert_to_truststore ( & ca_cert, STACKABLE_CLIENT_TLS_DIR ) ,
106- ) ;
107- }
108- }
109- }
110- }
125+ resolved_config. init_container_extra_start_commands . extend (
126+ s3_tls_truststore_commands ( & s3_connection. tls )
127+ . map_err ( |_| Error :: S3TlsNoVerificationNotSupported ) ?,
128+ ) ;
111129
112130 Ok ( resolved_config)
113131 }
0 commit comments