Skip to content

Commit fca6aad

Browse files
author
j-griffith
committed
Remove logging of args for failed iscsi cmds
The iscsiadm functions provide a debug mode that currently logs the iscsiadm command that was issued and the response. This is handy for the lib as it's in beta and we want to make it easy for users to pick up and start using, BUT it also has a major problem in that it will also log the arguments passed in for things like CHAP secrets. This change just removes the debug logging of the iscsiadm cmd args, in the future if we need/want some debug tools we can implement a more robust and secure method that's safe and doesn't leak secrets to log files. closes #8
1 parent 696aa76 commit fca6aad

File tree

2 files changed

+5
-45
lines changed

2 files changed

+5
-45
lines changed

iscsi/iscsi.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ func Connect(c Connector) (string, error) {
273273
// create db entry
274274
args := append(baseArgs, []string{"-I", iFace, "-o", "new"}...)
275275
debug.Printf("create the new record: %s\n", args)
276+
// Make sure we don't log the secrets
276277
err := CreateDBEntry(c.TargetIqn, p, iFace, c.DiscoverySecrets, c.SessionSecrets)
277278
if err != nil {
278279
debug.Printf("Error creating db entry: %s\n", err.Error())

iscsi/iscsiadm.go

Lines changed: 4 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ package iscsi
33
import (
44
"bytes"
55
"fmt"
6-
"os/exec"
76
"strings"
8-
"syscall"
97
)
108

119
// Secrets provides optional iscsi security credentials (CHAP settings)
@@ -60,57 +58,18 @@ func iscsiCmd(args ...string) (string, error) {
6058
}
6159
}
6260

63-
iscsiadmDebug(args, string(stdout.Bytes()), iscsiadmError)
61+
iscsiadmDebug(string(stdout.Bytes()), iscsiadmError)
6462
return string(stdout.Bytes()), iscsiadmError
6563
}
6664

67-
func iscsiadmDebug(args []string, output string, cmdError error) {
65+
func iscsiadmDebug(output string, cmdError error) {
6866
debugOutput := strings.Replace(output, "\n", "\\n", -1)
69-
debug.Printf("Output of iscsiadm command: {{cmd: iscsiadm %s}, {output: %s}", args, debugOutput)
67+
debug.Printf("Output of iscsiadm command: {output: %s}", debugOutput)
7068
if cmdError != nil {
71-
debug.Printf("Error message returned from issiadm command: %s", cmdError.Error())
69+
debug.Printf("Error message returned from iscsiadm command: %s", cmdError.Error())
7270
}
7371
}
7472

75-
func iscsiCmdHide(args ...string) (string, error) {
76-
debug.Printf("Execute iscsiadm %s", args)
77-
var waitStatus syscall.WaitStatus
78-
var iscsiHelper = "iscsiadm"
79-
eStat := 0
80-
out := &bytes.Buffer{}
81-
cmdErr := &bytes.Buffer{}
82-
83-
c := execCommand(iscsiHelper, args...)
84-
c.Stdout = out
85-
c.Stderr = cmdErr
86-
iscsiadmErr := CmdError{}
87-
88-
if err := c.Run(); err != nil {
89-
if exitError, ok := err.(*exec.ExitError); ok {
90-
waitStatus = exitError.Sys().(syscall.WaitStatus)
91-
eStat = waitStatus.ExitStatus()
92-
}
93-
} else {
94-
waitStatus = c.ProcessState.Sys().(syscall.WaitStatus)
95-
eStat = waitStatus.ExitStatus()
96-
}
97-
if eStat != 0 || string(cmdErr.Bytes()) != "" {
98-
iscsiadmErr = CmdError{
99-
StdErr: string(cmdErr.Bytes()),
100-
ExitCode: eStat,
101-
CMD: iscsiHelper + " " + strings.Join(args, " "),
102-
}
103-
}
104-
if &iscsiadmErr != nil {
105-
debug.Printf("FUCK: %v\n", &iscsiadmErr)
106-
}
107-
debugOutput := strings.Replace(string(out.Bytes()), "\n", "\\n ", -1)
108-
debugStderr := strings.Replace(string(cmdErr.Bytes()), "\n", "\\n ", -1)
109-
110-
debug.Printf("Response from iscsiadm, {{output: %s}, {stderr: %s}, {exit-code: %d}}", debugOutput, debugStderr, eStat)
111-
return string(out.Bytes()), &iscsiadmErr
112-
}
113-
11473
// ListInterfaces returns a list of all iscsi interfaces configured on the node
11574
/// along with the raw output in Response.StdOut we add the convenience of
11675
// returning a list of entries found

0 commit comments

Comments
 (0)