Skip to content

Commit

Permalink
fix(sts): handle China STS regions (#3613)
Browse files Browse the repository at this point in the history
  • Loading branch information
sergargar authored Mar 27, 2024
1 parent 5b46bf4 commit 3015381
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions prowler/providers/aws/lib/credentials/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ def print_aws_credentials(audit_info: AWS_Audit_Info):
def create_sts_session(
session: session.Session, aws_region: str
) -> session.Session.client:
return session.client(
"sts", aws_region, endpoint_url=f"https://sts.{aws_region}.amazonaws.com"
sts_endpoint_url = (
f"https://sts.{aws_region}.amazonaws.com"
if "cn-" not in aws_region
else f"https://sts.{aws_region}.amazonaws.com.cn"
)
return session.client("sts", aws_region, endpoint_url=sts_endpoint_url)
2 changes: 1 addition & 1 deletion tests/providers/aws/lib/credentials/credentials_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,4 +507,4 @@ def test_create_sts_session_china(self):
sts_client = create_sts_session(session, aws_region)

assert sts_client._endpoint._endpoint_prefix == "sts"
assert sts_client._endpoint.host == f"https://sts.{aws_region}.amazonaws.com"
assert sts_client._endpoint.host == f"https://sts.{aws_region}.amazonaws.com.cn"

0 comments on commit 3015381

Please sign in to comment.