Skip to content

Commit 318c600

Browse files
committed
fix spool secret length
1 parent cc24f64 commit 318c600

2 files changed

Lines changed: 64 additions & 31 deletions

File tree

rust/operator-binary/src/controller.rs

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -527,14 +527,18 @@ pub async fn reconcile_trino(
527527
create_random_secret(
528528
&shared_internal_secret_name(trino),
529529
ENV_INTERNAL_SECRET,
530+
512,
530531
trino,
531532
client,
532533
)
533534
.await?;
534535

536+
// This secret is created even if spooling is not configured.
537+
// Trino currently requires the secret to be exactly 256 bits long.
535538
create_random_secret(
536539
&shared_spooling_secret_name(trino),
537540
ENV_SPOOLING_SECRET,
541+
32,
538542
trino,
539543
client,
540544
)
@@ -796,6 +800,16 @@ fn build_rolegroup_config_map(
796800
);
797801
}
798802

803+
// Add spooling properties from resolved configuration
804+
if let Some(resolved_spooling) = resolved_spooling_config {
805+
dynamic_resolved_config.extend(
806+
resolved_spooling
807+
.config_properties
808+
.iter()
809+
.map(|(k, v)| (k.clone(), Some(v.clone()))),
810+
);
811+
}
812+
799813
// Add static properties and overrides
800814
dynamic_resolved_config.extend(transformed_config);
801815

@@ -1027,8 +1041,19 @@ fn build_rolegroup_statefulset(
10271041
// additional authentication env vars
10281042
let mut env = trino_authentication_config.env_vars(trino_role, &Container::Trino);
10291043

1030-
let secret_name = shared_internal_secret_name(trino);
1031-
env.push(env_var_from_secret(&secret_name, None, ENV_INTERNAL_SECRET));
1044+
let internal_secret_name = shared_internal_secret_name(trino);
1045+
env.push(env_var_from_secret(
1046+
&internal_secret_name,
1047+
None,
1048+
ENV_INTERNAL_SECRET,
1049+
));
1050+
1051+
let spooling_secret_name = shared_spooling_secret_name(trino);
1052+
env.push(env_var_from_secret(
1053+
&spooling_secret_name,
1054+
None,
1055+
ENV_SPOOLING_SECRET,
1056+
));
10321057

10331058
trino_authentication_config
10341059
.add_authentication_pod_and_volume_config(
@@ -1466,11 +1491,12 @@ fn build_recommended_labels<'a>(
14661491
async fn create_random_secret(
14671492
secret_name: &str,
14681493
secret_key: &str,
1494+
secret_byte_size: usize,
14691495
trino: &v1alpha1::TrinoCluster,
14701496
client: &Client,
14711497
) -> Result<()> {
14721498
let mut internal_secret = BTreeMap::new();
1473-
internal_secret.insert(secret_key.to_string(), get_random_base64());
1499+
internal_secret.insert(secret_key.to_string(), get_random_base64(secret_byte_size));
14741500

14751501
let secret = Secret {
14761502
immutable: Some(true),
@@ -1513,8 +1539,8 @@ fn shared_spooling_secret_name(trino: &v1alpha1::TrinoCluster) -> String {
15131539
format!("{}-spooling-secret", trino.name_any())
15141540
}
15151541

1516-
fn get_random_base64() -> String {
1517-
let mut buf = [0; 512];
1542+
fn get_random_base64(byte_size: usize) -> String {
1543+
let mut buf: Vec<u8> = vec![0; byte_size];
15181544
openssl::rand::rand_bytes(&mut buf).unwrap();
15191545
openssl::base64::encode_block(&buf)
15201546
}

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

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ pub struct S3SpoolingConfig {
8484
}
8585

8686
pub struct ResolvedSpoolingProtocolConfig {
87+
/// Properties to add to config.properties
88+
pub config_properties: BTreeMap<String, String>,
89+
8790
// Properties for spooling-manager.properties
8891
pub spooling_manager_properties: BTreeMap<String, String>,
8992

@@ -110,22 +113,9 @@ impl ResolvedSpoolingProtocolConfig {
110113
client: Option<&Client>,
111114
namespace: &str,
112115
) -> Result<Self, Error> {
113-
let mut spooling_manager_properties = BTreeMap::new();
114-
115-
spooling_manager_properties.insert(
116-
"protocol.spooling.enabled".to_string(),
117-
config.enabled.to_string(),
118-
);
119-
120-
spooling_manager_properties.insert(
121-
"protocol.spooling.shared-secret-key".to_string(),
122-
format!("${{ENV:{secret}}}", secret = ENV_SPOOLING_SECRET),
123-
);
124-
125-
spooling_manager_properties.insert("fs.location".to_string(), config.location.clone());
126-
127116
let mut resolved_config = Self {
128-
spooling_manager_properties,
117+
config_properties: BTreeMap::new(),
118+
spooling_manager_properties: BTreeMap::new(),
129119
volumes: Vec::new(),
130120
volume_mounts: Vec::new(),
131121
load_env_from_files: BTreeMap::new(),
@@ -144,6 +134,26 @@ impl ResolvedSpoolingProtocolConfig {
144134
}
145135
}
146136

137+
resolved_config.spooling_manager_properties.extend([
138+
("fs.location".to_string(), config.location.clone()),
139+
(
140+
"spooling-manager.name".to_string(),
141+
"filesystem".to_string(),
142+
),
143+
]);
144+
145+
// Enable spooling protocol
146+
resolved_config.config_properties.extend([
147+
(
148+
"protocol.spooling.enabled".to_string(),
149+
config.enabled.to_string(),
150+
),
151+
(
152+
"protocol.spooling.shared-secret-key".to_string(),
153+
format!("${{ENV:{secret}}}", secret = ENV_SPOOLING_SECRET),
154+
),
155+
]);
156+
147157
// Finally, extend the spooling manager properties with any user configuration
148158
if let Some(user_config) = config.config_overrides.as_ref() {
149159
resolved_config
@@ -284,17 +294,15 @@ mod tests {
284294
.unwrap();
285295

286296
let expected_props = BTreeMap::from([
287-
("protocol.spooling.enabled".to_string(), "true".to_string()),
288-
(
289-
"protocol.spooling.shared-secret-key".to_string(),
290-
format!("${{ENV:{}}}", ENV_SPOOLING_SECRET),
291-
),
292297
(
293298
"fs.location".to_string(),
294299
"s3://my-bucket/spooling".to_string(),
295300
),
301+
(
302+
"spooling-manager.name".to_string(),
303+
"filesystem".to_string(),
304+
),
296305
]);
297-
298306
assert_eq!(
299307
expected_props,
300308
resolved_spooling_config.spooling_manager_properties
@@ -330,11 +338,6 @@ mod tests {
330338
.unwrap();
331339

332340
let expected_props = BTreeMap::from([
333-
("protocol.spooling.enabled".to_string(), "true".to_string()),
334-
(
335-
"protocol.spooling.shared-secret-key".to_string(),
336-
format!("${{ENV:{}}}", ENV_SPOOLING_SECRET),
337-
),
338341
(
339342
"fs.location".to_string(),
340343
"s3://my-bucket/spooling".to_string(),
@@ -343,6 +346,10 @@ mod tests {
343346
"protocol.spooling.retrieval-mode".to_string(),
344347
"STORAGE".to_string(),
345348
),
349+
(
350+
"spooling-manager.name".to_string(),
351+
"filesystem".to_string(),
352+
),
346353
]);
347354

348355
assert_eq!(

0 commit comments

Comments
 (0)