Skip to content

Commit c489b44

Browse files
committed
configure tls on run-securityadmin
1 parent d45f8fb commit c489b44

4 files changed

Lines changed: 66 additions & 17 deletions

File tree

rust/operator-binary/src/controller/build.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ use std::marker::PhantomData;
22

33
use role_builder::RoleBuilder;
44

5-
use crate::controller::build::job_builder::JobBuilder;
6-
75
use super::{ContextNames, KubernetesResources, Prepared, ValidatedCluster};
6+
use crate::controller::build::job_builder::JobBuilder;
87

98
pub mod job_builder;
109
pub mod node_config;

rust/operator-binary/src/controller/build/job_builder.rs

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
use stackable_operator::{
22
builder::{
33
meta::ObjectMetaBuilder,
4-
pod::{container::ContainerBuilder, resources::ResourceRequirementsBuilder},
4+
pod::{
5+
container::ContainerBuilder, resources::ResourceRequirementsBuilder,
6+
volume::SecretFormat,
7+
},
58
},
69
k8s_openapi::api::{
710
batch::v1::{Job, JobSpec},
@@ -14,17 +17,20 @@ use stackable_operator::{
1417
Label, Labels,
1518
consts::{STACKABLE_VENDOR_KEY, STACKABLE_VENDOR_VALUE},
1619
},
20+
time::Duration,
1721
};
1822

1923
use crate::{
2024
controller::{ContextNames, ValidatedCluster},
2125
framework::{
22-
IsLabelValue, builder::meta::ownerreference_from_resource, role_utils::ResourceNames,
26+
IsLabelValue,
27+
builder::{meta::ownerreference_from_resource, volume::build_tls_volume},
28+
role_utils::ResourceNames,
2329
},
2430
};
2531

2632
const RUN_SECURITYADMIN_CERT_VOLUME_NAME: &str = "tls";
27-
const RUN_SECURITYADMIN_CERT_VOLUME_MOUNT: &str = "/stackable/cert";
33+
const RUN_SECURITYADMIN_CERT_VOLUME_MOUNT: &str = "/stackable/tls-client";
2834
const SECURITY_CONFIG_VOLUME_NAME: &str = "security-config";
2935
const SECURITY_CONFIG_VOLUME_MOUNT: &str = "/stackable/opensearch/config/opensearch-security";
3036
const RUN_SECURITYADMIN_CONTAINER_NAME: &str = "run-securityadmin";
@@ -61,11 +67,11 @@ impl<'a> JobBuilder<'a> {
6167
let args = [
6268
"plugins/opensearch-security/tools/securityadmin.sh".to_string(),
6369
"-cacert".to_string(),
64-
"config/tls-client/ca.crt".to_string(),
70+
"/stackable/tls-client/ca.crt".to_string(),
6571
"-cert".to_string(),
66-
"config/tls-client/tls.crt".to_string(),
72+
"/stackable/tls-client/tls.crt".to_string(),
6773
"-key".to_string(),
68-
"config/tls-client/tls.key".to_string(),
74+
"/stackable/tls-client/tls.key".to_string(),
6975
"--hostname".to_string(),
7076
self.opensearch_master_fqdn(),
7177
"--configdir".to_string(),
@@ -105,20 +111,29 @@ impl<'a> JobBuilder<'a> {
105111
metadata: Some(metadata.clone()),
106112
spec: Some(PodSpec {
107113
containers: vec![container],
108-
109114
security_context: Some(PodSecurityContext {
110115
fs_group: Some(1000),
111116
..PodSecurityContext::default()
112117
}),
118+
restart_policy: Some("OnFailure".to_string()),
113119
service_account_name: Some(self.resource_names.service_account_name()),
114-
volumes: Some(vec![Volume {
115-
name: SECURITY_CONFIG_VOLUME_NAME.to_owned(),
116-
secret: Some(SecretVolumeSource {
117-
secret_name: Some("opensearch-security-config".to_string()),
118-
..Default::default()
119-
}),
120-
..Volume::default()
121-
}]),
120+
volumes: Some(vec![
121+
Volume {
122+
name: SECURITY_CONFIG_VOLUME_NAME.to_owned(),
123+
secret: Some(SecretVolumeSource {
124+
secret_name: Some("opensearch-security-config".to_string()),
125+
..Default::default()
126+
}),
127+
..Volume::default()
128+
},
129+
build_tls_volume(
130+
RUN_SECURITYADMIN_CERT_VOLUME_NAME,
131+
Vec::<String>::new(),
132+
SecretFormat::TlsPem,
133+
&Duration::from_days_unchecked(15),
134+
None,
135+
),
136+
]),
122137
..PodSpec::default()
123138
}),
124139
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
pub mod meta;
22
pub mod pdb;
33
pub mod pod;
4+
pub mod volume;
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
use stackable_operator::{
2+
builder::pod::volume::{SecretFormat, SecretOperatorVolumeSourceBuilder, VolumeBuilder},
3+
k8s_openapi::api::core::v1::Volume,
4+
time::Duration,
5+
};
6+
7+
pub fn build_tls_volume(
8+
volume_name: &str,
9+
service_scopes: impl IntoIterator<Item = impl AsRef<str>>,
10+
secret_format: SecretFormat,
11+
requested_secret_lifetime: &Duration,
12+
listener_scope: Option<&str>,
13+
) -> Volume {
14+
let mut secret_volume_source_builder =
15+
SecretOperatorVolumeSourceBuilder::new("tls".to_string());
16+
17+
for scope in service_scopes {
18+
secret_volume_source_builder.with_service_scope(scope.as_ref());
19+
}
20+
if let Some(listener_scope) = listener_scope {
21+
secret_volume_source_builder.with_listener_volume_scope(listener_scope);
22+
}
23+
24+
VolumeBuilder::new(volume_name)
25+
.ephemeral(
26+
secret_volume_source_builder
27+
.with_pod_scope()
28+
.with_format(secret_format)
29+
.with_auto_tls_cert_lifetime(*requested_secret_lifetime)
30+
.build()
31+
.expect("volume should be built"),
32+
)
33+
.build()
34+
}

0 commit comments

Comments
 (0)