apache / apache/cloudstack

Security Vulnerability Report: Sensitive User Data and SSH Public Key Exposure in VM Metadata Logging

Đang mở
#12,030 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
component:logging
Ngôn ngữ chính
Java
Star
3.1k
Fork
1.4k
Merge trung bình
6 ngày 19 giờ
Pull request đã merge (30 ngày)
32

Mô tả

## Description

We have identified a security vulnerability where sensitive data (user-data and public-keys) is exposed through application logs during the execution of `VmDataCommand`.

## Data Flow

### 1. Sensitive Data Injection

In `com.cloud.network.router.CommandSetupHelper.generateVmDataCommand`, sensitive information including user data and public keys is added to the `VmDataCommand`:

```java
// com.cloud.network.router.CommandSetupHelper.generateVmDataCommand
private VmDataCommand generateVmDataCommand(final VirtualRouter router, final String vmPrivateIpAddress, final String userData, String userDataDetails, final String serviceOffering,
final String zoneName, final String publicIpAddress, final String vmName, final String vmInstanceName, final long vmId, final String vmUuid, final String publicKey,
final long guestNetworkId, String hostname) {
final VmDataCommand cmd = new VmDataCommand(vmPrivateIpAddress, vmName, _networkModel.getExecuteInSeqNtwkElmtCmd());

...

cmd.addVmData("userdata", "user-data", userData);
...
cmd.addVmData("metadata", "public-keys", publicKey);
```

### 2. Script Construction with Sensitive Data

In `com.cloud.baremetal.networkservice.BaremetalKickStartPxeResource.execute`, the VM data containing sensitive information is retrieved and embedded into a shell script command:

```java
//com.cloud.baremetal.networkservice.BaremetalKickStartPxeResource.execute
private Answer execute(VmDataCommand cmd) {
com.trilead.ssh2.Connection sshConnection = new com.trilead.ssh2.Connection(_ip, 22);
try {
List vmData = cmd.getVmData();
StringBuilder sb = new StringBuilder();
for (String[] data : vmData) {
String folder = data[0];
String file = data[1];
String contents = (data[2] == null) ? "none" : data[2];
sb.append(cmd.getVmIpAddress());
sb.append(",");
sb.append(folder);
sb.append(",");
sb.append(file);
sb.append(",");
sb.append(contents); // Sensitive data included here
sb.append(";");
}
String arg = StringUtils.stripEnd(sb.toString(), ";");

String script = String.format("python /usr/bin/baremetal_user_data.py '%s'", arg);
if (!SSHCmdHelper.sshExecuteCmd(sshConnection, script)) {
return new Answer(cmd, false, "Failed to add user data, command:" + script);
}
```

### 3. Sensitive Data Logged

Finally, in `com.cloud.utils.ssh.SSHCmdHelper.sshExecuteCmdOneShot`, the constructed script containing sensitive data is logged at DEBUG level:

```java
// com.cloud.utils.ssh.SSHCmdHelper.sshExecuteCmdOneShot
public static SSHCmdResult sshExecuteCmdOneShot(com.trilead.ssh2.Connection sshConnection, String cmd) throws SshException {
LOGGER.debug("Executing cmd: " + cmd.split(KeyStoreUtils.KS_FILENAME)[0]); // ← Sensitive data logged here
Session sshSession = null;
try {
sshSession = sshConnection.openSession();
Thread.sleep(1000);

if (sshSession == null) {
throw new SshException("Cannot open ssh session");
}
// ... execution continues
}
...
if (!StringUtils.isAllEmpty(result.getStdOut(), result.getStdErr())) {
LOGGER.debug("SSH command: " + cmd.split(KeyStoreUtils.KS_FILENAME)[0] + "\nSSH command output:" + result.getStdOut().split("-----BEGIN")[0] + "\n" + result.getStdErr()); // ← Sensitive data logged here again
}
}
```

## Security Impact

This vulnerability results in sensitive information being written to application logs, including:
- **User-data**: May contain passwords, API keys, configuration secrets, or other confidential initialization data
- **Public keys**: SSH public keys that could be used for reconnaissance or social engineering attacks

When debug logging is enabled, this sensitive data becomes accessible to anyone with access to the log files, potentially including:
- System administrators
- Log aggregation systems
- Backup systems
- Attackers who gain unauthorized access to log storage

This constitutes a violation of security best practices and may lead to unauthorized access or information disclosure.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

Bắt đầu tại com.cloud.utils.ssh.SSHCmdHelper.sshExecuteCmdOneShot, sau đó lần theo quá trình xây dựng lệnh qua com.cloud.baremetal.networkservice.BaremetalKickStartPxeResource.execute và com.cloud.network.router.CommandSetupHelper.generateVmDataCommand. Xem xét cách các thông báo debug làm lộ nội dung lệnh; công việc được hoàn tất khi user-data và các khóa công khai không còn được ghi vào log, đồng thời việc thực thi lệnh vẫn hoạt động.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
java, python
Lĩnh vực
infrastructure, security
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.