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

sollhui pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 314bfc2ccfc [refactor](storage) Simplify container credentials 
provider construction (#69316)
314bfc2ccfc is described below

commit 314bfc2ccfc653c42cb8499bc493cd105c7e4972
Author: hui lai <[email protected]>
AuthorDate: Wed Nov 25 12:01:28 2026 +0800

    [refactor](storage) Simplify container credentials provider construction 
(#69316)
    
    ### What problem does this PR solve?
    
    Related PR: #67076
    
    Simplify the container credentials setup added by #67076. Construct
    `GeneralHTTPCredentialsProvider` directly from the four
    `AWS_CONTAINER_*` environment variables using the SDK's own constants,
    and remove duplicate constants, endpoint-selection logging, and lengthy
    wiring comments. The SDK continues to handle URI precedence, token-file
    loading, and credential refresh.
    
    Share the four container environment assignments in one private test
    helper, retaining the ECS, Pod Identity, and inline-token scenario
    methods.
    
    Keep the custom default chain and its provider order unchanged. Preserve
    the SDK 1.11.221 token/token-file argument order and the existing ECS,
    EKS token-rotation, MSK, and recycler tests.
---
 .../cpp/custom_aws_credentials_provider_chain.cpp  |  3 --
 .../auth/aws/aws_credential_provider.cpp           | 61 ++++------------------
 .../obj-storage/auth/aws/aws_credential_provider.h | 20 +------
 common/cpp/test/container_credentials_test_util.h  | 36 +++++++------
 4 files changed, 33 insertions(+), 87 deletions(-)

diff --git a/common/cpp/custom_aws_credentials_provider_chain.cpp 
b/common/cpp/custom_aws_credentials_provider_chain.cpp
index c7c390e788b..0d81fec82dc 100644
--- a/common/cpp/custom_aws_credentials_provider_chain.cpp
+++ b/common/cpp/custom_aws_credentials_provider_chain.cpp
@@ -45,9 +45,6 @@ 
CustomAwsCredentialsProviderChain::CustomAwsCredentialsProviderChain()
                         "The environment variable value " << 
AWS_EC2_METADATA_DISABLED << " is "
                                                           << 
ec2MetadataDisabled);
 
-    // One provider serves both container platforms: 
create_container_credentials_provider() reads
-    // all four AWS_CONTAINER_* variables, applies the provider's own 
relative-then-absolute
-    // precedence, and logs which variable supplied the endpoint.
     if (container_credentials_available()) {
         AddProvider(create_container_credentials_provider());
     }
diff --git a/common/cpp/obj-storage/auth/aws/aws_credential_provider.cpp 
b/common/cpp/obj-storage/auth/aws/aws_credential_provider.cpp
index 26cb26a7ddc..88ecdae4365 100644
--- a/common/cpp/obj-storage/auth/aws/aws_credential_provider.cpp
+++ b/common/cpp/obj-storage/auth/aws/aws_credential_provider.cpp
@@ -19,15 +19,10 @@
 
 #include <aws/core/auth/GeneralHTTPCredentialsProvider.h>
 #include <aws/core/platform/Environment.h>
-#include <aws/core/utils/memory/AWSMemory.h>
 #include <glog/logging.h>
 
 namespace doris {
 
-namespace {
-const char CONTAINER_CREDENTIALS_PROVIDER_TAG[] = 
"ContainerCredentialsProvider";
-} // namespace
-
 CredProviderType cred_provider_type_from_string(const std::string& type) {
     if (type.empty() || type == "DEFAULT") {
         return CredProviderType::Default;
@@ -58,54 +53,20 @@ CredProviderType cred_provider_type_from_string(const 
std::string& type) {
 }
 
 bool container_credentials_available() {
-    return 
!Aws::Environment::GetEnv(AWS_CONTAINER_CREDENTIALS_RELATIVE_URI).empty() ||
-           
!Aws::Environment::GetEnv(AWS_CONTAINER_CREDENTIALS_FULL_URI).empty();
+    using Provider = Aws::Auth::GeneralHTTPCredentialsProvider;
+    using Aws::Environment::GetEnv;
+    return !GetEnv(Provider::AWS_CONTAINER_CREDENTIALS_RELATIVE_URI).empty() ||
+           !GetEnv(Provider::AWS_CONTAINER_CREDENTIALS_FULL_URI).empty();
 }
 
 std::shared_ptr<Aws::Auth::AWSCredentialsProvider> 
create_container_credentials_provider() {
-    const auto relative_uri = 
Aws::Environment::GetEnv(AWS_CONTAINER_CREDENTIALS_RELATIVE_URI);
-    const auto absolute_uri = 
Aws::Environment::GetEnv(AWS_CONTAINER_CREDENTIALS_FULL_URI);
-    const auto token = 
Aws::Environment::GetEnv(AWS_CONTAINER_AUTHORIZATION_TOKEN);
-    const auto token_path = 
Aws::Environment::GetEnv(AWS_CONTAINER_AUTHORIZATION_TOKEN_FILE);
-
-    // Both URIs are forwarded and the provider decides between them: a 
non-empty relative URI wins
-    // and is resolved against the ECS agent's address, otherwise the full URI 
is used as-is. This
-    // is the same precedence the AWS SDK's own default chain applies.
-    //
-    // Both token forms are forwarded for the same reason. The endpoint 
authenticates every fetch
-    // with a bearer token, which the provider takes either inline or as a 
file path, and given a
-    // path it re-reads the file before each fetch. ECS sets only the inline 
variable, EKS Pod
-    // Identity sets only the file one - so forwarding the path is what makes 
the Authorization header
-    // non-empty under Pod Identity, and what keeps it valid once the kubelet 
rotates the file.
-    //
-    // NOTE: The header file names its third parameter authTokenFilePath and 
its fourth authToken,
-    // but the implementation binds them the other way round. The header is 
the side that is wrong,
-    // not the definition. This is reported as aws/aws-sdk-cpp#3143, fixed by
-    // aws/aws-sdk-cpp#3162.
-    auto provider = Aws::MakeShared<Aws::Auth::GeneralHTTPCredentialsProvider>(
-            CONTAINER_CREDENTIALS_PROVIDER_TAG, relative_uri, absolute_uri, 
token, token_path);
-
-    const bool uses_relative_uri = !relative_uri.empty();
-    const char* const uri_var = uses_relative_uri ? 
AWS_CONTAINER_CREDENTIALS_RELATIVE_URI
-                                                  : 
AWS_CONTAINER_CREDENTIALS_FULL_URI;
-    const auto& uri = uses_relative_uri ? relative_uri : absolute_uri;
-
-    if (relative_uri.empty() && absolute_uri.empty()) {
-        LOG(WARNING) << "Container credentials provider has no endpoint to 
call and will return no "
-                        "credentials: neither "
-                     << AWS_CONTAINER_CREDENTIALS_RELATIVE_URI << " nor "
-                     << AWS_CONTAINER_CREDENTIALS_FULL_URI << " is set.";
-    } else {
-        LOG(INFO)
-                << "Created container credentials provider from " << uri_var 
<< ": [" << uri
-                << "] with a" << (token.empty() ? "n empty" : " non-empty")
-                << " inline authorization token and a"
-                << (token_path.empty() ? "n empty" : " non-empty")
-                << " authorization token file path: [" << token_path
-                << "]. If credentials come back empty, raise aws_log_level to 
3 or higher for the "
-                   "SDK's own reason.";
-    }
-    return provider;
+    using Provider = Aws::Auth::GeneralHTTPCredentialsProvider;
+    using Aws::Environment::GetEnv;
+    // SDK 1.11.221's header swaps the token and token-file parameter names; 
follow the implementation.
+    return 
std::make_shared<Provider>(GetEnv(Provider::AWS_CONTAINER_CREDENTIALS_RELATIVE_URI),
+                                      
GetEnv(Provider::AWS_CONTAINER_CREDENTIALS_FULL_URI),
+                                      
GetEnv(Provider::AWS_CONTAINER_AUTHORIZATION_TOKEN),
+                                      
GetEnv(Provider::AWS_CONTAINER_AUTHORIZATION_TOKEN_FILE));
 }
 
 } // namespace doris
diff --git a/common/cpp/obj-storage/auth/aws/aws_credential_provider.h 
b/common/cpp/obj-storage/auth/aws/aws_credential_provider.h
index f6340c5b709..11d6067ce6f 100644
--- a/common/cpp/obj-storage/auth/aws/aws_credential_provider.h
+++ b/common/cpp/obj-storage/auth/aws/aws_credential_provider.h
@@ -38,26 +38,10 @@ enum class CredProviderType {
     Anonymous = 7
 };
 
-// The environment variables through which a container runtime advertises its 
credentials
-// endpoint. ECS exports a relative URI, which is a path resolved against the 
ECS agent's fixed
-// link-local address, and optionally an inline authorization token. EKS Pod 
Identity exports a
-// full URI, which is a complete URL, and an authorization token file that the 
kubelet rotates in
-// place. A runtime never sets both URIs, so code that reads only one of them 
silently gets
-// nothing on the other platform.
-inline constexpr char AWS_CONTAINER_CREDENTIALS_RELATIVE_URI[] =
-        "AWS_CONTAINER_CREDENTIALS_RELATIVE_URI";
-inline constexpr char AWS_CONTAINER_CREDENTIALS_FULL_URI[] = 
"AWS_CONTAINER_CREDENTIALS_FULL_URI";
-inline constexpr char AWS_CONTAINER_AUTHORIZATION_TOKEN[] = 
"AWS_CONTAINER_AUTHORIZATION_TOKEN";
-inline constexpr char AWS_CONTAINER_AUTHORIZATION_TOKEN_FILE[] =
-        "AWS_CONTAINER_AUTHORIZATION_TOKEN_FILE";
-
 CredProviderType cred_provider_type_from_string(const std::string& type);
 
-// Builds the credentials provider that talks to a container runtime's 
credentials endpoint, from
-// the four AWS_CONTAINER_* environment variables above. Every caller that 
asks for container credentials
-// - the default provider chain, and the explicit CONTAINER/ECS provider modes 
of the BE S3 client
-// factory, the cloud recycler and the Kafka MSK IAM signer - has to support 
both ECS and EKS Pod
-// Identity, so none of them can afford to read a subset of the variables.
+// Builds the ECS / EKS provider from AWS_CONTAINER_* environment variables.
+// The SDK handles URI precedence and re-reads the authorization token file on 
credential refresh.
 std::shared_ptr<Aws::Auth::AWSCredentialsProvider> 
create_container_credentials_provider();
 
 // True when the runtime advertises a container credentials endpoint through 
either URI variable.
diff --git a/common/cpp/test/container_credentials_test_util.h 
b/common/cpp/test/container_credentials_test_util.h
index 8a30f5fba0c..07b2d24a331 100644
--- a/common/cpp/test/container_credentials_test_util.h
+++ b/common/cpp/test/container_credentials_test_util.h
@@ -31,8 +31,6 @@
 #include <string>
 #include <vector>
 
-#include "cpp/obj-storage/auth/aws/aws_credential_provider.h"
-
 // Test support for the container credentials provider built by
 // create_container_credentials_provider(). It lives in common/cpp/test 
because both test trees need
 // it and neither can include the other's: the BE unit tests cover the S3 
client factory and the
@@ -42,6 +40,8 @@ namespace doris {
 
 // Clears the four AWS_CONTAINER_* variables on construction and restores them 
on destruction.
 class ContainerCredentialsEnvGuard {
+    using Provider = Aws::Auth::GeneralHTTPCredentialsProvider;
+
 public:
     ContainerCredentialsEnvGuard() {
         for (const char* name : kNames) {
@@ -71,26 +71,17 @@ public:
     // Presents the environment the way EKS Pod Identity does: a full URL, a 
token that exists only
     // as a file, and no relative URI or inline token at all.
     void set_pod_identity(const std::string& full_uri, const std::string& 
token_file) {
-        unsetenv(AWS_CONTAINER_CREDENTIALS_RELATIVE_URI);
-        unsetenv(AWS_CONTAINER_AUTHORIZATION_TOKEN);
-        setenv(AWS_CONTAINER_CREDENTIALS_FULL_URI, full_uri.c_str(), 1);
-        setenv(AWS_CONTAINER_AUTHORIZATION_TOKEN_FILE, token_file.c_str(), 1);
+        set_environment({nullptr, full_uri.c_str(), nullptr, 
token_file.c_str()});
     }
 
     // Presents the environment the way ECS does: a relative path against the 
agent's own address,
     // and no full URI or token file.
     void set_ecs_task_role(const std::string& relative_uri) {
-        unsetenv(AWS_CONTAINER_CREDENTIALS_FULL_URI);
-        unsetenv(AWS_CONTAINER_AUTHORIZATION_TOKEN);
-        unsetenv(AWS_CONTAINER_AUTHORIZATION_TOKEN_FILE);
-        setenv(AWS_CONTAINER_CREDENTIALS_RELATIVE_URI, relative_uri.c_str(), 
1);
+        set_environment({relative_uri.c_str(), nullptr, nullptr, nullptr});
     }
 
     void set_inline_token_endpoint(const std::string& full_uri, const 
std::string& token) {
-        unsetenv(AWS_CONTAINER_CREDENTIALS_RELATIVE_URI);
-        unsetenv(AWS_CONTAINER_AUTHORIZATION_TOKEN_FILE);
-        setenv(AWS_CONTAINER_CREDENTIALS_FULL_URI, full_uri.c_str(), 1);
-        setenv(AWS_CONTAINER_AUTHORIZATION_TOKEN, token.c_str(), 1);
+        set_environment({nullptr, full_uri.c_str(), token.c_str(), nullptr});
     }
 
     // Writes a token file and takes responsibility for deleting it. Call it 
again with the same path
@@ -108,9 +99,22 @@ public:
     }
 
 private:
+    // nullptr unsets a variable; an empty string keeps it set with an empty 
value.
+    static void set_environment(const std::array<const char*, 4>& values) {
+        for (size_t i = 0; i < kNames.size(); ++i) {
+            if (values[i] != nullptr) {
+                setenv(kNames[i], values[i], 1);
+            } else {
+                unsetenv(kNames[i]);
+            }
+        }
+    }
+
     static constexpr std::array<const char*, 4> kNames {
-            AWS_CONTAINER_CREDENTIALS_RELATIVE_URI, 
AWS_CONTAINER_CREDENTIALS_FULL_URI,
-            AWS_CONTAINER_AUTHORIZATION_TOKEN, 
AWS_CONTAINER_AUTHORIZATION_TOKEN_FILE};
+            Provider::AWS_CONTAINER_CREDENTIALS_RELATIVE_URI,
+            Provider::AWS_CONTAINER_CREDENTIALS_FULL_URI,
+            Provider::AWS_CONTAINER_AUTHORIZATION_TOKEN,
+            Provider::AWS_CONTAINER_AUTHORIZATION_TOKEN_FILE};
 
     std::vector<std::optional<std::string>> _saved;
     std::vector<std::string> _token_files;


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to