-
-
Notifications
You must be signed in to change notification settings - Fork 229
[Docs]: Tenant isolation guide #3913
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jvstme
wants to merge
2
commits into
master
Choose a base branch
from
tenant_isolation_guide
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+102
−10
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| --- | ||
| title: Tenant isolation | ||
| description: Restricting access to hosts managed by dstack | ||
| --- | ||
|
|
||
| # Tenant isolation | ||
|
|
||
| `dstack` assumes mutual trust between users of the same project. While users' jobs run in Docker containers, users and their containers may have broad access to the underlying hosts. This guide explains how to restrict access to the host when stronger boundaries are required. | ||
|
|
||
| !!! info "Disclaimer" | ||
| Even with all precautions, complete isolation on shared hardware is hardly achievable — container escape vulnerabilities are common. The best way to provide true isolation between users is to place them in different `dstack` projects and not share hardware between them. | ||
|
|
||
| ## Host SSH access | ||
|
|
||
| While attached to a run, users can SSH directly into the host machine — not just the container — using: | ||
|
|
||
| ```shell | ||
| ssh <run-name>-host | ||
| ``` | ||
|
|
||
| This gives unrestricted access to the underlying instance, bypassing container boundaries. | ||
|
|
||
| If desired, host SSH access can be disabled server-wide by configuring the [SSH proxy](server-deployment.md#ssh-proxy) and setting the following environment variable when starting the `dstack` server: | ||
|
|
||
| ```shell | ||
| DSTACK_SERVER_SSHPROXY_ENFORCED=1 | ||
| ``` | ||
|
|
||
| With this setting, all users' SSH connections go through the SSH proxy, which only allows connections into the container and not into the host. | ||
|
|
||
| ## Privileged mode | ||
|
|
||
| Running a container in privileged mode gives it full access to the host kernel, making container escape straightforward. `dstack` supports requesting privileged mode through several configuration properties: | ||
|
|
||
| | Property | Applies to | | ||
| |---|---| | ||
| | `privileged: true` | Tasks, dev environments, services | | ||
| | `docker: true` | Tasks, dev environments, services | | ||
| | `replicas[i].privileged: true` | Services with replica groups | | ||
| | `replicas[i].docker: true` | Services with replica groups | | ||
|
|
||
| To block runs that request privileged mode, write a [REST plugin](../reference/plugins/rest/index.md) or a [Python plugin](../reference/plugins/python/index.md) with an apply policy. | ||
|
|
||
| <div editor-title="src/isolation_plugin/__init__.py"> | ||
|
|
||
| ```python | ||
| class NoPrivilegedPolicy(ApplyPolicy): | ||
| def on_run_apply(self, user: str, project: str, spec: RunSpec) -> RunSpec: | ||
| conf = spec.configuration | ||
|
|
||
| if conf.privileged or conf.docker: | ||
| raise ValueError("Privileged mode and Docker-in-Docker are not allowed") | ||
|
|
||
| if isinstance(conf, ServiceConfiguration) and isinstance(conf.replicas, list): | ||
| for group in conf.replicas: | ||
| if group.privileged or group.docker: | ||
| raise ValueError( | ||
| f"Replica group '{group.name}' requests privileged mode, which is not allowed" | ||
| ) | ||
|
|
||
| return spec | ||
| ``` | ||
|
|
||
| </div> | ||
|
|
||
| ## Instance volumes | ||
|
|
||
| [Instance volumes](../concepts/volumes.md#instance-volumes) mount a path from the host filesystem directly into the container. A user with access to this feature can mount arbitrary host paths — including sensitive directories such as `/etc`, `/proc`, or `/var`. | ||
|
|
||
| You can disallow instance volumes or restrict access to certain paths by writing a [REST plugin](../reference/plugins/rest/index.md) or a [Python plugin](../reference/plugins/python/index.md). | ||
|
|
||
| ## Host network access | ||
|
|
||
| By default, most `dstack` jobs run in host networking mode, sharing the network namespace of the instance. This is significant because the instance also runs internal `dstack` services — including APIs used to manage containers and SSH authorized keys. A container on the host network can reach these APIs. | ||
|
|
||
| The `DSTACK_SERVER_JOB_NETWORK_MODE` environment variable controls which jobs get host vs. bridge networking: | ||
|
|
||
| | Value | Name | Behavior | | ||
| |---|---|---| | ||
| | `1` | `HOST_FOR_MULTINODE_ONLY` | Host for distributed tasks, bridge otherwise | | ||
| | `2` | `HOST_WHEN_POSSIBLE` | Host whenever the job occupies a full instance (default) | | ||
| | `3` | `FORCED_BRIDGE` | Always bridge, including distributed tasks | | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Must be explicit that this prevents both distributed tasks and PD disaggregation to work |
||
|
|
||
| ### No distributed tasks | ||
|
|
||
| If you don't need distributed tasks or other runs with inter-job communication, set `DSTACK_SERVER_JOB_NETWORK_MODE=3` when starting the server: | ||
|
|
||
| ```shell | ||
| DSTACK_SERVER_JOB_NETWORK_MODE=3 | ||
| ``` | ||
|
|
||
| This forces bridge networking for all jobs on the server without exception, preventing access to internal `dstack` APIs. | ||
|
|
||
| ### Allow distributed tasks in selected projects | ||
|
|
||
| If you want distributed tasks or other runs with inter-job communication to be available in some projects but not others, use `DSTACK_SERVER_JOB_NETWORK_MODE=1` instead. With this mode, single-node jobs get bridge networking, while distributed tasks still run with host networking. They can then be selectively blocked per project or user by writing a [REST plugin](../reference/plugins/rest/index.md) or a [Python plugin](../reference/plugins/python/index.md). | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DOn't we want to include a guide on how to set up SSH proxy here?