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

Xuanwo pushed a commit to branch 
xuanwo/refactor-oss-typed-oidc-and-default-provider
in repository https://gitbox.apache.org/repos/asf/opendal.git

commit d07089c9385a328dbd5771a0bd6ec7c20b2185a0
Author: Xuanwo <[email protected]>
AuthorDate: Mon Nov 23 14:05:05 2026 +0100

    refactor(services/oss): use typed OIDC builder and DefaultCredentialProvider
    
    - Configure `AssumeRoleWithOidcCredentialProvider` through its typed builder
      methods instead of overlaying config values into a `StaticEnv` snapshot of
      the whole process environment.
    - Build the base credential chain with 
`DefaultCredentialProvider::builder()`
      so OSS also reads `~/.oss/credentials`, the Alibaba Cloud shared 
credentials
      and CLI config files, and `ALIBABA_CLOUD_CREDENTIALS_URI`. Explicit access
      keys stay first, and OIDC keeps its precedence over ECS metadata (#8339).
    - Add `disable_config_load` so those ambient sources can be turned off.
    - Re-export `reqsign_aliyun_oss` for custom credential provider chains.
---
 .../OpenDAL/ServiceConfig/OssServiceConfig.cs      |   8 +
 .../java/org/apache/opendal/ServiceConfig.java     |  13 +
 bindings/python/python/opendal/config.py           |   2 +
 core/services/oss/src/backend.rs                   | 408 +++++++++++++++++----
 core/services/oss/src/config.rs                    |   9 +
 core/services/oss/src/docs.md                      |  13 +-
 core/services/oss/src/lib.rs                       |  10 +
 website/data/services.json                         |  19 +-
 8 files changed, 405 insertions(+), 77 deletions(-)

diff --git a/bindings/dotnet/OpenDAL/ServiceConfig/OssServiceConfig.cs 
b/bindings/dotnet/OpenDAL/ServiceConfig/OssServiceConfig.cs
index 8b2d9bfb07..ac0a212667 100644
--- a/bindings/dotnet/OpenDAL/ServiceConfig/OssServiceConfig.cs
+++ b/bindings/dotnet/OpenDAL/ServiceConfig/OssServiceConfig.cs
@@ -60,6 +60,10 @@ namespace OpenDAL.ServiceConfig
         [System.Obsolete("OSS delete batch capability is enabled by default. 
Use CapabilityOverrideLayer to override delete_max_size for specific 
endpoints.")]
         public long? DeleteMaxSize { get; init; }
         /// <summary>
+        /// Disable loading credentials from ambient sources. This removes the 
environment provider and the OSS profile, Alibaba Cloud shared credentials, 
Alibaba Cloud CLI config, and `ALIBABA_CLOUD_CREDENTIALS_URI` sources. Explicit 
access keys, OIDC options that are all set on the builder, and the `role_arn` 
AssumeRole flow remain enabled, and ECS instance RAM role credentials keep 
loading from instance metadata.
+        /// </summary>
+        public bool? DisableConfigLoad { get; init; }
+        /// <summary>
         /// Deprecated: OSS versioning capability is enabled by default.
         /// </summary>
         [System.Obsolete("OSS versioning capability is enabled by default and 
this option is no longer needed.")]
@@ -160,6 +164,10 @@ namespace OpenDAL.ServiceConfig
                 map["delete_max_size"] = 
Utilities.ToOptionString(DeleteMaxSize);
             }
 #pragma warning restore CS0618
+            if (DisableConfigLoad is not null)
+            {
+                map["disable_config_load"] = 
Utilities.ToOptionString(DisableConfigLoad);
+            }
 #pragma warning disable CS0618
             if (EnableVersioning is not null)
             {
diff --git a/bindings/java/src/main/java/org/apache/opendal/ServiceConfig.java 
b/bindings/java/src/main/java/org/apache/opendal/ServiceConfig.java
index 5a17f08638..829899ab8b 100644
--- a/bindings/java/src/main/java/org/apache/opendal/ServiceConfig.java
+++ b/bindings/java/src/main/java/org/apache/opendal/ServiceConfig.java
@@ -2607,6 +2607,16 @@ public interface ServiceConfig {
          * @deprecated OSS delete batch capability is enabled by default. Use 
CapabilityOverrideLayer to override delete_max_size for specific endpoints.
          */
         public final Long deleteMaxSize;
+        /**
+         * <p>Disable loading credentials from ambient sources.</p>
+         * <p>This removes the environment provider and the OSS profile, 
Alibaba
+         * Cloud shared credentials, Alibaba Cloud CLI config, and
+         * <code>ALIBABA_CLOUD_CREDENTIALS_URI</code> sources. Explicit access 
keys, OIDC
+         * options that are all set on the builder, and the 
<code>role_arn</code> AssumeRole
+         * flow remain enabled, and ECS instance RAM role credentials keep 
loading
+         * from instance metadata.</p>
+         */
+        public final Boolean disableConfigLoad;
         /**
          * <p>Deprecated: OSS versioning capability is enabled by default.</p>
          *
@@ -2718,6 +2728,9 @@ public interface ServiceConfig {
             if (deleteMaxSize != null) {
                 map.put("delete_max_size", String.valueOf(deleteMaxSize));
             }
+            if (disableConfigLoad != null) {
+                map.put("disable_config_load", 
String.valueOf(disableConfigLoad));
+            }
             if (enableVersioning != null) {
                 map.put("enable_versioning", String.valueOf(enableVersioning));
             }
diff --git a/bindings/python/python/opendal/config.py 
b/bindings/python/python/opendal/config.py
index d0e816466e..98c12ab991 100644
--- a/bindings/python/python/opendal/config.py
+++ b/bindings/python/python/opendal/config.py
@@ -663,6 +663,8 @@ class OssConfig(TypedDict):
     """Bucket for oss."""
     delete_max_size: NotRequired[int]
     """Deprecated: OSS delete batch capability is enabled by default. 
[Deprecated since 0.57.0] OSS delete batch capability is enabled by default. 
Use CapabilityOverrideLayer to override delete_max_size for specific 
endpoints."""
+    disable_config_load: NotRequired[bool]
+    """Disable loading credentials from ambient sources.  This removes the 
environment provider and the OSS profile, Alibaba Cloud shared credentials, 
Alibaba Cloud CLI config, and `ALIBABA_CLOUD_CREDENTIALS_URI` sources. Explicit 
access keys, OIDC options that are all set on the builder, and the `role_arn` 
AssumeRole flow remain enabled, and ECS instance RAM role credentials keep 
loading from instance metadata."""
     enable_versioning: NotRequired[bool]
     """Deprecated: OSS versioning capability is enabled by default. 
[Deprecated since 0.57.0] OSS versioning capability is enabled by default and 
this option is no longer needed."""
     endpoint: NotRequired[str]
diff --git a/core/services/oss/src/backend.rs b/core/services/oss/src/backend.rs
index 2ef13a6b04..828bef33c2 100644
--- a/core/services/oss/src/backend.rs
+++ b/core/services/oss/src/backend.rs
@@ -24,16 +24,14 @@ use log::debug;
 use reqsign_aliyun_oss::AssumeRoleCredentialProvider;
 use reqsign_aliyun_oss::AssumeRoleWithOidcCredentialProvider;
 use reqsign_aliyun_oss::Credential;
+use reqsign_aliyun_oss::DefaultCredentialProvider;
 use reqsign_aliyun_oss::EcsRamRoleCredentialProvider;
-use reqsign_aliyun_oss::EnvCredentialProvider;
 use reqsign_aliyun_oss::RequestSigner;
 use reqsign_aliyun_oss::StaticCredentialProvider;
 use reqsign_core::Context;
-use reqsign_core::Env as _;
 use reqsign_core::OsEnv;
 use reqsign_core::ProvideCredentialChain;
 use reqsign_core::Signer;
-use reqsign_core::StaticEnv;
 use reqsign_file_read_tokio::TokioFileRead;
 
 use super::OSS_SCHEME;
@@ -326,6 +324,14 @@ impl OssBuilder {
         self.skip_signature()
     }
 
+    /// Disable loading credentials from ambient sources.
+    ///
+    /// See [`OssConfig::disable_config_load`] for the affected sources.
+    pub fn disable_config_load(mut self) -> Self {
+        self.config.disable_config_load = true;
+        self
+    }
+
     /// Set role_arn for this backend.
     ///
     /// If `role_arn` is set, we will use already known config as source
@@ -484,46 +490,11 @@ impl Builder for OssBuilder {
             ),
         };
 
-        // NOTE: `AssumeRoleWithOidcCredentialProvider` still reads 
`role_arn`, `oidc_provider_arn`
-        // and `oidc_token_file` from `Context` environment variables at 
runtime. Until reqsign
-        // exposes typed builder APIs for all of them, we overlay config 
values into a `StaticEnv`
-        // snapshot here.
-        let os_env = OsEnv;
-        let mut envs = os_env.vars();
-
-        if let Some(v) = &self.config.role_arn {
-            envs.insert("ALIBABA_CLOUD_ROLE_ARN".to_string(), v.clone());
-        }
-        if let Some(v) = &self.config.oidc_provider_arn {
-            envs.insert("ALIBABA_CLOUD_OIDC_PROVIDER_ARN".to_string(), 
v.clone());
-        }
-        if let Some(v) = &self.config.oidc_token_file {
-            envs.insert("ALIBABA_CLOUD_OIDC_TOKEN_FILE".to_string(), 
v.clone());
-        }
-
-        let mut assume_role = AssumeRoleWithOidcCredentialProvider::new();
-
-        if let Some(sts_endpoint) = &self.config.sts_endpoint {
-            if sts_endpoint.starts_with("http://";) || 
sts_endpoint.starts_with("https://";) {
-                assume_role = 
assume_role.with_sts_endpoint(sts_endpoint.clone());
-            } else {
-                envs.insert(
-                    "ALIBABA_CLOUD_STS_ENDPOINT".to_string(),
-                    sts_endpoint.clone(),
-                );
-            }
-        }
-
-        if let Some(role_session_name) = &self.config.role_session_name {
-            assume_role = 
assume_role.with_role_session_name(role_session_name.clone());
-        }
-
-        let ctx = Context::new()
-            .with_file_read(TokioFileRead)
-            .with_env(StaticEnv {
-                home_dir: os_env.home_dir(),
-                envs,
-            });
+        // The signer reads credential files (OIDC tokens, OSS profile and
+        // Alibaba Cloud files) and ambient environment variables through this
+        // context. `OperationContext` supplies the HTTP sender for STS and
+        // metadata requests when requests are signed.
+        let ctx = Context::new().with_file_read(TokioFileRead).with_env(OsEnv);
 
         let static_provider = if let (Some(ak), Some(sk)) =
             (&self.config.access_key_id, &self.config.access_key_secret)
@@ -537,33 +508,87 @@ impl Builder for OssBuilder {
             None
         };
 
-        let mut provider = ProvideCredentialChain::new();
+        // Configure OIDC from builder options so that it never depends on the
+        // environment. Options that are unset keep falling back to their
+        // `ALIBABA_CLOUD_*` environment variables.
+        let mut oidc = AssumeRoleWithOidcCredentialProvider::new();
+        if let Some(v) = self.config.role_arn.as_deref() {
+            oidc = oidc.with_role_arn(v);
+        }
+        if let Some(v) = self.config.oidc_provider_arn.as_deref() {
+            oidc = oidc.with_oidc_provider_arn(v);
+        }
+        if let Some(v) = self.config.oidc_token_file.as_deref() {
+            oidc = oidc.with_oidc_token_file(v);
+        }
+        if let Some(v) = self.config.sts_endpoint.as_deref() {
+            oidc = oidc.with_sts_endpoint(v);
+        }
+        if let Some(v) = self.config.role_session_name.as_deref() {
+            oidc = oidc.with_role_session_name(v);
+        }
+
+        // `role_arn` is taken from this builder only. Disabling the default
+        // assume-role slot keeps an ambient `ALIBABA_CLOUD_ROLE_ARN` from
+        // replacing explicit access keys with an assumed role.
+        //
+        // OIDC must stay ahead of ECS metadata so that ACK RRSA deployments 
use
+        // the pod role instead of the node role (#8339). Both providers are
+        // appended to the chain below instead of using their default slots,
+        // because the default order tries ECS metadata before OIDC.
+        let mut default_credential = DefaultCredentialProvider::builder()
+            .no_assume_role()
+            .no_oidc()
+            .no_ecs_ram_role();
+
+        if self.config.disable_config_load {
+            default_credential = default_credential
+                .no_env()
+                .no_oss_profile()
+                .no_credentials_file()
+                .no_config_file()
+                .no_credentials_uri();
+        }
+
+        // A partially configured OIDC provider still reads the missing options
+        // from the environment, so it only runs when every required option is
+        // set here or when loading ambient configuration is allowed.
+        let oidc_configured_explicitly = self.config.role_arn.is_some()
+            && self.config.oidc_provider_arn.is_some()
+            && self.config.oidc_token_file.is_some();
+
+        let mut provider = 
ProvideCredentialChain::new().push(default_credential.build());
+        if !self.config.disable_config_load || oidc_configured_explicitly {
+            provider = provider.push(oidc);
+        }
+        provider = provider.push(EcsRamRoleCredentialProvider::new());
+
+        // Explicit access keys take precedence over every ambient source.
         if let Some(static_provider) = static_provider {
-            provider = provider.push(static_provider);
+            provider = provider.push_front(static_provider);
         }
-        let mut provider = provider
-            .push(EnvCredentialProvider::new())
-            .push(assume_role)
-            .push(EcsRamRoleCredentialProvider::new());
 
-        if let Some(role_arn) = &self.config.role_arn {
-            let mut assume_role_with_ak = AssumeRoleCredentialProvider::new()
+        // When `role_arn` is configured, the credentials above call STS and 
the
+        // assumed role signs requests.
+        let provider = if let Some(role_arn) = &self.config.role_arn {
+            let mut assume_role = AssumeRoleCredentialProvider::new()
                 .with_base_provider(provider)
-                .with_role_arn(role_arn.clone());
+                .with_role_arn(role_arn);
 
-            if let Some(role_session_name) = &self.config.role_session_name {
-                assume_role_with_ak =
-                    
assume_role_with_ak.with_role_session_name(role_session_name.clone());
+            if let Some(v) = self.config.role_session_name.as_deref() {
+                assume_role = assume_role.with_role_session_name(v);
             }
-            if let Some(external_id) = &self.config.external_id {
-                assume_role_with_ak = 
assume_role_with_ak.with_external_id(external_id.clone());
+            if let Some(v) = self.config.external_id.as_deref() {
+                assume_role = assume_role.with_external_id(v);
             }
-            if let Some(sts_endpoint) = &self.config.sts_endpoint {
-                assume_role_with_ak = 
assume_role_with_ak.with_sts_endpoint(sts_endpoint.clone());
+            if let Some(v) = self.config.sts_endpoint.as_deref() {
+                assume_role = assume_role.with_sts_endpoint(v);
             }
 
-            provider = ProvideCredentialChain::new().push(assume_role_with_ak);
-        }
+            ProvideCredentialChain::new().push(assume_role)
+        } else {
+            provider
+        };
 
         let provider = if let Some(credential_providers) = 
self.credential_providers {
             credential_providers
@@ -894,17 +919,41 @@ mod tests {
 
     use bytes::Bytes;
     use reqsign_core::time::Timestamp;
-    use reqsign_core::{FileRead, HttpSend, ProvideCredential};
+    use reqsign_core::{FileRead, HttpSend, ProvideCredential, StaticEnv};
 
     use super::*;
 
-    #[derive(Debug)]
-    struct OidcTokenFile;
+    #[derive(Clone, Debug, Default)]
+    struct TestFileRead {
+        files: HashMap<String, String>,
+        reads: Arc<Mutex<Vec<String>>>,
+    }
 
-    impl FileRead for OidcTokenFile {
+    impl TestFileRead {
+        fn new(files: impl IntoIterator<Item = (&'static str, &'static str)>) 
-> Self {
+            Self {
+                files: files
+                    .into_iter()
+                    .map(|(path, content)| (path.to_string(), 
content.to_string()))
+                    .collect(),
+                reads: Arc::new(Mutex::new(Vec::new())),
+            }
+        }
+
+        fn reads(&self) -> Vec<String> {
+            self.reads.lock().unwrap().clone()
+        }
+    }
+
+    impl FileRead for TestFileRead {
         async fn file_read(&self, path: &str) -> reqsign_core::Result<Vec<u8>> 
{
-            assert_eq!(path, "/test/oidc-token");
-            Ok(b"test-oidc-token".to_vec())
+            self.reads.lock().unwrap().push(path.to_string());
+            self.files
+                .get(path)
+                .map(|content| content.as_bytes().to_vec())
+                .ok_or_else(|| {
+                    reqsign_core::Error::unexpected(format!("unexpected file 
path: {path}"))
+                })
         }
     }
 
@@ -975,6 +1024,18 @@ mod tests {
                     );
                     
r#"{"Credentials":{"AccessKeyId":"oidc-ak","AccessKeySecret":"oidc-secret","SecurityToken":"oidc-token","Expiration":"2099-01-01T00:00:00Z"}}"#
                 }
+                ("sts.example.com", "/") => {
+                    let query = req.uri().query().unwrap();
+                    if query.contains("Action=AssumeRoleWithOIDC") {
+                        
assert!(query.contains("RoleSessionName=builder-session"));
+                        assert!(query.contains("OIDCToken=test-oidc-token"));
+                        
r#"{"Credentials":{"AccessKeyId":"oidc-ak","AccessKeySecret":"oidc-secret","SecurityToken":"oidc-token","Expiration":"2099-01-01T00:00:00Z"}}"#
+                    } else {
+                        assert!(query.contains("Action=AssumeRole"));
+                        
assert!(query.contains("RoleSessionName=builder-session"));
+                        
r#"{"Credentials":{"AccessKeyId":"assumed-ak","AccessKeySecret":"assumed-secret","SecurityToken":"assumed-token","Expiration":"2099-01-01T00:00:00Z"}}"#
+                    }
+                }
                 ("100.100.100.200", "/latest/api/token") => "metadata-token",
                 ("100.100.100.200", 
"/latest/meta-data/ram/security-credentials/") => "node-role",
                 ("100.100.100.200", 
"/latest/meta-data/ram/security-credentials/node-role") => {
@@ -1040,7 +1101,7 @@ mod tests {
                     home_dir: None,
                     envs,
                 })
-                .with_file_read(OidcTokenFile)
+                .with_file_read(TestFileRead::new([("/test/oidc-token", 
"test-oidc-token")]))
                 .with_http_send(http.clone());
             let signer = backend.core.signer.clone().with_context(ctx);
             let (mut parts, _) = http::Request::builder()
@@ -1137,7 +1198,7 @@ mod tests {
                 home_dir: None,
                 envs,
             })
-            .with_file_read(OidcTokenFile)
+            .with_file_read(TestFileRead::new([("/test/oidc-token", 
"test-oidc-token")]))
             .with_http_send(http.clone());
         let signer = backend.core.signer.clone().with_context(ctx);
 
@@ -1217,4 +1278,213 @@ mod tests {
         assert_eq!(calls.load(Ordering::SeqCst), 2);
         assert!(http.requests.lock().unwrap().is_empty());
     }
+
+    fn build_test_core(builder: OssBuilder) -> Arc<OssCore> {
+        let backend = builder.build().unwrap();
+        let backend = (&backend as &dyn std::any::Any)
+            .downcast_ref::<OssBackend>()
+            .unwrap();
+        backend.core.clone()
+    }
+
+    #[test]
+    fn test_reqsign_aliyun_oss_is_reexported() {
+        // `credential_provider_chain` takes providers built from the
+        // re-exported crate, so this only compiles while the re-export exists
+        // and matches the types used by the service.
+        let provider = 
crate::reqsign_aliyun_oss::StaticCredentialProvider::new("ak", "sk");
+        let chain = ProvideCredentialChain::new().push(provider);
+        let _ = OssBuilder::default().credential_provider_chain(chain);
+    }
+
+    #[tokio::test]
+    async fn test_oidc_credentials_from_builder_config() {
+        let file_read = TestFileRead::new([("/test/oidc-token", 
"test-oidc-token")]);
+        let http = CredentialHttpSend::default();
+        // No `ALIBABA_CLOUD_OIDC_*` or `ALIBABA_CLOUD_ROLE_ARN` variables: the
+        // STS request can only be built when every OIDC option comes from the
+        // builder.
+        let ctx = Context::new()
+            .with_env(StaticEnv {
+                home_dir: None,
+                envs: HashMap::from([(
+                    "ALIBABA_CLOUD_ECS_METADATA_DISABLED".to_string(),
+                    "true".to_string(),
+                )]),
+            })
+            .with_file_read(file_read.clone())
+            .with_http_send(http.clone());
+
+        let core = build_test_core(
+            OssBuilder::default()
+                .bucket("test-bucket")
+                .endpoint("https://oss-cn-hangzhou.aliyuncs.com";)
+                .role_arn("acs:ram::123:role/builder-role")
+                
.oidc_provider_arn("acs:ram::123:oidc-provider/builder-provider")
+                .oidc_token_file("/test/oidc-token")
+                .sts_endpoint("sts.example.com")
+                .role_session_name("builder-session"),
+        );
+        let parts = 
sign_test_request(&core.signer.clone().with_context(ctx)).await;
+
+        // `role_arn` wraps the OIDC credential with an AK-based AssumeRole 
call.
+        assert!(
+            parts.headers[http::header::AUTHORIZATION]
+                .to_str()
+                .unwrap()
+                .starts_with("OSS assumed-ak:")
+        );
+        assert_eq!(parts.headers["x-oss-security-token"], "assumed-token");
+        assert_eq!(file_read.reads(), vec!["/test/oidc-token".to_string()]);
+        assert_eq!(
+            *http.requests.lock().unwrap(),
+            vec![
+                "sts.example.com/".to_string(),
+                "sts.example.com/".to_string()
+            ]
+        );
+    }
+
+    #[tokio::test]
+    async fn test_default_credential_provider_loads_oss_profile_file() {
+        let http = CredentialHttpSend::default();
+        let file_read = TestFileRead::new([(
+            "/mock/oss-credentials",
+            "[default]\naccess_key_id = profile-ak\naccess_key_secret = 
profile-secret\nsecurity_token = profile-token\n",
+        )]);
+        let ctx = Context::new()
+            .with_env(StaticEnv {
+                home_dir: None,
+                envs: HashMap::from([
+                    (
+                        "OSS_CREDENTIAL_PROFILES_FILE".to_string(),
+                        "/mock/oss-credentials".to_string(),
+                    ),
+                    (
+                        "ALIBABA_CLOUD_ECS_METADATA_DISABLED".to_string(),
+                        "true".to_string(),
+                    ),
+                ]),
+            })
+            .with_file_read(file_read.clone())
+            .with_http_send(http.clone());
+
+        let core = build_test_core(
+            OssBuilder::default()
+                .bucket("test-bucket")
+                .endpoint("https://oss-cn-hangzhou.aliyuncs.com";),
+        );
+        let parts = 
sign_test_request(&core.signer.clone().with_context(ctx)).await;
+        assert!(
+            parts.headers[http::header::AUTHORIZATION]
+                .to_str()
+                .unwrap()
+                .starts_with("OSS profile-ak:")
+        );
+        assert_eq!(parts.headers["x-oss-security-token"], "profile-token");
+        assert_eq!(file_read.reads(), 
vec!["/mock/oss-credentials".to_string()]);
+        assert!(http.requests.lock().unwrap().is_empty());
+
+        // Explicit access keys still take precedence over the profile file.
+        let static_file_read = TestFileRead::new([]);
+        let ctx = Context::new()
+            .with_env(StaticEnv {
+                home_dir: None,
+                envs: HashMap::from([
+                    (
+                        "OSS_CREDENTIAL_PROFILES_FILE".to_string(),
+                        "/mock/oss-credentials".to_string(),
+                    ),
+                    (
+                        "ALIBABA_CLOUD_ECS_METADATA_DISABLED".to_string(),
+                        "true".to_string(),
+                    ),
+                ]),
+            })
+            .with_file_read(static_file_read.clone())
+            .with_http_send(http.clone());
+
+        let core = build_test_core(
+            OssBuilder::default()
+                .bucket("test-bucket")
+                .endpoint("https://oss-cn-hangzhou.aliyuncs.com";)
+                .access_key_id("static-ak")
+                .access_key_secret("static-secret")
+                .security_token("static-token"),
+        );
+        let parts = 
sign_test_request(&core.signer.clone().with_context(ctx)).await;
+        assert!(
+            parts.headers[http::header::AUTHORIZATION]
+                .to_str()
+                .unwrap()
+                .starts_with("OSS static-ak:")
+        );
+        assert_eq!(parts.headers["x-oss-security-token"], "static-token");
+        assert!(static_file_read.reads().is_empty());
+    }
+
+    #[tokio::test]
+    async fn test_disable_config_load_skips_ambient_credentials() {
+        let file_read = TestFileRead::new([(
+            "/mock/oss-credentials",
+            "[default]\naccess_key_id = profile-ak\naccess_key_secret = 
profile-secret\n",
+        )]);
+        let http = CredentialHttpSend::default();
+        let ctx = Context::new()
+            .with_env(StaticEnv {
+                home_dir: None,
+                envs: HashMap::from([
+                    (
+                        "ALIBABA_CLOUD_ACCESS_KEY_ID".to_string(),
+                        "env-ak".to_string(),
+                    ),
+                    (
+                        "ALIBABA_CLOUD_ACCESS_KEY_SECRET".to_string(),
+                        "env-secret".to_string(),
+                    ),
+                    (
+                        "ALIBABA_CLOUD_SECURITY_TOKEN".to_string(),
+                        "env-token".to_string(),
+                    ),
+                    (
+                        "ALIBABA_CLOUD_CREDENTIALS_URI".to_string(),
+                        "http://127.0.0.1/credentials".to_string(),
+                    ),
+                    (
+                        "OSS_CREDENTIAL_PROFILES_FILE".to_string(),
+                        "/mock/oss-credentials".to_string(),
+                    ),
+                    (
+                        "ALIBABA_CLOUD_ECS_METADATA_DISABLED".to_string(),
+                        "true".to_string(),
+                    ),
+                ]),
+            })
+            .with_file_read(file_read.clone())
+            .with_http_send(http.clone());
+
+        let core = build_test_core(
+            OssBuilder::default()
+                .bucket("test-bucket")
+                .endpoint("https://oss-cn-hangzhou.aliyuncs.com";)
+                .disable_config_load(),
+        );
+
+        let (mut parts, _) = http::Request::builder()
+            .method(http::Method::PUT)
+            
.uri("https://test-bucket.oss-cn-hangzhou.aliyuncs.com/manifest.json";)
+            .body(())
+            .unwrap()
+            .into_parts();
+        let err = core
+            .signer
+            .clone()
+            .with_context(ctx)
+            .sign(&mut parts, None)
+            .await
+            .expect_err("ambient credentials must not be loaded");
+        assert_eq!(err.to_string(), "failed to load signing credential");
+        assert!(file_read.reads().is_empty());
+        assert!(http.requests.lock().unwrap().is_empty());
+    }
 }
diff --git a/core/services/oss/src/config.rs b/core/services/oss/src/config.rs
index 9a4feeceff..2a5c4a58b3 100644
--- a/core/services/oss/src/config.rs
+++ b/core/services/oss/src/config.rs
@@ -65,6 +65,15 @@ pub struct OssConfig {
     pub allow_anonymous: bool,
 
     // authenticate options
+    /// Disable loading credentials from ambient sources.
+    ///
+    /// This removes the environment provider and the OSS profile, Alibaba
+    /// Cloud shared credentials, Alibaba Cloud CLI config, and
+    /// `ALIBABA_CLOUD_CREDENTIALS_URI` sources. Explicit access keys, OIDC
+    /// options that are all set on the builder, and the `role_arn` AssumeRole
+    /// flow remain enabled, and ECS instance RAM role credentials keep loading
+    /// from instance metadata.
+    pub disable_config_load: bool,
     /// Access key id for oss.
     ///
     /// - this field if it's `is_some`
diff --git a/core/services/oss/src/docs.md b/core/services/oss/src/docs.md
index 6ea8e8ced6..f48ccde592 100644
--- a/core/services/oss/src/docs.md
+++ b/core/services/oss/src/docs.md
@@ -23,7 +23,9 @@ accepted values, defaults, and environment interaction.
 
 ### Credential resolution
 
-OSS tries explicit access keys, environment credentials, OIDC assume-role
+OSS tries explicit access keys, environment credentials, the OSS profile file
+(`~/.oss/credentials`), the Alibaba Cloud shared credentials and CLI config
+files, credentials from `ALIBABA_CLOUD_CREDENTIALS_URI`, OIDC assume-role
 credentials, and ECS instance RAM role credentials, in that order. The first
 provider that returns credentials is used. In ACK RRSA deployments, OIDC
 credentials therefore take precedence over the node's ECS metadata credentials.
@@ -33,6 +35,13 @@ An OSS permission error does not trigger a switch to another 
credential provider
 When `role_arn` is set in the service configuration, these providers supply the
 base credentials for the additional AK-based AssumeRole request.
 
+Set [`OssBuilder::disable_config_load`] to stop reading ambient configuration:
+the environment, `~/.oss/credentials`, the Alibaba Cloud shared credentials and
+CLI config files, and `ALIBABA_CLOUD_CREDENTIALS_URI`. Explicit access keys, 
OIDC
+options that are all set on the builder, and the `role_arn` flow keep working.
+ECS instance RAM role credentials still load because they come from instance
+metadata instead of local configuration.
+
 [`OssBuilder::credential_provider_chain`] replaces this entire chain, including
 the additional AssumeRole provider. Explicit access keys,
 `ALIBABA_CLOUD_*` environment credentials, `role_arn`, OIDC settings, and ECS
@@ -88,7 +97,7 @@ use opendal_core::reqsign_core;
 use opendal_core::reqsign_core::time::Timestamp;
 use opendal_core::reqsign_core::{Context, ProvideCredential, 
ProvideCredentialChain};
 use opendal_service_oss::Oss;
-use reqsign_aliyun_oss::Credential;
+use opendal_service_oss::reqsign_aliyun_oss::Credential;
 
 #[derive(Debug)]
 struct CustomStsProvider;
diff --git a/core/services/oss/src/lib.rs b/core/services/oss/src/lib.rs
index 26e5785577..dc6c51efac 100644
--- a/core/services/oss/src/lib.rs
+++ b/core/services/oss/src/lib.rs
@@ -31,6 +31,16 @@ mod writer;
 pub use backend::OssBuilder as Oss;
 pub use config::OssConfig;
 
+/// Re-export of the [`reqsign_aliyun_oss`] crate that this service signs
+/// requests with.
+///
+/// [`Oss::credential_provider_chain`] takes a chain of providers for
+/// [`reqsign_aliyun_oss::Credential`]. Implement providers against this
+/// re-export and [`opendal_core::reqsign_core`] rather than depending on the
+/// `reqsign` crates directly, so that the types always match the ones this
+/// service is built with.
+pub use reqsign_aliyun_oss;
+
 /// URI scheme used for service registration and scheme-driven construction.
 pub const OSS_SCHEME: &str = "oss";
 
diff --git a/website/data/services.json b/website/data/services.json
index e576fdf20d..6f4669b213 100644
--- a/website/data/services.json
+++ b/website/data/services.json
@@ -3628,6 +3628,13 @@
           },
           "comments": "Allow anonymous for oss."
         },
+        {
+          "name": "disable_config_load",
+          "type": "bool",
+          "required": false,
+          "group": "General",
+          "comments": "Disable loading credentials from ambient 
sources.\n\nThis removes the environment provider and the OSS profile, 
Alibaba\nCloud shared credentials, Alibaba Cloud CLI config, 
and\n`ALIBABA_CLOUD_CREDENTIALS_URI` sources. Explicit access keys, 
OIDC\noptions that are all set on the builder, and the `role_arn` 
AssumeRole\nflow remain enabled, and ECS instance RAM role credentials keep 
loading\nfrom instance metadata."
+        },
         {
           "name": "access_key_id",
           "type": "string",
@@ -3719,37 +3726,37 @@
           "binding": "rust",
           "language": "rust",
           "minimal": "use opendal::Operator;\n\nlet operator = 
Operator::via_iter(\"oss\", [\n    (\"bucket\".to_string(), 
\"...\".to_string()),\n])?;",
-          "full": "use opendal::Operator;\n\nlet operator = 
Operator::via_iter(\"oss\", [\n    // Root for oss.\n    // 
(\"root\".to_string(), \"...\".to_string()),\n\n    // Endpoint for oss.\n    
// (\"endpoint\".to_string(), \"...\".to_string()),\n\n    // Presign endpoint 
for oss.\n    // (\"presign_endpoint\".to_string(), \"...\".to_string()),\n\n   
 // Bucket for oss.\n    (\"bucket\".to_string(), \"...\".to_string()),\n\n    
// Addressing style for oss.\n    // (\"addressing_style [...]
+          "full": "use opendal::Operator;\n\nlet operator = 
Operator::via_iter(\"oss\", [\n    // Root for oss.\n    // 
(\"root\".to_string(), \"...\".to_string()),\n\n    // Endpoint for oss.\n    
// (\"endpoint\".to_string(), \"...\".to_string()),\n\n    // Presign endpoint 
for oss.\n    // (\"presign_endpoint\".to_string(), \"...\".to_string()),\n\n   
 // Bucket for oss.\n    (\"bucket\".to_string(), \"...\".to_string()),\n\n    
// Addressing style for oss.\n    // (\"addressing_style [...]
         },
         {
           "binding": "java",
           "language": "java",
           "minimal": "import java.util.HashMap;\nimport java.util.Map;\nimport 
org.apache.opendal.Operator;\n\nMap<String, String> config = new 
HashMap<>();\nconfig.put(\"bucket\", \"...\");\nOperator operator = 
Operator.of(\"oss\", config);",
-          "full": "import java.util.HashMap;\nimport java.util.Map;\nimport 
org.apache.opendal.Operator;\n\nMap<String, String> config = new 
HashMap<>();\n// Root for oss.\n// config.put(\"root\", \"...\");\n\n// 
Endpoint for oss.\n// config.put(\"endpoint\", \"...\");\n\n// Presign endpoint 
for oss.\n// config.put(\"presign_endpoint\", \"...\");\n\n// Bucket for 
oss.\nconfig.put(\"bucket\", \"...\");\n\n// Addressing style for oss.\n// 
config.put(\"addressing_style\", \"...\");\n\n// Pr [...]
+          "full": "import java.util.HashMap;\nimport java.util.Map;\nimport 
org.apache.opendal.Operator;\n\nMap<String, String> config = new 
HashMap<>();\n// Root for oss.\n// config.put(\"root\", \"...\");\n\n// 
Endpoint for oss.\n// config.put(\"endpoint\", \"...\");\n\n// Presign endpoint 
for oss.\n// config.put(\"presign_endpoint\", \"...\");\n\n// Bucket for 
oss.\nconfig.put(\"bucket\", \"...\");\n\n// Addressing style for oss.\n// 
config.put(\"addressing_style\", \"...\");\n\n// Pr [...]
         },
         {
           "binding": "python",
           "language": "python",
           "minimal": "import opendal\n\noperator = opendal.Operator(\n    
\"oss\",\n    bucket=\"...\",\n)",
-          "full": "import opendal\n\noperator = opendal.Operator(\n    
\"oss\",\n    # Root for oss.\n    # root=\"...\",\n\n    # Endpoint for oss.\n 
   # endpoint=\"...\",\n\n    # Presign endpoint for oss.\n    # 
presign_endpoint=\"...\",\n\n    # Bucket for oss.\n    bucket=\"...\",\n\n    
# Addressing style for oss.\n    # addressing_style=\"...\",\n\n    # Pre sign 
addressing style for oss.\n    # presign_addressing_style=\"...\",\n\n    # 
Server side encryption for oss.\n    # ser [...]
+          "full": "import opendal\n\noperator = opendal.Operator(\n    
\"oss\",\n    # Root for oss.\n    # root=\"...\",\n\n    # Endpoint for oss.\n 
   # endpoint=\"...\",\n\n    # Presign endpoint for oss.\n    # 
presign_endpoint=\"...\",\n\n    # Bucket for oss.\n    bucket=\"...\",\n\n    
# Addressing style for oss.\n    # addressing_style=\"...\",\n\n    # Pre sign 
addressing style for oss.\n    # presign_addressing_style=\"...\",\n\n    # 
Server side encryption for oss.\n    # ser [...]
         },
         {
           "binding": "nodejs",
           "language": "javascript",
           "minimal": "import { Operator } from \"opendal\";\n\nconst operator 
= new Operator(\"oss\", {\n  bucket: \"...\",\n});",
-          "full": "import { Operator } from \"opendal\";\n\nconst operator = 
new Operator(\"oss\", {\n  // Root for oss.\n  // root: \"...\",\n\n  // 
Endpoint for oss.\n  // endpoint: \"...\",\n\n  // Presign endpoint for oss.\n  
// presign_endpoint: \"...\",\n\n  // Bucket for oss.\n  bucket: \"...\",\n\n  
// Addressing style for oss.\n  // addressing_style: \"...\",\n\n  // Pre sign 
addressing style for oss.\n  // presign_addressing_style: \"...\",\n\n  // 
Server side encryption for os [...]
+          "full": "import { Operator } from \"opendal\";\n\nconst operator = 
new Operator(\"oss\", {\n  // Root for oss.\n  // root: \"...\",\n\n  // 
Endpoint for oss.\n  // endpoint: \"...\",\n\n  // Presign endpoint for oss.\n  
// presign_endpoint: \"...\",\n\n  // Bucket for oss.\n  bucket: \"...\",\n\n  
// Addressing style for oss.\n  // addressing_style: \"...\",\n\n  // Pre sign 
addressing style for oss.\n  // presign_addressing_style: \"...\",\n\n  // 
Server side encryption for os [...]
         },
         {
           "binding": "ruby",
           "language": "ruby",
           "minimal": "require \"opendal\"\n\noperator = 
OpenDal::Operator.new(\"oss\", {\n  \"bucket\" => \"...\",\n})",
-          "full": "require \"opendal\"\n\noperator = 
OpenDal::Operator.new(\"oss\", {\n  # Root for oss.\n  # \"root\" => 
\"...\",\n\n  # Endpoint for oss.\n  # \"endpoint\" => \"...\",\n\n  # Presign 
endpoint for oss.\n  # \"presign_endpoint\" => \"...\",\n\n  # Bucket for 
oss.\n  \"bucket\" => \"...\",\n\n  # Addressing style for oss.\n  # 
\"addressing_style\" => \"...\",\n\n  # Pre sign addressing style for oss.\n  # 
\"presign_addressing_style\" => \"...\",\n\n  # Server side encrypti [...]
+          "full": "require \"opendal\"\n\noperator = 
OpenDal::Operator.new(\"oss\", {\n  # Root for oss.\n  # \"root\" => 
\"...\",\n\n  # Endpoint for oss.\n  # \"endpoint\" => \"...\",\n\n  # Presign 
endpoint for oss.\n  # \"presign_endpoint\" => \"...\",\n\n  # Bucket for 
oss.\n  \"bucket\" => \"...\",\n\n  # Addressing style for oss.\n  # 
\"addressing_style\" => \"...\",\n\n  # Pre sign addressing style for oss.\n  # 
\"presign_addressing_style\" => \"...\",\n\n  # Server side encrypti [...]
         },
         {
           "binding": "go",
           "language": "go",
           "minimal": "import 
(\n\t\"github.com/apache/opendal-go-services/oss\"\n\topendal 
\"github.com/apache/opendal/bindings/go\"\n)\n\noperator, err := 
opendal.NewOperator(oss.Scheme, opendal.OperatorOptions{\n\t\"bucket\": 
\"...\",\n})",
-          "full": "import 
(\n\t\"github.com/apache/opendal-go-services/oss\"\n\topendal 
\"github.com/apache/opendal/bindings/go\"\n)\n\noperator, err := 
opendal.NewOperator(oss.Scheme, opendal.OperatorOptions{\n\t// Root for 
oss.\n\t// \"root\": \"...\",\n\n\t// Endpoint for oss.\n\t// \"endpoint\": 
\"...\",\n\n\t// Presign endpoint for oss.\n\t// \"presign_endpoint\": 
\"...\",\n\n\t// Bucket for oss.\n\t\"bucket\": \"...\",\n\n\t// Addressing 
style for oss.\n\t// \"addressing_style\": \ [...]
+          "full": "import 
(\n\t\"github.com/apache/opendal-go-services/oss\"\n\topendal 
\"github.com/apache/opendal/bindings/go\"\n)\n\noperator, err := 
opendal.NewOperator(oss.Scheme, opendal.OperatorOptions{\n\t// Root for 
oss.\n\t// \"root\": \"...\",\n\n\t// Endpoint for oss.\n\t// \"endpoint\": 
\"...\",\n\n\t// Presign endpoint for oss.\n\t// \"presign_endpoint\": 
\"...\",\n\n\t// Bucket for oss.\n\t\"bucket\": \"...\",\n\n\t// Addressing 
style for oss.\n\t// \"addressing_style\": \ [...]
         }
       ]
     },

Reply via email to