Skip to content

Commit ffa3c6a

Browse files
Felix Hennigfhennig
andcommitted
fix/ldap-secret-key-name (#362)
# Description This PR fixes the inconsistency of Trino with Superset and NiFi. While Superset and NiFi use "user" and "password" for the LDAP Secret keys, Trino just used it's environment variable names. Co-authored-by: Felix Hennig <fhennig@users.noreply.github.com>
1 parent cbe8413 commit ffa3c6a

3 files changed

Lines changed: 24 additions & 22 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ All notable changes to this project will be documented in this file.
1616
- `operator-rs` `0.25.0` -> `0.30.1` ([#344], [#360]).
1717
- LDAP integration tests create all resources in their namespace and not some in the default namespace ([#344]).
1818
- Don't run init container as root and avoid chmod and chowning ([#353]).
19-
- [BREAKING] Use Product image selection instead of version. `spec.version` has been replaced by `spec.image` ([#356]).
19+
- [BREAKING]: Use Product image selection instead of version. `spec.version` has been replaced by `spec.image` ([#356]).
2020
- [BREAKING]: Removed tools image for init container and replaced with Trino product image. This means the latest stackable version has to be used in the product image selection ([#357])
21+
- [BREAKING]: Use `user` and `password` Secret keys for LDAP bind credentials Secrets, instead of env var names ([#362])
2122

2223
### Fixed
2324

@@ -34,6 +35,7 @@ All notable changes to this project will be documented in this file.
3435
[#357]: https://github.com/stackabletech/trino-operator/pull/357
3536
[#358]: https://github.com/stackabletech/trino-operator/pull/358
3637
[#360]: https://github.com/stackabletech/trino-operator/pull/360
38+
[#362]: https://github.com/stackabletech/trino-operator/pull/362
3739

3840
## [0.8.0] - 2022-11-07
3941

rust/operator-binary/src/controller.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -647,29 +647,26 @@ fn build_rolegroup_statefulset(
647647
.collect::<Vec<_>>();
648648

649649
let secret_name = build_shared_internal_secret_name(trino);
650-
if let Some(internal_secret) = env_var_from_secret(&Some(secret_name), ENV_INTERNAL_SECRET) {
651-
env.push(internal_secret);
652-
};
650+
env.push(env_var_from_secret(&secret_name, None, ENV_INTERNAL_SECRET));
653651

654652
// we need to mount ldap bind credentials from the secret as env vars
655653
if let Some(auth) = authentication_config {
656654
match auth {
657655
TrinoAuthenticationConfig::MultiUser { .. } => {}
658656
TrinoAuthenticationConfig::Ldap(ldap) => {
659657
if let Some(ldap_bind_secret) = &ldap.bind_credentials {
660-
if let Some(ldap_user) = env_var_from_secret(
661-
&Some(ldap_bind_secret.secret_class.clone()),
658+
// LDAP user
659+
env.push(env_var_from_secret(
660+
&ldap_bind_secret.secret_class,
661+
Some("user"),
662662
LDAP_USER_ENV,
663-
) {
664-
env.push(ldap_user);
665-
}
666-
667-
if let Some(ldap_password) = env_var_from_secret(
668-
&Some(ldap_bind_secret.secret_class.clone()),
663+
));
664+
// LDAP password
665+
env.push(env_var_from_secret(
666+
&ldap_bind_secret.secret_class,
667+
Some("password"),
669668
LDAP_PASSWORD_ENV,
670-
) {
671-
env.push(ldap_password);
672-
}
669+
));
673670
}
674671
}
675672
}
@@ -863,19 +860,22 @@ async fn user_authentication(
863860
})
864861
}
865862

866-
fn env_var_from_secret(secret_name: &Option<String>, env_var: &str) -> Option<EnvVar> {
867-
secret_name.as_ref().map(|secret| EnvVar {
863+
/// Give a secret name and an optional key in the secret to use.
864+
/// The value from the key will be set into the given env var name.
865+
/// If not secret key is given, the env var name will be used as the secret key.
866+
fn env_var_from_secret(secret_name: &str, secret_key: Option<&str>, env_var: &str) -> EnvVar {
867+
EnvVar {
868868
name: env_var.to_string(),
869869
value_from: Some(EnvVarSource {
870870
secret_key_ref: Some(SecretKeySelector {
871871
optional: Some(false),
872-
name: Some(secret.to_string()),
873-
key: env_var.to_string(),
872+
name: Some(secret_name.to_string()),
873+
key: secret_key.unwrap_or(env_var).to_string(),
874874
}),
875875
..EnvVarSource::default()
876876
}),
877877
..EnvVar::default()
878-
})
878+
}
879879
}
880880

881881
/// Defines all required roles and their required configuration.

tests/templates/kuttl/ldap/12-install-trino.yaml.j2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ metadata:
66
labels:
77
secrets.stackable.tech/class: trino-with-ldap-bind
88
stringData:
9-
LDAP_USER: cn=admin,dc=example,dc=org
10-
LDAP_PASSWORD: admin
9+
user: cn=admin,dc=example,dc=org
10+
password: admin
1111
---
1212
apiVersion: trino.stackable.tech/v1alpha1
1313
kind: TrinoCluster

0 commit comments

Comments
 (0)