Azure-AD SSO with AWS manual Cli access
Manual Cli access for Azure-AD SSO to AWS
For Cli access for Azure-AD SSO to AWS there is an opensource tool called AWS-Azure login
[ https://github.com/sportradar/aws-azure-login ]. But some may feel insecure for using your Azure credentials with opensource tools. Then how to gain Cli access. As mentioned in the Microsoft post
[ https://feedback.azure.com/forums/169401-azure-active-directory/suggestions/39560995-azure-ad-aws-cli-authentication ] the process seems to be lengthy and manual but still it is possible. You cannot find all these steps in a single place anywhere as documented here. So, if you are security concerned to not share your Azure credentials with opensource tools then you can follow below steps.
Start Azure-AD SSO and capture the SAML response from the browser developer console:
Google chrome:
To view a SAML response in chrome
These steps were tested using version 54.0.2840.87m. If you use another version, you might need to adapt the steps accordingly.
- Press F12 to start the developer console. 
- Select the Network tab, and then select Preserve log. 
- Reproduce the issue. 
- Look for a SAML Post in the developer console pane. Select that row, and then view the Headers tab at the bottom. Look for the SAML Response attribute that contains the encoded request. 
- Mozilla Firefox: - To view a SAML response in Firefox: - This procedure was tested on version 37.0.2 of Mozilla Firefox. If you use another version, you might need to adapt the steps accordingly. - Press F12 to start the developer console. 
 - In the upper right of the developer tools window, click options (the small gear icon). Under Common Preferences select Enable persistent logs. 
 - Select the Network tab. 
 - Reproduce the issue. 
 - Look for a POST SAML in the table. Select that row. In the Form Data window on the right, select the Params tab and find the SAML Response element. - Apple safari: - To view a SAML response in safari - These steps were tested using version 8.0.6 (10600.6.3). If you use another version, you might need to adapt the steps accordingly. - Enable Web Inspector in Safari. Open the Preferences window, select the Advanced tab, and then select Show Develop menu in the menu bar. 
 - Now you can open Web Inspector. Click Develop, then select Show Web Inspector. 
 - Select the Resources tab. 
 - Reproduce the issue. 
 - Look for a saml-signin.aws.amazon.com request. 
 - Scroll down to find Request Data with the name SAM Response. The associated value is the Base64-encoded response. 
- 1. Now copy the SAML Response. 
 - 2. Issue the following command: 
- aws sts assume-role-with-saml 
 - --role-arn arn:aws:iam::accountID:role/ec2-sso-testingrole - --principal-arn arn:aws:iam::accountID:saml-provider/AzureADSSO - --saml-assertion (Paste the SAML response) 
- The output will be like: 
 - https://signin.aws.amazon.com/saml https://sts.windows.net/f5530189-fe77 rG876M0Gxfm0iosuJPGPpLT/nJM= Thuvaragesh@fx.com urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress - ASSUMEDROLEUSER arn:aws:sts::459:assumed-role/ec2-sso-testingrole/Thuvaragesh@fx.com AROAWV6A57:Thuvaragesh@fx.com - CREDENTIALS ASIAWV 2020-11-23T06:42:56+00:00 1WXbwyA5wzs+v7xMOVvPdgFKq - IQoJb3JpZ2luX2VjED8aCXVzLWVhc3QtMSJHMEUCIQDWb 
- F9uz8P5t641wmg9koNHu0UriJ2y3qvD6II33592XwIgIp1w85Q 
- 7QV7CSRjxGoeMqBEKqX5QFrSkPsTC8+UBPWgqjgMIuP///// 
- /////ARAAGgw0NTk0MjkyNDc0NTEiDMfzAHiEaUfsMmfvliriAlK 
- uBnI8Z/P2rENe7N8KivRg7oD1BS1btX/MDTaderimMG54dgtNd 
- w4SZZmzdSY8a/Klo/z1tlSBLdZ5VsyPEta4a2utrZMBhtM0GznV 
- JsEnwJttqVwVAqig+dPq2n/K0m6gZnN27ZPVM67nEkJ/nNrVN6 
- xI1q1Z+v87XhkvBPYvfPz8Bg8ft3ndORLaolNqxmjGpckFGgg4 
- Uh/rGg3hK4cuCz4CEMC9kZIXUQS9zD6e2dWTddvOo5BY0/+9 
- ouCDoUMU7HIWgL+84GznsiLcidJKOiFNzkn5TZncXfchrtmZM 
- V5Hse8LuYFhDKiCYnV0FU0H59Qk7xUO2SLOjIItb8PH9n7rwR 
- MtCfFH6+R+zZ9eIy43Yo//kPPCiyxZFZOoIyZtPWZvNSizsQvoJh 
- ATUG34rGcshpTQNmawy8duDIgdvWCNTyeMQyizjuQhM8okZ 
- RkWdcemvIhjFmksgoaP3CN+UzDsrO39BTqaAQe0R4+YX5D4Z 
- uBC3nGxEvkOcOk7nLTEvuOlBDmnRtRtk+7mwVggZwW0Umo 
- bLaN7Swd3ADgTciRJl+RRQyw6JXnU8rqVsJdW7/eaHLXmCPS 
- NyUykWx3Uy/Na0HajI8NtLn 
- 1. Copy the credentials from the above output i.e. acces_key_id, in this case 	ASIAWV 
- 2. Copy the 	aws_secret_access_key i.e. 	1WXbwyA5wzs+v7xMOVvPdgFKq in this case after the credentials. 
- 3. Copy the aws_session_token i.e. the remainings.
- 4. Now give this command $ aws configure and provide the access_key_id and aws_secret_access_key
 - 5. Copy aws_session_token into ~/.aws/credentials file at the end like - aws_session_token=[$token values] - 6. Now send your instance SSH public to the required EC2 instance with the following command, [ make sure you have configured EC2 instance connect configured for reference: https://hibern8e.blogspot.com/2020/12/ubuntu-ec2-instance-connect-for-cli-ssh.html ]
 - 7. aws ec2-instance-connect send-ssh-public-key \ - --instance-id yourinstanceID \ - --availability-zone yourzone \ - --instance-os-user yourusername \ - --ssh-public-key file://~/.ssh/my_rsa_key.pub 
- 8. now connect to the instance using the below command 
- 9. ssh -i ~/.ssh/my_rsa_key.pub ragesh@ip -p port number 
 
 
Comments