Skip to content

Commit dccdcee

Browse files
committed
feat: add secret lifetime field
1 parent 4a8d377 commit dccdcee

File tree

5 files changed

+52
-0
lines changed

5 files changed

+52
-0
lines changed

crates/stackable-operator/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44

55
## [Unreleased]
66

7+
### Added
8+
9+
- Add new configuration field `CommonConfiguration::min_secret_lifetime` and supporting `SecretOperatorVolumeSourceBuilder` code to use it ([#908]).
10+
11+
[#908]: https://github.com/stackabletech/operator-rs/pull/908
12+
713
## [0.81.0] - 2024-11-05
814

915
### Added

crates/stackable-operator/src/builder/pod/volume.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use tracing::warn;
1515
use crate::{
1616
builder::meta::ObjectMetaBuilder,
1717
kvp::{Annotation, AnnotationError, Annotations, LabelError, Labels},
18+
time::Duration,
1819
};
1920

2021
/// A builder to build [`Volume`] objects. May only contain one `volume_source`
@@ -280,6 +281,7 @@ pub struct SecretOperatorVolumeSourceBuilder {
280281
format: Option<SecretFormat>,
281282
kerberos_service_names: Vec<String>,
282283
tls_pkcs12_password: Option<String>,
284+
auto_tls_cert_lifetime: Option<Duration>,
283285
}
284286

285287
impl SecretOperatorVolumeSourceBuilder {
@@ -290,9 +292,15 @@ impl SecretOperatorVolumeSourceBuilder {
290292
format: None,
291293
kerberos_service_names: Vec::new(),
292294
tls_pkcs12_password: None,
295+
auto_tls_cert_lifetime: None,
293296
}
294297
}
295298

299+
pub fn with_auto_tls_cert_lifetime(&mut self, lifetime: impl Into<Duration>) -> &mut Self {
300+
self.auto_tls_cert_lifetime = Some(lifetime.into());
301+
self
302+
}
303+
296304
pub fn with_node_scope(&mut self) -> &mut Self {
297305
self.scopes.push(SecretOperatorVolumeScope::Node);
298306
self
@@ -364,6 +372,13 @@ impl SecretOperatorVolumeSourceBuilder {
364372
}
365373
}
366374

375+
if let Some(lifetime) = &self.auto_tls_cert_lifetime {
376+
annotations.insert(
377+
Annotation::auto_tls_cert_lifetime(&lifetime.to_string())
378+
.context(ParseAnnotationSnafu)?,
379+
);
380+
}
381+
367382
Ok(EphemeralVolumeSource {
368383
volume_claim_template: Some(PersistentVolumeClaimTemplate {
369384
metadata: Some(ObjectMetaBuilder::new().annotations(annotations).build()),

crates/stackable-operator/src/kvp/annotation/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,15 @@ impl Annotation {
137137
))?;
138138
Ok(Self(kvp))
139139
}
140+
141+
/// Constructs a `secrets.stackable.tech/backend.autotls.cert.lifetime` annotation.
142+
pub fn auto_tls_cert_lifetime(lifetime: &str) -> Result<Self, AnnotationError> {
143+
let kvp = KeyValuePair::try_from((
144+
"secrets.stackable.tech/backend.autotls.cert.lifetime",
145+
lifetime,
146+
))?;
147+
Ok(Self(kvp))
148+
}
140149
}
141150

142151
/// A validated set/list of Kubernetes annotations.

crates/stackable-operator/src/product_config_utils.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,7 @@ mod tests {
523523

524524
use super::*;
525525
use crate::role_utils::{Role, RoleGroup};
526+
use crate::time::Duration;
526527
use k8s_openapi::api::core::v1::PodTemplateSpec;
527528
use rstest::*;
528529
use std::collections::HashMap;
@@ -617,6 +618,7 @@ mod tests {
617618
env_overrides: env_overrides.unwrap_or_default(),
618619
cli_overrides: cli_overrides.unwrap_or_default(),
619620
pod_overrides: PodTemplateSpec::default(),
621+
min_secret_lifetime: Duration::default(),
620622
}
621623
}
622624

crates/stackable-operator/src/role_utils.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ use crate::{
9292
merge::Merge,
9393
},
9494
product_config_utils::Configuration,
95+
time::Duration,
9596
utils::crds::raw_object_schema,
9697
};
9798
use derivative::Derivative;
@@ -144,6 +145,23 @@ pub struct CommonConfiguration<T> {
144145
#[serde(default)]
145146
#[schemars(schema_with = "raw_object_schema")]
146147
pub pod_overrides: PodTemplateSpec,
148+
149+
/// The minimum lifetime of secrets generated by the secret operator.
150+
/// Some secrets, such as self signed certificates are constrained to a maximum lifetime by the
151+
/// [SecretClass](DOCS_BASE_URL_PLACEHOLDER/secret-operator/secretclass) object it's self.
152+
/// Currently this property covers self signed certificates but in the future it may be extended to other
153+
/// secret types such as Kerberos keytabs.
154+
#[serde(default)]
155+
pub min_secret_lifetime: Duration,
156+
}
157+
158+
/// This implementation targets the `CommonConfiguration::min_secret_lifetime` specifically
159+
/// and corresponds to the current TLS certificate lifetime that the secret operator issues by
160+
/// default.
161+
impl Default for Duration {
162+
fn default() -> Self {
163+
Duration::from_hours_unchecked(24)
164+
}
147165
}
148166

149167
fn config_schema_default() -> serde_json::Value {
@@ -203,6 +221,7 @@ where
203221
env_overrides: self.config.env_overrides,
204222
cli_overrides: self.config.cli_overrides,
205223
pod_overrides: self.config.pod_overrides,
224+
min_secret_lifetime: self.config.min_secret_lifetime,
206225
},
207226
role_config: self.role_config,
208227
role_groups: self
@@ -219,6 +238,7 @@ where
219238
env_overrides: group.config.env_overrides,
220239
cli_overrides: group.config.cli_overrides,
221240
pod_overrides: group.config.pod_overrides,
241+
min_secret_lifetime: group.config.min_secret_lifetime,
222242
},
223243
replicas: group.replicas,
224244
},

0 commit comments

Comments
 (0)