Skip to content

Commit f000b9f

Browse files
committed
refactor: consolidate authentication build
1 parent 35e66ab commit f000b9f

5 files changed

Lines changed: 19 additions & 11 deletions

File tree

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ type Result<T, E = Error> = std::result::Result<T, E>;
8080
/// may be in parts reused in other operators.
8181
#[derive(Clone, Debug, Default)]
8282
pub struct TrinoAuthenticationConfig {
83+
/// The enabled `http-server.authentication.type` values, in evaluation order. Empty when no
84+
/// authentication is configured.
85+
authentication_types: Vec<String>,
8386
/// All config properties that have to be added to the `config.properties` of the given role
8487
config_properties: HashMap<TrinoRole, BTreeMap<String, String>>,
8588
/// All extra config files required for authentication for each role.
@@ -136,6 +139,7 @@ impl TrinoAuthenticationConfig {
136139
http_server_authentication_types.join(","),
137140
);
138141
}
142+
authentication_config.authentication_types = http_server_authentication_types;
139143

140144
trace!(
141145
"Final Trino authentication config: {:?}",
@@ -145,6 +149,11 @@ impl TrinoAuthenticationConfig {
145149
Ok(authentication_config)
146150
}
147151

152+
/// Whether no authentication is configured.
153+
pub fn is_empty(&self) -> bool {
154+
self.authentication_types.is_empty()
155+
}
156+
148157
/// Automatically add volumes, volume mounts, commands and containers to
149158
/// the respective pod / container builders.
150159
pub fn add_authentication_pod_and_volume_config(

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ pub fn build(
134134
// authentication-requires-TLS check.
135135
let server_tls_enabled = cluster.cluster_config.tls.server.is_some();
136136
let internal_tls_enabled = cluster.cluster_config.tls.internal.is_some();
137-
if cluster.cluster_config.authentication_enabled && !server_tls_enabled {
137+
if cluster.cluster_config.authentication_enabled() && !server_tls_enabled {
138138
return Err(Error::AuthenticationRequiresTls);
139139
}
140140
if server_tls_enabled || internal_tls_enabled {

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,20 @@ pub struct ValidatedTls {
6060
pub struct ValidatedClusterConfig {
6161
pub tls: ValidatedTls,
6262
pub authentication: TrinoAuthenticationConfig,
63-
pub authentication_enabled: bool,
6463
pub authorization: Option<TrinoOpaConfig>,
6564
pub fault_tolerant_execution: Option<ResolvedFaultTolerantExecutionConfig>,
6665
pub client_protocol: Option<ResolvedClientProtocolConfig>,
6766
pub coordinator_pod_refs: Vec<TrinoPodRef>,
6867
pub catalogs: Vec<CatalogConfig>,
6968
}
7069

70+
impl ValidatedClusterConfig {
71+
/// Whether any authentication is configured.
72+
pub fn authentication_enabled(&self) -> bool {
73+
!self.authentication.is_empty()
74+
}
75+
}
76+
7177
/// A validated, merged Trino role-group config.
7278
///
7379
/// Holds the merged [`v1alpha1::TrinoConfig`] fields so the build steps consume this
@@ -184,7 +190,7 @@ impl ValidatedCluster {
184190

185191
/// Whether client TLS should be set, depending on authentication and server TLS settings.
186192
pub fn tls_enabled(&self) -> bool {
187-
self.cluster_config.authentication_enabled || self.server_tls_enabled()
193+
self.cluster_config.authentication_enabled() || self.server_tls_enabled()
188194
}
189195

190196
/// The client-facing port Trino exposes: HTTPS when server TLS is enabled, otherwise HTTP.

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,6 @@ pub fn validate(
266266
internal: tls.internal_secret_class.as_ref().map(ToString::to_string),
267267
},
268268
authentication,
269-
authentication_enabled: trino.authentication_enabled(),
270269
authorization: dereferenced_objects.trino_opa_config.clone(),
271270
fault_tolerant_execution: dereferenced_objects.resolved_fte_config.clone(),
272271
client_protocol: dereferenced_objects.resolved_client_protocol_config.clone(),
@@ -366,7 +365,7 @@ mod tests {
366365
"e6ac237d-a6d4-43a1-8135-f36506110912"
367366
);
368367
assert_eq!(validated.product_version, 479);
369-
assert!(!validated.cluster_config.authentication_enabled);
368+
assert!(!validated.cluster_config.authentication_enabled());
370369
assert!(
371370
validated
372371
.role_group_configs

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -568,12 +568,6 @@ impl v1alpha1::TrinoCluster {
568568
&self.spec.cluster_config.authentication
569569
}
570570

571-
/// Check if any authentication settings are provided
572-
pub fn authentication_enabled(&self) -> bool {
573-
let spec: &v1alpha1::TrinoClusterSpec = &self.spec;
574-
!spec.cluster_config.authentication.is_empty()
575-
}
576-
577571
pub fn get_opa_config(&self) -> Option<&v1alpha1::TrinoAuthorizationOpaConfig> {
578572
self.spec
579573
.cluster_config

0 commit comments

Comments
 (0)