-
Notifications
You must be signed in to change notification settings - Fork 30
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
Add an Option to Disable v2 to v1 Fallback #218
Changes from 3 commits
12e4403
1d70e02
60ab2eb
71bec24
47bf246
87e9979
e344b32
74d312a
a1d996b
030456b
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 | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -67,6 +67,7 @@ struct aws_imds_client { | |||||||||||||||||||
struct aws_linked_list pending_queries; | ||||||||||||||||||||
struct aws_mutex token_lock; | ||||||||||||||||||||
struct aws_condition_variable token_signal; | ||||||||||||||||||||
bool ec2_metadata_v1_disabled; | ||||||||||||||||||||
|
||||||||||||||||||||
struct aws_atomic_var ref_count; | ||||||||||||||||||||
}; | ||||||||||||||||||||
|
@@ -146,6 +147,7 @@ struct aws_imds_client *aws_imds_client_new( | |||||||||||||||||||
client->function_table = | ||||||||||||||||||||
options->function_table ? options->function_table : g_aws_credentials_provider_http_function_table; | ||||||||||||||||||||
client->token_required = options->imds_version == IMDS_PROTOCOL_V1 ? false : true; | ||||||||||||||||||||
client->ec2_metadata_v1_disabled = options->ec2_metadata_v1_disabled; | ||||||||||||||||||||
client->shutdown_options = options->shutdown_options; | ||||||||||||||||||||
|
||||||||||||||||||||
struct aws_socket_options socket_options; | ||||||||||||||||||||
|
@@ -220,6 +222,7 @@ struct imds_user_data { | |||||||||||||||||||
/* Indicate the request is a fallback from a failure call. */ | ||||||||||||||||||||
bool is_fallback_request; | ||||||||||||||||||||
bool is_imds_token_request; | ||||||||||||||||||||
bool ec2_metadata_v1_disabled; | ||||||||||||||||||||
int status_code; | ||||||||||||||||||||
int error_code; | ||||||||||||||||||||
|
||||||||||||||||||||
|
@@ -281,6 +284,7 @@ static struct imds_user_data *s_user_data_new( | |||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
wrapped_user_data->imds_token_required = client->token_required; | ||||||||||||||||||||
wrapped_user_data->ec2_metadata_v1_disabled = client->ec2_metadata_v1_disabled; | ||||||||||||||||||||
aws_atomic_store_int(&wrapped_user_data->ref_count, 1); | ||||||||||||||||||||
return wrapped_user_data; | ||||||||||||||||||||
|
||||||||||||||||||||
|
@@ -509,7 +513,8 @@ static void s_client_on_token_response(struct imds_user_data *user_data) { | |||||||||||||||||||
* we should fall back to insecure request. Otherwise, we should use | ||||||||||||||||||||
* token in following requests. | ||||||||||||||||||||
*/ | ||||||||||||||||||||
waahm7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||
if (user_data->status_code != AWS_HTTP_STATUS_CODE_200_OK || user_data->current_result.len == 0) { | ||||||||||||||||||||
if (!user_data->ec2_metadata_v1_disabled && | ||||||||||||||||||||
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 would prefer to be more clear about this:
Suggested change
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. Thanks, I have refactored the code to the following.
|
||||||||||||||||||||
(user_data->status_code != AWS_HTTP_STATUS_CODE_200_OK || user_data->current_result.len == 0)) { | ||||||||||||||||||||
AWS_LOGF_DEBUG( | ||||||||||||||||||||
AWS_LS_IMDS_CLIENT, | ||||||||||||||||||||
"(id=%p) IMDS client failed to fetch token for requester %p, fall back to v1 for the same " | ||||||||||||||||||||
|
@@ -533,7 +538,10 @@ static void s_client_on_token_response(struct imds_user_data *user_data) { | |||||||||||||||||||
uint64_t expire_timestamp = aws_add_u64_saturating( | ||||||||||||||||||||
current, aws_timestamp_convert(s_imds_token_ttl_secs, AWS_TIMESTAMP_SECS, AWS_TIMESTAMP_NANOS, NULL)); | ||||||||||||||||||||
s_update_token_safely( | ||||||||||||||||||||
user_data->client, cursor.len == 0 ? NULL : &user_data->imds_token, cursor.len != 0, expire_timestamp); | ||||||||||||||||||||
user_data->client, | ||||||||||||||||||||
cursor.len == 0 ? NULL : &user_data->imds_token, | ||||||||||||||||||||
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. we checked that 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 have added an assert, as it should not be empty at this point. |
||||||||||||||||||||
cursor.len != 0 || user_data->ec2_metadata_v1_disabled, | ||||||||||||||||||||
expire_timestamp); | ||||||||||||||||||||
} | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
|
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.
ec2_metadata_v1_disabled
, but you can still set theimds_version
to V1 manually.And, it's already part of IMDS options, I think we can skip the
ec2_metadata
partMaybe
v1_fallback_disabled
?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.
ec2_metadata_v1_disabled
will be used cross SDKs along with the relevant env variable.