forked from miquella/ssh-proxy-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroot_cli.go
66 lines (50 loc) · 1.83 KB
/
root_cli.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"os"
"github.com/spf13/cobra"
"github.com/miquella/ssh-proxy-agent/lib/proxyagent"
)
// RootCLI is the root command for the `ssh-proxy-agent` entrypoint
var RootCLI = &cobra.Command{
Use: "ssh-proxy-agent",
Short: "SSH-Proxy-Agent creates an ssh-agent proxy",
RunE: shellRunE,
SilenceUsage: true,
Version: "0.7.unstable",
}
var doctor bool
var interactive bool
var agentConfig = proxyagent.AgentConfig{}
var shell = proxyagent.Spawn{}
func init() {
RootCLI.Flags().BoolVarP(&interactive, "shell", "l", false, "spawn an interactive shell")
RootCLI.Flags().BoolVarP(&doctor, "doctor", "", false, "verify if a spawned session is running correctly")
RootCLI.Flags().BoolVar(&agentConfig.GenerateRSAKey, "generate-key", false, "generate RSA key pair (default: false)")
RootCLI.Flags().BoolVar(&agentConfig.DisableProxy, "no-proxy", false, "disable forwarding to an upstream agent (default: false)")
RootCLI.Flags().BoolVar(&agentConfig.ExposeUnsigned, "expose-unsigned", false, "expose both signed and unsigned versions of keys when signing is enabled (default: false)")
RootCLI.Flags().StringSliceVar(&agentConfig.ValidPrincipals, "valid-principals", []string{proxyagent.DefaultPrincipal()}, "valid principals for Vault key signing")
RootCLI.Flags().StringVar(&agentConfig.VaultSigningUrl, "vault-signing-url", "", "HashiCorp Vault url to sign SSH keys")
}
func shellRunE(cmd *cobra.Command, args []string) error {
if doctor {
proxyagent.Doctor()
return nil
}
if !interactive {
return cmd.Usage()
}
var err error
shell.Agent, err = proxyagent.SetupAgent(agentConfig)
if err != nil {
return err
}
shell.Command = loginShellCommand()
return shell.Run()
}
func loginShellCommand() []string {
shell := os.Getenv("SHELL")
if shell == "" {
shell = "/bin/sh"
}
return []string{shell, "--login"}
}