Skip to content

Ministack: Free, open-source local AWS emulator - 60+ services, Terraform compatible, real databases. Free forever. MIT licensed.

fix(router): access key extraction from query params (#1011)

Neriya Cohen88ebbfc7aa9c
diff --git a/ministack/app.py b/ministack/app.py
index 125678ae..e85848dc 100644
--- a/ministack/app.py
+++ b/ministack/app.py
@@ -1552,7 +1552,7 @@ def _maybe_record_cloudtrail(
try:
event_name = _ct_event_name(service, method, path, headers, query_params)
resources = _ct_resources(service, method, path, body)
- access_key_id = extract_access_key_id(headers) or "test"
+ access_key_id = extract_access_key_id(headers, query_params) or "test"
user_agent = headers.get("user-agent", "")
request_params = _ct_request_params(headers, body, query_params)
ct_mod.record_event(
@@ -1715,7 +1715,7 @@ async def app(scope, receive, send):
# Set per-request account ID from credentials (multi-tenancy support).
# If the access key is a 12-digit number, it becomes the account ID.
- _access_key = extract_access_key_id(headers)
+ _access_key = extract_access_key_id(headers, query_params)
if _access_key:
set_request_account_id(_access_key)
diff --git a/ministack/core/router.py b/ministack/core/router.py
index 10918a61..54c50ad6 100644
--- a/ministack/core/router.py
+++ b/ministack/core/router.py
@@ -912,13 +912,28 @@ def extract_region(headers: dict) -> str:
return os.environ.get("MINISTACK_REGION", "us-east-1")
-def extract_access_key_id(headers: dict) -> str:
- """Extract the AWS access key ID from the Authorization header."""
+def extract_access_key_id(headers: dict, query_params: dict) -> str:
+ """Extract the AWS access key ID from the Authorization header or query parameters."""
+
+ if "X-Amz-Credential" in query_params:
+ credential = query_params["X-Amz-Credential"][0]
+ access_key_id = credential.split("/")[0]
+ return access_key_id
+
auth = headers.get("authorization", "")
- if auth:
+ if auth.startswith("AWS4-HMAC"):
match = re.search(r"Credential=([^/]+)/", auth)
if match:
return match.group(1)
+
+ if "AWSAccessKeyId" in query_params:
+ return query_params["AWSAccessKeyId"][0]
+
+ if auth.startswith("AWS "):
+ match = re.search(r"AWS ([^:]+):", auth)
+ if match:
+ return match.group(1)
+
return ""