Received OTK in SSH client. Forked SSH process from CLI. Added utility file for SSH.

This commit is contained in:
Vishal Nayak
2015-06-17 20:33:03 -04:00
parent fb866f9059
commit fa83fe89f0
6 changed files with 135 additions and 5 deletions

View File

@@ -2,8 +2,12 @@ package command
import (
"fmt"
"io/ioutil"
"log"
"os"
"os/exec"
"strings"
"syscall"
)
type SshCommand struct {
@@ -11,6 +15,7 @@ type SshCommand struct {
}
func (c *SshCommand) Run(args []string) int {
log.SetFlags(log.LstdFlags | log.Lshortfile)
log.Printf("Vishal: SshCommand.Run: args:%#v len(args):%d\n", args, len(args))
flags := c.Meta.FlagSet("ssh", FlagSetDefault)
flags.Usage = func() { c.Ui.Error(c.Help()) }
@@ -31,9 +36,22 @@ func (c *SshCommand) Run(args []string) int {
return 2
}
log.Printf("Vishal: client.Sys().Ssh() returned! OTK:%#v\n", sshOneTimeKey)
log.Printf("Vishal: command.ssh.Run returned! OTK:%#v\n", sshOneTimeKey)
err = ioutil.WriteFile("./vault_ssh_otk_"+args[0]+".pem", []byte(sshOneTimeKey.Key), 0400)
//if sshOneTimeKey is empty, fail
//Establish a session directly from client to the target using the one time key received without making the vault server the middle guy:w
sshBinary, err := exec.LookPath("ssh")
if err != nil {
log.Printf("ssh binary not found in PATH\n")
}
sshEnv := os.Environ()
sshCmdArgs := []string{"ssh", "-i", "vault_ssh_otk_" + args[0] + ".pem", "vishal@localhost"}
if err := syscall.Exec(sshBinary, sshCmdArgs, sshEnv); err != nil {
log.Printf("Execution failed: sshCommand: " + err.Error())
}
return 0
}