-
Notifications
You must be signed in to change notification settings - Fork 1.1k
C++ support AWS_METADATA_SERVICE_TIMEOUT #3493
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
#pragma once | ||
|
||
#include <aws/core/config/AWSProfileConfigLoaderBase.h> | ||
#include <aws/core/client/ClientConfiguration.h> | ||
|
||
#include <aws/core/utils/memory/stl/AWSString.h> | ||
#include <aws/core/utils/memory/stl/AWSMap.h> | ||
|
@@ -19,6 +20,8 @@ namespace Aws | |
class EC2MetadataClient; | ||
} | ||
|
||
|
||
|
||
namespace Config | ||
{ | ||
static const char* const INSTANCE_PROFILE_KEY = "InstanceProfile"; | ||
|
@@ -33,6 +36,16 @@ namespace Aws | |
* If client is nullptr, the default EC2MetadataClient will be created. | ||
*/ | ||
EC2InstanceProfileConfigLoader(const std::shared_ptr<Aws::Internal::EC2MetadataClient>& = nullptr); | ||
|
||
/** | ||
* Creates EC2MetadataClient using the provided ClientConfiguration. | ||
*/ | ||
EC2InstanceProfileConfigLoader(const Aws::Client::ClientConfiguration& clientConfig); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why are we adding a additional for |
||
|
||
/** | ||
* Creates EC2MetadataClient using the provided CredentialProviderConfiguration. | ||
*/ | ||
EC2InstanceProfileConfigLoader(const Aws::Client::ClientConfiguration::CredentialProviderConfiguration& credentialConfig); | ||
|
||
virtual ~EC2InstanceProfileConfigLoader() = default; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,10 @@ static const char* DISABLE_IMDSV1_CONFIG_VAR = "AWS_EC2_METADATA_V1_DISABLED"; | |
static const char* DISABLE_IMDSV1_ENV_VAR = "ec2_metadata_v1_disabled"; | ||
static const char* AWS_ACCOUNT_ID_ENDPOINT_MODE_ENVIRONMENT_VARIABLE = "AWS_ACCOUNT_ID_ENDPOINT_MODE"; | ||
static const char* AWS_ACCOUNT_ID_ENDPOINT_MODE_CONFIG_FILE_OPTION = "account_id_endpoint_mode"; | ||
static const char* AWS_METADATA_SERVICE_TIMEOUT_ENV_VAR = "AWS_METADATA_SERVICE_TIMEOUT"; | ||
static const char* AWS_METADATA_SERVICE_TIMEOUT_CONFIG_VAR = "metadata_service_timeout"; | ||
static const char* AWS_METADATA_SERVICE_NUM_ATTEMPTS_ENV_VAR = "AWS_METADATA_SERVICE_NUM_ATTEMPTS"; | ||
static const char* AWS_METADATA_SERVICE_NUM_ATTEMPTS_CONFIG_VAR = "metadata_service_num_attempts"; | ||
|
||
using RequestChecksumConfigurationEnumMapping = std::pair<const char*, RequestChecksumCalculation>; | ||
static const std::array<RequestChecksumConfigurationEnumMapping, 2> REQUEST_CHECKSUM_CONFIG_MAPPING = {{ | ||
|
@@ -288,6 +292,31 @@ void setConfigFromEnvOrProfile(ClientConfiguration &config) | |
AWS_ACCOUNT_ID_ENDPOINT_MODE_CONFIG_FILE_OPTION, | ||
{"required", "disabled", "preferred"}, /* allowed values */ | ||
"preferred" /* default value */); | ||
|
||
// Load IMDS configuration from environment variables and config file | ||
Aws::String timeoutStr = ClientConfiguration::LoadConfigFromEnvOrProfile(AWS_METADATA_SERVICE_TIMEOUT_ENV_VAR, | ||
config.profileName, | ||
AWS_METADATA_SERVICE_TIMEOUT_CONFIG_VAR, | ||
{}, /* allowed values */ | ||
"1" /* default value */); | ||
|
||
// Load IMDS configuration from environment variables and config file | ||
Aws::String numAttemptsStr = ClientConfiguration::LoadConfigFromEnvOrProfile(AWS_METADATA_SERVICE_NUM_ATTEMPTS_ENV_VAR, | ||
config.profileName, | ||
AWS_METADATA_SERVICE_NUM_ATTEMPTS_CONFIG_VAR, | ||
{}, /* allowed values */ | ||
"1" /* default value */); | ||
|
||
// Parse and set IMDS num attempts | ||
long attempts = std::stol(numAttemptsStr.c_str()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dont use |
||
if (attempts >= 1) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dont think we need to bounds check this, should be able to just assign |
||
config.credentialProviderConfig.imdsConfig.metadataServiceNumAttempts = attempts; | ||
} | ||
// Parse and set IMDS timeout | ||
long timeout = std::stol(timeoutStr.c_str()); | ||
if (timeout >= 1) { | ||
config.credentialProviderConfig.imdsConfig.metadataServiceTimeout = timeout; | ||
} | ||
} | ||
|
||
ClientConfiguration::ClientConfiguration() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
#include <aws/core/config/AWSProfileConfigLoader.h> | ||
#include <aws/core/internal/AWSHttpResourceClient.h> | ||
#include <aws/core/auth/AWSCredentialsProvider.h> | ||
#include <aws/core/client/ClientConfiguration.h> | ||
#include <aws/core/utils/memory/stl/AWSList.h> | ||
#include <aws/core/utils/logging/LogMacros.h> | ||
#include <aws/core/utils/json/JsonSerializer.h> | ||
|
@@ -38,6 +39,14 @@ namespace Aws | |
} | ||
} | ||
|
||
EC2InstanceProfileConfigLoader::EC2InstanceProfileConfigLoader(const Aws::Client::ClientConfiguration& clientConfig) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i dont this we want to add a constructor for |
||
: m_ec2metadataClient(Aws::MakeShared<Aws::Internal::EC2MetadataClient>(EC2_INSTANCE_PROFILE_LOG_TAG, clientConfig)) | ||
{} | ||
|
||
EC2InstanceProfileConfigLoader::EC2InstanceProfileConfigLoader(const Aws::Client::ClientConfiguration::CredentialProviderConfiguration& credentialConfig) | ||
: m_ec2metadataClient(Aws::MakeShared<Aws::Internal::EC2MetadataClient>(EC2_INSTANCE_PROFILE_LOG_TAG, credentialConfig)) | ||
{} | ||
|
||
bool EC2InstanceProfileConfigLoader::LoadInternal() | ||
{ | ||
// re-use old credentials until we need to call IMDS again. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -207,6 +207,30 @@ namespace Aws | |
AWS_LOGSTREAM_TRACE(m_logtag.c_str(), "IMDSv1 had been disabled at the SDK build time"); | ||
#endif | ||
} | ||
|
||
EC2MetadataClient::EC2MetadataClient(const Aws::Client::ClientConfiguration::CredentialProviderConfiguration& credentialConfig, | ||
const char *endpoint) : | ||
AWSHttpResourceClient([&credentialConfig]() { | ||
Aws::Client::ClientConfiguration clientConfig; | ||
clientConfig.credentialProviderConfig = credentialConfig; | ||
clientConfig.connectTimeoutMs = credentialConfig.imdsConfig.metadataServiceTimeout * 1000; | ||
clientConfig.requestTimeoutMs = credentialConfig.imdsConfig.metadataServiceTimeout * 1000; | ||
clientConfig.retryStrategy = Aws::MakeShared<DefaultRetryStrategy>(RESOURCE_CLIENT_CONFIGURATION_ALLOCATION_TAG, credentialConfig.imdsConfig.metadataServiceNumAttempts - 1, 1000); | ||
clientConfig.maxConnections = 2; | ||
clientConfig.scheme = Scheme::HTTP; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why HTTP, thats not secure why are we setting this at all? |
||
return clientConfig; | ||
}(), EC2_METADATA_CLIENT_LOG_TAG), | ||
m_endpoint(endpoint), | ||
m_disableIMDS(false), | ||
m_tokenRequired(true), | ||
m_disableIMDSV1(false) | ||
{ | ||
#if defined(DISABLE_IMDSV1) | ||
AWS_UNREFERENCED_PARAM(m_disableIMDSV1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do we have a |
||
m_disableIMDSV1 = true; | ||
AWS_LOGSTREAM_TRACE(m_logtag.c_str(), "IMDSv1 had been disabled at the SDK build time"); | ||
#endif | ||
} | ||
|
||
EC2MetadataClient::~EC2MetadataClient() | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: whitespace change without content changed