Skip to content

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

Closed
rexnp/envoy
#1

Description

@wbertelsen

Title:
The AWS Request Signing Filter breaks for internal requests if the x-envoy-retry-on header is set

Description:
For requests marked by envoy as "internal", if the x-envoy-retry-on header is set to any value, such as x-envoy-retry-on: 5xx, the aws request signing filter signs the request using x-envoy-retry-on: but the router makes the request with this header missing. This causes signature validation to fail with a The request signature we calculated does not match the signature you provided. Check your key and signing method. error

Repro steps:
To repro, run envoy with the config below and make sure you have your AWS credential env vars set correctly.

export AWS_ACCESS_KEY_ID=<inset>
export AWS_SECRET_ACCESS_KEY=<insert>
export AWS_SESSION_TOKEN=<insert if needed>
envoy --config-path  ./envoy-repro.yaml

Then, demonstrate that request signing works correctly without the x-envoy-retry-on header

curl  localhost:4141/ # this lists buckets successfully as long as you have the right iam permissions

Finally, repro the issue by adding the header

curl  --header "x-envoy-retry-on: 5xx"  localhost:4141/ # This should respond with an error and the correct string to sign

Config:

static_resources:
  listeners:
    - name: example
      address:
        socket_address: { address: 127.0.0.1, port_value: 4141 }
      traffic_direction: OUTBOUND
      filter_chains:
        - filters:
            - name: envoy.http_connection_manager
              typed_config:
                "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
                stat_prefix: example
                codec_type: auto
                route_config:
                  name: sts
                  virtual_hosts:
                    - name: sts
                      domains: ["*"]
                      routes:
                        - match: { prefix: "/" }
                          route: { cluster: example } 
                use_remote_address: true # This marks requests as 'internal' and is required to repro this issue
                http_filters:
                  - name: sigv4-signing
                    typed_config:
                      "@type": type.googleapis.com/envoy.extensions.filters.http.aws_request_signing.v3.AwsRequestSigning
                      service_name: s3
                      host_rewrite: s3.amazonaws.com
                      region: us-east-1
                      use_unsigned_payload: true
                  - name: envoy.filters.http.router
  clusters:
    - name: example
      type: STRICT_DNS
      connect_timeout: 0.250s
# BEGIN TAP CONFIG - this is useful for debugging this issue but not required to repro      
      transport_socket:
        name: envoy.transport_sockets.tap
        typed_config:
          "@type": type.googleapis.com/envoy.extensions.transport_sockets.tap.v3.Tap
          common_config:
            static_config:
              match_config:
                any_match: true
              output_config:
                max_buffered_tx_bytes: 1000000
                max_buffered_rx_bytes: 1000000
                sinks:
                  - format: JSON_BODY_AS_STRING
                    file_per_tap:
                      path_prefix: /var/log/envoy/tap/json_tap
          transport_socket:
            name: envoy.transport_sockets.tls
            typed_config:
              '@type': type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext
# END TAP CONFIG
      load_assignment:
        cluster_name: s3
        endpoints:
          - lb_endpoints:
              - endpoint:
                  address:
                    socket_address:
                      address: s3.amazonaws.com
                      port_value: 443

Activity

  1. added
    triage
    on Oct 20, 2021
  2. added and removed
    triage
    on Oct 21, 2021
  3. htuch commented on Oct 21, 2021

    @htuch
    Member

    @tonya11en @rgs1 @derekargueta @marcomagdy any thoughts on this one?

  4. rgs1 commented on Oct 21, 2021

    @rgs1
    Member

    Pretty sure it's because the signature get invalidated on retry because we add new headers. So, we should either omit the retry related headers when signing or recreate the signature on retry (not sure if there's a hook for this). I am leaning towards the former.

    @wbertelsen I am might not be able to submit a patch soon since I am still on pat leave, but happy to review PRs if you are willing to give it a try in omitting the retry related headers from the signing. Otherwise I'll try to get to this next week.

  5. rgs1 commented on Oct 21, 2021

    @rgs1
    Member

    @wbertelsen just realized that I mostly restated what you had already said in the description :-) So yeah I think we should omit x-envoy-retry-on (rather than regenerating the signature on retry).

    #10280 should serve as an example, in canonicalizeHeaders() we skip some headers already.

  6. wbertelsen commented on Oct 21, 2021

    @wbertelsen
    Author

    I also ended up raising this with @lavignes and his team internally and they may take a pass at a generalized fix for this.

    In the meantime I have been looking at something like the below diff as a simple way to stop signing all the headers touched in
    https://github.com/envoyproxy/envoy/blob/0fae697/source/common/router/retry_state_impl.cc#L35

    diff --git a/source/extensions/common/aws/utility.cc b/source/extensions/common/aws/utility.cc
    index a0ba42fe4..6b982312f 100644
    --- a/source/extensions/common/aws/utility.cc
    +++ b/source/extensions/common/aws/utility.cc
    @@ -38,7 +38,9 @@ Utility::canonicalizeHeaders(const Http::RequestHeaderMap& headers) {
         // Skip headers that are likely to mutate, when crossing 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") {
    +        key == Http::Headers::get().ForwardedProto.get() ||
    +        key == "x-amzn-trace-id" ||
    +        absl::StartsWith(key, "x-envoy")) {
           return Http::HeaderMap::Iterate::Continue;
         }
  7. rgs1 commented on Oct 21, 2021

    @rgs1
    Member

    I think that works. I do have some recollections of discussing this with @marcomagdy or @lavignes and maybe we had a reason to not skip all x-envoy headers 🤔...

    Could you add a test case to that diff and turn it into a PR please?

  8. wbertelsen commented on Oct 22, 2021

    @wbertelsen
    Author

    Could you add a test case to that diff and turn it into a PR please?

    PR is up here: #18729

  9. lavignes commented on Oct 25, 2021

    @lavignes
    Contributor

    Hey didn't notice I was tagged in this thread. I commented on the CR, but this just seems to be an oversight in the signing filter to me. The signer is intentionally designed to sign every part of the request given to it, leaving it up to the caller to decide what needs to be fiddled with on a case-by-case basis. But it looks like a couple excluded headers got hacked into it for the signing extension like x-amzn-trace-id and x-forwarded-*. Really these should get filtered out prior to being handed to the signer.

    Overall I dont mind just hardcoding these to be excluded but ideally headers should be allowlisted via config on the signing filter's API. The signer code itself should really just stick to the sigv4 spec and not have special rules added to it.

  10. wbertelsen commented on Oct 25, 2021

    @wbertelsen
    Author

    I've closed #18729 based on a consensus that the list of non mandatory headers to sign should be configurable.

  11. rexnp commented on Nov 2, 2021

    @rexnp
    Contributor

    hi! just dropping a note that I'll be taking a look at this issue- looking into how to extend the signing filter to include/exclude certain headers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions