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,scp: implement ssh and scp clients #619

Closed
wants to merge 17 commits into from
Closed

ssh,scp: implement ssh and scp clients #619

wants to merge 17 commits into from

Conversation

xmudrii
Copy link
Member

@xmudrii xmudrii commented Apr 8, 2018

ssh and scp packages

Closes #609

This PR implements the ssh package used to handle SSH connections. It comes with a kubicorn ssh <cluster-name> CLI command for connecting to the master instance of the cluster.

Beside ssh package and command, this PR refactors the scp package to utilize the new ssh package, as well as implements the WriteBytes function used to send a file to the cluster.

Implementation of the PR

Currently, ssh package is used only for kubicorn ssh command.
The scp package is used to download the VPN credentials, if VPN is enabled for DigitalOcean clusters.

Resolving agent problems

This ssh implementation is not dependent on the agent package we're using currently. Instead, it implements the auth package which handles SSH authentication.

The default authentication method is password authentication. As we're connecting only one time (ensured by the Connect function) and then we're just reusing the same connection, user needs to enter password only once.

Beside password authentication, users can also use the system SSH agent. To use the system agent, it's required to set the KUBICORN_SSH_AGENT environment variable (documented in envar.md). If the variable is set, kubicorn will try to use system SSH agent. If error occurs (e.g. the system agent is not present or the key is not present in the agent), kubicorn will resort to the password authentication with the appropriate error message and recommended steps to fix the issue.

Notes

  • The kubicorn ssh command supports only SSH-ing to the master.

Parts needing attention

Steps before merging PR

We want to make this actually works. I would love @kris-nova to test this before we merge the PR, so we're sure it works as intended. The easiest way to test the PR is to use the kubicorn ssh command.

Steps after merging PR

To make this PR cleaner and easier to review, it only implements the ssh and scp packages without implementing them in the code (beside for DigitalOcean VPN). When the PR is merged, we need to implement it for the kubeconfig and initapi packages.

After merging the PR, we can make the following changes to further improve the packages:

  • Make the kubicorn ssh command able to SSH to all nodes in the cluster.
  • Implement agent forwarding (probably hidden behind an environment variable). Helpful if you want to be able to use your agent/SSH keys from the cluster.
  • Delete the agent package when we implement the ssh package in all places.
  • Possibly integrate with teleport and teleconsole packages and offer profiles with bastion (issue teleconsole and teleport #533).

@xmudrii xmudrii self-assigned this Apr 8, 2018
cmd/ssh.go Outdated
ip = cluster.ProviderConfig().KubernetesAPI.Endpoint
}

client := ssh.NewSSHClient(ip, "22", "root")
Copy link
Member

Choose a reason for hiding this comment

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

Should we hard code this? I know the user and port is stored in the cluster API...

Copy link
Member Author

Choose a reason for hiding this comment

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

It should be better now :)

@xmudrii xmudrii changed the title [WIP] ssh: implement ssh client [WIP] ssh,scp: implement ssh and scp clients Apr 13, 2018
@xmudrii xmudrii changed the title [WIP] ssh,scp: implement ssh and scp clients ssh,scp: implement ssh and scp clients Apr 13, 2018
@xmudrii xmudrii requested a review from krisnova April 13, 2018 10:09
@xmudrii
Copy link
Member Author

xmudrii commented Apr 13, 2018

@kris-nova ready for review

)

// SystemAgent returns system agent if it exists.
func SystemAgent() agent.Agent {
Copy link
Member

Choose a reason for hiding this comment

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

So wondering how the workflow would work here..

Should we return an error if the system agent doesnt exist?
Should we change the function name to SystemAgentIfExists() or something?

Just think we could be a little more strict here is all

Copy link
Member Author

Choose a reason for hiding this comment

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

Should we return an error if the system agent doesnt exist?

It could be useful for debugging purposes, so I added it.

Should we change the function name to SystemAgentIfExists() or something?

Sounds better than SystemAgent. Updated.

return nil, nil, fmt.Errorf("Unable to connect to SSH: %v", err)
}

masterVpnIP, err := scp.ReadBytes(client, "/tmp/.ip")
Copy link
Member

Choose a reason for hiding this comment

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

Do we want to pass in the client every time we call ReadBytes or do we want to cache it in memory somewhere and then tell it which file to read from?

Copy link
Member Author

Choose a reason for hiding this comment

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

I guess we can encapsulate it into a struct. I've updated the SCP package to try to fix this. Let me know is it any better.

@xmudrii xmudrii removed their assignment Jul 30, 2018
@krisnova krisnova closed this Jul 13, 2023
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.

kubicorn ssh cli command
2 participants