Skip to content

Commit 5b4167c

Browse files
authored
feat(end-to-end-security): add superset OPA (#407)
* feat(end-to-end-security): add superset OPA * chore: update postgres dump * chore: update overview image and appease linter * chore: adjust admin user information to make it more generic
1 parent b9c7761 commit 5b4167c

8 files changed

Lines changed: 1135 additions & 2043 deletions

File tree

demos/end-to-end-security/README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
# How to persist changes in Superset
22

3-
1. Log into Keycloak as the user `admin` (in the master realm) and create a user called `admin` in the demo realm.
4-
2. Use that to log into Superset with the `Admin` role.
5-
3. Optional: Add Database connection
6-
4. Add admin user in Keycloak to all relevant groups (so that he has access to the tables, so he can create datasets, charts and dashboards).
7-
5. `pgdump` the Postgres and update the dump in Git. For that shell into `postgresql-superset-0` and execute
3+
Note: User role assignments no longer need to be maintained in the dump.
4+
They are assigned by OPA on every login based on the Keycloak group memberships
5+
(see `stacks/end-to-end-security/superset-regorules.yaml`).
6+
7+
1. Log into Superset via `Sign in with Keycloak` as the user `admin` (default password `adminadmin`).
8+
The user is part of the demo realm in `keycloak-realm-config.yaml` and is automatically assigned the Superset `Admin` role by OPA.
9+
2. Optional: Add Database connection
10+
3. Add admin user in Keycloak to all relevant groups (so that he has access to the tables, so he can create datasets, charts and dashboards).
11+
4. `pgdump` the Postgres and update the dump in Git. For that shell into `postgresql-superset-0` and execute
812

913
```sh
1014
export PGPASSWORD=$(cat "${POSTGRES_POSTGRES_PASSWORD_FILE}")
-445 Bytes
Loading

docs/modules/demos/pages/end-to-end-security.adoc

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
:k8s-cpu: https://kubernetes.io/docs/tasks/debug/debug-cluster/resource-metrics-pipeline/#cpu
55
:rego: https://www.openpolicyagent.org/docs/latest/policy-language/
66
:trino-policies: https://github.com/stackabletech/demos/blob/main/stacks/end-to-end-security/trino-policies.yaml
7+
:superset-regorules: https://github.com/stackabletech/demos/blob/main/stacks/end-to-end-security/superset-regorules.yaml
78

89
This is a demo to showcase what can be done with Open Policy Agent around authorization in the Stackable Data Platform.
910
It covers the following aspects of security:
@@ -16,7 +17,7 @@ This demo will:
1617
** *Spark*: A multi-language engine for executing data engineering, data science, and machine learning. This demo uses it to create a (rather simple) report and write the results back into the persistence.
1718
** *HDFS*: A distributed file system that is designed to scale up from single servers to thousands of machines, each offering local computation and storage.
1819
** *Hive metastore*: A service that stores metadata related to Apache Hive and other services. This demo uses it as metadata storage for Trino and Spark.
19-
** *Open policy agent (OPA)*: An open-source, general-purpose policy engine unifies policy enforcement across the stack. This demo uses it as the authorizer for Trino and HDFS, which decides which user can query which data.
20+
** *Open policy agent (OPA)*: An open-source, general-purpose policy engine unifies policy enforcement across the stack. This demo uses it as the authorizer for Trino and HDFS, which decides which user can query which data. It also assigns Superset roles based on the Keycloak group memberships.
2021
** *Superset*: A modern data exploration and visualization platform. This demo utilizes Superset to retrieve data from Trino via SQL queries and build dashboards on top of that data.
2122
* Configure security to showcase the following features
2223
** Column- and row-level filtering
@@ -101,6 +102,10 @@ The following user accounts are configured in Keycloak:
101102
|mark.ketting
102103
|mark.ketting
103104
|Head of Marketing
105+
106+
|admin
107+
|adminadmin
108+
|Administrator, not member of any department
104109
|===
105110

106111
[#ruleset]
@@ -323,6 +328,24 @@ When clicking on the button, you are redirected to the Superset UI being already
323328

324329
image::end-to-end-security/superset_2.png[]
325330

331+
=== Superset role assignment via OPA
332+
333+
Which dashboards a user can see in Superset is determined by Superset roles.
334+
Instead of assigning these roles manually, Superset asks OPA for the roles of a user at every login (configured via `roleMappingFromOpa` on the SupersetCluster).
335+
OPA derives the roles from the Keycloak group memberships using the user-info-fetcher - the same group lookup the Trino rules are based on.
336+
The mapping is defined in the {superset-regorules}[superset-regorules ConfigMap]:
337+
338+
* Every user gets the `Gamma` and `sql_lab` roles, granting access to the Superset UI including SQL Lab.
339+
* Members of a department additionally get the role granting access to the datasets of their department, e.g. members of `/Customer Service/Analytics` get the `Customer Service Analytics` role and with it the `Customer analytics` dashboard.
340+
* The `admin` user is assigned the Superset `Admin` role, so Superset can be administered via Single Sign On as well.
341+
342+
You can try this out by logging in to Superset as `pamela.scott` (Customer Analytics) and `william.lewis` (Compliance Analytics) and comparing the dashboards each of them sees.
343+
Adding a user to a department group in Keycloak is all that is needed: on the next login, the user is assigned the matching Superset roles automatically.
344+
345+
Note that the Superset roles only control which dashboards and datasets are visible.
346+
The data shown in the charts is still protected by Trino and OPA, because Superset impersonates the logged-in user when querying Trino.
347+
Also note that role assignments made in the Superset UI are overwritten on the next login of the affected user - the Rego rules are the single source of truth.
348+
326349
=== Open Policy Agent for the utmost flexibility in building access rules
327350

328351
Some examples of access rules you can define for the Open Policy Agent authorization mechanism were already shown in the <<column-row-filtering, Column- and row-level filtering section>>. For more examples, check out the {trino-policies}[trino-policies ConfigMap] of this demo and also the https://www.youtube.com/watch?v=ATlq_l3WNiA&t=1970s[ACL section of the 'Mastering Data Platform Security' recording from above].

stacks/end-to-end-security/keycloak-realm-config.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,24 @@ stringData:
4646
"subGroups" : [ ]
4747
} ],
4848
"users" : [ {
49+
"username" : "admin",
50+
"enabled" : true,
51+
"totp" : false,
52+
"emailVerified" : true,
53+
"firstName" : "Admin",
54+
"lastName" : "Admin",
55+
"email" : "admin@example.com",
56+
"credentials" : [ {
57+
"type" : "password",
58+
"value" : "{{ adminPassword }}",
59+
"temporary" : false
60+
} ],
61+
"disableableCredentialTypes" : [ ],
62+
"requiredActions" : [ ],
63+
"realmRoles" : [ "default-roles-demo" ],
64+
"notBefore" : 0,
65+
"groups" : [ ]
66+
}, {
4967
"id" : "e44a09fa-bce1-40e8-a1da-28902b79dcf0",
5068
"createdTimestamp" : 1711375603780,
5169
"username" : "daniel.king",

0 commit comments

Comments
 (0)