-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathkerberos.rs
More file actions
308 lines (283 loc) · 11 KB
/
kerberos.rs
File metadata and controls
308 lines (283 loc) · 11 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
use std::collections::BTreeMap;
use snafu::{OptionExt, ResultExt, Snafu};
use stackable_operator::{
builder::{
self,
pod::{
PodBuilder,
container::ContainerBuilder,
volume::{SecretFormat, SecretOperatorVolumeSourceBuilder, VolumeBuilder},
},
},
kube::{ResourceExt, runtime::reflector::ObjectRef},
time::Duration,
utils::cluster_info::KubernetesClusterInfo,
};
use crate::crd::{TLS_STORE_DIR, TLS_STORE_PASSWORD, TLS_STORE_VOLUME_NAME, v1alpha1};
#[derive(Snafu, Debug)]
pub enum Error {
#[snafu(display("object {hbase} is missing namespace"))]
ObjectMissingNamespace {
hbase: ObjectRef<v1alpha1::HbaseCluster>,
},
#[snafu(display("failed to add Kerberos secret volume"))]
AddKerberosSecretVolume {
source: stackable_operator::builder::pod::volume::SecretOperatorVolumeSourceBuilderError,
},
#[snafu(display("failed to add TLS secret volume"))]
AddTlsSecretVolume {
source: stackable_operator::builder::pod::volume::SecretOperatorVolumeSourceBuilderError,
},
#[snafu(display("failed to add needed volume"))]
AddVolume { source: builder::pod::Error },
#[snafu(display("failed to add needed volumeMount"))]
AddVolumeMount {
source: builder::pod::container::Error,
},
}
pub fn kerberos_config_properties(
hbase: &v1alpha1::HbaseCluster,
cluster_info: &KubernetesClusterInfo,
) -> Result<BTreeMap<String, String>, Error> {
if !hbase.has_kerberos_enabled() {
return Ok(BTreeMap::new());
}
let principal_host_part = principal_host_part(hbase, cluster_info)?;
Ok(BTreeMap::from([
// Kerberos settings
(
"hbase.security.authentication".to_string(),
"kerberos".to_string(),
),
(
"hbase.security.authorization".to_string(),
"true".to_string(),
),
("hbase.rpc.protection".to_string(), "privacy".to_string()),
(
"dfs.data.transfer.protection".to_string(),
"privacy".to_string(),
),
(
"hbase.rpc.engine".to_string(),
"org.apache.hadoop.hbase.ipc.SecureRpcEngine".to_string(),
),
(
"hbase.master.kerberos.principal".to_string(),
format!(
"{service_name}/{principal_host_part}",
service_name = kerberos_service_name()
),
),
(
"hbase.regionserver.kerberos.principal".to_string(),
format!(
"{service_name}/{principal_host_part}",
service_name = kerberos_service_name()
),
),
(
"hbase.rest.kerberos.principal".to_string(),
format!(
"{service_name}/{principal_host_part}",
service_name = kerberos_service_name()
),
),
(
"hbase.master.keytab.file".to_string(),
"/stackable/kerberos/keytab".to_string(),
),
(
"hbase.regionserver.keytab.file".to_string(),
"/stackable/kerberos/keytab".to_string(),
),
(
"hbase.rest.keytab.file".to_string(),
"/stackable/kerberos/keytab".to_string(),
),
(
"hbase.coprocessor.master.classes".to_string(),
"org.apache.hadoop.hbase.security.access.AccessController".to_string(),
),
(
"hbase.coprocessor.region.classes".to_string(),
"org.apache.hadoop.hbase.security.token.TokenProvider,org.apache.hadoop.hbase.security.access.AccessController".to_string(),
),
// Rest server
("hbase.rest.authentication.type".to_string(), "kerberos".to_string()),
("hbase.rest.authentication.kerberos.principal".to_string(), format!(
"HTTP/{principal_host_part}"
)),
("hbase.rest.authentication.kerberos.keytab".to_string(), "/stackable/kerberos/keytab".to_string()),
// Enabled https as well
("hbase.ssl.enabled".to_string(), "true".to_string()),
("hbase.http.policy".to_string(), "HTTPS_ONLY".to_string()),
// Recommended by the docs https://hbase.apache.org/book.html#hbase.ui.cache
("hbase.http.filter.no-store.enable".to_string(), "true".to_string()),
// Ḱey- and truststore come from ssl-server.xml and ssl-client.xml
// Https for rest server
("hbase.rest.ssl.enabled".to_string(), "true".to_string()),
("hbase.rest.ssl.keystore.store".to_string(), format!("{TLS_STORE_DIR}/keystore.p12")),
("hbase.rest.ssl.keystore.password".to_string(), TLS_STORE_PASSWORD.to_string()),
("hbase.rest.ssl.keystore.type".to_string(), "pkcs12".to_string()),
]))
}
pub fn kerberos_discovery_config_properties(
hbase: &v1alpha1::HbaseCluster,
cluster_info: &KubernetesClusterInfo,
) -> Result<BTreeMap<String, String>, Error> {
if !hbase.has_kerberos_enabled() {
return Ok(BTreeMap::new());
}
let principal_host_part = principal_host_part(hbase, cluster_info)?;
Ok(BTreeMap::from([
(
"hbase.security.authentication".to_string(),
"kerberos".to_string(),
),
("hbase.rpc.protection".to_string(), "privacy".to_string()),
("hbase.ssl.enabled".to_string(), "true".to_string()),
(
"hbase.master.kerberos.principal".to_string(),
format!(
"{service_name}/{principal_host_part}",
service_name = kerberos_service_name()
),
),
(
"hbase.regionserver.kerberos.principal".to_string(),
format!(
"{service_name}/{principal_host_part}",
service_name = kerberos_service_name()
),
),
(
"hbase.rest.kerberos.principal".to_string(),
format!(
"{service_name}/{principal_host_part}",
service_name = kerberos_service_name()
),
),
]))
}
pub fn kerberos_ssl_server_settings(hbase: &v1alpha1::HbaseCluster) -> BTreeMap<String, String> {
if !hbase.has_https_enabled() {
return BTreeMap::new();
}
BTreeMap::from([
(
"ssl.server.truststore.location".to_string(),
format!("{TLS_STORE_DIR}/truststore.p12"),
),
(
"ssl.server.truststore.type".to_string(),
"pkcs12".to_string(),
),
(
"ssl.server.truststore.password".to_string(),
TLS_STORE_PASSWORD.to_string(),
),
(
"ssl.server.keystore.location".to_string(),
format!("{TLS_STORE_DIR}/keystore.p12"),
),
("ssl.server.keystore.type".to_string(), "pkcs12".to_string()),
(
"ssl.server.keystore.password".to_string(),
TLS_STORE_PASSWORD.to_string(),
),
])
}
pub fn kerberos_ssl_client_settings(hbase: &v1alpha1::HbaseCluster) -> BTreeMap<String, String> {
if !hbase.has_https_enabled() {
return BTreeMap::new();
}
BTreeMap::from([
(
"ssl.client.truststore.location".to_string(),
format!("{TLS_STORE_DIR}/truststore.p12"),
),
(
"ssl.client.truststore.type".to_string(),
"pkcs12".to_string(),
),
(
"ssl.client.truststore.password".to_string(),
TLS_STORE_PASSWORD.to_string(),
),
])
}
pub fn add_kerberos_pod_config(
hbase: &v1alpha1::HbaseCluster,
cb: &mut ContainerBuilder,
pb: &mut PodBuilder,
requested_secret_lifetime: Duration,
) -> Result<(), Error> {
if let Some(kerberos_secret_class) = hbase.kerberos_secret_class() {
// Mount keytab
let kerberos_secret_operator_volume =
SecretOperatorVolumeSourceBuilder::new(kerberos_secret_class)
.with_service_scope(hbase.name_any())
.with_kerberos_service_name(kerberos_service_name())
.with_kerberos_service_name("HTTP")
.build()
.context(AddKerberosSecretVolumeSnafu)?;
pb.add_volume(
VolumeBuilder::new("kerberos")
.ephemeral(kerberos_secret_operator_volume)
.build(),
)
.context(AddVolumeSnafu)?;
cb.add_volume_mount("kerberos", "/stackable/kerberos")
.context(AddVolumeMountSnafu)?;
// Needed env vars
cb.add_env_var("KRB5_CONFIG", "/stackable/kerberos/krb5.conf");
}
if let Some(https_secret_class) = hbase.https_secret_class() {
// Mount TLS keystore
pb.add_volume(
VolumeBuilder::new(TLS_STORE_VOLUME_NAME)
.ephemeral(
SecretOperatorVolumeSourceBuilder::new(https_secret_class)
.with_pod_scope()
.with_node_scope()
.with_format(SecretFormat::TlsPkcs12)
.with_tls_pkcs12_password(TLS_STORE_PASSWORD)
.with_auto_tls_cert_lifetime(requested_secret_lifetime)
.build()
.context(AddTlsSecretVolumeSnafu)?,
)
.build(),
)
.context(AddVolumeSnafu)?;
cb.add_volume_mount(TLS_STORE_VOLUME_NAME, TLS_STORE_DIR)
.context(AddVolumeMountSnafu)?;
}
Ok(())
}
fn principal_host_part(
hbase: &v1alpha1::HbaseCluster,
cluster_info: &KubernetesClusterInfo,
) -> Result<String, Error> {
let hbase_name = hbase.name_any();
let hbase_namespace = hbase.namespace().context(ObjectMissingNamespaceSnafu {
hbase: ObjectRef::from_obj(hbase),
})?;
let cluster_domain = &cluster_info.cluster_domain;
Ok(format!(
"{hbase_name}.{hbase_namespace}.svc.{cluster_domain}@${{env.KERBEROS_REALM}}"
))
}
/// We could have different service names depended on the role (e.g. "hbase-master", "hbase-regionserver" and
/// "hbase-restserver"). However this produces error messages such as
/// [RpcServer.priority.RWQ.Fifo.write.handler=0,queue=0,port=16020] security.ShellBasedUnixGroupsMapping: unable to return groups for user hbase-master PartialGroupNameException The user name 'hbase-master' is not found. id: 'hbase-master': no such user
/// or
/// Caused by: org.apache.hadoop.hbase.ipc.RemoteWithExtrasException(org.apache.hadoop.hbase.security.AccessDeniedException): org.apache.hadoop.hbase.security.AccessDeniedException: Insufficient permissions (user=hbase-master/hbase-master-default-1.hbase-master-default.kuttl-test-poetic-sunbeam.svc.cluster.local@CLUSTER.LOCAL, scope=hbase:meta, family=table:state, params=[table=hbase:meta,family=table:state],action=WRITE)
///
/// Also the documentation states:
/// > A Kerberos principal has three parts, with the form username/fully.qualified.domain.name@YOUR-REALM.COM. We recommend using hbase as the username portion.
///
/// As a result we use "hbase" everywhere (which e.g. differs from the current hdfs implementation)
fn kerberos_service_name() -> &'static str {
"hbase"
}