-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Signed header using on host:port instead of host only #2965
Comments
Hi @aimran-adroll, thanks for reaching out about this. We do intentionally include the port if it's provided and not implicit with the scheme (http -> 80 and https -> 443). The HTTP RFC for a Host header is defined as (emphasis mine):
You won't typically encounter this scenario with a production AWS service though. Could you provide some more details about your use case and where you found information on the exclusion of the port in signing? Thanks! |
We use Banyan for managing our corporate network. Tldr: Something sits in the middle to mediate access between user (aka my laptop) and internal resources (aws services). Consequently, instead of directly hitting In any case, here is an example where import boto3
from opensearchpy import OpenSearch, AWSV4SignerAuth, RequestsHttpConnection
from requests_aws4auth import AWS4Auth
credentials = boto3.Session().get_credentials()
## THIS WORKS (does _not_ uses botocore)
auth = AWS4Auth(credentials.access_key, credentials.secret_key,
"us-west-2", "es", session_token=credentials.token)
## !!!!! THIS DOES NOT
## (dont be thrown off by AWSV4SignerAuth. it uses merely uses botocre
auth = AWSV4SignerAuth(credentials, "us-west-2")
### everything else remaining same
c = OpenSearch(
hosts=[{"host": "localhost", "port": 7443}],
http_auth=auth, # <---------------------- switch
connection_class=RequestsHttpConnection,
use_ssl=True,
verify_certs=False,
ssl_show_warn=False,
) After spending absurdly crazy amount of time, i am fairly convinced its the use of host:port in the canonical signature thats messing things up. I verified it by crafting the signature by hand and issuing raw requests |
Thanks for the info, @aimran-adroll. To quickly clarify, the Taking a look at There is also a similar discussion around OpenSearch in the originating issue for that PR. Their specific case is due to setting the If you can provide the info requested above, it'll be helpful while we investigate internally. Thanks! |
Thanks @nateprewitt for sticking on this. Its a touch difficult to explain but here it goes. I repeated the above (the two ways of generating in both cases, I am passing host="localhost:7443"case 1: request_aws4authThis is right after it has generated the canonical headers. I inspected the values and host is indeed case 2: using opensearchpy.AWSV4SignerAuthI dropped down to the following place in botocore Line 245 in 6caef35
You can see that host is Since case 2 fails to sign the request, its reasonable to assume that host in botocore in this particular scenario is not set correctly at the signing phase. |
And just to be annoying 😅 , i commented out the following lines in botocore, and 💥 . Case 2 works too Lines 83 to 85 in 6caef35
|
Ok interesting, so this may work, but is 100% not intended functionality. The It looks like OpenSearch, and potentially other services, are interpreting "localhost" as the service host. I'm actually surprised they are accepting this to begin with, but it may be an unintentional omission. |
That certainly makes sense. I am not sure if there is anything to be done here. I guess I will keep using requests_aws4auth since its unintentionally using uri-host for the host header (atleast until they "fix" it) Thanks again |
This issue is now closed. Comments on closed issues are hard for our team to see. |
Describe the bug
At our company. we use 0-trust solution that puts most services (including https) behind non standard local port (e.g 7443 instead of 443)
Consequently, this bit breaks the signing
https://github.com/boto/botocore/blame/5ba1dc100324723b56ff6953350d8218a85b63bf/botocore/auth.py#L83-L85
Because if I am not mistaken the SDK should only use the host bit (e.g 127.0.0.1). But as you can see on line 85, host is being modified if my port does not match your default_ports scheme.
To wit: Canonical header should not have host:port but rather just host regardless if I am not sorely mistaken. And sdk should not confuse endpoint (for making requests) with what goes into awsv4 headers.
To make matter worse. looks like Golang sdk copy pasted the same bits of code
Expected Behavior
canonical header should only contain host
Current Behavior
Getting
Reproduction Steps
Repeat the aws example https://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-query-string-auth.html
with host and host:port to see how this is getting messed up
Possible Solution
No response
Additional Information/Context
No response
SDK version used
botocore==1.29.110, boto3==1.26.97
Environment details (OS name and version, etc.)
py3.9, mac
The text was updated successfully, but these errors were encountered: