Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support using MFA devices for AWS CLI commands #28

Merged
merged 1 commit into from
Jun 17, 2021

Conversation

toricls
Copy link
Contributor

@toricls toricls commented Jun 16, 2021

This PR implements MFA support for AWS CLI commands and closes #27 🚀

image

It reads the AWS CLI configuration (by aws configure get mfa_serial) to detect if it needs an MFA code to proceed. The script also accepts an environment variable AWS_MFA_SERIAL to set the ARN of the MFA device, instead of the AWS CLI configuration.

Try it with AWS_PROFILE=<your-profile-here> bash <( curl -Ls https://raw.github.com/toricls/amazon-ecs-exec-checker/support-mfa/check-ecs-exec.sh ) <ecs-cluster-name> <ecs-task-id>.

@toricls toricls added the enhancement New feature or request label Jun 16, 2021
@toricls toricls mentioned this pull request Jun 16, 2021
@deleugpn
Copy link

I'm not sure if I'm missing something

sh-4.2# AWS_PROFILE=customergauge_dta sh check-ecs-exec.sh Fargate 95c18c8a48e847dc94cdab124302e191
-------------------------------------------------------------
Prerequisites for check-ecs-exec.sh v0.5
-------------------------------------------------------------
  jq      | OK (/usr/bin/jq)
  AWS CLI | OK (/usr/local/bin/aws)

Type your MFA code from "arn:aws:iam::############:mfa/marco.deleu": 00000
Enter MFA code for arn:aws:iam::############:mfa/marco.deleu:

An error occurred (AccessDenied) when calling the GetSessionToken operation: Cannot call GetSessionToken with session credentials

Notice how I got asked twice, the first one numbers are visible and the 2nd one they're not.

@toricls
Copy link
Contributor Author

toricls commented Jun 17, 2021

Thanks @deleugpn for checking!

I'm still not sure about the cause of the error, but could you run that again with the following command to make sure you're using the latest script?

AWS_PROFILE=customergauge_dta bash <( curl -Ls https://raw.github.com/toricls/amazon-ecs-exec-checker/support-mfa/check-ecs-exec.sh ) Fargate 95c18c8a48e847dc94cdab124302e191

@deleugpn
Copy link

That command seems to be broken for me, so I used that link to download the file and run it

sh-4.2# AWS_PROFILE=customergauge_dta bash <( curl -Ls https://raw.github.com/toricls/amazon-ecs-exec-checker/support-mfa/check-ecs-exec.sh ) Fargate 95c18c8a48e847dc94cdab124302e191
sh: syntax error near unexpected token `('
sh-4.2#
sh-4.2#
sh-4.2# curl https://raw.github.com/toricls/amazon-ecs-exec-checker/support-mfa/check-ecs-exec.sh > check-ecs-exec.sh
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 27104  100 27104    0     0   199k      0 --:--:-- --:--:-- --:--:--  197k
sh-4.2# chmod 777 check-ecs-exec.sh
sh-4.2# AWS_PROFILE=customergauge_dta sh check-ecs-exec.sh Fargate 95c18c8a48e847dc94cdab124302e191
-------------------------------------------------------------
Prerequisites for check-ecs-exec.sh v0.5
-------------------------------------------------------------
  jq      | OK (/usr/bin/jq)
  AWS CLI | OK (/usr/local/bin/aws)

Type your MFA code from "arn:aws:iam::##########:mfa/marco.deleu": 000000
Enter MFA code for arn:aws:iam::::##########:mfa/marco.deleu:

An error occurred (AccessDenied) when calling the GetSessionToken operation: Cannot call GetSessionToken with session credentials

@toricls toricls force-pushed the support-mfa branch 2 times, most recently from a6ec79a to 1fb4641 Compare June 17, 2021 08:54
@toricls
Copy link
Contributor Author

toricls commented Jun 17, 2021

Thank you! I fixed an issue that the script couldn't handle an MFA + AssumeRole case correctly, so hope it works this time! 🙏

@deleugpn
Copy link

Awesome! This seems to work great!

@toricls toricls merged commit 1a5e57c into aws-containers:main Jun 17, 2021
@toricls toricls deleted the support-mfa branch June 17, 2021 22:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for MFA
2 participants