Dstack-TEE / Dstack-TEE/dstack

Security: App keys and decrypted env vars written with world-readable permissions

Đang mở
#606 2 bình luận 0 reaction 0 người được giao Xem trên GitHub
security security: hardening security: report
Ngôn ngữ chính
Rust
Star
544
Fork
96
Merge trung bình
23 giờ 40 phút
Pull request đã merge (30 ngày)
126

Mô tả

> Note: This issue documents a vulnerability that was originally reported privately as the repository security advisory [GHSA-535m-2x67-prhm](https://github.com/Dstack-TEE/dstack/security/advisories/GHSA-535m-2x67-prhm) by @pbeza.

## Root Cause

[`fs::write()`][app-keys-write] is used with default permissions (`0o644`) to write `AppKeys` to the filesystem. The `AppKeys` structure contains `disk_crypt_key`, `env_crypt_key`, and `k256_key` — all highly sensitive cryptographic secrets. Similarly, decrypted environment variables are written to files with default world-readable permissions.

```rust
// Default fs::write() creates files with 0o644 permissions
fs::write(&app_keys_path, serde_json::to_string(&app_keys)?)?;
```

## Attack Path

1. Any process inside the CVM can read `/path/to/app-keys.json`
2. Attacker compromises any container workload (web vulnerability, dependency exploit, etc.)
3. Compromised process reads `app-keys.json` with `disk_crypt_key`, `env_crypt_key`, `k256_key`
4. Attacker can decrypt the disk, decrypt environment variables, and use the k256 signing key

## Impact

Any compromised process inside the CVM can read all application cryptographic keys and decrypted environment variables. This includes the disk encryption key (enables offline disk reading), the env encryption key (decrypts all environment secrets), and the k256 key (enables signing as the CVM).

## Suggested Fix

Set restrictive permissions before writing:

```rust
use std::os::unix::fs::OpenOptionsExt;

let mut file = std::fs::OpenOptions::new()
.write(true)
.create(true)
.truncate(true)
.mode(0o600)
.open(&app_keys_path)?;
file.write_all(serde_json::to_string(&app_keys)?.as_bytes())?;
```

Consider further restricting to `0o400` (read-only by owner) after the initial write.

---

> Note: This finding was reported automatically as part of an AI/Claude-driven internal audit by the NEAR One MPC team. It has not been manually verified by a human to confirm whether it constitutes an actual security issue.

[app-keys-write]: https://github.com/Dstack-TEE/dstack/blob/master/dstack-util/src/system_setup.rs#L1350-L1351
[env-vars-write]: https://github.com/Dstack-TEE/dstack/blob/master/dstack-util/src/system_setup.rs#L1409-L1419

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

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

Đánh giá

Issue này chưa được đánh giá.

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.