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
463 changes: 453 additions & 10 deletions Cargo.lock

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,43 @@ pbkdf2 = { version = "0.13.0", default-features = false, features = ["hmac"] }
hmac = "0.13.0" # PRF backing PBKDF2
zeroize = "1.9" # Wipe derived key material on drop

# JWT private-key client-credentials auth (service-principal M2M with a
# signed client assertion instead of a client secret). Mirrors the JDBC
# driver's JwtPrivateKeyClientCredentials. We sign with `jsonwebtoken`
# (RS/PS/ES families, backed by `ring` — already in the graph via rustls,
# so this adds no new heavyweight dependency) and load PEM/PKCS#8 keys
# with the RustCrypto `pkcs8`/`sec1` family. This deliberately avoids the
# `openssl` crate to preserve the pure-Rust/rustls posture the napi
# binding depends on (see the `reqwest` / `[features]` TLS notes above);
# the one accepted gap vs. JDBC/BouncyCastle is ES512 (P-521), which
# `ring` does not support. All crates are dual Apache-2.0/MIT.
#
# Pinned to 9.x deliberately. jsonwebtoken 10.x dropped the built-in
# `ring` backend and forces an explicit crypto backend, both of which
# regress us: `rust_crypto` pulls `rsa` (RUSTSEC-2023-0071, Marvin) into
# the RUNTIME crate, and `aws_lc_rs` links a C library (AWS-LC) that
# breaks the pure-Rust posture and adds a recurring C-CVE maintenance
# tail. 9.x's advisory GHSA-h395-gr6q-cpjc is in the DECODE/validation
# path, which the kernel never exercises (it only signs), so it is
# suppressed with justification in `osv-scanner.toml` rather than paying
# the 10.x cost. Revisit if jsonwebtoken ships a ring-backed 10.x.
jsonwebtoken = { version = "9", default-features = false, features = ["use_pem"] } # JWT signing (RS256/384/512, PS256/384/512, ES256/384); use_pem = PEM key loading (adds pem + simple_asn1, no TLS)
pkcs8 = { version = "0.10", features = ["encryption", "pem", "std"] } # PKCS#8 PEM parsing + PBES2 passphrase decryption

[dev-dependencies]
tokio = { version = "1", features = ["rt-multi-thread", "macros"] }
wiremock = "0.6"
tempfile = "3"
log = "0.4"
# Test-only private-key generation for the JWT auth tests. Keys are
# generated in-process (RSA + P-256, plus a PBES2-encrypted PKCS#8
# variant) rather than committed as PEM fixtures, so the repo's secret
# scanner has nothing to flag and the tests need no `openssl` CLI (which
# the repo deliberately avoids — not present on Windows). These are the
# RustCrypto siblings of the `pkcs8` runtime dep. dev-only: never linked
# into the shipped crate.
rsa = { version = "0.9", features = ["pem"] }
p256 = { version = "0.13", features = ["pkcs8", "pem"] }

# TLS backend selection.
#
Expand Down
13 changes: 13 additions & 0 deletions NEXT_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@ changes go in their respective binding's NEXT_CHANGELOG.

### Added

- Auth: `AuthConfig::OAuthM2MPrivateKey` — OAuth 2.0 machine-to-machine using a JWT
private-key client assertion (RFC 7523) instead of a client secret. The kernel
signs a short-lived JWT with a PEM/PKCS#8 private key (RSA or EC; unencrypted or
PBES2-passphrase-encrypted) and sends it as the `client_assertion` in the
client-credentials grant. Supported algorithms: `RS256`/`384`/`512`,
`PS256`/`384`/`512`, `ES256`, `ES384` (default `RS256`); `ES512` is not supported
and is rejected with a clear error. Construct via `AuthConfig::oauth_m2m_private_key`.
- C ABI: `kernel_session_config_set_auth_m2m_jwt()` — expose the JWT private-key M2M
flow over the C ABI (for ODBC / Go consumers), alongside the existing
`set_auth_pat` / `set_auth_m2m` / `set_auth_u2m` setters. Required `client_id` /
`jwt_key_file` / `jwt_kid`; optional `jwt_passphrase` (encrypted PKCS#8),
`jwt_algorithm` (NULL → `RS256`), `scopes` (comma-separated; NULL → `all-apis`),
and `token_url` (NULL → OIDC discovery). Maps to `AuthConfig::oauth_m2m_private_key`.
- C ABI: `kernel_session_config_set_retry_config()` — expose the crate's existing
HTTP retry knobs (`HttpConfig::retry_min_wait` / `retry_max_wait` /
`retry_max_retries` / `overall_timeout`) over the C ABI so a host can make its own
Expand Down
31 changes: 30 additions & 1 deletion deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,36 @@ all-features = true

[advisories]
yanked = "warn"
ignore = []
ignore = [
# RUSTSEC-2023-0071 — "Marvin Attack": RSA timing sidechannel in the
# `rsa` crate. No fixed version exists (only 0.10 release candidates;
# stable 0.9.x is still affected), so it cannot be cleared by a bump.
#
# `rsa` is a DEV-ONLY dependency here: it generates RSA test keys
# in-process for the JWT auth unit tests (`src/auth/oauth/test_keys.rs`)
# so we don't commit PEM fixtures (secret scanner) or shell out to
# `openssl` (not on Windows). Verified dev-only via `cargo tree -i rsa`
# — it is never linked into the shipped kernel, pyo3, or napi artifacts,
# so the timing sidechannel is not reachable by any driver consumer.
# The runtime signing path uses `jsonwebtoken` (ring), not `rsa`.
#
# We keep `rsa` (rather than dropping RSA test coverage for EC-only)
# because RS256 is the JDBC default and the most common real-world key
# type, so exercising the RSA load+sign path in tests has value.
# Re-evaluate when `rsa` ships a constant-time stable release.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Low — The RUSTSEC-2023-0071 (rsa Marvin attack) ignore is global by advisory ID — cargo-deny's [advisories].ignore has no per-package/dev-only scoping. The justification correctly notes rsa is dev-only today, but if a future change ever pulls rsa into the runtime graph (e.g. adopting a jsonwebtoken 10.x rust_crypto backend, exactly the path the Cargo.toml note contemplates), this entry will silently keep suppressing the advisory in shipped code, defeating the CI gate. Consider pairing the ignore with a [bans] deny that forbids rsa outside dev-dependencies, or at minimum note in the comment that the ignore is unconditional and must be removed the moment rsa moves to a runtime dep.

"RUSTSEC-2023-0071",
# RUSTSEC-2026-0258 — "h2 unbounded empty DATA frames". A DoS advisory
# in `h2 0.4.15`, pulled in transitively via `hyper` <- `reqwest`
# (`cargo tree -i h2`); not a direct dependency and unrelated to this
# crate's code. 0.4.15 is already the latest 0.4.x (a `cargo update -p
# h2` is a no-op), so it cannot be cleared by a bump; clearing it needs
# an upstream `hyper`/`reqwest` release that requires the fixed `h2`.
# The advisory concerns a server-side frame-flood; the kernel is an
# HTTP *client* to Databricks SEA, so the attack surface is not exercised
# here. Pre-existing on `main` (fires against the shared reqwest stack,
# not this PR). Re-evaluate when the reqwest/hyper stack picks up the fix.
"RUSTSEC-2026-0258",
]

[licenses]
# Permissive licenses we allow in transitive deps. Adding a new
Expand Down
16 changes: 16 additions & 0 deletions include/databricks_kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,22 @@ KernelStatusCode kernel_session_config_set_auth_pat(KernelSessionConfig* config,
KernelStatusCode kernel_session_config_set_auth_m2m(KernelSessionConfig* config,
const char* client_id,
const char* client_secret);
/* OAuth M2M via a JWT private-key client assertion (RFC 7523): the kernel signs
* a short-lived JWT with the private key and sends it as the client_assertion
* instead of a client secret. `client_id`, `jwt_key_file` (PEM/PKCS#8 private
* key path), and `jwt_kid` (key id in the JWT header) are required. Optional
* (pass NULL to omit): `jwt_passphrase` (encrypted PKCS#8 key), `jwt_algorithm`
* (RS256/384/512, PS256/384/512, ES256, ES384; NULL → RS256), `scopes`
* (comma-separated; NULL → kernel default `all-apis`), and `token_url` (explicit
* token endpoint; NULL → discover via OIDC). */
KernelStatusCode kernel_session_config_set_auth_m2m_jwt(KernelSessionConfig* config,
const char* client_id,
const char* jwt_key_file,
const char* jwt_kid,
const char* jwt_passphrase,
const char* jwt_algorithm,
const char* scopes,
const char* token_url);
/* OAuth U2M (user-to-machine: authorization code + PKCE, browser flow).
* All args optional: `client_id` NULL → `databricks-sql-connector` client;
* `redirect_port` 0 → kernel default (8030); `scopes` (comma-separated)
Expand Down
Loading
Loading