Skip to content

Commit 028dd86

Browse files
authored
fixed Password Exposure in IPMI Tool Command Execution (#12028)
1 parent f0a0936 commit 028dd86

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

utils/src/main/java/org/apache/cloudstack/utils/process/ProcessRunner.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,13 @@ String removeCommandSensitiveInfoForLogging(String command) {
6767
public ProcessRunner(ExecutorService executor) {
6868
this.executor = executor;
6969
commandLogReplacements.add(new Ternary<>("ipmitool", "-P\\s+\\S+", "-P *****"));
70+
commandLogReplacements.add(new Ternary<>("ipmitool", "(?i)password\\s+\\S+\\s+\\S+", "password **** ****"));
7071
}
7172

7273
/**
7374
* Executes a process with provided list of commands with a max default timeout
7475
* of 5 minutes
76+
*
7577
* @param commands list of string commands
7678
* @return returns process result
7779
*/
@@ -82,6 +84,7 @@ public ProcessResult executeCommands(final List<String> commands) {
8284
/**
8385
* Executes a process with provided list of commands with a given timeout that is less
8486
* than or equal to DEFAULT_MAX_TIMEOUT
87+
*
8588
* @param commands list of string commands
8689
* @param timeOut timeout duration
8790
* @return returns process result
@@ -109,14 +112,16 @@ public Integer call() throws Exception {
109112
}
110113
});
111114
try {
112-
logger.debug("Waiting for a response from command [{}]. Defined timeout: [{}].", commandLog, timeOut.getStandardSeconds());
115+
logger.debug("Waiting for a response from command [{}]. Defined timeout: [{}].", commandLog,
116+
timeOut.getStandardSeconds());
113117
retVal = processFuture.get(timeOut.getStandardSeconds(), TimeUnit.SECONDS);
114118
} catch (ExecutionException e) {
115-
logger.warn("Failed to complete the requested command [{}] due to execution error.", commands, e);
119+
logger.warn("Failed to complete the requested command [{}] due to execution error.", commandLog, e);
116120
retVal = -2;
117121
stdError = e.getMessage();
118122
} catch (TimeoutException e) {
119-
logger.warn("Failed to complete the requested command [{}] within timeout. Defined timeout: [{}].", commandLog, timeOut.getStandardSeconds(), e);
123+
logger.warn("Failed to complete the requested command [{}] within timeout. Defined timeout: [{}].",
124+
commandLog, timeOut.getStandardSeconds(), e);
120125
retVal = -1;
121126
stdError = "Operation timed out, aborted.";
122127
} finally {

utils/src/test/java/org/apache/cloudstack/utils/process/ProcessRunnerTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,16 @@ public void testRemoveCommandSensitiveInfoForLoggingIpmi() {
6060
Assert.assertTrue(log.contains(password));
6161
Assert.assertEquals(1, countSubstringOccurrences(log, password));
6262
}
63+
64+
@Test
65+
public void testRemoveCommandSensitiveInfoForLoggingIpmiPasswordCommand() {
66+
String userId = "3";
67+
String newPassword = "Sup3rSecr3t!";
68+
String command = String.format("/usr/bin/ipmitool user set password %s %s", userId, newPassword);
69+
String log = processRunner.removeCommandSensitiveInfoForLogging(command);
70+
71+
Assert.assertFalse(log.contains(userId));
72+
Assert.assertFalse(log.contains(newPassword));
73+
Assert.assertTrue(log.contains("password **** ****"));
74+
}
6375
}

0 commit comments

Comments
 (0)