Skip to content

aws_request_signing: extend api to allow header exclusion#1

Merged
rexnp merged 5 commits intomainfrom
signing
Nov 12, 2021
Merged

aws_request_signing: extend api to allow header exclusion#1
rexnp merged 5 commits intomainfrom
signing

Conversation

@rexnp
Copy link
Copy Markdown
Owner

@rexnp rexnp commented Nov 9, 2021

Commit Message: extends aws request signing filter with header exclusion list.
Additional Description:
Risk Level: Low
Testing: unit tests
Docs Changes: Pending
Release Notes: Pending
Platform Specific Features: N/A
[Optional Runtime guard:]
[Optional Fixes #Issue]
[Optional Fixes commit #PR or SHA]
[Optional Deprecated:]
[Optional API Considerations:]
Fixes envoyproxy#18695

Signed-off-by: Rex Chang <chiyc@amazon.com>
@rexnp
Copy link
Copy Markdown
Owner Author

rexnp commented Nov 9, 2021

working on doc changes now

// <https://docs.aws.amazon.com/AmazonS3/latest/API/sig-v4-header-based-auth.html>`_ policy for details.
bool use_unsigned_payload = 4;

// A given header that matches any of the configured matchers will not be signed.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Let's rephrase this. I propose:

A list of request headers that will be excluded from signing.

You might expand a bit on the matcher implementation (haven't gotten that far yet) on whether these are prefix matchers etc.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

expanded and added an example.

Copy link
Copy Markdown
Collaborator

@abaptiste abaptiste 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. Had a few comments.

-e SYSTEM_STAGEDISPLAYNAME \
-e SYSTEM_JOBDISPLAYNAME \
-e SYSTEM_PULLREQUEST_PULLREQUESTNUMBER \
-e GOPROXY=direct \
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Let's omit this. It may not be applicable to Envoy, and is a direct artifact of building in our environment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

yeah that slipped in.

"//source/common/buffer:buffer_lib",
"//source/common/common:hex_lib",
"//source/common/common:logger_lib",
"//source/common/common:matchers_lib",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Wouldn't the signer library get the matchers_lib from including :utility_lib? Can you double check this and see if things still build and work without this line.

Copy link
Copy Markdown
Owner Author

@rexnp rexnp Nov 11, 2021

Choose a reason for hiding this comment

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

nice catch! that can be removed indeed.

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 std::vector<envoy::type::matcher::v3::StringMatcher>& matcher_config)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I suggest changing this so that you consume the vector of matcher pointers from the config when the signer is instantiated.

If this doesn't make sense because of lambda, and gRPC, then "this is fine" :)

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

I started with this but it seemed simpler to only handle the conversion between the proto and matcher pointer once in the Signer class, vs repeating them in the request signing, lamda, and grpc iam filters.

// proxies
const auto key = entry.key().getStringView();
if (key == Http::Headers::get().ForwardedFor.get() ||
key == Http::Headers::get().ForwardedProto.get() || key == "x-amzn-trace-id" ||
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is there any way we can add x-amzn-trace-id as a default entry in the excluded headers?
Or even pre-populate the excluded headers with the XFF headers and amazon trace header?

I don't have strong feelings either way. I think it'd make this block a bit cleaner.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

opted to provide a default exclusion list in the signer constructor.

auto signer = std::make_unique<Common::Aws::SignerImpl>(
config.service_name(), getRegion(config), credentials_provider, api.timeSource());
config.service_name(), getRegion(config), credentials_provider, api.timeSource(),
std::vector<envoy::type::matcher::v3::StringMatcher>{});
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I suggest having a type defined for std::vector<envoy::type::matcher::v3::StringMatcher> perhaps:

using AwsSigV4HeaderExclusionVector = std::vector<envoy::type::matcher::v3::StringMatcher>;

That way you have a angle bracket less type (AwsSigV4HeaderExclusionVector) you can use throughout the implementation.

You might also have a hardcoded static entry for an empty vector? This last bit isn't a hard requirement.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

neat! done.

Comment on lines +25 to +26
prefix: [x-envoy]
exact: [foo]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

As I mentioned earlier in the proto file, let's add a bit of details as to how a user can specify a header and what sort of matcher we support.

Signed-off-by: Rex Chang <chiyc@amazon.com>
Signed-off-by: Rex Chang <chiyc@amazon.com>
@rexnp rexnp requested a review from abaptiste November 11, 2021 22:21
Signed-off-by: Rex Chang <chiyc@amazon.com>
Comment on lines +45 to +48
match_excluded_headers:
- prefix: x-envoy
- prefix: x-forwarded
- exact: x-amzn-trace-id
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Perfect :D

Comment on lines +88 to +89
std::vector<Matchers::StringMatcherPtr> default_excluded_headers{};
for (const auto& header : default_excluded_headers_) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

renamed to matcher_ptrs to better reflect the return type

Copy link
Copy Markdown
Collaborator

@abaptiste abaptiste left a comment

Choose a reason for hiding this comment

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

One minor change suggested. Looks good!

Signed-off-by: Rex Chang <chiyc@amazon.com>
@rexnp rexnp requested a review from abaptiste November 12, 2021 20:04
Copy link
Copy Markdown
Collaborator

@abaptiste abaptiste left a comment

Choose a reason for hiding this comment

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

Ship it!

@rexnp rexnp merged this pull request into main Nov 12, 2021
rexnp added a commit that referenced this pull request Nov 15, 2021
Signed-off-by: Rex Chang <chiyc@amazon.com>

* extends aws request signing filter with header exclusion list

Signed-off-by: Rex Chang <chiyc@amazon.com>

aws_request_signing: extend api to allow header exclusion (#1)

* extends aws request signing filter with header exclusion list

Signed-off-by: Rex Chang <chiyc@amazon.com>

Signed-off-by: Rex Chang <58710378+rexnp@users.noreply.github.com>
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.

AWS Request Signing Filter breaks for internal requests if x-envoy-retry-on is set

2 participants