Skip to content

Commit a43d34c

Browse files
jerome079DaanHoogland
authored andcommitted
fixing s3 credentials leak
1 parent 8e4fe1c commit a43d34c

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

services/secondary-storage/server/src/main/java/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,17 @@ public static String retrieveNfsVersionFromParams(Map<String, Object> params) {
286286

287287
@Override
288288
public Answer executeRequest(Command cmd) {
289-
logger.debug(LogUtils.logGsonWithoutException("Executing command %s [%s].", cmd.getClass().getSimpleName(), cmd));
289+
if (cmd instanceof DownloadCommand) {
290+
DownloadCommand safeCmd = new DownloadCommand((DownloadCommand) cmd);
291+
DataStoreTO store = safeCmd.getDataStore();
292+
if (store instanceof S3TO) {
293+
((S3TO) store).setAccessKey("***REDACTED***");
294+
((S3TO) store).setSecretKey("***REDACTED***");
295+
}
296+
logger.debug(LogUtils.logGsonWithoutException("Executing command %s [%s].", safeCmd.getClass().getSimpleName(), safeCmd));
297+
} else {
298+
logger.debug(LogUtils.logGsonWithoutException("Executing command %s [%s].", cmd.getClass().getSimpleName(), cmd));
299+
}
290300
if (cmd instanceof DownloadProgressCommand) {
291301
return _dlMgr.handleDownloadCommand(this, (DownloadProgressCommand)cmd);
292302
} else if (cmd instanceof DownloadCommand) {

services/secondary-storage/server/src/test/java/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResourceTest.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
import org.mockito.junit.MockitoJUnitRunner;
4848

4949
import com.cloud.agent.api.to.DataStoreTO;
50+
import org.apache.cloudstack.storage.command.DownloadCommand;
51+
import com.cloud.agent.api.to.S3TO;
5052

5153
@RunWith(MockitoJUnitRunner.class)
5254
public class NfsSecondaryStorageResourceTest {
@@ -241,4 +243,18 @@ public void getUploadProtocolTestReturnHttpWhenUseHttpsToUploadIsFalse() {
241243

242244
Assert.assertEquals(NetUtils.HTTP_PROTO, result);
243245
}
244-
}
246+
247+
@Test
248+
public void testExecuteRequestRedactsS3Credentials() {
249+
S3TO mockS3 = Mockito.mock(S3TO.class);
250+
DownloadCommand mockCmd = Mockito.mock(DownloadCommand.class);
251+
252+
Mockito.when(mockCmd.getDataStore()).thenReturn(mockS3);
253+
254+
resource.executeRequest(mockCmd);
255+
256+
Mockito.verify(mockS3).setAccessKey("***REDACTED***");
257+
Mockito.verify(mockS3).setSecretKey("***REDACTED***");
258+
}
259+
260+
}

0 commit comments

Comments
 (0)