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

Account ID support for Crendentials Providers #262

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

Conversation

waahm7
Copy link
Contributor

@waahm7 waahm7 commented Jan 29, 2025

Issue: awslabs/aws-crt-swift#303

Description of changes:
Update the following providers to provide account_id if present.

  1. EnvironmentCredentialsProvider: Checks AWS_ACCOUNT_ID env variable.
  2. SSOCredentialsProvider: Account id is parsed from the sso_account_id config parameter which was also required for the request.
  3. STS: Account_id is parsed from the Arn in the response.
  4. STSWebIdentity: Account_id is parsed from the Arn in the response.
  5. ProcessCredentialsProvider: Account_id is parsed from AccountId field in the response if present.
  6. ECSProvider: Account_id is parsed from AccountId field in the response if present.
  7. ProfileProvider: Parses aws_account_id in the config file.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 92.94118% with 6 lines in your changes missing coverage. Please review.

Project coverage is 80.64%. Comparing base (b513db4) to head (dfd8bde).

Files with missing lines Patch % Lines
source/credentials_provider_sts.c 86.36% 3 Missing ⚠️
source/credentials_provider_sts_web_identity.c 88.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #262      +/-   ##
==========================================
+ Coverage   80.50%   80.64%   +0.13%     
==========================================
  Files          33       33              
  Lines        6099     6158      +59     
==========================================
+ Hits         4910     4966      +56     
- Misses       1189     1192       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@waahm7 waahm7 changed the title WIP | Account ID support for Crendentials Providers Account ID support for Crendentials Providers Jan 29, 2025
@waahm7 waahm7 marked this pull request as ready for review January 29, 2025 22:52
Comment on lines +814 to +820
struct aws_credentials *aws_credentials_new_from_string_with_account_id(
struct aws_allocator *allocator,
const struct aws_string *access_key_id,
const struct aws_string *secret_access_key,
const struct aws_string *session_token,
const struct aws_string *account_id,
uint64_t expiration_timepoint_seconds);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a time-honored tradition in this codebase, when new arguments keep creeping into constructors...

Suggested change
struct aws_credentials *aws_credentials_new_from_string_with_account_id(
struct aws_allocator *allocator,
const struct aws_string *access_key_id,
const struct aws_string *secret_access_key,
const struct aws_string *session_token,
const struct aws_string *account_id,
uint64_t expiration_timepoint_seconds);
struct aws_credentials *aws_credentials_new_from_options(
struct aws_allocator *allocator,
const struct aws_credentials_options *options);

/* The format of the Arn is arn:partition:service:region:account-id:resource-ID and we need to parse the
* account-id out of it which is the fifth element. */
for (int i = 0; i < 5; i++) {
if (!aws_byte_cursor_next_split(&arn_cursor, ':', &account_id)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: its valid for arn not to have account id field. most fields are optional from what i remember (s3 is an example of arns without a bunch of fields). do we want to have logic that accounts for that? or just setting it to empty string is fine?

struct aws_byte_cursor arn_cursor;
AWS_ZERO_STRUCT(arn_cursor);

if (aws_byte_cursor_eq_c_str_ignore_case(&node_name, "Arn")) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe pull arn parsing into a separate helper that we can test standalone?

if (options->token_name) {
token = aws_json_value_get_from_object(document_root, aws_byte_cursor_from_c_str((char *)options->token_name));
if (!aws_json_value_is_string(token) || aws_json_value_get_string(token, &token_cursor) == AWS_OP_ERR) {
if (!aws_json_value_is_string(token) || aws_json_value_get_string(token, &token_cursor) == AWS_OP_ERR ||
token_cursor.len == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this one getting a length check, but access_key_id and secret_access_key above don't get a length check?

worth breaking these 4 checks out into a helper function?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants