Skip to content
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

Refactor ECSCredentialsProvider Part 2 #235

Merged
merged 9 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion source/credentials_provider_cognito.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <inttypes.h>

#define COGNITO_CONNECT_TIMEOUT_DEFAULT_IN_SECONDS 5
#define COGNITO_MAX_RETRIES 8
#define COGNITO_MAX_RETRIES 3
#define HTTP_REQUEST_BODY_INITIAL_SIZE 1024
#define HTTP_RESPONSE_BODY_INITIAL_SIZE 4096

Expand Down
10 changes: 9 additions & 1 deletion source/credentials_provider_ecs.c
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,10 @@ static int s_make_ecs_http_query(
.user_data = ecs_user_data,
.request = request,
};

/* for test with mocking http stack where make request finishes
immediately and releases client before stream activate call */
struct aws_credentials_provider *provider = ecs_user_data->ecs_provider;
aws_credentials_provider_acquire(provider);
stream = impl->function_table->aws_http_connection_make_request(ecs_user_data->connection, &request_options);

if (!stream) {
Expand All @@ -410,6 +413,7 @@ static int s_make_ecs_http_query(
if (impl->function_table->aws_http_stream_activate(stream)) {
goto on_error;
}
aws_credentials_provider_release(provider);

return AWS_OP_SUCCESS;

Expand Down Expand Up @@ -705,6 +709,10 @@ struct aws_credentials_provider *aws_credentials_provider_new_ecs_from_environme

} else {
/* Neither environment variable is set */
AWS_LOGF_INFO(
AWS_LS_AUTH_CREDENTIALS_PROVIDER,
"ECS provider: Unable to initialize from environment because AWS_CONTAINER_CREDENTIALS_FULL_URI and "
"AWS_CONTAINER_CREDENTIALS_RELATIVE_URI are not set.");
aws_raise_error(AWS_AUTH_CREDENTIALS_PROVIDER_INVALID_ENVIRONMENT);
goto cleanup;
}
Expand Down
17 changes: 17 additions & 0 deletions source/credentials_provider_profile.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ static struct aws_byte_cursor s_default_session_name_pfx =
AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("aws-common-runtime-profile-config");
static struct aws_byte_cursor s_ec2_imds_name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("Ec2InstanceMetadata");
static struct aws_byte_cursor s_environment_name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("Environment");
static struct aws_byte_cursor s_ecs_credentials_provider_name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("EcsContainer");

#define MAX_SESSION_NAME_LEN ((size_t)64)

Expand Down Expand Up @@ -372,6 +373,22 @@ static struct aws_credentials_provider *s_create_sts_based_provider(
provider = aws_credentials_provider_new_sts(allocator, &sts_options);

aws_credentials_provider_release(env_provider);
} else if (aws_string_eq_byte_cursor_ignore_case(
aws_profile_property_get_value(credential_source_property), &s_ecs_credentials_provider_name)) {
struct aws_credentials_provider_ecs_environment_options ecs_options = {
.bootstrap = options->bootstrap,
.function_table = options->function_table,
.tls_ctx = tls_ctx,
};
struct aws_credentials_provider *ecs_provider =
aws_credentials_provider_new_ecs_from_environment(allocator, &ecs_options);
if (!ecs_provider) {
goto done;
}
sts_options.creds_provider = ecs_provider;
provider = aws_credentials_provider_new_sts(allocator, &sts_options);

aws_credentials_provider_release(ecs_provider);
} else {
AWS_LOGF_ERROR(
AWS_LS_AUTH_CREDENTIALS_PROVIDER,
Expand Down
2 changes: 1 addition & 1 deletion source/credentials_provider_sts.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ static struct aws_byte_cursor s_content_length = AWS_BYTE_CUR_INIT_FROM_STRING_L
static struct aws_byte_cursor s_path = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("/");
static struct aws_byte_cursor s_signing_region = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("us-east-1");
static struct aws_byte_cursor s_service_name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("sts");
static const int s_max_retries = 8;
static const int s_max_retries = 3;

const uint16_t aws_sts_assume_role_default_duration_secs = 900;

Expand Down
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ add_net_test_case(credentials_provider_sts_direct_config_connection_failed)
add_net_test_case(credentials_provider_sts_direct_config_service_fails)
add_net_test_case(credentials_provider_sts_from_profile_config_succeeds)
add_net_test_case(credentials_provider_sts_from_profile_config_with_chain)
add_net_test_case(credentials_provider_sts_from_profile_config_with_ecs_credentials_source)
add_net_test_case(credentials_provider_sts_from_profile_config_with_chain_and_profile_creds)
add_net_test_case(credentials_provider_sts_from_profile_config_with_chain_and_partial_profile_creds)
add_net_test_case(credentials_provider_sts_from_self_referencing_profile)
Expand Down
Loading
Loading