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

Use relevant SSHProxyAddr after Login #2657

Merged
merged 1 commit into from
Apr 24, 2019
Merged

Use relevant SSHProxyAddr after Login #2657

merged 1 commit into from
Apr 24, 2019

Conversation

klizhentas
Copy link
Contributor

Login could change the SSH proxy address based
on the information from "ping" endpoint

The function ConnectToProxy was saving
old version of the variable and kept using
it during login procedure.

This commit fixes that so the relevant
variable is always referenced.

@klizhentas klizhentas requested review from r0mant and russjones April 17, 2019 01:07
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.

Looks fine, can you add a comment to the tc.Login line in connectToProxy that it has a side effect of updating the proxy address?

Ideally we'd factor out the applyProxySettings from Login and into connectToProxy so it's more clear, but I'm not sure if that's safe for all code paths.

@klizhentas
Copy link
Contributor Author

@russjones updated comment line

@klizhentas klizhentas force-pushed the sasha/tsh branch 3 times, most recently from 29fdbac to 1a73408 Compare April 23, 2019 16:52
@klizhentas klizhentas requested review from r0mant and russjones April 23, 2019 23:50
@klizhentas
Copy link
Contributor Author

@russjones @r0mant I had to introduce a concept of "alias" proxy names, otherwise in some cases (when proxy name does not match advertised web_proxy or ssh_proxy addr) tsh did not work as expected.

bytes, err := yaml.Marshal(&cp)
if err != nil {
return trace.Wrap(err)
}
if err = ioutil.WriteFile(filePath, bytes, 0660); err != nil {
return trace.Wrap(err)
}
if profileAliasPath != "" && filepath.Base(profileAliasPath) != filepath.Base(filePath) {
os.Remove(profileAliasPath)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Unchecked error.

Login could change the SSH proxy address based
on the information from "ping" endpoint

The function ConnectToProxy was saving
old version of the variable and kept using
it during login procedure.

This commit fixes that so the relevant
variable is always referenced.
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.

Logic looks fine, some restructuring would help clear things up further.

@@ -398,7 +398,7 @@ func onLogin(cf *CLIConf) {
// but cluster is specified, treat this as selecting a new cluster
// for the same proxy
case (cf.Proxy == "" || host(cf.Proxy) == host(profile.ProxyURL.Host)) && cf.SiteName != "":
tc.SaveProfile("")
tc.SaveProfile("", "")
Copy link
Contributor

@russjones russjones Apr 24, 2019

Choose a reason for hiding this comment

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

SaveProfile should take a struct of params, SaveProfile("", "") is not clear what's being saved.

This would also simply things when no alias is needed (see other comment), because you could do things like:

tc.SaveProfile(&profile{
   path: "/path/to/profile",
})

@@ -535,6 +538,11 @@ func (c *Config) SaveProfile(profileDir string, profileOptions ...ProfileOptions
profileDir = FullProfilePath(profileDir)
profilePath := path.Join(profileDir, webProxyHost) + ".yaml"

profileAliasPath := ""
Copy link
Contributor

Choose a reason for hiding this comment

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

Proxy alias logic is split in two different places in SaveProfile and SaveTo. However, SaveTo appears to mainly be working with files on disk where as SaveProfile is updating configuration.

Moving that configuration logic from SaveTo into SaveProfile would simply things. Something like the following.

// Set alias path if it differs from the address advertised by Teleport.
aliasPath = ""
if profilePath != profileAliasPath {
    aliasPath = profileAliasPath
}

err := SaveTo(&profile{
    path: profilePath,
    alias: aliasPath,
    options: ...,
})

Then SaveTo once again only works with files on disk:

// If a alias has been provided, update the symlink to to point to the profile
// that Teleport advertises.
if p.alias != "" {
    if err := os.Remove(profileAliasPath); err != nil {
        log.Warningf("Failed to remove symlink alias: %v", err)
    }

    err := os.Symlink(filepath.Base(filePath), profileAliasPath)
    if err != nil {
        log.Warningf("Failed to create profile alias: %v", err)
    }
}

@@ -446,6 +446,9 @@ func Status(profileDir string, proxyHost string) (*ProfileStatus, []*ProfileStat
if file.IsDir() {
continue
}
if file.Mode()&os.ModeSymlink != 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Comment explaining why symlinks are skipped because it's not clear from reading this function that you are skipping over aliases.

// Skip over symlinks (aliases) to prevent double printing of profiles.

@klizhentas
Copy link
Contributor Author

ok, I will refactor in the master, will keep backport relatively small.

@klizhentas klizhentas merged commit 1549e72 into branch/3.2 Apr 24, 2019
@klizhentas klizhentas deleted the sasha/tsh branch April 24, 2019 18:11
klizhentas added a commit that referenced this pull request Apr 24, 2019
Login could change the SSH proxy address based
on the information from "ping" endpoint

The function ConnectToProxy was saving
old version of the variable and kept using
it during login procedure.

This commit fixes that so the relevant
variable is always referenced.
klizhentas added a commit that referenced this pull request Apr 24, 2019
Login could change the SSH proxy address based
on the information from "ping" endpoint

The function ConnectToProxy was saving
old version of the variable and kept using
it during login procedure.

This commit fixes that so the relevant
variable is always referenced.
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.

3 participants