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
+52 -18
View File
@@ -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<StorageIntegrationI
| "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"
| "trust_policy"
@@ -265,6 +277,28 @@ mod tests {
use super::*;
#[test]
fn azure_account_access_key_sql_references_only_the_key_secret() {
let mut request = CreateStorageIntegrationRequest::azure_with_account_access_key(
"az://customer-data/raw/",
"customeraccount",
SecretReference::new("blob_key")
.with_database("shared")
.with_namespace(vec!["credentials".into()]),
);
let sql = create_sql("blobs", &[], &request).unwrap();
assert!(sql.contains("STORAGE_AZURE_STORAGE_ACCOUNT = 'customeraccount'"));
assert!(sql.contains(
r#"STORAGE_AZURE_STORAGE_ACCOUNT_ACCESS_KEY_SECRET = "shared"."credentials"."blob_key""#
));
assert!(!sql.contains("STORAGE_AZURE_TENANT_ID_SECRET"));
assert!(!sql.contains("STORAGE_AZURE_CLIENT_ID_SECRET"));
assert!(!sql.contains("STORAGE_AZURE_CLIENT_SECRET_SECRET"));
request.azure_client_id_secret = Some(SecretReference::new("client"));
assert!(create_sql("blobs", &[], &request).is_err());
}
#[test]
fn create_if_not_exists_preserves_provider_options() {
let secret = SecretReference::new("credential");
+40
View File
@@ -62,6 +62,8 @@ pub struct CreateStorageIntegrationRequest {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub azure_client_secret_secret: Option<SecretReference>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub azure_storage_account_access_key_secret: Option<SecretReference>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub gcp_credentials_json_secret: Option<SecretReference>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub huggingface_token_secret: Option<SecretReference>,
@@ -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<String>,
storage_account: impl Into<String>,
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<SecretReference>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub azure_storage_account_access_key_secret: Option<SecretReference>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub gcp_credentials_json_secret: Option<SecretReference>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub huggingface_token_secret: Option<SecretReference>,