saltstack / saltstack/salt

[BUG] salt.utils.aws.sig4 force usage of version as GET parameters even if method is not GET

Open
#61,243 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
15.7k
Forks
5.6k
Avg merge
2d 44m
Merged PRs (30d)
80

Description

Description
A clear and concise description of what the bug is.

** Setup
No Setup required

Steps to Reproduce the behavior

from salt.utils.aws import sig4
import requests

method = "POST"
body="Action=GetCallerIdentity&Version=2011-06-15"
endpoint="sts.amazonaws.com"
location="us-east-1"
params = {}
version = "2011-06-15"
product = "sts"
provider = {'id': 'use-instance-role-credentials', 'key': 'use-instance-role-credentials'}
hd = {"Content-Type": "application/x-www-form-urlencoded; charset=utf-8"}
headers, requests_url = sig4(   method=method, 
                                endpoint=endpoint,
                                prov_dict=provider,
                                params=params,
                                product="sts",
                                data=body,
                                aws_api_version=version,
                                location=location,
                                requesturl=f"https://{endpoint}/",
                                headers=hd
                            )
print(requests_url)
# https://sts.amazonaws.com?Version=2011-06-15
print(headers)
# {'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8', 'X-Amz-date': '20211116T160158Z', 'host': 'sts.amazonaws.com', 'x-amz-content-sha256': 'ab821ae955788b0e33ebd34c208442ccfc2d406e2edc5e7a39bd6458fbb4f843', 'X-Amz-security-token': '<redacted>', 'Authorization': 'AWS4-HMAC-SHA256 Credential=<redacted>/20211116/us-east-1/sts/aws4_request, SignedHeaders=content-type;host;x-amz-content-sha256;x-amz-date;x-amz-security-token, Signature=<redacted>'}
r = requests.post(requests_url,headers= headers, data=body) # https://sts.amazonaws.com/?Version=2011-06-15
print(r.status_code)
# 400
print(r.text)
# ... When Content-Type:application/x-www-form-urlencoded, URL cannot include query-string parameters (after \'?\'): \'/?Version=2011-06-15\' ...
r = requests.post("https://sts.amazonaws.com/",headers= headers, data=body) # Manually remove GET parameters
print(r.status_code)
# 403
print(r.text)
# 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.
params = {"Action":"GetCallerIdentity", "Version": "2011-06-15"}
method = "GET"
hd = {}
body=""
headers, requests_url = sig4(   method=method, 
                                endpoint=endpoint,
                                prov_dict=provider,
                                params=params,
                                product="sts",
                                data=body,
                                aws_api_version=version,
                                location=location,
                                requesturl=f"https://{endpoint}/",
                                headers=hd
                            )
print(requests_url)
# https://sts.amazonaws.com/?Action=GetCallerIdentity&Version=2011-06-15
r = requests.get(requests_url,headers= headers)
print(r.status_code)
# 200

Expected behavior
request_url should not contains any params when not using GET method and then query_string should be empty in order to have a valid aws sig4 signature

Versions Report

salt --versions-report ``` Salt Version: Salt: 3004

Dependency Versions:
cffi: Not Installed
cherrypy: Not Installed
dateutil: 2.7.3
docker-py: Not Installed
gitdb: 2.0.6
gitpython: 3.0.7
Jinja2: 2.10.1
libgit2: 0.28.3
M2Crypto: Not Installed
Mako: Not Installed
msgpack: 0.6.2
msgpack-pure: Not Installed
mysql-python: Not Installed
pycparser: Not Installed
pycrypto: Not Installed
pycryptodome: 3.6.1
pygit2: 1.0.3
Python: 3.8.10 (default, Sep 28 2021, 16:10:42)
python-gnupg: 0.4.5
PyYAML: 5.3.1
PyZMQ: 18.1.1
smmap: 2.0.5
timelib: Not Installed
Tornado: 4.5.3
ZMQ: 4.3.2

System Versions:
dist: ubuntu 20.04 focal
locale: utf-8
machine: x86_64
release: 5.11.0-1020-aws
system: Linux
version: Ubuntu 20.04 focal

</details>

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with salt.utils.aws.sig4 and run the POST and GET reproductions from the issue against the shown AWS STS endpoint. Trace how aws_api_version and params become the request URL and signed query string; done means non-GET requests have no query parameters and produce a valid AWS SigV4 signature while GET behavior remains valid.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, python
Domain
cloud
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.