Skip to content

Commit e196275

Browse files
authored
ipmi: extra log sanitation (#10428)
1 parent 66f8a35 commit e196275

File tree

2 files changed

+26
-19
lines changed

2 files changed

+26
-19
lines changed

plugins/outofbandmanagement-drivers/ipmitool/src/main/java/org/apache/cloudstack/outofbandmanagement/driver/ipmitool/IpmitoolOutOfBandManagementDriver.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ public final class IpmitoolOutOfBandManagementDriver extends AdapterBase impleme
4747
private final ExecutorService ipmitoolExecutor = Executors.newFixedThreadPool(OutOfBandManagementService.SyncThreadPoolSize.value(), new NamedThreadFactory("IpmiToolDriver"));
4848
private final IpmitoolWrapper IPMITOOL = new IpmitoolWrapper(ipmitoolExecutor);
4949

50-
public final ConfigKey<String> IpmiToolPath = new ConfigKey<String>("Advanced", String.class, "outofbandmanagement.ipmitool.path", "/usr/bin/ipmitool",
50+
public final ConfigKey<String> IpmiToolPath = new ConfigKey<>("Advanced", String.class, "outofbandmanagement.ipmitool.path", "/usr/bin/ipmitool",
5151
"The out of band management ipmitool path used by the IpmiTool driver. Default: /usr/bin/ipmitool.", true, ConfigKey.Scope.Global);
5252

53-
public final ConfigKey<String> IpmiToolInterface = new ConfigKey<String>("Advanced", String.class, "outofbandmanagement.ipmitool.interface", "lanplus",
53+
public final ConfigKey<String> IpmiToolInterface = new ConfigKey<>("Advanced", String.class, "outofbandmanagement.ipmitool.interface", "lanplus",
5454
"The out of band management IpmiTool driver interface to use. Default: lanplus. Valid values are: lan, lanplus, open etc.", true, ConfigKey.Scope.Global);
5555

56-
public final ConfigKey<String> IpmiToolRetries = new ConfigKey<String>("Advanced", String.class, "outofbandmanagement.ipmitool.retries", "1",
56+
public final ConfigKey<String> IpmiToolRetries = new ConfigKey<>("Advanced", String.class, "outofbandmanagement.ipmitool.retries", "1",
5757
"The out of band management IpmiTool driver retries option -R. Default 1.", true, ConfigKey.Scope.Global);
5858

5959
private String getIpmiUserId(ImmutableMap<OutOfBandManagement.Option, String> options, final Duration timeOut) {
@@ -122,7 +122,7 @@ private OutOfBandManagementDriverResponse execute(final OutOfBandManagementDrive
122122

123123
final OutOfBandManagementDriverResponse response = IPMITOOL.executeCommands(ipmiToolCommands, cmd.getTimeout());
124124

125-
String oneLineCommand = StringUtils.join(ipmiToolCommands, " ");
125+
String oneLineCommand = StringUtils.join(IPMITOOL.getSanatisedCommandStrings(ipmiToolCommands), " ");
126126
String result = response.getResult().trim();
127127

128128
if (response.isSuccess()) {

plugins/outofbandmanagement-drivers/ipmitool/src/main/java/org/apache/cloudstack/outofbandmanagement/driver/ipmitool/IpmitoolWrapper.java

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.apache.cloudstack.utils.process.ProcessResult;
2727
import org.apache.cloudstack.utils.process.ProcessRunner;
2828
import org.apache.log4j.Logger;
29+
import org.jetbrains.annotations.NotNull;
2930
import org.joda.time.Duration;
3031

3132
import java.util.ArrayList;
@@ -156,25 +157,31 @@ public OutOfBandManagementDriverResponse executeCommands(final List<String> comm
156157
public OutOfBandManagementDriverResponse executeCommands(final List<String> commands, final Duration timeOut) {
157158
final ProcessResult result = RUNNER.executeCommands(commands, timeOut);
158159
if (LOG.isTraceEnabled()) {
159-
List<String> cleanedCommands = new ArrayList<String>();
160-
int maskNextCommand = 0;
161-
for (String command : commands) {
162-
if (maskNextCommand > 0) {
163-
cleanedCommands.add("**** ");
164-
maskNextCommand--;
165-
continue;
166-
}
167-
if (command.equalsIgnoreCase("-P")) {
168-
maskNextCommand = 1;
169-
} else if (command.toLowerCase().endsWith("password")) {
170-
maskNextCommand = 2;
171-
}
172-
cleanedCommands.add(command);
173-
}
160+
List<String> cleanedCommands = getSanatisedCommandStrings(commands);
174161
LOG.trace("Executed ipmitool process with commands: " + StringUtils.join(cleanedCommands, ", ") +
175162
"\nIpmitool execution standard output: " + result.getStdOutput() +
176163
"\nIpmitool execution error output: " + result.getStdError());
177164
}
178165
return new OutOfBandManagementDriverResponse(result.getStdOutput(), result.getStdError(), result.isSuccess());
179166
}
167+
168+
@NotNull
169+
List<String> getSanatisedCommandStrings(List<String> commands) {
170+
List<String> cleanedCommands = new ArrayList<String>();
171+
int maskNextCommand = 0;
172+
for (String command : commands) {
173+
if (maskNextCommand > 0) {
174+
cleanedCommands.add("**** ");
175+
maskNextCommand--;
176+
continue;
177+
}
178+
if (command.equalsIgnoreCase("-P")) {
179+
maskNextCommand = 1;
180+
} else if (command.toLowerCase().endsWith("password")) {
181+
maskNextCommand = 2;
182+
}
183+
cleanedCommands.add(command);
184+
}
185+
return cleanedCommands;
186+
}
180187
}

0 commit comments

Comments
 (0)