Skip to main content

Securing a Self-Hosted Data Lakehouse: RBAC for People and Workloads (M2M)

Keycloak, Kubernetes service account tokens, Istio, Trino and Nessie: who can read, write and audit Bronze, Silver and Gold data.

Updated 42 min readMarkdown
Securing a Self-Hosted Data Lakehouse: RBAC for People and Workloads (M2M)

Part of the homelab build series. Who may read and write which tables in a self-hosted lakehouse on RKE2: people through Keycloak, workloads through identities Kubernetes and Istio already issue, and every rule in Git. The data it guards is already highly available (three Postgres instances, two Nessie replicas, replicated Ceph); this is about making it safe as well.

Lakehouse RBAC for people and machine-to-machine (M2M) workloads: Keycloak, Kubernetes, Istio, Trino and Nessie, and who may read Bronze, Silver and Gold


Introduction

Everyone at the door had a badge. Nobody checked what it said.

The lakehouse had sign-in everywhere a person could see. OpenMetadata, MLflow, Kubeflow, and now the Nessie and Trino web UIs all sit behind Keycloak. It looked locked.

Then I asked a different question: not "who can open the UI?" but "who can read the data?" The honest answer was any pod in the cluster. Trino, the SQL engine that reads every table, had no client authentication and no authorization. A pod could connect, call itself any user it liked, and read or write anything. The sign-in pages were guarding the windows.

This article closes that door in stages. There are two kinds of caller, and they need different answers:

People Workloads (machine to machine)
Who me, and any future analyst dbt, the OpenMetadata crawl, the football pipeline, notebooks
Proves who it is with Keycloak sign-in its Kubernetes service account, proved by Istio mTLS and by short-lived tokens Kubernetes mounts into the pod
What decides access table rules by layer (Bronze, Silver, Gold), kept in Git the same rules

All six stages are live: a fence that decides which workloads may connect, an identity check that decides who each of them is, rules that decide what each identity may read and write, the same identities and rules on the catalog itself, people signing in to Trino as themselves, and an audit trail of who read and wrote what. On top sits Superset for dashboards, built so that it reads the data as the person using it, never as itself.

Where each identity is checked: people at Keycloak, workloads with Kubernetes tokens, the Istio fence deciding who may connect, Trino deciding what each name may read by layer, Nessie giving each writer one lane, and every query landing in an audit table

Where it stood

Layer What controlled access Per person?
Trino (SQL over every table) nothing: no authentication, no authorization; the user name was whatever the caller sent in X-Trino-User no
Nessie (the catalog) an Istio policy deciding which workloads may read or write; Nessie's own authentication is off workloads only
Ceph bucket (the files) an S3 key per app; Nessie vends bucket credentials to engines no
OpenMetadata its own roles decide who can see and edit metadata, not who can read data metadata only

Trino was the widest door, because it reads the files as well as the catalog.

The first lock: only known workloads reach Trino

Before writing a rule, I needed to know who actually calls Trino. Guessing is how you lock out the nightly job and only find out the next morning. I used two sources, because neither is complete on its own:

  • Configuration. Every file in the repo that points at the Trino coordinator.
  • Live traffic. Istio's per-caller connection counters on the Trino pod's sidecar, and Hubble's flow log for the pod.
Caller Service account How I know
dbt build mlops/dbt-runner its profile points at Trino; hundreds of live connections per build
OpenMetadata crawl mlops/om-ingestion its workflow points at Trino
Trino web UI, through Keycloak trino-sso/oauth2-proxy-trino the proxy overlay; live connections
Trino itself mlops/platform-trino-serviceaccount coordinator-to-worker traffic

Just as useful was the list of things that don't call Trino. The football pipeline mentions Trino only in comments; it writes through Nessie directly. No notebook is configured for it, and nothing scrapes its metrics.

The rule is an Istio AuthorizationPolicy on the Trino pod. Istio already proves each workload's identity with mTLS, so the policy can name service accounts instead of IP addresses:

apiVersion: security.istio.io/v1
kind: AuthorizationPolicy
metadata:
  name: trino-callers-only
  namespace: mlops
spec:
  selector:
    matchLabels:
      app.kubernetes.io/name: trino
      app.kubernetes.io/instance: platform-trino
  action: ALLOW
  rules:
    - from:
        - source:
            principals:
              - cluster.local/ns/mlops/sa/dbt-runner
      to:
        - operation:
            ports:
              - "8443"
    # … one rule each for om-ingestion, oauth2-proxy-trino and Trino's own account

An ALLOW policy refuses everything it doesn't list, at the sidecar, before Trino sees a byte.

Two things I checked before applying it, because either would have taken Trino down:

  • Health checks. Istio rewrites Kubernetes' probes to go to the sidecar, which then calls Trino over localhost, outside the policy. Hubble showed the kubelet only ever reaching the sidecar's ports.
  • The UI proxy. It talks to Trino over TLS, so Envoy treats the connection as TCP and it still carries the proxy's mTLS identity.

Then I tested it from both sides:

Caller Result
a throwaway pod using the namespace's default service account refused: the TLS connection is reset (curl exit 35); Nessie answers 403
dbt, a full build allowed: 23 of 23 models and tests passed, merged into main
OpenMetadata's Trino crawl allowed: 12 records, 0 errors
the Trino web UI allowed

Keycloak's sign-in page for the kiali realm: KIALI UI SSO, with Google and GitHub sign-in

Kiali, like every web UI in the lab, sits behind a Keycloak sign-in of its own.

Kiali's Istio Config list for mlops: three AuthorizationPolicies, one PeerAuthentication and four VirtualServices, with trino-callers-only and nessie-consumers-only marked red

Everything the mesh enforces in mlops: the fences on Trino, on Nessie and on the audit receiver, plus the routes to the web UIs. The red marks are a Kiali quirk, explained under the next picture.

Kiali showing the trino-callers-only policy in mlops, with dbt-runner and om-ingestion as allowed principals on port 8443, both marked KIA0106

The fence as Kiali shows it. The two red marks are Kiali, not the fence: it only knows the service accounts of pods running right now, and dbt and the OpenMetadata crawl run as Jobs that come and go. Both accounts exist, and both connect every morning.

What this does not do yet. It decides which workloads may connect. It doesn't decide what they may read or write, and an allowed workload can still claim any user name. dbt could announce itself as admin. That's what the next stage fixes.

Workload identity, without secrets

The usual answer to "how does a job prove who it is?" is a client ID and secret: one more credential per workload, stored in Vault, rotated by someone, leaked by someone else. Kubernetes already gives every pod a better one. The kubelet can mount a service account token made for that pod: signed by the cluster, valid only for one audience, and replaced before it expires. Nothing to store, nothing to rotate.

So each Trino client gets its own token, for audience trino:

volumes:
  - name: trino-token
    projected:
      sources:
        - serviceAccountToken:
            audience: trino
            expirationSeconds: 3600
            path: token

dbt sends it with method: jwt, and the OpenMetadata crawl with its Trino connector's jwt option. Both read it from the mounted file at start; neither stores it anywhere.

On the other side, Trino checks every SQL request's token: the signature against the cluster's public key, the issuer, and the audience. Its user is the token's subject, mapped from system:serviceaccount:mlops:dbt-runner to plain dbt-runner. The mapping only matches the mlops namespace, so a valid token from anywhere else fails as well.

http-server.authentication.type: "JWT"
http-server.authentication.jwt.key-file: "/stackable/jwt/sa-pub.pem"
http-server.authentication.jwt.required-issuer: "https://kubernetes.default.svc.cluster.local"
http-server.authentication.jwt.required-audience: "trino"
http-server.authentication.jwt.user-mapping.pattern: "system:serviceaccount:mlops:(.+)"

One snag cost me a detour. Trino can normally fetch a key set from a URL, and Kubernetes publishes one. But on this cluster that endpoint itself requires a token, and it points at a single control-plane node. Trino can't authenticate its own key fetch, so the public key ships as a file in a ConfigMap instead. It's a public key, not a secret, and if the cluster's signing key ever changes, every token fails until the file is updated. It fails closed.

I changed the clients first, while Trino still ignored tokens, so the switch-over couldn't break a run. Then Trino started checking:

Request Result
no token refused (401)
dbt's token, but for the wrong audience refused (401)
a token for trino from another namespace refused (401)
dbt's valid token, claiming to be george refused: User dbt-runner cannot impersonate user george
dbt's valid token accepted, current_user = dbt-runner
the OpenMetadata crawl's valid token accepted, current_user = om-ingestion
a full dbt build, then the OpenMetadata crawl 23 of 23 models and tests passed and merged; crawl finished with 0 errors

The impersonation line is the one I care about. A workload that's allowed in still can't pretend to be someone else.

Who can read Gold

Knowing who a workload is doesn't decide what it may touch. Until this stage, every identity Trino accepted could read and write every table.

The lakehouse already has a natural map for permissions: its layers. Bronze is data as it lands (raw, raw_football), Silver is typed and cleaned (marts_staging), Gold is tested and ready to use (marts_marts, marts_football, and curated_football, which the Spark ETL job writes and audits on its own branch before merging). So the rules follow the layers.

Before writing any rule, I asked Trino what each workload actually does. Its query log showed that dbt only ever writes to audit, the catalog pinned to the dbt-audit Nessie branch, and only reads from iceberg, which is main. Merging the branch into main happens through Nessie's API, not through Trino. The OpenMetadata crawl only reads. That made one rule possible that I hadn't expected: nobody except the admin writes to main through Trino, not even dbt.

Identity Bronze Silver Gold audit (dbt's branch)
dbt-runner read read read read and write
om-ingestion read read read none
lakehouse-reader none none read none
george (admin) all all all all
anyone else none none none none

lakehouse-reader is new: a service account with no pod and no Kubernetes permissions, kept for a read-only report or notebook that should only see finished data. No workload uses it yet, and the mesh fence doesn't list it, so from inside the cluster it can't even connect. The daily check further down proves that as well.

dbt has a second branch catalog since this stage, eltci, where a CI run tests the ELT before anything reaches main. It has the same rights there as on audit, and nobody else can see it.

The rules use Trino's built-in file-based access control, so there's nothing new to run. They live in Git as a ConfigMap that Trino re-reads every minute, so changing a rule doesn't need a restart. The core of it:

tables:
  - user: dbt-runner
    catalog: audit
    privileges: [SELECT, INSERT, DELETE, UPDATE, OWNERSHIP]
  - user: dbt-runner|om-ingestion
    catalog: iceberg
    privileges: [SELECT]
  - user: lakehouse-reader
    catalog: iceberg
    schema: marts_marts|marts_football|curated_football
    privileges: [SELECT]
  - privileges: []          # everyone else: nothing

(The file itself is JSON; the shape is the same.)

Then each identity, with its own token, tried what it should and shouldn't be able to do:

Identity Request Result
lakehouse-reader read a Gold table allowed
lakehouse-reader read a Bronze table refused: Access Denied: Cannot select from table iceberg.raw_football.matches
lakehouse-reader read a Silver table refused
lakehouse-reader create a table in Gold refused
lakehouse-reader list the schemas only the Gold schemas come back; the other layers are invisible
dbt-runner write a table straight into main refused
dbt-runner write a table on its audit branch allowed
om-ingestion read a Bronze table allowed
om-ingestion insert a row refused

The real jobs ran under the rules too. The dbt build passed 23 of 23 and merged into main through its branch, and the OpenMetadata crawl finished. I checked that one specifically, because the crawl marks any table it can't see as deleted: all five tables were still there, with their certification and owner.

Superset SQL Lab listing lakehouse-reader's queries from the audit table: the Gold count and SHOW SCHEMAS finished, the Bronze read and audit-table reads failed with PERMISSION_DENIED

The Gold-only reader, as the audit table remembers it: counting Gold matches works, listing schemas works, and reading raw Bronze or the audit table is refused.

Closing the catalog

Trino was locked, but it wasn't the only way in. Nessie, the catalog, has its own API, and that API can do things SQL can't: create a branch, merge it into main, delete a tag. Until this stage the only guard was the Istio policy, which can say "dbt may send POST requests to Nessie" but not "dbt may only touch its own branch". Any workload on the list could have merged anything into main or deleted the tags that pin each model's training data.

So Nessie gets the same treatment as Trino: every writer proves who it is with its own Kubernetes token, this time for audience nessie, and rules decide which branches and tags each identity may change.

The same identity, a second audience

Nessie runs on Quarkus, whose OIDC support can verify a token against a fixed public key without talking to any identity server. That's the same key Trino already uses, so no Keycloak client, no client secret, nothing new to rotate:

authentication:
  enabled: true
advancedConfig:
  quarkus.oidc.public-key: "<the cluster's service-account public key>"
  quarkus.oidc.token.issuer: "https://kubernetes.default.svc.cluster.local"
  quarkus.oidc.token.audience: "nessie"

Four workloads write to the catalog, and each needed to send a token before Nessie could start asking for one:

Writer How it gets its token
dbt's branch-and-merge script a token the kubelet mounts into the pod, re-read on every call
the football pipeline's publish step the same, added to the pipeline's job template; a new image sends it
the tag clean-up job the same
Trino the awkward one, below

Trino's Iceberg client takes a token only as a fixed value, read once when Trino starts. It can't follow a file that the kubelet rotates every hour. So a small daily job mints a token for Trino's service account, valid for seven days, straight into a Kubernetes Secret, and Trino reads it at start-up. The token never passes through a log or a terminal. The lab powers off every night, so Trino always starts with a token less than a day old.

Reads stay open, writes need a name

Not every caller should need a token. The Nessie web UI, the OpenMetadata crawl and the garbage collector only read, and the mesh already decides which of them may connect. So the catalog's read paths, and the UI's own pages, accept anonymous requests. Nessie treats those as a caller with no role, and the rules let that caller read and nothing else. A request that does carry a token is always checked, so a bad or expired token gets 401, never a free pass as anonymous.

Three things surprised me here, and each would have broken something quietly:

  • The chart adds its own UI login. With authentication on, Nessie's Helm chart sets up a second OIDC login just for the web UI. The UI already signs in through Keycloak at its proxy, so I switched that one off.
  • The UI loads more than its page lists. I opened every file named in the UI's HTML. After going live, the access log still showed refusals for five more: images and an icon font that the UI's code loads by itself. I scanned the bundle for every root-level file and opened those too.
  • pyiceberg sends "Bearer None". Without a token, the Python Iceberg client sends the literal header Authorization: Bearer None. That's a bad token, so Nessie refuses it, even on a read path open to everyone. An anonymous pyiceberg reader has to set its auth type to noop in the catalog properties. No such reader is on the mesh list yet, but the next notebook would have hit this.

One more broke the UI, and it was older than this stage. The UI's table page reads a table's details with a POST request, and the mesh rule for the UI's proxy only allowed GET. Every table page said "Content not found". It's a read, so Nessie's own rules allow it; the mesh rule now allows that one POST path too.

One lane per writer

The rules are CEL expressions over three things Nessie knows about each request: the operation, the caller's identity (role), and the branch or tag (ref). A request passes if any rule matches.

Identity May change
dbt-runner its branch dbt-audit (reset, re-create), and merge it into main
Trino tables on dbt-audit, the CI ELT branch and main, but never create, move or delete a branch or tag
the publisher its own ingest-football-* branches, merges into main, new train-football-* tags
the tag clean-up job deleting train-football-* tags, nothing else
the Spark ETL job its own etl-football-* branches, and merges into main, but only tables under curated_football
anyone, including anonymous read everything, write nothing

Nobody may move or delete main.

One lane per writer: dbt on dbt-audit, the publisher on ingest-football-, the Spark ETL job on etl-football- and curated_football only, the tag clean-up job deleting train-football-* tags, Trino changing tables but never refs, the audit receiver alone on audit_log, and nobody moving main

Two of the rules, as they sit in the Helm values:

authorization:
  enabled: true
  rules:
    anyone_reads: "op in ['VIEW_REFERENCE','READ_ENTRIES','READ_CONTENT_KEY','LIST_COMMIT_LOG','READ_ENTITY_VALUE','READ_REPOSITORY_CONFIG']"
    tag_retention: "role == 'system:serviceaccount:mlops:xgboost-tag-retention' && ref.startsWith('train-football-') && op == 'DELETE_REFERENCE'"

Tested on a copy first, then switched on in steps

A wrong rule here doesn't fail loudly. It fails as "table not found" in Trino or a pipeline that stops at the publish step. So before touching the real Nessie, I ran a throwaway copy with the rules on and an empty in-memory store, and replayed each client's real sequence of calls with its own token. That included the publisher writing a table through pyiceberg, which goes through the Iceberg endpoint and Nessie's S3 request signing. 33 of 33 cases behaved as intended.

Then the real switch, in three steps, each verified before the next:

  1. Every writer sends its token, while Nessie still ignores tokens.
  2. Nessie checks tokens: anonymous reads, and any service account in the namespace may write.
  3. Each writer narrowed to its own lane.

Each step is one commit, and undoing it is a revert. The real jobs ran after the last step:

Check on the live catalog Result
UI pages, its files, and API reads without a token 200
a bad token, or one minted for Trino 401
a write without a token 403
dbt: reset its branch, build, merge into main 23 of 23 passed, merged
the football pipeline end to end succeeded; the publish step branched, wrote, merged and tagged
the tag clean-up job ran (still in dry-run mode, so it only lists)
13 attempts by real identities to step outside their lane: the publisher moving main or deleting a tag, dbt creating a publisher branch, Trino deleting dbt-audit, the reader creating a branch all 403; nothing created, main unchanged
refusals in Nessie's access log during the real runs none

Keycloak's sign-in page for the nessie realm: NESSIE UI SSO, with Google and GitHub sign-in

Nessie's web UI sits behind Keycloak too, in its own realm.

The Nessie UI on main after sign-in: the audit_log, curated_football, marts and raw schemas, with 5 branches and 65 tags

Inside: main and its schemas, five branches and the training tags the publisher creates. Reading is open; every write still has to pass the lanes above.

People sign in as themselves

Every workload now had a name. People still didn't. The Trino web UI sat behind a Keycloak sign-in at a proxy, and once you were through, Trino showed everyone as one fixed user, george. The query list couldn't say who ran what, and the layer rules couldn't tell one person from another.

So Trino signs people in itself now, against the same Keycloak, and the proxy in front of it is gone.

Two kinds of token, one server

Trino can run more than one authenticator and tries them in order. Workloads keep their service-account tokens; people get a Keycloak sign-in in the browser, whether they use the web UI, the Trino CLI or DBeaver:

http-server.authentication.type: "JWT,OAUTH2"
http-server.authentication.oauth2.issuer: "https://keycloak.georgehomelab.com/realms/trino"
http-server.authentication.oauth2.client-id: "trino"
http-server.authentication.oauth2.client-secret: "${ENV:TRINO_OAUTH2_CLIENT_SECRET}"
http-server.authentication.oauth2.principal-field: "preferred_username"
web-ui.authentication.type: "oauth2"

A Keycloak token fails the first check, because the cluster didn't sign it, and is then checked against Keycloak's published keys. A person's name in Trino is their Keycloak user name, which here is their email.

The client secret follows the pattern the rest of the platform uses. Terraform generates it into Vault, Keycloak's client reads it from there, and the Vault operator copies it into a Kubernetes Secret that Trino reads at start. Nobody types it, and the two sides can't drift apart.

With the proxy gone, the gateway reaches Trino directly, on Trino's plain HTTP port and inside the mesh's mutual TLS, so the request still carries the gateway's identity. The fence from the first stage gets one more line: only the gateway may use that port. Workloads keep the TLS port and their tokens.

Who may sign in, and what they get

The obvious design was to grant rights by Keycloak group: admins get everything, analysts get Gold. Then I read the realm. Every account that signs in through Google or GitHub is put into admins automatically, on every login. That's convenient for the other tools behind Keycloak and fatal here: a group rule would make any Google account a Trino admin. And retiring the proxy had retired its email allow-list with it.

So the allow-list moved to Keycloak, where it covers the browser, the CLI and DBeaver alike. After Google or GitHub has signed someone in, a short Keycloak login flow checks the account's email against a list kept in Git and refuses everyone else. Nobody has to be created in advance: a listed person is in at their first sign-in. In short:

post-broker-allowlist:              # runs after every Google or GitHub sign-in
  deny-unless-allowed-email:        # only when the condition below holds
    - condition: user attribute
      attribute_name: email
      attribute_expected_value: you@example\.com|second@example\.com
      regex: "true"
      not: "true"                   # i.e. the email is NOT on the list
    - deny access                   # "not on the allow-list for this service"
  allow access:                     # everyone who got past the step above

With Keycloak deciding who gets in, Trino's rules stay simple: every person is an admin. People arrive as their email; workloads arrive as service-account names, which never contain @:

catalogs:
  - user: .+@.+
    catalog: .*
    allow: all
queries:
  - user: .+@.+
    allow: [execute, kill, view]
  - allow: [execute]

(The rules file itself is JSON; the shape is the same.) Adding a person is one email in Git and an apply. Nobody is added to a group, and Keycloak's own admins group isn't used at all, so a Trino admin can't administer the realm or its sign-in flow.

My first version listed the admins by email in Trino's rules and kept the group membership in Keycloak. It worked, but every new person had to sign in once, be refused, and then be added by hand. Checking the email at sign-in removed that step.

What broke on the way

  • A setting Trino no longer has. I added one for accepting sign-ins forwarded over HTTP, found by name in Trino's own code. Trino 451 marks it defunct and refuses to start with it, so the coordinator crash-looped until it came out. The setting that does the job, honouring the forwarded headers, was already on.
  • Refresh tokens broke every SQL client. With them on, Trino hands clients its own encrypted token. The service-account check, first in the list, can't parse an encrypted token and throws instead of declining, so every CLI query got a 500. Signing in through the browser still worked, which hid it. I reproduced it with a fake encrypted token (500) next to a forged signed one (401, as it should be), then turned refresh tokens off. A session now lasts as long as one Keycloak token, and then the client signs in again.
  • The allow-list refused the person it was for. The first version of the flow had only the conditional step. For an allowed email the condition didn't fire, so the step was skipped, the flow ended with nothing that had succeeded, and Keycloak failed the sign-in anyway, with "Invalid username or password". That isn't the deny step's message, which is what gave it away: the deny step says "access denied". Keycloak ships an "Allow access" step for exactly this, to end a flow after its conditions, and adding it fixed it. A throwaway test of the rules couldn't have caught this one; it took a real browser sign-in.
  • The CLI pretends to be your laptop. Signed in as my email, my first query was refused: User you@example.com cannot impersonate user george. The CLI sends the laptop's login name as the session user, and nobody may act as someone else. That refusal is the rule working; --user fixes the client.

Checked

Check Result
the web UI redirects to Keycloak's trino realm, then opens with a Log Out button
the Trino CLI after sign-in, SELECT current_user you@example.com
the same person, catalogs and a Bronze read audit, iceberg, system; 1,140 rows
a query with no token 401, offering both kinds of sign-in
a token shaped like Keycloak's but signed with another key 401
a pod that isn't the gateway, on the web port 403 at the sidecar
the dbt build and the OpenMetadata crawl afterwards 23 of 23 passed and merged; crawl finished with 0 errors
a listed email signing in through the allow-list, then a Gold query signed in at the first try; 20 rows from marts_football.matches, and the query is in the audit table under that email with the 15 columns it read

Keycloak's sign-in page for the trino realm: TRINO UI SSO, with Google and GitHub and no Forgot Password link

Trino's own sign-in, in its own Keycloak realm. There's no "Forgot Password?" link: resetting a password would sign someone in without the allow-list check.

The Trino web UI after sign-in: cluster overview, version 451, environment PLATFORM_TRINO, with a Log Out button

Through Keycloak and into Trino as a named person; the Log Out button belongs to that session.

Proving it: who read what

Rules decide what may happen. They don't tell you what did. When someone asks "who read the raw match data last week?", the answer has to come from a record, not from the rules.

Trino has a query history, but it lives in memory. Every coordinator restart erases it, and this lab powers off every night. So the history had to go somewhere that lasts.

Writes were already on record

The write side came for free with the catalog stage. Once Nessie knew who each caller was, it started stamping that identity on every commit:

Commit on main Committer
Merged dbt-audit system:serviceaccount:mlops:dbt-runner
Merged ingest-football-… system:serviceaccount:mlops:xgboost-iceberg-publisher

Nessie keeps that history in Postgres, so it survives restarts, and it's per identity, like a Git log of the data.

Nessie's commit history on main: the audit receiver committing to audit_log.trino_queries as system:serviceaccount:mlops:trino-audit, and dbt-runner merging dbt-audit into main

Nessie's history on main: every commit carries its writer. dbt's merge of dbt-audit is signed by dbt-runner; the audit rows are signed by trino-audit, the only identity allowed to write them.

Reads go into the lakehouse they audit

For reads, Trino's HTTP event listener sends one JSON event for every finished query. A small receiver collects the events and appends them, about once a minute, to an Iceberg table, audit_log.trino_queries. Each row says who ran the query, from which client, the SQL, the tables and columns it read, the table it wrote, whether it succeeded, and how long it took. The raw event is kept too, so nothing is lost to a field I didn't think to extract.

The receiver writes through the Python Iceberg library, never through Trino. An insert through Trino would itself be a query, which would produce an event, which would need an insert.

Who read what: every query from Superset, dbt, the OpenMetadata crawl or a person goes through Trino, whose event listener posts it to the trino-audit receiver, which appends it to the Iceberg table audit_log.trino_queries, guarded by Nessie, Trino and Istio

An audit trail nobody else can edit

An audit table that anyone can edit isn't an audit. Three layers keep it honest:

  • Nessie: the receiver gets its own lane, which may change audit_log on main and nothing else. Every other writer's lane now excludes audit_log. Nessie's rules can look at the table path, not just the branch:
audit_writer: "role == 'system:serviceaccount:mlops:trino-audit' && ref == 'main' && (op == 'COMMIT_CHANGE_AGAINST_REFERENCE' || (op in ['CREATE_ENTITY','UPDATE_ENTITY','DELETE_ENTITY'] && (path == 'audit_log' || path.startsWith('audit_log.'))))"
  • Trino: admins may read the table and nothing more; everyone else can't read it or even see its name.
  • The mesh: only Trino's own identity may send events to the receiver, so nobody can slip in fake rows.

The trickiest case was dbt. Its branch is a sandbox where it may do anything, and it merges that branch into main. Could it change the audit table on its branch and merge it in? No: Nessie checks a merge per table, against the rules on the target, so that merge is refused.

What broke on the way

  • The listener's name. The plugin's settings all start with http-event-listener, so I used that as its name. Trino registers it as http, refused to start, and the coordinator crash-looped for about twelve minutes until the fix went in. The error message listed the right names; I should have read the plugin's registration before guessing.
  • Hidden isn't first-match. Reading a table follows the first rule that matches, so the audit rule at the top refused everyone. Listing a schema follows any rule that grants something in it, and dbt's broad "read everything" rule still showed the name audit_log. That rule now excludes it by name.
  • Partitioning needed an extra package. Writing to a table partitioned by day needs an optional native part of the Python library. At a few hundred queries a day, partitioning saves nothing, so the table isn't partitioned.

Checked

Check Result
the rules on a throwaway Nessie, including dbt's branch-and-merge attempt 31 of 31 behaved as intended
the receiver with Nessie down, then back 5 events held through four failed attempts, all written once Nessie returned
Trino, the publisher and dbt each creating a table in audit_log on the live catalog refused (403); nothing created
the receiver writing outside audit_log, or creating a branch refused (403)
three workloads reading the audit table, in both catalogs, or listing it 9 of 9 refused or hidden
dbt build and OpenMetadata crawl with the audit running 23 of 23 passed and merged; crawl finished with 0 errors
the audit table after those runs 137 queries by user, with the refused attempts to read the audit table among them

A dashboard tool that doesn't become a back door

The lakehouse needed somewhere for people to look at the data without a SQL client: charts, dashboards and a web SQL editor. That's Apache Superset. It's also the classic way to undo everything above. The usual setup gives a BI tool one shared database login, so every chart runs as "superset", the audit table fills up with one name, and the tool can read whatever that login can.

So Superset gets no data rights of its own. It signs people in, and asks Trino to run each query as that person.

Who Superset is, and who it speaks for

The identity chain has three links, each checked by a different system:

Link Proved by Checked by
the person signing in to Superset Keycloak, realm trino, behind the same email allow-list Keycloak's post-login flow
Superset itself, connecting to Trino a Kubernetes token for the superset service account, audience trino, rotated hourly Trino's JWT check, and the mesh fence on port 8443
the person the query runs as Superset's "impersonate logged in user" setting Trino's impersonation rule

The impersonation rule is one line in the same rules file as before:

impersonation:
  - original_user: superset
    new_user: you@example\.com|second@example\.com   # the sign-in allow-list, by exact email
    allow: true

Superset may act only as the people on the sign-in allow-list, and nothing else. It can't act as dbt-runner or trino-audit, and on its own it can't even open the iceberg catalog. If someone took over the Superset pod, they'd hold a token that can only borrow a person's name, and Trino would record that person's name next to Superset's in every row of the audit table.

That's also why Superset's sign-in has to sit in the trino realm and nowhere else. Trino treats every email as an admin because only listed people can get one through Keycloak. Superset bypasses Trino's sign-in, so it must pass through the same list, and it does: its Keycloak client lives in the same realm, behind the same post-login check. One list in Git covers the Trino UI, the CLI, DBeaver and Superset.

The token is read from the mounted file every time Superset opens a connection to Trino, so it's never stored in Superset's database and never older than an hour:

config: |
  TRINO_TOKEN_FILE = "/var/run/secrets/trino/token"

  def DB_CONNECTION_MUTATOR(uri, params, username, security_manager, source):
      if uri.drivername == "trino":
          from trino.auth import JWTAuthentication
          with open(TRINO_TOKEN_FILE) as token_file:
              token = token_file.read().strip()
          connect_args = params.setdefault("connect_args", {})
          connect_args["auth"] = JWTAuthentication(token)
          connect_args["http_scheme"] = "https"
          connect_args["verify"] = "/stackable/tls/ca.crt"
      return uri, params

Run by an operator, not a chart

Superset's Helm chart is no longer maintained, and the project's own docs now point at the Superset Kubernetes Operator. Superset is one resource in Git; the operator builds the Deployment, the Service and superset_config.py from it, and runs the database migration and superset init as tasks whenever the image or the config changes. Its metadata lives in a new database in the same Postgres cluster as everything else, and its secrets come from Vault like every other app here.

The image is built in the same pipeline as the other lakehouse images, with the Trino driver, the Postgres driver and the OIDC library baked in. The stock image had 4 critical and 121 high findings that a fix existed for; the built one passes the scan gate with none. The few that can't move without breaking Superset's own pins are listed in Git with a reason and an expiry date.

What broke on the way

  • The operator stripped the certificate request. Superset needs Trino's CA to verify its TLS. dbt gets it from the Stackable secret operator through a volume claim whose annotations say which certificate to issue. Inside the Superset resource, those annotations vanished: the operator's schema doesn't keep the claim template's metadata, so the claim arrived without a class, and the migration pod waited forever with "missing field secrets.stackable.tech/class". An inline CSI volume carries the same settings as ordinary fields, and those survive.
  • Read-only meant unreadable. The certificate files arrive owned by root and readable by a group. Kubernetes hands that group to the pod's fsGroup, but skips it when the volume is marked read-only, so Superset's user got "Permission denied". The volume itself is now writable and the container mounts it read-only.
  • The Service had a hyphen. The operator names the web Service superset-web-server; my route pointed at superset-webserver, and the gateway answered 503.
  • Any email was too wide. My first impersonation rule let Superset act as any name with an @ in it, because only allow-listed people can sign in. But Trino treats every name with an @ as an admin, and Superset's token doesn't go through Keycloak. So a stolen Superset token could have invented x@y and had full rights. The rule now lists the same emails as the Keycloak allow-list, and the daily check below tries an invented name to prove it's refused.
  • Unnamed columns can't be charted. SELECT count(*) works in the SQL editor, but turning it into a chart wraps it in another query that refers to the column as _col0, and Trino refuses a name that was never given. count(*) AS matches fixes it. The audit table recorded the failure like any other query, which is how I found it.

Checked

Check Result
a listed person signs in to Superset through Keycloak's trino realm with Google; created in Superset on first sign-in
that person queries Gold in the SQL editor 1,140 rows from marts_football.matches
the same query in the audit table user = the person's email, principal = system:serviceaccount:mlops:superset, source Apache Superset
Superset asking to act as dbt-runner, lakehouse-reader or trino-audit refused: User superset cannot impersonate user dbt-runner
Superset asking to act as an invented email refused, every day, by the check below
dbt's token asking to act as a person refused: User dbt-runner cannot impersonate user you@example.com
Superset as itself, with no person refused: Cannot access catalog iceberg
a person's failed queries through Superset in the audit table too, with their errors (MISSING_SCHEMA_NAME, COLUMN_NOT_FOUND)

Superset SQL Lab counting PERMISSION_DENIED rows in the audit table by user: om-ingestion 32, dbt-runner 38, lakehouse-reader 6, trino-audit 1, superset 18, probe@example.invalid 15, one person 1

Every refusal lands in the audit table, so Superset can count them by caller. Most are the daily check below doing its job; probe@example.invalid is the invented person Superset is never allowed to act as.

Superset SQL Lab listing the latest refusals with their caller, service account and Access Denied message

The latest refusals, newest first. dbt can't write to Bronze or read the audit table, the crawl can't touch the CI catalog, Superset can't read as itself, and nobody gets to invent a user.

Checked every day, not once

Every table in this article was true on the day I wrote it. Rules drift: a new job gets a broad grant to get it working, a lane gets widened for a test, and nobody narrows it again. So the checks became a job of their own.

A GitHub Actions workflow runs every morning, after the lab has booted and the daily jobs have finished. It reads a list of cases from Git, 28 of them today. Each case names an identity, a target and an action, and says whether it must be allowed or refused:

- name: superset cannot impersonate an invented user
  identity: superset
  target: trino
  op: query
  arg: SELECT 1
  impersonate: probe@example.invalid
  expect: deny
  layer: authz

For each case, a short-lived Job runs as that service account, with its real token, and tries it. Ten cases must pass and eighteen must be refused, and the refusals are checked at the right layer: five at the mesh (the connection never opens), two at authentication (a token for the wrong audience), and eleven at the rules. An unexpected allow is a security hole; an unexpected refusal is a broken lane. Either fails the run.

Borrowing identities is exactly what an attacker would want to do, so the probes are fenced too. When the CI runner creates a Job as one of these service accounts, Kyverno admits it only if it runs exactly python3 rbac_probe.py, in one container, with no Secrets and no volumes except its own token and Trino's CA.

GitHub Actions run of M2M RBAC conformance: plan, 26 phase-1 jobs, phase 2, phase 3 and report all green; 28 cases, 10 expected allows and 18 expected denies

One morning's run: 28 cases, each a short-lived pod holding one workload's own token. Green means every allow got in and every deny was refused.

What comes next

  • Column-level rules. Gold is all-or-nothing for a reader for now; masking or hiding a column is Trino's next layer.
  • Keeping the audit table lean. With Nessie as the catalog, the table's own metadata only ever holds the current snapshot; each flush becomes a Nessie commit instead, so Iceberg's usual snapshot expiry has nothing to do. What piles up is old data files, left behind by compaction and earlier commits. The catalog's garbage collector already covers the audit table, keeping 30 days, but it only records what it would delete for now. Letting it actually delete is the next step.
  • Who signed in. Keycloak can record sign-ins too, which would put logins beside queries.

How reliable is it?

If this happens What the platform does Evidence from the live cluster
An unknown pod tries to query Trino The Trino pod's sidecar refuses the connection test pod with the default service account: connection reset; Nessie 403
The nightly build runs after the policy It is on the list, so it runs as before 23/23 dbt models and tests passed and merged
istiod restarts The policy is already in every sidecar, so enforcement continues Istio pushes policy to the sidecars; each pod enforces locally
A workload sends no token, a wrong one, or claims another name Trino refuses it 401 for a missing, wrong-audience or foreign token; impersonation refused
A token leaks It expires within the hour and only works against Trino tokens are minted per pod with audience trino and a 3,600-second lifetime
Something tries to write to main through Trino Refused; only the admin may, so main changes only through dbt's tested merge dbt's own direct write to main was refused
A Gold-only reader asks for raw data Refused, and the raw schemas aren't even listed Access Denied on Bronze and Silver; only Gold schemas shown
A workload tries to merge into main or delete a tag it doesn't own Nessie refuses it by identity, whatever the mesh allows 13 of 13 out-of-lane writes refused; main unchanged
One of the two Nessie replicas restarts The other serves; rules and keys are config, so both enforce the same every change in this stage rolled out one replica at a time, and the checks passed after each
A person signs in and claims another name Refused; the session user must be the signed-in person User you@example.com cannot impersonate user george
Someone presents a token that looks like Keycloak's Refused unless Keycloak's own keys signed it forged token: 401
The audit receiver restarts, or Nessie is unreachable Trino retries its events; the receiver keeps what it holds and writes it when Nessie is back throwaway test: 5 of 5 events written after an outage
Anything but the receiver tries to change the audit trail Nessie refuses it by identity and table path live: Trino, the publisher and dbt each refused; dbt's branch-and-merge attempt refused on the throwaway
A workload asks for the audit table Refused, and the schema isn't listed 9 of 9 refused or hidden
Someone takes over the Superset pod Its token can only act as a person, never as a workload, and every query names that person and Superset superset cannot impersonate user dbt-runner; Cannot access catalog iceberg as itself
Superset's Trino token expires Superset reads a fresh one for every connection the kubelet rotates it hourly; it's never stored in Superset's database

And the honest limits:

  • Trino is one coordinator. If it restarts, queries fail until it's back. The policy doesn't change that.
  • Every allowed person is a full admin. There is one tier of person for now. A read-only analyst would need a second list and a role or group in the token, which Trino doesn't read yet.
  • The password form is still on the sign-in page. Keycloak draws the Google and GitHub buttons as part of it, so it can't be removed. It's no longer a way around the list: a password sign-in runs the same email check, and "Forgot password" is off, because resetting a password signs you in without passing the check.
  • Rules are per schema, not per column. Gold is all-or-nothing for a reader; hiding a column (masking) would be the next step.
  • The bucket is still guarded per app, not per person. SQL goes through Trino's rules and the catalog through Nessie's, but the files underneath are protected by per-app S3 keys.
  • An admin's port-forward skips the fence. kubectl port-forward enters the Trino pod from inside, so the mesh policy never sees it. The token check and the rules still apply, which is how I can test lakehouse-reader at all, but only someone who may port-forward into mlops can do it.
  • Catalog reads are open to anything the mesh admits. Anonymous reads are what keep the UI and the crawl simple; the mesh list is what limits them.
  • Trino's catalog token is fixed at start-up. It's valid for seven days. A Trino that ran a week without a restart would lose catalog access; the nightly power-off makes that impossible here, and a Trino version whose client refreshes its own token would remove the limit.
  • The public key is copied by hand. If the cluster's signing key changes, it has to be updated, and until then Trino refuses everything.
  • Only reads through Trino are audited. Reading tables straight through the catalog with the Python Iceberg library, or reading files from the bucket, doesn't go through Trino and isn't in the audit table. Writes are covered either way, by Nessie's commit history.
  • The receiver is one pod. A crash loses at most the events it was holding, about a minute's worth; a restart is covered by Trino's retries.
  • Superset is one pod, on an alpha API. If it restarts, dashboards are down for a minute; its state is in Postgres. The operator's API is v1alpha1, so its version is pinned and read before every upgrade.
  • Every person who signs in to Superset is a Superset admin. That matches Trino, where every listed person is an admin. What they can read is still Trino's decision, not Superset's.
  • A query refused before it runs has no table list. Trino reports the tables only for queries it planned, so those rows keep the SQL but leave the tables empty.

Trino's worker status page: a single node, the coordinator itself, with 2 processors and a 1.25 GB heap

The first limit, on Trino's own worker page: one node, and it's the coordinator.


For the next build in this series, 🚀 Follow me on LinkedIn

Author: George Ezejiofor

About the author

  • I'm an AI/ML Platform and MLOps Engineer and a Kubestronaut, with 13+ years in IT and 5+ in DevOps and DevSecOps. Through my consultancy, GeoCloudTech, I design secure, highly available Kubernetes platforms for regulated industries, on cloud and on-premises. What I build: - Kubernetes platforms: RKE2, AKS, EKS, GKE - MLOps: Kubeflow, KServe, MLflow, NVIDIA GPU Operator - DevSecOps: Vault, Kyverno, KubeArmor, Trivy, signed supply chains with Tekton and Cosign - GitOps and automation: Argo CD, Flux, Terraform, Ansible - Storage and identity: Rook Ceph, CloudNativePG, Keycloak - Observability and networking: Prometheus, OpenTelemetry, Cilium, Istio Most of what I publish comes from my multi-datacentre homelab: RKE2 on Proxmox, run through GitOps. My rule: build it, break it, understand it, then harden it. Every article is a real build, traps included. Certifications: Kubestronaut (CKA, CKAD, CKS, KCNA, KCSA), HashiCorp Terraform Associate.

No comments yet. Be the first to comment.