Skip to content

Commit dbfb6dc

Browse files
authored
fix: E2E Security demo - Separate DB setup from superset resource (#151)
* fix: Separate DB setup from superset resource * restored full paths
1 parent 08226fb commit dbfb6dc

File tree

4 files changed

+89
-37
lines changed

4 files changed

+89
-37
lines changed

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
apiVersion: rbac.authorization.k8s.io/v1
3+
kind: RoleBinding
4+
metadata:
5+
name: superset-job-rb
6+
roleRef:
7+
apiGroup: rbac.authorization.k8s.io
8+
kind: Role
9+
name: superset-job-role
10+
subjects:
11+
- apiGroup: rbac.authorization.k8s.io
12+
kind: Group
13+
name: system:serviceaccounts
14+
---
15+
apiVersion: rbac.authorization.k8s.io/v1
16+
kind: Role
17+
metadata:
18+
name: superset-job-role
19+
rules:
20+
- apiGroups:
21+
- batch
22+
resources:
23+
- jobs
24+
verbs:
25+
- get
26+
- list
27+
- watch
28+
- apiGroups:
29+
- apps
30+
resources:
31+
- statefulsets
32+
verbs:
33+
- get
34+
- list
35+
- watch
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
apiVersion: batch/v1
3+
kind: Job
4+
metadata:
5+
name: setup-db-job
6+
spec:
7+
template:
8+
spec:
9+
initContainers:
10+
# The postgres image does not contain curl or wget...
11+
- name: download-dump
12+
image: oci.stackable.tech/sdp/testing-tools:0.2.0-stackable0.0.0-dev
13+
command:
14+
- bash
15+
- -c
16+
- |
17+
kubectl rollout status --watch statefulset/postgresql-superset
18+
cd /tmp
19+
curl --fail -O https://raw.githubusercontent.com/stackabletech/demos/main/stacks/end-to-end-security/postgres_superset_dump.sql.gz
20+
gunzip postgres_superset_dump.sql.gz
21+
22+
# We need to omit changing the users password, as otherwise the content in the Secrets does not match
23+
# the actual password in Postgres.
24+
grep -vwE '(CREATE ROLE postgres;|CREATE ROLE superset;|ALTER ROLE postgres|ALTER ROLE superset)' postgres_superset_dump.sql > /dump/postgres_superset_dump.sql
25+
volumeMounts:
26+
- name: dump
27+
mountPath: /dump/
28+
containers:
29+
- name: restore-postgres
30+
image: docker.io/bitnami/postgresql:16.1.0-debian-11-r11 # Same image as the bitnami postgres helm-chart is using
31+
command:
32+
- bash
33+
- -c
34+
- |
35+
echo "Preparing restore..."
36+
psql --host postgresql-superset --user postgres < /dump/postgres_superset_dump.sql
37+
env:
38+
- name: PGPASSWORD
39+
valueFrom:
40+
secretKeyRef:
41+
name: postgresql-superset
42+
key: postgres-password
43+
volumeMounts:
44+
- name: dump
45+
mountPath: /dump/
46+
volumes:
47+
- name: dump
48+
emptyDir: {}
49+
restartPolicy: OnFailure
50+
backoffLimit: 20

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

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -21,49 +21,14 @@ spec:
2121
replicas: 1
2222
podOverrides:
2323
spec:
24-
# We need to restore the postgres state before the superset container itself starts some database migrations
2524
initContainers:
26-
# The postgres image does not contain curl or wget...
27-
- name: download-dump
25+
- name: wait-for-setup-db-job
2826
image: oci.stackable.tech/sdp/testing-tools:0.2.0-stackable0.0.0-dev
2927
command:
3028
- bash
3129
- -c
3230
- |
33-
cd /tmp
34-
curl --fail -O https://raw.githubusercontent.com/stackabletech/demos/main/stacks/end-to-end-security/postgres_superset_dump.sql.gz
35-
gunzip postgres_superset_dump.sql.gz
36-
37-
# We need to omit changing the users password, as otherwise the content in the Secrets does not match
38-
# the actual password in Postgres.
39-
grep -vwE '(CREATE ROLE postgres;|CREATE ROLE superset;|ALTER ROLE postgres|ALTER ROLE superset)' postgres_superset_dump.sql > /dump/postgres_superset_dump.sql
40-
volumeMounts:
41-
- name: dump
42-
mountPath: /dump/
43-
- name: restore-postgres
44-
image: docker.io/bitnami/postgresql:16.1.0-debian-11-r11 # Same image as the bitnami postgres helm-chart is using
45-
command:
46-
- bash
47-
- -c
48-
- |
49-
if psql --host postgresql-superset --user postgres --csv -c "SELECT datname FROM pg_database where datname = 'superset' limit 1" | grep -q superset; then
50-
# The flask app will do any necessary migrations.
51-
echo "Skip restoring the DB as it already exists"
52-
exit 0
53-
fi
54-
psql --host postgresql-superset --user postgres < /dump/postgres_superset_dump.sql
55-
env:
56-
- name: PGPASSWORD
57-
valueFrom:
58-
secretKeyRef:
59-
name: postgresql-superset
60-
key: postgres-password
61-
volumeMounts:
62-
- name: dump
63-
mountPath: /dump/
64-
volumes:
65-
- name: dump
66-
emptyDir: {}
31+
kubectl wait --for=condition=complete job/setup-db-job
6732
---
6833
apiVersion: v1
6934
kind: Secret

stacks/stacks-v2.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,8 @@ stacks:
582582
- plainYaml: https://raw.githubusercontent.com/stackabletech/demos/main/stacks/end-to-end-security/trino.yaml
583583
- plainYaml: https://raw.githubusercontent.com/stackabletech/demos/main/stacks/end-to-end-security/trino-regorules.yaml
584584
- plainYaml: https://raw.githubusercontent.com/stackabletech/demos/main/stacks/end-to-end-security/trino-policies.yaml
585+
- plainYaml: https://raw.githubusercontent.com/stackabletech/demos/main/stacks/end-to-end-security/rbac.yaml
586+
- plainYaml: https://raw.githubusercontent.com/stackabletech/demos/main/stacks/end-to-end-security/setup-postgresql.yaml
585587
- plainYaml: https://raw.githubusercontent.com/stackabletech/demos/main/stacks/end-to-end-security/superset.yaml
586588
parameters:
587589
- name: keycloakAdminPassword

0 commit comments

Comments
 (0)