Skip to content

AWS Request Signing Documentation enhancement #13904

Closed

Description

@juanvasquezreyes

Can you please update the current documentation and explain how the client_id, client_secret, grant_type, refresh_token can be send using this filer? these are used to generate the token in amazon api first

The current documentation doesnt explain that
https://www.envoyproxy.io/docs/envoy/latest/configuration/http/http_filters/aws_request_signing_filter#config-http-filters-aws-request-signing

also if you have an example using this filter will be very helpful

Activity

  1. added
    triage
    on Nov 4, 2020
  2. juanvasquezreyes commented on Nov 5, 2020

    @juanvasquezreyes
    Author

    @marcomagdy, Can you please help me with this issue I'm facing using the AWS Signing

    These are my logs, I saw the previously opened issue 11292 but I am sending the host as mentioned

    Logs

    [2020-11-05 17:17:42.383][13][debug][aws] [source/extensions/common/aws/credentials_provider_impl.cc:54] Found following AWS credentials in the environment: AWS_ACCESS_KEY_ID=xxxx, AWS_SECRET_ACCESS_KEY=*****, AWS_SESSION_TOKEN=
    [2020-11-05 17:17:42.383][13][debug][http] [source/extensions/common/aws/signer_impl.cc:65] Canonical request:
    POST
    /vendor/directFulfillment/shipping/v1/shippingLabels

    content-length:762
    host:sellingpartnerapi-na.amazon.com
    x-amz-access-token: xxx
    x-amz-content-sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
    x-amz-date:20201105T171700Z
    x-request-id:7371fcb1-4baf-96ec-82ff-a6e7e9c97779

    content-length;host;x-amz-access-token;x-amz-content-sha256;x-amz-date;x-request-id
    e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
    [2020-11-05 17:17:42.383][13][debug][http] [source/extensions/common/aws/signer_impl.cc:69] String to sign:
    AWS4-HMAC-SHA256
    20201105T171700Z
    20201105/us-east-1/execute-api/aws4_request
    a2c24eb435d9c13e9962ad28cda228ca3085e330286396c9436b89cdd95ed017
    [2020-11-05 17:17:42.383][13][debug][http] [source/extensions/common/aws/signer_impl.cc:76] Signing request with: AWS4-HMAC-SHA256 Credential=AKIARYJ2SNXBEZAL526C/20201105/us-east-1/execute-api/aws4_request, SignedHeaders=content-length;host;x-amz-access-token;x-amz-content-sha256;x-amz-date;x-request-id, Signature=79320053c646847e8c105b81a7d2f29007373229e34ae054a33e6d51403e6e67
    [2020-11-05 17:17:42.383][13][trace][http] [source/common/http/filter_manager.cc:451] [C25][S2933720532882456304] decode headers called: filter=0x2ddb3f566600 status=0
    [2020-11-05 17:17:42.383][13][debug][router] [source/common/router/router.cc:429] [C25][S2933720532882456304] cluster 'mycluster' match for URL '/vendor/directFulfillment/shipping/v1/shippingLabels'
    [2020-11-05 17:17:42.383][13][debug][router] [source/common/router/router.cc:586] [C25][S2933720532882456304] router decoding headers:
    ':authority', 'sellingpartnerapi-na.amazon.com'
    ':path', '/vendor/directFulfillment/shipping/v1/shippingLabels'
    ':method', 'POST'
    ':scheme', 'https'
    'x-amz-access-token', 'xxx'
    'content-length', '762'
    'x-forwarded-proto', 'http'
    'x-request-id', '7371fcb1-4baf-96ec-82ff-a6e7e9c97779'
    'x-amz-content-sha256', 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
    'x-amz-date', '20201105T171700Z'
    'authorization', 'AWS4-HMAC-SHA256 Credential=AKIARYJ2SNXBEZAL526C/20201105/us-east-1/execute-api/aws4_request, SignedHeaders=content-length;host;x-amz-access-token;x-amz-content-sha256;x-amz-date;x-request-id, Signature=79320053c646847e8c105b81a7d2f29007373229e34ae054a33e6d51403e6e67'
    'x-envoy-expected-rq-timeout-ms', '15000'

    [2020-11-05 17:17:42.383][13][debug][pool] [source/common/conn_pool/conn_pool_base.cc:174] [C17] using existing connection
    [2020-11-05 17:17:42.383][13][debug][pool] [source/common/conn_pool/conn_pool_base.cc:126] [C17] creating stream
    [2020-11-05 17:17:42.383][13][debug][router] [source/common/router/upstream_request.cc:357] [C25][S2933720532882456304] pool ready
    [2020-11-05 17:17:42.383][13][trace][connection] [source/common/network/connection_impl.cc:435] [C17] writing 1002 bytes, end_stream false
    [2020-11-05 17:17:42.383][13][trace][http] [source/common/http/filter_manager.cc:451] [C25][S2933720532882456304] decode headers called: filter=0x2ddb3f467aa0 status=1
    [2020-11-05 17:17:42.383][13][trace][http] [source/common/http/filter_manager.cc:575] [C25][S2933720532882456304] decode data called: filter=0x2ddb3f566600 status=0
    [2020-11-05 17:17:42.383][13][trace][router] [source/common/router/upstream_request.cc:224] [C25][S2933720532882456304] proxying 762 bytes
    [2020-11-05 17:17:42.383][13][trace][connection] [source/common/network/connection_impl.cc:435] [C17] writing 762 bytes, end_stream false
    [2020-11-05 17:17:42.383][13][trace][http] [source/common/http/filter_manager.cc:575] [C25][S2933720532882456304] decode data called: filter=0x2ddb3f467aa0 status=3
    [2020-11-05 17:17:42.383][13][trace][main] [source/common/event/dispatcher_impl.cc:192] item added to deferred deletion list (size=2)
    [2020-11-05 17:17:42.383][13][debug][pool] [source/common/http/http1/conn_pool.cc:50] [C26] response complete
    [2020-11-05 17:17:42.383][13][debug][pool] [source/common/conn_pool/conn_pool_base.cc:151] [C26] destroying stream: 0 remaining
    [2020-11-05 17:17:42.383][13][trace][http] [source/common/http/http1/codec_impl.cc:599] [C26] parsed 255 bytes
    [2020-11-05 17:17:42.383][13][trace][main] [source/common/event/dispatcher_impl.cc:83] clearing deferred deletion list (size=2)
    [2020-11-05 17:17:42.383][13][trace][connection] [source/common/network/connection_impl.cc:517] [C17] socket event: 2
    [2020-11-05 17:17:42.383][13][trace][connection] [source/common/network/connection_impl.cc:625] [C17] write ready
    [2020-11-05 17:17:42.383][13][trace][connection] [source/extensions/transport_sockets/tls/ssl_socket.cc:249] [C17] ssl write returns: 1764
    [2020-11-05 17:17:42.440][13][trace][connection] [source/common/network/connection_impl.cc:517] [C17] socket event: 3
    [2020-11-05 17:17:42.440][13][trace][connection] [source/common/network/connection_impl.cc:625] [C17] write ready
    [2020-11-05 17:17:42.440][13][trace][connection] [source/common/network/connection_impl.cc:555] [C17] read ready. dispatch_buffered_data=false
    [2020-11-05 17:17:42.440][13][trace][connection] [source/extensions/transport_sockets/tls/ssl_socket.cc:91] [C17] ssl read returns: 1562
    [2020-11-05 17:17:42.440][13][trace][connection] [source/extensions/transport_sockets/tls/ssl_socket.cc:91] [C17] ssl read returns: -1
    [2020-11-05 17:17:42.440][13][trace][connection] [source/extensions/transport_sockets/tls/ssl_socket.cc:166] [C17] ssl read 1562 bytes
    [2020-11-05 17:17:42.440][13][trace][http] [source/common/http/http1/codec_impl.cc:559] [C17] parsing 1562 bytes
    [2020-11-05 17:17:42.440][13][trace][http] [source/common/http/http1/codec_impl.cc:821] [C17] message begin
    [2020-11-05 17:17:42.440][13][trace][http] [source/common/http/http1/codec_impl.cc:492] [C17] completed header: key=Date value=Thu, 05 Nov 2020 17:17:42 GMT
    [2020-11-05 17:17:42.440][13][trace][http] [source/common/http/http1/codec_impl.cc:492] [C17] completed header: key=Content-Type value=application/json
    [2020-11-05 17:17:42.440][13][trace][http] [source/common/http/http1/codec_impl.cc:492] [C17] completed header: key=Content-Length value=1286
    [2020-11-05 17:17:42.440][13][trace][http] [source/common/http/http1/codec_impl.cc:492] [C17] completed header: key=Connection value=keep-alive
    [2020-11-05 17:17:42.440][13][trace][http] [source/common/http/http1/codec_impl.cc:492] [C17] completed header: key=x-amzn-RequestId value=b906b38d-cbdf-4a31-82ed-7f9c152f4e34
    [2020-11-05 17:17:42.440][13][trace][http] [source/common/http/http1/codec_impl.cc:492] [C17] completed header: key=x-amzn-ErrorType value=InvalidSignatureException
    [2020-11-05 17:17:42.440][13][trace][http] [source/common/http/http1/codec_impl.cc:679] [C17] onHeadersCompleteBase
    [2020-11-05 17:17:42.440][13][trace][http] [source/common/http/http1/codec_impl.cc:492] [C17] completed header: key=x-amz-apigw-id value=Vi0EhFHuoAMF2dw=
    [2020-11-05 17:17:42.440][13][trace][http] [source/common/http/http1/codec_impl.cc:1172] [C17] status_code 403
    [2020-11-05 17:17:42.440][13][trace][http] [source/common/http/http1/codec_impl.cc:1182] [C17] Client: onHeadersComplete size=7
    [2020-11-05 17:17:42.440][13][debug][router] [source/common/router/router.cc:1177] [C25][S2933720532882456304] upstream headers complete: end_stream=false
    [2020-11-05 17:17:42.440][13][trace][http] [source/common/http/filter_manager.cc:938] [C25][S2933720532882456304] encode headers called: filter=0x2ddb3f4ddb30 status=0
    [2020-11-05 17:17:42.440][13][debug][http] [source/common/http/conn_manager_impl.cc:1460] [C25][S2933720532882456304] encoding headers via codec (end_stream=false):
    ':status', '403'
    'date', 'Thu, 05 Nov 2020 17:17:42 GMT'
    'content-type', 'application/json'
    'content-length', '1286'
    'x-amzn-requestid', 'b906b38d-cbdf-4a31-82ed-7f9c152f4e34'
    'x-amzn-errortype', 'InvalidSignatureException'
    'x-amz-apigw-id', 'Vi0EhFHuoAMF2dw='
    'x-envoy-upstream-service-time', '57'
    'server', 'envoy'

    [2020-11-05 17:17:42.440][13][trace][connection] [source/common/network/connection_impl.cc:435] [C25] writing 302 bytes, end_stream false
    [2020-11-05 17:17:42.440][13][trace][http] [source/common/http/http1/codec_impl.cc:797] [C17] message complete
    [2020-11-05 17:17:42.440][13][trace][http] [source/common/http/filter_manager.cc:1080] [C25][S2933720532882456304] encode data called: filter=0x2ddb3f4ddb30 status=0
    [2020-11-05 17:17:42.440][13][trace][http] [source/common/http/conn_manager_impl.cc:1469] [C25][S2933720532882456304] encoding data via codec (size=1286 end_stream=false)
    [2020-11-05 17:17:42.440][13][trace][connection] [source/common/network/connection_impl.cc:435] [C25] writing 1286 bytes, end_stream false
    [2020-11-05 17:17:42.440][13][trace][http] [source/common/http/http1/codec_impl.cc:1262] [C17] message complete
    [2020-11-05 17:17:42.440][13][debug][client] [source/common/http/codec_client.cc:109] [C17] response complete
    [2020-11-05 17:17:42.440][13][trace][main] [source/common/event/dispatcher_impl.cc:192] item added to deferred deletion list (size=1)
    [2020-11-05 17:17:42.440][13][trace][http] [source/common/http/filter_manager.cc:1080] [C25][S2933720532882456304] encode data called: filter=0x2ddb3f4ddb30 status=0
    [2020-11-05 17:17:42.440][13][trace][http] [source/common/http/conn_manager_impl.cc:1469] [C25][S2933720532882456304] encoding data via codec (size=0 end_stream=true)
    [2020-11-05 17:17:42.440][13][trace][connection] [source/common/network/connection_impl.cc:318] [C25] readDisable: disable=false disable_count=1 state=0 buffer_length=0
    [2020-11-05 17:17:42.440][13][trace][main] [source/common/event/dispatcher_impl.cc:192] item added to deferred deletion list (size=2)
    [2020-11-05 17:17:42.440][13][trace][misc] [source/common/event/scaled_range_timer_manager_impl.cc:60] enableTimer called on 0x2ddb3f47b980 for 3600000ms, min is 3600000ms
    [2020-11-05 17:17:42.440][13][debug][pool] [source/common/http/http1/conn_pool.cc:50] [C17] response complete
    [2020-11-05 17:17:42.440][13][debug][pool] [source/common/conn_pool/conn_pool_base.cc:151] [C17] destroying stream: 0 remaining
    [2020-11-05 17:17:42.440][13][trace][http] [source/common/http/http1/codec_impl.cc:599] [C17] parsed 1562 bytes
    [2020-11-05 17:17:42.440][13][trace][main] [source/common/event/dispatcher_impl.cc:83] clearing deferred deletion list (size=2)
    [2020-11-05 17:17:42.440][13][trace][connection] [source/common/network/connection_impl.cc:517] [C25] socket event: 2
    [2020-11-05 17:17:42.440][13][trace][connection] [source/common/network/connection_impl.cc:625] [C25] write ready
    [2020-11-05 17:17:42.441][13][trace][connection] [source/common/network/raw_buffer_socket.cc:68] [C25] write returns: 1588
    [2020-11-05 17:17:42.518][13][trace][connection] [source/common/network/connection_impl.cc:517] [C25] socket event: 3
    [2020-11-05 17:17:42.518][13][trace][connection] [source/common/network/connection_impl.cc:625] [C25] write ready
    [2020-11-05 17:17:42.518][13][trace][connection] [source/common/network/connection_impl.cc:555] [C25] read ready. dispatch_buffered_data=false
    [2020-11-05 17:17:42.518][13][trace][connection] [source/common/network/raw_buffer_socket.cc:25] [C25] read returns: 0
    [2020-11-05 17:17:42.518][13][debug][connection] [source/common/network/connection_impl.cc:602] [C25] remote close
    [2020-11-05 17:17:42.518][13][debug][connection] [source/common/network/connection_impl.cc:213] [C25] closing socket: 0
    [2020-11-05 17:17:42.519][13][debug][conn_handler] [source/server/connection_handler_impl.cc:164] [C25] adding to cleanup list
    [2020-11-05 17:17:42.519][13][trace][main] [source/common/event/dispatcher_impl.cc:192] item added to deferred deletion list (size=1)
    [2020-11-05 17:17:42.519][13][trace][main] [source/common/event/dispatcher_impl.cc:192] item added to deferred deletion list (size=2)
    [2020-11-05 17:17:42.519][13][trace][main] [source/common/event/dispatcher_impl.cc:83] clearing deferred deletion list (size=2)
    [2020-11-05 17:17:42.622][6][debug][upstream] [source/common/upstream/logical_dns_cluster.cc:100] starting async DNS resolution for api.amazon.com
    [2020-11-05 17:17:42.623][6][trace][upstream] [source/common/network/dns_impl.cc:206] Setting DNS resolution timer for 5000 milliseconds
    [2020-11-05 17:17:42.645][6][debug][upstream] [source/common/upstream/logical_dns_cluster.cc:108] async DNS resolution complete for api.amazon.com
    [2020-11-05 17:17:42.645][6][debug][upstream] [source/common/upstream/logical_dns_cluster.cc:153] DNS refresh rate reset for api.amazon.com, refresh rate 5000 ms
    [2020-11-05 17:17:42.672][6][debug][main] [source/server/server.cc:190] flushing stats
    [2020-11-05 17:17:43.910][14][trace][connection] [source/common/network/connection_impl.cc:517] [C14] socket event: 3
    [2020-11-05 17:17:43.910][14][trace][connection] [source/common/network/connection_impl.cc:625] [C14] write ready
    [2020-11-05 17:17:43.910][14][trace][connection] [source/common/network/connection_impl.cc:555] [C14] read ready. dispatch_buffered_data=false
    [2020-11-05 17:17:43.910][14][debug][misc] [source/common/network/io_socket_error_impl.cc:30] Unknown error code 104 details Connection reset by peer
    [2020-11-05 17:17:43.910][14][trace][connection] [source/extensions/transport_sockets/tls/ssl_socket.cc:91] [C14] ssl read returns: -1
    [2020-11-05 17:17:43.910][14][debug][connection] [source/extensions/transport_sockets/tls/ssl_socket.cc:215] [C14]
    [2020-11-05 17:17:43.910][14][trace][connection] [source/extensions/transport_sockets/tls/ssl_socket.cc:166] [C14] ssl read 0 bytes
    [2020-11-05 17:17:43.910][14][debug][connection] [source/common/network/connection_impl.cc:602] [C14] remote close
    [2020-11-05 17:17:43.910][14][debug][connection] [source/common/network/connection_impl.cc:213] [C14] closing socket: 0
    [2020-11-05 17:17:43.910][14][debug][misc] [source/common/network/io_socket_error_impl.cc:30] Unknown error code 32 details Broken pipe
    [2020-11-05 17:17:43.910][14][debug][connection] [source/extensions/transport_sockets/tls/ssl_socket.cc:288] [C14] SSL shutdown: rc=-1
    [2020-11-05 17:17:43.910][14][debug][connection] [source/extensions/transport_sockets/tls/ssl_socket.cc:215] [C14]
    [2020-11-05 17:17:43.910][14][debug][client] [source/common/http/codec_client.cc:96] [C14] disconnect. resetting 0 pending requests
    [2020-11-05 17:17:43.910][14][debug][pool] [source/common/conn_pool/conn_pool_base.cc:314] [C14] client disconnected, failure reason:
    [2020-11-05 17:17:43.910][14][trace][main] [source/common/event/dispatcher_impl.cc:192] item added to deferred deletion list (size=1)
    [2020-11-05 17:17:43.910][14][trace][main] [source/common/event/dispatcher_impl.cc:83] clearing deferred deletion list (size=1)
    [2020-11-05 17:17:44.356][6][debug][upstream] [source/common/upstream/logical_dns_cluster.cc:100] starting async DNS resolution for sandbox.sellingpartnerapi-na.amazon.com
    [2020-11-05 17:17:44.357][6][trace][upstream] [source/common/network/dns_impl.cc:206] Setting DNS resolution timer for 5000 milliseconds
    [2020-11-05 17:17:44.375][6][debug][upstream] [source/common/upstream/logical_dns_cluster.cc:108] async DNS resolution complete for sandbox.sellingpartnerapi-na.amazon.com
    [2020-11-05 17:17:44.375][6][debug][upstream] [source/common/upstream/logical_dns_cluster.cc:153] DNS refresh rate reset for sandbox.sellingpartnerapi-na.amazon.com, refresh rate 5000 ms

    In postman this is the output

    {
    "errors": [
    {
    "message": "The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.

    The Canonical String for this request should have been
    'POST
    /vendor/directFulfillment/shipping/v1/shippingLabels

    content-length: 762
    host:sellingpartnerapi-na.amazon.com
    x-amz-access-token: xxx
    x-amz-content-sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
    x-amz-date: 20201105T171700Z
    x-request-id: 7371fcb1-4baf-96ec-82ff-a6e7e9c97779

    content-length;host;x-amz-access-token;x-amz-content-sha256;x-amz-date;x-request-id
    0211d2a359609b6fc59a17a6a4b212c361d9cb0117acc150586630e6ab7bdbfb'

    The String-to-Sign should have been
    'AWS4-HMAC-SHA256
    20201105T171700Z
    20201105/us-east-1/execute-api/aws4_request
    0ea5d8673118836f10d56002e3cb599cae8f4cecffd3c1dc8aaedaa98089bb6a'
    ",
    "code": "InvalidSignature"
    }
    ]
    }

  3. lavignes commented on Nov 6, 2020

    @lavignes
    Contributor

    Hey @juanvasquezreyes the things you are referring to above:

    • client_id
    • client_secret
    • grant_type
    • refresh_token

    Seem to be related to OpenID/WebIdentity credentials.

    The credentials provider in Envoy doesn't support those credential sources right now. It supports environment variables and the EC2 Instance or ECS Task Metadata endpoints to fetch credentials.

    If you notice the logs you pasted, Envoy chose to use environment variables to get its credentials.

    Perhaps those credentials were expired?

  4. juanvasquezreyes commented on Nov 6, 2020

    @juanvasquezreyes
    Author

    Hey @juanvasquezreyes the things you are referring to above:

    • client_id
    • client_secret
    • grant_type
    • refresh_token

    Seem to be related to OpenID/WebIdentity credentials.

    The credentials provider in Envoy doesn't support those credential sources right now. It supports environment variables and the EC2 Instance or ECS Task Metadata endpoints to fetch credentials.

    If you notice the logs you pasted, Envoy chose to use environment variables to get its credentials.

    Perhaps those credentials were expired?

    They are not expired I already tested that not using envoy

    I think the issue I'm facing is related to the signing process, these are my latest logs, this value is harcoded e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 in this file https://github.com/envoyproxy/envoy/blob/master/source/extensions/common/aws/signer_impl.h, so not sure if is related

    [2020-11-06 15:46:23.820][15][debug][aws] [source/extensions/common/aws/credentials_provider_impl.cc:54] Found following AWS credentials in the environment: AWS_ACCESS_KEY_ID=AKIARYJ2SNXBEZAL526C, AWS_SECRET_ACCESS_KEY=*****, AWS_SESSION_TOKEN=
    [2020-11-06 15:46:23.820][15][debug][http] [source/extensions/common/aws/signer_impl.cc:65] Canonical request:
    POST
    /vendor/directFulfillment/shipping/v1/shippingLabels
    
    content-length:762
    host:sellingpartnerapi-na.amazon.com
    x-amz-access-token:Axxx
    x-amz-date:20201106T154600Z
    x-request-id:f9bfbbab-fc79-9871-8cfa-4ea92ac8a872
    
    content-length;host;x-amz-access-token;x-amz-content-sha256;x-amz-date;x-request-id
    e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
    [2020-11-06 15:46:23.820][15][debug][http] [source/extensions/common/aws/signer_impl.cc:69] String to sign:
    AWS4-HMAC-SHA256
    20201106T154600Z
    20201106/us-east-1/execute-api/aws4_request
    83c294f14dd9c09464481aa9ccb55c5bf0231060dd79c5f736c262c737431204
    [2020-11-06 15:46:23.820][15][debug][http] [source/extensions/common/aws/signer_impl.cc:76] Signing request with: AWS4-HMAC-SHA256 Credential=AKIARYJ2SNXBEZAL526C/20201106/us-east-1/execute-api/aws4_request, SignedHeaders=content-length;host;x-amz-access-token;x-amz-content-sha256;x-amz-date;x-request-id, Signature=fc293bfd5da61f067a011dc1cd3e2229370d711a34c860e7474f068491fea804
    [2020-11-06 15:46:23.820][15][trace][http] [source/common/http/filter_manager.cc:451] [C3][S7491712956101629142] decode headers called: filter=0xf86bf4e0f60 status=0
    [2020-11-06 15:46:23.820][15][debug][router] [source/common/router/router.cc:429] [C3][S7491712956101629142] cluster 'mycluster' match for URL '/vendor/directFulfillment/shipping/v1/shippingLabels'
    [2020-11-06 15:46:23.820][15][debug][router] [source/common/router/router.cc:586] [C3][S7491712956101629142] router decoding headers:
    ':authority', 'sellingpartnerapi-na.amazon.com'
    ':path', '/vendor/directFulfillment/shipping/v1/shippingLabels'
    ':method', 'POST'
    ':scheme', 'https'
    'content-length', '762'
    'x-forwarded-proto', 'http'
    'x-request-id', 'f9bfbbab-fc79-9871-8cfa-4ea92ac8a872'
    'x-amz-access-token', 'Axxx'
    'x-amz-content-sha256', 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
    'x-amz-date', '20201106T154600Z'
    'authorization', 'AWS4-HMAC-SHA256 Credential=AKIARYJ2SNXBEZAL526C/20201106/us-east-1/execute-api/aws4_request, SignedHeaders=content-length;host;x-amz-access-token;x-amz-content-sha256;x-amz-date;x-request-id, Signature=fc293bfd5da61f067a011dc1cd3e2229370d711a34c860e7474f068491fea804'
    'x-envoy-expected-rq-timeout-ms', '15000'
    
    [2020-11-06 15:46:23.820][15][debug][pool] [source/common/conn_pool/conn_pool_base.cc:174] [C2] using existing connection
    [2020-11-06 15:46:23.820][15][debug][pool] [source/common/conn_pool/conn_pool_base.cc:126] [C2] creating stream
    [2020-11-06 15:46:23.820][15][debug][router] [source/common/router/upstream_request.cc:357] [C3][S7491712956101629142] pool ready
    [2020-11-06 15:46:23.820][15][trace][connection] [source/common/network/connection_impl.cc:435] [C2] writing 1002 bytes, end_stream false
    [2020-11-06 15:46:23.820][15][trace][http] [source/common/http/filter_manager.cc:451] [C3][S7491712956101629142] decode headers called: filter=0xf86bf4e0ae0 status=1
    [2020-11-06 15:46:23.820][15][trace][http] [source/common/http/filter_manager.cc:575] [C3][S7491712956101629142] decode data called: filter=0xf86bf4e0f60 status=0
    [2020-11-06 15:46:23.820][15][trace][router] [source/common/router/upstream_request.cc:224] [C3][S7491712956101629142] proxying 762 bytes
    [2020-11-06 15:46:23.820][15][trace][connection] [source/common/network/connection_impl.cc:435] [C2] writing 762 bytes, end_stream false
    [2020-11-06 15:46:23.820][15][trace][http] [source/common/http/filter_manager.cc:575] [C3][S7491712956101629142] decode data called: filter=0xf86bf4e0ae0 status=3
    [2020-11-06 15:46:23.820][15][trace][main] [source/common/event/dispatcher_impl.cc:192] item added to deferred deletion list (size=2)
    [2020-11-06 15:46:23.820][15][debug][pool] [source/common/http/http1/conn_pool.cc:50] [C4] response complete
    [2020-11-06 15:46:23.820][15][debug][pool] [source/common/conn_pool/conn_pool_base.cc:151] [C4] destroying stream: 0 remaining
    [2020-11-06 15:46:23.820][15][trace][http] [source/common/http/http1/codec_impl.cc:599] [C4] parsed 1170 bytes
    [2020-11-06 15:46:23.820][15][trace][main] [source/common/event/dispatcher_impl.cc:83] clearing deferred deletion list (size=2)
    [2020-11-06 15:46:23.820][15][trace][connection] [source/common/network/connection_impl.cc:517] [C2] socket event: 2
    [2020-11-06 15:46:23.820][15][trace][connection] [source/common/network/connection_impl.cc:625] [C2] write ready
    [2020-11-06 15:46:23.820][15][trace][connection] [source/extensions/transport_sockets/tls/ssl_socket.cc:249] [C2] ssl write returns: 1764
    [2020-11-06 15:46:23.878][15][trace][connection] [source/common/network/connection_impl.cc:517] [C2] socket event: 3
    [2020-11-06 15:46:23.878][15][trace][connection] [source/common/network/connection_impl.cc:625] [C2] write ready
    [2020-11-06 15:46:23.878][15][trace][connection] [source/common/network/connection_impl.cc:555] [C2] read ready. dispatch_buffered_data=false
    [2020-11-06 15:46:23.878][15][trace][connection] [source/extensions/transport_sockets/tls/ssl_socket.cc:91] [C2] ssl read returns: 1562
    [2020-11-06 15:46:23.878][15][trace][connection] [source/extensions/transport_sockets/tls/ssl_socket.cc:91] [C2] ssl read returns: -1
    [2020-11-06 15:46:23.878][15][trace][connection] [source/extensions/transport_sockets/tls/ssl_socket.cc:166] [C2] ssl read 1562 bytes
    [2020-11-06 15:46:23.878][15][trace][http] [source/common/http/http1/codec_impl.cc:559] [C2] parsing 1562 bytes
    [2020-11-06 15:46:23.878][15][trace][http] [source/common/http/http1/codec_impl.cc:821] [C2] message begin
    [2020-11-06 15:46:23.878][15][trace][http] [source/common/http/http1/codec_impl.cc:492] [C2] completed header: key=Date value=Fri, 06 Nov 2020 15:46:23 GMT
    [2020-11-06 15:46:23.878][15][trace][http] [source/common/http/http1/codec_impl.cc:492] [C2] completed header: key=Content-Type value=application/json
    [2020-11-06 15:46:23.878][15][trace][http] [source/common/http/http1/codec_impl.cc:492] [C2] completed header: key=Content-Length value=1286
    [2020-11-06 15:46:23.878][15][trace][http] [source/common/http/http1/codec_impl.cc:492] [C2] completed header: key=Connection value=keep-alive
    [2020-11-06 15:46:23.878][15][trace][http] [source/common/http/http1/codec_impl.cc:492] [C2] completed header: key=x-amzn-RequestId value=8e363deb-67de-4435-a761-d9c172579b2a
    [2020-11-06 15:46:23.878][15][trace][http] [source/common/http/http1/codec_impl.cc:492] [C2] completed header: key=x-amzn-ErrorType value=InvalidSignatureException
    [2020-11-06 15:46:23.878][15][trace][http] [source/common/http/http1/codec_impl.cc:679] [C2] onHeadersCompleteBase
    [2020-11-06 15:46:23.878][15][trace][http] [source/common/http/http1/codec_impl.cc:492] [C2] completed header: key=x-amz-apigw-id value=Vl5ofE7AIAMFnDQ=
    [2020-11-06 15:46:23.878][15][trace][http] [source/common/http/http1/codec_impl.cc:1172] [C2] status_code 403
    [2020-11-06 15:46:23.878][15][trace][http] [source/common/http/http1/codec_impl.cc:1182] [C2] Client: onHeadersComplete size=7
    [2020-11-06 15:46:23.878][15][debug][router] [source/common/router/router.cc:1177] [C3][S7491712956101629142] upstream headers complete: end_stream=false
    [2020-11-06 15:46:23.878][15][trace][http] [source/common/http/filter_manager.cc:938] [C3][S7491712956101629142] encode headers called: filter=0xf86bfb7a820 status=0
    [2020-11-06 15:46:23.878][15][debug][http] [source/common/http/conn_manager_impl.cc:1460] [C3][S7491712956101629142] encoding headers via codec (end_stream=false):
    ':status', '403'
    'date', 'Fri, 06 Nov 2020 15:46:23 GMT'
    'content-type', 'application/json'
    'content-length', '1286'
    'x-amzn-requestid', '8e363deb-67de-4435-a761-d9c172579b2a'
    'x-amzn-errortype', 'InvalidSignatureException'
    'x-amz-apigw-id', 'Vl5ofE7AIAMFnDQ='
    'x-envoy-upstream-service-time', '58'
    'server', 'envoy'
    
    [2020-11-06 15:46:23.878][15][trace][connection] [source/common/network/connection_impl.cc:435] [C3] writing 302 bytes, end_stream false
    [2020-11-06 15:46:23.878][15][trace][http] [source/common/http/http1/codec_impl.cc:797] [C2] message complete
    

    These are the error log I see in my app

    {
        "errors": [
            {
                "message": "The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.
    
    The Canonical String for this request should have been
    'POST
    /vendor/directFulfillment/shipping/v1/shippingLabels
    
    content-length: 762
    host:sellingpartnerapi-na.amazon.com
    x-amz-access-token:Axxx
    x-amz-date: 20201106T154600Z
    x-request-id:f9bfbbab-fc79-9871-8cfa-4ea92ac8a872
    
    content-length;host;x-amz-access-token;x-amz-content-sha256;x-amz-date;x-request-id
    0211d2a359609b6fc59a17a6a4b212c361d9cb0117acc150586630e6ab7bdbfb'
    
    The String-to-Sign should have been
    'AWS4-HMAC-SHA256
    20201106T154600Z
    20201106/us-east-1/execute-api/aws4_request
    db7e8e237496d82d6652e8a96364e9c9fc41650d09ed86439713bea7ff711e0c'
    ",
         "code": "InvalidSignature"
            }
        ]
    }
    
  5. lavignes commented on Nov 6, 2020

    @lavignes
    Contributor

    Oh I see. So the value

    e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
    

    Is the hash of the empty string. In SigV4, if the x-amz-content-sha256 header is passed to the service as a signed header then it is implied that the client and server are using the request body to calculate the signature.

    It is very common for this header to not be passed. So many SigV4 implementations have this value hard-coded, as it is expected to be used when the request body is not signed.

    My guess is that this filter has a bug. It is signing the request as if the request body will be used as part of the signature but is not actually buffering the request body and calculating the hash.

    As I mentioned though, passing the x-amz-content-sha256 header (signing the request body) is optional. But there is no setting in this extension to turn that on or off. That should probably be added as well.

  6. abaptiste commented on Nov 6, 2020

    @abaptiste
    Contributor

    Looking a bit closer, the empty hash string is used if the specified service is not one of 's3', 'glacier' or 'es'.

    What does your filter config look like? Specifically looking at the service name

    Based on the request content, I would guess that the service is set to execute-api hence the filter not signing the body. These are the lines I'm basing my statement on:

    [2020-11-06 15:46:23.820][15][debug][http] [source/extensions/common/aws/signer_impl.cc:69] String to sign:
    AWS4-HMAC-SHA256
    20201106T154600Z
    20201106/us-east-1/execute-api/aws4_request
    ...
    
  7. juanvasquezreyes commented on Nov 6, 2020

    @juanvasquezreyes
    Author

    Looking a bit closer, the empty hash string is used if the specified service is not one of 's3', 'glacier' or 'es'.

    What does your filter config look like? Specifically looking at the service name

    Based on the request content, I would guess that the service is set to execute-api hence the filter not signing the body. These are the lines I'm basing my statement on:

    [2020-11-06 15:46:23.820][15][debug][http] [source/extensions/common/aws/signer_impl.cc:69] String to sign:
    AWS4-HMAC-SHA256
    20201106T154600Z
    20201106/us-east-1/execute-api/aws4_request
    ...
    
          - name: envoy.filters.http.aws_request_signing
            typed_config:
              "@type": type.googleapis.com/envoy.extensions.filters.http.aws_request_signing.v3.AwsRequestSigning
              service_name: execute-api
              region: us-east-1
          - name: envoy.router
    
  8. abaptiste commented on Nov 6, 2020

    @abaptiste
    Contributor

    As @lavignes mentioned, this is likely a bug. The filter needs to be extended to include API Gateway, since requests to that service can have a body.

  9. lavignes commented on Nov 6, 2020

    @lavignes
    Contributor

    I'd vote to not add API Gateway to that list and instead just add a boolean option to the extension to enable/disable body signing and adding the content hash header. But even then it looks like the extension doesn't even support body signing: https://github.com/envoyproxy/envoy/blob/master/source/extensions/filters/http/aws_request_signing/aws_request_signing_filter.cc#L36

    s3 should be the only service that requires special treatment as far as I'm aware. But it looks like those other services were added here: #12020. To me it seems like they were trying to fix the bug, but in the wrong way.

    Those hacks should be removed and then not pass x-amz-content-sha256 by default since it implies that Envoy will sign the actual request body.

  10. juanvasquezreyes commented on Nov 9, 2020

    @juanvasquezreyes
    Author

    Hello @lavignes thank you for your reply
    so, who should we talk to in order to do the changes required to make it work?

  11. 11 remaining items

  12. jstewmon commented on Apr 4, 2021

    @jstewmon
    Contributor

    👋 Hi @azihsoyn @dio @rgs1 @derekargueta @mattklein123 @marcomagdy

    Can we reopen this issue and add a no stalebot label? It precludes the use of POST (or any other method with with a body) because the x-amz-content-sha256 hash does not match the body.

    For anyone looking for a workaround, I found that the filter works with GET requests, as long as the query parameters are already sorted. Of course, GET requests aren't going to cover a lot of use cases.

    For example, I'm able to publish to SNS with a request like this:

    ✗ curl -G localhost:12345 \
    --data-urlencode "Action=Publish" \
    --data-urlencode "Message=Hello World" \
    --data-urlencode "TopicArn=arn:aws:sns:us-east-1:1234567890:stew-test" \
    --data-urlencode "Version=2010-03-31" \
    

    Using the following route config:

      route_config:
        name: local_route
        virtual_hosts:
          - name: sns
            domains: ['*']
            routes:
            - name: sns
              match:
                prefix: /
              route:
                cluster: sns
      http_filters:
        - name: envoy.filters.http.aws_request_signing
          typed_config:
            "@type": type.googleapis.com/envoy.extensions.filters.http.aws_request_signing.v3.AwsRequestSigning
            service_name: sns
            region: us-east-1
            host_rewrite: sns.us-east-1.amazonaws.com
        - name: envoy.filters.http.router
          typed_config: {}
  13. added
    help wanted
    and removed
    stale
    on Apr 4, 2021
  14. added a commit that references this issue on May 12, 2021
    80e1ca8
  15. abdennour commented on Feb 25, 2023

    @abdennour

    any working example for aws s3 with custom endpoint ?

  16. phlax commented on Feb 25, 2023

    @phlax
    Member

    any working example for aws s3 with custom endpoint ?

    not that im aware of - but worth searching docs

    minio sounds like something that would be pretty cool as a sandbox if we could figure out a working config

  17. abdennour commented on Feb 25, 2023

    @abdennour

    @phlax strongly needed! yes i meant Minio.

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

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions