feat: add Azure storage account access key support to SDKs (#5177)

Add `azure_storage_account_access_key_secret` to the sync and async
Python storage integration APIs, with a matching Rust constructor. The
SDK sends a Secret reference in SQL and decodes the reference returned
by CREATE and DESCRIBE.

```python
info = db.create_storage_integration(
    "blobs", "az://customer-data/raw/",
    storage_provider="AZURE",
    azure_storage_account="customeraccount",
    azure_storage_account_access_key_secret="azure_key",
)
```

Azure requires a storage account and one authentication mode. The
account access key uses a single Secret. Service principal
authentication uses the existing three Secret references.
This commit is contained in:
Jack Ye
2026-11-23 22:49:41 -08:00
committed by GitHub
parent a6cca1efb0
commit df1d3318df
9 changed files with 253 additions and 38 deletions
+29 -7
View File
@@ -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),
+4
View File
@@ -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,
@@ -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",
):
@@ -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):