From 83c61f5fe4e85df9161a8b1489a691ef56602027 Mon Sep 17 00:00:00 2001 From: Nikita Podshivalov Date: Mon, 24 Oct 2022 18:19:33 +0300 Subject: [PATCH] added debug logs for tunnel up/down --- internal/commands/tunnel_down.go | 5 +++++ internal/commands/tunnel_up.go | 15 ++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/internal/commands/tunnel_down.go b/internal/commands/tunnel_down.go index 32d37a646..dad0f2351 100644 --- a/internal/commands/tunnel_down.go +++ b/internal/commands/tunnel_down.go @@ -71,6 +71,11 @@ func (o *TunnelDownOptions) Run() error { c := exec.Command( "ssh", "-S", "bastion.sock", "-O", "exit", "", ) + + if o.Config.LogLevel == "debug" { + c.Args = append(c.Args, "-vvv") + } + out := &bytes.Buffer{} c.Stdout = out c.Stderr = out diff --git a/internal/commands/tunnel_up.go b/internal/commands/tunnel_up.go index 2e1c5adc8..b9628de79 100644 --- a/internal/commands/tunnel_up.go +++ b/internal/commands/tunnel_up.go @@ -171,12 +171,15 @@ func (o *TunnelUpOptions) Validate() error { func (o *TunnelUpOptions) Run() error { logrus.Debugf("public key path: %s", o.PublicKeyFile) + logrus.Debugf("private key path: %s", o.PrivateKeyFile) pk, err := getPublicKey(o.PublicKeyFile) if err != nil { return fmt.Errorf("can't get public key: %s", err) } + logrus.Debugf("public key:\n", pk) + if o.Metadata { err = sendSSHPublicKey(o.BastionHostID, pk, o.Config.Session) if err != nil { @@ -202,6 +205,7 @@ func (o *TunnelUpOptions) Run() error { func (o *TunnelUpOptions) upTunnel() (string, error) { sshConfigPath := fmt.Sprintf("%s/ssh.config", o.Config.EnvDir) + logrus.Debugf("ssh config path: %s", sshConfigPath) if err := setAWSCredentials(o.Config.Session); err != nil { return "", fmt.Errorf("can't run tunnel: %w", err) @@ -250,6 +254,11 @@ func (o *TunnelUpOptions) getSSHCommandArgs(sshConfigPath string) []string { if _, err := os.Stat(o.PrivateKeyFile); !os.IsNotExist(err) { args = append(args, "-i", o.PrivateKeyFile) } + + if o.Config.LogLevel == "debug" { + args = append(args, "-vvv") + } + return args } @@ -273,6 +282,8 @@ func getTerraformOutput(wr *SSMWrapper, env string) (terraformOutput, error) { return terraformOutput{}, fmt.Errorf("can't get terraform output: %w", err) } + logrus.Debugf("decoded terrafrom output: \n%s", value) + var output terraformOutput err = json.Unmarshal(value, &output) @@ -311,9 +322,11 @@ func sendSSHPublicKeyLegacy(bastionID string, key string, sess *session.Session) // This command is executed in the bastion host and it checks if our public key is present. If it's not it uploads it to _authorized_keys file. command := fmt.Sprintf( `grep -qR "%s" /home/ubuntu/.ssh/authorized_keys || echo "%s" >> /home/ubuntu/.ssh/authorized_keys`, - key, key, + strings.TrimSpace(key), strings.TrimSpace(key), ) + logrus.Debugf("send command: \n%s", command) + _, err := ssm.New(sess).SendCommand(&ssm.SendCommandInput{ InstanceIds: []*string{&bastionID}, DocumentName: aws.String("AWS-RunShellScript"),