dmint-cli 0.2.0__tar.gz → 1.0.0__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.
- dmint_cli-1.0.0/CHANGELOG.md +69 -0
- dmint_cli-1.0.0/MANIFEST.in +12 -0
- dmint_cli-1.0.0/PKG-INFO +502 -0
- dmint_cli-1.0.0/README.md +477 -0
- dmint_cli-1.0.0/pyproject.toml +46 -0
- dmint_cli-1.0.0/setup.py +3 -0
- dmint_cli-1.0.0/src/dmint_cli/__init__.py +54 -0
- dmint_cli-1.0.0/src/dmint_cli/__main__.py +149 -0
- {dmint_cli-0.2.0 → dmint_cli-1.0.0}/src/dmint_cli/api.py +18 -8
- dmint_cli-1.0.0/src/dmint_cli/compile_policy.py +90 -0
- dmint_cli-1.0.0/src/dmint_cli/create_mcp_policy.py +822 -0
- {dmint_cli-0.2.0 → dmint_cli-1.0.0}/src/dmint_cli/create_policy.py +91 -31
- dmint_cli-1.0.0/src/dmint_cli/errors.py +77 -0
- dmint_cli-1.0.0/src/dmint_cli/install_skill.py +304 -0
- dmint_cli-1.0.0/src/dmint_cli/io_utils.py +86 -0
- dmint_cli-1.0.0/src/dmint_cli/limits.py +103 -0
- dmint_cli-1.0.0/src/dmint_cli/mcp_auth.py +546 -0
- dmint_cli-1.0.0/src/dmint_cli/mcp_connections.py +543 -0
- dmint_cli-1.0.0/src/dmint_cli/mcp_credentials.py +560 -0
- dmint_cli-1.0.0/src/dmint_cli/mcp_oauth.py +606 -0
- dmint_cli-1.0.0/src/dmint_cli/skills/__init__.py +3 -0
- dmint_cli-1.0.0/src/dmint_cli/skills/dmint-policy-manager/SKILL.md +342 -0
- {dmint_cli-0.2.0 → dmint_cli-1.0.0}/src/dmint_cli/verify_policy.py +14 -6
- dmint_cli-1.0.0/src/dmint_cli/version.py +25 -0
- dmint_cli-1.0.0/src/dmint_cli.egg-info/PKG-INFO +502 -0
- {dmint_cli-0.2.0 → dmint_cli-1.0.0}/src/dmint_cli.egg-info/SOURCES.txt +14 -4
- dmint_cli-1.0.0/src/dmint_cli.egg-info/requires.txt +5 -0
- dmint_cli-0.2.0/MANIFEST.in +0 -1
- dmint_cli-0.2.0/PKG-INFO +0 -97
- dmint_cli-0.2.0/README.md +0 -86
- dmint_cli-0.2.0/pyproject.toml +0 -24
- dmint_cli-0.2.0/src/dmint_cli/__init__.py +0 -14
- dmint_cli-0.2.0/src/dmint_cli/__main__.py +0 -78
- dmint_cli-0.2.0/src/dmint_cli/compile_policy.py +0 -192
- dmint_cli-0.2.0/src/dmint_cli.egg-info/PKG-INFO +0 -97
- dmint_cli-0.2.0/src/dmint_cli.egg-info/requires.txt +0 -1
- dmint_cli-0.2.0/tests/test_cli_api.py +0 -138
- dmint_cli-0.2.0/tests/test_compile_policy.py +0 -140
- dmint_cli-0.2.0/tests/test_create_policy.py +0 -214
- dmint_cli-0.2.0/tests/test_verify_policy.py +0 -68
- {dmint_cli-0.2.0 → dmint_cli-1.0.0}/LICENSE +0 -0
- {dmint_cli-0.2.0 → dmint_cli-1.0.0}/setup.cfg +0 -0
- {dmint_cli-0.2.0 → dmint_cli-1.0.0}/src/dmint_cli/prompts/__init__.py +0 -0
- {dmint_cli-0.2.0 → dmint_cli-1.0.0}/src/dmint_cli/prompts/policy_skill.md +0 -0
- {dmint_cli-0.2.0 → dmint_cli-1.0.0}/src/dmint_cli.egg-info/dependency_links.txt +0 -0
- {dmint_cli-0.2.0 → dmint_cli-1.0.0}/src/dmint_cli.egg-info/entry_points.txt +0 -0
- {dmint_cli-0.2.0 → dmint_cli-1.0.0}/src/dmint_cli.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to `dmint-cli` will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [1.0.0] - 2026-09-16
|
|
9
|
+
|
|
10
|
+
### Security & Hardening
|
|
11
|
+
- **Streamable HTTP SSRF & Transport Protection**:
|
|
12
|
+
- Enforced mandatory HTTPS and strict private/loopback/cloud-metadata IP filtering on streamable HTTP MCP endpoints (`validate_connection()` and `_discover_streamable_http_tools()`).
|
|
13
|
+
- **OAuth Callback Server Security**:
|
|
14
|
+
- Added strict `Host` header validation against loopback addresses to neutralize DNS rebinding attacks against local OAuth callback servers.
|
|
15
|
+
- Added hardened HTTP response headers (`Content-Security-Policy`, `X-Frame-Options`, `X-Content-Type-Options`, `Cache-Control`, `Referrer-Policy`) to OAuth completion pages.
|
|
16
|
+
- Isolated static handler state across sequential OAuth flows with guaranteed `finally` block cleanup.
|
|
17
|
+
- **Path Traversal Defenses**:
|
|
18
|
+
- Validated skill names in `dmint install-skill` against strict alphanumeric/dash/underscore whitelist pattern (`^[a-zA-Z0-9_-]+$`), preventing arbitrary file write.
|
|
19
|
+
- **SSRF Filter Enhancements**:
|
|
20
|
+
- Blocked non-standard integer/octal IPv4 representations and cloud metadata hostnames (`metadata.google.internal`, `instance-data`).
|
|
21
|
+
- **Atomic I/O Hardening**:
|
|
22
|
+
- Eliminated TOCTOU vulnerabilities and descriptor leaks in `atomic_write_json` using `os.fchmod` on open file descriptors with guaranteed cleanup.
|
|
23
|
+
|
|
24
|
+
### Added
|
|
25
|
+
- **Skill Installation (`dmint install-skill`)**:
|
|
26
|
+
- Built-in command to install the `dmint-policy-manager` agent skill into `.agents/skills` or custom directories for AI coding assistants.
|
|
27
|
+
|
|
28
|
+
## [0.3.0] - 2026-09-16
|
|
29
|
+
|
|
30
|
+
### Added
|
|
31
|
+
- **Interactive Policy Authoring (`dmint create-policy`)**:
|
|
32
|
+
- Author and refine Dmint policies from natural language developer intent (`access.md`).
|
|
33
|
+
- Safe local capability discovery via static AST parsing (`ast.parse()`) with zero code execution.
|
|
34
|
+
- Multi-turn envelope output contract with clarification questions and candidate policy reviews.
|
|
35
|
+
- Self-correcting validation loop against Dmint policy invariants on validation errors.
|
|
36
|
+
- **Specialized MCP Protection Wizard (`dmint create-mcp-policy`)**:
|
|
37
|
+
- Live discovery of downstream MCP tools over `stdio` protocol using the official MCP SDK.
|
|
38
|
+
- Namespace preservation (`mcp.{integration_id}.{tool_name}`) to isolate distinct integrations.
|
|
39
|
+
- Fail-closed validation against unsupported remote transports.
|
|
40
|
+
- Generates verified `policy.json` and multi-integration `mcp_protection.json` configuration.
|
|
41
|
+
- Retains `protect-mcp` as a documented backward-compatibility alias.
|
|
42
|
+
- **Deterministic Standalone Verification (`dmint verify-policy`)**:
|
|
43
|
+
- 100% offline, zero-network, LLM-free schema and semantic invariant validation.
|
|
44
|
+
- Deterministic exit code contracts (`0` = valid, `1` = policy error, `2` = usage/CLI error, `3` = missing file).
|
|
45
|
+
- **OAuth 2.0 & Network Hardening**:
|
|
46
|
+
- Strict RFC 7636 PKCE code challenge and verification.
|
|
47
|
+
- RFC 8414 OAuth Authorization Server Discovery and Protected Resource Metadata (PRM) resolution.
|
|
48
|
+
- Strict SSRF protection rejecting IPv4/IPv6 loopback, link-local, multicast, and cloud metadata IPs (`169.254.169.254`).
|
|
49
|
+
- Cross-origin redirect prevention during discovery to prevent credential mix-up attacks.
|
|
50
|
+
- Strict file permission enforcement (`0600`) and symlink replacement defenses for credential stores.
|
|
51
|
+
- Constant-time secret masking and redaction across all logs, exceptions, and serialized configs.
|
|
52
|
+
- **Resource Exhaustion Hardening**:
|
|
53
|
+
- Explicit bounds and limits across all dimensions: integration count, tools per server, pagination depth, name/description lengths, schema size, metadata response size, credential/policy file size, and operation timeouts.
|
|
54
|
+
- **Public Packaging & Distribution**:
|
|
55
|
+
- Clean PEP 517 / PEP 621 packaging with single source of truth in `pyproject.toml`.
|
|
56
|
+
- Intentionally pinned runtime dependencies (`dmint>=0.1.0,<0.2.0`, `mcp>=2.2.0,<3.0.0`).
|
|
57
|
+
- Verified wheel and source distribution packaging containing required prompt assets (`policy_skill.md`) and zero repository build debris.
|
|
58
|
+
- **Version Metadata Consistency**:
|
|
59
|
+
- CLI version flag (`dmint --version`, `dmint -V`, `dmint version`) reporting `dmint 0.3.0`.
|
|
60
|
+
- Canonical User-Agent derivation across HTTP clients (`api.py`, `mcp_auth.py`, `mcp_credentials.py`, `mcp_oauth.py`) bound to package version.
|
|
61
|
+
- Dynamic RFC 7591 client metadata in OAuth registration containing client name and software version.
|
|
62
|
+
|
|
63
|
+
## [0.2.0] - 2026-09-14
|
|
64
|
+
### Added
|
|
65
|
+
- Experimental policy compilation and early MCP connection prototypes.
|
|
66
|
+
|
|
67
|
+
## [0.1.0] - 2026-09-11
|
|
68
|
+
### Added
|
|
69
|
+
- Initial project scaffolding and proof-of-concept LLM policy generator.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
include README.md
|
|
2
|
+
include LICENSE
|
|
3
|
+
include CHANGELOG.md
|
|
4
|
+
include pyproject.toml
|
|
5
|
+
include setup.py
|
|
6
|
+
recursive-include src/dmint_cli/prompts *.md
|
|
7
|
+
recursive-include src/dmint_cli/skills *.md
|
|
8
|
+
exclude AGENTS.md
|
|
9
|
+
recursive-exclude tests *
|
|
10
|
+
recursive-exclude .agents *
|
|
11
|
+
recursive-exclude .github *
|
|
12
|
+
global-exclude *.py[cod] __pycache__ *.so *.dylib *.swp *.tmp *.log
|
dmint_cli-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,502 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dmint-cli
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: CLI tooling for Dmint policy creation, compilation, and management
|
|
5
|
+
Author: Dmint Authors
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
8
|
+
Classifier: Environment :: Console
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Topic :: Security
|
|
16
|
+
Classifier: Topic :: Software Development :: Compilers
|
|
17
|
+
Requires-Python: >=3.10
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE
|
|
20
|
+
Requires-Dist: dmint<0.2.0,>=0.1.0
|
|
21
|
+
Requires-Dist: mcp<3.0.0,>=2.2.0
|
|
22
|
+
Provides-Extra: test
|
|
23
|
+
Requires-Dist: pytest>=8.0.0; extra == "test"
|
|
24
|
+
Dynamic: license-file
|
|
25
|
+
|
|
26
|
+
# dmint-cli (v1.0.0)
|
|
27
|
+
|
|
28
|
+
> **Developer tooling for interactive discovery, authoring, compilation, and offline verification of Dmint security policies and MCP protection artifacts.**
|
|
29
|
+
|
|
30
|
+
`dmint-cli` bridges the gap between natural language security requirements (`access.md`) and deterministic, schema-enforced Dmint authorization policies (`policy.json`) and runtime MCP protection configurations (`mcp_protection.json`).
|
|
31
|
+
|
|
32
|
+
```text
|
|
33
|
+
dmint-cli
|
|
34
|
+
│
|
|
35
|
+
┌──────────────────────┼──────────────────────┐
|
|
36
|
+
│ │ │
|
|
37
|
+
create-policy create-mcp-policy verify-policy
|
|
38
|
+
│ │ │
|
|
39
|
+
┌──────┴──────┐ MCP Tool Discovery 100% Offline
|
|
40
|
+
│ │ │ LLM-Free / Zero Network
|
|
41
|
+
Local MCP ┌─────┴────────────┐ │
|
|
42
|
+
Tools Tools │ │ ▼
|
|
43
|
+
│ │ stdio Streamable HTTP Exit 0 / 1 / 2 / 3
|
|
44
|
+
Static AST stdio │ │
|
|
45
|
+
│ │ subprocess handshake PRM / RFC 8414 OAuth
|
|
46
|
+
└──────┬──────┘ │ │
|
|
47
|
+
│ └─────────┬────────┘
|
|
48
|
+
▼ ▼
|
|
49
|
+
Multi-Turn Dialogue tools/list
|
|
50
|
+
with LLM Provider │
|
|
51
|
+
│ ▼
|
|
52
|
+
└──────────────────► Candidate Policy
|
|
53
|
+
│
|
|
54
|
+
Human Review &
|
|
55
|
+
Policy.from_mapping()
|
|
56
|
+
│
|
|
57
|
+
┌──────────┴──────────┐
|
|
58
|
+
▼ ▼
|
|
59
|
+
policy.json mcp_protection.json
|
|
60
|
+
│ │
|
|
61
|
+
└──────────┬──────────┘
|
|
62
|
+
▼
|
|
63
|
+
dmint-mcp Enforcement
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
## Table of Contents
|
|
69
|
+
|
|
70
|
+
1. [What dmint-cli Does](#1-what-dmint-cli-does)
|
|
71
|
+
2. [What Problem It Solves](#2-what-problem-it-solves)
|
|
72
|
+
3. [Installation](#3-installation)
|
|
73
|
+
4. [Quickstart](#4-quickstart)
|
|
74
|
+
5. [General Policy Authoring (`create-policy`)](#5-general-policy-authoring-create-policy)
|
|
75
|
+
6. [Specialized MCP Policy Wizard (`create-mcp-policy`)](#6-specialized-mcp-policy-wizard-create-mcp-policy)
|
|
76
|
+
7. [Deterministic Offline Verification (`verify-policy`)](#7-deterministic-offline-verification-verify-policy)
|
|
77
|
+
8. [stdio MCP Transport](#8-stdio-mcp-transport)
|
|
78
|
+
9. [Streamable HTTP MCP Transport](#9-streamable-http-mcp-transport)
|
|
79
|
+
10. [Authenticated MCP Servers](#10-authenticated-mcp-servers)
|
|
80
|
+
11. [OAuth 2.0 Browser Authentication Flow](#11-oauth-20-browser-authentication-flow)
|
|
81
|
+
12. [Credentials & Secret Storage Model](#12-credentials--secret-storage-model)
|
|
82
|
+
13. [Generated Artifacts](#13-generated-artifacts)
|
|
83
|
+
14. [Relationship with dmint and dmint-mcp](#14-relationship-with-dmint-and-dmint-mcp)
|
|
84
|
+
15. [Multi-MCP Server Setup](#15-multi-mcp-server-setup)
|
|
85
|
+
16. [Failure Behavior & Stable Exit Codes](#16-failure-behavior--stable-exit-codes)
|
|
86
|
+
17. [Known Limitations](#17-known-limitations)
|
|
87
|
+
18. [Security Model & Threat Hardening](#18-security-model--threat-hardening)
|
|
88
|
+
19. [Non-Goals](#19-non-goals)
|
|
89
|
+
20. [Troubleshooting & Common Errors](#20-troubleshooting--common-errors)
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
## 1. What dmint-cli Does
|
|
94
|
+
|
|
95
|
+
`dmint-cli` is the developer-facing CLI suite and interactive assistant for the Dmint authorization framework:
|
|
96
|
+
- **Discovers Capabilities**: Inspects local Python tool code via static AST analysis (zero execution) or queries downstream Model Context Protocol (MCP) servers live over `stdio` and HTTP transports.
|
|
97
|
+
- **Authors Least-Privilege Policies**: Converts high-level English access rules (`access.md`) into formal Dmint policies via an interactive multi-turn dialogue with LLM providers.
|
|
98
|
+
- **Validates Policy Invariants**: Enforces strict semantic constraints, rejecting unknown fields, ambiguous patterns, and schema violations.
|
|
99
|
+
- **Generates Runtime Protection Configs**: Produces multi-integration binding manifests (`mcp_protection.json`) for seamless handoff to `dmint-mcp` enforcement proxies.
|
|
100
|
+
- **Verifies Policies Offline**: Provides instant, deterministic, zero-network schema verification via `dmint verify-policy`.
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
## 2. What Problem It Solves
|
|
105
|
+
|
|
106
|
+
AI agents equipped with tool-calling capabilities (e.g., database clients, cloud CLIs, filesystem utilities) introduce severe security vulnerabilities:
|
|
107
|
+
- **Prompt Injection**: Malicious untrusted inputs can trick agents into executing unauthorized actions (e.g., dropping database tables or exfiltrating files).
|
|
108
|
+
- **Over-Privileged Tool Access**: Agents are frequently given broad wildcard access when they only require granular, parameter-constrained operations.
|
|
109
|
+
- **Difficult Policy Authoring**: Writing correct, mathematical access-control policies with argument-level validation rules by hand is tedious and error-prone.
|
|
110
|
+
|
|
111
|
+
`dmint-cli` solves this by automating capability discovery, prompting developers interactively to resolve permission ambiguities, and outputting deterministic, verifiable policy files that can be audited before deployment.
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
## 3. Installation
|
|
116
|
+
|
|
117
|
+
### Requirements
|
|
118
|
+
- Python 3.10 or higher
|
|
119
|
+
- Linux, macOS, or Windows
|
|
120
|
+
|
|
121
|
+
### Install via pip
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
pip install dmint-cli
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Install with Test Dependencies
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
pip install "dmint-cli[test]"
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
## 4. Quickstart
|
|
136
|
+
|
|
137
|
+
Verify your installation and version:
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
dmint --version
|
|
141
|
+
# dmint 1.0.0
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### 3-Step Walkthrough
|
|
145
|
+
|
|
146
|
+
#### Step 1: Define Intent (`access.md`)
|
|
147
|
+
Create a markdown file describing your access control rules:
|
|
148
|
+
|
|
149
|
+
```markdown
|
|
150
|
+
# Ops Bot Access Rules
|
|
151
|
+
- The agent may read rows from the 'analytics' database.
|
|
152
|
+
- Any writes, deletions, or schema updates require explicit human approval.
|
|
153
|
+
- Direct drop operations on production tables are denied.
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
#### Step 2: Author Policy Interactively
|
|
157
|
+
Run the wizard against your tools or downstream MCP server:
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
export OPENAI_API_KEY="sk-..."
|
|
161
|
+
dmint create-policy -f access.md -o policy.json --tools ./my_tools/
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
Review the candidate policy, resolve any clarifications, and confirm creation.
|
|
165
|
+
|
|
166
|
+
#### Step 3: Verify Offline
|
|
167
|
+
Verify the policy deterministically without network or LLM access:
|
|
168
|
+
|
|
169
|
+
```bash
|
|
170
|
+
dmint verify-policy policy.json
|
|
171
|
+
# ✓ Verified policy.json: 3 rule(s)
|
|
172
|
+
# [ALLOW] tool='db', action='read', resource='NoResource'
|
|
173
|
+
# [APPROVAL_REQUIRED] tool='db', action='write', resource='NoResource'
|
|
174
|
+
# [DENY] tool='db', action='drop', resource='NoResource'
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
---
|
|
178
|
+
|
|
179
|
+
## 5. General Policy Authoring (`create-policy`)
|
|
180
|
+
|
|
181
|
+
`dmint create-policy` is the primary interactive authoring command for both local source code and MCP tools.
|
|
182
|
+
|
|
183
|
+
```bash
|
|
184
|
+
dmint create-policy -f access.md -o policy.json [--tools <dir_or_file>]
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### Key Capabilities
|
|
188
|
+
- **Static AST Discovery**: Inspects Python source code using Python's `ast.parse()`. Code is **never executed or imported**, preventing malicious tools from running arbitrary code during policy generation.
|
|
189
|
+
- **Multi-Turn Dialogue Envelope**: Interacts with OpenAI, Gemini, Groq, OpenRouter, or local Ollama models. If requirements are ambiguous, the assistant asks targeted clarification questions before producing a policy.
|
|
190
|
+
- **Self-Correcting Validation Loop**: Automatically passes syntax or schema errors back to the LLM model to self-correct invalid policy mappings.
|
|
191
|
+
- **Deterministic Atomic Output**: Writes output files atomically using temporary files and directory fsyncs (`io_utils.py`), preventing partial or corrupted outputs.
|
|
192
|
+
|
|
193
|
+
### Flags & Options
|
|
194
|
+
| Flag | Description | Default |
|
|
195
|
+
| :--- | :--- | :--- |
|
|
196
|
+
| `-f, --file` | Path to natural language requirements file (markdown/text) | *Required* |
|
|
197
|
+
| `-o, --output` | Destination path for verified `policy.json` | *Required* |
|
|
198
|
+
| `--tools` | Path to tool source file or directory for AST inspection | `None` |
|
|
199
|
+
| `-provider` | LLM provider (`openai`, `gemini`, `groq`, `openrouter`, `ollama`) | `openai` |
|
|
200
|
+
| `-base_url` | OpenAI-compatible API base URL | Provider default |
|
|
201
|
+
| `-api_key` | API key (or via `OPENAI_API_KEY`, `GEMINI_API_KEY`, etc.) | Env vars |
|
|
202
|
+
| `-model` | LLM model name | `gpt-4o-mini` |
|
|
203
|
+
| `--non-interactive` | Non-interactive mode (disables terminal prompt queries) | `False` |
|
|
204
|
+
| `-y, --yes` | Auto-confirm candidate policy without prompting | `False` |
|
|
205
|
+
| `--timeout` | HTTP request timeout in seconds | `60.0` |
|
|
206
|
+
|
|
207
|
+
---
|
|
208
|
+
|
|
209
|
+
## 6. Specialized MCP Policy Wizard (`create-mcp-policy`)
|
|
210
|
+
|
|
211
|
+
`dmint create-mcp-policy` connects directly to downstream MCP servers, queries their live capabilities via the official MCP protocol, authors policies, and outputs runtime protection configurations.
|
|
212
|
+
|
|
213
|
+
```bash
|
|
214
|
+
dmint create-mcp-policy \
|
|
215
|
+
--command "mcp-server-postgres" \
|
|
216
|
+
--args "postgresql://localhost/production" \
|
|
217
|
+
--integration-id "postgres" \
|
|
218
|
+
-f access.md \
|
|
219
|
+
-o policy.json \
|
|
220
|
+
--config-output mcp_protection.json
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
> [!NOTE]
|
|
224
|
+
> `dmint protect-mcp` is retained as a fully supported backward-compatibility alias for `dmint create-mcp-policy`.
|
|
225
|
+
|
|
226
|
+
### Flags & Options
|
|
227
|
+
| Flag | Description | Default |
|
|
228
|
+
| :--- | :--- | :--- |
|
|
229
|
+
| `--command` | Subprocess executable command (e.g. `npx`, `python`) | `None` |
|
|
230
|
+
| `--args` | Command arguments passed to subprocess | `[]` |
|
|
231
|
+
| `--integration-id` | Unique ID namespace for this MCP server | Derived from command |
|
|
232
|
+
| `--transport` | MCP transport type (`stdio`, `streamable-http`) | `stdio` |
|
|
233
|
+
| `--url` | Remote MCP endpoint URL (for remote transports) | `None` |
|
|
234
|
+
| `-f, --file` | Input requirements markdown file | `access.md` |
|
|
235
|
+
| `-o, --output` | Output verified `policy.json` | `policy.json` |
|
|
236
|
+
| `--config-output` | Output `mcp_protection.json` runtime configuration | `mcp_protection.json` |
|
|
237
|
+
| `-y, --yes` | Auto-confirm candidate policy without prompting | `False` |
|
|
238
|
+
|
|
239
|
+
---
|
|
240
|
+
|
|
241
|
+
## 7. Deterministic Offline Verification (`verify-policy`)
|
|
242
|
+
|
|
243
|
+
`dmint verify-policy` performs mathematical, 100% offline schema and semantic validation of an existing `policy.json` file.
|
|
244
|
+
|
|
245
|
+
```bash
|
|
246
|
+
dmint verify-policy policy.json
|
|
247
|
+
# or
|
|
248
|
+
dmint verify-policy -f policy.json
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
### Guarantees
|
|
252
|
+
- **Zero Network Access**: Opens no sockets, performs no DNS queries, and contacts no external servers.
|
|
253
|
+
- **Zero LLM Invocations**: Contains no heuristic or stochastic evaluation.
|
|
254
|
+
- **Deterministic Exit Code**:
|
|
255
|
+
- `0`: Policy is valid and safe according to Dmint core schema rules.
|
|
256
|
+
- `1`: Policy validation failed (e.g. invalid rule effect, unknown keys).
|
|
257
|
+
- `2`: Usage or CLI syntax error.
|
|
258
|
+
- `3`: Policy file not found.
|
|
259
|
+
|
|
260
|
+
---
|
|
261
|
+
|
|
262
|
+
### AI Coding Agent Skill Installation (`install-skill`)
|
|
263
|
+
|
|
264
|
+
To enable AI coding assistants (such as Google Antigravity, Gemini CLI, Claude Code, or Cursor) to create, modify, understand, and verify Dmint policies directly through chat, install the official Dmint skill:
|
|
265
|
+
|
|
266
|
+
```bash
|
|
267
|
+
# Interactive installation (prompts to choose or type destination):
|
|
268
|
+
dmint install-skill
|
|
269
|
+
|
|
270
|
+
# Non-interactive workspace installation (defaults to .agents/skills/):
|
|
271
|
+
dmint install-skill -y
|
|
272
|
+
|
|
273
|
+
# Install to specific directory:
|
|
274
|
+
dmint install-skill --dest .agent/skills
|
|
275
|
+
# or
|
|
276
|
+
dmint install-skill --target ./my-skills
|
|
277
|
+
|
|
278
|
+
# Global machine-wide installation:
|
|
279
|
+
dmint install-skill --global # ~/.gemini/config/skills/
|
|
280
|
+
dmint install-skill --claude # ~/.claude/skills/
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
#### Interactive Selection
|
|
284
|
+
When run without `--dest`, `dmint install-skill` displays a numbered menu and allows typing any directory path directly:
|
|
285
|
+
- **`[1]` `.agents/skills/`** (Default: standard workspace path discovered by Antigravity, Gemini CLI, and Cursor)
|
|
286
|
+
- **`[2]` `.agent/skills/`** (Alternative project workspace path)
|
|
287
|
+
- **`[3]` `~/.gemini/config/skills/`** (Global config for Gemini & Antigravity)
|
|
288
|
+
- **`[4]` `~/.claude/skills/`** (Global config for Claude Code)
|
|
289
|
+
- **`[5]` Type custom path** (Or type any directory path directly at the prompt)
|
|
290
|
+
|
|
291
|
+
---
|
|
292
|
+
|
|
293
|
+
## 8. stdio MCP Transport
|
|
294
|
+
|
|
295
|
+
For local tool servers, `dmint-cli` connects over standard input/output (`stdio`):
|
|
296
|
+
1. Spawns the MCP server executable as an isolated subprocess (`subprocess.Popen`).
|
|
297
|
+
2. Performs the standard MCP JSON-RPC protocol handshake (`initialize` and `notifications/initialized`).
|
|
298
|
+
3. Dispatches `tools/list` to discover all published tools, input schemas, and descriptions.
|
|
299
|
+
4. Generates canonical capability names namespaced by integration ID:
|
|
300
|
+
```text
|
|
301
|
+
mcp.{integration_id}.{tool_name}
|
|
302
|
+
```
|
|
303
|
+
5. Terminates the discovery subprocess cleanly upon completion.
|
|
304
|
+
|
|
305
|
+
---
|
|
306
|
+
|
|
307
|
+
## 9. Streamable HTTP MCP Transport
|
|
308
|
+
|
|
309
|
+
For remote MCP endpoints, `dmint-cli` supports HTTP discovery:
|
|
310
|
+
- **Mandatory HTTPS**: Strictly requires TLS (`https://`) to protect tool metadata in transit.
|
|
311
|
+
- **Strict Same-Origin Redirects**: Forbids cross-origin redirects to prevent SSRF and credential mix-up attacks.
|
|
312
|
+
- **Streaming Negotiation**: Uses `Accept: application/json, text/event-stream` for live protocol negotiation.
|
|
313
|
+
|
|
314
|
+
> [!IMPORTANT]
|
|
315
|
+
> The `dmint-mcp` runtime enforcement proxy currently supports `stdio` subprocess downstream execution. If you discover remote HTTP MCP servers, configure a local stdio bridge or ensure upstream gateway proxying.
|
|
316
|
+
|
|
317
|
+
---
|
|
318
|
+
|
|
319
|
+
## 10. Authenticated MCP Servers
|
|
320
|
+
|
|
321
|
+
When an MCP endpoint responds with `401 Unauthorized` or `403 Forbidden`:
|
|
322
|
+
1. **RFC 9728 PRM Discovery**: Looks for the `WWW-Authenticate` header and resolves Protected Resource Metadata (PRM) via `/.well-known/oauth-protected-resource`.
|
|
323
|
+
2. **RFC 8414 AS Discovery**: Resolves the OAuth 2.0 Authorization Server metadata via `/.well-known/oauth-authorization-server`.
|
|
324
|
+
3. **Issuer Validation**: Enforces RFC 9207 issuer matching to prevent authorization server mix-up attacks.
|
|
325
|
+
4. **Dynamic Client Registration**: Performs RFC 7591 Dynamic Client Registration if the server supports it, advertising `client_name="dmint-cli"` and `software_version="1.0.0"`.
|
|
326
|
+
|
|
327
|
+
---
|
|
328
|
+
|
|
329
|
+
## 11. OAuth 2.0 Browser Authentication Flow
|
|
330
|
+
|
|
331
|
+
When user authentication is required:
|
|
332
|
+
1. **Port 0 Loopback Server**: Binds directly to `127.0.0.1` on an ephemeral OS-assigned port (port 0). This prevents local port collision attacks and socket-reuse vulnerabilities.
|
|
333
|
+
2. **RFC 7636 PKCE**: Generates a high-entropy cryptographically secure code verifier and `S256` code challenge.
|
|
334
|
+
3. **System Browser Authorization**: Launches the default OS web browser pointing to the server's authorization URL.
|
|
335
|
+
4. **Single-Use Callback Handler**: Captures the OAuth callback, matches `state` and `iss` parameters, exchanges the authorization code for tokens, and shuts down the loopback listener immediately.
|
|
336
|
+
|
|
337
|
+
---
|
|
338
|
+
|
|
339
|
+
## 12. Credentials & Secret Storage Model
|
|
340
|
+
|
|
341
|
+
`dmint-cli` manages sensitive tokens using an enterprise-grade credential architecture:
|
|
342
|
+
- **Storage Hierarchy**:
|
|
343
|
+
1. *Primary*: System OS Keyring via `keyring` (macOS Keychain, Linux Secret Service, Windows Credential Locker).
|
|
344
|
+
2. *Hardened File Fallback*: `~/.config/dmint/credentials.json`.
|
|
345
|
+
- **Strict POSIX Permissions**: Credential directories and files are strictly enforced with `0700` and `0600` permissions. Insecure permissions are automatically rectified.
|
|
346
|
+
- **Symlink Defenses**: Uses `os.O_NOFOLLOW` and inode verification (`lstat`) to prevent symlink replacement attacks.
|
|
347
|
+
- **Secret Redaction**: All API keys, bearer tokens, client secrets, and passwords are masked (`***` or `sk-...1234`) across logs, console stdout/stderr, and serialized artifacts.
|
|
348
|
+
|
|
349
|
+
---
|
|
350
|
+
|
|
351
|
+
## 13. Generated Artifacts
|
|
352
|
+
|
|
353
|
+
### 1. `policy.json`
|
|
354
|
+
The authoritative security policy evaluated at runtime by `dmint`:
|
|
355
|
+
|
|
356
|
+
```json
|
|
357
|
+
{
|
|
358
|
+
"rules": [
|
|
359
|
+
{
|
|
360
|
+
"effect": "allow",
|
|
361
|
+
"tool": "mcp.postgres.run_query",
|
|
362
|
+
"action": "execute",
|
|
363
|
+
"resource": "public_tables"
|
|
364
|
+
},
|
|
365
|
+
{
|
|
366
|
+
"effect": "approval_required",
|
|
367
|
+
"tool": "mcp.postgres.delete_rows",
|
|
368
|
+
"action": "execute",
|
|
369
|
+
"resource": "production_db"
|
|
370
|
+
}
|
|
371
|
+
]
|
|
372
|
+
}
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
### 2. `mcp_protection.json`
|
|
376
|
+
The multi-integration runtime manifest consumed by `dmint-mcp`:
|
|
377
|
+
|
|
378
|
+
```json
|
|
379
|
+
{
|
|
380
|
+
"policy_file": "policy.json",
|
|
381
|
+
"integrations": [
|
|
382
|
+
{
|
|
383
|
+
"integration_id": "postgres",
|
|
384
|
+
"command": "mcp-server-postgres",
|
|
385
|
+
"args": ["postgresql://localhost/prod"],
|
|
386
|
+
"transport": "stdio",
|
|
387
|
+
"default_discovery": "hidden",
|
|
388
|
+
"tool_bindings": {
|
|
389
|
+
"run_query": {
|
|
390
|
+
"capability": "mcp.postgres.run_query",
|
|
391
|
+
"discovery": "exposed"
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
]
|
|
396
|
+
}
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
---
|
|
400
|
+
|
|
401
|
+
## 14. Relationship with dmint and dmint-mcp
|
|
402
|
+
|
|
403
|
+
| Package | Role | Execution Phase | Dependencies |
|
|
404
|
+
| :--- | :--- | :--- | :--- |
|
|
405
|
+
| **`dmint`** | In-process authorization engine | Runtime | Pure Python (Zero dependencies) |
|
|
406
|
+
| **`dmint-cli`** | Developer policy authoring & verification CLI | Development / Build | `dmint`, `mcp` SDK |
|
|
407
|
+
| **`dmint-mcp`** | MCP proxy server and tool enforcement gateway | Runtime | `dmint`, `mcp` SDK |
|
|
408
|
+
|
|
409
|
+
> [!CAUTION]
|
|
410
|
+
> ### The Fundamental Enforcement Invariant
|
|
411
|
+
> **Dmint does not secure an MCP server if the agent can bypass the protected execution path and call the original capability directly.**
|
|
412
|
+
>
|
|
413
|
+
> To enforce real security:
|
|
414
|
+
> 1. The downstream MCP server must **not** be exposed directly to the agent.
|
|
415
|
+
> 2. The agent's client configuration must target **only** the `dmint-mcp` proxy gateway.
|
|
416
|
+
> 3. Subprocess command environments and credentials must remain restricted to the proxy process.
|
|
417
|
+
|
|
418
|
+
---
|
|
419
|
+
|
|
420
|
+
## 15. Multi-MCP Server Setup
|
|
421
|
+
|
|
422
|
+
`dmint-cli` handles multi-server setups with zero namespace collision:
|
|
423
|
+
- **Namespaced Tool Capabilities**: Tools named `query` in both a Postgres server and a MySQL server become `mcp.postgres.query` and `mcp.mysql.query`.
|
|
424
|
+
- **Deterministic Ordering**: Integrations in `mcp_protection.json` are sorted deterministically by `integration_id` to guarantee reproducible byte-for-byte outputs across git commits.
|
|
425
|
+
|
|
426
|
+
---
|
|
427
|
+
|
|
428
|
+
## 16. Failure Behavior & Stable Exit Codes
|
|
429
|
+
|
|
430
|
+
`dmint-cli` adheres to a strict fail-closed contract. Every command exits with an unambiguous, documented status code:
|
|
431
|
+
|
|
432
|
+
| Code | Constant | Meaning |
|
|
433
|
+
| :---: | :--- | :--- |
|
|
434
|
+
| **0** | `SUCCESS` | Operation completed successfully |
|
|
435
|
+
| **1** | `POLICY_ERROR` | Policy validation failed or user rejected candidate |
|
|
436
|
+
| **2** | `USAGE_ERROR` | Invalid CLI arguments or malformed flags |
|
|
437
|
+
| **3** | `FILE_NOT_FOUND` | Required input file does not exist |
|
|
438
|
+
| **4** | `JSON_ERROR` | Malformed JSON in inputs or LLM response extraction failure |
|
|
439
|
+
| **5** | `OUTPUT_WRITE_ERROR` | Atomic write failure or read-back verification failed |
|
|
440
|
+
| **6** | `API_ERROR` | External LLM provider API failure or HTTP error |
|
|
441
|
+
| **7** | `RESOURCE_EXHAUSTION`| Input size, loop count, or response limit exceeded |
|
|
442
|
+
| **8** | `SECURITY_VIOLATION` | SSRF attempt, insecure credentials, or protocol mix-up |
|
|
443
|
+
|
|
444
|
+
---
|
|
445
|
+
|
|
446
|
+
## 17. Known Limitations
|
|
447
|
+
|
|
448
|
+
- **Static AST vs. Dynamic Code**: `create-policy --tools` inspects static AST trees. Dynamic metaprogramming (`setattr`, runtime decorators) will not expose inferred capabilities.
|
|
449
|
+
- **Single-Host Stdio Proxy**: `dmint-mcp` currently wraps local subprocesses via `stdio`. Remote HTTP endpoints must be accessed via network gateways or secure tunnels.
|
|
450
|
+
- **LLM Non-Determinism**: Because policy *authoring* uses LLM reasoning, output policies should always be reviewed by humans before writing production files.
|
|
451
|
+
|
|
452
|
+
---
|
|
453
|
+
|
|
454
|
+
## 18. Security Model & Threat Hardening
|
|
455
|
+
|
|
456
|
+
`dmint-cli` is hardened against hostile inputs:
|
|
457
|
+
- **SSRF Defenses**: Validates all URLs and rejects loopback, RFC 1918 private subnets, link-local addresses, multicast, and cloud metadata endpoints (`169.254.169.254`).
|
|
458
|
+
- **Resource Exhaustion Bounds**:
|
|
459
|
+
- Maximum MCP integrations: `32`
|
|
460
|
+
- Maximum tools per integration: `256`
|
|
461
|
+
- Maximum pagination depth: `20`
|
|
462
|
+
- Maximum tool name length: `128` characters
|
|
463
|
+
- Maximum HTTP response size: `1 MB`
|
|
464
|
+
- Maximum OAuth metadata size: `512 KB`
|
|
465
|
+
- Maximum policy/credential file size: `1 MB`
|
|
466
|
+
- **Zero Plaintext Secrets**: Secrets are permanently scrubbed from exceptions, error messages, and log records.
|
|
467
|
+
|
|
468
|
+
---
|
|
469
|
+
|
|
470
|
+
## 19. Non-Goals
|
|
471
|
+
|
|
472
|
+
To maintain security focus and boundary clarity, `dmint-cli` explicitly does **not**:
|
|
473
|
+
- **Act as a Runtime Gateway**: Runtime enforcement is exclusively the job of `dmint` and `dmint-mcp`.
|
|
474
|
+
- **Run Background Daemons**: `dmint-cli` is an ephemeral CLI tool; it runs on-demand and exits.
|
|
475
|
+
- **Replace Human Approval**: Policies are proposed for human review; automated generation never auto-deploys unreviewed policies without explicit `--yes` flags.
|
|
476
|
+
|
|
477
|
+
---
|
|
478
|
+
|
|
479
|
+
## 20. Troubleshooting & Common Errors
|
|
480
|
+
|
|
481
|
+
### 1. `PolicyValidationError` on generation
|
|
482
|
+
- **Cause**: The LLM produced rules with unrecognized effects or illegal fields.
|
|
483
|
+
- **Fix**: Re-run the command; `dmint-cli` automatically provides error feedback to the model to correct itself.
|
|
484
|
+
|
|
485
|
+
### 2. `Security error: Refusing connection to private or cloud-metadata IP`
|
|
486
|
+
- **Cause**: The MCP server URL points to `169.254.169.254` or private LAN without explicit configuration.
|
|
487
|
+
- **Fix**: Use public HTTPS URLs or use local `stdio` transport.
|
|
488
|
+
|
|
489
|
+
### 3. `API connection failed`
|
|
490
|
+
- **Cause**: Invalid API key or unreachable provider endpoint.
|
|
491
|
+
- **Fix**: Ensure `OPENAI_API_KEY`, `GEMINI_API_KEY`, or `GROQ_API_KEY` is exported in your environment.
|
|
492
|
+
|
|
493
|
+
### 4. `Insecure permissions on credential file`
|
|
494
|
+
- **Cause**: Credential file has permissions wider than `0600`.
|
|
495
|
+
- **Fix**: Run `chmod 600 ~/.config/dmint/credentials.json` (the CLI will also attempt to auto-repair this).
|
|
496
|
+
|
|
497
|
+
---
|
|
498
|
+
|
|
499
|
+
## License
|
|
500
|
+
|
|
501
|
+
Licensed under the [Apache License, Version 2.0](LICENSE).
|
|
502
|
+
See the [`LICENSE`](LICENSE) file for the complete license text.
|