@@ -132,8 +132,15 @@ MetadataCredentialsProviderBase::MetadataCredentialsProviderBase(
132132 cluster_name_(std::string(cluster_name)), cluster_type_(cluster_type), uri_(std::string(uri)),
133133 cache_duration_(getCacheDuration()), refresh_state_(refresh_state),
134134 initialization_timer_(initialization_timer), debug_name_(cluster_name) {
135+
136+ // Most code sets the context and uses the async http client, except for one extension
137+ // which is scheduled to be deprecated and deleted. Modes can no longer be switched via runtime,
138+ // so each caller should only pass parameters to support a single mode.
139+ // https://github.com/envoyproxy/envoy/issues/36910
140+ ASSERT ((context.has_value () ^ (fetch_metadata_using_curl != nullptr )));
141+
135142 // Async provider cluster setup
136- if (useHttpAsyncClient () && context_) {
143+ if (context_) {
137144 // Set up metadata credentials statistics
138145 scope_ = api.rootScope ().createScope (
139146 fmt::format (" aws.metadata_credentials_provider.{}." , cluster_name_));
@@ -249,7 +256,7 @@ void MetadataCredentialsProviderBase::ThreadLocalCredentialsCache::onClusterRemo
249256
250257// Async provider uses its own refresh mechanism. Calling refreshIfNeeded() here is not thread safe.
251258Credentials MetadataCredentialsProviderBase::getCredentials () {
252- if (useHttpAsyncClient () ) {
259+ if (context_ ) {
253260 if (tls_slot_) {
254261 return *(*tls_slot_)->credentials_ .get ();
255262 } else {
@@ -269,7 +276,7 @@ std::chrono::seconds MetadataCredentialsProviderBase::getCacheDuration() {
269276}
270277
271278void MetadataCredentialsProviderBase::handleFetchDone () {
272- if (useHttpAsyncClient () && context_) {
279+ if (context_) {
273280 if (cache_duration_timer_ && !cache_duration_timer_->enabled ()) {
274281 // Receiver state handles the initial credential refresh scenario. If for some reason we are
275282 // unable to perform credential refresh after cluster initialization has completed, we use a
@@ -317,11 +324,6 @@ void MetadataCredentialsProviderBase::setCredentialsToAllThreads(
317324 }
318325}
319326
320- bool MetadataCredentialsProviderBase::useHttpAsyncClient () {
321- return Runtime::runtimeFeatureEnabled (
322- " envoy.reloadable_features.use_http_client_to_fetch_aws_credentials" );
323- }
324-
325327bool CredentialsFileCredentialsProvider::needsRefresh () {
326328 return api_.timeSource ().systemTime () - last_updated_ > REFRESH_INTERVAL;
327329}
@@ -403,7 +405,7 @@ void InstanceProfileCredentialsProvider::refresh() {
403405 token_req_message.headers ().setCopy (Http::LowerCaseString (EC2_IMDS_TOKEN_TTL_HEADER),
404406 EC2_IMDS_TOKEN_TTL_DEFAULT_VALUE);
405407
406- if (!useHttpAsyncClient () || ! context_) {
408+ if (!context_) {
407409 // Using curl to fetch the AWS credentials where we first get the token.
408410 const auto token_string = fetch_metadata_using_curl_ (token_req_message);
409411 if (token_string) {
@@ -555,7 +557,7 @@ void InstanceProfileCredentialsProvider::extractCredentials(
555557 session_token.empty () ? " " : " *****" );
556558
557559 last_updated_ = api_.timeSource ().systemTime ();
558- if (useHttpAsyncClient () && context_) {
560+ if (context_) {
559561 setCredentialsToAllThreads (
560562 std::make_unique<Credentials>(access_key_id, secret_access_key, session_token));
561563 stats_->credential_refreshes_succeeded_ .inc ();
@@ -642,7 +644,7 @@ void ContainerCredentialsProvider::refresh() {
642644 message.headers ().setHost (host);
643645 message.headers ().setPath (path);
644646 message.headers ().setCopy (Http::CustomHeaders::get ().Authorization , authorization_header);
645- if (!useHttpAsyncClient () || ! context_) {
647+ if (!context_) {
646648 // Using curl to fetch the AWS credentials.
647649 const auto credential_document = fetch_metadata_using_curl_ (message);
648650 if (!credential_document) {
@@ -708,7 +710,7 @@ void ContainerCredentialsProvider::extractCredentials(
708710 }
709711
710712 last_updated_ = api_.timeSource ().systemTime ();
711- if (useHttpAsyncClient () && context_) {
713+ if (context_) {
712714 setCredentialsToAllThreads (
713715 std::make_unique<Credentials>(access_key_id, secret_access_key, session_token));
714716 ENVOY_LOG (debug, " Metadata receiver {} moving to Ready state" , cluster_name_);
@@ -760,12 +762,6 @@ bool WebIdentityCredentialsProvider::needsRefresh() {
760762}
761763
762764void WebIdentityCredentialsProvider::refresh () {
763- // If http async client is not enabled then just set empty credentials and return.
764- if (!useHttpAsyncClient ()) {
765- cached_credentials_ = Credentials ();
766- return ;
767- }
768-
769765 ENVOY_LOG (debug, " Getting AWS web identity credentials from STS: {}" , sts_endpoint_);
770766
771767 std::string identity_token = token_;
@@ -1085,9 +1081,8 @@ absl::StatusOr<CredentialsProviderSharedPtr> createCredentialsProviderFromConfig
10851081 // This "two seconds" is a bit arbitrary, but matches the other places in the codebase.
10861082 const auto initialization_timer = std::chrono::seconds (2 );
10871083 return std::make_shared<WebIdentityCredentialsProvider>(
1088- context.api (), context, Extensions::Common::Aws::Utility::fetchMetadata,
1089- MetadataFetcher::create, " " , token, sts_endpoint, role_arn, role_session_name,
1090- refresh_state, initialization_timer, cluster_name);
1084+ context.api (), context, nullptr , MetadataFetcher::create, " " , token, sts_endpoint, role_arn,
1085+ role_session_name, refresh_state, initialization_timer, cluster_name);
10911086 } else {
10921087 return absl::InvalidArgumentError (" No AWS credential provider specified" );
10931088 }
0 commit comments