Skip to content

Commit 9c500d7

Browse files
authored
Merge pull request #215 from Dstack-TEE/sec-guide
doc: Add security guide
2 parents a75c95c + 05433f2 commit 9c500d7

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ Now you can open 3 terminals to start the components:
117117
3. Run `./dstack-vmm -c vmm.toml`
118118

119119
⚠️ *Warning: this is for local development, and the kms is not secure, so you should not use it in production.*
120-
For production, you should follow the [deployment guide](./docs/deployment.md).
120+
For production, you should follow the [deployment guide](./docs/deployment.md) and read the [security guide](./docs/security-guide/security-guide.md).
121121

122122
## Deploy an App
123123
Open the dstack-vmm webpage [http://localhost:9080](http://localhost:9080)(change the port according to your configuration) on your local machine to deploy a `docker-compose.yaml` file:

docs/security-guide/security-guide.md

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,21 @@ This document describes security considerations for deploying dstack apps in pro
77
When deploying applications in a TEE environment, it's critical to ensure the integrity and immutability of your container images. Using image digests (SHA256 hashes) instead of tags cryptographically ensures that the exact same image is always pulled, preventing supply chain attacks. This proves to users that your App is anchored to a specific code version.
88

99
❌ Bad example:
10+
1011
```yaml
1112
services:
1213
nginx:
13-
image: nginx
14+
image: nginx:latest
15+
```
16+
17+
```yaml
18+
services:
19+
nginx:
20+
image: nginx:1.27.5
1421
```
1522
1623
✅ Good example:
24+
1725
```yaml
1826
services:
1927
nginx:
@@ -25,6 +33,7 @@ services:
2533
If your App is intended for end users who need to verify what code your App is running, then the verifiability of Docker images is crucial. Dstack anchors the code running inside the CVM through the hash of app-compose.json. However, at the same time, the App needs to provide users with a reproducible build method. There are multiple ways to achieve reproducible image builds, and dstack provides a reference example: [dstack-ingress](https://github.com/Dstack-TEE/dstack-examples/tree/main/custom-domain/dstack-ingress)
2634
2735
## Authenticated envs and user_config
36+
2837
Dstack provides encrypted environment variable functionality. Although the CVM physical machine controller cannot view encrypted environment variables, they may forge encrypted environment variables because the CVM encryption public key is known to everyone. Therefore, Apps need to perform auth checks on encrypted environment variables at the application layer. LAUNCH_TOKEN pattern is one method to prevent unauthorized envs replacement. For details, refer to the deployment script of [dstack-gateway](https://github.com/Dstack-TEE/dstack/blob/1b8a4516826b02f9d7f747eddac244dcd68fc325/gateway/dstack-app/deploy-to-vmm.sh#L150-L165).
2938
3039
If you use dstack-vmm's built-in UI, the prelaunch script has already been automatically filled in for you:
@@ -37,9 +46,14 @@ You only need to add the `APP_LAUNCH_TOKEN` environment variable to enable LAUNC
3746

3847
user_config is not encrypted, and similarly requires integrity checks at the application layer. For example, you can store a USER_CONFIG_HASH in encrypted environment variables and verify it in the prelaunch script.
3948

40-
## app-compose.json is public by default
41-
CVM needs to ensure verifiability, so app-compose.json is public by default, containing the prelaunch script and docker-compose.yaml. You can disable exposing app-compose.json by setting public_tcbinfo=false in app-compose.json.
49+
## Don't put secrets in docker-compose.yaml
50+
51+
CVM needs to ensure verifiability, so app-compose.json is public by default, containing the prelaunch script and docker-compose.yaml.
52+
You should not put secrets in docker-compose.yaml for best security practice. Use encrypted environment variables instead.
53+
54+
In case by any chance you really do not want to expose your compose file, you can disable exposing app-compose.json by setting public_tcbinfo=false in app-compose.json.
4255
Example app-compose.json:
56+
4357
```json
4458
{
4559
...
@@ -48,9 +62,13 @@ Example app-compose.json:
4862
}
4963
```
5064

65+
**But keep in mind, even if you disable exposing app-compose.json, it is just hidden from the public API, the physical machine controller can still access it on the file system.**
66+
5167
## docker logs is public available by default
68+
5269
Similarly, to facilitate App observability, docker logs are public by default. You can disable exposing docker logs by setting public_logs=false.
5370
Example app-compose.json:
71+
5472
```json
5573
{
5674
...
@@ -66,6 +84,7 @@ In Dstack CVM, dstack-guest-agent listens on port 8090, allowing public access t
6684
In docker-compose.yaml, all declared ports will be exposed to the public internet. Do not expose unnecessary ports.
6785

6886
For example:
87+
6988
```yaml
7089
# This will expose port 80 to the public
7190
services:
@@ -92,11 +111,11 @@ services:
92111
```
93112

94113
Note that when setting network_mode: host, all ports listened to within the container will be exposed to the public internet.
114+
95115
```yaml
96116
# This will expose port 80 to the public
97117
services:
98118
nginx:
99119
image: nginx@sha256:eee5eae48e79b2e75178328c7c585b89d676eaae616f03f9a1813aaed820745a
100120
network_mode: host
101121
```
102-

0 commit comments

Comments
 (0)