Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,13 @@ String removeCommandSensitiveInfoForLogging(String command) {
public ProcessRunner(ExecutorService executor) {
this.executor = executor;
commandLogReplacements.add(new Ternary<>("ipmitool", "-P\\s+\\S+", "-P *****"));
commandLogReplacements.add(new Ternary<>("ipmitool", "(?i)(password)(\\s+)\\S+(\\s+)\\S+", "$1 ****$2****"));
}

/**
* Executes a process with provided list of commands with a max default timeout
* of 5 minutes
*
* @param commands list of string commands
* @return returns process result
*/
Expand All @@ -82,6 +84,7 @@ public ProcessResult executeCommands(final List<String> commands) {
/**
* Executes a process with provided list of commands with a given timeout that is less
* than or equal to DEFAULT_MAX_TIMEOUT
*
* @param commands list of string commands
* @param timeOut timeout duration
* @return returns process result
Expand Down Expand Up @@ -109,14 +112,16 @@ public Integer call() throws Exception {
}
});
try {
logger.debug("Waiting for a response from command [{}]. Defined timeout: [{}].", commandLog, timeOut.getStandardSeconds());
logger.debug("Waiting for a response from command [{}]. Defined timeout: [{}].", commandLog,
timeOut.getStandardSeconds());
retVal = processFuture.get(timeOut.getStandardSeconds(), TimeUnit.SECONDS);
} catch (ExecutionException e) {
logger.warn("Failed to complete the requested command [{}] due to execution error.", commands, e);
logger.warn("Failed to complete the requested command [{}] due to execution error.", commandLog, e);
retVal = -2;
stdError = e.getMessage();
} catch (TimeoutException e) {
logger.warn("Failed to complete the requested command [{}] within timeout. Defined timeout: [{}].", commandLog, timeOut.getStandardSeconds(), e);
logger.warn("Failed to complete the requested command [{}] within timeout. Defined timeout: [{}].",
commandLog, timeOut.getStandardSeconds(), e);
retVal = -1;
stdError = "Operation timed out, aborted.";
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,16 @@ public void testRemoveCommandSensitiveInfoForLoggingIpmi() {
Assert.assertTrue(log.contains(password));
Assert.assertEquals(1, countSubstringOccurrences(log, password));
}

@Test
public void testRemoveCommandSensitiveInfoForLoggingIpmiPasswordCommand() {
String userId = "3";
String newPassword = "Sup3rSecr3t!";
String command = String.format("/usr/bin/ipmitool user set password %s %s", userId, newPassword);
String log = processRunner.removeCommandSensitiveInfoForLogging(command);

Assert.assertFalse(log.contains(userId));
Assert.assertFalse(log.contains(newPassword));
Assert.assertTrue(log.contains("password **** ****"));
}
}
Loading