mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
ipmi: extra log sanitation (#10428)
This commit is contained in:
parent
66f8a351dd
commit
e196275d5a
@ -47,13 +47,13 @@ public final class IpmitoolOutOfBandManagementDriver extends AdapterBase impleme
|
||||
private final ExecutorService ipmitoolExecutor = Executors.newFixedThreadPool(OutOfBandManagementService.SyncThreadPoolSize.value(), new NamedThreadFactory("IpmiToolDriver"));
|
||||
private final IpmitoolWrapper IPMITOOL = new IpmitoolWrapper(ipmitoolExecutor);
|
||||
|
||||
public final ConfigKey<String> IpmiToolPath = new ConfigKey<String>("Advanced", String.class, "outofbandmanagement.ipmitool.path", "/usr/bin/ipmitool",
|
||||
public final ConfigKey<String> IpmiToolPath = new ConfigKey<>("Advanced", String.class, "outofbandmanagement.ipmitool.path", "/usr/bin/ipmitool",
|
||||
"The out of band management ipmitool path used by the IpmiTool driver. Default: /usr/bin/ipmitool.", true, ConfigKey.Scope.Global);
|
||||
|
||||
public final ConfigKey<String> IpmiToolInterface = new ConfigKey<String>("Advanced", String.class, "outofbandmanagement.ipmitool.interface", "lanplus",
|
||||
public final ConfigKey<String> IpmiToolInterface = new ConfigKey<>("Advanced", String.class, "outofbandmanagement.ipmitool.interface", "lanplus",
|
||||
"The out of band management IpmiTool driver interface to use. Default: lanplus. Valid values are: lan, lanplus, open etc.", true, ConfigKey.Scope.Global);
|
||||
|
||||
public final ConfigKey<String> IpmiToolRetries = new ConfigKey<String>("Advanced", String.class, "outofbandmanagement.ipmitool.retries", "1",
|
||||
public final ConfigKey<String> IpmiToolRetries = new ConfigKey<>("Advanced", String.class, "outofbandmanagement.ipmitool.retries", "1",
|
||||
"The out of band management IpmiTool driver retries option -R. Default 1.", true, ConfigKey.Scope.Global);
|
||||
|
||||
private String getIpmiUserId(ImmutableMap<OutOfBandManagement.Option, String> options, final Duration timeOut) {
|
||||
@ -122,7 +122,7 @@ public final class IpmitoolOutOfBandManagementDriver extends AdapterBase impleme
|
||||
|
||||
final OutOfBandManagementDriverResponse response = IPMITOOL.executeCommands(ipmiToolCommands, cmd.getTimeout());
|
||||
|
||||
String oneLineCommand = StringUtils.join(ipmiToolCommands, " ");
|
||||
String oneLineCommand = StringUtils.join(IPMITOOL.getSanatisedCommandStrings(ipmiToolCommands), " ");
|
||||
String result = response.getResult().trim();
|
||||
|
||||
if (response.isSuccess()) {
|
||||
|
||||
@ -26,6 +26,7 @@ import org.apache.cloudstack.outofbandmanagement.driver.OutOfBandManagementDrive
|
||||
import org.apache.cloudstack.utils.process.ProcessResult;
|
||||
import org.apache.cloudstack.utils.process.ProcessRunner;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.joda.time.Duration;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -156,25 +157,31 @@ public final class IpmitoolWrapper {
|
||||
public OutOfBandManagementDriverResponse executeCommands(final List<String> commands, final Duration timeOut) {
|
||||
final ProcessResult result = RUNNER.executeCommands(commands, timeOut);
|
||||
if (LOG.isTraceEnabled()) {
|
||||
List<String> cleanedCommands = new ArrayList<String>();
|
||||
int maskNextCommand = 0;
|
||||
for (String command : commands) {
|
||||
if (maskNextCommand > 0) {
|
||||
cleanedCommands.add("**** ");
|
||||
maskNextCommand--;
|
||||
continue;
|
||||
}
|
||||
if (command.equalsIgnoreCase("-P")) {
|
||||
maskNextCommand = 1;
|
||||
} else if (command.toLowerCase().endsWith("password")) {
|
||||
maskNextCommand = 2;
|
||||
}
|
||||
cleanedCommands.add(command);
|
||||
}
|
||||
List<String> cleanedCommands = getSanatisedCommandStrings(commands);
|
||||
LOG.trace("Executed ipmitool process with commands: " + StringUtils.join(cleanedCommands, ", ") +
|
||||
"\nIpmitool execution standard output: " + result.getStdOutput() +
|
||||
"\nIpmitool execution error output: " + result.getStdError());
|
||||
}
|
||||
return new OutOfBandManagementDriverResponse(result.getStdOutput(), result.getStdError(), result.isSuccess());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
List<String> getSanatisedCommandStrings(List<String> commands) {
|
||||
List<String> cleanedCommands = new ArrayList<String>();
|
||||
int maskNextCommand = 0;
|
||||
for (String command : commands) {
|
||||
if (maskNextCommand > 0) {
|
||||
cleanedCommands.add("**** ");
|
||||
maskNextCommand--;
|
||||
continue;
|
||||
}
|
||||
if (command.equalsIgnoreCase("-P")) {
|
||||
maskNextCommand = 1;
|
||||
} else if (command.toLowerCase().endsWith("password")) {
|
||||
maskNextCommand = 2;
|
||||
}
|
||||
cleanedCommands.add(command);
|
||||
}
|
||||
return cleanedCommands;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user