devpy-cli 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.
- devpy_cli-1.0.0/PKG-INFO +330 -0
- devpy_cli-1.0.0/README.md +305 -0
- devpy_cli-1.0.0/app.py +17 -0
- devpy_cli-1.0.0/backend.py +417 -0
- devpy_cli-1.0.0/config_manager.py +47 -0
- devpy_cli-1.0.0/devpy_cli.egg-info/PKG-INFO +330 -0
- devpy_cli-1.0.0/devpy_cli.egg-info/SOURCES.txt +15 -0
- devpy_cli-1.0.0/devpy_cli.egg-info/dependency_links.txt +1 -0
- devpy_cli-1.0.0/devpy_cli.egg-info/entry_points.txt +2 -0
- devpy_cli-1.0.0/devpy_cli.egg-info/requires.txt +9 -0
- devpy_cli-1.0.0/devpy_cli.egg-info/top_level.txt +7 -0
- devpy_cli-1.0.0/frontend_cli.py +205 -0
- devpy_cli-1.0.0/permissions_config_manager.py +92 -0
- devpy_cli-1.0.0/permissions_manager.py +174 -0
- devpy_cli-1.0.0/pyproject.toml +48 -0
- devpy_cli-1.0.0/setup.cfg +4 -0
- devpy_cli-1.0.0/ssh_key_manager.py +85 -0
devpy_cli-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: devpy-cli
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: AI-powered DevOps CLI Assistant for local and remote Docker management
|
|
5
|
+
Author-email: Eddy Ortega <atrox390@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/your-username/devpy-cli
|
|
8
|
+
Project-URL: Bug Tracker, https://github.com/your-username/devpy-cli/issues
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Topic :: System :: Systems Administration
|
|
13
|
+
Classifier: Topic :: Software Development :: Build Tools
|
|
14
|
+
Requires-Python: >=3.11
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
Requires-Dist: docker>=7.0.0
|
|
17
|
+
Requires-Dist: paramiko>=3.4.0
|
|
18
|
+
Requires-Dist: cryptography>=42.0.0
|
|
19
|
+
Requires-Dist: rich>=13.7.0
|
|
20
|
+
Requires-Dist: langchain>=0.1.0
|
|
21
|
+
Requires-Dist: langchain-openai>=0.0.5
|
|
22
|
+
Requires-Dist: langgraph>=0.0.10
|
|
23
|
+
Requires-Dist: python-dotenv>=1.0.0
|
|
24
|
+
Requires-Dist: psutil>=5.9.0
|
|
25
|
+
|
|
26
|
+
# DevPy CLI
|
|
27
|
+
|
|
28
|
+
An intelligent command-line assistant powered by LLM (DeepSeek/OpenAI) to manage Docker environments, both local and remote via SSH. Designed to simplify DevOps tasks with natural language, ensuring security and control.
|
|
29
|
+
|
|
30
|
+
## Key Features
|
|
31
|
+
|
|
32
|
+
* **Natural Language Interaction**: "Restart the nginx container", "Show database logs", "Monitor memory usage".
|
|
33
|
+
* **Local and Remote Docker Management**: Connect to your local machine or remote servers via SSH transparently.
|
|
34
|
+
* **Secure SSH Key Management**: Encrypted storage (AES-256) of SSH private keys. Import from `~/.ssh`.
|
|
35
|
+
* **Granular Permission System**:
|
|
36
|
+
* Interactive confirmation for critical operations (write/delete).
|
|
37
|
+
* Configurable whitelists.
|
|
38
|
+
* Persistent permission rules with hot-reload.
|
|
39
|
+
* "Dry-Run" mode to simulate executions.
|
|
40
|
+
* **Logging and Auditing**: Detailed logging of all operations and permission decisions in `logs/permissions.log`.
|
|
41
|
+
|
|
42
|
+
## System Requirements
|
|
43
|
+
|
|
44
|
+
* Python 3.9 or higher.
|
|
45
|
+
* Docker client installed (local) or SSH access to a server with Docker.
|
|
46
|
+
* Operating System: Windows, macOS, Linux.
|
|
47
|
+
|
|
48
|
+
## Installation
|
|
49
|
+
|
|
50
|
+
1. **Clone the repository:**
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
git clone <repo-url>
|
|
54
|
+
cd devpy-cli
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
2. **Create virtual environment (recommended):**
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
python -m venv venv
|
|
61
|
+
# Windows
|
|
62
|
+
.\venv\Scripts\activate
|
|
63
|
+
# Linux/Mac
|
|
64
|
+
source venv/bin/activate
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
3. **Install dependencies:**
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
pip install -e .
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
4. **Configure environment:**
|
|
74
|
+
Create a `.env` file in the root (you can copy the example if it exists) with your LLM API key:
|
|
75
|
+
|
|
76
|
+
```ini
|
|
77
|
+
DEEPSEEK_API_KEY=your_api_key_here
|
|
78
|
+
# Optional: LLM=chatgpt and OPENAI_API_KEY=...
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Usage Guide
|
|
82
|
+
|
|
83
|
+
### Start the CLI
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
# From the repository
|
|
87
|
+
python app.py
|
|
88
|
+
|
|
89
|
+
# Or if installed in editable mode
|
|
90
|
+
devpy-cli
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
On first run, if no `.env` file exists, an interactive setup wizard will guide you through:
|
|
94
|
+
- Choosing your LLM provider.
|
|
95
|
+
- Entering the API key.
|
|
96
|
+
- Optionally setting a custom base URL.
|
|
97
|
+
|
|
98
|
+
After setup, the CLI banner appears and you are asked whether to enable dry-run mode.
|
|
99
|
+
|
|
100
|
+
---
|
|
101
|
+
|
|
102
|
+
### CLI Mode (Local Docker)
|
|
103
|
+
|
|
104
|
+
Use this mode when you want to manage containers running on the same machine where DevPy CLI is installed.
|
|
105
|
+
|
|
106
|
+
- **Requirements**
|
|
107
|
+
- Docker is installed and the daemon is running locally.
|
|
108
|
+
- Your user can talk to the Docker socket (e.g., `docker ps` works from your shell).
|
|
109
|
+
|
|
110
|
+
- **Step-by-step**
|
|
111
|
+
1. Start the CLI (see above).
|
|
112
|
+
2. When prompted, choose whether to enable dry-run mode.
|
|
113
|
+
3. Ensure the mode is set to `local` (this is the default):
|
|
114
|
+
```bash
|
|
115
|
+
config mode local
|
|
116
|
+
```
|
|
117
|
+
4. Type natural language instructions, for example:
|
|
118
|
+
- `What containers are running?`
|
|
119
|
+
- `Restart the nginx container and show me its latest logs`
|
|
120
|
+
- `Create a redis container called cache`
|
|
121
|
+
5. When an action is potentially destructive (creating/stopping/removing containers, starting monitors, etc.), DevPy will:
|
|
122
|
+
- Show a preview of the Docker command.
|
|
123
|
+
- Ask for confirmation (once, for the command, or for the whole session).
|
|
124
|
+
|
|
125
|
+
- **Typical local use cases**
|
|
126
|
+
- Quickly inspecting and restarting local services from the terminal.
|
|
127
|
+
- Checking logs of a misbehaving container.
|
|
128
|
+
- Spinning up utility containers (e.g., Redis, Postgres) by name and image.
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
### SSH Mode (Remote Docker over SSH)
|
|
133
|
+
|
|
134
|
+
Use this mode to manage containers on a remote host over SSH, while still talking to the CLI locally.
|
|
135
|
+
|
|
136
|
+
- **Prerequisites**
|
|
137
|
+
- The remote server:
|
|
138
|
+
- Has Docker installed and running.
|
|
139
|
+
- Is reachable via SSH (e.g., `ssh user@host` works).
|
|
140
|
+
- You have an SSH private key that can authenticate to that server.
|
|
141
|
+
|
|
142
|
+
- **Step 1: Store your SSH key (encrypted)**
|
|
143
|
+
|
|
144
|
+
You can import keys from `~/.ssh` or add a specific file:
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
# Scan ~/.ssh for potential keys and import one
|
|
148
|
+
keys scan
|
|
149
|
+
|
|
150
|
+
# Or add a specific key path
|
|
151
|
+
keys add my-remote /path/to/id_rsa
|
|
152
|
+
|
|
153
|
+
# List stored keys
|
|
154
|
+
keys list
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
During `keys scan` or `keys add`, you are asked for a **passphrase for encryption**.
|
|
158
|
+
This passphrase is used to derive a key that encrypts your private key on disk (AES-256 via `cryptography.Fernet`).
|
|
159
|
+
|
|
160
|
+
- **Step 2: Configure SSH connection**
|
|
161
|
+
|
|
162
|
+
In the CLI, run:
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
config ssh
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
You will be prompted for:
|
|
169
|
+
- **SSH Host** (e.g., `myserver.example.com` or `192.168.1.100`)
|
|
170
|
+
- **SSH User** (e.g., `ubuntu`, `root`, `deploy`)
|
|
171
|
+
- **SSH Key Name** (one of the names returned by `keys list`)
|
|
172
|
+
|
|
173
|
+
This information is stored in `config.json`.
|
|
174
|
+
|
|
175
|
+
- **Step 3: Switch to SSH mode**
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
config mode ssh
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
From now on, Docker operations happen against the remote host using the stored SSH configuration.
|
|
182
|
+
|
|
183
|
+
- **Step 4: Authenticate with your key**
|
|
184
|
+
|
|
185
|
+
When the backend needs to connect to the remote Docker daemon, it:
|
|
186
|
+
- Prompts for the passphrase you used when storing the key, **or**
|
|
187
|
+
- Uses the `DOCKER_SSH_PASSPHRASE` environment variable if it is set.
|
|
188
|
+
|
|
189
|
+
This decrypted key is written to a temporary file (with restricted permissions) and used only for the SSH connection.
|
|
190
|
+
|
|
191
|
+
- **Typical SSH use cases**
|
|
192
|
+
- Managing a remote Docker host from your laptop without logging in manually.
|
|
193
|
+
- Checking logs and restarting containers in staging/production environments.
|
|
194
|
+
- Monitoring memory usage of remote containers and triggering alerts.
|
|
195
|
+
|
|
196
|
+
---
|
|
197
|
+
|
|
198
|
+
### Command Reference
|
|
199
|
+
|
|
200
|
+
#### Configuration Commands
|
|
201
|
+
|
|
202
|
+
Use these to configure how the CLI connects and which LLM it uses:
|
|
203
|
+
|
|
204
|
+
```bash
|
|
205
|
+
# Show or set connection mode
|
|
206
|
+
config mode # shows current mode (local or ssh)
|
|
207
|
+
config mode local # use local Docker
|
|
208
|
+
config mode ssh # use remote Docker over SSH
|
|
209
|
+
|
|
210
|
+
# Configure SSH details (host, user, key)
|
|
211
|
+
config ssh
|
|
212
|
+
|
|
213
|
+
# Re-run the LLM setup wizard and regenerate .env
|
|
214
|
+
config llm
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
#### SSH Key Management Commands
|
|
218
|
+
|
|
219
|
+
```bash
|
|
220
|
+
# Import keys from ~/.ssh (interactive)
|
|
221
|
+
keys scan
|
|
222
|
+
|
|
223
|
+
# Add a key manually
|
|
224
|
+
keys add <name> <path_to_private_key>
|
|
225
|
+
|
|
226
|
+
# List saved keys
|
|
227
|
+
keys list
|
|
228
|
+
|
|
229
|
+
# Delete a stored key
|
|
230
|
+
keys delete <name>
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
#### Permission Management Commands
|
|
234
|
+
|
|
235
|
+
Control what the agent is allowed to do:
|
|
236
|
+
|
|
237
|
+
```bash
|
|
238
|
+
# View current rules
|
|
239
|
+
permissions list
|
|
240
|
+
|
|
241
|
+
# Block container restarts permanently
|
|
242
|
+
permissions add restart_container deny
|
|
243
|
+
|
|
244
|
+
# Allow container creation (with optional parameters)
|
|
245
|
+
permissions add create_container allow
|
|
246
|
+
|
|
247
|
+
# Reset all persistent permission rules
|
|
248
|
+
permissions reset
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
During interactive confirmations, you can choose:
|
|
252
|
+
- `y` – allow once.
|
|
253
|
+
- `yc` – always allow this exact command during the session.
|
|
254
|
+
- `ys` – always allow this operation type during the session.
|
|
255
|
+
- `n` – deny.
|
|
256
|
+
|
|
257
|
+
---
|
|
258
|
+
|
|
259
|
+
### Interaction Examples with the Agent
|
|
260
|
+
|
|
261
|
+
Once configured, simply type what you need:
|
|
262
|
+
|
|
263
|
+
- *"What containers are running?"*
|
|
264
|
+
- *"Restart the 'web-app' container and show me its latest logs"*
|
|
265
|
+
- *"Create a redis container named 'my-redis'"*
|
|
266
|
+
- *"Alert me if memory usage of container 'api' exceeds 80%"*
|
|
267
|
+
|
|
268
|
+
The agent plans and executes one or more Docker operations, asking for permission when necessary.
|
|
269
|
+
|
|
270
|
+
---
|
|
271
|
+
|
|
272
|
+
### Dry-Run Mode
|
|
273
|
+
|
|
274
|
+
You can enable dry-run mode in two ways:
|
|
275
|
+
|
|
276
|
+
- At startup, when the CLI asks:
|
|
277
|
+
- Answer `y` to run in dry-run mode for the session.
|
|
278
|
+
- Via environment variable:
|
|
279
|
+
- Set `DRY_RUN=1` before starting the app.
|
|
280
|
+
|
|
281
|
+
In this mode, the agent **simulates** write actions (creating, deleting, restarting containers, starting monitors, etc.) without actually executing them.
|
|
282
|
+
The permission log still records what *would* have been executed.
|
|
283
|
+
|
|
284
|
+
---
|
|
285
|
+
|
|
286
|
+
## Authentication and Security
|
|
287
|
+
|
|
288
|
+
- **LLM API Authentication**
|
|
289
|
+
- The `.env` file created by the setup wizard stores:
|
|
290
|
+
- `LLM` – which provider/adapter to use.
|
|
291
|
+
- `<PROVIDER>_API_KEY` – the API key for that provider.
|
|
292
|
+
- Optionally `LLM_BASE_URL` – custom base URL for compatible providers.
|
|
293
|
+
- You can re-run the wizard at any time with:
|
|
294
|
+
```bash
|
|
295
|
+
config llm
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
- **SSH Key Encryption**
|
|
299
|
+
- Stored SSH keys live in `ssh_keys.enc`.
|
|
300
|
+
- Each key is encrypted using a passphrase-derived key (PBKDF2 + AES-256).
|
|
301
|
+
- The file permissions are hardened to allow read/write only for the current user.
|
|
302
|
+
|
|
303
|
+
- **Runtime Environment Variables**
|
|
304
|
+
- `DRY_RUN` – if set to `1`, `true`, `yes`, or `y`, forces dry-run mode.
|
|
305
|
+
- `DOCKER_SSH_PASSPHRASE` – optional; if set, avoids interactive passphrase prompts for SSH keys.
|
|
306
|
+
- `DOCKER_SAFE_COMMANDS` – comma-separated list of operations that never prompt for confirmation.
|
|
307
|
+
- `DOCKER_CLI_USER` – overrides the username recorded in permission logs.
|
|
308
|
+
|
|
309
|
+
- **Logging and Auditing**
|
|
310
|
+
- All operations go through a permission and logging layer.
|
|
311
|
+
- Logs are written as JSON lines to `logs/permissions.log`.
|
|
312
|
+
- Each entry includes timestamp, user, operation, arguments, decision, and optional command preview.
|
|
313
|
+
|
|
314
|
+
## Project Structure
|
|
315
|
+
|
|
316
|
+
* `app.py`: Entry point.
|
|
317
|
+
* `frontend_cli.py`: User interface and CLI command handling.
|
|
318
|
+
* `backend.py`: Agent logic, integration with LangChain/LangGraph and Docker tools.
|
|
319
|
+
* `permissions_manager.py`: Access control and auditing system.
|
|
320
|
+
* `ssh_key_manager.py`: Encryption and key management.
|
|
321
|
+
* `config_manager.py`: Configuration persistence (mode, ssh host).
|
|
322
|
+
* `logs/`: Audit log files.
|
|
323
|
+
|
|
324
|
+
## License
|
|
325
|
+
|
|
326
|
+
MIT License. See `LICENSE` file for more details.
|
|
327
|
+
|
|
328
|
+
## Author
|
|
329
|
+
|
|
330
|
+
Developed by [Your Name/Organization].
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
# DevPy CLI
|
|
2
|
+
|
|
3
|
+
An intelligent command-line assistant powered by LLM (DeepSeek/OpenAI) to manage Docker environments, both local and remote via SSH. Designed to simplify DevOps tasks with natural language, ensuring security and control.
|
|
4
|
+
|
|
5
|
+
## Key Features
|
|
6
|
+
|
|
7
|
+
* **Natural Language Interaction**: "Restart the nginx container", "Show database logs", "Monitor memory usage".
|
|
8
|
+
* **Local and Remote Docker Management**: Connect to your local machine or remote servers via SSH transparently.
|
|
9
|
+
* **Secure SSH Key Management**: Encrypted storage (AES-256) of SSH private keys. Import from `~/.ssh`.
|
|
10
|
+
* **Granular Permission System**:
|
|
11
|
+
* Interactive confirmation for critical operations (write/delete).
|
|
12
|
+
* Configurable whitelists.
|
|
13
|
+
* Persistent permission rules with hot-reload.
|
|
14
|
+
* "Dry-Run" mode to simulate executions.
|
|
15
|
+
* **Logging and Auditing**: Detailed logging of all operations and permission decisions in `logs/permissions.log`.
|
|
16
|
+
|
|
17
|
+
## System Requirements
|
|
18
|
+
|
|
19
|
+
* Python 3.9 or higher.
|
|
20
|
+
* Docker client installed (local) or SSH access to a server with Docker.
|
|
21
|
+
* Operating System: Windows, macOS, Linux.
|
|
22
|
+
|
|
23
|
+
## Installation
|
|
24
|
+
|
|
25
|
+
1. **Clone the repository:**
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
git clone <repo-url>
|
|
29
|
+
cd devpy-cli
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
2. **Create virtual environment (recommended):**
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
python -m venv venv
|
|
36
|
+
# Windows
|
|
37
|
+
.\venv\Scripts\activate
|
|
38
|
+
# Linux/Mac
|
|
39
|
+
source venv/bin/activate
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
3. **Install dependencies:**
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
pip install -e .
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
4. **Configure environment:**
|
|
49
|
+
Create a `.env` file in the root (you can copy the example if it exists) with your LLM API key:
|
|
50
|
+
|
|
51
|
+
```ini
|
|
52
|
+
DEEPSEEK_API_KEY=your_api_key_here
|
|
53
|
+
# Optional: LLM=chatgpt and OPENAI_API_KEY=...
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Usage Guide
|
|
57
|
+
|
|
58
|
+
### Start the CLI
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
# From the repository
|
|
62
|
+
python app.py
|
|
63
|
+
|
|
64
|
+
# Or if installed in editable mode
|
|
65
|
+
devpy-cli
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
On first run, if no `.env` file exists, an interactive setup wizard will guide you through:
|
|
69
|
+
- Choosing your LLM provider.
|
|
70
|
+
- Entering the API key.
|
|
71
|
+
- Optionally setting a custom base URL.
|
|
72
|
+
|
|
73
|
+
After setup, the CLI banner appears and you are asked whether to enable dry-run mode.
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
### CLI Mode (Local Docker)
|
|
78
|
+
|
|
79
|
+
Use this mode when you want to manage containers running on the same machine where DevPy CLI is installed.
|
|
80
|
+
|
|
81
|
+
- **Requirements**
|
|
82
|
+
- Docker is installed and the daemon is running locally.
|
|
83
|
+
- Your user can talk to the Docker socket (e.g., `docker ps` works from your shell).
|
|
84
|
+
|
|
85
|
+
- **Step-by-step**
|
|
86
|
+
1. Start the CLI (see above).
|
|
87
|
+
2. When prompted, choose whether to enable dry-run mode.
|
|
88
|
+
3. Ensure the mode is set to `local` (this is the default):
|
|
89
|
+
```bash
|
|
90
|
+
config mode local
|
|
91
|
+
```
|
|
92
|
+
4. Type natural language instructions, for example:
|
|
93
|
+
- `What containers are running?`
|
|
94
|
+
- `Restart the nginx container and show me its latest logs`
|
|
95
|
+
- `Create a redis container called cache`
|
|
96
|
+
5. When an action is potentially destructive (creating/stopping/removing containers, starting monitors, etc.), DevPy will:
|
|
97
|
+
- Show a preview of the Docker command.
|
|
98
|
+
- Ask for confirmation (once, for the command, or for the whole session).
|
|
99
|
+
|
|
100
|
+
- **Typical local use cases**
|
|
101
|
+
- Quickly inspecting and restarting local services from the terminal.
|
|
102
|
+
- Checking logs of a misbehaving container.
|
|
103
|
+
- Spinning up utility containers (e.g., Redis, Postgres) by name and image.
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
### SSH Mode (Remote Docker over SSH)
|
|
108
|
+
|
|
109
|
+
Use this mode to manage containers on a remote host over SSH, while still talking to the CLI locally.
|
|
110
|
+
|
|
111
|
+
- **Prerequisites**
|
|
112
|
+
- The remote server:
|
|
113
|
+
- Has Docker installed and running.
|
|
114
|
+
- Is reachable via SSH (e.g., `ssh user@host` works).
|
|
115
|
+
- You have an SSH private key that can authenticate to that server.
|
|
116
|
+
|
|
117
|
+
- **Step 1: Store your SSH key (encrypted)**
|
|
118
|
+
|
|
119
|
+
You can import keys from `~/.ssh` or add a specific file:
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
# Scan ~/.ssh for potential keys and import one
|
|
123
|
+
keys scan
|
|
124
|
+
|
|
125
|
+
# Or add a specific key path
|
|
126
|
+
keys add my-remote /path/to/id_rsa
|
|
127
|
+
|
|
128
|
+
# List stored keys
|
|
129
|
+
keys list
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
During `keys scan` or `keys add`, you are asked for a **passphrase for encryption**.
|
|
133
|
+
This passphrase is used to derive a key that encrypts your private key on disk (AES-256 via `cryptography.Fernet`).
|
|
134
|
+
|
|
135
|
+
- **Step 2: Configure SSH connection**
|
|
136
|
+
|
|
137
|
+
In the CLI, run:
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
config ssh
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
You will be prompted for:
|
|
144
|
+
- **SSH Host** (e.g., `myserver.example.com` or `192.168.1.100`)
|
|
145
|
+
- **SSH User** (e.g., `ubuntu`, `root`, `deploy`)
|
|
146
|
+
- **SSH Key Name** (one of the names returned by `keys list`)
|
|
147
|
+
|
|
148
|
+
This information is stored in `config.json`.
|
|
149
|
+
|
|
150
|
+
- **Step 3: Switch to SSH mode**
|
|
151
|
+
|
|
152
|
+
```bash
|
|
153
|
+
config mode ssh
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
From now on, Docker operations happen against the remote host using the stored SSH configuration.
|
|
157
|
+
|
|
158
|
+
- **Step 4: Authenticate with your key**
|
|
159
|
+
|
|
160
|
+
When the backend needs to connect to the remote Docker daemon, it:
|
|
161
|
+
- Prompts for the passphrase you used when storing the key, **or**
|
|
162
|
+
- Uses the `DOCKER_SSH_PASSPHRASE` environment variable if it is set.
|
|
163
|
+
|
|
164
|
+
This decrypted key is written to a temporary file (with restricted permissions) and used only for the SSH connection.
|
|
165
|
+
|
|
166
|
+
- **Typical SSH use cases**
|
|
167
|
+
- Managing a remote Docker host from your laptop without logging in manually.
|
|
168
|
+
- Checking logs and restarting containers in staging/production environments.
|
|
169
|
+
- Monitoring memory usage of remote containers and triggering alerts.
|
|
170
|
+
|
|
171
|
+
---
|
|
172
|
+
|
|
173
|
+
### Command Reference
|
|
174
|
+
|
|
175
|
+
#### Configuration Commands
|
|
176
|
+
|
|
177
|
+
Use these to configure how the CLI connects and which LLM it uses:
|
|
178
|
+
|
|
179
|
+
```bash
|
|
180
|
+
# Show or set connection mode
|
|
181
|
+
config mode # shows current mode (local or ssh)
|
|
182
|
+
config mode local # use local Docker
|
|
183
|
+
config mode ssh # use remote Docker over SSH
|
|
184
|
+
|
|
185
|
+
# Configure SSH details (host, user, key)
|
|
186
|
+
config ssh
|
|
187
|
+
|
|
188
|
+
# Re-run the LLM setup wizard and regenerate .env
|
|
189
|
+
config llm
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
#### SSH Key Management Commands
|
|
193
|
+
|
|
194
|
+
```bash
|
|
195
|
+
# Import keys from ~/.ssh (interactive)
|
|
196
|
+
keys scan
|
|
197
|
+
|
|
198
|
+
# Add a key manually
|
|
199
|
+
keys add <name> <path_to_private_key>
|
|
200
|
+
|
|
201
|
+
# List saved keys
|
|
202
|
+
keys list
|
|
203
|
+
|
|
204
|
+
# Delete a stored key
|
|
205
|
+
keys delete <name>
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
#### Permission Management Commands
|
|
209
|
+
|
|
210
|
+
Control what the agent is allowed to do:
|
|
211
|
+
|
|
212
|
+
```bash
|
|
213
|
+
# View current rules
|
|
214
|
+
permissions list
|
|
215
|
+
|
|
216
|
+
# Block container restarts permanently
|
|
217
|
+
permissions add restart_container deny
|
|
218
|
+
|
|
219
|
+
# Allow container creation (with optional parameters)
|
|
220
|
+
permissions add create_container allow
|
|
221
|
+
|
|
222
|
+
# Reset all persistent permission rules
|
|
223
|
+
permissions reset
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
During interactive confirmations, you can choose:
|
|
227
|
+
- `y` – allow once.
|
|
228
|
+
- `yc` – always allow this exact command during the session.
|
|
229
|
+
- `ys` – always allow this operation type during the session.
|
|
230
|
+
- `n` – deny.
|
|
231
|
+
|
|
232
|
+
---
|
|
233
|
+
|
|
234
|
+
### Interaction Examples with the Agent
|
|
235
|
+
|
|
236
|
+
Once configured, simply type what you need:
|
|
237
|
+
|
|
238
|
+
- *"What containers are running?"*
|
|
239
|
+
- *"Restart the 'web-app' container and show me its latest logs"*
|
|
240
|
+
- *"Create a redis container named 'my-redis'"*
|
|
241
|
+
- *"Alert me if memory usage of container 'api' exceeds 80%"*
|
|
242
|
+
|
|
243
|
+
The agent plans and executes one or more Docker operations, asking for permission when necessary.
|
|
244
|
+
|
|
245
|
+
---
|
|
246
|
+
|
|
247
|
+
### Dry-Run Mode
|
|
248
|
+
|
|
249
|
+
You can enable dry-run mode in two ways:
|
|
250
|
+
|
|
251
|
+
- At startup, when the CLI asks:
|
|
252
|
+
- Answer `y` to run in dry-run mode for the session.
|
|
253
|
+
- Via environment variable:
|
|
254
|
+
- Set `DRY_RUN=1` before starting the app.
|
|
255
|
+
|
|
256
|
+
In this mode, the agent **simulates** write actions (creating, deleting, restarting containers, starting monitors, etc.) without actually executing them.
|
|
257
|
+
The permission log still records what *would* have been executed.
|
|
258
|
+
|
|
259
|
+
---
|
|
260
|
+
|
|
261
|
+
## Authentication and Security
|
|
262
|
+
|
|
263
|
+
- **LLM API Authentication**
|
|
264
|
+
- The `.env` file created by the setup wizard stores:
|
|
265
|
+
- `LLM` – which provider/adapter to use.
|
|
266
|
+
- `<PROVIDER>_API_KEY` – the API key for that provider.
|
|
267
|
+
- Optionally `LLM_BASE_URL` – custom base URL for compatible providers.
|
|
268
|
+
- You can re-run the wizard at any time with:
|
|
269
|
+
```bash
|
|
270
|
+
config llm
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
- **SSH Key Encryption**
|
|
274
|
+
- Stored SSH keys live in `ssh_keys.enc`.
|
|
275
|
+
- Each key is encrypted using a passphrase-derived key (PBKDF2 + AES-256).
|
|
276
|
+
- The file permissions are hardened to allow read/write only for the current user.
|
|
277
|
+
|
|
278
|
+
- **Runtime Environment Variables**
|
|
279
|
+
- `DRY_RUN` – if set to `1`, `true`, `yes`, or `y`, forces dry-run mode.
|
|
280
|
+
- `DOCKER_SSH_PASSPHRASE` – optional; if set, avoids interactive passphrase prompts for SSH keys.
|
|
281
|
+
- `DOCKER_SAFE_COMMANDS` – comma-separated list of operations that never prompt for confirmation.
|
|
282
|
+
- `DOCKER_CLI_USER` – overrides the username recorded in permission logs.
|
|
283
|
+
|
|
284
|
+
- **Logging and Auditing**
|
|
285
|
+
- All operations go through a permission and logging layer.
|
|
286
|
+
- Logs are written as JSON lines to `logs/permissions.log`.
|
|
287
|
+
- Each entry includes timestamp, user, operation, arguments, decision, and optional command preview.
|
|
288
|
+
|
|
289
|
+
## Project Structure
|
|
290
|
+
|
|
291
|
+
* `app.py`: Entry point.
|
|
292
|
+
* `frontend_cli.py`: User interface and CLI command handling.
|
|
293
|
+
* `backend.py`: Agent logic, integration with LangChain/LangGraph and Docker tools.
|
|
294
|
+
* `permissions_manager.py`: Access control and auditing system.
|
|
295
|
+
* `ssh_key_manager.py`: Encryption and key management.
|
|
296
|
+
* `config_manager.py`: Configuration persistence (mode, ssh host).
|
|
297
|
+
* `logs/`: Audit log files.
|
|
298
|
+
|
|
299
|
+
## License
|
|
300
|
+
|
|
301
|
+
MIT License. See `LICENSE` file for more details.
|
|
302
|
+
|
|
303
|
+
## Author
|
|
304
|
+
|
|
305
|
+
Developed by [Your Name/Organization].
|
devpy_cli-1.0.0/app.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
# Check for .env before importing frontend_cli which imports backend
|
|
4
|
+
if not os.path.exists('.env'):
|
|
5
|
+
try:
|
|
6
|
+
from setup_wizard import run_setup
|
|
7
|
+
|
|
8
|
+
run_setup()
|
|
9
|
+
except ImportError:
|
|
10
|
+
print('Error: setup_wizard module not found. Please ensure all files are installed correctly.')
|
|
11
|
+
exit(1)
|
|
12
|
+
|
|
13
|
+
from frontend_cli import run_cli
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
if __name__ == '__main__':
|
|
17
|
+
run_cli()
|