Skip to content

Commit 44739b5

Browse files
committed
chore: add tests / changelog entry
1 parent fb36ae9 commit 44739b5

File tree

4 files changed

+118
-5
lines changed

4 files changed

+118
-5
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ All notable changes to this project will be documented in this file.
1717
### Changed
1818

1919
- Default to OCI for image metadata ([#544]).
20+
- [BREAKING] When using a fully qualified domain name, only the variant without the trailing dot is added to the SANs. This should only improve the behavior in scenarios where FQDNs are used and not affect anything else ([#564]).
2021

2122
[#528]: https://github.com/stackabletech/secret-operator/pull/528
2223
[#548]: https://github.com/stackabletech/secret-operator/pull/548
2324
[#552]: https://github.com/stackabletech/secret-operator/pull/552
2425
[#544]: https://github.com/stackabletech/secret-operator/pull/544
26+
[#564]: https://github.com/stackabletech/secret-operator/pull/564
2527

2628
## [24.11.1] - 2025-01-10
2729

docs/modules/secret-operator/pages/scope.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,5 @@ For example, a TLS certificate provisioned by the xref:secretclass.adoc#backend-
5959
xref:#node[] and xref:#pod[] would contain the following values in its `subjectAlternateName` (SAN) extension field:
6060

6161
* The node's IP address
62-
* The node's fully qualified domain name (`my-node.example.com`)
63-
* The pod's fully qualified domain name (`my-pod.my-service.my-namespace.svc.cluster.local`)
62+
* The node's fully qualified domain name (`my-node.example.com`, trailing dots are removed)
63+
* The pod's fully qualified domain name (`my-pod.my-service.my-namespace.svc.cluster.local`, trailing dots are removed)

rust/operator-binary/src/backend/mod.rs

Lines changed: 113 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ impl SecretVolumeSelector {
179179
scope: &scope::SecretScope,
180180
) -> Result<Vec<Address>, ScopeAddressesError> {
181181
use scope_addresses_error::*;
182-
// Turn FQDNs into bare domain names by removing the trailing dot
182+
// Turn FQDNs into bare domain names by removing the trailing dots
183183
let cluster_domain = pod_info.kubernetes_cluster_domain.trim_end_matches(".");
184184
let namespace = &self.namespace;
185185
Ok(match scope {
@@ -211,7 +211,7 @@ impl SecretVolumeSelector {
211211
.context(NoListenerAddressesSnafu { listener: name })?
212212
.iter()
213213
.map(|addr| match addr {
214-
// Turn FQDNs into bare domain names by removing the trailing dot
214+
// Turn FQDNs into bare domain names by removing the trailing dots
215215
Address::Dns(dns) => Address::Dns(dns.trim_end_matches(".").to_string()),
216216
_ => addr.clone(),
217217
})
@@ -304,3 +304,114 @@ impl SecretBackendError for Infallible {
304304
match *self {}
305305
}
306306
}
307+
308+
#[cfg(test)]
309+
mod tests {
310+
use std::collections::HashMap;
311+
312+
use pod_info::PodInfo;
313+
314+
use super::*;
315+
316+
#[test]
317+
fn test_scope_addresses_without_trailing_dot() {
318+
let pod_info = construct_pod_info("cluster.local");
319+
320+
assert_eq!(
321+
calculate_scope(&pod_info, &SecretScope::Pod),
322+
vec![
323+
dns("my-sts.default.svc.cluster.local"),
324+
dns("my-sts-0.my-sts.default.svc.cluster.local"),
325+
ip("10.0.0.42"),
326+
]
327+
);
328+
329+
assert_eq!(
330+
calculate_scope(
331+
&pod_info,
332+
&SecretScope::Service {
333+
name: "my-service".to_owned()
334+
}
335+
),
336+
vec![dns("my-service.default.svc.cluster.local"),]
337+
);
338+
339+
assert_eq!(
340+
calculate_scope(&pod_info, &SecretScope::Node),
341+
vec![dns("my-node"), ip("192.168.0.1"),]
342+
);
343+
}
344+
345+
#[test]
346+
fn test_scope_addresses_with_trailing_dot() {
347+
let pod_info = construct_pod_info("custom.cluster.local.");
348+
349+
assert_eq!(
350+
calculate_scope(&pod_info, &SecretScope::Pod),
351+
vec![
352+
dns("my-sts.default.svc.custom.cluster.local"),
353+
dns("my-sts-0.my-sts.default.svc.custom.cluster.local"),
354+
ip("10.0.0.42"),
355+
]
356+
);
357+
358+
assert_eq!(
359+
calculate_scope(
360+
&pod_info,
361+
&SecretScope::Service {
362+
name: "my-service".to_owned()
363+
}
364+
),
365+
vec![
366+
dns("my-service.default.svc.custom.cluster.local")
367+
]
368+
);
369+
370+
assert_eq!(
371+
calculate_scope(&pod_info, &SecretScope::Node),
372+
vec![dns("my-node"), ip("192.168.0.1"),]
373+
);
374+
}
375+
376+
fn construct_pod_info(cluster_domain: &str) -> PodInfo {
377+
PodInfo {
378+
pod_ips: vec!["10.0.0.42".parse().unwrap()],
379+
service_name: Some("my-sts".to_owned()),
380+
node_name: "my-node".to_owned(),
381+
node_ips: vec!["192.168.0.1".parse().unwrap()],
382+
listener_addresses: HashMap::from([]),
383+
kubernetes_cluster_domain: cluster_domain.parse().unwrap(),
384+
scheduling: SchedulingPodInfo {
385+
namespace: "default".to_owned(),
386+
volume_listener_names: HashMap::new(),
387+
has_node_scope: false,
388+
},
389+
}
390+
}
391+
392+
fn calculate_scope(pod_info: &PodInfo, scope: &SecretScope) -> Vec<Address> {
393+
let secret_volume_selector = construct_secret_volume_selector();
394+
secret_volume_selector
395+
.scope_addresses(pod_info, scope)
396+
.unwrap()
397+
}
398+
399+
fn dns(dns: &str) -> Address {
400+
Address::Dns(dns.to_owned())
401+
}
402+
403+
fn ip(ip: &str) -> Address {
404+
Address::Ip(ip.parse().unwrap())
405+
}
406+
407+
fn construct_secret_volume_selector() -> SecretVolumeSelector {
408+
serde_yaml::from_str(
409+
r#"
410+
secrets.stackable.tech/class: tls
411+
csi.storage.k8s.io/pod.name: my-sts-0
412+
csi.storage.k8s.io/pod.namespace: default
413+
"#,
414+
)
415+
.unwrap()
416+
}
417+
}

rust/operator-binary/src/backend/pod_info.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ impl PodInfo {
175175
}
176176
}
177177

178-
#[derive(Debug, Clone)]
178+
#[derive(Debug, Clone, PartialEq)]
179179
pub enum Address {
180180
Dns(String),
181181
Ip(IpAddr),

0 commit comments

Comments
 (0)