Skip to content

Commit 76d2778

Browse files
authored
e2e-security: enable OPA for hive (#345)
* enable decision logs * rename opa package to hive-iceberg * improve comments * fix package name * fix hive rego filename
1 parent 47b9502 commit 76d2778

4 files changed

Lines changed: 81 additions & 0 deletions

File tree

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
---
2+
# {% raw %}
3+
apiVersion: v1
4+
kind: ConfigMap
5+
metadata:
6+
name: hive-metastore-regorules
7+
labels:
8+
opa.stackable.tech/bundle: "true"
9+
data:
10+
hive-metastore.rego: |
11+
package hive_iceberg
12+
13+
trino_user := "trino"
14+
spark_user := "spark"
15+
customer_analytics_db := "customer_analytics"
16+
compliance_analytics_db := "compliance_analytics"
17+
18+
default database_allow = false
19+
default table_allow = false
20+
default column_allow = false
21+
default partition_allow = false
22+
default user_allow = false
23+
24+
### SPARK ###
25+
# These rules are tailored for the create-spark-report job.
26+
27+
# Allow the spark user access to the 'customer_analytics_db'
28+
database_allow if {
29+
input.identity.username == spark_user
30+
input.resources.database.name == customer_analytics_db
31+
}
32+
33+
# Allow the 'SELECT * FROM lakehouse.customer_analytics.customer' query in create-spark-report
34+
table_allow if {
35+
input.identity.username == spark_user
36+
input.resources.table.dbName == customer_analytics_db
37+
input.resources.table.tableName == "customer"
38+
input.privileges.readRequiredPriv[0].priv == "SELECT"
39+
}
40+
41+
# Allow the 'CREATE TABLE IF NOT EXISTS lakehouse.customer_analytics.spark_report AS SELECT c_birth_country, count(*) FROM ..'
42+
# query in create-spark-report
43+
table_allow if {
44+
input.identity.username == spark_user
45+
input.resources.table.dbName == customer_analytics_db
46+
input.resources.table.tableName == "spark_report"
47+
input.privileges.writeRequiredPriv[0].priv == "CREATE"
48+
}
49+
50+
### TRINO ###
51+
# We allow everything here for the technical trino user in order to still do data exploration
52+
database_allow if {
53+
input.identity.username == trino_user
54+
}
55+
56+
table_allow if {
57+
input.identity.username == trino_user
58+
}
59+
60+
column_allow if {
61+
input.identity.username == trino_user
62+
}
63+
64+
partition_allow if {
65+
input.identity.username == trino_user
66+
}
67+
68+
user_allow if {
69+
input.identity.username == trino_user
70+
}
71+
72+
# {% endraw %}

stacks/end-to-end-security/hive-metastore.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ spec:
77
image:
88
productVersion: 4.0.0
99
clusterConfig:
10+
authorization:
11+
opa:
12+
configMapName: opa
13+
package: hive_iceberg
1014
database:
1115
connString: jdbc:postgresql://postgresql-hive-iceberg:5432/hive
1216
credentialsSecret: postgres-credentials

stacks/end-to-end-security/opa.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ spec:
2525
logging:
2626
containers:
2727
opa:
28+
console:
29+
level: INFO
30+
file:
31+
level: INFO
2832
loggers:
2933
decision:
3034
level: INFO

stacks/stacks-v2.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,7 @@ stacks:
589589
- plainYaml: https://raw.githubusercontent.com/stackabletech/demos/main/stacks/end-to-end-security/hdfs.yaml
590590
- plainYaml: https://raw.githubusercontent.com/stackabletech/demos/main/stacks/end-to-end-security/hdfs-regorules.yaml
591591
- plainYaml: https://raw.githubusercontent.com/stackabletech/demos/main/stacks/end-to-end-security/hive-metastore.yaml
592+
- plainYaml: https://raw.githubusercontent.com/stackabletech/demos/main/stacks/end-to-end-security/hive-metastore-regorules.yaml
592593
- plainYaml: https://raw.githubusercontent.com/stackabletech/demos/main/stacks/end-to-end-security/trino.yaml
593594
- plainYaml: https://raw.githubusercontent.com/stackabletech/demos/main/stacks/end-to-end-security/trino-regorules.yaml
594595
- plainYaml: https://raw.githubusercontent.com/stackabletech/demos/main/stacks/end-to-end-security/trino-policies.yaml

0 commit comments

Comments
 (0)