add -prepare and -ssh_config flags for usage in SSH ProxyCommand
E.g.: Host router7 ProxyCommand /bin/sh -c 'breakglass -prepare_only -ssh_config=/dev/null -debug_tarball_pattern=$HOME/gokrazy/debug-\${GOARCH}.tar %h; /usr/bin/nc %h %p'
This commit is contained in:
parent
b54c2f919e
commit
9eab5f8b0d
@ -30,6 +30,7 @@ type bg struct {
|
|||||||
hostname string
|
hostname string
|
||||||
pw string
|
pw string
|
||||||
forceRestart bool
|
forceRestart bool
|
||||||
|
sshConfig string
|
||||||
|
|
||||||
// state
|
// state
|
||||||
GOARCH string
|
GOARCH string
|
||||||
@ -133,7 +134,11 @@ func (bg *bg) uploadDebugTarball(debugTarballPattern string) error {
|
|||||||
time.Since(st.ModTime()).Round(1*time.Second),
|
time.Since(st.ModTime()).Round(1*time.Second),
|
||||||
strings.Join(contents, "\n\t\t"))
|
strings.Join(contents, "\n\t\t"))
|
||||||
|
|
||||||
scp := exec.Command("scp", debugTarball, bg.hostname+":")
|
var opts []string
|
||||||
|
if bg.sshConfig != "" {
|
||||||
|
opts = append(opts, "-F", bg.sshConfig)
|
||||||
|
}
|
||||||
|
scp := exec.Command("scp", append(opts, debugTarball, bg.hostname+":")...)
|
||||||
scp.Stderr = os.Stderr
|
scp.Stderr = os.Stderr
|
||||||
if err := scp.Run(); err != nil {
|
if err := scp.Run(); err != nil {
|
||||||
return fmt.Errorf("%v: %v", scp.Args, err)
|
return fmt.Errorf("%v: %v", scp.Args, err)
|
||||||
@ -152,6 +157,16 @@ func breakglass() error {
|
|||||||
"debug_tarball_pattern",
|
"debug_tarball_pattern",
|
||||||
"",
|
"",
|
||||||
"If non-empty, a pattern resulting in the path to a debug.tar archive that should be copied to breakglass before starting a shell. This can be used to make additional tools available for debugging. All occurrences of ${GOARCH} will be replaced with the runtime.GOARCH of the remote gokrazy installation.")
|
"If non-empty, a pattern resulting in the path to a debug.tar archive that should be copied to breakglass before starting a shell. This can be used to make additional tools available for debugging. All occurrences of ${GOARCH} will be replaced with the runtime.GOARCH of the remote gokrazy installation.")
|
||||||
|
|
||||||
|
prepare = flag.Bool(
|
||||||
|
"prepare_only",
|
||||||
|
false,
|
||||||
|
"prepare the SSH connection only, but do not execute SSH (useful for using breakglass within an SSH ProxyCommand)")
|
||||||
|
|
||||||
|
sshConfig = flag.String(
|
||||||
|
"ssh_config",
|
||||||
|
"",
|
||||||
|
"an alternative per-user configuration file for ssh and scp")
|
||||||
)
|
)
|
||||||
|
|
||||||
flag.Usage = func() {
|
flag.Usage = func() {
|
||||||
@ -179,6 +194,7 @@ func breakglass() error {
|
|||||||
hostname: hostname,
|
hostname: hostname,
|
||||||
pw: pw,
|
pw: pw,
|
||||||
forceRestart: *forceRestart,
|
forceRestart: *forceRestart,
|
||||||
|
sshConfig: *sshConfig,
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("checking breakglass status on gokrazy installation %q", hostname)
|
log.Printf("checking breakglass status on gokrazy installation %q", hostname)
|
||||||
@ -199,6 +215,10 @@ func breakglass() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if *prepare {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
ssh := exec.Command("ssh", hostname)
|
ssh := exec.Command("ssh", hostname)
|
||||||
if args := flag.Args()[1:]; len(args) > 0 {
|
if args := flag.Args()[1:]; len(args) > 0 {
|
||||||
ssh.Args = append(ssh.Args, args...)
|
ssh.Args = append(ssh.Args, args...)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user