-
Notifications
You must be signed in to change notification settings - Fork 0
aws_request_signing: extend api to allow header exclusion #1
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 4 commits
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 |
|---|---|---|
| @@ -1,7 +1,11 @@ | ||
| #pragma once | ||
|
|
||
| #include <utility> | ||
|
|
||
| #include "source/common/common/logger.h" | ||
| #include "source/common/common/matchers.h" | ||
| #include "source/common/common/utility.h" | ||
| #include "source/common/http/headers.h" | ||
| #include "source/common/singleton/const_singleton.h" | ||
| #include "source/extensions/common/aws/credentials_provider.h" | ||
| #include "source/extensions/common/aws/signer.h" | ||
|
|
@@ -38,17 +42,26 @@ class SignatureConstantValues { | |
|
|
||
| using SignatureConstants = ConstSingleton<SignatureConstantValues>; | ||
|
|
||
| using AwsSigV4HeaderExclusionVector = std::vector<envoy::type::matcher::v3::StringMatcher>; | ||
|
|
||
| /** | ||
| * Implementation of the Signature V4 signing process. | ||
| * See https://docs.aws.amazon.com/general/latest/gr/signature-version-4.html | ||
| */ | ||
| class SignerImpl : public Signer, public Logger::Loggable<Logger::Id::http> { | ||
| public: | ||
| SignerImpl(absl::string_view service_name, absl::string_view region, | ||
| const CredentialsProviderSharedPtr& credentials_provider, TimeSource& time_source) | ||
| const CredentialsProviderSharedPtr& credentials_provider, TimeSource& time_source, | ||
| const AwsSigV4HeaderExclusionVector& matcher_config) | ||
| : service_name_(service_name), region_(region), credentials_provider_(credentials_provider), | ||
| time_source_(time_source), long_date_formatter_(SignatureConstants::get().LongDateFormat), | ||
| short_date_formatter_(SignatureConstants::get().ShortDateFormat) {} | ||
| short_date_formatter_(SignatureConstants::get().ShortDateFormat) { | ||
| for (const auto& matcher : matcher_config) { | ||
| excluded_header_matchers_.emplace_back( | ||
| std::make_unique<Matchers::StringMatcherImpl<envoy::type::matcher::v3::StringMatcher>>( | ||
| matcher)); | ||
| } | ||
| } | ||
|
|
||
| void sign(Http::RequestMessage& message, bool sign_body = false) override; | ||
| void sign(Http::RequestHeaderMap& headers, const std::string& content_hash) override; | ||
|
|
@@ -71,9 +84,24 @@ class SignerImpl : public Signer, public Logger::Loggable<Logger::Id::http> { | |
| const std::map<std::string, std::string>& canonical_headers, | ||
| absl::string_view signature) const; | ||
|
|
||
| std::vector<Matchers::StringMatcherPtr> defaultMatchers() { | ||
| std::vector<Matchers::StringMatcherPtr> default_excluded_headers{}; | ||
| for (const auto& header : default_excluded_headers_) { | ||
|
Collaborator
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. The default_excluded_headers objects are really closely named. Don't really have a suggestion here other than something that disambiguates these a bit more.
Owner
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. renamed to |
||
| envoy::type::matcher::v3::StringMatcher m; | ||
| m.set_exact(header); | ||
| default_excluded_headers.emplace_back( | ||
| std::make_unique<Matchers::StringMatcherImpl<envoy::type::matcher::v3::StringMatcher>>( | ||
| m)); | ||
| } | ||
| return default_excluded_headers; | ||
| } | ||
|
|
||
| const std::string service_name_; | ||
| const std::string region_; | ||
|
|
||
| const std::vector<std::string> default_excluded_headers_ = { | ||
| Http::Headers::get().ForwardedFor.get(), Http::Headers::get().ForwardedProto.get(), | ||
| "x-amzn-trace-id"}; | ||
| std::vector<Matchers::StringMatcherPtr> excluded_header_matchers_ = defaultMatchers(); | ||
| CredentialsProviderSharedPtr credentials_provider_; | ||
| TimeSource& time_source_; | ||
| DateFormatter long_date_formatter_; | ||
|
|
||
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.
Perfect :D