opensecagent 0.2.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.
- opensecagent-0.2.0/PKG-INFO +329 -0
- opensecagent-0.2.0/README.md +290 -0
- opensecagent-0.2.0/opensecagent/__init__.py +2 -0
- opensecagent-0.2.0/opensecagent/__main__.py +5 -0
- opensecagent-0.2.0/opensecagent/cli.py +608 -0
- opensecagent-0.2.0/opensecagent/collector/__init__.py +1 -0
- opensecagent-0.2.0/opensecagent/collector/docker_collector.py +70 -0
- opensecagent-0.2.0/opensecagent/collector/drift.py +120 -0
- opensecagent-0.2.0/opensecagent/collector/host.py +137 -0
- opensecagent-0.2.0/opensecagent/config/default.yaml +93 -0
- opensecagent-0.2.0/opensecagent/config.py +241 -0
- opensecagent-0.2.0/opensecagent/daemon.py +281 -0
- opensecagent-0.2.0/opensecagent/detector/__init__.py +1 -0
- opensecagent-0.2.0/opensecagent/detector/auth.py +50 -0
- opensecagent-0.2.0/opensecagent/detector/containers.py +31 -0
- opensecagent-0.2.0/opensecagent/detector/manager.py +124 -0
- opensecagent-0.2.0/opensecagent/detector/ports.py +27 -0
- opensecagent-0.2.0/opensecagent/detector/resources.py +73 -0
- opensecagent-0.2.0/opensecagent/detector/users.py +27 -0
- opensecagent-0.2.0/opensecagent/llm_advisor.py +58 -0
- opensecagent-0.2.0/opensecagent/llm_agent.py +247 -0
- opensecagent-0.2.0/opensecagent/llm_client.py +83 -0
- opensecagent-0.2.0/opensecagent/main.py +76 -0
- opensecagent-0.2.0/opensecagent/models.py +95 -0
- opensecagent-0.2.0/opensecagent/normalizer.py +42 -0
- opensecagent-0.2.0/opensecagent/policy_engine.py +46 -0
- opensecagent-0.2.0/opensecagent/prompts.py +37 -0
- opensecagent-0.2.0/opensecagent/reporter/__init__.py +1 -0
- opensecagent-0.2.0/opensecagent/reporter/activity.py +147 -0
- opensecagent-0.2.0/opensecagent/reporter/audit.py +74 -0
- opensecagent-0.2.0/opensecagent/reporter/email_reporter.py +200 -0
- opensecagent-0.2.0/opensecagent/reporter/manager.py +92 -0
- opensecagent-0.2.0/opensecagent/reporter/pdf_report.py +74 -0
- opensecagent-0.2.0/opensecagent/responder.py +64 -0
- opensecagent-0.2.0/opensecagent/threat_registry.py +92 -0
- opensecagent-0.2.0/opensecagent.egg-info/PKG-INFO +329 -0
- opensecagent-0.2.0/opensecagent.egg-info/SOURCES.txt +42 -0
- opensecagent-0.2.0/opensecagent.egg-info/dependency_links.txt +1 -0
- opensecagent-0.2.0/opensecagent.egg-info/entry_points.txt +3 -0
- opensecagent-0.2.0/opensecagent.egg-info/requires.txt +16 -0
- opensecagent-0.2.0/opensecagent.egg-info/top_level.txt +1 -0
- opensecagent-0.2.0/pyproject.toml +60 -0
- opensecagent-0.2.0/setup.cfg +4 -0
- opensecagent-0.2.0/tests/test_models.py +18 -0
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: opensecagent
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Autonomous Server Cybersecurity Expert Bot - monitors hosts and containers, detects risks, recommends and executes safe remediation
|
|
5
|
+
Author: OpenSecAgent Contributors
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/DulanDias/opensecagent
|
|
8
|
+
Project-URL: Repository, https://github.com/DulanDias/opensecagent
|
|
9
|
+
Project-URL: Issues, https://github.com/DulanDias/opensecagent/issues
|
|
10
|
+
Keywords: security,cybersecurity,monitoring,docker,incident-response
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: System Administrators
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Topic :: Security
|
|
22
|
+
Requires-Python: >=3.9
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
Requires-Dist: pyyaml>=6.0.1
|
|
25
|
+
Requires-Dist: python-dotenv>=1.0.0
|
|
26
|
+
Requires-Dist: aiofiles>=23.2.1
|
|
27
|
+
Requires-Dist: aiohttp>=3.9.0
|
|
28
|
+
Requires-Dist: docker>=7.0.0
|
|
29
|
+
Requires-Dist: aiosmtplib>=3.0.0
|
|
30
|
+
Requires-Dist: openai>=1.12.0
|
|
31
|
+
Requires-Dist: anthropic>=0.39.0
|
|
32
|
+
Requires-Dist: httpx>=0.26.0
|
|
33
|
+
Requires-Dist: filelock>=3.13.0
|
|
34
|
+
Requires-Dist: psutil>=5.9.0
|
|
35
|
+
Requires-Dist: reportlab>=4.0.0
|
|
36
|
+
Provides-Extra: dev
|
|
37
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
38
|
+
Requires-Dist: pytest-asyncio>=0.21; extra == "dev"
|
|
39
|
+
|
|
40
|
+
# OpenSecAgent
|
|
41
|
+
|
|
42
|
+
<p align="center">
|
|
43
|
+
<strong>Autonomous Server Cybersecurity Expert Bot</strong>
|
|
44
|
+
</p>
|
|
45
|
+
|
|
46
|
+
<p align="center">
|
|
47
|
+
A server-side security agent that continuously monitors hosts and containers, detects risky changes, recommends and executes safe remediation, and produces clear reports—all with explainable security.
|
|
48
|
+
</p>
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## Overview
|
|
53
|
+
|
|
54
|
+
**OpenSecAgent** is an open-source, server-resident security agent for small/medium companies, DevOps teams, and MSPs. It reduces time-to-detect and time-to-contain incidents by:
|
|
55
|
+
|
|
56
|
+
- **Continuous monitoring** of host and container assets
|
|
57
|
+
- **Drift detection** for critical config files
|
|
58
|
+
- **Rule-based detectors** (auth failures, new admins, new ports, new containers)
|
|
59
|
+
- **Policy-controlled remediation** (alert-only or soft containment)
|
|
60
|
+
- **Audit trail** and email alerts
|
|
61
|
+
|
|
62
|
+
### One-liner
|
|
63
|
+
|
|
64
|
+
> OpenSecAgent is a server-side security expert that continuously watches your hosts and containers, explains risk in plain English, and safely contains incidents—then emails you a clean report.
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
## Current Implementation Status
|
|
69
|
+
|
|
70
|
+
| Feature | Status | Notes |
|
|
71
|
+
|--------|--------|-------|
|
|
72
|
+
| Host inventory (OS, packages, services, ports, sudo users) | ✅ Implemented | dpkg/rpm, systemd, ss/netstat |
|
|
73
|
+
| Docker inventory (containers, images) | ✅ Implemented | Via Docker SDK |
|
|
74
|
+
| Drift monitoring (critical files) | ✅ Implemented | Baseline + hash diff |
|
|
75
|
+
| Detectors (auth, admin, ports, containers) | ✅ Implemented | Rule-based |
|
|
76
|
+
| Policy engine (Tier 0/1) | ✅ Implemented | Alert-only + soft containment |
|
|
77
|
+
| Responder (stop container, block IP stub) | ✅ Implemented | Docker stop; IP block placeholder |
|
|
78
|
+
| Audit log (incidents + actions) | ✅ Implemented | JSONL append-only |
|
|
79
|
+
| Email (immediate + daily digest) | ✅ Implemented | SMTP |
|
|
80
|
+
| LLM summaries | ✅ Implemented | Optional; incident summaries only |
|
|
81
|
+
| **LLM agent (command loop)** | ✅ Implemented | LLM suggests commands → execute → feed back → repeat (whitelist) |
|
|
82
|
+
| **Full activity logging** | ✅ Implemented | Every collector, detector, command, LLM call in activity.jsonl |
|
|
83
|
+
| **Packaging (pip, Docker)** | ✅ Implemented | `pip install opensecagent`, Dockerfile, docker-compose |
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## Installation
|
|
88
|
+
|
|
89
|
+
### Option A: pip (recommended)
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
pip install opensecagent
|
|
93
|
+
opensecagent config # interactive wizard → writes config (no path needed)
|
|
94
|
+
opensecagent status # or run the daemon: opensecagent
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
After `opensecagent config`, the config file is written to `/etc/opensecagent/config.yaml` (if writable) or `~/.config/opensecagent/config.yaml`. You never need to pass `--config` unless you use a custom path.
|
|
98
|
+
|
|
99
|
+
### Option B: From source
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
git clone https://github.com/DulanDias/opensecagent.git
|
|
103
|
+
cd opensecagent
|
|
104
|
+
pip install -e .
|
|
105
|
+
opensecagent config # wizard → writes config
|
|
106
|
+
opensecagent status
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Option C: systemd service
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
# After cloning or extracting
|
|
113
|
+
sudo SOURCE_DIR=/path/to/opensecagent bash scripts/install.sh
|
|
114
|
+
sudo vi /etc/opensecagent/config.yaml # Configure admin_emails, smtp, etc.
|
|
115
|
+
sudo systemctl enable opensecagent && sudo systemctl start opensecagent
|
|
116
|
+
sudo journalctl -u opensecagent -f
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Option D: Docker
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
# Build and run
|
|
123
|
+
docker build -t opensecagent .
|
|
124
|
+
docker run -d --name opensecagent \
|
|
125
|
+
-v /var/run/docker.sock:/var/run/docker.sock \
|
|
126
|
+
-v /etc/opensecagent:/etc/opensecagent \
|
|
127
|
+
-v /var/lib/opensecagent:/var/lib/opensecagent \
|
|
128
|
+
-v /var/log/opensecagent:/var/log/opensecagent \
|
|
129
|
+
opensecagent
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
---
|
|
133
|
+
|
|
134
|
+
## Configuration
|
|
135
|
+
|
|
136
|
+
**Easiest:** run `opensecagent config`. You answer a few questions (scan frequency, email, LLM API key, etc.) and the tool writes the YAML for you. No need to pass a config path afterward.
|
|
137
|
+
|
|
138
|
+
**Config file location** (when not using `--config`): `/etc/opensecagent/config.yaml` or `~/.config/opensecagent/config.yaml`. Override with `OPENSECAGENT_CONFIG=/path/to/config.yaml` or `opensecagent --config /path/to/config.yaml`.
|
|
139
|
+
|
|
140
|
+
| Key | Description | Default |
|
|
141
|
+
|-----|-------------|---------|
|
|
142
|
+
| `agent.data_dir` | State and drift baseline | `/var/lib/opensecagent` |
|
|
143
|
+
| `agent.log_dir` | Log directory | `/var/log/opensecagent` |
|
|
144
|
+
| `collector.host_interval_sec` | Host inventory interval | 300 |
|
|
145
|
+
| `collector.docker_interval_sec` | Docker inventory interval | 60 |
|
|
146
|
+
| `collector.drift_interval_sec` | Drift check interval | 300 |
|
|
147
|
+
| `collector.critical_files` | Files to monitor for drift | `/etc/passwd`, `/etc/sudoers`, etc. |
|
|
148
|
+
| `action_tier_max` | 0=alert only, 1=soft containment | 1 |
|
|
149
|
+
| `notifications.admin_emails` | Alert recipients | `[]` |
|
|
150
|
+
| `notifications.smtp` | SMTP host, port, user, password | — |
|
|
151
|
+
| `llm.enabled` | Use LLM for summaries + agent | false |
|
|
152
|
+
| `llm.api_key` | OpenAI (or compatible) API key | — |
|
|
153
|
+
| `llm_agent.enabled` | Run LLM agent loop on incidents | false |
|
|
154
|
+
| `llm_agent.run_on_incident` | Run agent when P1/P2 incident | true |
|
|
155
|
+
| `llm_agent.run_interval_sec` | Periodic agent run (0=disabled) | 0 |
|
|
156
|
+
| `audit.file` | Audit log path | `/var/log/opensecagent/audit.jsonl` |
|
|
157
|
+
| `activity.file` | Activity log path | `/var/log/opensecagent/activity.jsonl` |
|
|
158
|
+
|
|
159
|
+
---
|
|
160
|
+
|
|
161
|
+
## Setup & configuration (CLI, wizard-driven)
|
|
162
|
+
|
|
163
|
+
**Recommended: run the full wizard once** (paths → config → validate → optional systemd install):
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
opensecagent wizard
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
The wizard will prompt for: config/data/log directories, admin emails, SMTP, environment, action tier, LLM (optional), then validate, and optionally install the systemd service.
|
|
170
|
+
|
|
171
|
+
**Other commands** (all support interactive/wizard-style where noted):
|
|
172
|
+
|
|
173
|
+
```bash
|
|
174
|
+
# Setup with interactive prompts (paths + optional config wizard)
|
|
175
|
+
opensecagent setup --interactive
|
|
176
|
+
|
|
177
|
+
# Or non-interactive with explicit paths
|
|
178
|
+
opensecagent setup --config-dir /etc/opensecagent --data-dir /var/lib/opensecagent --log-dir /var/log/opensecagent
|
|
179
|
+
|
|
180
|
+
# Configure (interactive wizard)
|
|
181
|
+
opensecagent --config /etc/opensecagent/config.yaml config wizard
|
|
182
|
+
|
|
183
|
+
# Or set single keys
|
|
184
|
+
opensecagent --config /etc/opensecagent/config.yaml config set notifications.smtp.host smtp.example.com
|
|
185
|
+
opensecagent --config /etc/opensecagent/config.yaml config set notifications.admin_emails.0 admin@example.com
|
|
186
|
+
|
|
187
|
+
# Validate and show config
|
|
188
|
+
opensecagent --config /etc/opensecagent/config.yaml config validate
|
|
189
|
+
opensecagent --config /etc/opensecagent/config.yaml config show
|
|
190
|
+
|
|
191
|
+
# Install systemd (interactive: prompts for dirs and start service)
|
|
192
|
+
opensecagent install --interactive
|
|
193
|
+
# Or non-interactive
|
|
194
|
+
opensecagent install --config-dir /etc/opensecagent --no-start
|
|
195
|
+
|
|
196
|
+
# Status and uninstall
|
|
197
|
+
opensecagent --config /etc/opensecagent/config.yaml status
|
|
198
|
+
opensecagent uninstall --remove-unit
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
| Command | Description |
|
|
202
|
+
|---------|-------------|
|
|
203
|
+
| `wizard` | **Full wizard**: paths → config → validate → optional install → status |
|
|
204
|
+
| `setup` | Create dirs + default config; `--interactive` / `-i` prompts for paths and runs config wizard |
|
|
205
|
+
| `config wizard` | Interactive config (emails, SMTP, env, tier, LLM) |
|
|
206
|
+
| `config set KEY VALUE` | Set one key (dot notation) |
|
|
207
|
+
| `config show` | Print merged config as YAML |
|
|
208
|
+
| `config validate` | Validate config file |
|
|
209
|
+
| `install` | Install systemd unit; `--interactive` / `-i` prompts for dirs and start service |
|
|
210
|
+
| `status` | Show version, paths, daemon state |
|
|
211
|
+
| `uninstall` | Stop/disable service; `--remove-unit` to remove unit file |
|
|
212
|
+
|
|
213
|
+
---
|
|
214
|
+
|
|
215
|
+
## CLI (run & export)
|
|
216
|
+
|
|
217
|
+
```bash
|
|
218
|
+
# One-off collection (host + Docker)
|
|
219
|
+
opensecagent --config config/default.yaml collect
|
|
220
|
+
|
|
221
|
+
# Drift check
|
|
222
|
+
opensecagent --config config/default.yaml drift
|
|
223
|
+
|
|
224
|
+
# Run detectors
|
|
225
|
+
opensecagent --config config/default.yaml detect
|
|
226
|
+
|
|
227
|
+
# Run LLM agent loop once (scan + fix; requires llm.enabled and api_key)
|
|
228
|
+
opensecagent --config config/default.yaml agent
|
|
229
|
+
|
|
230
|
+
# Export audit log as JSON
|
|
231
|
+
opensecagent --config config/default.yaml export-audit --path /var/log/opensecagent/audit.jsonl
|
|
232
|
+
|
|
233
|
+
# Export activity log as JSON
|
|
234
|
+
opensecagent --config config/default.yaml export-activity --path /var/log/opensecagent/activity.jsonl
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
---
|
|
238
|
+
|
|
239
|
+
## Logging & Audit
|
|
240
|
+
|
|
241
|
+
- **Audit log** (`audit.file`): Append-only JSONL with incidents and actions. Use `export-audit` to convert to JSON.
|
|
242
|
+
- **Activity log** (`activity.file`): Full activity log—every collector run, detector run, policy decision, command execution, LLM call. Use `export-activity` to convert to JSON.
|
|
243
|
+
- **Python logging**: INFO to stdout (daemon start/stop, errors). Redirect to a file or use systemd/journal.
|
|
244
|
+
|
|
245
|
+
---
|
|
246
|
+
|
|
247
|
+
## Deployment Options
|
|
248
|
+
|
|
249
|
+
| Environment | How to deploy |
|
|
250
|
+
|-------------|---------------|
|
|
251
|
+
| **Bare metal / VPS** | systemd service via `scripts/install.sh` |
|
|
252
|
+
| **Docker host** | Run agent in container with Docker socket mount |
|
|
253
|
+
| **AWS EC2 / Lightsail** | systemd on Amazon Linux / Ubuntu |
|
|
254
|
+
| **GCP Compute / Azure VM** | systemd on Debian/Ubuntu |
|
|
255
|
+
| **Kubernetes** | DaemonSet (planned) |
|
|
256
|
+
| **Managed service** | Self-host on your infra; no SaaS yet |
|
|
257
|
+
|
|
258
|
+
### Where to run OpenSecAgent
|
|
259
|
+
|
|
260
|
+
- **On each server** you want to protect (agent per host)
|
|
261
|
+
- **Central management server** (optional control plane, planned)
|
|
262
|
+
- **MSP / multi-tenant**: One agent per client server; central dashboard planned
|
|
263
|
+
|
|
264
|
+
---
|
|
265
|
+
|
|
266
|
+
## Architecture
|
|
267
|
+
|
|
268
|
+
```
|
|
269
|
+
┌─────────────────────────────────────────────────────────────────┐
|
|
270
|
+
│ OpenSecAgent Daemon │
|
|
271
|
+
├─────────────────────────────────────────────────────────────────┤
|
|
272
|
+
│ Collectors │ Detectors │ Policy Engine │
|
|
273
|
+
│ • Host inventory │ • Auth failures │ • Action tiers │
|
|
274
|
+
│ • Docker inventory │ • New admin user │ • Maintenance windows│
|
|
275
|
+
│ • Drift monitor │ • New port │ │
|
|
276
|
+
│ │ • New container │ Responder │
|
|
277
|
+
│ │ │ • Stop container │
|
|
278
|
+
│ │ │ • Block IP (stub) │
|
|
279
|
+
├─────────────────────────────────────────────────────────────────┤
|
|
280
|
+
│ Reporter: Audit (JSONL) │ Email (SMTP) │ LLM summaries (optional)│
|
|
281
|
+
└─────────────────────────────────────────────────────────────────┘
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
---
|
|
285
|
+
|
|
286
|
+
## Security
|
|
287
|
+
|
|
288
|
+
- **Defensive only**: No offensive scanning, exploitation, or "hacking back"
|
|
289
|
+
- **Policy-first**: High-impact actions require policy and (optionally) approval
|
|
290
|
+
- **Sensitive data**: Redacted before sending to LLM
|
|
291
|
+
- **Least privilege**: Run as dedicated user where possible; escalate only for specific tasks
|
|
292
|
+
|
|
293
|
+
---
|
|
294
|
+
|
|
295
|
+
## Roadmap
|
|
296
|
+
|
|
297
|
+
- [x] **LLM agent loop**: LLM suggests commands → execute → feed output back → repeat (whitelist-based)
|
|
298
|
+
- [x] **Full activity logging**: Every collector, detector, command in activity.jsonl
|
|
299
|
+
- [x] **pip package**: `pip install opensecagent`
|
|
300
|
+
- [x] **Docker image**: Dockerfile included
|
|
301
|
+
- [ ] **Kubernetes DaemonSet**: For cluster-wide deployment
|
|
302
|
+
- [ ] **Control plane**: Central dashboard, multi-tenant, policy management
|
|
303
|
+
- [ ] **Slack/Teams/PagerDuty**: Additional notification channels
|
|
304
|
+
- [ ] **Compliance packs**: SOC2/ISO27001 mapping reports
|
|
305
|
+
|
|
306
|
+
---
|
|
307
|
+
|
|
308
|
+
## Contributing
|
|
309
|
+
|
|
310
|
+
Contributions are welcome. Please open an issue or PR on GitHub.
|
|
311
|
+
|
|
312
|
+
1. Fork the repo
|
|
313
|
+
2. Create a feature branch
|
|
314
|
+
3. Add tests where applicable
|
|
315
|
+
4. Submit a pull request
|
|
316
|
+
|
|
317
|
+
---
|
|
318
|
+
|
|
319
|
+
## License
|
|
320
|
+
|
|
321
|
+
[Choose: MIT, Apache 2.0, or your preferred license]
|
|
322
|
+
|
|
323
|
+
---
|
|
324
|
+
|
|
325
|
+
## Links
|
|
326
|
+
|
|
327
|
+
- **GitHub**: https://github.com/DulanDias/opensecagent
|
|
328
|
+
- **Issues**: https://github.com/DulanDias/opensecagent/issues
|
|
329
|
+
- **Documentation**: (link when available)
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
# OpenSecAgent
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<strong>Autonomous Server Cybersecurity Expert Bot</strong>
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
A server-side security agent that continuously monitors hosts and containers, detects risky changes, recommends and executes safe remediation, and produces clear reports—all with explainable security.
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## Overview
|
|
14
|
+
|
|
15
|
+
**OpenSecAgent** is an open-source, server-resident security agent for small/medium companies, DevOps teams, and MSPs. It reduces time-to-detect and time-to-contain incidents by:
|
|
16
|
+
|
|
17
|
+
- **Continuous monitoring** of host and container assets
|
|
18
|
+
- **Drift detection** for critical config files
|
|
19
|
+
- **Rule-based detectors** (auth failures, new admins, new ports, new containers)
|
|
20
|
+
- **Policy-controlled remediation** (alert-only or soft containment)
|
|
21
|
+
- **Audit trail** and email alerts
|
|
22
|
+
|
|
23
|
+
### One-liner
|
|
24
|
+
|
|
25
|
+
> OpenSecAgent is a server-side security expert that continuously watches your hosts and containers, explains risk in plain English, and safely contains incidents—then emails you a clean report.
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## Current Implementation Status
|
|
30
|
+
|
|
31
|
+
| Feature | Status | Notes |
|
|
32
|
+
|--------|--------|-------|
|
|
33
|
+
| Host inventory (OS, packages, services, ports, sudo users) | ✅ Implemented | dpkg/rpm, systemd, ss/netstat |
|
|
34
|
+
| Docker inventory (containers, images) | ✅ Implemented | Via Docker SDK |
|
|
35
|
+
| Drift monitoring (critical files) | ✅ Implemented | Baseline + hash diff |
|
|
36
|
+
| Detectors (auth, admin, ports, containers) | ✅ Implemented | Rule-based |
|
|
37
|
+
| Policy engine (Tier 0/1) | ✅ Implemented | Alert-only + soft containment |
|
|
38
|
+
| Responder (stop container, block IP stub) | ✅ Implemented | Docker stop; IP block placeholder |
|
|
39
|
+
| Audit log (incidents + actions) | ✅ Implemented | JSONL append-only |
|
|
40
|
+
| Email (immediate + daily digest) | ✅ Implemented | SMTP |
|
|
41
|
+
| LLM summaries | ✅ Implemented | Optional; incident summaries only |
|
|
42
|
+
| **LLM agent (command loop)** | ✅ Implemented | LLM suggests commands → execute → feed back → repeat (whitelist) |
|
|
43
|
+
| **Full activity logging** | ✅ Implemented | Every collector, detector, command, LLM call in activity.jsonl |
|
|
44
|
+
| **Packaging (pip, Docker)** | ✅ Implemented | `pip install opensecagent`, Dockerfile, docker-compose |
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## Installation
|
|
49
|
+
|
|
50
|
+
### Option A: pip (recommended)
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
pip install opensecagent
|
|
54
|
+
opensecagent config # interactive wizard → writes config (no path needed)
|
|
55
|
+
opensecagent status # or run the daemon: opensecagent
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
After `opensecagent config`, the config file is written to `/etc/opensecagent/config.yaml` (if writable) or `~/.config/opensecagent/config.yaml`. You never need to pass `--config` unless you use a custom path.
|
|
59
|
+
|
|
60
|
+
### Option B: From source
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
git clone https://github.com/DulanDias/opensecagent.git
|
|
64
|
+
cd opensecagent
|
|
65
|
+
pip install -e .
|
|
66
|
+
opensecagent config # wizard → writes config
|
|
67
|
+
opensecagent status
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Option C: systemd service
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
# After cloning or extracting
|
|
74
|
+
sudo SOURCE_DIR=/path/to/opensecagent bash scripts/install.sh
|
|
75
|
+
sudo vi /etc/opensecagent/config.yaml # Configure admin_emails, smtp, etc.
|
|
76
|
+
sudo systemctl enable opensecagent && sudo systemctl start opensecagent
|
|
77
|
+
sudo journalctl -u opensecagent -f
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Option D: Docker
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
# Build and run
|
|
84
|
+
docker build -t opensecagent .
|
|
85
|
+
docker run -d --name opensecagent \
|
|
86
|
+
-v /var/run/docker.sock:/var/run/docker.sock \
|
|
87
|
+
-v /etc/opensecagent:/etc/opensecagent \
|
|
88
|
+
-v /var/lib/opensecagent:/var/lib/opensecagent \
|
|
89
|
+
-v /var/log/opensecagent:/var/log/opensecagent \
|
|
90
|
+
opensecagent
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
## Configuration
|
|
96
|
+
|
|
97
|
+
**Easiest:** run `opensecagent config`. You answer a few questions (scan frequency, email, LLM API key, etc.) and the tool writes the YAML for you. No need to pass a config path afterward.
|
|
98
|
+
|
|
99
|
+
**Config file location** (when not using `--config`): `/etc/opensecagent/config.yaml` or `~/.config/opensecagent/config.yaml`. Override with `OPENSECAGENT_CONFIG=/path/to/config.yaml` or `opensecagent --config /path/to/config.yaml`.
|
|
100
|
+
|
|
101
|
+
| Key | Description | Default |
|
|
102
|
+
|-----|-------------|---------|
|
|
103
|
+
| `agent.data_dir` | State and drift baseline | `/var/lib/opensecagent` |
|
|
104
|
+
| `agent.log_dir` | Log directory | `/var/log/opensecagent` |
|
|
105
|
+
| `collector.host_interval_sec` | Host inventory interval | 300 |
|
|
106
|
+
| `collector.docker_interval_sec` | Docker inventory interval | 60 |
|
|
107
|
+
| `collector.drift_interval_sec` | Drift check interval | 300 |
|
|
108
|
+
| `collector.critical_files` | Files to monitor for drift | `/etc/passwd`, `/etc/sudoers`, etc. |
|
|
109
|
+
| `action_tier_max` | 0=alert only, 1=soft containment | 1 |
|
|
110
|
+
| `notifications.admin_emails` | Alert recipients | `[]` |
|
|
111
|
+
| `notifications.smtp` | SMTP host, port, user, password | — |
|
|
112
|
+
| `llm.enabled` | Use LLM for summaries + agent | false |
|
|
113
|
+
| `llm.api_key` | OpenAI (or compatible) API key | — |
|
|
114
|
+
| `llm_agent.enabled` | Run LLM agent loop on incidents | false |
|
|
115
|
+
| `llm_agent.run_on_incident` | Run agent when P1/P2 incident | true |
|
|
116
|
+
| `llm_agent.run_interval_sec` | Periodic agent run (0=disabled) | 0 |
|
|
117
|
+
| `audit.file` | Audit log path | `/var/log/opensecagent/audit.jsonl` |
|
|
118
|
+
| `activity.file` | Activity log path | `/var/log/opensecagent/activity.jsonl` |
|
|
119
|
+
|
|
120
|
+
---
|
|
121
|
+
|
|
122
|
+
## Setup & configuration (CLI, wizard-driven)
|
|
123
|
+
|
|
124
|
+
**Recommended: run the full wizard once** (paths → config → validate → optional systemd install):
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
opensecagent wizard
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
The wizard will prompt for: config/data/log directories, admin emails, SMTP, environment, action tier, LLM (optional), then validate, and optionally install the systemd service.
|
|
131
|
+
|
|
132
|
+
**Other commands** (all support interactive/wizard-style where noted):
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
# Setup with interactive prompts (paths + optional config wizard)
|
|
136
|
+
opensecagent setup --interactive
|
|
137
|
+
|
|
138
|
+
# Or non-interactive with explicit paths
|
|
139
|
+
opensecagent setup --config-dir /etc/opensecagent --data-dir /var/lib/opensecagent --log-dir /var/log/opensecagent
|
|
140
|
+
|
|
141
|
+
# Configure (interactive wizard)
|
|
142
|
+
opensecagent --config /etc/opensecagent/config.yaml config wizard
|
|
143
|
+
|
|
144
|
+
# Or set single keys
|
|
145
|
+
opensecagent --config /etc/opensecagent/config.yaml config set notifications.smtp.host smtp.example.com
|
|
146
|
+
opensecagent --config /etc/opensecagent/config.yaml config set notifications.admin_emails.0 admin@example.com
|
|
147
|
+
|
|
148
|
+
# Validate and show config
|
|
149
|
+
opensecagent --config /etc/opensecagent/config.yaml config validate
|
|
150
|
+
opensecagent --config /etc/opensecagent/config.yaml config show
|
|
151
|
+
|
|
152
|
+
# Install systemd (interactive: prompts for dirs and start service)
|
|
153
|
+
opensecagent install --interactive
|
|
154
|
+
# Or non-interactive
|
|
155
|
+
opensecagent install --config-dir /etc/opensecagent --no-start
|
|
156
|
+
|
|
157
|
+
# Status and uninstall
|
|
158
|
+
opensecagent --config /etc/opensecagent/config.yaml status
|
|
159
|
+
opensecagent uninstall --remove-unit
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
| Command | Description |
|
|
163
|
+
|---------|-------------|
|
|
164
|
+
| `wizard` | **Full wizard**: paths → config → validate → optional install → status |
|
|
165
|
+
| `setup` | Create dirs + default config; `--interactive` / `-i` prompts for paths and runs config wizard |
|
|
166
|
+
| `config wizard` | Interactive config (emails, SMTP, env, tier, LLM) |
|
|
167
|
+
| `config set KEY VALUE` | Set one key (dot notation) |
|
|
168
|
+
| `config show` | Print merged config as YAML |
|
|
169
|
+
| `config validate` | Validate config file |
|
|
170
|
+
| `install` | Install systemd unit; `--interactive` / `-i` prompts for dirs and start service |
|
|
171
|
+
| `status` | Show version, paths, daemon state |
|
|
172
|
+
| `uninstall` | Stop/disable service; `--remove-unit` to remove unit file |
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
## CLI (run & export)
|
|
177
|
+
|
|
178
|
+
```bash
|
|
179
|
+
# One-off collection (host + Docker)
|
|
180
|
+
opensecagent --config config/default.yaml collect
|
|
181
|
+
|
|
182
|
+
# Drift check
|
|
183
|
+
opensecagent --config config/default.yaml drift
|
|
184
|
+
|
|
185
|
+
# Run detectors
|
|
186
|
+
opensecagent --config config/default.yaml detect
|
|
187
|
+
|
|
188
|
+
# Run LLM agent loop once (scan + fix; requires llm.enabled and api_key)
|
|
189
|
+
opensecagent --config config/default.yaml agent
|
|
190
|
+
|
|
191
|
+
# Export audit log as JSON
|
|
192
|
+
opensecagent --config config/default.yaml export-audit --path /var/log/opensecagent/audit.jsonl
|
|
193
|
+
|
|
194
|
+
# Export activity log as JSON
|
|
195
|
+
opensecagent --config config/default.yaml export-activity --path /var/log/opensecagent/activity.jsonl
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
---
|
|
199
|
+
|
|
200
|
+
## Logging & Audit
|
|
201
|
+
|
|
202
|
+
- **Audit log** (`audit.file`): Append-only JSONL with incidents and actions. Use `export-audit` to convert to JSON.
|
|
203
|
+
- **Activity log** (`activity.file`): Full activity log—every collector run, detector run, policy decision, command execution, LLM call. Use `export-activity` to convert to JSON.
|
|
204
|
+
- **Python logging**: INFO to stdout (daemon start/stop, errors). Redirect to a file or use systemd/journal.
|
|
205
|
+
|
|
206
|
+
---
|
|
207
|
+
|
|
208
|
+
## Deployment Options
|
|
209
|
+
|
|
210
|
+
| Environment | How to deploy |
|
|
211
|
+
|-------------|---------------|
|
|
212
|
+
| **Bare metal / VPS** | systemd service via `scripts/install.sh` |
|
|
213
|
+
| **Docker host** | Run agent in container with Docker socket mount |
|
|
214
|
+
| **AWS EC2 / Lightsail** | systemd on Amazon Linux / Ubuntu |
|
|
215
|
+
| **GCP Compute / Azure VM** | systemd on Debian/Ubuntu |
|
|
216
|
+
| **Kubernetes** | DaemonSet (planned) |
|
|
217
|
+
| **Managed service** | Self-host on your infra; no SaaS yet |
|
|
218
|
+
|
|
219
|
+
### Where to run OpenSecAgent
|
|
220
|
+
|
|
221
|
+
- **On each server** you want to protect (agent per host)
|
|
222
|
+
- **Central management server** (optional control plane, planned)
|
|
223
|
+
- **MSP / multi-tenant**: One agent per client server; central dashboard planned
|
|
224
|
+
|
|
225
|
+
---
|
|
226
|
+
|
|
227
|
+
## Architecture
|
|
228
|
+
|
|
229
|
+
```
|
|
230
|
+
┌─────────────────────────────────────────────────────────────────┐
|
|
231
|
+
│ OpenSecAgent Daemon │
|
|
232
|
+
├─────────────────────────────────────────────────────────────────┤
|
|
233
|
+
│ Collectors │ Detectors │ Policy Engine │
|
|
234
|
+
│ • Host inventory │ • Auth failures │ • Action tiers │
|
|
235
|
+
│ • Docker inventory │ • New admin user │ • Maintenance windows│
|
|
236
|
+
│ • Drift monitor │ • New port │ │
|
|
237
|
+
│ │ • New container │ Responder │
|
|
238
|
+
│ │ │ • Stop container │
|
|
239
|
+
│ │ │ • Block IP (stub) │
|
|
240
|
+
├─────────────────────────────────────────────────────────────────┤
|
|
241
|
+
│ Reporter: Audit (JSONL) │ Email (SMTP) │ LLM summaries (optional)│
|
|
242
|
+
└─────────────────────────────────────────────────────────────────┘
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
---
|
|
246
|
+
|
|
247
|
+
## Security
|
|
248
|
+
|
|
249
|
+
- **Defensive only**: No offensive scanning, exploitation, or "hacking back"
|
|
250
|
+
- **Policy-first**: High-impact actions require policy and (optionally) approval
|
|
251
|
+
- **Sensitive data**: Redacted before sending to LLM
|
|
252
|
+
- **Least privilege**: Run as dedicated user where possible; escalate only for specific tasks
|
|
253
|
+
|
|
254
|
+
---
|
|
255
|
+
|
|
256
|
+
## Roadmap
|
|
257
|
+
|
|
258
|
+
- [x] **LLM agent loop**: LLM suggests commands → execute → feed output back → repeat (whitelist-based)
|
|
259
|
+
- [x] **Full activity logging**: Every collector, detector, command in activity.jsonl
|
|
260
|
+
- [x] **pip package**: `pip install opensecagent`
|
|
261
|
+
- [x] **Docker image**: Dockerfile included
|
|
262
|
+
- [ ] **Kubernetes DaemonSet**: For cluster-wide deployment
|
|
263
|
+
- [ ] **Control plane**: Central dashboard, multi-tenant, policy management
|
|
264
|
+
- [ ] **Slack/Teams/PagerDuty**: Additional notification channels
|
|
265
|
+
- [ ] **Compliance packs**: SOC2/ISO27001 mapping reports
|
|
266
|
+
|
|
267
|
+
---
|
|
268
|
+
|
|
269
|
+
## Contributing
|
|
270
|
+
|
|
271
|
+
Contributions are welcome. Please open an issue or PR on GitHub.
|
|
272
|
+
|
|
273
|
+
1. Fork the repo
|
|
274
|
+
2. Create a feature branch
|
|
275
|
+
3. Add tests where applicable
|
|
276
|
+
4. Submit a pull request
|
|
277
|
+
|
|
278
|
+
---
|
|
279
|
+
|
|
280
|
+
## License
|
|
281
|
+
|
|
282
|
+
[Choose: MIT, Apache 2.0, or your preferred license]
|
|
283
|
+
|
|
284
|
+
---
|
|
285
|
+
|
|
286
|
+
## Links
|
|
287
|
+
|
|
288
|
+
- **GitHub**: https://github.com/DulanDias/opensecagent
|
|
289
|
+
- **Issues**: https://github.com/DulanDias/opensecagent/issues
|
|
290
|
+
- **Documentation**: (link when available)
|