Skip to content

Commit 81bec4d

Browse files
committed
feat: Add annotation to provision public secret data only
1 parent 6de8388 commit 81bec4d

5 files changed

Lines changed: 83 additions & 40 deletions

File tree

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ pub struct SecretVolumeSelector {
7373
/// The desired format of the mounted secrets
7474
///
7575
/// Currently supported formats:
76+
///
7677
/// - `tls-pem` - A Kubernetes-style triple of PEM-encoded certificate files (`tls.crt`, `tls.key`, `ca.crt`).
7778
/// - `tls-pkcs12` - A PKCS#12 key store named `keystore.p12` and truststore named `truststore.p12`.
7879
/// - `kerberos` - A Kerberos keytab named `keytab`, along with a `krb5.conf`.
@@ -138,6 +139,21 @@ pub struct SecretVolumeSelector {
138139
default
139140
)]
140141
pub cert_manager_cert_lifetime: Option<Duration>,
142+
143+
// TODO (@Techassi): Name to be decided. Will potentially be renamed.
144+
/// Only provision non-sensitive secret data.
145+
///
146+
/// - TLS (PEM): Only provision the `ca.crt` file
147+
/// - TLS (PKCS#12): Only provision the `truststore.p12` file
148+
/// - Kerberos: Only provision the `krb5.conf` file
149+
///
150+
/// This defaults to `false` to be backwords compatible with behaviour before SDP 26.3.0.
151+
#[serde(
152+
rename = "secrets.stackable.tech/only-provision-identity",
153+
deserialize_with = "SecretVolumeSelector::deserialize_str_as_bool",
154+
default
155+
)]
156+
pub only_provision_identity: bool,
141157
}
142158

143159
/// Configuration provided by the [`TrustStore`] selecting what trust data should be provided.
@@ -270,6 +286,16 @@ impl SecretVolumeSelector {
270286
)
271287
})
272288
}
289+
290+
fn deserialize_str_as_bool<'de, D: Deserializer<'de>>(de: D) -> Result<bool, D::Error> {
291+
let str = String::deserialize(de)?;
292+
str.parse().map_err(|_| {
293+
<D::Error as serde::de::Error>::invalid_value(
294+
Unexpected::Str(&str),
295+
&"a string containing a boolean",
296+
)
297+
})
298+
}
273299
}
274300

275301
#[derive(Debug)]

rust/operator-binary/src/csi_server/node.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@ use crate::{
2626
self, SecretBackendError, SecretContents, SecretVolumeSelector,
2727
pod_info::{self, PodInfo},
2828
},
29-
format::{
30-
self, SecretFormat,
31-
well_known::{CompatibilityOptions, NamingOptions},
32-
},
29+
format,
3330
grpc::csi::v1::{
3431
NodeExpandVolumeRequest, NodeExpandVolumeResponse, NodeGetCapabilitiesRequest,
3532
NodeGetCapabilitiesResponse, NodeGetInfoRequest, NodeGetInfoResponse,
@@ -220,10 +217,16 @@ impl SecretProvisionerNode {
220217
&self,
221218
target_path: &Path,
222219
data: SecretContents,
223-
format: Option<SecretFormat>,
224-
names: NamingOptions,
225-
compat: CompatibilityOptions,
220+
selector: SecretVolumeSelector,
226221
) -> Result<(), PublishError> {
222+
let SecretVolumeSelector {
223+
only_provision_identity,
224+
format,
225+
compat,
226+
names,
227+
..
228+
} = selector;
229+
227230
let create_secret = {
228231
let mut opts = OpenOptions::new();
229232
opts.create(true)
@@ -234,9 +237,10 @@ impl SecretProvisionerNode {
234237
.mode(0o640);
235238
opts
236239
};
240+
237241
for (k, v) in data
238242
.data
239-
.into_files(format, names, compat)
243+
.into_files(format, names, compat, only_provision_identity)
240244
.context(publish_error::FormatDataSnafu)?
241245
{
242246
// The following few lines of code do some basic checks against
@@ -423,10 +427,7 @@ impl Node for SecretProvisionerNode {
423427
self.save_secret_data(
424428
&target_path,
425429
data,
426-
// NOTE (@Techassi): At this point, we might want to pass the whole selector instead
427-
selector.format,
428-
selector.names,
429-
selector.compat,
430+
selector
430431
)
431432
.await?;
432433
Ok(Response::new(NodePublishVolumeResponse {}))

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub enum SecretData {
2222
impl SecretData {
2323
pub fn parse(self) -> Result<WellKnownSecretData, ParseError> {
2424
match self {
25-
Self::WellKnown(x) => Ok(x),
25+
Self::WellKnown(data) => Ok(data),
2626
Self::Unknown(files) => WellKnownSecretData::from_files(files),
2727
}
2828
}
@@ -32,15 +32,20 @@ impl SecretData {
3232
format: Option<SecretFormat>,
3333
names: NamingOptions,
3434
compat: CompatibilityOptions,
35+
only_identity: bool,
3536
) -> Result<SecretFiles, IntoFilesError> {
36-
if let Some(format) = format {
37-
Ok(self.parse()?.convert_to(format, compat)?.into_files(names))
37+
let files = if let Some(format) = format {
38+
self.parse()?
39+
.convert_to(format, compat)?
40+
.into_files(names, only_identity)
3841
} else {
39-
Ok(match self {
40-
SecretData::WellKnown(data) => data.into_files(names),
42+
match self {
43+
SecretData::WellKnown(data) => data.into_files(names, only_identity),
4144
SecretData::Unknown(files) => files,
42-
})
43-
}
45+
}
46+
};
47+
48+
Ok(files)
4449
}
4550
}
4651

rust/operator-binary/src/format/well_known.rs

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -47,35 +47,45 @@ pub enum WellKnownSecretData {
4747
}
4848

4949
impl WellKnownSecretData {
50-
pub fn into_files(self, names: NamingOptions) -> SecretFiles {
50+
pub fn into_files(self, names: NamingOptions, only_identity: bool) -> SecretFiles {
5151
match self {
5252
WellKnownSecretData::TlsPem(TlsPem {
5353
certificate_pem,
5454
key_pem,
5555
ca_pem,
56-
}) => [
57-
Some(names.tls_pem_cert_name).zip(certificate_pem),
58-
Some(names.tls_pem_key_name).zip(key_pem),
59-
Some((names.tls_pem_ca_name, ca_pem)),
60-
]
61-
.into_iter()
62-
.flatten()
63-
.collect(),
56+
}) => {
57+
let mut files = vec![Some((names.tls_pem_ca_name, ca_pem))];
58+
59+
if !only_identity {
60+
files.extend([
61+
Some(names.tls_pem_cert_name).zip(certificate_pem),
62+
Some(names.tls_pem_key_name).zip(key_pem),
63+
]);
64+
}
65+
66+
files.into_iter().flatten().collect()
67+
}
6468
WellKnownSecretData::TlsPkcs12(TlsPkcs12 {
6569
keystore,
6670
truststore,
67-
}) => [
68-
Some(names.tls_pkcs12_keystore_name).zip(keystore),
69-
Some((names.tls_pkcs12_truststore_name, truststore)),
70-
]
71-
.into_iter()
72-
.flatten()
73-
.collect(),
74-
WellKnownSecretData::Kerberos(Kerberos { keytab, krb5_conf }) => [
75-
(FILE_KERBEROS_KEYTAB_KEYTAB.to_string(), keytab),
76-
(FILE_KERBEROS_KEYTAB_KRB5_CONF.to_string(), krb5_conf),
77-
]
78-
.into(),
71+
}) => {
72+
let mut files = vec![Some((names.tls_pkcs12_truststore_name, truststore))];
73+
74+
if !only_identity {
75+
files.push(Some(names.tls_pkcs12_keystore_name).zip(keystore));
76+
}
77+
78+
files.into_iter().flatten().collect()
79+
}
80+
WellKnownSecretData::Kerberos(Kerberos { keytab, krb5_conf }) => {
81+
let mut files = vec![(FILE_KERBEROS_KEYTAB_KRB5_CONF.to_string(), krb5_conf)];
82+
83+
if !only_identity {
84+
files.push((FILE_KERBEROS_KEYTAB_KEYTAB.to_string(), keytab));
85+
}
86+
87+
SecretFiles::from_iter(files)
88+
}
7989
}
8090
}
8191

rust/operator-binary/src/truststore_controller.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ async fn reconcile(
291291
truststore.spec.format,
292292
NamingOptions::default(),
293293
CompatibilityOptions::default(),
294+
false,
294295
)
295296
.context(FormatDataSnafu {
296297
secret_class: secret_class_ref,

0 commit comments

Comments
 (0)