Repository navigation
Description
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
htuch commentedon Oct 21, 2021
@tonya11en @rgs1 @derekargueta @marcomagdy any thoughts on this one?
rgs1 commentedon Oct 21, 2021
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.
rgs1 commentedon Oct 21, 2021
@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.wbertelsen commentedon Oct 21, 2021
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
rgs1 commentedon Oct 21, 2021
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-envoyheaders 🤔...Could you add a test case to that diff and turn it into a PR please?
aws_request_signing: Don't sign x-envoy headers
wbertelsen commentedon Oct 22, 2021
PR is up here: #18729
lavignes commentedon Oct 25, 2021
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-idandx-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.
wbertelsen commentedon Oct 25, 2021
I've closed #18729 based on a consensus that the list of non mandatory headers to sign should be configurable.
rexnp commentedon Nov 2, 2021
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.