Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 100 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,18 @@ sha2 = "0.11" # SHA-256 for token cache key generation
open = "5" # Browser launch for interactive OAuth flows
dirs = "6" # Cross-platform config directory (~/.config/)

# Token-cache encryption at rest. The cached OAuth payload holds a
# long-lived refresh token, so it is encrypted with AES-256-CBC under a
# PBKDF2-HMAC-SHA256 key derived from a caller-supplied passphrase. The
# parameters mirror the JDBC driver's EncryptedFileTokenCache so both
# drivers give the same file the same protection. All four are RustCrypto
# crates, dual Apache-2.0/MIT (both already allow-listed in deny.toml).
aes = { version = "0.9.2", features = ["zeroize"] } # AES-256 block cipher
cbc = { version = "0.2.1", features = ["alloc", "block-padding", "zeroize"] } # CBC mode + PKCS#7 padding
pbkdf2 = { version = "0.13.0", default-features = false, features = ["hmac"] } # Passphrase-based key derivation
hmac = "0.13.0" # PRF backing PBKDF2
zeroize = "1.9" # Wipe derived key material on drop

[dev-dependencies]
tokio = { version = "1", features = ["rt-multi-thread", "macros"] }
wiremock = "0.6"
Expand Down
28 changes: 28 additions & 0 deletions include/databricks_kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,34 @@ KernelStatusCode kernel_session_config_set_retry_config(KernelSessionConfig* con
KernelStatusCode kernel_session_config_set_ignore_transactions(KernelSessionConfig* config,
bool ignore);

/* Configure the on-disk OAuth token cache for U2M (browser) auth. Mirrors
* the EnableTokenCache / TokenCachePassPhrase pair exposed by the reference
* ODBC driver and JDBC.
*
* `enabled = true` (the default) persists the refresh token under
* ~/.config/databricks-sql-kernel/oauth/ so the user is not sent through
* the browser on every connection. The file is ALWAYS encrypted
* (AES-256-CBC, PBKDF2-HMAC-SHA256) — there is no plaintext mode. A
* non-NULL `passphrase` keys it; NULL or blank falls back to a
* machine-local derived key, matching the reference driver, which caches
* with an empty TokenCachePassPhrase. Supplying a passphrase is stronger:
* the derived key defends against the cache file being read elsewhere (a
* backup, an image layer, a support bundle), not against an attacker who
* can already run code as this user.
*
* `enabled = false` disables DISK PERSISTENCE ONLY; tokens are still
* reused and refreshed in memory for the session's lifetime, so this does
* not re-trigger the browser flow on every refresh. Use it when the
* process must not write credentials to disk at all. `passphrase` is
* ignored in that case.
*
* Only U2M auth touches the cache; PAT and M2M ignore this setting.
*
* The on-disk format is wire-compatible with the JDBC driver's
* EncryptedFileTokenCache (given the same passphrase). */
KernelStatusCode kernel_session_config_set_token_cache(KernelSessionConfig* config, bool enabled,
const char* passphrase);

/* ─── Session lifecycle ───────────────────────────────────────────────*/

/*
Expand Down
Loading
Loading