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

tsh proxy aws fails after one minute when using per-session MFA #44475

Closed
webvictim opened this issue Jul 19, 2024 · 4 comments
Closed

tsh proxy aws fails after one minute when using per-session MFA #44475

webvictim opened this issue Jul 19, 2024 · 4 comments
Assignees
Labels
aws Used for AWS Related Issues. bug mfa Issues related to Multi Factor Authentication tsh tsh - Teleport's command line tool for logging into nodes running Teleport. ux

Comments

@webvictim
Copy link
Contributor

webvictim commented Jul 19, 2024

Expected behavior: tsh app login <aws-console-app-name> should give you a certificate with a useful lifetime when using per-session MFA.

Current behavior: tsh proxy aws stops working after 1 minute, because the certificate issued is only valid for that long.

Logs:

# log into app, get prompted for MFA as expected
gus@apollo:~ % tsh app login awsconsole --aws-role PurpleAWSEC2FullAccess
MFA is required to access Application "awsconsole"
Tap any security key
Detected security key tap
Logged into AWS app "awsconsole".

Your IAM role:
  arn:aws:iam::<account>:role/PurpleAWSEC2FullAccess

Example AWS CLI command:
  tsh aws s3 ls

Or start a local proxy:
  tsh proxy aws --app awsconsole

# start local proxy in background
gus@apollo:~ % tsh proxy aws &
[1] 10617

gus@apollo:~ [fg: 1] % Started AWS proxy on http://127.0.0.1:54430.
To avoid port randomization, you can choose the listening port using the --port flag.

Use the following credentials and HTTPS proxy setting to connect to the proxy:
  export AWS_ACCESS_KEY_ID=ce940091...
  export AWS_SECRET_ACCESS_KEY=c0e32fb5...
  export AWS_CA_BUNDLE=/Users/gus/.tsh/keys/teleport.example.com/[email protected]/purple/awsconsole-localca.pem
  export HTTPS_PROXY=http://127.0.0.1:54430

# copy variables and re-paste into terminal
# (super annoying UX btw, we should support `tsh proxy aws --exec` or `--output aws-creds`
# so you can source the file easily)
gus@apollo:~ [fg: 1] %   export AWS_ACCESS_KEY_ID=ce940091...
  export AWS_SECRET_ACCESS_KEY=c0e32fb5...
  export AWS_CA_BUNDLE=/Users/gus/.tsh/keys/teleport.example.com/[email protected]/purple/awsconsole-localca.pem
  export HTTPS_PROXY=http://127.0.0.1:54430

# run command against ec2, works
gus@apollo:~ [fg: 1] % aws ec2 describe-instances --no-cli-pager
{
    "Reservations": [
        {
            "Groups": [],
            "Instances": [
                {
                    "AmiLaunchIndex": 0,
                    "ImageId": "ami-05912b6333beaa478",
                    "InstanceId": "i-08b794f12128dd450",
                    "InstanceType": "t3.medium",
<snip>

# wait a minute
gus@apollo:~ [fg: 1] % sleep 60

# re-run command, fails
gus@apollo:~ [fg: 1] % aws ec2 describe-instances

SSL validation failed for https://ec2.us-east-1.amazonaws.com/ [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1006)

# kill proxy
gus@apollo:~ [fg: 1] % fg
[1]  + 10617 running    tsh proxy aws
^C

# try to reauthenticate, fails due to HTTPS_PROXY being set
gus@apollo:~ % tsh app login awsconsole --aws-role PurpleAWSEC2FullAccess
ERROR: connection error: desc = "transport: Error while dialing: failed to dial: unable to establish proxy stream\n\trpc error: code = Unavailable desc = connection error: desc = \"transport: Error while dialing: dial tcp 127.0.0.1:54430: connect: connection refused\""

# angrily unset
gus@apollo:~ % unset HTTPS_PROXY

# reauthenticate again, provide MFA again
gus@apollo:~ % tsh app login awsconsole --aws-role PurpleAWSEC2FullAccess
MFA is required to access Application "awsconsole"
Tap any security key
Detected security key tap
Logged into AWS app "awsconsole".

Your IAM role:
  arn:aws:iam::<account>:role/PurpleAWSEC2FullAccess

Example AWS CLI command:
  tsh aws s3 ls

Or start a local proxy:
  tsh proxy aws --app awsconsole

# run proxy in background again
gus@apollo:~ % tsh proxy aws &
[1] 24772

gus@apollo:~ [fg: 1] % Started AWS proxy on http://127.0.0.1:54514.
To avoid port randomization, you can choose the listening port using the --port flag.

Use the following credentials and HTTPS proxy setting to connect to the proxy:
  export AWS_ACCESS_KEY_ID=17794ced...
  export AWS_SECRET_ACCESS_KEY=cc9d0564...
  export AWS_CA_BUNDLE=/Users/gus/.tsh/keys/teleport.example.com/[email protected]/purple/awsconsole-localca.pem
  export HTTPS_PROXY=http://127.0.0.1:54514

# copy/paste creds again, etc etc...

Bug details:

  • Teleport version: 16.0.4
@webvictim webvictim added bug ux tsh tsh - Teleport's command line tool for logging into nodes running Teleport. aws Used for AWS Related Issues. mfa Issues related to Multi Factor Authentication developer-experience Addressing these issues will improve the experience of developers working on Teleport and removed developer-experience Addressing these issues will improve the experience of developers working on Teleport labels Jul 19, 2024
@Joerger
Copy link
Contributor

Joerger commented Jul 19, 2024

This is working as expected - tsh app login creates MFA verified creds in the filesystem, so they shouldn't live longer than 1 minute. I added logic that allow the user to login and then tsh proxy app or tsh aws which opens a proxy under the hood, only prompting you for tap after 1 minute once it's needed. The second tap will result in longer lived certs stored in memory. Should I remove the first case and always promp for MFA immediately instea, ignoring previous tsh app logins?

Edit: relooked at the debug logs, is tsh proxy aws not prompting you for tap after a minute?

@webvictim
Copy link
Contributor Author

webvictim commented Jul 19, 2024

Correct, I don't get a prompt - the operation just fails. Maybe because I'm not running it in the foreground?

I realised I'm using tsh 16.0.1 if that makes any difference. I don't think I saw anything in the changelog.

@Joerger
Copy link
Contributor

Joerger commented Jul 20, 2024

Ah I should have added a changelog entry, I thought it was going to make it into v16.0.0 under the MFA for App access umbrella - #40985. It made it into v16.0.2 instead. Note you may run into this other issue before it's fixed.

@webvictim
Copy link
Contributor Author

Got it - I'll update, retest, and then reopen the issue if anything new is broken. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aws Used for AWS Related Issues. bug mfa Issues related to Multi Factor Authentication tsh tsh - Teleport's command line tool for logging into nodes running Teleport. ux
Projects
None yet
Development

No branches or pull requests

2 participants