Created
January 13, 2023 04:20
-
-
Save keniver/0e4b9a84fa86bbf862c737b6e92faa25 to your computer and use it in GitHub Desktop.
Use the AWS API Access Key to login the AWS Web Console via the Federation Sign in.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests, json, sys, urllib | |
try: | |
import boto3 | |
import botocore.config | |
import requests | |
except ModuleNotFoundError: | |
print("Don't forget to install boto3 and requests.") | |
sys.exit(1) | |
AWS_REGION = "us-east-1" | |
AWS_ACCESS_KEY_ID = "" | |
AWS_ACCESS_KEY_SECRET = "" | |
FEDERATION_NAME = "Rilakkuma" | |
botocore_config = botocore.config.Config( | |
region_name=AWS_REGION, | |
user_agent="Debian", | |
) | |
boto3_session = boto3.session.Session( | |
region_name="us-east-1", | |
aws_access_key_id=AWS_ACCESS_KEY_ID, | |
aws_secret_access_key=AWS_ACCESS_KEY_SECRET, | |
) | |
sts = boto3_session.client("sts", config=botocore_config) | |
sts_federation_response = sts.get_federation_token( | |
Name=FEDERATION_NAME, | |
Policy=json.dumps({"Version": "2012-10-17", "Statement": [{"Effect": "Allow", "Action": "*", "Resource": "*"}]}) | |
) | |
sts_federation_credentials = sts_federation_response["Credentials"] | |
_params = { | |
"Action": "getSigninToken", | |
"SessionType": "json", | |
"Session": json.dumps({ | |
"sessionId": sts_federation_credentials["AccessKeyId"], | |
"sessionKey": sts_federation_credentials["SecretAccessKey"], | |
"sessionToken": sts_federation_credentials["SessionToken"] | |
}) | |
} | |
federation_signin_token = requests.get("https://signin.aws.amazon.com/federation", params=_params).json()["SigninToken"] | |
_params = { | |
"Action": "login", | |
"Issuer": FEDERATION_NAME, | |
"Destination": "https://console.aws.amazon.com/console/home", | |
"SigninToken": federation_signin_token | |
} | |
signin_url = "https://signin.aws.amazon.com/federation?" + urllib.parse.urlencode(_params) | |
print("Signin Url:\n{0}".format(signin_url)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment