Skip to content

Commit 8cfb5f9

Browse files
committed
refactor: move security mode to controller, rename KafkaTlsSecurity -> ValidatedKafkaSecurity
1 parent ebcb5bc commit 8cfb5f9

10 files changed

Lines changed: 59 additions & 46 deletions

File tree

rust/operator-binary/src/controller.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ use strum::{EnumDiscriminants, IntoStaticStr};
4848
pub(crate) mod build;
4949
pub(crate) mod dereference;
5050
pub(crate) mod node_id_hasher;
51+
pub(crate) mod security;
5152
pub(crate) mod validate;
5253

5354
/// The type-safe role-group name from stackable-operator. Re-exported so the rest
@@ -69,12 +70,12 @@ use crate::{
6970
},
7071
},
7172
node_id_hasher::node_id_hash32_offset,
73+
security::ValidatedKafkaSecurity,
7274
},
7375
crd::{
7476
APP_NAME, KafkaClusterStatus, KafkaPodDescriptor, MetadataManager, OPERATOR_NAME,
7577
authorization::KafkaAuthorizationConfig,
7678
role::{AnyConfig, AnyConfigOverrides, KafkaRole},
77-
security::KafkaTlsSecurity,
7879
v1alpha1,
7980
},
8081
};
@@ -334,7 +335,7 @@ pub(crate) fn controller_name() -> ControllerName {
334335
/// Everything the build steps need is resolved here so they never have to read the
335336
/// raw [`v1alpha1::KafkaCluster`] spec.
336337
pub struct ValidatedClusterConfig {
337-
pub kafka_security: KafkaTlsSecurity,
338+
pub kafka_security: ValidatedKafkaSecurity,
338339
pub authorization_config: Option<KafkaAuthorizationConfig>,
339340
pub metadata_manager: MetadataManager,
340341

rust/operator-binary/src/controller/build/command.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ use stackable_operator::{
88
};
99

1010
use super::properties::ConfigFileName;
11-
use crate::crd::{
12-
BROKER_ID_POD_MAP_DIR, KafkaPodDescriptor, STACKABLE_CONFIG_DIR, STACKABLE_KERBEROS_KRB5_PATH,
13-
STACKABLE_LOG_CONFIG_DIR, security::KafkaTlsSecurity,
11+
use crate::{
12+
controller::security::ValidatedKafkaSecurity,
13+
crd::{
14+
BROKER_ID_POD_MAP_DIR, KafkaPodDescriptor, STACKABLE_CONFIG_DIR,
15+
STACKABLE_KERBEROS_KRB5_PATH, STACKABLE_LOG_CONFIG_DIR,
16+
},
1417
};
1518

1619
/// The JVM options selecting the Kafka log4j/log4j2 config file. Kafka 3.x uses log4j,
@@ -38,7 +41,7 @@ pub fn kafka_log_opts_env_var() -> String {
3841
pub fn broker_kafka_container_commands(
3942
kraft_mode: bool,
4043
controller_descriptors: Vec<KafkaPodDescriptor>,
41-
kafka_security: &KafkaTlsSecurity,
44+
kafka_security: &ValidatedKafkaSecurity,
4245
product_version: &str,
4346
) -> String {
4447
formatdoc! {"

rust/operator-binary/src/controller/build/kerberos.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@ use stackable_operator::{
1414
commons::secret_class::SecretClassVolumeProvisionParts,
1515
};
1616

17-
use crate::crd::{
18-
LISTENER_BOOTSTRAP_VOLUME_NAME, LISTENER_BROKER_VOLUME_NAME, STACKABLE_KERBEROS_DIR,
19-
STACKABLE_KERBEROS_KRB5_PATH, role::KafkaRole, security::KafkaTlsSecurity,
17+
use crate::{
18+
controller::security::ValidatedKafkaSecurity,
19+
crd::{
20+
LISTENER_BOOTSTRAP_VOLUME_NAME, LISTENER_BROKER_VOLUME_NAME, STACKABLE_KERBEROS_DIR,
21+
STACKABLE_KERBEROS_KRB5_PATH, role::KafkaRole,
22+
},
2023
};
2124

2225
#[derive(Snafu, Debug)]
@@ -36,7 +39,7 @@ pub enum Error {
3639
}
3740

3841
pub fn add_kerberos_pod_config(
39-
kafka_security: &KafkaTlsSecurity,
42+
kafka_security: &ValidatedKafkaSecurity,
4043
role: &KafkaRole,
4144
cb_kcat_prober: &mut ContainerBuilder,
4245
cb_kafka: &mut ContainerBuilder,

rust/operator-binary/src/controller/build/properties/listener.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,20 @@ use stackable_operator::{
1111
};
1212

1313
use crate::{
14-
controller::{RoleGroupName, ValidatedCluster},
14+
controller::{RoleGroupName, ValidatedCluster, security::ValidatedKafkaSecurity},
1515
crd::{
1616
STACKABLE_LISTENER_BROKER_DIR,
1717
listener::{
1818
KafkaListener, KafkaListenerConfig, KafkaListenerName, KafkaListenerProtocol,
1919
LISTENER_LOCAL_ADDRESS, node_address_cmd, node_port_cmd,
2020
},
2121
role::KafkaRole,
22-
security::KafkaTlsSecurity,
2322
},
2423
};
2524

2625
pub fn get_kafka_listener_config(
2726
validated_cluster: &ValidatedCluster,
28-
kafka_security: &KafkaTlsSecurity,
27+
kafka_security: &ValidatedKafkaSecurity,
2928
role: &KafkaRole,
3029
role_group_name: &RoleGroupName,
3130
cluster_info: &KubernetesClusterInfo,
@@ -49,7 +48,7 @@ pub fn get_kafka_listener_config(
4948
listeners.push(KafkaListener {
5049
name: KafkaListenerName::Client,
5150
host: LISTENER_LOCAL_ADDRESS.to_string(),
52-
port: KafkaTlsSecurity::SECURE_CLIENT_PORT.to_string(),
51+
port: ValidatedKafkaSecurity::SECURE_CLIENT_PORT.to_string(),
5352
});
5453
advertised_listeners.push(KafkaListener {
5554
name: KafkaListenerName::Client,
@@ -85,7 +84,7 @@ pub fn get_kafka_listener_config(
8584
listeners.push(KafkaListener {
8685
name: KafkaListenerName::Client,
8786
host: LISTENER_LOCAL_ADDRESS.to_string(),
88-
port: KafkaTlsSecurity::CLIENT_PORT.to_string(),
87+
port: ValidatedKafkaSecurity::CLIENT_PORT.to_string(),
8988
});
9089
advertised_listeners.push(KafkaListener {
9190
name: KafkaListenerName::Client,
@@ -106,12 +105,12 @@ pub fn get_kafka_listener_config(
106105
listeners.push(KafkaListener {
107106
name: KafkaListenerName::Internal,
108107
host: LISTENER_LOCAL_ADDRESS.to_string(),
109-
port: KafkaTlsSecurity::SECURE_INTERNAL_PORT.to_string(),
108+
port: ValidatedKafkaSecurity::SECURE_INTERNAL_PORT.to_string(),
110109
});
111110
advertised_listeners.push(KafkaListener {
112111
name: KafkaListenerName::Internal,
113112
host: pod_fqdn.to_string(),
114-
port: KafkaTlsSecurity::SECURE_INTERNAL_PORT.to_string(),
113+
port: ValidatedKafkaSecurity::SECURE_INTERNAL_PORT.to_string(),
115114
});
116115
listener_security_protocol_map
117116
.insert(KafkaListenerName::Internal, KafkaListenerProtocol::Ssl);
@@ -220,7 +219,7 @@ mod tests {
220219
"#;
221220
let kafka = minimal_kafka(kafka_cluster);
222221
let validated = validated_cluster(&kafka);
223-
let kafka_security = KafkaTlsSecurity::new(
222+
let kafka_security = ValidatedKafkaSecurity::new(
224223
ResolvedAuthenticationClasses::new(vec![core::v1alpha1::AuthenticationClass {
225224
metadata: ObjectMetaBuilder::new().name("auth-class").build(),
226225
spec: core::v1alpha1::AuthenticationClassSpec {
@@ -294,7 +293,7 @@ mod tests {
294293
)
295294
);
296295

297-
let kafka_security = KafkaTlsSecurity::new(
296+
let kafka_security = ValidatedKafkaSecurity::new(
298297
ResolvedAuthenticationClasses::new(vec![]),
299298
Some("tls".parse().unwrap()),
300299
Some("tls".parse().unwrap()),
@@ -357,8 +356,12 @@ mod tests {
357356
)
358357
);
359358

360-
let kafka_security =
361-
KafkaTlsSecurity::new(ResolvedAuthenticationClasses::new(vec![]), None, None, None);
359+
let kafka_security = ValidatedKafkaSecurity::new(
360+
ResolvedAuthenticationClasses::new(vec![]),
361+
None,
362+
None,
363+
None,
364+
);
362365

363366
let config = get_kafka_listener_config(
364367
&validated,
@@ -441,7 +444,7 @@ mod tests {
441444
"#;
442445
let kafka = minimal_kafka(kafka_cluster);
443446
let validated = validated_cluster(&kafka);
444-
let kafka_security = KafkaTlsSecurity::new(
447+
let kafka_security = ValidatedKafkaSecurity::new(
445448
ResolvedAuthenticationClasses::new(vec![core::v1alpha1::AuthenticationClass {
446449
metadata: ObjectMetaBuilder::new().name("auth-class").build(),
447450
spec: core::v1alpha1::AuthenticationClassSpec {

rust/operator-binary/src/controller/build/resource/listener.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,8 @@ use stackable_operator::{
44
};
55

66
use crate::{
7-
controller::{RoleGroupName, ValidatedCluster},
8-
crd::{
9-
role::{KafkaRole, broker::BrokerConfig},
10-
security::KafkaTlsSecurity,
11-
},
7+
controller::{RoleGroupName, ValidatedCluster, security::ValidatedKafkaSecurity},
8+
crd::role::{KafkaRole, broker::BrokerConfig},
129
};
1310

1411
/// Kafka clients will use the load-balanced bootstrap listener to get a list of broker addresses and will use those to
@@ -43,7 +40,7 @@ pub fn build_broker_rolegroup_bootstrap_listener(
4340
}
4441

4542
fn bootstrap_listener_ports(
46-
kafka_security: &KafkaTlsSecurity,
43+
kafka_security: &ValidatedKafkaSecurity,
4744
) -> Vec<listener::v1alpha1::ListenerPort> {
4845
vec![if kafka_security.has_kerberos_enabled() {
4946
listener::v1alpha1::ListenerPort {

rust/operator-binary/src/controller/build/resource/service.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use stackable_operator::{
66
};
77

88
use crate::{
9-
controller::{RoleGroupName, ValidatedCluster},
10-
crd::{METRICS_PORT, METRICS_PORT_NAME, role::KafkaRole, security::KafkaTlsSecurity},
9+
controller::{RoleGroupName, ValidatedCluster, security::ValidatedKafkaSecurity},
10+
crd::{METRICS_PORT, METRICS_PORT_NAME, role::KafkaRole},
1111
};
1212

1313
/// The rolegroup [`Service`] is a headless service that allows direct access to the instances of a certain rolegroup
@@ -17,7 +17,7 @@ pub fn build_rolegroup_headless_service(
1717
validated_cluster: &ValidatedCluster,
1818
role: &KafkaRole,
1919
role_group_name: &RoleGroupName,
20-
kafka_security: &KafkaTlsSecurity,
20+
kafka_security: &ValidatedKafkaSecurity,
2121
) -> Service {
2222
Service {
2323
metadata: ObjectMetaBuilder::new()
@@ -100,7 +100,7 @@ fn metrics_ports() -> Vec<ServicePort> {
100100
}]
101101
}
102102

103-
fn headless_ports(kafka_security: &KafkaTlsSecurity) -> Vec<ServicePort> {
103+
fn headless_ports(kafka_security: &ValidatedKafkaSecurity) -> Vec<ServicePort> {
104104
vec![ServicePort {
105105
name: Some(kafka_security.client_port_name().into()),
106106
port: kafka_security.client_port().into(),

rust/operator-binary/src/controller/build/resource/statefulset.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ use crate::{
5555
properties::product_logging::MAX_KAFKA_LOG_FILES_SIZE,
5656
},
5757
node_id_hasher::node_id_hash32_offset,
58+
security::ValidatedKafkaSecurity,
5859
validate::ValidatedLogging,
5960
},
6061
crd::{
@@ -67,7 +68,6 @@ use crate::{
6768
AnyConfig, KAFKA_NODE_ID_OFFSET, KafkaRole, broker::BrokerContainer,
6869
controller::ControllerContainer,
6970
},
70-
security::KafkaTlsSecurity,
7171
},
7272
};
7373

@@ -90,7 +90,9 @@ pub enum Error {
9090
},
9191

9292
#[snafu(display("failed to add Secret Volumes and VolumeMounts"))]
93-
AddVolumesAndVolumeMounts { source: crate::crd::security::Error },
93+
AddVolumesAndVolumeMounts {
94+
source: crate::controller::security::Error,
95+
},
9496

9597
#[snafu(display("failed to add needed volumeMount"))]
9698
AddVolumeMount {
@@ -643,7 +645,7 @@ pub fn build_controller_rolegroup_statefulset(
643645
}
644646

645647
/// We only expose client HTTP / HTTPS and Metrics ports.
646-
fn container_ports(kafka_security: &KafkaTlsSecurity) -> Vec<ContainerPort> {
648+
fn container_ports(kafka_security: &ValidatedKafkaSecurity) -> Vec<ContainerPort> {
647649
let mut ports = vec![
648650
ContainerPort {
649651
name: Some(METRICS_PORT_NAME.to_string()),

rust/operator-binary/src/crd/security.rs renamed to rust/operator-binary/src/controller/security.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@ use stackable_operator::{
2323
v2::types::{common::Port, kubernetes::SecretClassName},
2424
};
2525

26-
use super::listener::KafkaListenerProtocol;
2726
use crate::crd::{
2827
LISTENER_BOOTSTRAP_VOLUME_NAME, LISTENER_BROKER_VOLUME_NAME, STACKABLE_KERBEROS_KRB5_PATH,
2928
STACKABLE_LISTENER_BROKER_DIR,
3029
authentication::ResolvedAuthenticationClasses,
31-
listener::{self, KafkaListenerName, node_address_cmd_env, node_port_cmd_env},
30+
listener::{
31+
self, KafkaListenerName, KafkaListenerProtocol, node_address_cmd_env, node_port_cmd_env,
32+
},
3233
role::KafkaRole,
3334
tls, v1alpha1,
3435
};
@@ -58,14 +59,14 @@ pub enum Error {
5859
}
5960

6061
/// Helper struct combining TLS settings for server and internal with the resolved AuthenticationClasses
61-
pub struct KafkaTlsSecurity {
62+
pub struct ValidatedKafkaSecurity {
6263
resolved_authentication_classes: ResolvedAuthenticationClasses,
6364
internal_secret_class: Option<SecretClassName>,
6465
server_secret_class: Option<SecretClassName>,
6566
opa_secret_class: Option<SecretClassName>,
6667
}
6768

68-
impl KafkaTlsSecurity {
69+
impl ValidatedKafkaSecurity {
6970
pub const BOOTSTRAP_PORT: Port = Port(9094);
7071
// bootstrap: we will have a single named port with different values for
7172
// secure (9095) and insecure (9094). The bootstrap listener is needed to
@@ -114,7 +115,7 @@ impl KafkaTlsSecurity {
114115
}
115116
}
116117

117-
/// Build a [`KafkaTlsSecurity`] from already-resolved authentication classes.
118+
/// Build a [`ValidatedKafkaSecurity`] from already-resolved authentication classes.
118119
///
119120
/// The async retrieval of [`ResolvedAuthenticationClasses`] now happens in the dereference
120121
/// step of the controller; this constructor only reads TLS settings from the spec.
@@ -123,7 +124,7 @@ impl KafkaTlsSecurity {
123124
resolved_authentication_classes: ResolvedAuthenticationClasses,
124125
opa_secret_class: Option<SecretClassName>,
125126
) -> Self {
126-
KafkaTlsSecurity {
127+
ValidatedKafkaSecurity {
127128
resolved_authentication_classes,
128129
internal_secret_class: kafka
129130
.spec

rust/operator-binary/src/controller/validate.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ use stackable_operator::{
3030
use crate::{
3131
controller::{
3232
RoleGroupName, ValidatedCluster, ValidatedClusterConfig, ValidatedRoleConfig,
33-
ValidatedRoleGroupConfig, dereference::DereferencedObjects,
33+
ValidatedRoleGroupConfig,
34+
dereference::DereferencedObjects,
35+
security::{self, ValidatedKafkaSecurity},
3436
},
3537
crd::{
3638
self, CONTAINER_IMAGE_BASE_NAME,
@@ -40,7 +42,6 @@ use crate::{
4042
broker::{BrokerConfig, BrokerContainer},
4143
controller::{ControllerConfig, ControllerContainer},
4244
},
43-
security::{self, KafkaTlsSecurity},
4445
v1alpha1,
4546
},
4647
};
@@ -210,8 +211,11 @@ pub fn validate(
210211
.as_ref()
211212
.and_then(|cfg| cfg.secret_class.clone());
212213

213-
let kafka_security =
214-
KafkaTlsSecurity::new_from_kafka_cluster(kafka, authentication_classes, opa_secret_class);
214+
let kafka_security = ValidatedKafkaSecurity::new_from_kafka_cluster(
215+
kafka,
216+
authentication_classes,
217+
opa_secret_class,
218+
);
215219

216220
kafka_security
217221
.validate_authentication_methods()

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ pub mod authentication;
33
pub mod authorization;
44
pub mod listener;
55
pub mod role;
6-
pub mod security;
76
pub mod tls;
87

98
use authentication::KafkaAuthentication;

0 commit comments

Comments
 (0)