capacman opened a new issue, #7874: URL: https://github.com/apache/kyuubi/issues/7874
### Code of Conduct - [x] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct) ### Search before asking - [x] I have searched in the [issues](https://github.com/apache/kyuubi/issues?q=is%3Aissue) and found no similar issues. ### Describe the bug With `USER`/`GROUP`/`SERVER` share level, each Kyuubi session gets a Spark session from `SparkSession.newSession()`. That session starts with the SparkContext configs, i.e. the configs of the connection that launched the engine. During session open, the session's own configs are applied only after anything that may initialize a catalog plugin: 1. `SparkSQLSessionManager.newSparkSession` runs `kyuubi.engine.session.initialize.sql` right after `newSession()`, before any session config is set. 2. `SparkSessionImpl.open` handles `use:catalog` / `use:database` first, and only then applies the remaining session configs via `spark.conf.set`. A V2 catalog plugin reads `spark.sql.catalog.<name>.*` only once, in `CatalogPlugin.initialize`. So if the initialize SQL (e.g. `USE iceberg`) or `use:catalog` touches the catalog, the plugin is initialized with the stale configs, such as the first connection's credentials or URIs, and the configs the client passes for that session are ignored. There is also a related problem. `CatalogManager` resolves catalog configs through `SQLConf.get`, which reads from the thread's active session. `SparkSessionImpl.open` does not activate the new session before switching catalogs, so even with the configs applied first, the catalog can be loaded with another session's configs. Steps to reproduce: 1. Start an engine with share level `USER` and a catalog `spark.sql.catalog.cat=<some CatalogPlugin>` with `spark.sql.catalog.cat.token=engine-launch`. 2. Open a second session that passes `spark.sql.catalog.cat.token=session-token` plus either `use:catalog=cat` or `kyuubi.engine.session.initialize.sql=USE cat`. 3. The catalog's `initialize` receives `token=engine-launch` instead of `session-token`. Proposed fix: - In `newSparkSession`, apply the (modifiable) session configs before running the initialize SQLs. - In `SparkSessionImpl.open`, apply the session configs before `use:catalog` / `use:database`, and switch catalog/namespace with the new session set as active. ### Affects Version(s) master / 1.12 ### Kyuubi Server Log Output _No response_ ### Kyuubi Engine Log Output _No response_ ### Kyuubi Server Configurations _No response_ ### Kyuubi Engine Configurations ```yaml kyuubi.engine.share.level=USER spark.sql.catalog.iceberg=org.apache.iceberg.spark.SparkCatalog # per-connection values passed by the client, e.g. credentials spark.sql.catalog.iceberg.<option>=<value> ``` ### Additional context _No response_ ### Are you willing to submit PR? - [x] Yes. I would be willing to submit a PR with guidance from the Kyuubi community to fix. - [ ] No. I cannot submit a PR at this time. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
