docker-mcp-guardian 0.1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- docker_mcp_guardian-0.1.1/.gitignore +5 -0
- docker_mcp_guardian-0.1.1/LICENSE +21 -0
- docker_mcp_guardian-0.1.1/PKG-INFO +202 -0
- docker_mcp_guardian-0.1.1/README.md +171 -0
- docker_mcp_guardian-0.1.1/SECURITY.md +35 -0
- docker_mcp_guardian-0.1.1/docker_mcp_guardian/__init__.py +3 -0
- docker_mcp_guardian-0.1.1/docker_mcp_guardian/__main__.py +3 -0
- docker_mcp_guardian-0.1.1/docker_mcp_guardian/server.py +393 -0
- docker_mcp_guardian-0.1.1/pyproject.toml +71 -0
- docker_mcp_guardian-0.1.1/tests/test_server.py +482 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Siva Sai Krishna Suryadevara
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: docker-mcp-guardian
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: Read-only-by-default Docker MCP server: inspect, logs and gated restarts with secret redaction.
|
|
5
|
+
Project-URL: Homepage, https://github.com/SivaSaiKrishnaSuryadevara/docker-mcp-guardian
|
|
6
|
+
Project-URL: Source, https://github.com/SivaSaiKrishnaSuryadevara/docker-mcp-guardian
|
|
7
|
+
Project-URL: Issues, https://github.com/SivaSaiKrishnaSuryadevara/docker-mcp-guardian/issues
|
|
8
|
+
Project-URL: Security, https://github.com/SivaSaiKrishnaSuryadevara/docker-mcp-guardian/security/policy
|
|
9
|
+
Author: Siva Sai Krishna Suryadevara
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: ai-agents,docker,mcp,model-context-protocol,security
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Environment :: Console
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Intended Audience :: System Administrators
|
|
17
|
+
Classifier: Operating System :: MacOS
|
|
18
|
+
Classifier: Operating System :: POSIX
|
|
19
|
+
Classifier: Programming Language :: Python :: 3
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
23
|
+
Classifier: Topic :: Security
|
|
24
|
+
Classifier: Topic :: System :: Systems Administration
|
|
25
|
+
Requires-Python: >=3.10
|
|
26
|
+
Requires-Dist: docker>=7.2.0
|
|
27
|
+
Requires-Dist: mcp<2,>=1.30.0
|
|
28
|
+
Requires-Dist: pydantic>=2.14.1
|
|
29
|
+
Requires-Dist: regex>=2026.9.29
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
|
|
32
|
+
# Docker MCP Guardian
|
|
33
|
+
|
|
34
|
+
<!-- mcp-name: io.github.SivaSaiKrishnaSuryadevara/docker-mcp-guardian -->
|
|
35
|
+
|
|
36
|
+
A security-hardened Model Context Protocol (MCP) server written in Python with FastMCP that connects local LLM agents (Claude Desktop, Claude Code) to the Docker daemon with strict zero-trust boundaries.
|
|
37
|
+
|
|
38
|
+
[](https://github.com/SivaSaiKrishnaSuryadevara/docker-mcp-guardian/actions)
|
|
39
|
+
[](https://opensource.org/licenses/MIT)
|
|
40
|
+
|
|
41
|
+
## Core Capabilities & Safeguards
|
|
42
|
+
|
|
43
|
+
- **Read-Only by Default:** Mutation tools (`safe_restart_container`) reject calls before touching the Docker socket unless `GUARDIAN_ALLOW_WRITE=true` is explicitly set.
|
|
44
|
+
- **Canonical ID Resolution:** Resolves container IDs to Docker's internal canonical name before evaluating regex denylists, preventing evasion via hex IDs.
|
|
45
|
+
- **Credential & Secret Redaction:** `inspect_container` strips all environment variable values, returning only variable keys to prevent LLM prompt leakage.
|
|
46
|
+
- **Isolated Stdio JSON-RPC:** Strict logging separation ensures zero unstructured stdout writes, preventing JSON-RPC stream corruption in MCP clients.
|
|
47
|
+
- **Bounded Daemon Timeouts:** Every Docker API call is capped by `GUARDIAN_DOCKER_TIMEOUT` (default 5s), so a wedged or missing daemon returns a structured `daemon_unavailable` error instead of hanging the session.
|
|
48
|
+
|
|
49
|
+
## Quickstart
|
|
50
|
+
|
|
51
|
+
### Prerequisites
|
|
52
|
+
- Python 3.10+
|
|
53
|
+
- Docker Engine / Docker Desktop
|
|
54
|
+
- [uv](https://docs.astral.sh/uv/) for the one-line install, or Docker to run the container
|
|
55
|
+
|
|
56
|
+
### Install with uvx (recommended)
|
|
57
|
+
|
|
58
|
+
`uvx` downloads and runs the latest release from [PyPI](https://pypi.org/project/docker-mcp-guardian/); there is nothing to clone. Set `DOCKER_HOST` to your Docker socket (see [Docker endpoint resolution](#docker-endpoint-resolution)):
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
# Claude Code, with Docker Desktop on macOS
|
|
62
|
+
claude mcp add docker-guardian -e DOCKER_HOST="unix://$HOME/.docker/run/docker.sock" -- uvx docker-mcp-guardian
|
|
63
|
+
|
|
64
|
+
# Claude Code, with rootless Docker on Linux
|
|
65
|
+
claude mcp add docker-guardian -e DOCKER_HOST="unix://$XDG_RUNTIME_DIR/docker.sock" -- uvx docker-mcp-guardian
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Claude Desktop, Cursor and other clients (`mcpServers` in their JSON config; write the socket path literally):
|
|
69
|
+
|
|
70
|
+
```json
|
|
71
|
+
{
|
|
72
|
+
"mcpServers": {
|
|
73
|
+
"docker-guardian": {
|
|
74
|
+
"command": "uvx",
|
|
75
|
+
"args": ["docker-mcp-guardian"],
|
|
76
|
+
"env": { "DOCKER_HOST": "unix:///Users/you/.docker/run/docker.sock" }
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Run the container
|
|
83
|
+
|
|
84
|
+
The signed image from GHCR finds the mounted socket's group on its own:
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
claude mcp add docker-guardian -- docker run --rm -i \
|
|
88
|
+
-v /var/run/docker.sock:/var/run/docker.sock \
|
|
89
|
+
-e GUARDIAN_ALLOW_ROOTFUL=true \
|
|
90
|
+
ghcr.io/sivasaikrishnasuryadevara/docker-mcp-guardian:latest
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Install from source
|
|
94
|
+
```bash
|
|
95
|
+
git clone https://github.com/SivaSaiKrishnaSuryadevara/docker-mcp-guardian.git
|
|
96
|
+
cd docker-mcp-guardian
|
|
97
|
+
python3 -m venv .venv
|
|
98
|
+
source .venv/bin/activate
|
|
99
|
+
pip install -r requirements.txt
|
|
100
|
+
pytest tests/ -v
|
|
101
|
+
|
|
102
|
+
# connect it to Claude Code
|
|
103
|
+
claude mcp add docker-guardian -- "$PWD/.venv/bin/python" "$PWD/server.py"
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
For Claude Desktop, add the same interpreter and script paths (absolute) under `mcpServers` in `claude_desktop_config.json`.
|
|
107
|
+
|
|
108
|
+
## Configuration
|
|
109
|
+
|
|
110
|
+
| Variable | Default | Purpose |
|
|
111
|
+
|---|---|---|
|
|
112
|
+
| `GUARDIAN_ALLOW_WRITE` | `false` | Must be `true` for `safe_restart_container` to do anything |
|
|
113
|
+
| `GUARDIAN_RESTART_DENY_REGEX` | `^(prod\|db\|kube\|vault)-.*` | Containers that can never be restarted (always wins) |
|
|
114
|
+
| `GUARDIAN_RESTART_ALLOW_REGEX` | *(unset)* | If set, only matching containers can be restarted |
|
|
115
|
+
| `GUARDIAN_ANOMALY_REGEX` | error/exception/fatal/... | Pattern the log scanner flags |
|
|
116
|
+
| `GUARDIAN_REGEX_TIMEOUT` | `1` | Total seconds one log scan may spend matching; slower scans return `regex_timeout` |
|
|
117
|
+
| `GUARDIAN_DOCKER_TIMEOUT` | `5` | Seconds per Docker API call |
|
|
118
|
+
| `GUARDIAN_LOG_LEVEL` | `INFO` | Log level (logs go to stderr only) |
|
|
119
|
+
| `DOCKER_HOST` | *(unset)* | Docker endpoint to use; always wins when set |
|
|
120
|
+
| `GUARDIAN_ALLOW_ROOTFUL` | `false` | Allow falling back to the rootful `/var/run/docker.sock` |
|
|
121
|
+
|
|
122
|
+
### Docker endpoint resolution
|
|
123
|
+
|
|
124
|
+
Guardian picks its Docker endpoint in this order, and logs the choice to stderr:
|
|
125
|
+
|
|
126
|
+
1. `DOCKER_HOST`, if set.
|
|
127
|
+
2. A rootless Docker socket: `$XDG_RUNTIME_DIR/docker.sock`, then `/run/user/<uid>/docker.sock`. The second path covers MCP clients that start servers without `XDG_RUNTIME_DIR`.
|
|
128
|
+
3. The rootful `/var/run/docker.sock`, only when `GUARDIAN_ALLOW_ROOTFUL=true`. Guardian logs a warning, because rootful API access is root-equivalent.
|
|
129
|
+
|
|
130
|
+
If none applies, tools return a `docker_socket_unresolved` error instead of connecting. The system socket is never used while a rootless socket exists.
|
|
131
|
+
|
|
132
|
+
> **Upgrading:** earlier versions fell back to `/var/run/docker.sock` silently. If you rely on the rootful daemon, set `DOCKER_HOST=unix:///var/run/docker.sock` (or `GUARDIAN_ALLOW_ROOTFUL=true`) in your MCP server definition. Docker Desktop and Colima users should set `DOCKER_HOST` to their socket, for example `unix://$HOME/.docker/run/docker.sock` or `unix://$HOME/.colima/default/docker.sock`.
|
|
133
|
+
|
|
134
|
+
### Rootless Docker
|
|
135
|
+
|
|
136
|
+
MCP clients (Claude Desktop, Claude Code, Cursor, Cline) start Guardian as a child process, often with a reduced environment that has no `XDG_RUNTIME_DIR` or `DOCKER_HOST`. Guardian still checks `/run/user/<uid>/docker.sock`, but if your rootless runtime directory is elsewhere, or you want the endpoint pinned, set `DOCKER_HOST` in the server definition:
|
|
137
|
+
|
|
138
|
+
```json
|
|
139
|
+
{
|
|
140
|
+
"mcpServers": {
|
|
141
|
+
"docker-guardian": {
|
|
142
|
+
"command": "/path/to/docker-mcp-guardian/.venv/bin/python",
|
|
143
|
+
"args": ["/path/to/docker-mcp-guardian/server.py"],
|
|
144
|
+
"env": {
|
|
145
|
+
"DOCKER_HOST": "unix:///run/user/1000/docker.sock"
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
Write the path literally: most clients do not expand `$XDG_RUNTIME_DIR` or `$HOME` in `env`. To find the value for your user, run either of these in a shell where rootless Docker works:
|
|
153
|
+
|
|
154
|
+
```bash
|
|
155
|
+
echo "unix://$XDG_RUNTIME_DIR/docker.sock"
|
|
156
|
+
docker context inspect rootless --format '{{.Endpoints.docker.Host}}'
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
With Claude Code, the shell expands the variable when the server is added:
|
|
160
|
+
|
|
161
|
+
```bash
|
|
162
|
+
claude mcp add docker-guardian -e DOCKER_HOST="unix://$XDG_RUNTIME_DIR/docker.sock" -- "$PWD/.venv/bin/python" "$PWD/server.py"
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
To confirm the endpoint is the rootless daemon, check that this lists `name=rootless`:
|
|
166
|
+
|
|
167
|
+
```bash
|
|
168
|
+
DOCKER_HOST=unix:///run/user/1000/docker.sock docker info --format '{{.SecurityOptions}}'
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
On the first tool call, Guardian logs the endpoint it chose to stderr, for example `Using Docker endpoint unix:///run/user/1000/docker.sock (DOCKER_HOST is set).`
|
|
172
|
+
|
|
173
|
+
## Verifying Release Images
|
|
174
|
+
|
|
175
|
+
Release images are published to `ghcr.io/sivasaikrishnasuryadevara/docker-mcp-guardian` for `linux/amd64` and `linux/arm64` by [`release-signed.yml`](.github/workflows/release-signed.yml) when a `v*.*.*` tag is pushed. Each image is:
|
|
176
|
+
|
|
177
|
+
- **signed** with keyless [Sigstore cosign](https://docs.sigstore.dev/): the signing certificate is bound to this repository's release workflow through GitHub OIDC, and the signature is recorded in the public Rekor transparency log. No signing key exists to leak.
|
|
178
|
+
- **attested** with a [GitHub build provenance attestation](https://docs.github.com/en/actions/security-for-github-actions/using-artifact-attestations) (SLSA provenance) for the same image digest.
|
|
179
|
+
|
|
180
|
+
Verify both before running an image (requires cosign 3.x and the GitHub CLI):
|
|
181
|
+
|
|
182
|
+
```bash
|
|
183
|
+
IMAGE=ghcr.io/sivasaikrishnasuryadevara/docker-mcp-guardian:<version> # e.g. 1.0.0
|
|
184
|
+
|
|
185
|
+
# 1. Sigstore signature: issued to this repository's release workflow, for a version tag.
|
|
186
|
+
cosign verify "$IMAGE" \
|
|
187
|
+
--certificate-oidc-issuer https://token.actions.githubusercontent.com \
|
|
188
|
+
--certificate-identity-regexp '^https://github\.com/SivaSaiKrishnaSuryadevara/docker-mcp-guardian/\.github/workflows/release-signed\.yml@refs/tags/v'
|
|
189
|
+
|
|
190
|
+
# 2. Build provenance: built by this repository's GitHub Actions workflow.
|
|
191
|
+
gh attestation verify "oci://$IMAGE" --repo SivaSaiKrishnaSuryadevara/docker-mcp-guardian
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
Both commands exit non-zero if the image was not built and signed by this repository's release workflow. To run exactly what you verified, pull by digest: `docker pull ghcr.io/sivasaikrishnasuryadevara/docker-mcp-guardian@sha256:<digest>`, using the digest that `cosign verify` prints.
|
|
195
|
+
|
|
196
|
+
## Write-up
|
|
197
|
+
|
|
198
|
+
The security model, tool surface, and policy engine are documented in [docs/SECURITY_ARCHITECTURE.md](docs/SECURITY_ARCHITECTURE.md).
|
|
199
|
+
|
|
200
|
+
## Deep Dive & Publications
|
|
201
|
+
|
|
202
|
+
- **[Don't Hand Claude Your Docker Socket — Build It a Guarded One](https://hackernoon.com/dont-hand-claude-your-docker-socket-build-it-a-guarded-one)** (HackerNoon, October 21, 2026): why handing an AI agent the raw Docker socket is root-equivalent, and how this server's read-only default, canonical-name restart deny-list, secret redaction and bounded Docker API timeouts contain it.
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
# Docker MCP Guardian
|
|
2
|
+
|
|
3
|
+
<!-- mcp-name: io.github.SivaSaiKrishnaSuryadevara/docker-mcp-guardian -->
|
|
4
|
+
|
|
5
|
+
A security-hardened Model Context Protocol (MCP) server written in Python with FastMCP that connects local LLM agents (Claude Desktop, Claude Code) to the Docker daemon with strict zero-trust boundaries.
|
|
6
|
+
|
|
7
|
+
[](https://github.com/SivaSaiKrishnaSuryadevara/docker-mcp-guardian/actions)
|
|
8
|
+
[](https://opensource.org/licenses/MIT)
|
|
9
|
+
|
|
10
|
+
## Core Capabilities & Safeguards
|
|
11
|
+
|
|
12
|
+
- **Read-Only by Default:** Mutation tools (`safe_restart_container`) reject calls before touching the Docker socket unless `GUARDIAN_ALLOW_WRITE=true` is explicitly set.
|
|
13
|
+
- **Canonical ID Resolution:** Resolves container IDs to Docker's internal canonical name before evaluating regex denylists, preventing evasion via hex IDs.
|
|
14
|
+
- **Credential & Secret Redaction:** `inspect_container` strips all environment variable values, returning only variable keys to prevent LLM prompt leakage.
|
|
15
|
+
- **Isolated Stdio JSON-RPC:** Strict logging separation ensures zero unstructured stdout writes, preventing JSON-RPC stream corruption in MCP clients.
|
|
16
|
+
- **Bounded Daemon Timeouts:** Every Docker API call is capped by `GUARDIAN_DOCKER_TIMEOUT` (default 5s), so a wedged or missing daemon returns a structured `daemon_unavailable` error instead of hanging the session.
|
|
17
|
+
|
|
18
|
+
## Quickstart
|
|
19
|
+
|
|
20
|
+
### Prerequisites
|
|
21
|
+
- Python 3.10+
|
|
22
|
+
- Docker Engine / Docker Desktop
|
|
23
|
+
- [uv](https://docs.astral.sh/uv/) for the one-line install, or Docker to run the container
|
|
24
|
+
|
|
25
|
+
### Install with uvx (recommended)
|
|
26
|
+
|
|
27
|
+
`uvx` downloads and runs the latest release from [PyPI](https://pypi.org/project/docker-mcp-guardian/); there is nothing to clone. Set `DOCKER_HOST` to your Docker socket (see [Docker endpoint resolution](#docker-endpoint-resolution)):
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
# Claude Code, with Docker Desktop on macOS
|
|
31
|
+
claude mcp add docker-guardian -e DOCKER_HOST="unix://$HOME/.docker/run/docker.sock" -- uvx docker-mcp-guardian
|
|
32
|
+
|
|
33
|
+
# Claude Code, with rootless Docker on Linux
|
|
34
|
+
claude mcp add docker-guardian -e DOCKER_HOST="unix://$XDG_RUNTIME_DIR/docker.sock" -- uvx docker-mcp-guardian
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Claude Desktop, Cursor and other clients (`mcpServers` in their JSON config; write the socket path literally):
|
|
38
|
+
|
|
39
|
+
```json
|
|
40
|
+
{
|
|
41
|
+
"mcpServers": {
|
|
42
|
+
"docker-guardian": {
|
|
43
|
+
"command": "uvx",
|
|
44
|
+
"args": ["docker-mcp-guardian"],
|
|
45
|
+
"env": { "DOCKER_HOST": "unix:///Users/you/.docker/run/docker.sock" }
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Run the container
|
|
52
|
+
|
|
53
|
+
The signed image from GHCR finds the mounted socket's group on its own:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
claude mcp add docker-guardian -- docker run --rm -i \
|
|
57
|
+
-v /var/run/docker.sock:/var/run/docker.sock \
|
|
58
|
+
-e GUARDIAN_ALLOW_ROOTFUL=true \
|
|
59
|
+
ghcr.io/sivasaikrishnasuryadevara/docker-mcp-guardian:latest
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Install from source
|
|
63
|
+
```bash
|
|
64
|
+
git clone https://github.com/SivaSaiKrishnaSuryadevara/docker-mcp-guardian.git
|
|
65
|
+
cd docker-mcp-guardian
|
|
66
|
+
python3 -m venv .venv
|
|
67
|
+
source .venv/bin/activate
|
|
68
|
+
pip install -r requirements.txt
|
|
69
|
+
pytest tests/ -v
|
|
70
|
+
|
|
71
|
+
# connect it to Claude Code
|
|
72
|
+
claude mcp add docker-guardian -- "$PWD/.venv/bin/python" "$PWD/server.py"
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
For Claude Desktop, add the same interpreter and script paths (absolute) under `mcpServers` in `claude_desktop_config.json`.
|
|
76
|
+
|
|
77
|
+
## Configuration
|
|
78
|
+
|
|
79
|
+
| Variable | Default | Purpose |
|
|
80
|
+
|---|---|---|
|
|
81
|
+
| `GUARDIAN_ALLOW_WRITE` | `false` | Must be `true` for `safe_restart_container` to do anything |
|
|
82
|
+
| `GUARDIAN_RESTART_DENY_REGEX` | `^(prod\|db\|kube\|vault)-.*` | Containers that can never be restarted (always wins) |
|
|
83
|
+
| `GUARDIAN_RESTART_ALLOW_REGEX` | *(unset)* | If set, only matching containers can be restarted |
|
|
84
|
+
| `GUARDIAN_ANOMALY_REGEX` | error/exception/fatal/... | Pattern the log scanner flags |
|
|
85
|
+
| `GUARDIAN_REGEX_TIMEOUT` | `1` | Total seconds one log scan may spend matching; slower scans return `regex_timeout` |
|
|
86
|
+
| `GUARDIAN_DOCKER_TIMEOUT` | `5` | Seconds per Docker API call |
|
|
87
|
+
| `GUARDIAN_LOG_LEVEL` | `INFO` | Log level (logs go to stderr only) |
|
|
88
|
+
| `DOCKER_HOST` | *(unset)* | Docker endpoint to use; always wins when set |
|
|
89
|
+
| `GUARDIAN_ALLOW_ROOTFUL` | `false` | Allow falling back to the rootful `/var/run/docker.sock` |
|
|
90
|
+
|
|
91
|
+
### Docker endpoint resolution
|
|
92
|
+
|
|
93
|
+
Guardian picks its Docker endpoint in this order, and logs the choice to stderr:
|
|
94
|
+
|
|
95
|
+
1. `DOCKER_HOST`, if set.
|
|
96
|
+
2. A rootless Docker socket: `$XDG_RUNTIME_DIR/docker.sock`, then `/run/user/<uid>/docker.sock`. The second path covers MCP clients that start servers without `XDG_RUNTIME_DIR`.
|
|
97
|
+
3. The rootful `/var/run/docker.sock`, only when `GUARDIAN_ALLOW_ROOTFUL=true`. Guardian logs a warning, because rootful API access is root-equivalent.
|
|
98
|
+
|
|
99
|
+
If none applies, tools return a `docker_socket_unresolved` error instead of connecting. The system socket is never used while a rootless socket exists.
|
|
100
|
+
|
|
101
|
+
> **Upgrading:** earlier versions fell back to `/var/run/docker.sock` silently. If you rely on the rootful daemon, set `DOCKER_HOST=unix:///var/run/docker.sock` (or `GUARDIAN_ALLOW_ROOTFUL=true`) in your MCP server definition. Docker Desktop and Colima users should set `DOCKER_HOST` to their socket, for example `unix://$HOME/.docker/run/docker.sock` or `unix://$HOME/.colima/default/docker.sock`.
|
|
102
|
+
|
|
103
|
+
### Rootless Docker
|
|
104
|
+
|
|
105
|
+
MCP clients (Claude Desktop, Claude Code, Cursor, Cline) start Guardian as a child process, often with a reduced environment that has no `XDG_RUNTIME_DIR` or `DOCKER_HOST`. Guardian still checks `/run/user/<uid>/docker.sock`, but if your rootless runtime directory is elsewhere, or you want the endpoint pinned, set `DOCKER_HOST` in the server definition:
|
|
106
|
+
|
|
107
|
+
```json
|
|
108
|
+
{
|
|
109
|
+
"mcpServers": {
|
|
110
|
+
"docker-guardian": {
|
|
111
|
+
"command": "/path/to/docker-mcp-guardian/.venv/bin/python",
|
|
112
|
+
"args": ["/path/to/docker-mcp-guardian/server.py"],
|
|
113
|
+
"env": {
|
|
114
|
+
"DOCKER_HOST": "unix:///run/user/1000/docker.sock"
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Write the path literally: most clients do not expand `$XDG_RUNTIME_DIR` or `$HOME` in `env`. To find the value for your user, run either of these in a shell where rootless Docker works:
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
echo "unix://$XDG_RUNTIME_DIR/docker.sock"
|
|
125
|
+
docker context inspect rootless --format '{{.Endpoints.docker.Host}}'
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
With Claude Code, the shell expands the variable when the server is added:
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
claude mcp add docker-guardian -e DOCKER_HOST="unix://$XDG_RUNTIME_DIR/docker.sock" -- "$PWD/.venv/bin/python" "$PWD/server.py"
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
To confirm the endpoint is the rootless daemon, check that this lists `name=rootless`:
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
DOCKER_HOST=unix:///run/user/1000/docker.sock docker info --format '{{.SecurityOptions}}'
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
On the first tool call, Guardian logs the endpoint it chose to stderr, for example `Using Docker endpoint unix:///run/user/1000/docker.sock (DOCKER_HOST is set).`
|
|
141
|
+
|
|
142
|
+
## Verifying Release Images
|
|
143
|
+
|
|
144
|
+
Release images are published to `ghcr.io/sivasaikrishnasuryadevara/docker-mcp-guardian` for `linux/amd64` and `linux/arm64` by [`release-signed.yml`](.github/workflows/release-signed.yml) when a `v*.*.*` tag is pushed. Each image is:
|
|
145
|
+
|
|
146
|
+
- **signed** with keyless [Sigstore cosign](https://docs.sigstore.dev/): the signing certificate is bound to this repository's release workflow through GitHub OIDC, and the signature is recorded in the public Rekor transparency log. No signing key exists to leak.
|
|
147
|
+
- **attested** with a [GitHub build provenance attestation](https://docs.github.com/en/actions/security-for-github-actions/using-artifact-attestations) (SLSA provenance) for the same image digest.
|
|
148
|
+
|
|
149
|
+
Verify both before running an image (requires cosign 3.x and the GitHub CLI):
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
IMAGE=ghcr.io/sivasaikrishnasuryadevara/docker-mcp-guardian:<version> # e.g. 1.0.0
|
|
153
|
+
|
|
154
|
+
# 1. Sigstore signature: issued to this repository's release workflow, for a version tag.
|
|
155
|
+
cosign verify "$IMAGE" \
|
|
156
|
+
--certificate-oidc-issuer https://token.actions.githubusercontent.com \
|
|
157
|
+
--certificate-identity-regexp '^https://github\.com/SivaSaiKrishnaSuryadevara/docker-mcp-guardian/\.github/workflows/release-signed\.yml@refs/tags/v'
|
|
158
|
+
|
|
159
|
+
# 2. Build provenance: built by this repository's GitHub Actions workflow.
|
|
160
|
+
gh attestation verify "oci://$IMAGE" --repo SivaSaiKrishnaSuryadevara/docker-mcp-guardian
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
Both commands exit non-zero if the image was not built and signed by this repository's release workflow. To run exactly what you verified, pull by digest: `docker pull ghcr.io/sivasaikrishnasuryadevara/docker-mcp-guardian@sha256:<digest>`, using the digest that `cosign verify` prints.
|
|
164
|
+
|
|
165
|
+
## Write-up
|
|
166
|
+
|
|
167
|
+
The security model, tool surface, and policy engine are documented in [docs/SECURITY_ARCHITECTURE.md](docs/SECURITY_ARCHITECTURE.md).
|
|
168
|
+
|
|
169
|
+
## Deep Dive & Publications
|
|
170
|
+
|
|
171
|
+
- **[Don't Hand Claude Your Docker Socket — Build It a Guarded One](https://hackernoon.com/dont-hand-claude-your-docker-socket-build-it-a-guarded-one)** (HackerNoon, October 21, 2026): why handing an AI agent the raw Docker socket is root-equivalent, and how this server's read-only default, canonical-name restart deny-list, secret redaction and bounded Docker API timeouts contain it.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Security Policy
|
|
2
|
+
|
|
3
|
+
## Reporting a vulnerability
|
|
4
|
+
|
|
5
|
+
Please report vulnerabilities privately through a [GitHub security advisory](https://github.com/SivaSaiKrishnaSuryadevara/docker-mcp-guardian/security/advisories/new). Do not open a public issue, pull request, or discussion for an unfixed vulnerability.
|
|
6
|
+
|
|
7
|
+
Include what an attacker controls (the agent's tool arguments, a container's logs or labels, the server's environment), the steps to reproduce, and the impact. A failing test case is the most useful form.
|
|
8
|
+
|
|
9
|
+
You can expect an acknowledgement within 5 business days and an assessment within 14 days. Fixes are developed in the private advisory, released, and then disclosed with credit to the reporter unless you prefer otherwise.
|
|
10
|
+
|
|
11
|
+
## Supported versions
|
|
12
|
+
|
|
13
|
+
| Version | Supported |
|
|
14
|
+
|---|---|
|
|
15
|
+
| `main` | Yes |
|
|
16
|
+
| Latest release | Yes |
|
|
17
|
+
| Older releases | No; upgrade to the latest release |
|
|
18
|
+
|
|
19
|
+
## Threat model
|
|
20
|
+
|
|
21
|
+
The full model is in [docs/SECURITY_ARCHITECTURE.md](docs/SECURITY_ARCHITECTURE.md). In short:
|
|
22
|
+
|
|
23
|
+
**Guardian defends against** an LLM agent, or content an agent reads, steering the agent beyond the four tools Guardian exposes. In scope:
|
|
24
|
+
|
|
25
|
+
- bypassing the read-only write gate or the restart deny and allow policy
|
|
26
|
+
- tool arguments that reach the Docker API unvalidated
|
|
27
|
+
- secrets returned that the tools are documented to withhold, such as environment variable values
|
|
28
|
+
- tool calls that hang the server, exhaust its memory, or corrupt the stdio JSON-RPC stream
|
|
29
|
+
- Guardian connecting to the rootful Docker socket without `DOCKER_HOST` or `GUARDIAN_ALLOW_ROOTFUL`
|
|
30
|
+
|
|
31
|
+
**Out of scope:**
|
|
32
|
+
|
|
33
|
+
- Anyone who can already set Guardian's environment or open the Docker socket directly. Docker API access is root-equivalent, and Guardian is not a socket proxy.
|
|
34
|
+
- Secrets that containers write to their own logs. `get_container_logs` returns log lines verbatim; this is a documented limitation.
|
|
35
|
+
- Vulnerabilities in Docker, the MCP client, or third-party dependencies, unless Guardian's use of them makes the issue exploitable. Please report those upstream.
|