Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions ci/nightly/pipeline.template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2791,6 +2791,21 @@ steps:
agents:
queue: hetzner-aarch64-16cpu-32gb

- id: orchestratord-oidc-auth-tls
topics: [self-managed]
label: Orchestratord OIDC auth end-to-end with a private CA
artifact_paths: ["mz_debug_*.zip"]
depends_on: devel-docker-tags
timeout_in_minutes: 60
plugins:
- ./ci/plugins/mzcompose:
composition: orchestratord
run: oidc-auth-tls
args: [--recreate-cluster]
ci-builder: stable
agents:
queue: hetzner-aarch64-16cpu-32gb

- id: orchestratord-clusterd-generation-scheduling
topics: [self-managed]
label: Orchestratord clusterd generation scheduling
Expand Down
179 changes: 176 additions & 3 deletions src/cloud-resources/src/crd/materialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,55 @@ impl Default for RolloutRequestTimeout {
}
}

/// A key in a ConfigMap or Secret whose value holds one or more PEM-encoded
/// CA certificates.
///
/// Set exactly one of `configMapKeyRef` or `secretKeyRef`. The ConfigMap or
/// Secret must be in the same namespace as the Materialize resource. Only the
/// referenced key is mounted into the pods.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize, JsonSchema)]
#[serde(rename_all = "camelCase")]
pub struct AdditionalTrustBundle {
/// A key in a ConfigMap.
#[serde(skip_serializing_if = "Option::is_none")]
pub config_map_key_ref: Option<TrustBundleKeyRef>,
/// A key in a Secret.
#[serde(skip_serializing_if = "Option::is_none")]
pub secret_key_ref: Option<TrustBundleKeyRef>,
}

impl AdditionalTrustBundle {
/// The ConfigMap or Secret key holding the certificates. Errors unless
/// exactly one of `configMapKeyRef` and `secretKeyRef` is set.
pub fn source(&self) -> Result<TrustBundleSource<'_>, anyhow::Error> {
match (&self.config_map_key_ref, &self.secret_key_ref) {
(Some(key_ref), None) => Ok(TrustBundleSource::ConfigMap(key_ref)),
(None, Some(key_ref)) => Ok(TrustBundleSource::Secret(key_ref)),
(Some(_), Some(_)) => {
anyhow::bail!("set only one of configMapKeyRef and secretKeyRef, not both")
}
(None, None) => anyhow::bail!("set one of configMapKeyRef or secretKeyRef"),
}
}
}

/// Where an [`AdditionalTrustBundle`] holds its certificates.
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum TrustBundleSource<'a> {
ConfigMap(&'a TrustBundleKeyRef),
Secret(&'a TrustBundleKeyRef),
}

/// A key in a ConfigMap or Secret.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize, JsonSchema)]
#[serde(rename_all = "camelCase")]
pub struct TrustBundleKeyRef {
/// The name of the ConfigMap or Secret.
pub name: String,
/// The key whose value holds the PEM-encoded certificates.
pub key: String,
}

pub mod v1alpha1 {
use super::*;

Expand Down Expand Up @@ -380,6 +429,16 @@ pub mod v1alpha1 {
/// }
/// ```
pub system_parameter_configmap_name: Option<String>,
/// PEM-encoded CA certificates that environmentd and clusterd trust for
/// outbound TLS connections, in addition to the CAs in their image.
/// Use this when an OIDC provider, a source, a sink, or object storage
/// presents a certificate signed by a private or self-signed CA.
///
/// environmentd and clusterd read the certificates when they start, so
/// changes to the contents of the ConfigMap or Secret take effect the
/// next time their pods restart.
#[serde(skip_serializing_if = "Option::is_none")]
pub additional_trust_bundle: Option<AdditionalTrustBundle>,

/// The configuration for generating an x509 certificate using cert-manager for balancerd
/// to present to incoming connections.
Expand Down Expand Up @@ -974,6 +1033,7 @@ pub mod v1alpha1 {
enable_rbac: value.spec.enable_rbac,
environment_id: value.spec.environment_id,
system_parameter_configmap_name: value.spec.system_parameter_configmap_name,
additional_trust_bundle: value.spec.additional_trust_bundle,
balancerd_external_certificate_spec: value
.spec
.balancerd_external_certificate_spec,
Expand Down Expand Up @@ -1211,6 +1271,12 @@ pub mod v1alpha1 {
with = "double_option",
skip_serializing_if = "Option::is_none"
)]
pub additional_trust_bundle: PartialField,
#[serde(
default,
with = "double_option",
skip_serializing_if = "Option::is_none"
)]
pub balancerd_external_certificate_spec: PartialField,
#[serde(
default,
Expand Down Expand Up @@ -1331,6 +1397,7 @@ pub mod v1alpha1 {
enable_rbac,
environment_id,
system_parameter_configmap_name,
additional_trust_bundle,
balancerd_external_certificate_spec,
console_external_certificate_spec,
internal_certificate_spec,
Expand Down Expand Up @@ -1370,6 +1437,7 @@ pub mod v1alpha1 {
enable_rbac: present(enable_rbac),
environment_id: present(environment_id),
system_parameter_configmap_name: present_opt(system_parameter_configmap_name),
additional_trust_bundle: present_opt(additional_trust_bundle),
balancerd_external_certificate_spec: present_opt(
balancerd_external_certificate_spec,
),
Expand Down Expand Up @@ -1458,6 +1526,7 @@ pub mod v1alpha1 {
enable_rbac,
environment_id,
system_parameter_configmap_name,
additional_trust_bundle,
balancerd_external_certificate_spec,
console_external_certificate_spec,
internal_certificate_spec,
Expand Down Expand Up @@ -1500,6 +1569,7 @@ pub mod v1alpha1 {
enable_rbac,
environment_id,
system_parameter_configmap_name,
additional_trust_bundle,
balancerd_external_certificate_spec,
console_external_certificate_spec,
internal_certificate_spec,
Expand Down Expand Up @@ -1742,6 +1812,16 @@ pub mod v1 {
/// }
/// ```
pub system_parameter_configmap_name: Option<String>,
/// PEM-encoded CA certificates that environmentd and clusterd trust for
/// outbound TLS connections, in addition to the CAs in their image.
/// Use this when an OIDC provider, a source, a sink, or object storage
/// presents a certificate signed by a private or self-signed CA.
///
/// environmentd and clusterd read the certificates when they start, so
/// changes to the contents of the ConfigMap or Secret take effect the
/// next time their pods restart.
#[serde(skip_serializing_if = "Option::is_none")]
pub additional_trust_bundle: Option<AdditionalTrustBundle>,

/// The configuration for generating an x509 certificate using cert-manager for balancerd
/// to present to incoming connections.
Expand Down Expand Up @@ -1807,6 +1887,7 @@ pub mod v1 {
enable_rbac: self.spec.enable_rbac,
environment_id: self.spec.environment_id,
system_parameter_configmap_name: self.spec.system_parameter_configmap_name.clone(),
additional_trust_bundle: self.spec.additional_trust_bundle.clone(),
balancerd_external_certificate_spec: None,
console_external_certificate_spec: None,
internal_certificate_spec: self.spec.internal_certificate_spec.clone(),
Expand Down Expand Up @@ -2293,6 +2374,7 @@ pub mod v1 {
enable_rbac: value.spec.enable_rbac,
environment_id: value.spec.environment_id,
system_parameter_configmap_name: value.spec.system_parameter_configmap_name,
additional_trust_bundle: value.spec.additional_trust_bundle,
balancerd_external_certificate_spec: value
.spec
.balancerd_external_certificate_spec,
Expand Down Expand Up @@ -2535,6 +2617,12 @@ pub mod v1 {
with = "double_option",
skip_serializing_if = "Option::is_none"
)]
pub additional_trust_bundle: PartialField,
#[serde(
default,
with = "double_option",
skip_serializing_if = "Option::is_none"
)]
pub balancerd_external_certificate_spec: PartialField,
#[serde(
default,
Expand Down Expand Up @@ -2646,6 +2734,7 @@ pub mod v1 {
enable_rbac,
environment_id,
system_parameter_configmap_name,
additional_trust_bundle,
balancerd_external_certificate_spec,
console_external_certificate_spec,
internal_certificate_spec,
Expand Down Expand Up @@ -2682,6 +2771,7 @@ pub mod v1 {
enable_rbac: present(enable_rbac),
environment_id: present(environment_id),
system_parameter_configmap_name: present_opt(system_parameter_configmap_name),
additional_trust_bundle: present_opt(additional_trust_bundle),
balancerd_external_certificate_spec: present_opt(
balancerd_external_certificate_spec,
),
Expand Down Expand Up @@ -2771,6 +2861,7 @@ pub mod v1 {
enable_rbac,
environment_id,
system_parameter_configmap_name,
additional_trust_bundle,
balancerd_external_certificate_spec,
console_external_certificate_spec,
internal_certificate_spec,
Expand Down Expand Up @@ -2816,6 +2907,7 @@ pub mod v1 {
enable_rbac,
environment_id,
system_parameter_configmap_name,
additional_trust_bundle,
balancerd_external_certificate_spec,
console_external_certificate_spec,
internal_certificate_spec,
Expand Down Expand Up @@ -3037,9 +3129,10 @@ mod tests {

use super::v1alpha1::{Materialize, MaterializeSpec, MaterializeStatus};
use super::{
DEFAULT_ROLLOUT_REQUEST_TIMEOUT, FORCE_ROLLOUT_ANNOTATION, InitialStatusAnnotations,
LAST_KNOWN_ACTIVE_GENERATION_ANNOTATION, LAST_KNOWN_RESOURCE_ID_ANNOTATION,
RolloutRequestTimeout,
AdditionalTrustBundle, DEFAULT_ROLLOUT_REQUEST_TIMEOUT, FORCE_ROLLOUT_ANNOTATION,
InitialStatusAnnotations, LAST_KNOWN_ACTIVE_GENERATION_ANNOTATION,
LAST_KNOWN_RESOURCE_ID_ANNOTATION, RolloutRequestTimeout, TrustBundleKeyRef,
TrustBundleSource,
};

#[mz_ore::test]
Expand Down Expand Up @@ -3325,6 +3418,86 @@ mod tests {
assert_eq!(super::convert_v1_to_v1alpha1(v1).unwrap(), subset);
}

#[mz_ore::test]
#[cfg_attr(miri, ignore)]
fn additional_trust_bundle_triggers_rollout_and_survives_conversion() {
let mut mz = super::v1::Materialize {
spec: super::v1::MaterializeSpec {
environmentd_image_ref: "materialize/environmentd:v26.0.0".to_owned(),
..Default::default()
},
metadata: ObjectMeta::default(),
status: None,
};
let hash = mz.generate_rollout_hash();
// Omitting the unset field preserves hashes calculated by older operators.
assert!(
serde_json::to_value(&mz.spec)
.unwrap()
.get("additionalTrustBundle")
.is_none()
);

mz.spec.additional_trust_bundle = Some(AdditionalTrustBundle {
config_map_key_ref: Some(TrustBundleKeyRef {
name: "private-ca".to_owned(),
key: "ca.crt".to_owned(),
}),
secret_key_ref: None,
});
assert_ne!(mz.generate_rollout_hash(), hash);

let alpha = Materialize::from(mz.clone());
assert_eq!(
alpha.spec.additional_trust_bundle,
mz.spec.additional_trust_bundle
);
assert_eq!(
super::v1::Materialize::from(alpha)
.spec
.additional_trust_bundle,
mz.spec.additional_trust_bundle
);

let key_ref = TrustBundleKeyRef {
name: "private-ca".to_owned(),
key: "ca.crt".to_owned(),
};
let both = AdditionalTrustBundle {
config_map_key_ref: Some(key_ref.clone()),
secret_key_ref: Some(key_ref.clone()),
};
assert!(both.source().is_err(), "both refs set must be rejected");
let neither = AdditionalTrustBundle {
config_map_key_ref: None,
secret_key_ref: None,
};
assert!(neither.source().is_err(), "no ref set must be rejected");
let secret = AdditionalTrustBundle {
config_map_key_ref: None,
secret_key_ref: Some(key_ref.clone()),
};
assert_eq!(
secret.source().unwrap(),
TrustBundleSource::Secret(&key_ref)
);

for value in [
serde_json::json!({"secretKeyRef": {"name": "private-ca", "key": "ca.crt"}}),
serde_json::Value::Null,
] {
let subset = serde_json::json!({
"apiVersion": "materialize.cloud/v1alpha1",
"kind": "Materialize",
"metadata": {"name": "mz"},
"spec": {"additionalTrustBundle": value},
});
let v1 = super::convert_v1alpha1_to_v1(subset.clone()).unwrap();
assert_eq!(v1["spec"]["additionalTrustBundle"], value);
assert_eq!(super::convert_v1_to_v1alpha1(v1).unwrap(), subset);
}
}

#[mz_ore::test]
fn meets_minimum_version() {
let mut mz = Materialize {
Expand Down
1 change: 1 addition & 0 deletions src/clusterd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ mz-service = { path = "../service" }
mz-storage = { path = "../storage" }
mz-storage-types = { path = "../storage-types" }
mz-timely-util = { path = "../timely-util" }
mz-tls-util = { path = "../tls-util" }
mz-txn-wal = { path = "../txn-wal" }
num_cpus.workspace = true
rustls.workspace = true
Expand Down
5 changes: 4 additions & 1 deletion src/clusterd/ci/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@ fi

# In Kubernetes, /tmp is an emptyDir private to this container that outlives
# its restarts. Remove SSH private keys left behind by a process killed
# mid-connect. The pattern matches ssh-util's `tempfile` key directories.
# mid-connect, and the CA bundle that every start with
# `--additional-trust-bundle` writes and keeps. The patterns match the
# `tempfile` names in ssh-util and tls-util.
if [ "${KUBERNETES_SERVICE_HOST:-}" ]; then
rm -rf /tmp/ssh-tunnel-key??????
rm -f /tmp/mz-trust-bundle-??????.pem
fi

if [ -z "${MZ_EAT_MY_DATA:-}" ]; then
Expand Down
Loading