mirror of
https://github.com/lancedb/lancedb.git
synced 2026-12-03 07:45:17 +00:00
fix: read LANCEDB_API_KEY when connecting to remote without api_key (#5166)
## Summary - Rust remote connect reads `LANCEDB_API_KEY` when a `db://` connection has no `api_key` and no `oauth_config`. Python already does this in its own wrapper; Node and Rust callers did not. - An explicit API key still wins. An empty `LANCEDB_API_KEY` is treated as present, matching Python's `is None` check, and the connection sends no `x-api-key` header. - OAuth does not read the variable, so an ambient key cannot turn an OAuth connect into an invalid API-key-plus-OAuth configuration. The fallback lives in Rust `execute_remote`, so Node does not write the credential into the caller's options object. Supersedes #3797, which is stale and conflicting. This addresses the Gatekeeper requests there: do not apply the environment key when `oauthConfig` is set, and do not write it into the caller-owned options. ## Test plan - [x] `cargo test --features remote -p lancedb --lib connection::` (each env case re-runs the test binary as a child process with `LANCEDB_API_KEY` set or removed on the child `Command`; no in-process `set_var`/`remove_var`) - [x] `cargo clippy -p lancedb --all-targets --features remote -- -D warnings` - [x] `cargo fmt --all -- --check` - [x] `cd nodejs && pnpm build` - [x] `cd nodejs && pnpm exec jest __test__/remote_api_key_env.test.ts` (env set only in a child process; missing-key case asserts `connect()` itself rejects against the loopback endpoint; OAuth case asserts `x-api-key` is absent) - [x] `cd nodejs && pnpm lint-ci`; `pnpm run docs` leaves `docs/src/js` unchanged Written with Cursor (Grok). --------- Co-authored-by: Preston Zhao <195942578+canyang25@users.noreply.github.com> Co-authored-by: Xuanwo <github@xuanwo.io>
This commit is contained in:
co-authored by
Preston Zhao
Xuanwo
parent
5373da5760
commit
b3a8e6f08d
@@ -74,6 +74,8 @@ pub struct ConnectionOptions {
|
||||
/// (For LanceDB Enterprise or LanceDB Cloud only): the API key to use.
|
||||
///
|
||||
/// Can also be set via the environment variable `LANCEDB_API_KEY`.
|
||||
/// An explicit `apiKey` takes precedence. The variable is not read when
|
||||
/// `oauthConfig` is set.
|
||||
pub api_key: Option<String>,
|
||||
/// (For LanceDB Cloud only): the region to use for LanceDB Cloud (legacy).
|
||||
/// Defaults to 'us-east-1'.
|
||||
|
||||
Reference in New Issue
Block a user