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

Implement SSO Credentials Provider Part 2 #191

Merged
merged 40 commits into from
May 1, 2023

Conversation

waahm7
Copy link
Contributor

@waahm7 waahm7 commented Mar 20, 2023

Description of changes:

  • Follow up PR to timplement SSOCredentialsProvider.

Todos:

  • Add SSOCredentialsProvider to default chain.
  • Support cached config profiles
  • Remove mocked http connection manager implementation from StsWebIdentity as they are similar.
  • Support token refresh

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

@waahm7 waahm7 changed the base branch from main to token-provider-profile March 20, 2023 18:59
@waahm7 waahm7 changed the title WIP | implement SSO Credentials Provider 2 WIP | implement SSO Credentials Provider Part 2 Mar 20, 2023
@codecov-commenter
Copy link

codecov-commenter commented Mar 20, 2023

Codecov Report

❗ No coverage uploaded for pull request base (token-provider-profile@b6d0a2f). Click here to learn what that means.
Patch coverage: 79.45% of modified lines in pull request are covered.

❗ Current head 709bd3c differs from pull request most recent head 81d41a7. Consider uploading reports for the commit 81d41a7 to get more accurate results

Additional details and impacted files
@@                    Coverage Diff                    @@
##             token-provider-profile     #191   +/-   ##
=========================================================
  Coverage                          ?   79.50%           
=========================================================
  Files                             ?       33           
  Lines                             ?     5527           
  Branches                          ?        0           
=========================================================
  Hits                              ?     4394           
  Misses                            ?     1133           
  Partials                          ?        0           
Impacted Files Coverage Δ
source/credentials_provider_sso.c 78.87% <78.87%> (ø)
source/credentials_utils.c 83.76% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@waahm7 waahm7 marked this pull request as ready for review April 5, 2023 23:19
@waahm7 waahm7 changed the title WIP | implement SSO Credentials Provider Part 2 Implement SSO Credentials Provider Part 2 Apr 5, 2023
Copy link
Contributor

@TingDaoK TingDaoK left a comment

Choose a reason for hiding this comment

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

Overall looks good! Good job

@@ -73,13 +73,15 @@ struct aws_auth_http_system_vtable {
enum aws_parse_credentials_expiration_format {
AWS_PCEF_STRING_ISO_8601_DATE,
AWS_PCEF_NUMBER_UNIX_EPOCH,
AWS_PCEF_NUMBER_UNIX_EPOCH_MS,
Copy link
Contributor

Choose a reason for hiding this comment

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

So, what's AWS_PCEF_NUMBER_UNIX_EPOCH stands for, ns?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it stands for epoch seconds.

Copy link
Contributor

Choose a reason for hiding this comment

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

So, can we change AWS_PCEF_NUMBER_UNIX_EPOCH to AWS_PCEF_NUMBER_UNIX_EPOCH_SEC to be more clear?

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like unix epoch just stands for sec from googling. So, it's fine.

source/credentials_provider_sso.c Outdated Show resolved Hide resolved
source/credentials_provider_sso.c Outdated Show resolved Hide resolved
struct aws_byte_buf *endpoint,
const struct aws_string *region) {
if (!allocator || !endpoint || !region) {
return AWS_ERROR_INVALID_ARGUMENT;
Copy link
Contributor

Choose a reason for hiding this comment

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

return aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);

As it's an internal helper function, I'll only handle error from region not set and crash on others are missing:

AWS_PRECONDITION(allocator);
AWS_PRECONDITION(endpoint);

source/credentials_provider_sso.c Show resolved Hide resolved
}

struct sso_user_data *sso_user_data = user_data;
if (sso_user_data->status_code == AWS_OP_SUCCESS) {
Copy link
Contributor

Choose a reason for hiding this comment

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

trivial: we use AWS_OP_SUCCESS as return code, and AWS_ERROR_SUCCESS as error code.

And why you are check the status_code to be 0? To make sure it was not set before?
Oh, I see, the on_response_headers will be invoked more than once, but the on_response_header_block_done will be invoked only once, should we use that instead?

Copy link
Contributor

Choose a reason for hiding this comment

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

Or, you can just get the status code from complete callback.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, moved it to complete callback.

/* Request headers. */
AWS_STATIC_STRING_FROM_LITERAL(s_sso_token_header, "x-amz-sso_bearer_token");
AWS_STATIC_STRING_FROM_LITERAL(s_sso_user_agent_header, "User-Agent");
AWS_STATIC_STRING_FROM_LITERAL(s_sso_user_agent_header_value, "CRTAuthSSOCredentialsProvider");
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have an agreement on the user_agent value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, do we have to talk to someone?

Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure, there is a SDK metrics team, which may need this info?

}
if (user_data->connection) {
struct aws_credentials_provider_sso_impl *provider_impl = user_data->provider->impl;
provider_impl->function_table->aws_http_connection_manager_release_connection(
Copy link
Contributor

Choose a reason for hiding this comment

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

this function can fail, maybe just assert on the return code.

/*
* If we can retry the request based on error response, retry it, otherwise, call the finalize function.
*/
if (user_data->error_code) {
Copy link
Contributor

Choose a reason for hiding this comment

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

should we also try to retry based on the status code?

Suggested change
if (user_data->error_code) {
if (user_data->error_code || user_data->status_code!=AWS_HTTP_STATUS_CODE_200_OK) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We are already doing that as user_data->error_code will be set if http status code was not 200. I have changed it to your suggestion as it is more clear. thanks.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, I missed the part you set the error code based on status code. It's fine, it just couple line above, we can keep what you did before.

}
static void s_on_retry_ready(struct aws_retry_token *token, int error_code, void *wrapped_user_data);

static void s_on_stream_complete_fn(struct aws_http_stream *stream, int error_code, void *data) {
Copy link
Contributor

Choose a reason for hiding this comment

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

super trivial: I would prefer to have the callbacks listed as the order it get invoked, header->body->complete

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Most of the functions are listed in a bottom-to-top order fashion, which makes it easier to navigate the whole file from bottom to top. For example, the functions are listed as follows: acquireConnection -> tokenCallback -> send query -> incoming body -> stream complete -> finalize query.

source/credentials_provider_sso.c Outdated Show resolved Hide resolved
source/credentials_provider_sso.c Show resolved Hide resolved
AWS_LS_AUTH_CREDENTIALS_PROVIDER,
"(id=%p): failed to register operation success: %s",
(void *)sso_query_context->provider,
aws_error_str(aws_last_error()));
Copy link
Contributor

Choose a reason for hiding this comment

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

Well, if this function fails, we basically just log the error and everything else will keep moving as succeed.

I don't think this function can ever fail from the current impl, should we just change to assert on the return value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, updated.

source/credentials_provider_sso.c Outdated Show resolved Hide resolved
@@ -73,13 +73,15 @@ struct aws_auth_http_system_vtable {
enum aws_parse_credentials_expiration_format {
AWS_PCEF_STRING_ISO_8601_DATE,
AWS_PCEF_NUMBER_UNIX_EPOCH,
AWS_PCEF_NUMBER_UNIX_EPOCH_MS,
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like unix epoch just stands for sec from googling. So, it's fine.

@waahm7 waahm7 merged commit b761bdc into token-provider-profile May 1, 2023
@waahm7 waahm7 deleted the sso-credentials-provider branch May 1, 2023 16:12
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.

3 participants