Skip to content

Redact S3 credentials from logs #10811

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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 @@ -283,7 +283,17 @@ public static String retrieveNfsVersionFromParams(Map<String, Object> params) {

@Override
public Answer executeRequest(Command cmd) {
logger.debug(LogUtils.logGsonWithoutException("Executing command %s [%s].", cmd.getClass().getSimpleName(), cmd));
if (cmd instanceof DownloadCommand) {
DownloadCommand safeCmd = new DownloadCommand((DownloadCommand) cmd);
DataStoreTO store = safeCmd.getDataStore();
if (store instanceof S3TO) {
((S3TO) store).setAccessKey("***REDACTED***");
((S3TO) store).setSecretKey("***REDACTED***");
}
logger.debug(LogUtils.logGsonWithoutException("Executing command %s [%s].", safeCmd.getClass().getSimpleName(), safeCmd));
Comment on lines +288 to +293
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code looks good, but it seems this should be in LogUtils. There is other obfuscation code also scattered across the code base, so definately not a 👎 but a mere suggestion.

} else {
logger.debug(LogUtils.logGsonWithoutException("Executing command %s [%s].", cmd.getClass().getSimpleName(), cmd));
}
if (cmd instanceof DownloadProgressCommand) {
return _dlMgr.handleDownloadCommand(this, (DownloadProgressCommand)cmd);
} else if (cmd instanceof DownloadCommand) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
import org.mockito.junit.MockitoJUnitRunner;

import com.cloud.agent.api.to.DataStoreTO;
import org.apache.cloudstack.storage.command.DownloadCommand;
import com.cloud.agent.api.to.S3TO;

@RunWith(MockitoJUnitRunner.class)
public class NfsSecondaryStorageResourceTest {
Expand Down Expand Up @@ -241,4 +243,18 @@ public void getUploadProtocolTestReturnHttpWhenUseHttpsToUploadIsFalse() {

Assert.assertEquals(NetUtils.HTTP_PROTO, result);
}
}

@Test
public void testExecuteRequestRedactsS3Credentials() {
S3TO mockS3 = Mockito.mock(S3TO.class);
DownloadCommand mockCmd = Mockito.mock(DownloadCommand.class);

Mockito.when(mockCmd.getDataStore()).thenReturn(mockS3);

resource.executeRequest(mockCmd);

Mockito.verify(mockS3).setAccessKey("***REDACTED***");
Mockito.verify(mockS3).setSecretKey("***REDACTED***");
}

}