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

ssh: fix relogin with jumphosts #6213

Merged
merged 4 commits into from
Mar 30, 2021
Merged

ssh: fix relogin with jumphosts #6213

merged 4 commits into from
Mar 30, 2021

Conversation

awly
Copy link
Contributor

@awly awly commented Mar 30, 2021

Several fixes to make tsh ssh -J leaf.proxy.com work if the root cert
is missing/expired.

@awly awly requested a review from andrejtokarcik March 30, 2021 00:14
@awly
Copy link
Contributor Author

awly commented Mar 30, 2021

@andrejtokarcik after a bit of tweaking, this change makes the following work:

# simulate expired session
$ tsh login --proxy=root.example.com --insecure
...
$ rm ~/.tsh/keys/root.example.com/awly-ssh/*

$ tsh ssh --insecure -J leaf.example.com:3023 leaf-node

I'm not confident that all of the changes are safe though, WDYT?

@awly awly force-pushed the andrew/jumphost-relogin-fix branch from 8f45bc1 to 66f8061 Compare March 30, 2021 17:43
@awly awly requested a review from andrejtokarcik March 30, 2021 17:48
Andrew Lytvynov added 2 commits March 30, 2021 10:48
Several fixes to make `tsh ssh -J leaf.proxy.com` work if the root cert
is missing/expired.
Correctly parse trusted CAs on GetKey.
Move retry without jumphosts from relogin to UpdateClusterCAs.
@awly awly force-pushed the andrew/jumphost-relogin-fix branch from 66f8061 to 0d12ddd Compare March 30, 2021 17:48
It doesn't seem to break anything.
@awly awly force-pushed the andrew/jumphost-relogin-fix branch from 1f632ef to 1097859 Compare March 30, 2021 18:08
@awly awly marked this pull request as ready for review March 30, 2021 18:09
@awly awly added this to the 6.1 milestone Mar 30, 2021
Copy link
Collaborator

@r0mant r0mant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code lgtm but a question about the removed block.

Comment on lines -472 to -480
// Override client's auth methods, current cluster and user name
authMethod, err := key.AsAuthMethod()
if err != nil {
return trace.Wrap(err)
}
// After successful login we have local agent updated with latest
// and greatest auth information, setup client to try only this new
// method fetched from key, to isolate the retry
tc.Config.AuthMethods = []ssh.AuthMethod{authMethod}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This messes up the relogin flow.

tc.Config.AuthMethods is used as the first choice when connecting to a proxy over SSH.
If you were originally connecting to a leaf cluster (as in tsh ssh -J leaf.proxy.com somenode) and relogin kicked in, you're be logged in via the root cluster (which is correct).
But after you've re-logged through the root cluster tc.Config.AuthMethods would have an SSH cert for the root cluster, not for the leaf.
The cert caching and loading logic that @andrejtokarcik added correctly adds a leaf cert into the localAgent, but it gets overriden by tc.Config.AuthMethods.

Copy link
Contributor

@russjones russjones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bot.

@awly awly enabled auto-merge (rebase) March 30, 2021 21:37
@awly awly disabled auto-merge March 30, 2021 21:37
@awly awly enabled auto-merge (squash) March 30, 2021 21:37
@awly awly merged commit fffe215 into master Mar 30, 2021
@awly awly deleted the andrew/jumphost-relogin-fix branch March 30, 2021 21:50
awly pushed a commit that referenced this pull request Mar 30, 2021
* ssh: fix relogin with jumphosts

Several fixes to make `tsh ssh -J leaf.proxy.com` work if the root cert
is missing/expired.

* Address review feedback

Correctly parse trusted CAs on GetKey.
Move retry without jumphosts from relogin to UpdateClusterCAs.

* Remove TelpoertClient.AuthMethods override on relogin

It doesn't seem to break anything.
awly pushed a commit that referenced this pull request Mar 30, 2021
* ssh: fix relogin with jumphosts

Several fixes to make `tsh ssh -J leaf.proxy.com` work if the root cert
is missing/expired.

* Address review feedback

Correctly parse trusted CAs on GetKey.
Move retry without jumphosts from relogin to UpdateClusterCAs.

* Remove TelpoertClient.AuthMethods override on relogin

It doesn't seem to break anything.
pierrebeaucamp pushed a commit that referenced this pull request Mar 31, 2021
…e/dynamodb-gsi-autoscaling

* 'master' of github.com:gravitational/teleport: (41 commits)
  Refactor ssh.ClientConfig used by tctl and API clients to use the first valid principal as User.
  Update Architecture Overview With Link To User Roles (#6224)
  Add `lint-api` target and fix lint errors (#6169)
  ssh: fix relogin with jumphosts (#6213)
  drone: use emptyDir for /var/lib/docker filesystem and prevent repetitive docker pulls (#6145)
  Remove ARM64 FIPS builds (#6236)
  tsh Profile SSH certs fix (#6214)
  mfa: fix gRPC unimplemented check in cert reissue
  Open Sources Access Controls Docs (#6188) (#6217)
  add PAM environment with interpolation support
  Cache per-cluster SSH certificates under ~/.tsh (#5938)
  add special resource type for access plugin data
  Enable DynamoDB autoscaling on global secondary indices (#6112)
  darwin fips builds (#5866)
  kube: add kubernetes_labels to role JSON schema
  mfa: send username instead of SSH login name in MFA cert request
  fix nil slice bug
  RFD 16: Add a section on `tctl rm` resetting resources back to defaults (#5673)
  Update application access docs (#6055) (#6137)
  Bump linux FIPS builds to use go1.16.2b7 release (#6143)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants