guard-agent 2.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.
- guard_agent-2.0.0/LICENSE +21 -0
- guard_agent-2.0.0/MANIFEST.in +3 -0
- guard_agent-2.0.0/PKG-INFO +335 -0
- guard_agent-2.0.0/README.md +279 -0
- guard_agent-2.0.0/guard_agent/__init__.py +66 -0
- guard_agent-2.0.0/guard_agent/buffer.py +322 -0
- guard_agent-2.0.0/guard_agent/client.py +353 -0
- guard_agent-2.0.0/guard_agent/encryption.py +192 -0
- guard_agent-2.0.0/guard_agent/models.py +231 -0
- guard_agent-2.0.0/guard_agent/protocols.py +55 -0
- guard_agent-2.0.0/guard_agent/py.typed +0 -0
- guard_agent-2.0.0/guard_agent/transport.py +381 -0
- guard_agent-2.0.0/guard_agent/utils.py +195 -0
- guard_agent-2.0.0/guard_agent.egg-info/PKG-INFO +335 -0
- guard_agent-2.0.0/guard_agent.egg-info/SOURCES.txt +26 -0
- guard_agent-2.0.0/guard_agent.egg-info/dependency_links.txt +1 -0
- guard_agent-2.0.0/guard_agent.egg-info/requires.txt +28 -0
- guard_agent-2.0.0/guard_agent.egg-info/top_level.txt +1 -0
- guard_agent-2.0.0/pyproject.toml +186 -0
- guard_agent-2.0.0/setup.cfg +4 -0
- guard_agent-2.0.0/setup.py +9 -0
- guard_agent-2.0.0/tests/test_buffer.py +669 -0
- guard_agent-2.0.0/tests/test_client.py +849 -0
- guard_agent-2.0.0/tests/test_encryption.py +376 -0
- guard_agent-2.0.0/tests/test_models.py +253 -0
- guard_agent-2.0.0/tests/test_performance.py +279 -0
- guard_agent-2.0.0/tests/test_transport.py +1095 -0
- guard_agent-2.0.0/tests/test_utils.py +513 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Renzo Franceschini
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: guard-agent
|
|
3
|
+
Version: 2.0.0
|
|
4
|
+
Summary: Framework-agnostic telemetry and monitoring agent for the Guard security ecosystem (fastapi-guard, flaskapi-guard, djangoapi-guard, tornadoapi-guard)
|
|
5
|
+
Author-email: Renzo Franceschini <rennf93@users.noreply.github.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://guard-core.com
|
|
8
|
+
Project-URL: Documentation, https://rennf93.github.io/guard-agent/latest/
|
|
9
|
+
Project-URL: Repository, https://github.com/rennf93/guard-agent
|
|
10
|
+
Project-URL: Changelog, https://github.com/rennf93/guard-agent/blob/master/CHANGELOG.md
|
|
11
|
+
Project-URL: Bug Tracker, https://github.com/rennf93/guard-agent/issues
|
|
12
|
+
Project-URL: Cloud Dashboard, https://app.guard-core.com
|
|
13
|
+
Project-URL: Live Playground, https://playground.guard-core.com
|
|
14
|
+
Classifier: Development Status :: 4 - Beta
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
24
|
+
Classifier: Topic :: Security
|
|
25
|
+
Classifier: Topic :: System :: Monitoring
|
|
26
|
+
Requires-Python: <3.15,>=3.10
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
License-File: LICENSE
|
|
29
|
+
Requires-Dist: cryptography
|
|
30
|
+
Requires-Dist: httpx
|
|
31
|
+
Requires-Dist: pydantic
|
|
32
|
+
Requires-Dist: typing-extensions
|
|
33
|
+
Provides-Extra: dev
|
|
34
|
+
Requires-Dist: black; extra == "dev"
|
|
35
|
+
Requires-Dist: fastapi; extra == "dev"
|
|
36
|
+
Requires-Dist: fastapi-guard>=5.0.0; extra == "dev"
|
|
37
|
+
Requires-Dist: httpx; extra == "dev"
|
|
38
|
+
Requires-Dist: mkdocs; extra == "dev"
|
|
39
|
+
Requires-Dist: mkdocstrings; extra == "dev"
|
|
40
|
+
Requires-Dist: mkdocstrings-python; extra == "dev"
|
|
41
|
+
Requires-Dist: mkdocs-material; extra == "dev"
|
|
42
|
+
Requires-Dist: mypy; extra == "dev"
|
|
43
|
+
Requires-Dist: pre-commit; extra == "dev"
|
|
44
|
+
Requires-Dist: psutil; extra == "dev"
|
|
45
|
+
Requires-Dist: pymarkdownlnt; extra == "dev"
|
|
46
|
+
Requires-Dist: pytest; extra == "dev"
|
|
47
|
+
Requires-Dist: pytest-asyncio; extra == "dev"
|
|
48
|
+
Requires-Dist: pytest-cov; extra == "dev"
|
|
49
|
+
Requires-Dist: pytest-mock; extra == "dev"
|
|
50
|
+
Requires-Dist: ruff; extra == "dev"
|
|
51
|
+
Requires-Dist: types-psutil; extra == "dev"
|
|
52
|
+
Requires-Dist: types-setuptools; extra == "dev"
|
|
53
|
+
Provides-Extra: redis
|
|
54
|
+
Requires-Dist: redis; extra == "redis"
|
|
55
|
+
Dynamic: license-file
|
|
56
|
+
|
|
57
|
+
<p align="center">
|
|
58
|
+
<a href="https://rennf93.github.io/guard-agent/latest/">
|
|
59
|
+
<img src="https://rennf93.github.io/guard-agent/latest/assets/big_logo.svg" alt="Guard Agent">
|
|
60
|
+
</a>
|
|
61
|
+
</p>
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
<p align="center">
|
|
66
|
+
<strong>Guard Agent is an enterprise-grade, framework-agnostic telemetry and monitoring agent for the Guard security ecosystem. It integrates with <code>fastapi-guard</code>, <code>flaskapi-guard</code>, <code>djangoapi-guard</code>, and <code>tornadoapi-guard</code> to provide centralized security intelligence, real-time policy updates, and comprehensive event collection across any Python web framework.</strong>
|
|
67
|
+
</p>
|
|
68
|
+
|
|
69
|
+
<p align="center">
|
|
70
|
+
<a href="https://badge.fury.io/py/guard-agent">
|
|
71
|
+
<img src="https://badge.fury.io/py/guard-agent.svg?cache=none&icon=si%3Apython&icon_color=%23008cb4" alt="PyPiVersion">
|
|
72
|
+
</a>
|
|
73
|
+
<a href="https://github.com/rennf93/guard-agent/actions/workflows/release.yml">
|
|
74
|
+
<img src="https://github.com/rennf93/guard-agent/actions/workflows/release.yml/badge.svg" alt="Release">
|
|
75
|
+
</a>
|
|
76
|
+
<a href="https://opensource.org/licenses/MIT">
|
|
77
|
+
<img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="License">
|
|
78
|
+
</a>
|
|
79
|
+
<a href="https://github.com/rennf93/guard-agent/actions/workflows/ci.yml">
|
|
80
|
+
<img src="https://github.com/rennf93/guard-agent/actions/workflows/ci.yml/badge.svg" alt="CI">
|
|
81
|
+
</a>
|
|
82
|
+
<a href="https://github.com/rennf93/guard-agent/actions/workflows/code-ql.yml">
|
|
83
|
+
<img src="https://github.com/rennf93/guard-agent/actions/workflows/code-ql.yml/badge.svg" alt="CodeQL">
|
|
84
|
+
</a>
|
|
85
|
+
</p>
|
|
86
|
+
|
|
87
|
+
<p align="center">
|
|
88
|
+
<a href="https://github.com/rennf93/guard-agent/actions/workflows/pages/pages-build-deployment">
|
|
89
|
+
<img src="https://github.com/rennf93/guard-agent/actions/workflows/pages/pages-build-deployment/badge.svg?branch=gh-pages" alt="PagesBuildDeployment">
|
|
90
|
+
</a>
|
|
91
|
+
<a href="https://github.com/rennf93/guard-agent/actions/workflows/docs.yml">
|
|
92
|
+
<img src="https://github.com/rennf93/guard-agent/actions/workflows/docs.yml/badge.svg" alt="DocsUpdate">
|
|
93
|
+
</a>
|
|
94
|
+
<img src="https://img.shields.io/github/last-commit/rennf93/guard-agent?style=flat&logo=git&logoColor=white&color=0080ff" alt="last-commit">
|
|
95
|
+
</p>
|
|
96
|
+
|
|
97
|
+
<p align="center">
|
|
98
|
+
<img src="https://img.shields.io/badge/Python-3776AB.svg?style=flat&logo=Python&logoColor=white" alt="Python">
|
|
99
|
+
<img src="https://img.shields.io/badge/Redis-FF4438.svg?style=flat&logo=Redis&logoColor=white" alt="Redis">
|
|
100
|
+
<a href="https://pepy.tech/project/guard-agent">
|
|
101
|
+
<img src="https://pepy.tech/badge/guard-agent" alt="Downloads">
|
|
102
|
+
</a>
|
|
103
|
+
</p>
|
|
104
|
+
|
|
105
|
+
<p align="center">
|
|
106
|
+
<a href="https://guard-core.com">Website</a> ·
|
|
107
|
+
<a href="https://rennf93.github.io/guard-agent/latest/">Docs</a> ·
|
|
108
|
+
<a href="https://playground.guard-core.com">Playground</a> ·
|
|
109
|
+
<a href="https://app.guard-core.com">Dashboard</a> ·
|
|
110
|
+
<a href="https://discord.gg/ZW7ZJbjMkK">Discord</a>
|
|
111
|
+
</p>
|
|
112
|
+
|
|
113
|
+
<p align="center">
|
|
114
|
+
Framework-agnostic security telemetry for Python web apps.<br>
|
|
115
|
+
Feeds the Guard dashboard with events, metrics, and dynamic rules from any supported adapter.
|
|
116
|
+
</p>
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
> **Renamed from `fastapi-guard-agent`.** As of `guard-agent` 2.0.0, the package has been renamed to reflect its multi-framework scope. The Python import path (`from guard_agent import ...`) is unchanged. Existing `pip install fastapi-guard-agent` commands continue to work via a meta-package that transitively pulls the renamed distribution.
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
Documentation & Platform
|
|
125
|
+
========================
|
|
126
|
+
|
|
127
|
+
- 🌐 **[guard-core.com](https://guard-core.com)** — marketing site & product overview
|
|
128
|
+
- 📚 **[Documentation](https://rennf93.github.io/guard-agent/latest/)** — full technical documentation
|
|
129
|
+
- 🎮 **[Playground](https://playground.guard-core.com)** — try the Guard stack in-browser, no install required
|
|
130
|
+
- 📊 **[Dashboard](https://app.guard-core.com)** — real-time security events, metrics, and dynamic rules for your projects
|
|
131
|
+
- 💬 **[Discord](https://discord.gg/ZW7ZJbjMkK)** — community & maintainer support
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
Supported Adapters
|
|
136
|
+
------------------
|
|
137
|
+
|
|
138
|
+
Guard Agent is framework-agnostic. Pair it with the adapter for your stack:
|
|
139
|
+
|
|
140
|
+
| Framework | Adapter package | Status |
|
|
141
|
+
|-----------|-----------------|--------|
|
|
142
|
+
| FastAPI | [`fastapi-guard`](https://github.com/rennf93/fastapi-guard) | Stable |
|
|
143
|
+
| Flask | [`flaskapi-guard`](https://github.com/rennf93/flaskapi-guard) | Stable |
|
|
144
|
+
| Django | [`djangoapi-guard`](https://github.com/rennf93/djangoapi-guard) | Stable |
|
|
145
|
+
| Tornado | [`tornadoapi-guard`](https://github.com/rennf93/tornadoapi-guard) | Stable |
|
|
146
|
+
|
|
147
|
+
All adapters share the same Guard Agent runtime and dashboard — a single telemetry contract across every framework.
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
Key Features
|
|
152
|
+
------------
|
|
153
|
+
|
|
154
|
+
- **Framework-Agnostic Core**: One agent, one dashboard — works with every Guard adapter (FastAPI, Flask, Django, Tornado) through a shared wire protocol.
|
|
155
|
+
- **Automatic Integration**: Adapters wire the agent into their middleware automatically. Enable it through the adapter's `SecurityConfig` — no glue code required.
|
|
156
|
+
- **High-Performance Architecture**: Built on asynchronous I/O principles to ensure zero performance impact on your application while maintaining real-time data collection capabilities.
|
|
157
|
+
- **Enterprise-Grade Reliability**: Implements industry-standard resilience patterns including circuit breakers, exponential backoff with jitter, and intelligent retry mechanisms to guarantee data delivery.
|
|
158
|
+
- **Intelligent Data Management**: Features multi-tier buffering with in-memory and optional Redis persistence, ensuring zero data loss during network interruptions or application restarts.
|
|
159
|
+
- **Real-Time Security Updates**: Supports dynamic security policy updates from the centralized management platform, enabling immediate threat response without service interruption.
|
|
160
|
+
- **Extensible Architecture**: Designed with protocol-based abstractions, allowing seamless integration with custom transport layers, storage backends, and monitoring systems.
|
|
161
|
+
- **Comprehensive Security Intelligence**: Captures granular security events and performance metrics, providing actionable insights for security operations and compliance requirements.
|
|
162
|
+
|
|
163
|
+
---
|
|
164
|
+
|
|
165
|
+
Installation
|
|
166
|
+
------------
|
|
167
|
+
|
|
168
|
+
```bash
|
|
169
|
+
pip install guard-agent
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
Or with `uv`:
|
|
173
|
+
|
|
174
|
+
```bash
|
|
175
|
+
uv add guard-agent
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
> The legacy name `fastapi-guard-agent` is still published as a meta-package that installs `guard-agent` transitively — existing installs keep working, but new projects should use `guard-agent` directly.
|
|
179
|
+
|
|
180
|
+
Optional extras:
|
|
181
|
+
|
|
182
|
+
```bash
|
|
183
|
+
pip install "guard-agent[redis]" # Enable Redis-backed event buffer
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
---
|
|
187
|
+
|
|
188
|
+
Getting Started
|
|
189
|
+
---------------
|
|
190
|
+
|
|
191
|
+
Guard Agent is embedded directly by your framework's adapter — you enable it through the adapter's security config rather than importing it manually.
|
|
192
|
+
|
|
193
|
+
### FastAPI example
|
|
194
|
+
|
|
195
|
+
```python
|
|
196
|
+
from fastapi import FastAPI
|
|
197
|
+
from guard import SecurityConfig, SecurityMiddleware
|
|
198
|
+
|
|
199
|
+
config = SecurityConfig(
|
|
200
|
+
auto_ban_threshold=5,
|
|
201
|
+
auto_ban_duration=300,
|
|
202
|
+
|
|
203
|
+
# Enable agent telemetry
|
|
204
|
+
enable_agent=True,
|
|
205
|
+
agent_api_key="YOUR_API_KEY",
|
|
206
|
+
agent_project_id="YOUR_PROJECT_ID",
|
|
207
|
+
agent_endpoint="https://api.guard-core.com",
|
|
208
|
+
|
|
209
|
+
agent_buffer_size=100,
|
|
210
|
+
agent_flush_interval=30,
|
|
211
|
+
agent_enable_events=True,
|
|
212
|
+
agent_enable_metrics=True,
|
|
213
|
+
|
|
214
|
+
enable_dynamic_rules=True,
|
|
215
|
+
dynamic_rule_interval=300,
|
|
216
|
+
)
|
|
217
|
+
|
|
218
|
+
app = FastAPI()
|
|
219
|
+
SecurityMiddleware(app, config=config)
|
|
220
|
+
|
|
221
|
+
@app.get("/")
|
|
222
|
+
async def root():
|
|
223
|
+
return {"message": "Hello World"}
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
Flask, Django, and Tornado adapters expose analogous `SecurityConfig` interfaces — see each adapter's README for framework-native examples.
|
|
227
|
+
|
|
228
|
+
With `enable_agent=True`, the agent automatically:
|
|
229
|
+
|
|
230
|
+
- Captures security violations (IP bans, rate-limit breaches, suspicious request patterns)
|
|
231
|
+
- Collects performance telemetry for security operations monitoring
|
|
232
|
+
- Synchronizes security policies from the centralized management platform
|
|
233
|
+
- Implements intelligent buffering for optimal network utilization
|
|
234
|
+
- Recovers automatically from transient network failures
|
|
235
|
+
|
|
236
|
+
---
|
|
237
|
+
|
|
238
|
+
Advanced Configuration
|
|
239
|
+
----------------------
|
|
240
|
+
|
|
241
|
+
For standalone use or custom event handling, instantiate the agent directly:
|
|
242
|
+
|
|
243
|
+
```python
|
|
244
|
+
from guard_agent.client import guard_agent
|
|
245
|
+
from guard_agent.models import AgentConfig
|
|
246
|
+
|
|
247
|
+
config = AgentConfig(
|
|
248
|
+
api_key="YOUR_API_KEY",
|
|
249
|
+
project_id="YOUR_PROJECT_ID",
|
|
250
|
+
)
|
|
251
|
+
|
|
252
|
+
agent = guard_agent(config)
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
### Configuration Parameters
|
|
256
|
+
|
|
257
|
+
#### Authentication & Identification
|
|
258
|
+
- **`api_key: str`** (Required): Authentication key for the Guard management platform
|
|
259
|
+
- **`project_id: str | None`**: Unique project identifier for data segregation and multi-tenancy support
|
|
260
|
+
|
|
261
|
+
#### Network Configuration
|
|
262
|
+
- **`endpoint: str`**: Management platform API endpoint (Default: `https://api.guard-core.com`)
|
|
263
|
+
- **`timeout: int`**: HTTP request timeout in seconds (Default: `30`)
|
|
264
|
+
- **`retry_attempts: int`**: Maximum retry attempts for failed requests (Default: `3`)
|
|
265
|
+
- **`backoff_factor: float`**: Exponential backoff multiplier for retry delays (Default: `1.0`)
|
|
266
|
+
|
|
267
|
+
#### Data Management
|
|
268
|
+
- **`buffer_size: int`**: Maximum events in memory buffer before automatic flush (Default: `100`)
|
|
269
|
+
- **`flush_interval: int`**: Automatic buffer flush interval in seconds (Default: `30`)
|
|
270
|
+
- **`max_payload_size: int`**: Maximum payload size in bytes before truncation (Default: `1024`)
|
|
271
|
+
|
|
272
|
+
#### Feature Control
|
|
273
|
+
- **`enable_metrics: bool`**: Enable performance metrics collection (Default: `True`)
|
|
274
|
+
- **`enable_events: bool`**: Enable security event collection (Default: `True`)
|
|
275
|
+
|
|
276
|
+
#### Security & Privacy
|
|
277
|
+
- **`sensitive_headers: list[str]`**: HTTP headers to redact from collected data (Default: `["authorization", "cookie", "x-api-key"]`)
|
|
278
|
+
|
|
279
|
+
---
|
|
280
|
+
|
|
281
|
+
Migration from `fastapi-guard-agent`
|
|
282
|
+
------------------------------------
|
|
283
|
+
|
|
284
|
+
No code changes required. The import path was always `guard_agent`:
|
|
285
|
+
|
|
286
|
+
```python
|
|
287
|
+
# This worked before and still works:
|
|
288
|
+
from guard_agent import GuardAgentHandler, AgentConfig
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
To switch your install command:
|
|
292
|
+
|
|
293
|
+
```bash
|
|
294
|
+
# Old (still works via shim)
|
|
295
|
+
pip install fastapi-guard-agent
|
|
296
|
+
|
|
297
|
+
# New (preferred)
|
|
298
|
+
pip install guard-agent
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
The legacy `fastapi-guard-agent` name is maintained as a meta-package pointing to `guard-agent>=2.0.0,<3.0.0`, so pinned environments keep resolving correctly.
|
|
302
|
+
|
|
303
|
+
---
|
|
304
|
+
|
|
305
|
+
Contributing
|
|
306
|
+
------------
|
|
307
|
+
|
|
308
|
+
Contributions are welcome! Please open an issue or submit a pull request on GitHub.
|
|
309
|
+
|
|
310
|
+
---
|
|
311
|
+
|
|
312
|
+
License
|
|
313
|
+
-------
|
|
314
|
+
|
|
315
|
+
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
|
|
316
|
+
|
|
317
|
+
---
|
|
318
|
+
|
|
319
|
+
Author
|
|
320
|
+
------
|
|
321
|
+
|
|
322
|
+
Renzo Franceschini - [rennf93@users.noreply.github.com](mailto:rennf93@users.noreply.github.com)
|
|
323
|
+
|
|
324
|
+
---
|
|
325
|
+
|
|
326
|
+
Acknowledgements
|
|
327
|
+
----------------
|
|
328
|
+
|
|
329
|
+
- [FastAPI](https://fastapi.tiangolo.com/)
|
|
330
|
+
- [Flask](https://flask.palletsprojects.com/)
|
|
331
|
+
- [Django](https://www.djangoproject.com/)
|
|
332
|
+
- [Tornado](https://www.tornadoweb.org/)
|
|
333
|
+
- [Redis](https://redis.io/)
|
|
334
|
+
- [httpx](https://www.python-httpx.org/)
|
|
335
|
+
- [Pydantic](https://pydantic-docs.helpmanual.io/)
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://rennf93.github.io/guard-agent/latest/">
|
|
3
|
+
<img src="https://rennf93.github.io/guard-agent/latest/assets/big_logo.svg" alt="Guard Agent">
|
|
4
|
+
</a>
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
<p align="center">
|
|
10
|
+
<strong>Guard Agent is an enterprise-grade, framework-agnostic telemetry and monitoring agent for the Guard security ecosystem. It integrates with <code>fastapi-guard</code>, <code>flaskapi-guard</code>, <code>djangoapi-guard</code>, and <code>tornadoapi-guard</code> to provide centralized security intelligence, real-time policy updates, and comprehensive event collection across any Python web framework.</strong>
|
|
11
|
+
</p>
|
|
12
|
+
|
|
13
|
+
<p align="center">
|
|
14
|
+
<a href="https://badge.fury.io/py/guard-agent">
|
|
15
|
+
<img src="https://badge.fury.io/py/guard-agent.svg?cache=none&icon=si%3Apython&icon_color=%23008cb4" alt="PyPiVersion">
|
|
16
|
+
</a>
|
|
17
|
+
<a href="https://github.com/rennf93/guard-agent/actions/workflows/release.yml">
|
|
18
|
+
<img src="https://github.com/rennf93/guard-agent/actions/workflows/release.yml/badge.svg" alt="Release">
|
|
19
|
+
</a>
|
|
20
|
+
<a href="https://opensource.org/licenses/MIT">
|
|
21
|
+
<img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="License">
|
|
22
|
+
</a>
|
|
23
|
+
<a href="https://github.com/rennf93/guard-agent/actions/workflows/ci.yml">
|
|
24
|
+
<img src="https://github.com/rennf93/guard-agent/actions/workflows/ci.yml/badge.svg" alt="CI">
|
|
25
|
+
</a>
|
|
26
|
+
<a href="https://github.com/rennf93/guard-agent/actions/workflows/code-ql.yml">
|
|
27
|
+
<img src="https://github.com/rennf93/guard-agent/actions/workflows/code-ql.yml/badge.svg" alt="CodeQL">
|
|
28
|
+
</a>
|
|
29
|
+
</p>
|
|
30
|
+
|
|
31
|
+
<p align="center">
|
|
32
|
+
<a href="https://github.com/rennf93/guard-agent/actions/workflows/pages/pages-build-deployment">
|
|
33
|
+
<img src="https://github.com/rennf93/guard-agent/actions/workflows/pages/pages-build-deployment/badge.svg?branch=gh-pages" alt="PagesBuildDeployment">
|
|
34
|
+
</a>
|
|
35
|
+
<a href="https://github.com/rennf93/guard-agent/actions/workflows/docs.yml">
|
|
36
|
+
<img src="https://github.com/rennf93/guard-agent/actions/workflows/docs.yml/badge.svg" alt="DocsUpdate">
|
|
37
|
+
</a>
|
|
38
|
+
<img src="https://img.shields.io/github/last-commit/rennf93/guard-agent?style=flat&logo=git&logoColor=white&color=0080ff" alt="last-commit">
|
|
39
|
+
</p>
|
|
40
|
+
|
|
41
|
+
<p align="center">
|
|
42
|
+
<img src="https://img.shields.io/badge/Python-3776AB.svg?style=flat&logo=Python&logoColor=white" alt="Python">
|
|
43
|
+
<img src="https://img.shields.io/badge/Redis-FF4438.svg?style=flat&logo=Redis&logoColor=white" alt="Redis">
|
|
44
|
+
<a href="https://pepy.tech/project/guard-agent">
|
|
45
|
+
<img src="https://pepy.tech/badge/guard-agent" alt="Downloads">
|
|
46
|
+
</a>
|
|
47
|
+
</p>
|
|
48
|
+
|
|
49
|
+
<p align="center">
|
|
50
|
+
<a href="https://guard-core.com">Website</a> ·
|
|
51
|
+
<a href="https://rennf93.github.io/guard-agent/latest/">Docs</a> ·
|
|
52
|
+
<a href="https://playground.guard-core.com">Playground</a> ·
|
|
53
|
+
<a href="https://app.guard-core.com">Dashboard</a> ·
|
|
54
|
+
<a href="https://discord.gg/ZW7ZJbjMkK">Discord</a>
|
|
55
|
+
</p>
|
|
56
|
+
|
|
57
|
+
<p align="center">
|
|
58
|
+
Framework-agnostic security telemetry for Python web apps.<br>
|
|
59
|
+
Feeds the Guard dashboard with events, metrics, and dynamic rules from any supported adapter.
|
|
60
|
+
</p>
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
> **Renamed from `fastapi-guard-agent`.** As of `guard-agent` 2.0.0, the package has been renamed to reflect its multi-framework scope. The Python import path (`from guard_agent import ...`) is unchanged. Existing `pip install fastapi-guard-agent` commands continue to work via a meta-package that transitively pulls the renamed distribution.
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
Documentation & Platform
|
|
69
|
+
========================
|
|
70
|
+
|
|
71
|
+
- 🌐 **[guard-core.com](https://guard-core.com)** — marketing site & product overview
|
|
72
|
+
- 📚 **[Documentation](https://rennf93.github.io/guard-agent/latest/)** — full technical documentation
|
|
73
|
+
- 🎮 **[Playground](https://playground.guard-core.com)** — try the Guard stack in-browser, no install required
|
|
74
|
+
- 📊 **[Dashboard](https://app.guard-core.com)** — real-time security events, metrics, and dynamic rules for your projects
|
|
75
|
+
- 💬 **[Discord](https://discord.gg/ZW7ZJbjMkK)** — community & maintainer support
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
Supported Adapters
|
|
80
|
+
------------------
|
|
81
|
+
|
|
82
|
+
Guard Agent is framework-agnostic. Pair it with the adapter for your stack:
|
|
83
|
+
|
|
84
|
+
| Framework | Adapter package | Status |
|
|
85
|
+
|-----------|-----------------|--------|
|
|
86
|
+
| FastAPI | [`fastapi-guard`](https://github.com/rennf93/fastapi-guard) | Stable |
|
|
87
|
+
| Flask | [`flaskapi-guard`](https://github.com/rennf93/flaskapi-guard) | Stable |
|
|
88
|
+
| Django | [`djangoapi-guard`](https://github.com/rennf93/djangoapi-guard) | Stable |
|
|
89
|
+
| Tornado | [`tornadoapi-guard`](https://github.com/rennf93/tornadoapi-guard) | Stable |
|
|
90
|
+
|
|
91
|
+
All adapters share the same Guard Agent runtime and dashboard — a single telemetry contract across every framework.
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
Key Features
|
|
96
|
+
------------
|
|
97
|
+
|
|
98
|
+
- **Framework-Agnostic Core**: One agent, one dashboard — works with every Guard adapter (FastAPI, Flask, Django, Tornado) through a shared wire protocol.
|
|
99
|
+
- **Automatic Integration**: Adapters wire the agent into their middleware automatically. Enable it through the adapter's `SecurityConfig` — no glue code required.
|
|
100
|
+
- **High-Performance Architecture**: Built on asynchronous I/O principles to ensure zero performance impact on your application while maintaining real-time data collection capabilities.
|
|
101
|
+
- **Enterprise-Grade Reliability**: Implements industry-standard resilience patterns including circuit breakers, exponential backoff with jitter, and intelligent retry mechanisms to guarantee data delivery.
|
|
102
|
+
- **Intelligent Data Management**: Features multi-tier buffering with in-memory and optional Redis persistence, ensuring zero data loss during network interruptions or application restarts.
|
|
103
|
+
- **Real-Time Security Updates**: Supports dynamic security policy updates from the centralized management platform, enabling immediate threat response without service interruption.
|
|
104
|
+
- **Extensible Architecture**: Designed with protocol-based abstractions, allowing seamless integration with custom transport layers, storage backends, and monitoring systems.
|
|
105
|
+
- **Comprehensive Security Intelligence**: Captures granular security events and performance metrics, providing actionable insights for security operations and compliance requirements.
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
Installation
|
|
110
|
+
------------
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
pip install guard-agent
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Or with `uv`:
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
uv add guard-agent
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
> The legacy name `fastapi-guard-agent` is still published as a meta-package that installs `guard-agent` transitively — existing installs keep working, but new projects should use `guard-agent` directly.
|
|
123
|
+
|
|
124
|
+
Optional extras:
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
pip install "guard-agent[redis]" # Enable Redis-backed event buffer
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
Getting Started
|
|
133
|
+
---------------
|
|
134
|
+
|
|
135
|
+
Guard Agent is embedded directly by your framework's adapter — you enable it through the adapter's security config rather than importing it manually.
|
|
136
|
+
|
|
137
|
+
### FastAPI example
|
|
138
|
+
|
|
139
|
+
```python
|
|
140
|
+
from fastapi import FastAPI
|
|
141
|
+
from guard import SecurityConfig, SecurityMiddleware
|
|
142
|
+
|
|
143
|
+
config = SecurityConfig(
|
|
144
|
+
auto_ban_threshold=5,
|
|
145
|
+
auto_ban_duration=300,
|
|
146
|
+
|
|
147
|
+
# Enable agent telemetry
|
|
148
|
+
enable_agent=True,
|
|
149
|
+
agent_api_key="YOUR_API_KEY",
|
|
150
|
+
agent_project_id="YOUR_PROJECT_ID",
|
|
151
|
+
agent_endpoint="https://api.guard-core.com",
|
|
152
|
+
|
|
153
|
+
agent_buffer_size=100,
|
|
154
|
+
agent_flush_interval=30,
|
|
155
|
+
agent_enable_events=True,
|
|
156
|
+
agent_enable_metrics=True,
|
|
157
|
+
|
|
158
|
+
enable_dynamic_rules=True,
|
|
159
|
+
dynamic_rule_interval=300,
|
|
160
|
+
)
|
|
161
|
+
|
|
162
|
+
app = FastAPI()
|
|
163
|
+
SecurityMiddleware(app, config=config)
|
|
164
|
+
|
|
165
|
+
@app.get("/")
|
|
166
|
+
async def root():
|
|
167
|
+
return {"message": "Hello World"}
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
Flask, Django, and Tornado adapters expose analogous `SecurityConfig` interfaces — see each adapter's README for framework-native examples.
|
|
171
|
+
|
|
172
|
+
With `enable_agent=True`, the agent automatically:
|
|
173
|
+
|
|
174
|
+
- Captures security violations (IP bans, rate-limit breaches, suspicious request patterns)
|
|
175
|
+
- Collects performance telemetry for security operations monitoring
|
|
176
|
+
- Synchronizes security policies from the centralized management platform
|
|
177
|
+
- Implements intelligent buffering for optimal network utilization
|
|
178
|
+
- Recovers automatically from transient network failures
|
|
179
|
+
|
|
180
|
+
---
|
|
181
|
+
|
|
182
|
+
Advanced Configuration
|
|
183
|
+
----------------------
|
|
184
|
+
|
|
185
|
+
For standalone use or custom event handling, instantiate the agent directly:
|
|
186
|
+
|
|
187
|
+
```python
|
|
188
|
+
from guard_agent.client import guard_agent
|
|
189
|
+
from guard_agent.models import AgentConfig
|
|
190
|
+
|
|
191
|
+
config = AgentConfig(
|
|
192
|
+
api_key="YOUR_API_KEY",
|
|
193
|
+
project_id="YOUR_PROJECT_ID",
|
|
194
|
+
)
|
|
195
|
+
|
|
196
|
+
agent = guard_agent(config)
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### Configuration Parameters
|
|
200
|
+
|
|
201
|
+
#### Authentication & Identification
|
|
202
|
+
- **`api_key: str`** (Required): Authentication key for the Guard management platform
|
|
203
|
+
- **`project_id: str | None`**: Unique project identifier for data segregation and multi-tenancy support
|
|
204
|
+
|
|
205
|
+
#### Network Configuration
|
|
206
|
+
- **`endpoint: str`**: Management platform API endpoint (Default: `https://api.guard-core.com`)
|
|
207
|
+
- **`timeout: int`**: HTTP request timeout in seconds (Default: `30`)
|
|
208
|
+
- **`retry_attempts: int`**: Maximum retry attempts for failed requests (Default: `3`)
|
|
209
|
+
- **`backoff_factor: float`**: Exponential backoff multiplier for retry delays (Default: `1.0`)
|
|
210
|
+
|
|
211
|
+
#### Data Management
|
|
212
|
+
- **`buffer_size: int`**: Maximum events in memory buffer before automatic flush (Default: `100`)
|
|
213
|
+
- **`flush_interval: int`**: Automatic buffer flush interval in seconds (Default: `30`)
|
|
214
|
+
- **`max_payload_size: int`**: Maximum payload size in bytes before truncation (Default: `1024`)
|
|
215
|
+
|
|
216
|
+
#### Feature Control
|
|
217
|
+
- **`enable_metrics: bool`**: Enable performance metrics collection (Default: `True`)
|
|
218
|
+
- **`enable_events: bool`**: Enable security event collection (Default: `True`)
|
|
219
|
+
|
|
220
|
+
#### Security & Privacy
|
|
221
|
+
- **`sensitive_headers: list[str]`**: HTTP headers to redact from collected data (Default: `["authorization", "cookie", "x-api-key"]`)
|
|
222
|
+
|
|
223
|
+
---
|
|
224
|
+
|
|
225
|
+
Migration from `fastapi-guard-agent`
|
|
226
|
+
------------------------------------
|
|
227
|
+
|
|
228
|
+
No code changes required. The import path was always `guard_agent`:
|
|
229
|
+
|
|
230
|
+
```python
|
|
231
|
+
# This worked before and still works:
|
|
232
|
+
from guard_agent import GuardAgentHandler, AgentConfig
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
To switch your install command:
|
|
236
|
+
|
|
237
|
+
```bash
|
|
238
|
+
# Old (still works via shim)
|
|
239
|
+
pip install fastapi-guard-agent
|
|
240
|
+
|
|
241
|
+
# New (preferred)
|
|
242
|
+
pip install guard-agent
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
The legacy `fastapi-guard-agent` name is maintained as a meta-package pointing to `guard-agent>=2.0.0,<3.0.0`, so pinned environments keep resolving correctly.
|
|
246
|
+
|
|
247
|
+
---
|
|
248
|
+
|
|
249
|
+
Contributing
|
|
250
|
+
------------
|
|
251
|
+
|
|
252
|
+
Contributions are welcome! Please open an issue or submit a pull request on GitHub.
|
|
253
|
+
|
|
254
|
+
---
|
|
255
|
+
|
|
256
|
+
License
|
|
257
|
+
-------
|
|
258
|
+
|
|
259
|
+
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
|
|
260
|
+
|
|
261
|
+
---
|
|
262
|
+
|
|
263
|
+
Author
|
|
264
|
+
------
|
|
265
|
+
|
|
266
|
+
Renzo Franceschini - [rennf93@users.noreply.github.com](mailto:rennf93@users.noreply.github.com)
|
|
267
|
+
|
|
268
|
+
---
|
|
269
|
+
|
|
270
|
+
Acknowledgements
|
|
271
|
+
----------------
|
|
272
|
+
|
|
273
|
+
- [FastAPI](https://fastapi.tiangolo.com/)
|
|
274
|
+
- [Flask](https://flask.palletsprojects.com/)
|
|
275
|
+
- [Django](https://www.djangoproject.com/)
|
|
276
|
+
- [Tornado](https://www.tornadoweb.org/)
|
|
277
|
+
- [Redis](https://redis.io/)
|
|
278
|
+
- [httpx](https://www.python-httpx.org/)
|
|
279
|
+
- [Pydantic](https://pydantic-docs.helpmanual.io/)
|