Skip to content

Commit 2eb3f97

Browse files
adwk67maltesander
andauthored
fix: move metastore db credentials into a secret (#452)
* fix: move metastore db credentials into a secret * changelog * changed references in documentation/examples * changelog * Update rust/operator-binary/src/controller.rs Co-authored-by: Malte Sander <[email protected]> * Update CHANGELOG.md Co-authored-by: Malte Sander <[email protected]> * consistent ordering --------- Co-authored-by: Malte Sander <[email protected]>
1 parent 114bc0c commit 2eb3f97

25 files changed

+227
-66
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ All notable changes to this project will be documented in this file.
88

99
- Added documentation/tutorial on using external database drivers ([#449]).
1010

11+
### Fixed
12+
13+
- [BREAKING] Move the metastore `user` and `password` DB credentials out of the CRD into a Secret containing the keys `username` and `password` ([#452]).
14+
1115
### Changed
1216

1317
- BREAKING: Switch to new image that only contains HMS.
@@ -17,6 +21,7 @@ All notable changes to this project will be documented in this file.
1721

1822
[#447]: https://github.com/stackabletech/hive-operator/pull/447
1923
[#449]: https://github.com/stackabletech/hive-operator/pull/449
24+
[#452]: https://github.com/stackabletech/hive-operator/pull/452
2025

2126
## [24.3.0] - 2024-03-20
2227

deploy/helm/hive-operator/crds/crds.yaml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ spec:
5050
connString:
5151
description: 'A connection string for the database. For example: `jdbc:postgresql://hivehdfs-postgresql:5432/hivehdfs`'
5252
type: string
53+
credentialsSecret:
54+
description: A reference to a Secret containing the database credentials. The Secret needs to contain the keys `username` and `password`.
55+
type: string
5356
dbType:
5457
description: 'The type of database to connect to. Supported are: `postgres`, `mysql`, `oracle`, `mssql` and `derby`. This value is used to configure the jdbc driver class.'
5558
enum:
@@ -59,17 +62,10 @@ spec:
5962
- oracle
6063
- mssql
6164
type: string
62-
password:
63-
description: The password for the database user.
64-
type: string
65-
user:
66-
description: The database user.
67-
type: string
6865
required:
6966
- connString
67+
- credentialsSecret
7068
- dbType
71-
- password
72-
- user
7369
type: object
7470
hdfs:
7571
description: HDFS connection specification.

docs/modules/hive/examples/getting_started/hive-postgres-s3.yaml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,20 @@ spec:
99
clusterConfig:
1010
database:
1111
connString: jdbc:postgresql://postgresql:5432/hive
12-
user: hive
13-
password: hive
12+
credentialsSecret: hive-credentials
1413
dbType: postgres
1514
s3:
1615
reference: minio
1716
metastore:
1817
roleGroups:
1918
default:
2019
replicas: 1
20+
---
21+
apiVersion: v1
22+
kind: Secret
23+
metadata:
24+
name: hive-credentials
25+
type: Opaque
26+
stringData:
27+
username: hive
28+
password: hive

docs/modules/hive/examples/getting_started/hive-postgres-s3.yaml.j2

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,20 @@ spec:
99
clusterConfig:
1010
database:
1111
connString: jdbc:postgresql://postgresql:5432/hive
12-
user: hive
13-
password: hive
12+
credentialsSecret: hive-credentials
1413
dbType: postgres
1514
s3:
1615
reference: minio
1716
metastore:
1817
roleGroups:
1918
default:
2019
replicas: 1
20+
---
21+
apiVersion: v1
22+
kind: Secret
23+
metadata:
24+
name: hive-credentials
25+
type: Opaque
26+
stringData:
27+
username: hive
28+
password: hive

docs/modules/hive/pages/reference/discovery.adoc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,21 @@ spec:
2525
clusterConfig:
2626
database:
2727
connString: jdbc:postgresql://postgresql:5432/hive
28-
user: hive
29-
password: hive
28+
credentialsSecret: hive-credentials
3029
dbType: postgres
3130
metastore:
3231
roleGroups:
3332
default: # <3>
3433
replicas: 2
34+
---
35+
apiVersion: v1
36+
kind: Secret
37+
metadata:
38+
name: hive-credentials
39+
type: Opaque
40+
stringData:
41+
username: hive
42+
password: hive
3543
----
3644
<1> The name of the Hive cluster, which is also the name of the created discovery ConfigMap.
3745
<2> The namespace of the discovery ConfigMap.

docs/modules/hive/pages/usage-guide/database-driver.adoc

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,7 @@ spec:
145145
clusterConfig:
146146
database:
147147
connString: jdbc:mysql://mysql:3306/hive # <1>
148-
user: hive # <2>
149-
password: hive
148+
credentialsSecret: hive-credentials # <2>
150149
dbType: mysql
151150
s3:
152151
reference: minio # <3>
@@ -167,10 +166,19 @@ spec:
167166
persistentVolumeClaim:
168167
claimName: pvc-hive-drivers
169168
replicas: 1
169+
---
170+
apiVersion: v1
171+
kind: Secret
172+
metadata:
173+
name: hive-credentials # <2>
174+
type: Opaque
175+
stringData:
176+
username: hive
177+
password: hive
170178
----
171179

172180
<1> The database connection details matching those given when deploying the MySQL Helm chart
173-
<2> Plain-text Hive credentials will be replaced in an upcoming release!
181+
<2> Hive credentials are retrieved from a Secret
174182
<3> A reference to the file store using S3 (this has been omitted from this article for the sake of brevity, but is described in e.g. the xref:getting_started/first_steps.adoc[] guide)
175183
<4> Use `envOverrides` to set the driver path
176184
<5> Use `podOverrides` to mount the driver

docs/modules/hive/pages/usage-guide/derby-example.adoc

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,21 @@ spec:
2020
clusterConfig:
2121
database:
2222
connString: jdbc:derby:;databaseName=/tmp/metastore_db;create=true
23-
user: APP
24-
password: mine
23+
credentialsSecret: hive-credentials
2524
dbType: derby
2625
metastore:
2726
roleGroups:
2827
default:
2928
replicas: 1
29+
---
30+
apiVersion: v1
31+
kind: Secret
32+
metadata:
33+
name: hive-credentials
34+
type: Opaque
35+
stringData:
36+
username: APP
37+
password: mine
3038
----
3139

3240
WARNING: You should not use the `Derby` database in production. Derby stores data locally which does not work in high availability setups (multiple replicas) and all data is lost after Pod restarts.
@@ -62,8 +70,7 @@ spec:
6270
clusterConfig:
6371
database:
6472
connString: jdbc:derby:;databaseName=/stackable/metastore_db;create=true
65-
user: APP
66-
password: mine
73+
credentialsSecret: hive-credentials
6774
dbType: derby
6875
s3:
6976
inline:
@@ -96,6 +103,15 @@ metadata:
96103
stringData:
97104
accessKey: minio-access-key
98105
secretKey: minio-secret-key
106+
---
107+
apiVersion: v1
108+
kind: Secret
109+
metadata:
110+
name: hive-credentials
111+
type: Opaque
112+
stringData:
113+
username: APP
114+
password: mine
99115
----
100116

101117

@@ -131,11 +147,19 @@ spec:
131147
clusterConfig:
132148
database:
133149
connString: jdbc:postgresql://hive-postgresql.default.svc.cluster.local:5432/hive
134-
user: hive
135-
password: hive
150+
credentialsSecret: hive-credentials
136151
dbType: postgres
137152
metastore:
138153
roleGroups:
139154
default:
140155
replicas: 1
156+
---
157+
apiVersion: v1
158+
kind: Secret
159+
metadata:
160+
name: hive-credentials
161+
type: Opaque
162+
stringData:
163+
username: hive
164+
password: hive
141165
----

examples/simple-hive-cluster-postgres-s3.yaml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ spec:
2222
clusterConfig:
2323
database:
2424
connString: jdbc:derby:;databaseName=/tmp/hive;create=true
25-
user: APP
26-
password: mine
25+
credentialsSecret: hive-credentials
2726
dbType: derby
2827
s3:
2928
inline:
@@ -56,3 +55,12 @@ metadata:
5655
stringData:
5756
accessKey: minio-access-key
5857
secretKey: minio-secret-key
58+
---
59+
apiVersion: v1
60+
kind: Secret
61+
metadata:
62+
name: hive-credentials
63+
type: Opaque
64+
stringData:
65+
username: APP
66+
password: mine

examples/simple-hive-cluster.yaml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ spec:
1010
clusterConfig:
1111
database:
1212
connString: jdbc:derby:;databaseName=/tmp/hive;create=true
13-
user: APP
14-
password: mine
13+
credentialsSecret: hive-credentials
1514
dbType: derby
1615
metastore:
1716
roleGroups:
@@ -24,3 +23,12 @@ spec:
2423
max: "2"
2524
memory:
2625
limit: 5Gi
26+
---
27+
apiVersion: v1
28+
kind: Secret
29+
metadata:
30+
name: hive-credentials
31+
type: Opaque
32+
stringData:
33+
username: APP
34+
password: mine

rust/crd/src/affinity.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,8 @@ mod tests {
4949
clusterConfig:
5050
database:
5151
connString: jdbc:derby:;databaseName=/tmp/hive;create=true
52-
user: APP
53-
password: mine
5452
dbType: derby
53+
credentialsSecret: mySecret
5554
metastore:
5655
roleGroups:
5756
default:

rust/crd/src/lib.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ pub const HADOOP_OPTS: &str = "HADOOP_OPTS";
7171
pub const HADOOP_HEAPSIZE: &str = "HADOOP_HEAPSIZE";
7272
pub const JVM_HEAP_FACTOR: f32 = 0.8;
7373

74+
// DB credentials
75+
pub const DB_USERNAME_PLACEHOLDER: &str = "xxx_db_username_xxx";
76+
pub const DB_PASSWORD_PLACEHOLDER: &str = "xxx_db_password_xxx";
77+
pub const DB_USERNAME_ENV: &str = "DB_USERNAME_ENV";
78+
pub const DB_PASSWORD_ENV: &str = "DB_PASSWORD_ENV";
79+
7480
const DEFAULT_METASTORE_GRACEFUL_SHUTDOWN_TIMEOUT: Duration = Duration::from_minutes_unchecked(5);
7581

7682
#[derive(Snafu, Debug)]
@@ -422,16 +428,14 @@ pub struct DatabaseConnectionSpec {
422428
/// `jdbc:postgresql://hivehdfs-postgresql:5432/hivehdfs`
423429
pub conn_string: String,
424430

425-
/// The database user.
426-
pub user: String,
427-
428-
/// The password for the database user.
429-
pub password: String,
430-
431431
/// The type of database to connect to. Supported are:
432432
/// `postgres`, `mysql`, `oracle`, `mssql` and `derby`.
433433
/// This value is used to configure the jdbc driver class.
434434
pub db_type: DbType,
435+
436+
/// A reference to a Secret containing the database credentials.
437+
/// The Secret needs to contain the keys `username` and `password`.
438+
pub credentials_secret: String,
435439
}
436440

437441
impl Configuration for MetaStoreConfigFragment {
@@ -492,13 +496,14 @@ impl Configuration for MetaStoreConfigFragment {
492496
MetaStoreConfig::CONNECTION_URL.to_string(),
493497
Some(hive.spec.cluster_config.database.conn_string.clone()),
494498
);
499+
// use a placeholder that will be replaced in the start command (also for the password)
495500
result.insert(
496501
MetaStoreConfig::CONNECTION_USER_NAME.to_string(),
497-
Some(hive.spec.cluster_config.database.user.clone()),
502+
Some(DB_USERNAME_PLACEHOLDER.into()),
498503
);
499504
result.insert(
500505
MetaStoreConfig::CONNECTION_PASSWORD.to_string(),
501-
Some(hive.spec.cluster_config.database.password.clone()),
506+
Some(DB_PASSWORD_PLACEHOLDER.into()),
502507
);
503508
result.insert(
504509
MetaStoreConfig::CONNECTION_DRIVER_NAME.to_string(),

rust/operator-binary/src/command.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use stackable_hive_crd::{
2-
HiveCluster, HIVE_METASTORE_LOG4J2_PROPERTIES, HIVE_SITE_XML, STACKABLE_CONFIG_DIR,
2+
HiveCluster, DB_PASSWORD_ENV, DB_PASSWORD_PLACEHOLDER, DB_USERNAME_ENV,
3+
DB_USERNAME_PLACEHOLDER, HIVE_METASTORE_LOG4J2_PROPERTIES, HIVE_SITE_XML, STACKABLE_CONFIG_DIR,
34
STACKABLE_CONFIG_MOUNT_DIR, STACKABLE_LOG_CONFIG_MOUNT_DIR, STACKABLE_TRUST_STORE,
45
STACKABLE_TRUST_STORE_PASSWORD, SYSTEM_TRUST_STORE, SYSTEM_TRUST_STORE_PASSWORD,
56
};
@@ -59,6 +60,13 @@ pub fn build_container_command_args(
5960
}
6061
}
6162

63+
// db credentials
64+
args.extend([
65+
format!("echo replacing {DB_USERNAME_PLACEHOLDER} and {DB_PASSWORD_PLACEHOLDER} with secret values."),
66+
format!("sed -i \"s|{DB_USERNAME_PLACEHOLDER}|${DB_USERNAME_ENV}|g\" {STACKABLE_CONFIG_DIR}/{HIVE_SITE_XML}"),
67+
format!("sed -i \"s|{DB_PASSWORD_PLACEHOLDER}|${DB_PASSWORD_ENV}|g\" {STACKABLE_CONFIG_DIR}/{HIVE_SITE_XML}"),
68+
]);
69+
6270
// metastore start command
6371
args.push(start_command);
6472

0 commit comments

Comments
 (0)