Skip to content

Commit e028cf4

Browse files
committed
use config-utils to resolve S3 credentials
1 parent e916710 commit e028cf4

4 files changed

Lines changed: 29 additions & 71 deletions

File tree

rust/operator-binary/src/command.rs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ use crate::{
1111
catalog::config::CatalogConfig,
1212
controller::{STACKABLE_LOG_CONFIG_DIR, STACKABLE_LOG_DIR},
1313
crd::{
14-
CONFIG_DIR_NAME, Container, LOG_PROPERTIES, RW_CONFIG_DIR_NAME, STACKABLE_CLIENT_TLS_DIR,
14+
CONFIG_DIR_NAME, Container, EXCHANGE_MANAGER_PROPERTIES, LOG_PROPERTIES,
15+
RW_CONFIG_DIR_NAME, SPOOLING_MANAGER_PROPERTIES, STACKABLE_CLIENT_TLS_DIR,
1516
STACKABLE_INTERNAL_TLS_DIR, STACKABLE_MOUNT_INTERNAL_TLS_DIR,
1617
STACKABLE_MOUNT_SERVER_TLS_DIR, STACKABLE_SERVER_TLS_DIR, STACKABLE_TLS_STORE_PASSWORD,
1718
SYSTEM_TRUST_STORE, SYSTEM_TRUST_STORE_PASSWORD, TrinoRole, client_protocol,
@@ -97,8 +98,6 @@ pub fn container_prepare_args(
9798
pub fn container_trino_args(
9899
authentication_config: &TrinoAuthenticationConfig,
99100
catalogs: &[CatalogConfig],
100-
resolved_fte_config: &Option<ResolvedFaultTolerantExecutionConfig>,
101-
resolved_spooling_config: &Option<client_protocol::ResolvedClientProtocolConfig>,
102101
) -> Vec<String> {
103102
let mut args = vec![
104103
// copy config files to a writeable empty folder
@@ -126,19 +125,17 @@ pub fn container_trino_args(
126125
}
127126
});
128127

129-
// Add fault tolerant execution environment variables from files
130-
if let Some(resolved_fte) = resolved_fte_config {
131-
for (env_name, file) in &resolved_fte.load_env_from_files {
132-
args.push(format!("export {env_name}=\"$(cat {file})\""));
133-
}
134-
}
128+
// Resolve credentials for fault tolerant execution exchange manager if needed
129+
args.push(format!(
130+
"test -f {rw_exchange_manager_config_file} && config-utils template {rw_exchange_manager_config_file}",
131+
rw_exchange_manager_config_file = format!("{RW_CONFIG_DIR_NAME}/{EXCHANGE_MANAGER_PROPERTIES}")
132+
));
135133

136-
// Add client spooling environment variables from files
137-
if let Some(resolved_spooling) = resolved_spooling_config {
138-
for (env_name, file) in &resolved_spooling.load_env_from_files {
139-
args.push(format!("export {env_name}=\"$(cat {file})\""));
140-
}
141-
}
134+
// Resolve credentials for spooling manager if needed
135+
args.push(format!(
136+
"test -f {rw_spooling_config_file} && config-utils template {rw_spooling_config_file}",
137+
rw_spooling_config_file = format!("{RW_CONFIG_DIR_NAME}/{SPOOLING_MANAGER_PROPERTIES}")
138+
));
142139

143140
args.push("set -x".to_string());
144141

rust/operator-binary/src/controller.rs

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -875,31 +875,17 @@ fn build_rolegroup_config_map(
875875

876876
// Add exchange manager properties from resolved fault tolerant execution configuration
877877
if let Some(resolved_fte) = resolved_fte_config {
878-
if !resolved_fte.exchange_manager_properties.is_empty() {
879-
let exchange_props_with_options: BTreeMap<String, Option<String>> = resolved_fte
880-
.exchange_manager_properties
881-
.iter()
882-
.map(|(k, v)| (k.clone(), Some(v.clone())))
883-
.collect();
884-
cm_conf_data.insert(
885-
EXCHANGE_MANAGER_PROPERTIES.to_string(),
886-
to_java_properties_string(exchange_props_with_options.iter())
887-
.with_context(|_| FailedToWriteJavaPropertiesSnafu)?,
888-
);
889-
}
878+
cm_conf_data.insert(
879+
EXCHANGE_MANAGER_PROPERTIES.to_string(),
880+
unsafe_java_properties_string(&resolved_fte.exchange_manager_properties),
881+
);
890882
}
891883

892884
// Add client protocol properties (especially spooling properties)
893885
if let Some(spooling_config) = resolved_spooling_config {
894-
let spooling_props_with_options: BTreeMap<String, Option<String>> = spooling_config
895-
.spooling_manager_properties
896-
.iter()
897-
.map(|(k, v)| (k.clone(), Some(v.clone())))
898-
.collect();
899886
cm_conf_data.insert(
900887
SPOOLING_MANAGER_PROPERTIES.to_string(),
901-
to_java_properties_string(spooling_props_with_options.iter())
902-
.with_context(|_| FailedToWriteJavaPropertiesSnafu)?,
888+
unsafe_java_properties_string(&spooling_config.spooling_manager_properties),
903889
);
904890
}
905891

@@ -943,6 +929,13 @@ fn build_rolegroup_config_map(
943929
})
944930
}
945931

932+
fn unsafe_java_properties_string(map: &BTreeMap<String, String>) -> String {
933+
map.iter()
934+
.map(|(k, v)| format!("{}={}", k, v))
935+
.collect::<Vec<_>>()
936+
.join("\n")
937+
}
938+
946939
/// The rolegroup catalog [`ConfigMap`] configures the rolegroup catalog based on the configuration
947940
/// given by the administrator
948941
fn build_rolegroup_catalog_config_map(
@@ -1200,13 +1193,7 @@ fn build_rolegroup_statefulset(
12001193
"-c".to_string(),
12011194
])
12021195
.args(vec![
1203-
command::container_trino_args(
1204-
trino_authentication_config,
1205-
catalogs,
1206-
resolved_fte_config,
1207-
resolved_spooling_config,
1208-
)
1209-
.join("\n"),
1196+
command::container_trino_args(trino_authentication_config, catalogs).join("\n"),
12101197
])
12111198
.add_env_vars(env)
12121199
.add_volume_mount("config", CONFIG_DIR_NAME)

rust/operator-binary/src/crd/client_protocol.rs

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ use crate::{
2020
crd::{ENV_SPOOLING_SECRET, STACKABLE_CLIENT_TLS_DIR},
2121
};
2222

23-
const SPOOLING_S3_AWS_ACCESS_KEY: &str = "SPOOLING_S3_AWS_ACCESS_KEY";
24-
const SPOOLING_S3_AWS_SECRET_KEY: &str = "SPOOLING_S3_AWS_SECRET_KEY";
25-
2623
#[derive(Clone, Debug, Deserialize, JsonSchema, PartialEq, Serialize)]
2724
#[serde(rename_all = "camelCase")]
2825
pub enum ClientProtocolConfig {
@@ -88,10 +85,6 @@ pub struct ResolvedClientProtocolConfig {
8885
/// Volume mounts required for the configuration
8986
pub volume_mounts: Vec<VolumeMount>,
9087

91-
/// Env-Vars that should be exported from files.
92-
/// You can think of it like `export <key>="$(cat <value>)"`
93-
pub load_env_from_files: BTreeMap<String, String>,
94-
9588
/// Additional commands that need to be executed before starting Trino
9689
/// Used to add TLS certificates to the client's trust store.
9790
pub init_container_extra_start_commands: Vec<String>,
@@ -110,7 +103,6 @@ impl ResolvedClientProtocolConfig {
110103
spooling_manager_properties: BTreeMap::new(),
111104
volumes: Vec::new(),
112105
volume_mounts: Vec::new(),
113-
load_env_from_files: BTreeMap::new(),
114106
init_container_extra_start_commands: Vec::new(),
115107
};
116108

@@ -194,18 +186,13 @@ impl ResolvedClientProtocolConfig {
194186
self.spooling_manager_properties.extend([
195187
(
196188
"s3.aws-access-key".to_string(),
197-
format!("${{ENV:{SPOOLING_S3_AWS_ACCESS_KEY}}}"),
189+
format!("${{file:UTF-8:{access_key_path}}}"),
198190
),
199191
(
200192
"s3.aws-secret-key".to_string(),
201-
format!("${{ENV:{SPOOLING_S3_AWS_SECRET_KEY}}}"),
193+
format!("${{file:UTF-8:{secret_key_path}}}"),
202194
),
203195
]);
204-
205-
self.load_env_from_files.extend([
206-
(String::from(SPOOLING_S3_AWS_ACCESS_KEY), access_key_path),
207-
(String::from(SPOOLING_S3_AWS_SECRET_KEY), secret_key_path),
208-
]);
209196
}
210197

211198
if let Some(tls) = s3_connection.tls.tls.as_ref() {

rust/operator-binary/src/crd/fault_tolerant_execution.rs

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,6 @@ pub struct ResolvedFaultTolerantExecutionConfig {
226226
/// Volume mounts required for the configuration
227227
pub volume_mounts: Vec<VolumeMount>,
228228

229-
/// Env-Vars that should be exported from files.
230-
/// You can think of it like `export <key>="$(cat <value>)"`
231-
pub load_env_from_files: BTreeMap<String, String>,
232-
233229
/// Additional commands that need to be executed before starting Trino
234230
pub init_container_extra_start_commands: Vec<String>,
235231
}
@@ -453,7 +449,6 @@ impl ResolvedFaultTolerantExecutionConfig {
453449
exchange_manager_properties,
454450
volumes: Vec::new(),
455451
volume_mounts: Vec::new(),
456-
load_env_from_files: BTreeMap::new(),
457452
init_container_extra_start_commands: Vec::new(),
458453
};
459454

@@ -516,22 +511,14 @@ impl ResolvedFaultTolerantExecutionConfig {
516511
);
517512

518513
if let Some((access_key_path, secret_key_path)) = s3_connection.credentials_mount_paths() {
519-
let access_key_env = "EXCHANGE_S3_AWS_ACCESS_KEY".to_string();
520-
let secret_key_env = "EXCHANGE_S3_AWS_SECRET_KEY".to_string();
521-
522514
self.exchange_manager_properties.insert(
523515
"exchange.s3.aws-access-key".to_string(),
524-
format!("${{ENV:{access_key_env}}}"),
516+
format!("${{file:UTF-8:{access_key_path}}}"),
525517
);
526518
self.exchange_manager_properties.insert(
527519
"exchange.s3.aws-secret-key".to_string(),
528-
format!("${{ENV:{secret_key_env}}}"),
520+
format!("${{file:UTF-8:{secret_key_path}}}"),
529521
);
530-
531-
self.load_env_from_files
532-
.insert(access_key_env, access_key_path);
533-
self.load_env_from_files
534-
.insert(secret_key_env, secret_key_path);
535522
}
536523

537524
if let Some(tls) = s3_connection.tls.tls.as_ref() {

0 commit comments

Comments
 (0)