From 3015381f43fb97c82834a5395d3c1fbca6af0308 Mon Sep 17 00:00:00 2001 From: Sergio Garcia <38561120+sergargar@users.noreply.github.com> Date: Wed, 27 Mar 2024 11:18:44 +0100 Subject: [PATCH] fix(sts): handle China STS regions (#3613) --- prowler/providers/aws/lib/credentials/credentials.py | 7 +++++-- tests/providers/aws/lib/credentials/credentials_test.py | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/prowler/providers/aws/lib/credentials/credentials.py b/prowler/providers/aws/lib/credentials/credentials.py index 8d7984d855..6e8e7967f0 100644 --- a/prowler/providers/aws/lib/credentials/credentials.py +++ b/prowler/providers/aws/lib/credentials/credentials.py @@ -69,6 +69,9 @@ Caller Identity ARN: {Fore.YELLOW}[{audit_info.audited_identity_arn}]{Style.RESE 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) diff --git a/tests/providers/aws/lib/credentials/credentials_test.py b/tests/providers/aws/lib/credentials/credentials_test.py index 6397cc3d64..c230e5f66e 100644 --- a/tests/providers/aws/lib/credentials/credentials_test.py +++ b/tests/providers/aws/lib/credentials/credentials_test.py @@ -507,4 +507,4 @@ class Test_AWS_Credentials: 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"