cmd

package
Version: v0.0.0-...-3764ea7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 7, 2021 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultWindowsAdhocAgentListener = `\\.\pipe\sshi-adhoc-%s`
)

Variables

View Source
var AddCaCmd = &cobra.Command{
	Use:   "add [caKeyFile]",
	Short: "Add CA private key from file",
	Args:  cobra.MaximumNArgs(1),
	RunE: func(cmd *cobra.Command, args []string) error {
		if len(args) > 0 {
			ClientConfig.CAKeyFile = args[0]
		}
		c := &client.Client{
			Config: ClientConfig,
		}
		defer c.Close()
		return c.AddCA()
	},
}
View Source
var CaCmd = &cobra.Command{
	Use:   "ca",
	Short: "CA key management",
}
View Source
var ClientConfig = &client.Config{
	UseAgent:            true,
	Timeout:             2 * time.Second,
	Retries:             3,
	GenerateKeypairType: "rsa",
	GenerateKeypairSize: 2048,
}
View Source
var CompletionCmd = &cobra.Command{
	Use:   "completion [bash|zsh|fish|powershell]",
	Short: "Generate shell completion script",
	RunE: func(cmd *cobra.Command, args []string) error {
		switch args[0] {
		case "bash":
			return cmd.Root().GenBashCompletion(os.Stdout)
		case "zsh":
			return cmd.Root().GenZshCompletion(os.Stdout)
		case "fish":
			return cmd.Root().GenFishCompletion(os.Stdout, true)
		case "powershell":
			return cmd.Root().GenPowerShellCompletion(os.Stdout)
		}
		return fmt.Errorf("unsupported shell: %s", args[0])
	},
	Args: cobra.ExactArgs(1),
	ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
		var shells []string
		if len(args) == 0 {
			shells = []string{"bash", "zsh", "fish", "powershell"}
		}
		return shells, cobra.ShellCompDirectiveNoFileComp
	},
}
View Source
var ExecCmd = &cobra.Command{
	Use:                "exec",
	Short:              "Invoke any command with signed certificate on ssh-agent",
	DisableFlagParsing: true,
	RunE: func(cmd *cobra.Command, args []string) error {
		ignoreFlagsAfter("exec")
		return runExecCommand(RootCmd.Flags().Args()[2:])
	},
	ValidArgsFunction: noCompletion,
}
View Source
var Log = logging.GetLogger("exec").WithField("pkg", "cmd/exec")
View Source
var ReqCmd = &cobra.Command{
	Use:   "req",
	Short: "Login to server and generate SSH certificate",
	RunE: func(cmd *cobra.Command, args []string) error {
		c := &client.Client{
			Config: ClientConfig,
		}
		defer c.Close()
		if b, _ := cmd.Flags().GetBool("clear"); b == true {
			return c.Logout()
		} else if b, _ := cmd.Flags().GetBool("list-logins"); b == true {
			discoverResult, err := c.GetAuthenticators()
			if err != nil {
				return err
			}
			for _, v := range discoverResult {
				fmt.Printf("%s (%s)\n", v.AuthenticatorName, v.AuthenticatorRealm)
			}
			return nil
		}
		return c.Login()
	},
	ValidArgsFunction: noCompletion,
}
View Source
var ResponseCmd = &cobra.Command{
	Use:   "response",
	Short: "Send a response to a CA challenge in order to decrypt and add the CA key",
	Args:  cobra.MaximumNArgs(1),
	RunE: func(cmd *cobra.Command, args []string) error {
		c := &client.Client{
			Config: ClientConfig,
		}
		defer c.Close()
		return c.ChallengeResponse()
	},
}
View Source
var RootCmd = &cobra.Command{
	Use:           "sshi",
	Short:         "sshi connects to ssh-inscribed for SSH certificate generation",
	SilenceErrors: true,
	SilenceUsage:  true,
}
View Source
var ShowCaCmd = &cobra.Command{
	Use:   "show",
	Short: "Show CA public key",
	RunE: func(cmd *cobra.Command, args []string) error {
		c := &client.Client{
			Config: ClientConfig,
		}
		defer c.Close()
		caKey, err := c.GetCA()
		if err != nil {
			return err
		}
		if principals != nil {
			fmt.Printf(`cert-authority,principals="%s" %s`,
				strings.Join(principals, ","),
				ssh.MarshalAuthorizedKey(caKey),
			)
		} else {
			fmt.Printf("%s", ssh.MarshalAuthorizedKey(caKey))
		}
		return nil
	},
	ValidArgsFunction: noCompletion,
}
View Source
var SshCmd = &cobra.Command{
	Use:                "ssh",
	Short:              "Invoke ssh command with signed certificate on ssh-agent",
	DisableFlagParsing: true,
	RunE: func(cmd *cobra.Command, args []string) error {
		ignoreFlagsAfter("ssh")
		return runExecCommand(RootCmd.Flags().Args()[1:])
	},
	ValidArgsFunction: noCompletion,
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL