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

Added ssh key import feature in "key import" #52

Merged
merged 1 commit into from
Mar 23, 2018
Merged

Added ssh key import feature in "key import" #52

merged 1 commit into from
Mar 23, 2018

Conversation

adyxax
Copy link

@adyxax adyxax commented Mar 11, 2018

What this PR does / why we need it:
This PR allows admins to import an existing ssh private key (typically needed when testing sshportal in an existing environment).

Special notes for your reviewer:
I don’t know if this feature is wanted, but we found it quite useful. I couldn't find a contributing guide, but I'm of course open to any code change that may be needed to properly integrate this code in the project.

@moul
Copy link
Owner

moul commented Mar 11, 2018

Nice, can you add a small usage example somewhere (readme, example dir or in this PR) ?

Thanks :)

@adyxax
Copy link
Author

adyxax commented Mar 12, 2018

I am glad the feature is of interest to you.

I added a small change to the readme to document the "key import", here is an example run :

julien@andromeda:~/prog/go/src/github.com/moul/sshportal$ ssh -p2222 localhost -l julien


    __________ _____           __       __
   / __/ __/ // / _ \___  ____/ /____ _/ /
  _\ \_\ \/ _  / ___/ _ \/ __/ __/ _ '/ /
 /___/___/_//_/_/   \___/_/  \__/\_,_/_/


config> key import --name="test"
Paste your key and end with a blank line> -----BEGIN RSA PRIVATE KEY-----
Paste your key and end with a blank line> MIIEogIBAAKCAQEAv2yatLaFMtuBYZd3Cmnn9VcItANwT2AOxX18DNwX4evYtOEx
Paste your key and end with a blank line> jyEBkcBN+zAhbi6mClHUNfZSs+jQTIblpdzjDSxHHlRG3j/03U5Wa3fkXC4xKm1u
Paste your key and end with a blank line> eHSG+OC6QpoYtaEPyG9RZ11Zn/IWS6FPgmL8ysAjwzqU+CSO5qdM3nHXJI9w1U3C
Paste your key and end with a blank line> x8hQlNf1052oZihHe0CYx+5j+orUGA0+5qoiwgz9bIZKFTKSN22+oAaTIIw1nBFk
Paste your key and end with a blank line> CvxoauHopqIqvmhrRozGxVzNFhCJCxTaJaO3CV0sdSlFtYQjgSz3ZQEbIvg8+L9S
Paste your key and end with a blank line> 9TCNn8mgHaaEqQN6zVS2eDBm6cnIqtkcozpA5wIDAQABAoIBADW+aDEUjZEZz9l2
Paste your key and end with a blank line> jRV/ZoCbTvY7gOzIK12HPazenlXvwYgHMcLdoXMqarp7aOdmcXe0QcBkyBN66gCS
Paste your key and end with a blank line> XyeSPK0WIWGCh+MeUcFQnTLPFm5LCcK/tqRbEwoNDj5kxUs5TRUZK+G5c9BUR640
Paste your key and end with a blank line> O/5/jDngeCn36JtCqFxZ3FsX2y+IGeAHOLrMsfop4N1lIGDC8QsRazGVK6Z/bkUX
Paste your key and end with a blank line> Bn/QnPOIUBGjYNn490mNZLFrZ29XPXtvEA5vkiAsKCpQeMqT/AO/zL+mVdWJ4k7o
Paste your key and end with a blank line> ckXE2gysJTqtFnTBv9CT2BiWhXr2D0qXiGgu4H6xYUbLUVLMVINpyBytb7NDL983
Paste your key and end with a blank line> bxkbrgECgYEA5hthgOYGA16uVzhLpq8tdKI0wAoKQgMYlocfhCL1qRL62PPeUOdv
Paste your key and end with a blank line> GdfO5ohdF86SHhp/uAHa6VioKc1JWP4om4FhDn8ZnxrBaDqxsPP0YyshRSe8Ge4I
Paste your key and end with a blank line> m7Om1FFckUMbF6cz1+fjfU5y5hut+k/pbNE9eih1iIM4OfnXTcoRZh8CgYEA1Pbn
Paste your key and end with a blank line> A/fxwxlH9qiX79L7d2IjlCLzTv5qYgLUotmk8A3UNQdM5EpX7sQsq5ZTNX6EYEMQ
Paste your key and end with a blank line> Zivc7NIjXl6Rw5Koyorn0TbcCRYGq9J2u+sEz9cGOnaTqqP5PaRKW3JFSfcTw86O
Paste your key and end with a blank line> VTZh3kO7ypbxhtAB6UIDfFU3zXkBQ2qPohis/DkCgYANGnoO8QpensGmzdnhABDC
Paste your key and end with a blank line> l4oRdYDoCW0ZBVDSIXuDyUTnnduHF+bHvfZWQmWquWSwuimTvOdOanIJD1uh6bc+
Paste your key and end with a blank line> Q7vXK322BbwFx3He9cVw8D/QxFZ904RB+ZUCei+fRgcA7dCR9u6JcDIy0Fiz7GEK
Paste your key and end with a blank line> hU/O6QboYzCMfKG6GEutWQKBgCzzZHWQ+yWsC2WD1nYXeV6Mh2f4LJUK3FeNs2Yg
Paste your key and end with a blank line> PFEzCgybWt6A1qieHbOmCjArYTOUVDzMm1gdTrvXiDrYlOoTgbTGOJFuZcAUr10g
Paste your key and end with a blank line> 0SYxg64JY0fMTop1SACfUQK4tSJKUf6oeOXaNCQh0h8bfpvGhEfVEO880EhzkJet
Paste your key and end with a blank line> T635AoGAR1T58battIKUn0PO0afvU1zgE/mFNYn2PFuBTHdDJxrBOp64lV76s8x5
Paste your key and end with a blank line> jiYPjSOIQ0JGzUkDhvwIIZg0pu7FevLlBbK6AiufU59wT2dsCMgg46VafpPpn9VB
Paste your key and end with a blank line> hsVwCYFurjhPeVNNWzsK39KW8g0AC4MIOTvm607Pv1g6PxP2v8E=
Paste your key and end with a blank line> -----END RSA PRIVATE KEY-----
Paste your key and end with a blank line>
11
config> key ls
  ID |  NAME   | TYPE | LENGTH | HOSTS |    UPDATED     |    CREATED     |       COMMENT
+----+---------+------+--------+-------+----------------+----------------+----------------------
  11 | test    | rsa  |   2048 |     0 | 10 seconds ago | 10 seconds ago |
   7 | adyxax  | rsa  |   4096 |     1 | 20 hours ago   | 20 hours ago   |
   2 | host    | rsa  |   2048 |     0 | 1 day ago      | 1 day ago      | created by sshportal
   1 | default | rsa  |   2048 |     0 | 1 day ago      | 1 day ago      | created by sshportal
Total: 4 keys.
config>

I wanted to add this run to the integration tests but couldn't figure out how to properly run thos tests : the testserver keeps crashing shortly after the docker-compose up on my setup with the following error :

julien@XXX:~/prog/go/src/github.com/moul/sshportal/examples/integration$ docker-compose up testserver
Recreating integration_testserver_1 ...
Recreating integration_testserver_1 ... done
Attaching to integration_testserver_1
testserver_1  | 2018/03/12 13:19:31 starting ssh server on port 2222...
testserver_1  | panic: runtime error: slice bounds out of range
testserver_1  |
testserver_1  | goroutine 37 [running]:
testserver_1  | main.testServer.func1(0x9f8aa0, 0xc4202be840)
testserver_1  |         /go/src/github.com/moul/sshportal/hidden.go:34 +0x9a4
testserver_1  | github.com/moul/sshportal/vendor/github.com/gliderlabs/ssh.(*session).handleRequests.func1(0xc4202be840)
testserver_1  |         /go/src/github.com/moul/sshportal/vendor/github.com/gliderlabs/ssh/session.go:219 +0x3b
testserver_1  | created by github.com/moul/sshportal/vendor/github.com/gliderlabs/ssh.(*session).handleRequests
testserver_1  |         /go/src/github.com/moul/sshportal/vendor/github.com/gliderlabs/ssh/session.go:218 +0x1ff
integration_testserver_1 exited with code 2

With some debugging I managed to isolate the fact that the healthcheck call from docker is the cause of the problem, the testserver sees it without arguments and the s.Command()[1:] on hidden.go:33 fails.

@ivomarino
Copy link

useful feature, thanks, when will this be merged? thanks

@adyxax
Copy link
Author

adyxax commented Mar 23, 2018

I updated my pull request by rebasing on top of the last commits.

@moul moul merged commit 84d77d0 into moul:master Mar 23, 2018
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