You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by xu...@apache.org on 2026/03/18 10:56:27 UTC

(opendal-reqsign) branch main updated: feat: migrate azure-storage default credential provider API (#715)

This is an automated email from the ASF dual-hosted git repository.

xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/opendal-reqsign.git


The following commit(s) were added to refs/heads/main by this push:
     new 56cc5a8  feat: migrate azure-storage default credential provider API (#715)
56cc5a8 is described below

commit 56cc5a85aef517f893ffab7be5badfd9d7be4b09
Author: Xuanwo <gi...@xuanwo.io>
AuthorDate: Wed Mar 18 18:56:22 2026 +0800

    feat: migrate azure-storage default credential provider API (#715)
    
    This migrates `reqsign-azure-storage` to the slot-based
    `DefaultCredentialProvider` builder defined in
    `docs/default-credential-provider-api.md`.
    It removes the legacy `configure_*` and `disable_*(bool)` APIs, keeps
    the existing default chain and wasm/non-wasm slot set, and updates
    docs/examples/tests to cover `no_slot()` removal semantics.
---
 services/azure-storage/README.md                   | 216 +++++++--------------
 services/azure-storage/examples/blob_storage.rs    |   6 +-
 services/azure-storage/src/lib.rs                  |  14 ++
 .../src/provide_credential/default.rs              | 213 +++++++-------------
 .../tests/credential_providers/default.rs          | 125 +++++++++++-
 5 files changed, 283 insertions(+), 291 deletions(-)

diff --git a/services/azure-storage/README.md b/services/azure-storage/README.md
index 9c305cc..c6d37d2 100644
--- a/services/azure-storage/README.md
+++ b/services/azure-storage/README.md
@@ -1,194 +1,114 @@
 # reqsign-azure-storage
 
-Azure Storage signing implementation for reqsign.
+Azure Storage signing support for reqsign.
 
----
-
-This crate provides comprehensive signing support for Azure Storage services including Blob Storage, File Storage, Queue Storage, and Table Storage.
+This crate signs requests for Blob, File, Queue, and Table Storage. It supports
+shared key, SAS token, and Azure AD bearer token credentials.
 
 ## Quick Start
 
 ```rust
-use reqsign_azure_storage::{Builder, Config, DefaultLoader};
+use anyhow::Result;
+use reqsign_azure_storage::{DefaultCredentialProvider, RequestSigner};
 use reqsign_core::{Context, Signer};
-
-// Create context and signer
-let ctx = Context::default();
-let config = Config::default()
-    .account_name("mystorageaccount")
-    .from_env();
-let loader = DefaultLoader::new(config);
-let builder = Builder::new();
-let signer = Signer::new(ctx, loader, builder);
-
-// Sign requests
-let mut req = http::Request::get("https://mystorageaccount.blob.core.windows.net/container/blob")
+use reqsign_file_read_tokio::TokioFileRead;
+use reqsign_http_send_reqwest::ReqwestHttpSend;
+
+#[tokio::main]
+async fn main() -> Result<()> {
+    let ctx = Context::new()
+        .with_file_read(TokioFileRead)
+        .with_http_send(ReqwestHttpSend::default());
+
+    let signer = Signer::new(
+        ctx,
+        DefaultCredentialProvider::new(),
+        RequestSigner::new(),
+    );
+
+    let mut req = http::Request::get(
+        "https://mystorageaccount.blob.core.windows.net/container/blob",
+    )
     .body(())
     .unwrap()
     .into_parts()
     .0;
 
-signer.sign(&mut req, None).await?;
+    signer.sign(&mut req, None).await?;
+    Ok(())
+}
 ```
 
-## Features
+## Default Credential Chain
 
-- **Multiple Auth Methods**: Shared Key, SAS tokens, and Azure AD
-- **All Storage Services**: Blob, File, Queue, and Table storage
-- **Managed Identity**: Automatic authentication on Azure services
-- **Flexible Configuration**: Environment variables, config files, or code
+`DefaultCredentialProvider::new()` uses this chain:
 
-## Authentication Methods
+1. `env`
+2. `azure_cli` (`non-wasm32` only)
+3. `client_certificate` (`non-wasm32` only)
+4. `client_secret`
+5. `azure_pipelines`
+6. `workload_identity`
+7. `imds`
 
-### 1. Shared Key (Storage Account Key)
-
-```bash
-export AZURE_STORAGE_ACCOUNT_NAME=mystorageaccount
-export AZURE_STORAGE_ACCOUNT_KEY=base64encodedkey==
-```
+Use `DefaultCredentialProvider::builder()` to customize slot participation.
 
 ```rust
-let config = Config::default()
-    .account_name("mystorageaccount")
-    .account_key("base64encodedkey==");
-```
-
-### 2. SAS Token
-
-```bash
-export AZURE_STORAGE_SAS_TOKEN=sv=2021-06-08&ss=b&srt=sco&sp=rwdlacx&se=2024-12-31T23:59:59Z&...
+use reqsign_azure_storage::{
+    ClientSecretCredentialProvider, DefaultCredentialProvider,
+};
+
+let provider = DefaultCredentialProvider::builder()
+    .no_env()
+    .client_secret(
+        ClientSecretCredentialProvider::new().with_tenant_id("tenant-id"),
+    )
+    .no_imds()
+    .build();
 ```
 
-```rust
-let config = Config::default()
-    .account_name("mystorageaccount")
-    .sas_token("sv=2021-06-08&ss=b...");
-```
+## Environment Variables
 
-### 3. Azure AD / OAuth
+Shared key:
 
 ```bash
-export AZURE_CLIENT_ID=your-client-id
-export AZURE_CLIENT_SECRET=your-client-secret
-export AZURE_TENANT_ID=your-tenant-id
-```
-
-```rust
-let config = Config::default()
-    .account_name("mystorageaccount")
-    .client_id("client-id")
-    .client_secret("client-secret")
-    .tenant_id("tenant-id");
+export AZURE_STORAGE_ACCOUNT_NAME=mystorageaccount
+export AZURE_STORAGE_ACCOUNT_KEY=base64encodedkey==
 ```
 
-### 4. Managed Identity
-
-Automatically used when running on Azure services:
+SAS token:
 
-```rust
-// No explicit credentials needed
-let config = Config::default()
-    .account_name("mystorageaccount");
+```bash
+export AZURE_STORAGE_SAS_TOKEN="sv=2021-06-08&ss=b&srt=sco&sp=rwdlacx..."
 ```
 
-## Storage Services
-
-### Blob Storage
+Client secret:
 
-```rust
-// List containers
-let req = http::Request::get("https://account.blob.core.windows.net/?comp=list")
-    .header("x-ms-version", "2021-12-02")
-    .body(())?;
-
-// Get blob
-let req = http::Request::get("https://account.blob.core.windows.net/container/blob.txt")
-    .header("x-ms-version", "2021-12-02")
-    .body(())?;
-
-// Upload blob
-let req = http::Request::put("https://account.blob.core.windows.net/container/blob.txt")
-    .header("x-ms-version", "2021-12-02")
-    .header("x-ms-blob-type", "BlockBlob")
-    .body(content)?;
+```bash
+export AZURE_TENANT_ID=tenant-id
+export AZURE_CLIENT_ID=client-id
+export AZURE_CLIENT_SECRET=client-secret
 ```
 
-### File Storage
-
-```rust
-// List shares
-let req = http::Request::get("https://account.file.core.windows.net/?comp=list")
-    .header("x-ms-version", "2021-12-02")
-    .body(())?;
-
-// Get file
-let req = http::Request::get("https://account.file.core.windows.net/share/dir/file.txt")
-    .header("x-ms-version", "2021-12-02")
-    .body(())?;
-```
+## Using Specific Providers
 
-### Queue Storage
+Use a single provider directly when you do not want the default chain:
 
 ```rust
-// List queues
-let req = http::Request::get("https://account.queue.core.windows.net/?comp=list")
-    .header("x-ms-version", "2021-12-02")
-    .body(())?;
-
-// Get messages
-let req = http::Request::get("https://account.queue.core.windows.net/myqueue/messages")
-    .header("x-ms-version", "2021-12-02")
-    .body(())?;
-```
+use reqsign_azure_storage::{EnvCredentialProvider, StaticCredentialProvider};
 
-### Table Storage
+let env_provider = EnvCredentialProvider::new();
 
-```rust
-// Query entities
-let req = http::Request::get("https://account.table.core.windows.net/mytable()")
-    .header("x-ms-version", "2021-12-02")
-    .header("Accept", "application/json")
-    .body(())?;
+let static_provider = StaticCredentialProvider::new_shared_key(
+    "mystorageaccount",
+    "base64encodedkey==",
+);
 ```
 
 ## Examples
 
-Check out the examples directory:
-- [Blob storage operations](examples/blob_storage.rs) - Complete blob storage examples
+Run the example:
 
 ```bash
 cargo run --example blob_storage
 ```
-
-## Credential Loading Order
-
-The `DefaultLoader` tries credentials in this order:
-
-1. SAS Token (if provided)
-2. Shared Key (if provided)
-3. Azure AD Client Credentials
-4. Managed Identity (on Azure services)
-5. Azure CLI credentials
-
-## Advanced Configuration
-
-### Custom Authority Host
-
-```rust
-let config = Config::default()
-    .account_name("mystorageaccount")
-    .authority_host("https://login.microsoftonline.com");
-```
-
-### Specific Credential Type
-
-```rust
-// Force Shared Key only
-use reqsign_azure_storage::ClientSecretLoader;
-
-let loader = ClientSecretLoader::new(config);
-```
-
-## License
-
-Licensed under [Apache License, Version 2.0](./LICENSE).
\ No newline at end of file
diff --git a/services/azure-storage/examples/blob_storage.rs b/services/azure-storage/examples/blob_storage.rs
index 5ca242d..51cd197 100644
--- a/services/azure-storage/examples/blob_storage.rs
+++ b/services/azure-storage/examples/blob_storage.rs
@@ -16,7 +16,7 @@
 // under the License.
 
 use anyhow::Result;
-use reqsign_azure_storage::{DefaultCredentialProvider, RequestSigner};
+use reqsign_azure_storage::{DefaultCredentialProvider, EnvCredentialProvider, RequestSigner};
 use reqsign_core::{Context, OsEnv, Signer};
 use reqsign_file_read_tokio::TokioFileRead;
 use reqsign_http_send_reqwest::ReqwestHttpSend;
@@ -56,7 +56,9 @@ async fn main() -> Result<()> {
     }
 
     // Create credential loader
-    let loader = DefaultCredentialProvider::new();
+    let loader = DefaultCredentialProvider::builder()
+        .env(EnvCredentialProvider::new())
+        .build();
 
     // Create request builder
     let builder = RequestSigner::new();
diff --git a/services/azure-storage/src/lib.rs b/services/azure-storage/src/lib.rs
index 180c756..21c4581 100644
--- a/services/azure-storage/src/lib.rs
+++ b/services/azure-storage/src/lib.rs
@@ -97,6 +97,20 @@
 //! let loader = DefaultCredentialProvider::new();
 //! ```
 //!
+//! Customize the default chain with slot-based builder APIs:
+//!
+//! ```no_run
+//! use reqsign_azure_storage::{
+//!     ClientSecretCredentialProvider, DefaultCredentialProvider,
+//! };
+//!
+//! let loader = DefaultCredentialProvider::builder()
+//!     .no_env()
+//!     .client_secret(ClientSecretCredentialProvider::new().with_tenant_id("tenant-id"))
+//!     .no_imds()
+//!     .build();
+//! ```
+//!
 //! ## Storage Services
 //!
 //! ### Blob Storage
diff --git a/services/azure-storage/src/provide_credential/default.rs b/services/azure-storage/src/provide_credential/default.rs
index 5a00a7f..cd2dc49 100644
--- a/services/azure-storage/src/provide_credential/default.rs
+++ b/services/azure-storage/src/provide_credential/default.rs
@@ -85,10 +85,21 @@ impl DefaultCredentialProvider {
 
 /// Builder for `DefaultCredentialProvider`.
 ///
-/// Use `configure_*` to adjust provider behavior and `disable_*(bool)` to
-/// control participation in the chain. Then call `build()` to construct the
-/// final provider that resolves credentials in the documented order.
-#[derive(Default)]
+/// Each slot is represented by `Option<T>`:
+/// - `Some(provider)` keeps the provider in the default chain.
+/// - `None` removes the provider from the chain.
+///
+/// ```no_run
+/// use reqsign_azure_storage::{
+///     ClientSecretCredentialProvider, DefaultCredentialProvider,
+/// };
+///
+/// let provider = DefaultCredentialProvider::builder()
+///     .no_env()
+///     .client_secret(ClientSecretCredentialProvider::new().with_tenant_id("tenant-id"))
+///     .no_imds()
+///     .build();
+/// ```
 pub struct DefaultCredentialProviderBuilder {
     env: Option<EnvCredentialProvider>,
     #[cfg(not(target_arch = "wasm32"))]
@@ -101,176 +112,112 @@ pub struct DefaultCredentialProviderBuilder {
     imds: Option<ImdsCredentialProvider>,
 }
 
+impl Default for DefaultCredentialProviderBuilder {
+    fn default() -> Self {
+        Self {
+            env: Some(EnvCredentialProvider::new()),
+            #[cfg(not(target_arch = "wasm32"))]
+            azure_cli: Some(AzureCliCredentialProvider::new()),
+            #[cfg(not(target_arch = "wasm32"))]
+            client_certificate: Some(ClientCertificateCredentialProvider::new()),
+            client_secret: Some(ClientSecretCredentialProvider::new()),
+            azure_pipelines: Some(AzurePipelinesCredentialProvider::new()),
+            workload_identity: Some(WorkloadIdentityCredentialProvider::new()),
+            imds: Some(ImdsCredentialProvider::new()),
+        }
+    }
+}
+
 impl DefaultCredentialProviderBuilder {
     pub fn new() -> Self {
         Self::default()
     }
 
-    pub fn configure_env<F>(mut self, f: F) -> Self
-    where
-        F: FnOnce(EnvCredentialProvider) -> EnvCredentialProvider,
-    {
-        let p = self.env.take().unwrap_or_default();
-        self.env = Some(f(p));
+    /// Set the environment credential provider slot.
+    pub fn env(mut self, provider: EnvCredentialProvider) -> Self {
+        self.env = Some(provider);
         self
     }
 
-    pub fn disable_env(mut self, disable: bool) -> Self {
-        if disable {
-            self.env = None;
-        } else if self.env.is_none() {
-            self.env = Some(EnvCredentialProvider::new());
-        }
+    /// Remove the environment credential provider slot.
+    pub fn no_env(mut self) -> Self {
+        self.env = None;
         self
     }
 
-    /// Configure the Azure CLI credential provider.
-    ///
-    /// This is typically used for local development where Azure CLI is
-    /// available and authenticated. You can tweak behavior (like alternative
-    /// token acquisition strategies) via the provided closure. Only available
-    /// on non-wasm32 targets.
+    /// Set the Azure CLI credential provider slot.
     #[cfg(not(target_arch = "wasm32"))]
-    pub fn configure_azure_cli<F>(mut self, f: F) -> Self
-    where
-        F: FnOnce(AzureCliCredentialProvider) -> AzureCliCredentialProvider,
-    {
-        let p = self.azure_cli.take().unwrap_or_default();
-        self.azure_cli = Some(f(p));
+    pub fn azure_cli(mut self, provider: AzureCliCredentialProvider) -> Self {
+        self.azure_cli = Some(provider);
         self
     }
 
-    /// Disable (true) or ensure enabled (false) the Azure CLI provider.
-    ///
-    /// Useful in CI or constrained environments where Azure CLI is not
-    /// present, or to explicitly opt out. Only available on non-wasm32 targets.
+    /// Remove the Azure CLI credential provider slot.
     #[cfg(not(target_arch = "wasm32"))]
-    pub fn disable_azure_cli(mut self, disable: bool) -> Self {
-        if disable {
-            self.azure_cli = None;
-        } else if self.azure_cli.is_none() {
-            self.azure_cli = Some(AzureCliCredentialProvider::new());
-        }
+    pub fn no_azure_cli(mut self) -> Self {
+        self.azure_cli = None;
         self
     }
 
-    /// Configure the client certificate credential provider.
-    ///
-    /// Customize certificate-based SPN authentication (tenant/client/cert
-    /// parameters). Only available on non-wasm32 targets.
+    /// Set the client certificate credential provider slot.
     #[cfg(not(target_arch = "wasm32"))]
-    pub fn configure_client_certificate<F>(mut self, f: F) -> Self
-    where
-        F: FnOnce(ClientCertificateCredentialProvider) -> ClientCertificateCredentialProvider,
-    {
-        let p = self.client_certificate.take().unwrap_or_default();
-        self.client_certificate = Some(f(p));
+    pub fn client_certificate(mut self, provider: ClientCertificateCredentialProvider) -> Self {
+        self.client_certificate = Some(provider);
         self
     }
 
-    /// Disable (true) or ensure enabled (false) the client certificate provider.
-    ///
-    /// Use to explicitly remove certificate-based auth from the chain or to
-    /// ensure participation. Only available on non-wasm32 targets.
+    /// Remove the client certificate credential provider slot.
     #[cfg(not(target_arch = "wasm32"))]
-    pub fn disable_client_certificate(mut self, disable: bool) -> Self {
-        if disable {
-            self.client_certificate = None;
-        } else if self.client_certificate.is_none() {
-            self.client_certificate = Some(ClientCertificateCredentialProvider::new());
-        }
+    pub fn no_client_certificate(mut self) -> Self {
+        self.client_certificate = None;
         self
     }
 
-    /// Configure the client secret credential provider.
-    ///
-    /// Customize tenant/client parameters used to exchange a client secret
-    /// for an access token suitable for Azure Storage.
-    pub fn configure_client_secret<F>(mut self, f: F) -> Self
-    where
-        F: FnOnce(ClientSecretCredentialProvider) -> ClientSecretCredentialProvider,
-    {
-        let p = self.client_secret.take().unwrap_or_default();
-        self.client_secret = Some(f(p));
+    /// Set the client secret credential provider slot.
+    pub fn client_secret(mut self, provider: ClientSecretCredentialProvider) -> Self {
+        self.client_secret = Some(provider);
         self
     }
 
-    /// Disable (true) or ensure enabled (false) the client secret provider.
-    pub fn disable_client_secret(mut self, disable: bool) -> Self {
-        if disable {
-            self.client_secret = None;
-        } else if self.client_secret.is_none() {
-            self.client_secret = Some(ClientSecretCredentialProvider::new());
-        }
+    /// Remove the client secret credential provider slot.
+    pub fn no_client_secret(mut self) -> Self {
+        self.client_secret = None;
         self
     }
 
-    /// Configure the Azure Pipelines workload identity provider.
-    ///
-    /// Allows customizing how OIDC tokens from Azure Pipelines are exchanged
-    /// for Azure AD access tokens.
-    pub fn configure_azure_pipelines<F>(mut self, f: F) -> Self
-    where
-        F: FnOnce(AzurePipelinesCredentialProvider) -> AzurePipelinesCredentialProvider,
-    {
-        let p = self.azure_pipelines.take().unwrap_or_default();
-        self.azure_pipelines = Some(f(p));
+    /// Set the Azure Pipelines credential provider slot.
+    pub fn azure_pipelines(mut self, provider: AzurePipelinesCredentialProvider) -> Self {
+        self.azure_pipelines = Some(provider);
         self
     }
 
-    /// Disable (true) or ensure enabled (false) the Azure Pipelines provider.
-    pub fn disable_azure_pipelines(mut self, disable: bool) -> Self {
-        if disable {
-            self.azure_pipelines = None;
-        } else if self.azure_pipelines.is_none() {
-            self.azure_pipelines = Some(AzurePipelinesCredentialProvider::new());
-        }
+    /// Remove the Azure Pipelines credential provider slot.
+    pub fn no_azure_pipelines(mut self) -> Self {
+        self.azure_pipelines = None;
         self
     }
 
-    /// Configure the Kubernetes workload identity provider.
-    ///
-    /// Allows customizing tenant or other parameters used to exchange
-    /// federated tokens for Azure AD access tokens.
-    pub fn configure_workload_identity<F>(mut self, f: F) -> Self
-    where
-        F: FnOnce(WorkloadIdentityCredentialProvider) -> WorkloadIdentityCredentialProvider,
-    {
-        let p = self.workload_identity.take().unwrap_or_default();
-        self.workload_identity = Some(f(p));
+    /// Set the workload identity credential provider slot.
+    pub fn workload_identity(mut self, provider: WorkloadIdentityCredentialProvider) -> Self {
+        self.workload_identity = Some(provider);
         self
     }
 
-    /// Disable (true) or ensure enabled (false) the workload identity provider.
-    pub fn disable_workload_identity(mut self, disable: bool) -> Self {
-        if disable {
-            self.workload_identity = None;
-        } else if self.workload_identity.is_none() {
-            self.workload_identity = Some(WorkloadIdentityCredentialProvider::new());
-        }
+    /// Remove the workload identity credential provider slot.
+    pub fn no_workload_identity(mut self) -> Self {
+        self.workload_identity = None;
         self
     }
 
-    /// Configure the Azure IMDS provider.
-    ///
-    /// Allows setting an alternate metadata endpoint or other parameters used
-    /// to obtain managed identity tokens on Azure VMs.
-    pub fn configure_imds<F>(mut self, f: F) -> Self
-    where
-        F: FnOnce(ImdsCredentialProvider) -> ImdsCredentialProvider,
-    {
-        let p = self.imds.take().unwrap_or_default();
-        self.imds = Some(f(p));
+    /// Set the Azure IMDS credential provider slot.
+    pub fn imds(mut self, provider: ImdsCredentialProvider) -> Self {
+        self.imds = Some(provider);
         self
     }
 
-    /// Disable (true) or ensure enabled (false) the IMDS provider.
-    pub fn disable_imds(mut self, disable: bool) -> Self {
-        if disable {
-            self.imds = None;
-        } else if self.imds.is_none() {
-            self.imds = Some(ImdsCredentialProvider::new());
-        }
+    /// Remove the Azure IMDS credential provider slot.
+    pub fn no_imds(mut self) -> Self {
+        self.imds = None;
         self
     }
 
@@ -280,47 +227,33 @@ impl DefaultCredentialProviderBuilder {
 
         if let Some(p) = self.env {
             chain = chain.push(p);
-        } else {
-            chain = chain.push(EnvCredentialProvider::new());
         }
 
         #[cfg(not(target_arch = "wasm32"))]
         {
             if let Some(p) = self.azure_cli {
                 chain = chain.push(p);
-            } else {
-                chain = chain.push(AzureCliCredentialProvider::new());
             }
 
             if let Some(p) = self.client_certificate {
                 chain = chain.push(p);
-            } else {
-                chain = chain.push(ClientCertificateCredentialProvider::new());
             }
         }
 
         if let Some(p) = self.client_secret {
             chain = chain.push(p);
-        } else {
-            chain = chain.push(ClientSecretCredentialProvider::new());
         }
 
         if let Some(p) = self.azure_pipelines {
             chain = chain.push(p);
-        } else {
-            chain = chain.push(AzurePipelinesCredentialProvider::new());
         }
 
         if let Some(p) = self.workload_identity {
             chain = chain.push(p);
-        } else {
-            chain = chain.push(WorkloadIdentityCredentialProvider::new());
         }
 
         if let Some(p) = self.imds {
             chain = chain.push(p);
-        } else {
-            chain = chain.push(ImdsCredentialProvider::new());
         }
 
         DefaultCredentialProvider::with_chain(chain)
diff --git a/services/azure-storage/tests/credential_providers/default.rs b/services/azure-storage/tests/credential_providers/default.rs
index e76b5eb..95a7be4 100644
--- a/services/azure-storage/tests/credential_providers/default.rs
+++ b/services/azure-storage/tests/credential_providers/default.rs
@@ -16,9 +16,10 @@
 // under the License.
 
 use reqsign_azure_storage::{Credential, DefaultCredentialProvider};
-use reqsign_core::{Context, OsEnv, ProvideCredential, ProvideCredentialChain, Result};
+use reqsign_core::{Context, OsEnv, ProvideCredential, ProvideCredentialChain, Result, StaticEnv};
 use reqsign_file_read_tokio::TokioFileRead;
 use reqsign_http_send_reqwest::ReqwestHttpSend;
+use std::collections::HashMap;
 use std::sync::Arc;
 
 fn is_test_enabled() -> bool {
@@ -43,6 +44,66 @@ impl ProvideCredential for CountingProvider {
     }
 }
 
+#[derive(Debug)]
+struct StaticHttpSend {
+    status: http::StatusCode,
+    body: &'static str,
+}
+
+impl reqsign_core::HttpSend for StaticHttpSend {
+    async fn http_send(
+        &self,
+        _req: http::Request<bytes::Bytes>,
+    ) -> Result<http::Response<bytes::Bytes>> {
+        http::Response::builder()
+            .status(self.status)
+            .body(bytes::Bytes::copy_from_slice(self.body.as_bytes()))
+            .map_err(|err| {
+                reqsign_core::Error::unexpected("failed to build mock response").with_source(err)
+            })
+    }
+}
+
+fn builder_without_other_slots() -> reqsign_azure_storage::DefaultCredentialProviderBuilder {
+    let builder = DefaultCredentialProvider::builder()
+        .no_env()
+        .no_client_secret()
+        .no_azure_pipelines()
+        .no_workload_identity()
+        .no_imds();
+
+    #[cfg(not(target_arch = "wasm32"))]
+    let builder = builder.no_azure_cli().no_client_certificate();
+
+    builder
+}
+
+fn assert_shared_key(
+    result: Option<Credential>,
+    expected_account_name: &str,
+    expected_account_key: &str,
+) {
+    match result {
+        Some(Credential::SharedKey {
+            account_name,
+            account_key,
+        }) => {
+            assert_eq!(account_name, expected_account_name);
+            assert_eq!(account_key, expected_account_key);
+        }
+        other => panic!("Expected SharedKey credential, got {other:?}"),
+    }
+}
+
+fn assert_bearer_token(result: Option<Credential>, expected_token: &str) {
+    match result {
+        Some(Credential::BearerToken { token, .. }) => {
+            assert_eq!(token, expected_token);
+        }
+        other => panic!("Expected BearerToken credential, got {other:?}"),
+    }
+}
+
 #[tokio::test]
 async fn test_default_provider_chain() {
     if !is_test_enabled() {
@@ -146,3 +207,65 @@ async fn test_chain_returns_none_when_all_fail() {
     assert_eq!(*count1.lock().unwrap(), 1);
     assert_eq!(*count2.lock().unwrap(), 1);
 }
+
+#[tokio::test]
+async fn test_builder_no_env_removes_provider() {
+    let ctx = Context::new()
+        .with_file_read(TokioFileRead)
+        .with_http_send(ReqwestHttpSend::default())
+        .with_env(StaticEnv {
+            home_dir: None,
+            envs: HashMap::from([
+                (
+                    "AZURE_STORAGE_ACCOUNT_NAME".to_string(),
+                    "testaccount".to_string(),
+                ),
+                (
+                    "AZURE_STORAGE_ACCOUNT_KEY".to_string(),
+                    "dGVzdGtleQ==".to_string(),
+                ),
+            ]),
+        });
+
+    let provider = builder_without_other_slots()
+        .env(reqsign_azure_storage::EnvCredentialProvider::new())
+        .build();
+    let result = provider.provide_credential(&ctx).await.unwrap();
+    assert_shared_key(result, "testaccount", "dGVzdGtleQ==");
+
+    let provider = builder_without_other_slots().build();
+    let result = provider.provide_credential(&ctx).await.unwrap();
+    assert!(result.is_none());
+}
+
+#[tokio::test]
+async fn test_builder_no_client_secret_removes_provider() {
+    let ctx = Context::new()
+        .with_file_read(TokioFileRead)
+        .with_http_send(StaticHttpSend {
+            status: http::StatusCode::OK,
+            body: r#"{"access_token":"test-token","expires_in":3600}"#,
+        })
+        .with_env(StaticEnv {
+            home_dir: None,
+            envs: HashMap::from([
+                ("AZURE_TENANT_ID".to_string(), "test-tenant".to_string()),
+                ("AZURE_CLIENT_ID".to_string(), "test-client".to_string()),
+                ("AZURE_CLIENT_SECRET".to_string(), "test-secret".to_string()),
+                (
+                    "AZURE_AUTHORITY_HOST".to_string(),
+                    "https://login.microsoftonline.com".to_string(),
+                ),
+            ]),
+        });
+
+    let provider = builder_without_other_slots()
+        .client_secret(reqsign_azure_storage::ClientSecretCredentialProvider::new())
+        .build();
+    let result = provider.provide_credential(&ctx).await.unwrap();
+    assert_bearer_token(result, "test-token");
+
+    let provider = builder_without_other_slots().build();
+    let result = provider.provide_credential(&ctx).await.unwrap();
+    assert!(result.is_none());
+}