Skip to content

Commit 5e44c34

Browse files
DaanHooglanddhslove
authored andcommitted
ipmi: extra log sanitation (apache#10428)
1 parent beb0725 commit 5e44c34

File tree

2 files changed

+30
-22
lines changed

2 files changed

+30
-22
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
@@ -45,13 +45,13 @@ public final class IpmitoolOutOfBandManagementDriver extends AdapterBase impleme
4545
private final ExecutorService ipmitoolExecutor = Executors.newFixedThreadPool(OutOfBandManagementService.SyncThreadPoolSize.value(), new NamedThreadFactory("IpmiToolDriver"));
4646
private final IpmitoolWrapper IPMITOOL = new IpmitoolWrapper(ipmitoolExecutor);
4747

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

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

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

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

121121
final OutOfBandManagementDriverResponse response = IPMITOOL.executeCommands(ipmiToolCommands, cmd.getTimeout());
122122

123-
String oneLineCommand = StringUtils.join(ipmiToolCommands, " ");
123+
String oneLineCommand = StringUtils.join(IPMITOOL.getSanatisedCommandStrings(ipmiToolCommands), " ");
124124
String result = response.getResult().trim();
125125

126126
if (response.isSuccess()) {

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

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.apache.cloudstack.utils.process.ProcessRunner;
2828
import org.apache.logging.log4j.Logger;
2929
import org.apache.logging.log4j.LogManager;
30+
3031
import org.joda.time.Duration;
3132

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

0 commit comments

Comments
 (0)