Skip to content

Added a set of AWS credential providers.#7281

Merged
mattklein123 merged 3 commits intoenvoyproxy:masterfrom
ivitjuk:aws_sigv4_credential_providers
Jul 1, 2019
Merged

Added a set of AWS credential providers.#7281
mattklein123 merged 3 commits intoenvoyproxy:masterfrom
ivitjuk:aws_sigv4_credential_providers

Conversation

@ivitjuk
Copy link
Member

@ivitjuk ivitjuk commented Jun 14, 2019

Description:

Added a set of AWS credential providers.

  • EnvironmentCredentialsProvider fetches credentials from the environment
  • InstanceProfileCredentialsProvider fetches credentials from the instance metadata
  • TaskRoleCredentialsProvider fetches credentials from the ECS task metadata

Also added DefaultCredentialsProviderChain which is able to pick the
correct credential provider according to the execution environment it is
running in.

Signed-off-by: Ivan Vitjuk ivanvit@amazon.com

Risk Level: Low
Testing: Unit tests added
Docs Changes: Interface classes documented.
Release Notes: N/A
Fixes (partial): #5215

- EnvironmentCredentialsProvider fetches credentials from the environment
- InstanceProfileCredentialsProvider fetches credentials from the instance metadata
- TaskRoleCredentialsProvider fetches credentials from the ECS task metadata

Also added DefaultCredentialsProviderChain which is able to pick the
correct credential provider according to the execution environment it is
running in.

Signed-off-by: Ivan Vitjuk <ivanvit@amazon.com>
@ivitjuk ivitjuk marked this pull request as ready for review June 14, 2019 21:25
@ivitjuk
Copy link
Member Author

ivitjuk commented Jun 20, 2019

Hi, this was opened almost a week ago, can we get the feedback?

Copy link
Member

@dio dio left a comment

Choose a reason for hiding this comment

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

@ivitjuk thanks for your patience, was out last week. Looks good, but I see some potential improvements here:

- Replaced fromCString() and fromString() with a single Credential
  constructor accepting absl::string_view
- Use constexpr for string constants
- Pass std::string to credential constructors instead of absl::optional

Signed-off-by: Ivan Vitjuk <ivanvit@amazon.com>
@ivitjuk
Copy link
Member Author

ivitjuk commented Jun 24, 2019

/retest

@repokitteh-read-only
Copy link

🔨 rebuilding ci/circleci: tsan (failed build)

🐱

Caused by: a #7281 (comment) was created by @ivitjuk.

see: more, trace.

@ivitjuk
Copy link
Member Author

ivitjuk commented Jun 25, 2019

As far as I can see failing test is extensions/filters/http/lua/lua_filter_test which is unrelated to this change. Can we proceed with this review?

@ivitjuk
Copy link
Member Author

ivitjuk commented Jun 25, 2019

/retest

@repokitteh-read-only
Copy link

🔨 rebuilding ci/circleci: tsan (failed build)

🐱

Caused by: a #7281 (comment) was created by @ivitjuk.

see: more, trace.

@dio
Copy link
Member

dio commented Jun 25, 2019

@ivitjuk thanks. Let me check...

@ivitjuk
Copy link
Member Author

ivitjuk commented Jun 27, 2019

/wait-any

Copy link
Member

@dio dio left a comment

Choose a reason for hiding this comment

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

Looks good. We need some clarifications and one coverage test. Thank you!

Credentials(absl::string_view access_key_id = absl::string_view(),
absl::string_view secret_access_key = absl::string_view(),
absl::string_view session_token = absl::string_view()) {
if (!access_key_id.empty()) {
Copy link
Member

Choose a reason for hiding this comment

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

Does this mean we always need access_key_id? and we require either secret_access_key or session_token to be there? This if statements seem not necessary. What is the implication if we don't have (or empty) access_key_id?

Copy link
Member Author

Choose a reason for hiding this comment

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

Credentials can be one of:

  • Empty
  • Have access key only
  • Have access key and secret key
  • Have access key, secret key and session token

Implication of an empty access key is that request will be made with anonymous identity. For example requests can be made to S3 with anonymous identity if bucket is configured in that way. Non-production environments can also accept anonymous requests.

* If a credential component was not found in the execution environment, it's getter method will
* return absl::nullopt. Credential components with the empty string value are treated as not found.
*/
class Credentials {
Copy link
Member

Choose a reason for hiding this comment

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

I felt like this should be a struct but not feeling strongly about it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Interface of this type is not public by default. Data members specifically are not public and can not be changed once set by the constructor. In that sense it feels more like a type (class) than a collection of data (struct).

absl::string_view session_token)
: access_key_id_(access_key_id), secret_access_key_(secret_access_key),
session_token_(session_token) {}
Credentials(absl::string_view access_key_id = absl::string_view(),
Copy link
Member

Choose a reason for hiding this comment

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

Defaulting to absl::string_view() seems unnecessary? For convenience you always have the default constructor Credentials()?

Copy link
Member Author

Choose a reason for hiding this comment

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

As I already have this constructor, I wouldn't get the default one unless I request it with Credentials() = default. To me it looks simpler to have a single constructor, because relying on the default one would not lead to code reduction.

cached_credentials_ = Credentials(access_key_id, secret_access_key, session_token);
}

Credentials CredentialsProviderChain::getCredentials() {
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks to catching that. Added tests.

Signed-off-by: Ivan Vitjuk <ivanvit@amazon.com>
@ivitjuk
Copy link
Member Author

ivitjuk commented Jun 29, 2019

/wait-any

Copy link
Member

@dio dio left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks @ivitjuk for sticking with this!

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