-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathldap.rs
More file actions
127 lines (115 loc) · 4.21 KB
/
Copy pathldap.rs
File metadata and controls
127 lines (115 loc) · 4.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
use std::collections::BTreeMap;
use snafu::ResultExt;
use stackable_operator::{
builder::pod::{PodBuilder, container::ContainerBuilder},
crd::authentication::ldap,
};
use super::{
AddLdapVolumesSnafu, ConstructLdapEndpointUrlSnafu, Error, MissingLdapBindCredentialsSnafu,
};
use crate::crd::security::{STACKABLE_TLS_DIR, TLS_STORE_PASSWORD, add_cert_to_trust_store_cmd};
fn add_authenticator_config(
provider: &ldap::v1alpha1::AuthenticationProvider,
config: &mut BTreeMap<String, Option<String>>,
) -> Result<(), Error> {
config.insert(
"druid.auth.authenticator.Ldap.type".to_string(),
Some("basic".to_string()),
);
config.insert(
"druid.auth.authenticator.Ldap.enableCacheNotifications".to_string(),
Some("true".to_string()),
);
config.insert(
"druid.auth.authenticator.Ldap.credentialsValidator.type".to_string(),
Some("ldap".to_string()),
);
config.insert(
"druid.auth.authenticator.Ldap.credentialsValidator.url".to_string(),
Some(
provider
.endpoint_url()
.context(ConstructLdapEndpointUrlSnafu)?
.into(),
),
);
if let Some((ldap_bind_user_path, ldap_bind_password_path)) =
provider.bind_credentials_mount_paths()
{
config.insert(
"druid.auth.authenticator.Ldap.credentialsValidator.bindUser".to_string(),
Some(format!("${{file:UTF-8:{ldap_bind_user_path}}}").to_string()),
);
config.insert(
"druid.auth.authenticator.Ldap.credentialsValidator.bindPassword".to_string(),
Some(format!("${{file:UTF-8:{ldap_bind_password_path}}}").to_string()),
);
}
config.insert(
"druid.auth.authenticator.Ldap.credentialsValidator.baseDn".to_string(),
Some(provider.search_base.to_string()),
);
config.insert(
"druid.auth.authenticator.Ldap.credentialsValidator.userAttribute".to_string(),
Some(provider.ldap_field_names.uid.to_string()),
);
config.insert(
"druid.auth.authenticator.Ldap.credentialsValidator.userSearch".to_string(),
Some(provider.search_filter.to_string()),
);
config.insert(
"druid.auth.authenticator.Ldap.authorizerName".to_string(),
Some("LdapAuthorizer".to_string()),
);
config.insert(
"druid.auth.authenticatorChain".to_string(),
Some(r#"["DruidSystemAuthenticator", "Ldap"]"#.to_string()),
);
Ok(())
}
fn add_authorizer_config(config: &mut BTreeMap<String, Option<String>>) {
config.insert(
"druid.auth.authorizers".to_string(),
Some(r#"["LdapAuthorizer", "DruidSystemAuthorizer"]"#.to_string()),
);
config.insert(
"druid.auth.authorizer.LdapAuthorizer.type".to_string(),
Some(r#"allowAll"#.to_string()),
);
}
pub fn generate_runtime_properties_config(
provider: &ldap::v1alpha1::AuthenticationProvider,
config: &mut BTreeMap<String, Option<String>>,
) -> Result<(), Error> {
add_authenticator_config(provider, config)?;
add_authorizer_config(config);
Ok(())
}
pub fn prepare_container_commands(
provider: &ldap::v1alpha1::AuthenticationProvider,
command: &mut Vec<String>,
) {
if let Some(tls_ca_cert_mount_path) = provider.tls.tls_ca_cert_mount_path() {
command.extend(add_cert_to_trust_store_cmd(
&tls_ca_cert_mount_path,
STACKABLE_TLS_DIR,
TLS_STORE_PASSWORD,
))
}
}
pub fn add_volumes_and_mounts(
provider: &ldap::v1alpha1::AuthenticationProvider,
pb: &mut PodBuilder,
cb_druid: &mut ContainerBuilder,
cb_prepare: &mut ContainerBuilder,
) -> Result<(), Error> {
// TODO: Connecting to an LDAP server without bind credentials does not seem to be configurable in Druid at the moment
// see https://github.com/stackabletech/druid-operator/issues/383 for future work.
// Expect bind credentials to be provided for now, and throw return a useful error if there are none.
if provider.bind_credentials_mount_paths().is_none() {
return MissingLdapBindCredentialsSnafu.fail();
}
provider
.add_volumes_and_mounts(pb, vec![cb_druid, cb_prepare])
.context(AddLdapVolumesSnafu)
}