diff --git a/docs/src/python/python.md b/docs/src/python/python.md index 8b980b09e..a8ac45844 100644 --- a/docs/src/python/python.md +++ b/docs/src/python/python.md @@ -1522,7 +1522,7 @@ integration = db.create_storage_integration( print(integration.configuration_instructions) ``` -Use `SecretReference` to qualify another database or namespace. Sync and async connections use the same options. Secret values are never part of integration metadata. Azure supports service principal client credentials; managed identity, account key and SAS authentication are not integration modes. +Use `SecretReference` to qualify another database or namespace. Sync and async connections use the same options. Secret values are never part of integration metadata. Azure supports service principal credentials and storage account access keys. The equivalent SQL is: @@ -1539,6 +1539,23 @@ SHOW STORAGE INTEGRATIONS; DROP STORAGE INTEGRATION customer_blobs; ``` +For Shared Key authorization, store the storage account access key in one +Secret and pass its reference as the only credential option: + +```python +integration = db.create_storage_integration( + "customer_blobs_key", + "az://customer-data/raw/", + storage_provider="AZURE", + azure_storage_account="customeraccount", + azure_storage_account_access_key_secret="azure_key", +) +``` + +The equivalent SQL credential option is +`STORAGE_AZURE_STORAGE_ACCOUNT_ACCESS_KEY_SECRET = public.azure_key`. Shared +Key authorization must be enabled on the Azure storage account. + Registration returns setup instructions and leaves `access_verified` false. It stores an account-qualified prefix such as `az://customer-data@customeraccount.blob.core.windows.net/raw/`. ### GCP storage integrations diff --git a/docs/web/ingestion/define-storage-integration.mdx b/docs/web/ingestion/define-storage-integration.mdx index 96e137601..dbd8bbdd7 100644 --- a/docs/web/ingestion/define-storage-integration.mdx +++ b/docs/web/ingestion/define-storage-integration.mdx @@ -22,7 +22,7 @@ integration's prefix covers it. | --- | --- | --- | | AWS S3 | An IAM role to assume, or a static access key pair | A role needs one extra step outside LanceDB: [trust policy setup](#trust). | | Google Cloud Storage | A service account's JSON key | No role-based alternative. | -| Azure Blob Storage | A service principal's tenant, client ID and client secret | All three required together. | +| Azure Blob Storage | Three service principal Secrets or one storage account access key Secret | Both modes require the storage account name. | | HuggingFace | An access token | Always required to create an integration. For anonymous access at HuggingFace's default rate limits, register no integration for that prefix instead. | Every credential option takes a [Secret](/management/secret) reference, @@ -99,6 +99,11 @@ role-based alternative. ### Azure Blob Storage {#azure} +Specify the storage account and choose either service principal credentials or +a storage account access key. Reference the values through Secrets. + +#### Service principal + ```sql SQL icon="database" CREATE STORAGE INTEGRATION blobs @@ -121,8 +126,48 @@ db.create_storage_integration( ``` -All four options are required together; there is no role-based -alternative for Azure. +#### Storage account access key + +Store the key in a single Secret. Azure must allow Shared Key authorization on +the storage account. + + +```sql SQL icon="database" +CREATE STORAGE INTEGRATION blobs_key + STORAGE_PROVIDER = 'AZURE' + STORAGE_PREFIX = 'az://customer-data/raw/' + STORAGE_AZURE_STORAGE_ACCOUNT = 'customeraccount' + STORAGE_AZURE_STORAGE_ACCOUNT_ACCESS_KEY_SECRET = azure_key +``` + + +Use SQL to create the integration from TypeScript applications. + +{/* +Draft for the SDK release with Azure storage account access key support. +Publish these examples when the client APIs and Enterprise support ship. + + +```python Python icon="python" +db.create_storage_integration( + "blobs_key", "az://customer-data/raw/", + storage_provider="AZURE", + azure_storage_account="customeraccount", + azure_storage_account_access_key_secret="azure_key", +) +``` +```rust +use lancedb::storage_integration::{CreateStorageIntegrationRequest, SecretReference}; + +let request = CreateStorageIntegrationRequest::azure_with_account_access_key( + "az://customer-data/raw/", + "customeraccount", + SecretReference::new("azure_key"), +); +let info = db.create_storage_integration("blobs_key", request, &[]).await?; +``` + +*/} ### HuggingFace {#huggingface} diff --git a/docs/web/sql/ddl/storage-integration.mdx b/docs/web/sql/ddl/storage-integration.mdx index de64ba4e5..9e22970ec 100644 --- a/docs/web/sql/ddl/storage-integration.mdx +++ b/docs/web/sql/ddl/storage-integration.mdx @@ -97,9 +97,12 @@ CREATE STORAGE INTEGRATION blobs | `STORAGE_AZURE_TENANT_ID_SECRET` | Secret ref | Entra ID tenant | | `STORAGE_AZURE_CLIENT_ID_SECRET` | Secret ref | service principal client ID | | `STORAGE_AZURE_CLIENT_SECRET_SECRET` | Secret ref | service principal client secret | +| `STORAGE_AZURE_STORAGE_ACCOUNT_ACCESS_KEY_SECRET` | Secret ref | storage account access key for Azure Shared Key authorization | -All four are required together; there is no role-based alternative for -Azure. +Specify the storage account and choose one credential mode. Service principal +authentication requires all three service principal Secret references. Shared +Key authentication requires the account access key Secret reference and an Azure +storage account that allows Shared Key authorization. ### GCP {#gcp} diff --git a/python/python/lancedb/db.py b/python/python/lancedb/db.py index 9efee4393..61dafc855 100644 --- a/python/python/lancedb/db.py +++ b/python/python/lancedb/db.py @@ -463,6 +463,9 @@ class DBConnection(EnforceOverrides): azure_tenant_id_secret: Optional[Union[str, SecretReference]] = None, azure_client_id_secret: Optional[Union[str, SecretReference]] = None, azure_client_secret_secret: Optional[Union[str, SecretReference]] = None, + azure_storage_account_access_key_secret: Optional[ + Union[str, SecretReference] + ] = None, gcp_credentials_json_secret: Optional[Union[str, SecretReference]] = None, huggingface_token_secret: Optional[Union[str, SecretReference]] = None, exist_ok: bool = False, @@ -2754,6 +2757,9 @@ class LanceDBConnection(DBConnection): azure_tenant_id_secret: Optional[Union[str, SecretReference]] = None, azure_client_id_secret: Optional[Union[str, SecretReference]] = None, azure_client_secret_secret: Optional[Union[str, SecretReference]] = None, + azure_storage_account_access_key_secret: Optional[ + Union[str, SecretReference] + ] = None, gcp_credentials_json_secret: Optional[Union[str, SecretReference]] = None, huggingface_token_secret: Optional[Union[str, SecretReference]] = None, exist_ok: bool = False, @@ -2772,6 +2778,7 @@ class LanceDBConnection(DBConnection): azure_tenant_id_secret=azure_tenant_id_secret, azure_client_id_secret=azure_client_id_secret, azure_client_secret_secret=azure_client_secret_secret, + azure_storage_account_access_key_secret=azure_storage_account_access_key_secret, gcp_credentials_json_secret=gcp_credentials_json_secret, huggingface_token_secret=huggingface_token_secret, exist_ok=exist_ok, @@ -4269,6 +4276,9 @@ class AsyncConnection(object): azure_tenant_id_secret: Optional[Union[str, SecretReference]] = None, azure_client_id_secret: Optional[Union[str, SecretReference]] = None, azure_client_secret_secret: Optional[Union[str, SecretReference]] = None, + azure_storage_account_access_key_secret: Optional[ + Union[str, SecretReference] + ] = None, gcp_credentials_json_secret: Optional[Union[str, SecretReference]] = None, huggingface_token_secret: Optional[Union[str, SecretReference]] = None, exist_ok: bool = False, @@ -4279,7 +4289,8 @@ class AsyncConnection(object): ``namespace_path`` follows Secret naming rules. A SecretReference can name another database; a string names a root Secret in this database. For Azure, set ``storage_provider="AZURE"``, ``azure_storage_account``, - and Secret references for tenant ID, client ID and client secret. + and either ``azure_storage_account_access_key_secret`` or the three + Secret references for tenant ID, client ID and client secret. For GCP, set ``storage_provider="GCP"`` and ``gcp_credentials_json_secret`` to a Secret containing the application credentials JSON file content. For Hugging Face, set ``storage_provider="HUGGINGFACE"`` and @@ -4291,11 +4302,14 @@ class AsyncConnection(object): integration exists, preserving its provider, prefix and credential bindings. Existing names are errors by default. """ - azure_options = ( + azure_service_principal = ( azure_tenant_id_secret, azure_client_id_secret, azure_client_secret_secret, ) + azure_options = azure_service_principal + ( + azure_storage_account_access_key_secret, + ) if storage_provider != "HUGGINGFACE" and huggingface_token_secret is not None: raise ValueError( "Hugging Face options require storage_provider HUGGINGFACE" @@ -4331,12 +4345,17 @@ class AsyncConnection(object): ): raise ValueError("GCP integrations cannot contain AWS or Azure options") elif storage_provider == "AZURE": - if not azure_storage_account or any( - value is None for value in azure_options - ): + if not azure_storage_account: + raise ValueError("Azure integrations require azure_storage_account") + valid_credentials = ( + all(value is None for value in azure_service_principal) + if azure_storage_account_access_key_secret is not None + else all(value is not None for value in azure_service_principal) + ) + if not valid_credentials: raise ValueError( - "Azure requires a storage account and " - "all three credential Secret references" + "Specify either azure_storage_account_access_key_secret or " + "all three Azure service principal Secret references" ) if any( value is not None @@ -4393,6 +4412,9 @@ class AsyncConnection(object): "azure_tenant_id_secret": reference(azure_tenant_id_secret), "azure_client_id_secret": reference(azure_client_id_secret), "azure_client_secret_secret": reference(azure_client_secret_secret), + "azure_storage_account_access_key_secret": reference( + azure_storage_account_access_key_secret + ), "gcp_credentials_json_secret": reference(gcp_credentials_json_secret), "huggingface_token_secret": reference(huggingface_token_secret), "aws_access_key_id_secret": reference(aws_access_key_id_secret), diff --git a/python/python/lancedb/remote/db.py b/python/python/lancedb/remote/db.py index bf2f5669f..439e89100 100644 --- a/python/python/lancedb/remote/db.py +++ b/python/python/lancedb/remote/db.py @@ -1150,6 +1150,9 @@ class RemoteDBConnection(DBConnection): azure_tenant_id_secret: Optional[Union[str, SecretReference]] = None, azure_client_id_secret: Optional[Union[str, SecretReference]] = None, azure_client_secret_secret: Optional[Union[str, SecretReference]] = None, + azure_storage_account_access_key_secret: Optional[ + Union[str, SecretReference] + ] = None, gcp_credentials_json_secret: Optional[Union[str, SecretReference]] = None, huggingface_token_secret: Optional[Union[str, SecretReference]] = None, exist_ok: bool = False, @@ -1168,6 +1171,7 @@ class RemoteDBConnection(DBConnection): azure_tenant_id_secret=azure_tenant_id_secret, azure_client_id_secret=azure_client_id_secret, azure_client_secret_secret=azure_client_secret_secret, + azure_storage_account_access_key_secret=azure_storage_account_access_key_secret, gcp_credentials_json_secret=gcp_credentials_json_secret, huggingface_token_secret=huggingface_token_secret, exist_ok=exist_ok, diff --git a/python/python/lancedb/storage_integration.py b/python/python/lancedb/storage_integration.py index a9dda088b..e319a24be 100644 --- a/python/python/lancedb/storage_integration.py +++ b/python/python/lancedb/storage_integration.py @@ -50,6 +50,7 @@ class StorageIntegrationInfo: azure_client_secret_secret: Optional[SecretReference] = None gcp_credentials_json_secret: Optional[SecretReference] = None huggingface_token_secret: Optional[SecretReference] = None + azure_storage_account_access_key_secret: Optional[SecretReference] = None def __post_init__(self): for field in ( @@ -58,6 +59,7 @@ class StorageIntegrationInfo: "azure_tenant_id_secret", "azure_client_id_secret", "azure_client_secret_secret", + "azure_storage_account_access_key_secret", "gcp_credentials_json_secret", "huggingface_token_secret", ): diff --git a/python/python/tests/test_storage_integration.py b/python/python/tests/test_storage_integration.py index 84052e54c..9f01f2bc2 100644 --- a/python/python/tests/test_storage_integration.py +++ b/python/python/tests/test_storage_integration.py @@ -118,14 +118,23 @@ def remote_server(text_type=pa.string()): trust_policy=None, permissions_policy=None, ) - for field, name in ( - ("azure_tenant_id_secret", "tenant"), - ("azure_client_id_secret", "client"), - ("azure_client_secret_secret", "credential"), - ): - info[field] = dict( - database="shared", namespace_path=["credentials"], name=name + if b"STORAGE_AZURE_STORAGE_ACCOUNT_ACCESS_KEY_SECRET" in command: + info["azure_storage_account_access_key_secret"] = dict( + database="shared", + namespace_path=["credentials"], + name="blob_key", ) + else: + for field, name in ( + ("azure_tenant_id_secret", "tenant"), + ("azure_client_id_secret", "client"), + ("azure_client_secret_secret", "credential"), + ): + info[field] = dict( + database="shared", + namespace_path=["credentials"], + name=name, + ) if b"STORAGE_AWS_ACCESS_KEY_ID_SECRET" in command: info["aws_role_arn"] = None info["trust_policy"] = None @@ -149,6 +158,7 @@ def remote_server(text_type=pa.string()): "azure_tenant_id_secret", "azure_client_id_secret", "azure_client_secret_secret", + "azure_storage_account_access_key_secret", "gcp_credentials_json_secret", "huggingface_token_secret", ]: @@ -339,6 +349,44 @@ def test_azure_lifecycle_uses_three_qualified_secret_references(text_type): assert b"STORAGE_AWS" not in sql +def test_azure_lifecycle_uses_one_qualified_account_access_key_secret(): + with remote_server() as (host, calls): + db = connect(host) + key = SecretReference( + "blob_key", database="shared", namespace_path=("credentials",) + ) + config = { + "storage_provider": "AZURE", + "azure_storage_account": "customeraccount", + "azure_storage_account_access_key_secret": key, + } + with pytest.raises(ValueError, match="service principal"): + db.create_storage_integration( + "blobs", + "az://customer-data/raw/", + azure_client_id_secret="client", + **config, + ) + assert calls == [] + + info = db.create_storage_integration( + "blobs", "az://customer-data/raw/", **config + ) + reference = info.azure_storage_account_access_key_secret + assert reference is not None + assert reference.name == key.name + assert reference.database == key.database + assert tuple(reference.namespace_path) == key.namespace_path + assert info.azure_tenant_id_secret is None + assert info.azure_client_id_secret is None + assert info.azure_client_secret_secret is None + assert db.describe_storage_integration("blobs") == info + assert ( + b"STORAGE_AZURE_STORAGE_ACCOUNT_ACCESS_KEY_SECRET = " + b'"shared"."credentials"."blob_key"' in calls[0] + ) + + @pytest.mark.asyncio async def test_async_azure_requires_account_and_all_three_secret_references(): with remote_server() as (host, calls): diff --git a/rust/lancedb/src/remote/storage_integration.rs b/rust/lancedb/src/remote/storage_integration.rs index 6c132ab4b..104fbbc13 100644 --- a/rust/lancedb/src/remote/storage_integration.rs +++ b/rust/lancedb/src/remote/storage_integration.rs @@ -75,6 +75,7 @@ pub(super) fn create_sql( || request.azure_tenant_id_secret.is_some() || request.azure_client_id_secret.is_some() || request.azure_client_secret_secret.is_some() + || request.azure_storage_account_access_key_secret.is_some() || request.gcp_credentials_json_secret.is_some() { return Err(invalid( @@ -110,6 +111,7 @@ pub(super) fn create_sql( || request.azure_tenant_id_secret.is_some() || request.azure_client_id_secret.is_some() || request.azure_client_secret_secret.is_some() + || request.azure_storage_account_access_key_secret.is_some() { return Err(invalid( "GCP integrations cannot contain AWS or Azure options", @@ -145,24 +147,32 @@ pub(super) fn create_sql( literal(&request.storage_prefix), literal(account) ); - for (key, reference) in [ - ( - "STORAGE_AZURE_TENANT_ID_SECRET", - &request.azure_tenant_id_secret, - ), - ( - "STORAGE_AZURE_CLIENT_ID_SECRET", - &request.azure_client_id_secret, - ), - ( - "STORAGE_AZURE_CLIENT_SECRET_SECRET", - &request.azure_client_secret_secret, - ), - ] { - let reference = reference.as_ref().ok_or_else(|| { - invalid("Azure integrations require all three credential Secret references") - })?; - sql.push_str(&format!(" {key} = {}", secret_name(reference)?)); + match ( + &request.azure_storage_account_access_key_secret, + &request.azure_tenant_id_secret, + &request.azure_client_id_secret, + &request.azure_client_secret_secret, + ) { + (Some(reference), None, None, None) => { + sql.push_str(&format!( + " STORAGE_AZURE_STORAGE_ACCOUNT_ACCESS_KEY_SECRET = {}", + secret_name(reference)? + )); + } + (None, Some(tenant), Some(client), Some(secret)) => { + for (key, reference) in [ + ("STORAGE_AZURE_TENANT_ID_SECRET", tenant), + ("STORAGE_AZURE_CLIENT_ID_SECRET", client), + ("STORAGE_AZURE_CLIENT_SECRET_SECRET", secret), + ] { + sql.push_str(&format!(" {key} = {}", secret_name(reference)?)); + } + } + _ => { + return Err(invalid( + "Specify either azure_storage_account_access_key_secret or all three Azure service principal Secret references", + )); + } } return Ok(sql); } @@ -170,6 +180,7 @@ pub(super) fn create_sql( || request.azure_tenant_id_secret.is_some() || request.azure_client_id_secret.is_some() || request.azure_client_secret_secret.is_some() + || request.azure_storage_account_access_key_secret.is_some() { return Err(invalid("S3 integrations cannot contain Azure options")); } @@ -244,6 +255,7 @@ pub(super) fn decode_info(batches: &[RecordBatch]) -> Result, #[serde(default, skip_serializing_if = "Option::is_none")] + pub azure_storage_account_access_key_secret: Option, + #[serde(default, skip_serializing_if = "Option::is_none")] pub gcp_credentials_json_secret: Option, #[serde(default, skip_serializing_if = "Option::is_none")] pub huggingface_token_secret: Option, @@ -113,6 +115,7 @@ impl CreateStorageIntegrationRequest { azure_tenant_id_secret: None, azure_client_id_secret: None, azure_client_secret_secret: None, + azure_storage_account_access_key_secret: None, gcp_credentials_json_secret: None, huggingface_token_secret: None, } @@ -136,6 +139,7 @@ impl CreateStorageIntegrationRequest { azure_tenant_id_secret: None, azure_client_id_secret: None, azure_client_secret_secret: None, + azure_storage_account_access_key_secret: None, gcp_credentials_json_secret: None, huggingface_token_secret: None, } @@ -166,6 +170,38 @@ impl CreateStorageIntegrationRequest { azure_tenant_id_secret: Some(tenant_id), azure_client_id_secret: Some(client_id), azure_client_secret_secret: Some(client_secret), + azure_storage_account_access_key_secret: None, + gcp_credentials_json_secret: None, + huggingface_token_secret: None, + aws_role_arn: None, + aws_access_key_id_secret: None, + aws_secret_access_key_secret: None, + aws_region: None, + } + } + + /// Register Azure Blob access using a Secret containing a storage account access key. + /// + /// ``` + /// use lancedb::storage_integration::{CreateStorageIntegrationRequest, SecretReference}; + /// let config = CreateStorageIntegrationRequest::azure_with_account_access_key( + /// "az://customer-data/raw/", "customeraccount", SecretReference::new("azure_key"), + /// ); + /// ``` + pub fn azure_with_account_access_key( + storage_prefix: impl Into, + storage_account: impl Into, + access_key: SecretReference, + ) -> Self { + Self { + storage_provider: StorageProvider::Azure, + storage_prefix: storage_prefix.into(), + exist_ok: false, + azure_storage_account: Some(storage_account.into()), + azure_storage_account_access_key_secret: Some(access_key), + azure_tenant_id_secret: None, + azure_client_id_secret: None, + azure_client_secret_secret: None, gcp_credentials_json_secret: None, huggingface_token_secret: None, aws_role_arn: None, @@ -198,6 +234,7 @@ impl CreateStorageIntegrationRequest { azure_tenant_id_secret: None, azure_client_id_secret: None, azure_client_secret_secret: None, + azure_storage_account_access_key_secret: None, } } @@ -225,6 +262,7 @@ impl CreateStorageIntegrationRequest { azure_tenant_id_secret: None, azure_client_id_secret: None, azure_client_secret_secret: None, + azure_storage_account_access_key_secret: None, } } @@ -270,6 +308,8 @@ pub struct StorageIntegrationInfo { #[serde(default, skip_serializing_if = "Option::is_none")] pub azure_client_secret_secret: Option, #[serde(default, skip_serializing_if = "Option::is_none")] + pub azure_storage_account_access_key_secret: Option, + #[serde(default, skip_serializing_if = "Option::is_none")] pub gcp_credentials_json_secret: Option, #[serde(default, skip_serializing_if = "Option::is_none")] pub huggingface_token_secret: Option,