Skip to content

Commit 0dedb70

Browse files
committed
fixing s3 credentials leak
1 parent fd74895 commit 0dedb70

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
@@ -283,7 +283,17 @@ public static String retrieveNfsVersionFromParams(Map<String, Object> params) {
283283

284284
@Override
285285
public Answer executeRequest(Command cmd) {
286-
logger.debug(LogUtils.logGsonWithoutException("Executing command %s [%s].", cmd.getClass().getSimpleName(), cmd));
286+
if (cmd instanceof DownloadCommand) {
287+
DownloadCommand safeCmd = new DownloadCommand((DownloadCommand) cmd);
288+
DataStoreTO store = safeCmd.getDataStore();
289+
if (store instanceof S3TO) {
290+
((S3TO) store).setAccessKey("***REDACTED***");
291+
((S3TO) store).setSecretKey("***REDACTED***");
292+
}
293+
logger.debug(LogUtils.logGsonWithoutException("Executing command %s [%s].", safeCmd.getClass().getSimpleName(), safeCmd));
294+
} else {
295+
logger.debug(LogUtils.logGsonWithoutException("Executing command %s [%s].", cmd.getClass().getSimpleName(), cmd));
296+
}
287297
if (cmd instanceof DownloadProgressCommand) {
288298
return _dlMgr.handleDownloadCommand(this, (DownloadProgressCommand)cmd);
289299
} 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)