How a notebook reaches Spark
Every notebook kernel on the platform has spark in it, and nothing in the notebook says where
it goes. This page follows that one object: which calls it makes, in which order, with whose
identity, and what each service on the way is allowed to decide. It is for a person who wants to
know what they are using, an administrator who has to explain it, and a reviewer who has to
accept it.
The short version
spark is not a cluster the platform hands you: it is a client that builds a Spark Connect
session for you, on first use, in your own name. It asks Trino which catalogs you can see and
gives the new session one Iceberg catalog per name, each carrying your token, so the catalog
service decides what you may read. Everything past that runs on that token: the driver asks the
catalog, the executors ask the driver, and the table files are reached with a short-lived credential
the catalog vends for each table, not with a storage key of yours — which is the boundary this page
is mostly about.
Step by step
-
The kernel.
sparkis_LazySpark(python/stardelt/notebook.py), pushed into every kernel by%load_ext stardelt.notebook. It holds no connection: the first attribute you touch callsstardelt._session, where all of this happens. A kernel costs nothing until a cell uses Spark. -
The catalogs.
_sessioncalls_catalog_names(), which runsSHOW CATALOGSthrough Trino as you. Trino does the visibility filtering, so the list is already the set of catalogs your access control lets you see; engine-only names (system,information_schema,memory,tpch,tpcds,jmx) and anything that is not a valid platform catalog name are dropped before they can become a Spark setting. With Trino unreachable, the session is built withwarehousealone and says so on stderr. -
The token.
_token()returns your token, not a service account. On a hub-spawned server it isTRINO_TOKEN, which JupyterHub copies into the pod from your sign-in at spawn; within a minute of expiry,_token()re-reads your current token from the hub instead of making you restart. A pipeline pod has no hub behind it and renews through its own client-credentials grant instead. -
The session.
_sessionchecks that the endpoint answers (a three-second socket probe, so a stopped cluster fails in seconds rather than after minutes of retries) and then callsSparkSession.builder.remote(remote).create().create(), notgetOrCreate(): the latter returns the process-wide session, so a second person would inherit the first one's catalogs and token. -
The catalog settings. For each name from step 2, the session sets
spark.sql.catalog.<name>to Iceberg'sSparkCatalog,type=rest,uriat Lakekeeper, the token from step 3,warehouse=<name>, andio-impl=S3FileIOpointed at the platform's object storage. These are session configuration; the server's own configuration has no catalog at all. Each catalog is then loaded once — a catalog the service refuses is left out with one line on stderr — andwarehousebecomes the default when it loaded. -
The engine. The Connect driver is the group's
SparkCluster(spc-<name>-server): a server pod the Spark operator runs, with Kubernetes as the cluster manager. It asks Lakekeeper for the catalog, where your token and your grants are checked; it creates executor pods per query and releases them when the query is done, so an idle cluster runs the driver alone. Executors read and write the table files through Iceberg's S3 client with the credential the catalog vends on every load, scoped to that table; neither the driver nor an executor receives the platform's storage key, and the executor admission policy (spark-cluster-executor-pods) refuses a pod that reads a Secret. -
Your cluster. The session targets the Spark cluster your group owns;
STARDELT_CLUSTERin the notebook's environment names another one you may use. Either way the name reaches Nova's compute API (GET /api/compute) for the cluster's phase and endpoint, and the session is built against the endpoint it reports. Nothing is started implicitly: a stopped or failed cluster raisesClusterStoppedand names the two ways to start it, and one that is starting or stopping asks you to wait.
Who checks what
| The question | Who answers it | What you get |
|---|---|---|
| Which catalogs are there for me? | Trino, through SHOW CATALOGS, and then Lakekeeper | A catalog you have no grant on is refused and left out of the session; the rest are listed. |
| May I read this table? | Lakekeeper, with your token | A grant, or an error — at catalog, schema and table level, per person. |
| Are rows and columns masked? | Trino, once a policy exists | No row filter or column mask can be defined in this release (stardelt/stardelt#50). When one exists it applies to %sql; a spark read is governed by the table's grants, so a masked column is readable there. |
| Which files may the engine touch? | Nobody, per person | Spark: a short-lived, table-scoped credential the catalog vends on every load; it allows the reads and writes your grant allows, and a group SparkCluster's driver and executors carry no platform key. Trino: the platform's S3 key; it reaches the bucket regardless of the table grants. |
| Who may open a Connect channel at all? | Kubernetes, through a NetworkPolicy | From outside the cluster: the cluster's own token-checking front (Envoy jwt_authn, audience spark-connect) on spark-<name>.<baseDomain> over TLS, so a call without a valid token is refused 401, and a valid token from outside the owner group, spec.viewers and the admin group is refused 403. Inside the cluster a notebook pod reaches sc://spc-<name>-server.<ns>.svc.cluster.local:15002 directly, and the cluster's NetworkPolicy admits pods labelled with the owner group, Nova's pods and Airflow workers only, so a scheduled pipeline notebook's pod is still refused. |
The in-cluster NetworkPolicy applies to pods, not to the public route.
Session life
- A renewed token means a new session. Spark reads
spark.sql.catalog.*when it creates the session state, so an initialized catalog cannot be re-keyed;_sessionbuilds a fresh session with the new token and stops the previous one. - A server restart loses the session's contents. DataFrames, temporary views and settings of the old session are gone, and a running job is not retried. The next call notices and opens a new session with one line on stderr.
- Client and server must be on the same Spark line. A newer client mis-reads the server's settings in ways that break later calls, so the pair is checked when the session arrives and a mismatch is refused with a sentence that names both versions.
- Streams do not use this path. A
StreamAppis run by the Spark Operator as aSparkApplicationwith its own driver and executors, not through Spark Connect; see Spark Connect and the Spark Operator.
What changes next
The remaining gaps are known and planned, not hidden. Row filters and column masks do not exist
yet; when they do, they will apply in Trino only, so a Spark read is governed by table grants and
the files the table's credential reaches, not by a policy on the rows. The batch and stream paths —
a SparkApplication, from the Airflow loader or a StreamApp — still hold the platform's storage
key (stardelt/stardelt#494); the Connect path no longer does. Until they land, use %sql where a
policy must apply.