-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Add AWS http request signer #5580
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
Changes from 1 commit
929fc45
e941344
22ba065
78d49c8
c8b887c
e3ed20c
0fd58cd
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 |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| licenses(["notice"]) # Apache 2 | ||
|
|
||
| load( | ||
| "//bazel:envoy_build_system.bzl", | ||
| "envoy_cc_library", | ||
| "envoy_package", | ||
| ) | ||
|
|
||
| envoy_package() | ||
|
|
||
| envoy_cc_library( | ||
| name = "signer_lib", | ||
|
Member
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. Nit: if this is going to only ever be a pure interface,
Contributor
Author
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. Good to know. I thought that convention was only used the public headers. e.g. |
||
| hdrs = ["signer.h"], | ||
| deps = [ | ||
| "//include/envoy/http:message_interface", | ||
| ], | ||
| ) | ||
|
|
||
| envoy_cc_library( | ||
| name = "signer_impl_lib", | ||
| srcs = ["signer_impl.cc"], | ||
| hdrs = ["signer_impl.h"], | ||
| external_deps = ["ssl"], | ||
| deps = [ | ||
| ":credentials_provider_lib", | ||
| ":region_provider_lib", | ||
| ":signer_lib", | ||
| "//source/common/buffer:buffer_lib", | ||
| "//source/common/common:assert_lib", | ||
| "//source/common/common:hex_lib", | ||
| "//source/common/common:logger_lib", | ||
| "//source/common/common:stack_array", | ||
| "//source/common/common:utility_lib", | ||
| "//source/common/http:headers_lib", | ||
| ], | ||
| ) | ||
|
|
||
| envoy_cc_library( | ||
| name = "credentials_provider_lib", | ||
| hdrs = ["credentials_provider.h"], | ||
| external_deps = ["abseil_optional"], | ||
| ) | ||
|
|
||
| envoy_cc_library( | ||
| name = "region_provider_lib", | ||
| hdrs = ["region_provider.h"], | ||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| #pragma once | ||
|
|
||
| #include <string> | ||
|
|
||
| #include "envoy/common/pure.h" | ||
|
|
||
| #include "absl/types/optional.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Extensions { | ||
| namespace HttpFilters { | ||
| namespace Common { | ||
| namespace Aws { | ||
|
|
||
| class Credentials { | ||
| public: | ||
| Credentials() = default; | ||
|
|
||
| ~Credentials() = default; | ||
|
Member
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. Nit: probably don't need this if we're not doing polymorphic inheritance.
Contributor
Author
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. Removed the destructor, but I do use the no-args constructor. |
||
|
|
||
| Credentials(const std::string& access_key_id, const std::string& secret_access_key) | ||
|
Member
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. Nit: we tend to use
Member
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. clang-tidy will suggest pass by value here and std::move below for constructors like this. By doing this you may save one copy if caller does move too. |
||
| : access_key_id_(access_key_id), secret_access_key_(secret_access_key) {} | ||
|
|
||
| Credentials(const std::string& access_key_id, const std::string& secret_access_key, | ||
| const std::string& session_token) | ||
| : access_key_id_(access_key_id), secret_access_key_(secret_access_key), | ||
| session_token_(session_token) {} | ||
|
|
||
| void setAccessKeyId(const std::string& access_key_id) { | ||
| access_key_id_ = absl::optional<std::string>(access_key_id); | ||
| } | ||
|
|
||
| const absl::optional<std::string>& accessKeyId() const { return access_key_id_; } | ||
|
|
||
| void setSecretAccessKey(const std::string& secret_key) { | ||
| secret_access_key_ = absl::optional<std::string>(secret_key); | ||
| } | ||
|
|
||
| const absl::optional<std::string>& secretAccessKey() const { return secret_access_key_; } | ||
|
|
||
| void setSessionToken(const std::string& session_token) { | ||
|
Member
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. Do we need both setters and constructors for these fields? Could this be an immutable object?
Contributor
Author
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 don't need them. I can remove them. |
||
| session_token_ = absl::optional<std::string>(session_token); | ||
| } | ||
|
|
||
| const absl::optional<std::string>& sessionToken() const { return session_token_; } | ||
|
|
||
| private: | ||
| absl::optional<std::string> access_key_id_; | ||
| absl::optional<std::string> secret_access_key_; | ||
| absl::optional<std::string> session_token_; | ||
| }; | ||
|
|
||
| class CredentialsProvider { | ||
| public: | ||
| virtual ~CredentialsProvider() = default; | ||
|
|
||
| virtual Credentials getCredentials() PURE; | ||
| }; | ||
|
|
||
| typedef std::shared_ptr<CredentialsProvider> CredentialsProviderSharedPtr; | ||
|
|
||
| } // namespace Aws | ||
| } // namespace Common | ||
| } // namespace HttpFilters | ||
| } // namespace Extensions | ||
| } // namespace Envoy | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| #pragma once | ||
|
|
||
| #include "envoy/common/pure.h" | ||
|
|
||
| #include "absl/types/optional.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Extensions { | ||
| namespace HttpFilters { | ||
| namespace Common { | ||
| namespace Aws { | ||
|
|
||
| class RegionProvider { | ||
|
Member
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 had a look at how this works in #5546. This allows both static and environment to specify region. I guess my main question is "do we really need this?". Specifically, Envoy's
Contributor
Author
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. My intention was to eventually add a region provider impl that pulls the region from an AWS-endpoint, much like we pull the credentials.
Member
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 guess the larger point is "shouldn't we be synthesizing the Node locality in the bootstrap or CLI for Envoys based on the AWS endpoint data source?" If you do that, there is no need to manage data sources for this information in the extension. Credentials can also be placed in Node metadata, but the limitation there is that if they change dynamically during the lifetime of the Envoy, they can become stale. For region, this should be static for the lifetime of an Envoy.
Contributor
Author
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. Sorry for not addressing that larger point. I think it makes sense. I'll pipe the node metadata through in the later PR. I'll eliminate this class, especially since it will probably just provide static data for the foreseeable future. |
||
| public: | ||
| virtual ~RegionProvider() = default; | ||
|
|
||
| virtual absl::optional<std::string> getRegion() PURE; | ||
| }; | ||
|
|
||
| typedef std::shared_ptr<RegionProvider> RegionProviderSharedPtr; | ||
|
|
||
| } // namespace Aws | ||
| } // namespace Common | ||
| } // namespace HttpFilters | ||
| } // namespace Extensions | ||
| } // namespace Envoy | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| #pragma once | ||
|
|
||
| #include "envoy/common/pure.h" | ||
| #include "envoy/http/message.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Extensions { | ||
| namespace HttpFilters { | ||
| namespace Common { | ||
| namespace Aws { | ||
|
|
||
| class Signer { | ||
| public: | ||
| virtual ~Signer() = default; | ||
|
|
||
| /** | ||
| * Sign an AWS request. | ||
| * @param message an | ||
| */ | ||
| virtual void sign(Http::Message& message) const PURE; | ||
| }; | ||
|
|
||
| typedef std::shared_ptr<Signer> SignerSharedPtr; | ||
|
|
||
| } // namespace Aws | ||
| } // namespace Common | ||
| } // namespace HttpFilters | ||
| } // namespace Extensions | ||
| } // namespace Envoy |
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.
Is there any reason not to use
http?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.
Given where the code is now, it could just be classified as http. I'm fine doing that. :)