Locking down local files in Apache Kyuubi

·

We run Apache Kyuubi as the front door to Spark on our Hadoop clusters. People connect to it over JDBC, pipelines submit batch jobs through its REST API, and in both cases Kyuubi launches spark-submit on their behalf. This year we moved our jobs’ credentials (third-party API keys, service-account files, etc.) out of HDFS and into a read-only directory on the Kyuubi servers. That move is only safe if Kyuubi decides, per user, which of those files a Spark job may pick up. Out of the box it can’t, so I wrote a plugin that does: kyuubi-spark-local-file-acl, which we’ve open-sourced.

The problem: spark-submit reads files as Kyuubi

Spark has a family of settings that ship files along with a job: spark.files, spark.jars, spark.archives, spark.yarn.dist.files, spark.kerberos.keytab and a few more. When one of them holds a local path, spark-submit reads that file and distributes it to the driver and executors. Kyuubi runs spark-submit on its own server, as its own service user. So any file that user can read, any session can ask for: the server’s configuration, Kyuubi’s keytab, TLS keys, or the credentials another team’s pipeline depends on.

Kyuubi does have a guard for this. kyuubi.session.local.dir.allow.list requires local paths to sit under one of a set of directories. It has two limits. The list is the same for every user, so a directory of secrets that one pipeline needs is open to everyone. And while testing it, I found it could be bypassed: Spark accepts these keys without the spark. prefix (files works as well as spark.files), Kyuubi adds the prefix when it builds the spark-submit command, but the allowlist check didn’t cover the unprefixed forms. I reported it to the Apache Kyuubi security team; it’s now CVE-2026-62391, fixed in Kyuubi 1.12.0.

Even with that fixed, a server-wide directory list can’t say “this pipeline may read these three files and nothing else”. That needs a policy keyed on who is asking.

A checkpoint before spark-submit

Kyuubi has an extension point for exactly this: SessionConfAdvisor. It is called with the authenticated user and the session’s configuration before the Spark engine is launched, and it can either return extra configuration or throw to reject the session. The plugin is an advisor that returns nothing and throws a lot. For every policed key, it resolves each local path in the value and checks it against a YAML policy:

version: 2

users:
  alice:
    - '/opt/kyuubi/resources/alice/*.conf'
    - '/opt/kyuubi/resources/libraries/**/alice-*.jar'

groups:
  data-engineering:
    - '/opt/kyuubi/resources/shared/*.properties'
    - '/opt/kyuubi/certificates/{development,staging}/*.pem'

The rules are deliberately boring:

  • There are no deny rules. A path that matches nothing is denied.
  • A user’s permissions are the union of their own rules and the rules of every Hadoop group they belong to.
  • Submitted paths are canonicalized with toRealPath() before matching, so a symlink can’t lead out of an allowed directory.
  • Glob patterns are off unless explicitly enabled, and an exact rule must name a file that exists, so a typo doesn’t quietly authorize a file someone creates later.
  • Keys are normalized the same way Kyuubi’s own SparkProcessBuilder.convertConfigKey does it, so files, jars and yarn.dist.files are policed along with their spark.-prefixed forms. The gap behind the CVE can’t reopen here.

The policy reloads without a restart. Each reload re-checks that the file is owned by the Kyuubi administrator and isn’t group- or world-writable, reads it with a size bound, and only accepts it if nothing changed mid-read. If the new policy is invalid, the plugin fails closed: it doesn’t keep using the last good policy, it rejects sessions that reference local files until a valid one is in place. Sessions that only use remote paths (hdfs:, s3a: and so on) are never affected; those are the storage system’s job.

The tricky part: batch uploads

Kyuubi’s REST batch API lets a client upload its jar along with the submission. Kyuubi stages the file at <upload-root>/<batch-id>/app.jar before the advisor runs and passes that local path in the configuration. To an ACL, that path looks like any other local file, and no administrator can write a rule for a directory named after a batch ID that doesn’t exist yet. So a batch is allowed to read its own uploads without consulting the policy, and only its own: any other path under the upload root is denied outright, even if a broad pattern like /** would match it. Otherwise one user’s batch could name another batch’s directory and read what was uploaded there.

To know which batch it’s looking at, the advisor relies on two keys Kyuubi injects into batch sessions: kyuubi.batch.id and kyuubi.batch.resource.uploaded. Nothing marks them as server-supplied, so an interactive JDBC client can simply set them in its connection string and claim to be someone else’s batch:

jdbc:kyuubi://host:10009/;?kyuubi.batch.resource.uploaded=true;kyuubi.batch.id=<their-batch-uuid>;spark.files=<upload-root>/<their-batch-uuid>/app.jar

The fix is to have Kyuubi strip those two keys from interactive sessions with kyuubi.session.conf.ignore.list. The advisor then sees no current batch and denies the path. The plugin’s integration tests run this exact attack against a real Kyuubi server.

The obvious alternative, kyuubi.session.conf.restrict.list, which rejects a session outright instead of quietly dropping the keys, breaks every batch submission on Kyuubi 1.11. Kyuubi adds those two keys to every batch itself. Batch sessions look exempt from the restrict list, because KyuubiBatchSession overrides normalizedConf with a check that only consults the batch ignore list. But overriding a val in Scala doesn’t stop the superclass’s initializer from running, and that initializer validates the full configuration against the restrict list first. Its result is thrown away, its exception isn’t, so the server rejects the keys it injected itself.

Every decision is logged

Each authorization decision is written as one line to a dedicated log category, in a fixed format that’s easy to parse:

event=local_file_acl decision=ALLOW user="alice" key="spark.files" resource="/opt/kyuubi/resources/alice/app.conf" reason="user-rule" principal_type="user" principal="alice" pattern="/opt/kyuubi/resources/alice/*.conf"
event=local_file_acl decision=DENY user="mallory" key="spark.files" resource="/etc/kyuubi/kyuubi.keytab" reason="no-matching-rule" principal_type="" principal="" pattern=""

Values are escaped, including the Unicode line separators some log processors treat as line breaks, so a crafted username or path can’t forge a record. Policy reloads are logged in the same stream, so you can see when the policy changed next to the decisions it made. We load these records into a table with a dashboard on top. The stream of denials turned out to be useful in two ways: it shows anyone trying to read a file they shouldn’t, and it shows any job we broke during the migration.

What it doesn’t cover

  • The check happens before spark-submit reads the file. A file swapped between the check and the read isn’t caught; closing that gap would mean staging a trusted copy, which is out of scope.
  • A batch’s main resource (its application jar) never reaches the advisor. Keep kyuubi.session.local.dir.allow.list configured for it, and on Kyuubi 1.12 or later add kyuubi.server.spark.file.config.list as a server-wide upper bound.
  • Rejection depends on Kyuubi aborting the session when the advisor throws, which is current behaviour rather than a documented contract. It’s worth re-checking on every Kyuubi upgrade.

Trying it

The plugin is built and tested against Kyuubi 1.11.1 on JDK 17 and 21. Build it with mvn package, put the jar on the Kyuubi server’s classpath, and register it in kyuubi-defaults.conf:

kyuubi.session.conf.advisor=com.automattic.kyuubi.spark.localfileacl.SparkLocalFileAclAdvisor
kyuubi.session.conf.ignore.list=kyuubi.batch.resource.uploaded,kyuubi.batch.id

The plugin’s own settings go in as JVM system properties in kyuubi-env.sh, so a session can never override them:

export KYUUBI_JAVA_OPTS="$KYUUBI_JAVA_OPTS \
  -Dkyuubi.local.file.acl.rules.file=/etc/kyuubi/kyuubi-local-file-acl.yaml \
  -Dkyuubi.local.file.acl.reload.interval=PT60S \
  -Dkyuubi.local.file.acl.wildcards.enabled=true"

The README covers the rest: every setting, the audit log configuration, and why each choice was made. It’s Apache 2.0 licensed, and issues and pull requests are welcome.

Comments

2 responses to “Locking down local files in Apache Kyuubi”

  1. […] The credentials project is the clearest example. While hardening how our Spark jobs read local files through Apache Kyuubi, I dug into Kyuubi’s own protection for this and found that an earlier security fix was incomplete. I reported it to the Apache Kyuubi security team, and it’s now CVE-2026-62391, fixed in Kyuubi 1.12.0. We also built and open-sourced a plugin that adds per-user access control on top; I wrote about it in Locking down local files in Apache Kyuubi. […]

  2. […] Addendum: HiveServer2 was retired at the end of 2023, keeping only the Hive metastore as the catalog for Spark and Trino. Running every user’s Spark jobs through one gateway also raised its own security questions, which I wrote about in Locking down local files in Apache Kyuubi. […]

Leave a Reply

Your email address will not be published. Required fields are marked *