Skip to content

Commit 0914817

Browse files
committed
chore: Rename annotation
1 parent 6c58c18 commit 0914817

7 files changed

Lines changed: 44 additions & 37 deletions

File tree

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use time::OffsetDateTime;
2727

2828
use crate::{
2929
backend::{
30-
ScopeAddressesError, SecretBackend, SecretBackendError, SecretContents,
30+
ProvisionParts, ScopeAddressesError, SecretBackend, SecretBackendError, SecretContents,
3131
SecretVolumeSelector,
3232
pod_info::{Address, PodInfo},
3333
scope::SecretScope,
@@ -267,7 +267,6 @@ impl SecretBackend for TlsGenerate {
267267
// Extract and convert consumer input from the Volume annotations.
268268
let cert_lifetime = selector.autotls_cert_lifetime;
269269
let cert_restart_buffer = selector.autotls_cert_restart_buffer;
270-
let provision_cert = !selector.only_provision_identity;
271270

272271
// We need to check that the cert lifetime it is not longer than allowed,
273272
// by capping it to the maximum configured at the SecretClass.
@@ -325,7 +324,7 @@ impl SecretBackend for TlsGenerate {
325324
// Only run leaf certificate generation if it was requested based on the
326325
// secret volume selector. Otherwise only a ca.crt file as a PEM envelope
327326
// will be available (to be mounted).
328-
let tls_secret_data = if provision_cert {
327+
let tls_secret_data = if selector.provision_parts == ProvisionParts::PublicPrivate {
329328
let conf = Conf::new(ConfMethod::default())
330329
.expect("failed to initialize OpenSSL configuration");
331330

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use super::{
2222
scope::SecretScope,
2323
};
2424
use crate::{
25+
backend::ProvisionParts,
2526
crd::{self, KerberosPrincipal, v1alpha2},
2627
format::{SecretData, WellKnownSecretData, well_known},
2728
utils::Unloggable,
@@ -167,8 +168,6 @@ impl SecretBackend for KerberosKeytab {
167168
admin_principal,
168169
} = self;
169170

170-
let provision_keytab = !selector.only_provision_identity;
171-
172171
let admin_server_clause = match admin {
173172
v1alpha2::KerberosKeytabBackendAdmin::Mit(v1alpha2::KerberosKeytabBackendMit {
174173
kadmin_server,
@@ -211,7 +210,7 @@ cluster.local = {realm_name}
211210
}
212211

213212
let keytab_data =
214-
if provision_keytab {
213+
if selector.provision_parts == ProvisionParts::PublicPrivate {
215214
let admin_keytab_file_path = tmp.path().join("admin-keytab");
216215
{
217216
let mut admin_keytab_file = File::create(&admin_keytab_file_path)

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

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -140,19 +140,18 @@ pub struct SecretVolumeSelector {
140140
pub cert_manager_cert_lifetime: Option<Duration>,
141141

142142
// TODO (@Techassi): Name to be decided. Will potentially be renamed.
143-
/// Only provision non-sensitive secret data.
143+
/// Configure to either only provision public data or public + private data.
144+
///
145+
/// The following pieces of data are considered public/non-senstive:
144146
///
145147
/// - TLS (PEM): Only provision the `ca.crt` file
146148
/// - TLS (PKCS#12): Only provision the `truststore.p12` file
147149
/// - Kerberos: Only provision the `krb5.conf` file
148150
///
149-
/// This defaults to `false` to be backwords compatible with behaviour before SDP 26.3.0.
150-
#[serde(
151-
rename = "secrets.stackable.tech/only-provision-identity",
152-
deserialize_with = "SecretVolumeSelector::deserialize_str_as_bool",
153-
default
154-
)]
155-
pub only_provision_identity: bool,
151+
/// This defaults to [`ProvisionParts::PublicPrivate`] to be backwords compatible with behaviour
152+
/// before SDP 26.3.0.
153+
#[serde(rename = "secrets.stackable.tech/provision-parts", default)]
154+
pub provision_parts: ProvisionParts,
156155
}
157156

158157
/// Configuration provided by the [`TrustStore`] selecting what trust data should be provided.
@@ -161,6 +160,19 @@ pub struct TrustSelector {
161160
pub namespace: String,
162161
}
163162

163+
/// Contains options available for the `secrets.stackable.tech/provision-parts` annotation.
164+
#[derive(Debug, Default, PartialEq, Eq, Deserialize, strum::Display)]
165+
#[strum(serialize_all = "kebab-case")]
166+
#[serde(rename_all = "kebab-case")]
167+
pub enum ProvisionParts {
168+
/// Provision only public (non-senstive) data.
169+
Public,
170+
171+
/// Provision both public and private data.
172+
#[default]
173+
PublicPrivate,
174+
}
175+
164176
/// Internal parameters of [`SecretVolumeSelector`] managed by secret-operator itself.
165177
// These are optional even if they are set unconditionally, because otherwise we will
166178
// fail to restore volumes (after Node reboots etc) from before they were added during upgrades.
@@ -285,16 +297,6 @@ impl SecretVolumeSelector {
285297
)
286298
})
287299
}
288-
289-
fn deserialize_str_as_bool<'de, D: Deserializer<'de>>(de: D) -> Result<bool, D::Error> {
290-
let str = String::deserialize(de)?;
291-
str.parse().map_err(|_| {
292-
<D::Error as serde::de::Error>::invalid_value(
293-
Unexpected::Str(&str),
294-
&"a string containing a boolean",
295-
)
296-
})
297-
}
298300
}
299301

300302
#[derive(Debug)]

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ impl SecretProvisionerNode {
220220
selector: SecretVolumeSelector,
221221
) -> Result<(), PublishError> {
222222
let SecretVolumeSelector {
223-
only_provision_identity: relaxed,
223+
provision_parts,
224224
format,
225225
compat,
226226
names,
@@ -240,7 +240,7 @@ impl SecretProvisionerNode {
240240

241241
for (k, v) in data
242242
.data
243-
.into_files(format, names, compat, relaxed)
243+
.into_files(format, names, compat, provision_parts)
244244
.context(publish_error::FormatDataSnafu)?
245245
{
246246
// The following few lines of code do some basic checks against

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub use self::{
77
convert::ConvertError,
88
well_known::{FromFilesError as ParseError, SecretFormat, WellKnownSecretData},
99
};
10-
use crate::format::well_known::NamingOptions;
10+
use crate::{backend::ProvisionParts, format::well_known::NamingOptions};
1111

1212
mod convert;
1313
pub mod well_known;
@@ -20,10 +20,10 @@ pub enum SecretData {
2020
Unknown(SecretFiles),
2121
}
2222
impl SecretData {
23-
pub fn parse(self, relaxed: bool) -> Result<WellKnownSecretData, ParseError> {
23+
pub fn parse(self, provision_parts: ProvisionParts) -> Result<WellKnownSecretData, ParseError> {
2424
match self {
2525
Self::WellKnown(data) => Ok(data),
26-
Self::Unknown(files) => WellKnownSecretData::from_files(files, relaxed),
26+
Self::Unknown(files) => WellKnownSecretData::from_files(files, provision_parts),
2727
}
2828
}
2929

@@ -32,17 +32,17 @@ impl SecretData {
3232
format: Option<SecretFormat>,
3333
names: NamingOptions,
3434
compat: CompatibilityOptions,
35-
relaxed: bool,
35+
provision_parts: ProvisionParts,
3636
) -> Result<SecretFiles, IntoFilesError> {
3737
let files = if let Some(format) = format {
3838
tracing::debug!(
3939
?format,
4040
?names,
41-
relaxed,
41+
%provision_parts,
4242
"Explicit format requested: parsing and converting to transform into files"
4343
);
4444

45-
self.parse(relaxed)?
45+
self.parse(provision_parts)?
4646
.convert_to(format, compat)?
4747
.into_files(names)
4848
} else {

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use stackable_operator::schemars::{self, JsonSchema};
44
use strum::EnumDiscriminants;
55

66
use super::{ConvertError, SecretFiles, convert};
7-
use crate::utils::ResultExt;
7+
use crate::{backend::ProvisionParts, utils::ResultExt};
88

99
const FILE_PEM_CERT_CERT: &str = "tls.crt";
1010
const FILE_PEM_CERT_KEY: &str = "tls.key";
@@ -84,9 +84,16 @@ impl WellKnownSecretData {
8484

8585
pub fn from_files(
8686
mut files: SecretFiles,
87-
relaxed: bool,
87+
provision_parts: ProvisionParts,
8888
) -> Result<WellKnownSecretData, FromFilesError> {
89-
tracing::debug!(relaxed, "Constructing well-known secret data from files");
89+
tracing::debug!(
90+
%provision_parts,
91+
"Constructing well-known secret data from files"
92+
);
93+
94+
// Apply the relaxed file loading/parsing if the user only requested to provision the public
95+
// parts.
96+
let relaxed = provision_parts == ProvisionParts::Public;
9097

9198
let mut take_file = |format, file| {
9299
files

rust/operator-binary/src/truststore_controller.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use strum::{EnumDiscriminants, IntoStaticStr};
2727

2828
use crate::{
2929
OPERATOR_NAME,
30-
backend::{self, SecretBackendError, TrustSelector},
30+
backend::{self, ProvisionParts, SecretBackendError, TrustSelector},
3131
crd::{v1alpha1, v1alpha2},
3232
format::{
3333
self,
@@ -287,7 +287,7 @@ async fn reconcile(
287287
truststore.spec.format,
288288
NamingOptions::default(),
289289
CompatibilityOptions::default(),
290-
false,
290+
ProvisionParts::PublicPrivate,
291291
)
292292
.context(FormatDataSnafu {
293293
secret_class: secret_class_ref,

0 commit comments

Comments
 (0)