fix(webconsole): baremteasl ipmi sol instance_name hide password (#23549)

This commit is contained in:
wanyaoqi
2025-10-16 00:01:59 +08:00
committed by GitHub
parent 23a8fefbd0
commit 6f5feb6a7f
6 changed files with 33 additions and 1 deletions

View File

@@ -31,6 +31,7 @@ const (
type ICommand interface {
GetProtocol() string
GetCommand() *exec.Cmd
GetSafeCommandString() string
Cleanup() error
Scan(d byte, send func(msg string))
GetClientSession() *mcclient.ClientSession
@@ -66,6 +67,10 @@ func (c BaseCommand) GetCommand() *exec.Cmd {
return exec.Command(c.name, c.args...)
}
func (c BaseCommand) GetSafeCommandString() string {
return c.GetCommand().String()
}
func (c BaseCommand) Scan(byte, func(msg string)) {
}

View File

@@ -17,6 +17,7 @@ package command
import (
"fmt"
"os/exec"
"strings"
"yunion.io/x/log"
@@ -73,6 +74,20 @@ func (c *IpmitoolSol) GetCommand() *exec.Cmd {
return c.BaseCommand.GetCommand()
}
func (c *IpmitoolSol) GetSafeCommandString() string {
cmd := []string{c.BaseCommand.name}
i := 0
for i < len(c.BaseCommand.args) {
cmd = append(cmd, c.BaseCommand.args[i])
if c.BaseCommand.args[i] == "-P" {
cmd = append(cmd, "******")
i += 1
}
i += 1
}
return strings.Join(cmd, " ")
}
func (c IpmitoolSol) GetProtocol() string {
return PROTOCOL_TTY
}

View File

@@ -98,6 +98,10 @@ func (info *RemoteConsoleInfo) GetCommand() *exec.Cmd {
return nil
}
func (info *RemoteConsoleInfo) GetSafeCommandString() string {
return ""
}
// Cleanup implements ISessionData interface
func (info *RemoteConsoleInfo) Cleanup() error {
return nil

View File

@@ -83,6 +83,10 @@ func (info *RemoteRDPConsoleInfo) GetCommand() *exec.Cmd {
return nil
}
func (info *RemoteRDPConsoleInfo) GetSafeCommandString() string {
return ""
}
func (info *RemoteRDPConsoleInfo) Cleanup() error {
return nil
}

View File

@@ -135,7 +135,7 @@ func (s *RandomSessionData) GetDisplayInfo(ctx context.Context) (*SDisplayInfo,
}
dispInfo := SDisplayInfo{}
dispInfo.WaterMark = fetchWaterMark(userInfo)
dispInfo.InstanceName = s.GetCommand().String()
dispInfo.InstanceName = s.GetSafeCommandString()
return &dispInfo, nil
}

View File

@@ -101,6 +101,10 @@ func (s *SSshSession) GetCommand() *exec.Cmd {
return nil
}
func (s *SSshSession) GetSafeCommandString() string {
return ""
}
func (s *SSshSession) IsNeedLogin() (bool, error) {
if len(s.Username) > 0 && len(s.Password) > 0 {
config := &ssh.ClientConfig{