Skip to content

Commit dce2902

Browse files
feat: Allow the specification of additional trust roots (#573)
* feat: Allow the specification of additional trust roots * chore: Regenerate charts * test: Add integration test for additionalTrustRoots * docs: Extend CRD documentation * docs: Document the property additionalTrustRoots * chore: Improve log message Co-authored-by: Natalie Klestrup Röijezon <nat.roijezon@stackable.tech> * chore: Improve code style Co-authored-by: Natalie Klestrup Röijezon <nat.roijezon@stackable.tech> * chore: Fix compile error * feat: Support ConfigMaps in the additionalTrustRoots property * chore: Improve code style * chore: Improve code style * docs: Improve the description of additionalTrustRoots --------- Co-authored-by: Natalie Klestrup Röijezon <nat.roijezon@stackable.tech>
1 parent b247a1d commit dce2902

File tree

13 files changed

+384
-17
lines changed

13 files changed

+384
-17
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ All notable changes to this project will be documented in this file.
1414
- Made RSA key length configurable for certificates issued by cert-manager ([#528]).
1515
- Kerberos principal backends now also provision principals for IP address, not just DNS hostnames ([#552]).
1616
- OLM deployment helper ([#546]).
17+
- Allow the specification of additional trust roots in autoTls SecretClasses ([#573]).
1718

1819
### Changed
1920

@@ -38,6 +39,7 @@ All notable changes to this project will be documented in this file.
3839
[#566]: https://github.com/stackabletech/secret-operator/pull/566
3940
[#569]: https://github.com/stackabletech/secret-operator/pull/569
4041
[#571]: https://github.com/stackabletech/secret-operator/pull/571
42+
[#573]: https://github.com/stackabletech/secret-operator/pull/573
4143

4244
## [24.11.1] - 2025-01-10
4345

deploy/helm/secret-operator/crds/crds.yaml

+38
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,44 @@ spec:
4242
4343
A new certificate and key pair will be generated and signed for each Pod, keys or certificates are never reused.
4444
properties:
45+
additionalTrustRoots:
46+
default: []
47+
description: Additional trust roots which are added to the provided `ca.crt` file.
48+
items:
49+
oneOf:
50+
- required:
51+
- configMap
52+
- required:
53+
- secret
54+
properties:
55+
configMap:
56+
description: 'Reference (name and namespace) to a Kubernetes ConfigMap object where additional certificates are stored. The extensions of the keys denote its contents: A key suffixed with `.crt` contains a stack of base64 encoded DER certificates, a key suffixed with `.der` contains a binary DER certificate.'
57+
properties:
58+
name:
59+
description: Name of the ConfigMap being referred to.
60+
type: string
61+
namespace:
62+
description: Namespace of the ConfigMap being referred to.
63+
type: string
64+
required:
65+
- name
66+
- namespace
67+
type: object
68+
secret:
69+
description: 'Reference (name and namespace) to a Kubernetes Secret object where additional certificates are stored. The extensions of the keys denote its contents: A key suffixed with `.crt` contains a stack of base64 encoded DER certificates, a key suffixed with `.der` contains a binary DER certificate.'
70+
properties:
71+
name:
72+
description: Name of the Secret being referred to.
73+
type: string
74+
namespace:
75+
description: Namespace of the Secret being referred to.
76+
type: string
77+
required:
78+
- name
79+
- namespace
80+
type: object
81+
type: object
82+
type: array
4583
ca:
4684
description: Configures the certificate authority used to issue Pod certificates.
4785
properties:

deploy/helm/secret-operator/templates/roles.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ rules:
6969
- apiGroups:
7070
- ""
7171
resources:
72+
- configmaps
7273
- nodes
7374
- persistentvolumeclaims
7475
verbs:

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

+10
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ spec:
113113
keyGeneration:
114114
rsa:
115115
length: 4096
116+
additionalTrustRoots:
117+
- secret:
118+
name: trust-roots
119+
namespace: default
116120
maxCertificateLifetime: 15d # optional
117121
----
118122

@@ -125,6 +129,12 @@ spec:
125129
`autoTls.ca.keyGeneration`:: Configures how keys should be generated.
126130
`autoTls.ca.keyGeneration.rsa`:: Declares that keys should be generated using the RSA algorithm.
127131
`autoTls.ca.keyGeneration.rsa.length`:: The amount of bits used for generating the RSA key pair. Currently, `2048`, `3072` and `4096` are supported. Defaults to `2048` bits.
132+
`additionalTrustRoots`:: Configures additional trust roots which are added to the CA files or truststores in the provisioned volume mounts.
133+
`additionalTrustRoots.secret`::
134+
Reference (`name` and `namespace`) to a K8s `Secret` object where the trusted certificates are stored.
135+
The extension of a key defines its content:
136+
* `.crt` denotes a stack of PEM (base64-encoded DER) certificates.
137+
* `.der` denotes a a binary DER certificates.
128138
`autoTls.maxCertificateLifetime`:: Maximum lifetime the created certificates are allowed to have. In case consumers request a longer lifetime than allowed by this setting, the lifetime will be the minimum of both.
129139

130140
[#backend-certmanager]

rust/crd-utils/src/lib.rs

+48-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,47 @@ use std::fmt::Display;
44

55
use serde::{Deserialize, Serialize};
66
use stackable_operator::{
7-
k8s_openapi::api::core::v1::Secret,
8-
kube::runtime::reflector::ObjectRef,
7+
k8s_openapi::api::core::v1::{ConfigMap, Secret},
8+
kube::{api::DynamicObject, runtime::reflector::ObjectRef},
99
schemars::{self, JsonSchema},
1010
};
1111

12+
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
13+
#[serde(rename_all = "camelCase")]
14+
pub struct ConfigMapReference {
15+
/// Namespace of the ConfigMap being referred to.
16+
pub namespace: String,
17+
/// Name of the ConfigMap being referred to.
18+
pub name: String,
19+
}
20+
21+
// Use ObjectRef for logging/errors
22+
impl Display for ConfigMapReference {
23+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
24+
ObjectRef::<ConfigMap>::from(self).fmt(f)
25+
}
26+
}
27+
impl From<ConfigMapReference> for ObjectRef<ConfigMap> {
28+
fn from(val: ConfigMapReference) -> Self {
29+
ObjectRef::<ConfigMap>::from(&val)
30+
}
31+
}
32+
impl From<&ConfigMapReference> for ObjectRef<ConfigMap> {
33+
fn from(val: &ConfigMapReference) -> Self {
34+
ObjectRef::<ConfigMap>::new(&val.name).within(&val.namespace)
35+
}
36+
}
37+
impl From<ConfigMapReference> for ObjectRef<DynamicObject> {
38+
fn from(val: ConfigMapReference) -> Self {
39+
ObjectRef::<ConfigMap>::from(&val).erase()
40+
}
41+
}
42+
impl From<&ConfigMapReference> for ObjectRef<DynamicObject> {
43+
fn from(val: &ConfigMapReference) -> Self {
44+
ObjectRef::<ConfigMap>::from(val).erase()
45+
}
46+
}
47+
1248
// Redefine SecretReference instead of reusing k8s-openapi's, in order to make name/namespace mandatory.
1349
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
1450
#[serde(rename_all = "camelCase")]
@@ -35,3 +71,13 @@ impl From<&SecretReference> for ObjectRef<Secret> {
3571
ObjectRef::<Secret>::new(&val.name).within(&val.namespace)
3672
}
3773
}
74+
impl From<SecretReference> for ObjectRef<DynamicObject> {
75+
fn from(val: SecretReference) -> Self {
76+
ObjectRef::<Secret>::from(&val).erase()
77+
}
78+
}
79+
impl From<&SecretReference> for ObjectRef<DynamicObject> {
80+
fn from(val: &SecretReference) -> Self {
81+
ObjectRef::<Secret>::from(val).erase()
82+
}
83+
}

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

+2
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,13 @@ pub async fn from_class(
118118
}
119119
crd::SecretClassBackend::AutoTls(crd::AutoTlsBackend {
120120
ca,
121+
additional_trust_roots,
121122
max_certificate_lifetime,
122123
}) => from(
123124
super::TlsGenerate::get_or_create_k8s_certificate(
124125
client,
125126
&ca,
127+
&additional_trust_roots,
126128
max_certificate_lifetime,
127129
)
128130
.await?,

0 commit comments

Comments
 (0)