@aion0/bastion 0.1.7
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.
- package/LICENSE +21 -0
- package/README.md +183 -0
- package/README.zh.md +468 -0
- package/config/default.yaml +73 -0
- package/dist/cli/commands/config.d.ts +3 -0
- package/dist/cli/commands/config.d.ts.map +1 -0
- package/dist/cli/commands/config.js +31 -0
- package/dist/cli/commands/config.js.map +1 -0
- package/dist/cli/commands/env.d.ts +3 -0
- package/dist/cli/commands/env.d.ts.map +1 -0
- package/dist/cli/commands/env.js +83 -0
- package/dist/cli/commands/env.js.map +1 -0
- package/dist/cli/commands/health.d.ts +3 -0
- package/dist/cli/commands/health.d.ts.map +1 -0
- package/dist/cli/commands/health.js +45 -0
- package/dist/cli/commands/health.js.map +1 -0
- package/dist/cli/commands/openclaw.d.ts +3 -0
- package/dist/cli/commands/openclaw.d.ts.map +1 -0
- package/dist/cli/commands/openclaw.js +1062 -0
- package/dist/cli/commands/openclaw.js.map +1 -0
- package/dist/cli/commands/proxy.d.ts +8 -0
- package/dist/cli/commands/proxy.d.ts.map +1 -0
- package/dist/cli/commands/proxy.js +433 -0
- package/dist/cli/commands/proxy.js.map +1 -0
- package/dist/cli/commands/start.d.ts +3 -0
- package/dist/cli/commands/start.d.ts.map +1 -0
- package/dist/cli/commands/start.js +62 -0
- package/dist/cli/commands/start.js.map +1 -0
- package/dist/cli/commands/stats.d.ts +3 -0
- package/dist/cli/commands/stats.d.ts.map +1 -0
- package/dist/cli/commands/stats.js +32 -0
- package/dist/cli/commands/stats.js.map +1 -0
- package/dist/cli/commands/stop.d.ts +3 -0
- package/dist/cli/commands/stop.d.ts.map +1 -0
- package/dist/cli/commands/stop.js +28 -0
- package/dist/cli/commands/stop.js.map +1 -0
- package/dist/cli/commands/token.d.ts +3 -0
- package/dist/cli/commands/token.d.ts.map +1 -0
- package/dist/cli/commands/token.js +32 -0
- package/dist/cli/commands/token.js.map +1 -0
- package/dist/cli/commands/trust-ca.d.ts +3 -0
- package/dist/cli/commands/trust-ca.d.ts.map +1 -0
- package/dist/cli/commands/trust-ca.js +44 -0
- package/dist/cli/commands/trust-ca.js.map +1 -0
- package/dist/cli/commands/wrap.d.ts +3 -0
- package/dist/cli/commands/wrap.d.ts.map +1 -0
- package/dist/cli/commands/wrap.js +70 -0
- package/dist/cli/commands/wrap.js.map +1 -0
- package/dist/cli/daemon.d.ts +11 -0
- package/dist/cli/daemon.d.ts.map +1 -0
- package/dist/cli/daemon.js +82 -0
- package/dist/cli/daemon.js.map +1 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +35 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/config/index.d.ts +3 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +60 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/manager.d.ts +12 -0
- package/dist/config/manager.d.ts.map +1 -0
- package/dist/config/manager.js +73 -0
- package/dist/config/manager.js.map +1 -0
- package/dist/config/paths.d.ts +10 -0
- package/dist/config/paths.d.ts.map +1 -0
- package/dist/config/paths.js +16 -0
- package/dist/config/paths.js.map +1 -0
- package/dist/config/schema.d.ts +85 -0
- package/dist/config/schema.d.ts.map +1 -0
- package/dist/config/schema.js +3 -0
- package/dist/config/schema.js.map +1 -0
- package/dist/dashboard/api-routes.d.ts +6 -0
- package/dist/dashboard/api-routes.d.ts.map +1 -0
- package/dist/dashboard/api-routes.js +671 -0
- package/dist/dashboard/api-routes.js.map +1 -0
- package/dist/dashboard/api.d.ts +4 -0
- package/dist/dashboard/api.d.ts.map +1 -0
- package/dist/dashboard/api.js +25 -0
- package/dist/dashboard/api.js.map +1 -0
- package/dist/dashboard/page.d.ts +3 -0
- package/dist/dashboard/page.d.ts.map +1 -0
- package/dist/dashboard/page.js +1622 -0
- package/dist/dashboard/page.js.map +1 -0
- package/dist/dlp/actions.d.ts +13 -0
- package/dist/dlp/actions.d.ts.map +1 -0
- package/dist/dlp/actions.js +3 -0
- package/dist/dlp/actions.js.map +1 -0
- package/dist/dlp/ai-validator.d.ts +28 -0
- package/dist/dlp/ai-validator.d.ts.map +1 -0
- package/dist/dlp/ai-validator.js +214 -0
- package/dist/dlp/ai-validator.js.map +1 -0
- package/dist/dlp/engine.d.ts +34 -0
- package/dist/dlp/engine.d.ts.map +1 -0
- package/dist/dlp/engine.js +342 -0
- package/dist/dlp/engine.js.map +1 -0
- package/dist/dlp/entropy.d.ts +22 -0
- package/dist/dlp/entropy.d.ts.map +1 -0
- package/dist/dlp/entropy.js +43 -0
- package/dist/dlp/entropy.js.map +1 -0
- package/dist/dlp/message-cache.d.ts +45 -0
- package/dist/dlp/message-cache.d.ts.map +1 -0
- package/dist/dlp/message-cache.js +251 -0
- package/dist/dlp/message-cache.js.map +1 -0
- package/dist/dlp/patterns/context-aware.d.ts +4 -0
- package/dist/dlp/patterns/context-aware.d.ts.map +1 -0
- package/dist/dlp/patterns/context-aware.js +45 -0
- package/dist/dlp/patterns/context-aware.js.map +1 -0
- package/dist/dlp/patterns/high-confidence.d.ts +4 -0
- package/dist/dlp/patterns/high-confidence.d.ts.map +1 -0
- package/dist/dlp/patterns/high-confidence.js +140 -0
- package/dist/dlp/patterns/high-confidence.js.map +1 -0
- package/dist/dlp/patterns/prompt-injection.d.ts +4 -0
- package/dist/dlp/patterns/prompt-injection.d.ts.map +1 -0
- package/dist/dlp/patterns/prompt-injection.js +244 -0
- package/dist/dlp/patterns/prompt-injection.js.map +1 -0
- package/dist/dlp/patterns/validated.d.ts +4 -0
- package/dist/dlp/patterns/validated.d.ts.map +1 -0
- package/dist/dlp/patterns/validated.js +21 -0
- package/dist/dlp/patterns/validated.js.map +1 -0
- package/dist/dlp/remote-sync.d.ts +47 -0
- package/dist/dlp/remote-sync.d.ts.map +1 -0
- package/dist/dlp/remote-sync.js +252 -0
- package/dist/dlp/remote-sync.js.map +1 -0
- package/dist/dlp/semantics.d.ts +27 -0
- package/dist/dlp/semantics.d.ts.map +1 -0
- package/dist/dlp/semantics.js +93 -0
- package/dist/dlp/semantics.js.map +1 -0
- package/dist/dlp/structure.d.ts +25 -0
- package/dist/dlp/structure.d.ts.map +1 -0
- package/dist/dlp/structure.js +86 -0
- package/dist/dlp/structure.js.map +1 -0
- package/dist/dlp/validators.d.ts +6 -0
- package/dist/dlp/validators.d.ts.map +1 -0
- package/dist/dlp/validators.js +46 -0
- package/dist/dlp/validators.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +200 -0
- package/dist/index.js.map +1 -0
- package/dist/license/verify.d.ts +18 -0
- package/dist/license/verify.d.ts.map +1 -0
- package/dist/license/verify.js +71 -0
- package/dist/license/verify.js.map +1 -0
- package/dist/metrics/collector.d.ts +11 -0
- package/dist/metrics/collector.d.ts.map +1 -0
- package/dist/metrics/collector.js +17 -0
- package/dist/metrics/collector.js.map +1 -0
- package/dist/metrics/dashboard.d.ts +6 -0
- package/dist/metrics/dashboard.d.ts.map +1 -0
- package/dist/metrics/dashboard.js +66 -0
- package/dist/metrics/dashboard.js.map +1 -0
- package/dist/metrics/pricing.d.ts +10 -0
- package/dist/metrics/pricing.d.ts.map +1 -0
- package/dist/metrics/pricing.js +62 -0
- package/dist/metrics/pricing.js.map +1 -0
- package/dist/optimizer/cache.d.ts +14 -0
- package/dist/optimizer/cache.d.ts.map +1 -0
- package/dist/optimizer/cache.js +58 -0
- package/dist/optimizer/cache.js.map +1 -0
- package/dist/optimizer/estimator.d.ts +6 -0
- package/dist/optimizer/estimator.d.ts.map +1 -0
- package/dist/optimizer/estimator.js +12 -0
- package/dist/optimizer/estimator.js.map +1 -0
- package/dist/optimizer/reorder.d.ts +9 -0
- package/dist/optimizer/reorder.d.ts.map +1 -0
- package/dist/optimizer/reorder.js +27 -0
- package/dist/optimizer/reorder.js.map +1 -0
- package/dist/optimizer/trimmer.d.ts +9 -0
- package/dist/optimizer/trimmer.d.ts.map +1 -0
- package/dist/optimizer/trimmer.js +47 -0
- package/dist/optimizer/trimmer.js.map +1 -0
- package/dist/plugin-api/index.d.ts +3 -0
- package/dist/plugin-api/index.d.ts.map +1 -0
- package/dist/plugin-api/index.js +6 -0
- package/dist/plugin-api/index.js.map +1 -0
- package/dist/plugin-api/types.d.ts +77 -0
- package/dist/plugin-api/types.d.ts.map +1 -0
- package/dist/plugin-api/types.js +6 -0
- package/dist/plugin-api/types.js.map +1 -0
- package/dist/plugins/adapter.d.ts +12 -0
- package/dist/plugins/adapter.d.ts.map +1 -0
- package/dist/plugins/adapter.js +116 -0
- package/dist/plugins/adapter.js.map +1 -0
- package/dist/plugins/builtin/audit-logger.d.ts +9 -0
- package/dist/plugins/builtin/audit-logger.d.ts.map +1 -0
- package/dist/plugins/builtin/audit-logger.js +53 -0
- package/dist/plugins/builtin/audit-logger.js.map +1 -0
- package/dist/plugins/builtin/dlp-scanner.d.ts +19 -0
- package/dist/plugins/builtin/dlp-scanner.d.ts.map +1 -0
- package/dist/plugins/builtin/dlp-scanner.js +284 -0
- package/dist/plugins/builtin/dlp-scanner.js.map +1 -0
- package/dist/plugins/builtin/metrics-collector.d.ts +4 -0
- package/dist/plugins/builtin/metrics-collector.d.ts.map +1 -0
- package/dist/plugins/builtin/metrics-collector.js +111 -0
- package/dist/plugins/builtin/metrics-collector.js.map +1 -0
- package/dist/plugins/builtin/token-optimizer.d.ts +10 -0
- package/dist/plugins/builtin/token-optimizer.d.ts.map +1 -0
- package/dist/plugins/builtin/token-optimizer.js +120 -0
- package/dist/plugins/builtin/token-optimizer.js.map +1 -0
- package/dist/plugins/builtin/tool-guard.d.ts +20 -0
- package/dist/plugins/builtin/tool-guard.d.ts.map +1 -0
- package/dist/plugins/builtin/tool-guard.js +259 -0
- package/dist/plugins/builtin/tool-guard.js.map +1 -0
- package/dist/plugins/context.d.ts +8 -0
- package/dist/plugins/context.d.ts.map +1 -0
- package/dist/plugins/context.js +33 -0
- package/dist/plugins/context.js.map +1 -0
- package/dist/plugins/event-bus.d.ts +9 -0
- package/dist/plugins/event-bus.d.ts.map +1 -0
- package/dist/plugins/event-bus.js +25 -0
- package/dist/plugins/event-bus.js.map +1 -0
- package/dist/plugins/index.d.ts +18 -0
- package/dist/plugins/index.d.ts.map +1 -0
- package/dist/plugins/index.js +148 -0
- package/dist/plugins/index.js.map +1 -0
- package/dist/plugins/loader.d.ts +14 -0
- package/dist/plugins/loader.d.ts.map +1 -0
- package/dist/plugins/loader.js +98 -0
- package/dist/plugins/loader.js.map +1 -0
- package/dist/plugins/types.d.ts +91 -0
- package/dist/plugins/types.d.ts.map +1 -0
- package/dist/plugins/types.js +3 -0
- package/dist/plugins/types.js.map +1 -0
- package/dist/proxy/certs.d.ts +10 -0
- package/dist/proxy/certs.d.ts.map +1 -0
- package/dist/proxy/certs.js +110 -0
- package/dist/proxy/certs.js.map +1 -0
- package/dist/proxy/connect.d.ts +11 -0
- package/dist/proxy/connect.d.ts.map +1 -0
- package/dist/proxy/connect.js +298 -0
- package/dist/proxy/connect.js.map +1 -0
- package/dist/proxy/forwarder.d.ts +14 -0
- package/dist/proxy/forwarder.d.ts.map +1 -0
- package/dist/proxy/forwarder.js +342 -0
- package/dist/proxy/forwarder.js.map +1 -0
- package/dist/proxy/passthrough.d.ts +4 -0
- package/dist/proxy/passthrough.d.ts.map +1 -0
- package/dist/proxy/passthrough.js +68 -0
- package/dist/proxy/passthrough.js.map +1 -0
- package/dist/proxy/providers/anthropic.d.ts +4 -0
- package/dist/proxy/providers/anthropic.d.ts.map +1 -0
- package/dist/proxy/providers/anthropic.js +46 -0
- package/dist/proxy/providers/anthropic.js.map +1 -0
- package/dist/proxy/providers/classify.d.ts +14 -0
- package/dist/proxy/providers/classify.d.ts.map +1 -0
- package/dist/proxy/providers/classify.js +37 -0
- package/dist/proxy/providers/classify.js.map +1 -0
- package/dist/proxy/providers/claude-web.d.ts +8 -0
- package/dist/proxy/providers/claude-web.d.ts.map +1 -0
- package/dist/proxy/providers/claude-web.js +50 -0
- package/dist/proxy/providers/claude-web.js.map +1 -0
- package/dist/proxy/providers/gemini.d.ts +4 -0
- package/dist/proxy/providers/gemini.d.ts.map +1 -0
- package/dist/proxy/providers/gemini.js +38 -0
- package/dist/proxy/providers/gemini.js.map +1 -0
- package/dist/proxy/providers/index.d.ts +27 -0
- package/dist/proxy/providers/index.d.ts.map +1 -0
- package/dist/proxy/providers/index.js +32 -0
- package/dist/proxy/providers/index.js.map +1 -0
- package/dist/proxy/providers/messaging.d.ts +2 -0
- package/dist/proxy/providers/messaging.d.ts.map +1 -0
- package/dist/proxy/providers/messaging.js +53 -0
- package/dist/proxy/providers/messaging.js.map +1 -0
- package/dist/proxy/providers/openai.d.ts +4 -0
- package/dist/proxy/providers/openai.d.ts.map +1 -0
- package/dist/proxy/providers/openai.js +38 -0
- package/dist/proxy/providers/openai.js.map +1 -0
- package/dist/proxy/providers/telegram.d.ts +8 -0
- package/dist/proxy/providers/telegram.d.ts.map +1 -0
- package/dist/proxy/providers/telegram.js +35 -0
- package/dist/proxy/providers/telegram.js.map +1 -0
- package/dist/proxy/router.d.ts +12 -0
- package/dist/proxy/router.d.ts.map +1 -0
- package/dist/proxy/router.js +26 -0
- package/dist/proxy/router.js.map +1 -0
- package/dist/proxy/safety.d.ts +13 -0
- package/dist/proxy/safety.d.ts.map +1 -0
- package/dist/proxy/safety.js +58 -0
- package/dist/proxy/safety.js.map +1 -0
- package/dist/proxy/server.d.ts +8 -0
- package/dist/proxy/server.d.ts.map +1 -0
- package/dist/proxy/server.js +126 -0
- package/dist/proxy/server.js.map +1 -0
- package/dist/proxy/streaming.d.ts +21 -0
- package/dist/proxy/streaming.d.ts.map +1 -0
- package/dist/proxy/streaming.js +70 -0
- package/dist/proxy/streaming.js.map +1 -0
- package/dist/storage/database.d.ts +6 -0
- package/dist/storage/database.d.ts.map +1 -0
- package/dist/storage/database.js +44 -0
- package/dist/storage/database.js.map +1 -0
- package/dist/storage/encryption.d.ts +11 -0
- package/dist/storage/encryption.d.ts.map +1 -0
- package/dist/storage/encryption.js +47 -0
- package/dist/storage/encryption.js.map +1 -0
- package/dist/storage/migrations.d.ts +3 -0
- package/dist/storage/migrations.d.ts.map +1 -0
- package/dist/storage/migrations.js +265 -0
- package/dist/storage/migrations.js.map +1 -0
- package/dist/storage/repositories/audit-log.d.ts +115 -0
- package/dist/storage/repositories/audit-log.d.ts.map +1 -0
- package/dist/storage/repositories/audit-log.js +586 -0
- package/dist/storage/repositories/audit-log.js.map +1 -0
- package/dist/storage/repositories/cache.d.ts +26 -0
- package/dist/storage/repositories/cache.d.ts.map +1 -0
- package/dist/storage/repositories/cache.js +44 -0
- package/dist/storage/repositories/cache.js.map +1 -0
- package/dist/storage/repositories/dlp-config-history.d.ts +17 -0
- package/dist/storage/repositories/dlp-config-history.d.ts.map +1 -0
- package/dist/storage/repositories/dlp-config-history.js +30 -0
- package/dist/storage/repositories/dlp-config-history.js.map +1 -0
- package/dist/storage/repositories/dlp-events.d.ts +35 -0
- package/dist/storage/repositories/dlp-events.d.ts.map +1 -0
- package/dist/storage/repositories/dlp-events.js +57 -0
- package/dist/storage/repositories/dlp-events.js.map +1 -0
- package/dist/storage/repositories/dlp-patterns.d.ts +70 -0
- package/dist/storage/repositories/dlp-patterns.d.ts.map +1 -0
- package/dist/storage/repositories/dlp-patterns.js +187 -0
- package/dist/storage/repositories/dlp-patterns.js.map +1 -0
- package/dist/storage/repositories/optimizer-events.d.ts +28 -0
- package/dist/storage/repositories/optimizer-events.d.ts.map +1 -0
- package/dist/storage/repositories/optimizer-events.js +49 -0
- package/dist/storage/repositories/optimizer-events.js.map +1 -0
- package/dist/storage/repositories/plugin-events.d.ts +34 -0
- package/dist/storage/repositories/plugin-events.d.ts.map +1 -0
- package/dist/storage/repositories/plugin-events.js +64 -0
- package/dist/storage/repositories/plugin-events.js.map +1 -0
- package/dist/storage/repositories/requests.d.ts +68 -0
- package/dist/storage/repositories/requests.d.ts.map +1 -0
- package/dist/storage/repositories/requests.js +113 -0
- package/dist/storage/repositories/requests.js.map +1 -0
- package/dist/storage/repositories/sessions.d.ts +23 -0
- package/dist/storage/repositories/sessions.d.ts.map +1 -0
- package/dist/storage/repositories/sessions.js +42 -0
- package/dist/storage/repositories/sessions.js.map +1 -0
- package/dist/storage/repositories/tool-calls.d.ts +49 -0
- package/dist/storage/repositories/tool-calls.d.ts.map +1 -0
- package/dist/storage/repositories/tool-calls.js +61 -0
- package/dist/storage/repositories/tool-calls.js.map +1 -0
- package/dist/storage/repositories/tool-guard-rules.d.ts +50 -0
- package/dist/storage/repositories/tool-guard-rules.d.ts.map +1 -0
- package/dist/storage/repositories/tool-guard-rules.js +120 -0
- package/dist/storage/repositories/tool-guard-rules.js.map +1 -0
- package/dist/tool-guard/alert.d.ts +30 -0
- package/dist/tool-guard/alert.d.ts.map +1 -0
- package/dist/tool-guard/alert.js +113 -0
- package/dist/tool-guard/alert.js.map +1 -0
- package/dist/tool-guard/extractor.d.ts +10 -0
- package/dist/tool-guard/extractor.d.ts.map +1 -0
- package/dist/tool-guard/extractor.js +309 -0
- package/dist/tool-guard/extractor.js.map +1 -0
- package/dist/tool-guard/rules.d.ts +18 -0
- package/dist/tool-guard/rules.d.ts.map +1 -0
- package/dist/tool-guard/rules.js +255 -0
- package/dist/tool-guard/rules.js.map +1 -0
- package/dist/tool-guard/streaming-guard.d.ts +57 -0
- package/dist/tool-guard/streaming-guard.d.ts.map +1 -0
- package/dist/tool-guard/streaming-guard.js +389 -0
- package/dist/tool-guard/streaming-guard.js.map +1 -0
- package/dist/utils/hash.d.ts +2 -0
- package/dist/utils/hash.d.ts.map +1 -0
- package/dist/utils/hash.js +8 -0
- package/dist/utils/hash.js.map +1 -0
- package/dist/utils/logger.d.ts +11 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +54 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/timeout.d.ts +5 -0
- package/dist/utils/timeout.d.ts.map +1 -0
- package/dist/utils/timeout.js +26 -0
- package/dist/utils/timeout.js.map +1 -0
- package/dist/version.d.ts +5 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +23 -0
- package/dist/version.js.map +1 -0
- package/package.json +67 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 aiwatching
|
|
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.
|
package/README.md
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
**English** | [中文](README.zh.md)
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<a href="https://github.com/aiwatching/bastion/stargazers"><img src="https://img.shields.io/github/stars/aiwatching/bastion?style=flat-square" alt="Stars"></a>
|
|
5
|
+
<a href="https://github.com/aiwatching/bastion/blob/main/LICENSE"><img src="https://img.shields.io/github/license/aiwatching/bastion?style=flat-square" alt="License"></a>
|
|
6
|
+
<a href="https://github.com/aiwatching/bastion/commits/main"><img src="https://img.shields.io/github/last-commit/aiwatching/bastion?style=flat-square" alt="Last Commit"></a>
|
|
7
|
+
</p>
|
|
8
|
+
|
|
9
|
+
# Bastion — Secure Your AI Agents Locally
|
|
10
|
+
|
|
11
|
+
**AI agents can leak your credentials, get hijacked by prompt injection, and execute dangerous commands on your machine. Bastion stops all three.**
|
|
12
|
+
|
|
13
|
+
Bastion is a local-first security gateway that sits between your AI agents (Claude Code, Cursor, Copilot, custom agents) and LLM providers. It provides data loss prevention, prompt injection detection, tool call monitoring, and full audit logging — all running on your machine with zero cloud dependencies.
|
|
14
|
+
|
|
15
|
+
<!-- TODO: Replace with 30-second demo GIF:
|
|
16
|
+
bastion start → use Claude Code → DLP catches leaked API key → Tool Guard blocks rm -rf → dashboard view
|
|
17
|
+
-->
|
|
18
|
+

|
|
19
|
+
|
|
20
|
+
## The Problem
|
|
21
|
+
|
|
22
|
+
AI agents are powerful — and dangerous. Every time an agent runs on your machine, it can:
|
|
23
|
+
|
|
24
|
+
- **Leak secrets in prompts** — API keys, database passwords, private keys from your codebase get sent to LLM providers without you knowing
|
|
25
|
+
- **Be hijacked via prompt injection** — malicious instructions hidden in code comments, READMEs, or fetched content can take over your agent's behavior
|
|
26
|
+
- **Execute destructive commands** — `rm -rf /`, `curl | bash`, `git push --force` — one bad tool call and the damage is done
|
|
27
|
+
|
|
28
|
+
You can't watch every request manually. Bastion does it for you.
|
|
29
|
+
|
|
30
|
+
## Install
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
# macOS / Linux
|
|
34
|
+
curl -fsSL https://raw.githubusercontent.com/aiwatching/bastion/main/install.sh | bash
|
|
35
|
+
|
|
36
|
+
# Windows (PowerShell)
|
|
37
|
+
irm https://raw.githubusercontent.com/aiwatching/bastion/main/install.ps1 -OutFile install.ps1; .\install.ps1
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Requires Node.js 22 LTS (recommended). Node.js 18+ supported. Installs to `~/.bastion/app/`.
|
|
41
|
+
|
|
42
|
+
## Quick Start
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
bastion start # Start the gateway
|
|
46
|
+
bastion wrap claude # Wrap any AI agent
|
|
47
|
+
open http://127.0.0.1:8420/dashboard # Real-time security dashboard
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Three commands. Your agent traffic is now monitored.
|
|
51
|
+
|
|
52
|
+
For global proxy mode (all terminals, all apps):
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
eval $(bastion proxy on) # bash/zsh
|
|
56
|
+
bastion proxy on | Invoke-Expression # PowerShell
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Core Security Features
|
|
60
|
+
|
|
61
|
+
### 🔑 Data Loss Prevention (DLP)
|
|
62
|
+
|
|
63
|
+
Scans **both directions** — outgoing prompts and incoming responses — to catch sensitive data before it leaves your machine or reaches your agent.
|
|
64
|
+
|
|
65
|
+
5-layer detection pipeline: structure parsing → entropy filtering → regex matching → field-name semantics → optional AI validation.
|
|
66
|
+
|
|
67
|
+
**20 built-in patterns:**
|
|
68
|
+
|
|
69
|
+
| Category | What It Catches |
|
|
70
|
+
|----------|----------------|
|
|
71
|
+
| API Keys & Tokens | AWS, GitHub PAT, Slack, Stripe, OpenAI, Anthropic, Google AI, Hugging Face, and more |
|
|
72
|
+
| Secrets | Private keys, generic high-entropy secrets in sensitive fields (`password`, `secret`, `api_key`) |
|
|
73
|
+
| PII | Credit card (Luhn validated), US SSN, email, phone, driver license, passport |
|
|
74
|
+
|
|
75
|
+
Four action modes: `pass` · `warn` · `redact` · `block`
|
|
76
|
+
|
|
77
|
+
Add custom patterns from the dashboard. Sync shared patterns from a [remote Git repo](https://github.com/aiwatching/bastion_signature). No restart required.
|
|
78
|
+
|
|
79
|
+

|
|
80
|
+
|
|
81
|
+
### 🧬 Prompt Injection Detection
|
|
82
|
+
|
|
83
|
+
Detects malicious instructions injected into content that your agent processes — code comments, markdown files, web pages, API responses. Catches attempts to hijack agent behavior, override system prompts, or exfiltrate data through indirect prompt injection.
|
|
84
|
+
|
|
85
|
+
### 🛡️ Tool Guard
|
|
86
|
+
|
|
87
|
+
Monitors and blocks dangerous tool calls made by AI agents in real-time. Intercepts tool invocations from all major providers (Anthropic `tool_use`, OpenAI `tool_calls`, Gemini `functionCall`) and evaluates them against security rules.
|
|
88
|
+
|
|
89
|
+
**26 built-in rules across 9 categories:**
|
|
90
|
+
|
|
91
|
+
| Category | Examples | Severity |
|
|
92
|
+
|----------|----------|----------|
|
|
93
|
+
| Destructive filesystem | `rm -rf /`, `chmod 777`, `dd` to disk | critical |
|
|
94
|
+
| Code execution | `curl \| bash`, `eval()` on dynamic input | critical |
|
|
95
|
+
| Credential access | Read `.env`, access private keys, echo secrets | high |
|
|
96
|
+
| Network exfiltration | `curl POST` with data, transfer to raw IP | high |
|
|
97
|
+
| Git destructive | Force push, `reset --hard`, `clean -f` | high |
|
|
98
|
+
| System config | `sudo`, `iptables`, `systemctl` | medium |
|
|
99
|
+
| Package publish | `npm publish`, `pip upload` | medium |
|
|
100
|
+
| File operations | `rm` files, write to `/etc/` or `/usr/` | medium / low |
|
|
101
|
+
|
|
102
|
+
Action modes: `audit` (log and alert) or `block` (intercept in real-time, including streaming responses). Desktop notifications and webhook alerts (Slack, Discord) for high-severity matches.
|
|
103
|
+
|
|
104
|
+
### 📝 Audit Logger
|
|
105
|
+
|
|
106
|
+
Full request/response history for every AI interaction, encrypted at rest. Session-based timeline with DLP and Tool Guard tags. Any security event automatically creates an audit entry — even if the audit plugin is disabled.
|
|
107
|
+
|
|
108
|
+
Configurable retention with automatic purge. Formatted viewer in the dashboard for reviewing exactly what your agent sent and received.
|
|
109
|
+
|
|
110
|
+

|
|
111
|
+
|
|
112
|
+
## Dashboard
|
|
113
|
+
|
|
114
|
+
Real-time security dashboard at `http://127.0.0.1:8420/dashboard`:
|
|
115
|
+
|
|
116
|
+
- **Overview** — Request metrics, cost, tokens, per-provider/model/session breakdown
|
|
117
|
+
- **DLP** — Findings, config, signature management, standalone test scanner with trace log
|
|
118
|
+
- **Tool Guard** — Tool call history, severity, rule management (built-in + custom)
|
|
119
|
+
- **Audit** — Session timeline, security-tagged entries, formatted request/response viewer
|
|
120
|
+
- **Settings** — Toggle plugins, configure rules — all changes apply without restart
|
|
121
|
+
|
|
122
|
+
## How It Works
|
|
123
|
+
|
|
124
|
+
Bastion runs as a local HTTPS proxy with selective interception:
|
|
125
|
+
|
|
126
|
+
- **AI provider domains** (Anthropic, OpenAI, Google AI, etc.) → decrypted and processed through the security pipeline (DLP → Prompt Injection → Tool Guard → Audit), then forwarded upstream
|
|
127
|
+
- **Everything else** → plain TCP tunnel, zero inspection. OAuth, browser traffic, etc. pass through untouched
|
|
128
|
+
|
|
129
|
+
A local CA certificate is generated automatically. No data leaves your machine.
|
|
130
|
+
|
|
131
|
+
## Works With Any AI Agent
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
bastion wrap claude # Claude Code
|
|
135
|
+
bastion wrap cursor # Cursor
|
|
136
|
+
bastion wrap python app.py # Custom Python agent
|
|
137
|
+
bastion wrap node server.js # Custom Node.js agent
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### OpenClaw Integration
|
|
141
|
+
|
|
142
|
+
Proxy all AI traffic from [OpenClaw](https://github.com/openclaw/openclaw) instances with full Bastion security:
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
bastion openclaw docker up mywork --port 18789 # Docker
|
|
146
|
+
bastion openclaw local start mywork --port 18789 # Local
|
|
147
|
+
bastion openclaw docker attach <container-name> # Existing container
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
See [OpenClaw Docker Guide](docs/openclaw-docker.md) | [Local Guide](docs/openclaw-local.md)
|
|
151
|
+
|
|
152
|
+
## Documentation
|
|
153
|
+
|
|
154
|
+
| Doc | Description |
|
|
155
|
+
|-----|-------------|
|
|
156
|
+
| [DLP Engine Architecture](docs/dlp.md) | 5-layer detection pipeline internals |
|
|
157
|
+
| [AI Agent Monitoring](docs/agent-monitoring.md) | Monitor Claude Code, Cursor, custom apps |
|
|
158
|
+
| [Security Research](docs/security-research.md) | AI agent threat landscape & Bastion roadmap |
|
|
159
|
+
| [Remote Signatures](docs/remote-signatures.md) | Sync DLP patterns from Git repo |
|
|
160
|
+
| [OpenClaw DLP Alerts](docs/openclaw-dlp-skill.md) | Telegram/Discord alert integration |
|
|
161
|
+
| [Windows Troubleshooting](docs/windows-troubleshooting.md) | Common Windows issues |
|
|
162
|
+
|
|
163
|
+
Chinese versions (中文) available for all docs.
|
|
164
|
+
|
|
165
|
+
## Data Storage
|
|
166
|
+
|
|
167
|
+
Everything stays on your machine in `~/.bastion/`:
|
|
168
|
+
|
|
169
|
+
```
|
|
170
|
+
~/.bastion/
|
|
171
|
+
bastion.db # SQLite (metrics, DLP events, tool guard, audit)
|
|
172
|
+
config.yaml # Your config overrides
|
|
173
|
+
ca.key / ca.crt / certs/ # Local CA & certificates
|
|
174
|
+
.key # AES encryption key for audit data
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
## Contributing
|
|
178
|
+
|
|
179
|
+
Issues and PRs welcome. See [CONTRIBUTING.md](CONTRIBUTING.md).
|
|
180
|
+
|
|
181
|
+
## License
|
|
182
|
+
|
|
183
|
+
[MIT](LICENSE)
|
package/README.zh.md
ADDED
|
@@ -0,0 +1,468 @@
|
|
|
1
|
+
[English](README.md) | **中文**
|
|
2
|
+
|
|
3
|
+
# Bastion AI Gateway
|
|
4
|
+
|
|
5
|
+
本地优先的 LLM 提供商代理(Anthropic、OpenAI、Gemini)。提供 DLP 扫描、工具调用监控、使用量统计、费用追踪和响应缓存——全部在本机运行。
|
|
6
|
+
|
|
7
|
+

|
|
8
|
+
|
|
9
|
+

|
|
10
|
+
|
|
11
|
+

|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## 安装
|
|
15
|
+
|
|
16
|
+
### macOS / Linux
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
curl -fsSL https://raw.githubusercontent.com/aiwatching/bastion/main/install.sh | bash
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
或从本地源码安装:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
cd bastion && bash install.sh
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Windows (PowerShell)
|
|
29
|
+
|
|
30
|
+
```powershell
|
|
31
|
+
irm https://raw.githubusercontent.com/aiwatching/bastion/main/install.ps1 -OutFile install.ps1; .\install.ps1
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
或从本地源码安装:
|
|
35
|
+
|
|
36
|
+
```powershell
|
|
37
|
+
cd bastion; .\install.ps1
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
需要 **Node.js 22 LTS**(推荐)。Node.js 18+ 可用,但非 LTS 版本可能需要[额外配置](docs/windows-troubleshooting.zh.md#1-better-sqlite3-编译失败非-lts-nodejs)。安装至 `~/.bastion/app/`。
|
|
41
|
+
|
|
42
|
+
## 快速开始
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
# 启动网关
|
|
46
|
+
bastion start
|
|
47
|
+
|
|
48
|
+
# 方式 A:包裹单个命令(代理仅作用于该进程)
|
|
49
|
+
bastion wrap claude
|
|
50
|
+
bastion wrap python my_app.py
|
|
51
|
+
|
|
52
|
+
# 方式 B:全局代理(所有终端、所有新进程、GUI 应用)
|
|
53
|
+
eval $(bastion proxy on) # bash/zsh
|
|
54
|
+
bastion proxy on | Invoke-Expression # PowerShell
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## OpenClaw 集成
|
|
58
|
+
|
|
59
|
+
Bastion 可以代理 [OpenClaw](https://github.com/openclaw/openclaw) 实例的所有 AI 流量(Docker 和本地均支持),提供 DLP 扫描、费用追踪和审计日志。
|
|
60
|
+
|
|
61
|
+
### Docker
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
# 创建并启动 OpenClaw 实例,自动配置 Bastion 代理
|
|
65
|
+
bastion openclaw docker up mywork \
|
|
66
|
+
--port 18789 \
|
|
67
|
+
--image openclaw:local \
|
|
68
|
+
--config-dir ~/openclaw-data/mywork/config \
|
|
69
|
+
--workspace ~/openclaw-data/mywork/workspace
|
|
70
|
+
|
|
71
|
+
# 管理实例
|
|
72
|
+
bastion openclaw docker status # 查看所有实例
|
|
73
|
+
bastion openclaw docker stop mywork # 停止
|
|
74
|
+
bastion openclaw docker logs mywork -f # 实时日志
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
完整指南:[OpenClaw Docker 集成](docs/openclaw-docker.zh.md) | [English](docs/openclaw-docker.md)
|
|
78
|
+
|
|
79
|
+
### 本地运行
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
# 本地启动 OpenClaw 并通过 Bastion 代理
|
|
83
|
+
bastion openclaw local start mywork --port 18789
|
|
84
|
+
|
|
85
|
+
# 管理
|
|
86
|
+
bastion openclaw local status
|
|
87
|
+
bastion openclaw local stop mywork
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
完整指南:[OpenClaw 本地安装](docs/openclaw-local.zh.md) | [English](docs/openclaw-local.md)
|
|
91
|
+
|
|
92
|
+
### 接入已有容器
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
# 将 Bastion 代理注入到运行中的 Docker 容器
|
|
96
|
+
bastion openclaw docker attach <container-name>
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## 使用方法
|
|
100
|
+
|
|
101
|
+
### `bastion start`
|
|
102
|
+
|
|
103
|
+
启动网关(默认后台守护进程模式)。
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
bastion start # 后台守护进程
|
|
107
|
+
bastion start --foreground # 前台运行(实时查看日志)
|
|
108
|
+
bastion start -p 9000 # 自定义端口
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### `bastion stop`
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
bastion stop
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### `bastion proxy on/off/status`
|
|
118
|
+
|
|
119
|
+
全局代理模式——将**所有** AI 流量通过 Bastion 路由,包括后台进程和 GUI 应用。
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
eval $(bastion proxy on) # bash/zsh:启用
|
|
123
|
+
eval $(bastion proxy off) # bash/zsh:禁用
|
|
124
|
+
bastion proxy on | Invoke-Expression # PowerShell:启用
|
|
125
|
+
bastion proxy off | Invoke-Expression # PowerShell:禁用
|
|
126
|
+
bastion proxy status # 检查当前代理状态
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
`bastion proxy on` 做了什么:
|
|
130
|
+
1. 将代理环境变量写入 shell 配置文件(`~/.zshrc` / `~/.bashrc` / PowerShell `$PROFILE`)——新终端自动继承
|
|
131
|
+
2. 设置系统 HTTPS 代理(macOS `networksetup`、Linux GNOME `gsettings`、Windows 注册表)——GUI 应用也通过 Bastion 路由
|
|
132
|
+
3. 向 stdout 输出对应 shell 语法的命令——通过 `eval` / `Invoke-Expression` 使当前 shell 立即生效
|
|
133
|
+
|
|
134
|
+
设置的环境变量:
|
|
135
|
+
|
|
136
|
+
| Variable | Purpose |
|
|
137
|
+
|----------|---------|
|
|
138
|
+
| `HTTPS_PROXY` | Standard proxy (curl, Python, Go, etc.) |
|
|
139
|
+
| `NO_PROXY` | Excludes OAuth/auth domains |
|
|
140
|
+
| `NODE_EXTRA_CA_CERTS` | Node.js tools trust Bastion CA cert |
|
|
141
|
+
| `ANTHROPIC_BASE_URL` | Anthropic SDK direct connection |
|
|
142
|
+
| `OPENAI_BASE_URL` | OpenAI SDK direct connection |
|
|
143
|
+
| `GOOGLE_AI_BASE_URL` | Google AI SDK direct connection |
|
|
144
|
+
|
|
145
|
+
选项:
|
|
146
|
+
- `--no-system` — 跳过设置系统代理
|
|
147
|
+
- `--trust-ca` — 将 CA 证书添加到系统信任存储(需要 sudo)
|
|
148
|
+
|
|
149
|
+
> **注意:** `bastion stop` 会自动移除指向 Bastion 的系统代理设置,防止网络中断。
|
|
150
|
+
|
|
151
|
+
支持平台:macOS、Linux(GNOME 桌面支持系统代理;无桌面服务器直接使用 `HTTPS_PROXY` 环境变量)、Windows(系统代理通过注册表设置;自动配置 PowerShell profile)。
|
|
152
|
+
|
|
153
|
+
### `bastion wrap <command>`
|
|
154
|
+
|
|
155
|
+
通过 Bastion 路由 AI 流量来运行单个命令。代理设置仅作用于该进程。
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
bastion wrap claude
|
|
159
|
+
bastion wrap python app.py
|
|
160
|
+
bastion wrap node server.js
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
选项:
|
|
164
|
+
- `--base-url` — 使用 `ANTHROPIC_BASE_URL` 模式代替 `HTTPS_PROXY`(更简单但会影响 OAuth)
|
|
165
|
+
- `--label <name>` — 用于 Dashboard 追踪的可读会话标签
|
|
166
|
+
|
|
167
|
+
### `bastion env`
|
|
168
|
+
|
|
169
|
+
打印 shell 环境变量导出命令,用于手动设置代理。
|
|
170
|
+
|
|
171
|
+
```bash
|
|
172
|
+
eval $(bastion env) # bash/zsh
|
|
173
|
+
bastion env --powershell | Invoke-Expression # PowerShell
|
|
174
|
+
eval $(bastion env --unset) # bash/zsh:取消设置
|
|
175
|
+
bastion env --powershell --unset | Invoke-Expression # PowerShell:取消设置
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### `bastion stats`
|
|
179
|
+
|
|
180
|
+
查看使用统计(请求数、费用、token 数、延迟)。
|
|
181
|
+
|
|
182
|
+
```bash
|
|
183
|
+
bastion stats
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### `bastion health`
|
|
187
|
+
|
|
188
|
+
检查网关是否正在运行。
|
|
189
|
+
|
|
190
|
+
```bash
|
|
191
|
+
bastion health
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### `bastion trust-ca`
|
|
195
|
+
|
|
196
|
+
显示 CA 证书信息,用于手动信任配置。
|
|
197
|
+
|
|
198
|
+
```bash
|
|
199
|
+
bastion trust-ca
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
## Dashboard
|
|
203
|
+
|
|
204
|
+
网关运行时,在浏览器中打开 `http://127.0.0.1:8420/dashboard`。
|
|
205
|
+
|
|
206
|
+
6 个标签页:
|
|
207
|
+
- **Overview** — 请求指标、费用、token 数、按提供商/模型/会话分类的统计
|
|
208
|
+
- **DLP** — 子标签:Findings(方向、片段、钻取至审计记录)、Config(引擎开关、动作模式、AI 验证、语义规则)、Signatures(远程同步状态、版本追踪、变更日志、模式管理)、Test(独立扫描器,含预设、trace 日志)
|
|
209
|
+
- **Tool Guard** — 子标签:Calls(最近工具调用历史,含严重级别、规则匹配、执行动作)、Rules(26 条内置规则 + 自定义规则管理,可逐条启用/禁用)
|
|
210
|
+
- **Optimizer** — 缓存命中率、节省的 token 数
|
|
211
|
+
- **Audit** — 基于会话的时间线、DLP/Tool Guard 标记条目、摘要预览、格式化请求/响应查看器
|
|
212
|
+
- **Settings** — 切换 plugin、配置 AI 验证、语义规则,运行时修改无需重启
|
|
213
|
+
|
|
214
|
+
## 工作原理
|
|
215
|
+
|
|
216
|
+
Bastion 作为 HTTPS 代理运行,对特定域名进行选择性 MITM(中间人)拦截:
|
|
217
|
+
|
|
218
|
+
- **API 域名**(`api.anthropic.com`、`api.openai.com`、`generativelanguage.googleapis.com`、`claude.ai`、`api.telegram.org`、`discord.com`、`api.slack.com` 等)——流量被解密,通过 plugin 管线处理(DLP、指标、缓存),然后转发至真实上游。
|
|
219
|
+
- **其他所有域名**——纯 TCP 隧道,不做任何检查。OAuth 流程、浏览器流量等原样通过。
|
|
220
|
+
|
|
221
|
+
本地 CA 证书(`~/.bastion/ca.crt`)会自动生成。Node.js 工具通过 `NODE_EXTRA_CA_CERTS` 信任该证书。
|
|
222
|
+
|
|
223
|
+
## Plugins
|
|
224
|
+
|
|
225
|
+
### Metrics Collector
|
|
226
|
+
记录每个 API 请求的提供商、模型、token 数、费用、延迟。数据存储在 SQLite(`~/.bastion/bastion.db`)中。支持按会话和 API key 过滤。
|
|
227
|
+
|
|
228
|
+
### DLP Scanner
|
|
229
|
+
双向扫描——同时检查**发出的请求**和**收到的响应**中的敏感数据。非流式响应在发送前拦截(可在到达客户端之前阻止/脱敏)。流式响应在发送后扫描(仅检测和审计)。
|
|
230
|
+
|
|
231
|
+
任何 DLP 命中都会自动创建审计日志条目,包含完整的请求/响应内容,无论 Audit Logger plugin 是否启用。DLP 标记的审计条目在 Dashboard 中会有视觉标识。
|
|
232
|
+
|
|
233
|
+
引擎使用 5 层检测管线(结构解析 -> 熵过滤 -> 正则匹配 -> 字段名语义分析 -> AI 验证)。详见 [DLP 引擎架构](docs/dlp.zh.md)。
|
|
234
|
+
|
|
235
|
+
**内置模式(20 个):**
|
|
236
|
+
|
|
237
|
+
| Category | Patterns |
|
|
238
|
+
|----------|----------|
|
|
239
|
+
| `high-confidence` | AWS Access Key, AWS Secret Key, GitHub PAT, GitHub Fine-grained PAT, Slack Token, Stripe Secret Key, Private Key, OpenAI API Key, Anthropic API Key, Google AI / Gemini API Key, Hugging Face Token, Replicate API Token, Groq API Key, Perplexity API Key, xAI (Grok) API Key, Cohere / Mistral / Together AI API Key (context-aware), Azure OpenAI API Key (context-aware), Telegram Bot Token |
|
|
240
|
+
| `validated` | Credit Card (Luhn check), US SSN (structural validation) |
|
|
241
|
+
| `context-aware` | Email Address, Phone Number, IPv4 Address, Driver License, Passport Number |
|
|
242
|
+
|
|
243
|
+
模式存储在 SQLite 中,可通过 Dashboard 管理(启用/禁用、添加自定义模式),无需重启。内置模式在首次启动时自动初始化。
|
|
244
|
+
|
|
245
|
+
**远程签名库:**
|
|
246
|
+
模式也可以从远程 Git 仓库([bastion_signature](https://github.com/aiwatching/bastion_signature))同步,支持独立版本控制和自动更新检测。详见 [远程签名库](docs/remote-signatures.zh.md)。
|
|
247
|
+
|
|
248
|
+
**通用密钥检测:**
|
|
249
|
+
敏感字段名(如 `password`、`secret`、`api_key`)中的高熵值即使没有特定正则模式也能被检测到。敏感性规则和非敏感字段名可在运行时配置。
|
|
250
|
+
|
|
251
|
+
**AI 验证(可选,默认关闭):**
|
|
252
|
+
使用 LLM 过滤误报。在配置中填入 API key 即可启用——结果会被缓存(LRU)以减少 token 消耗。
|
|
253
|
+
|
|
254
|
+
**独立扫描 API:**
|
|
255
|
+
```bash
|
|
256
|
+
curl -X POST http://127.0.0.1:8420/api/dlp/scan \
|
|
257
|
+
-H "Content-Type: application/json" \
|
|
258
|
+
-d '{"text": "my key is sk-ant-abc123...", "action": "warn", "trace": true}'
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
传入 `"trace": true` 可获取检测管线的详细逐步 trace 日志(用于调试模式行为)。
|
|
262
|
+
|
|
263
|
+
在 `~/.bastion/config.yaml` 中配置:
|
|
264
|
+
```yaml
|
|
265
|
+
plugins:
|
|
266
|
+
dlp:
|
|
267
|
+
action: "warn" # pass | warn | redact | block
|
|
268
|
+
patterns:
|
|
269
|
+
- "high-confidence"
|
|
270
|
+
- "validated"
|
|
271
|
+
- "context-aware"
|
|
272
|
+
remotePatterns:
|
|
273
|
+
url: "https://github.com/aiwatching/bastion_signature.git" # leave empty to disable
|
|
274
|
+
branch: "auto" # "auto" = match Bastion VERSION, or explicit e.g. "v0.1.0"
|
|
275
|
+
syncOnStart: true # pull latest on startup
|
|
276
|
+
syncIntervalMinutes: 0 # 0 = startup only, >0 = periodic sync (minutes)
|
|
277
|
+
aiValidation:
|
|
278
|
+
enabled: false # set to true to enable LLM-based false positive filtering
|
|
279
|
+
provider: "anthropic" # anthropic | openai
|
|
280
|
+
model: "claude-haiku-4-5-20241022"
|
|
281
|
+
apiKey: "" # required if enabled
|
|
282
|
+
semantics:
|
|
283
|
+
sensitivePatterns: [] # extra regex patterns for sensitive field names
|
|
284
|
+
nonSensitiveNames: [] # extra field names to exclude from detection
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
### Tool Guard
|
|
288
|
+
实时监控和阻断 AI Agent 发起的危险工具调用。检查 LLM 响应中的工具调用(Anthropic `tool_use`、OpenAI `tool_calls`、Gemini `functionCall`),并根据可配置的规则进行评估。
|
|
289
|
+
|
|
290
|
+
两种动作模式:
|
|
291
|
+
- **audit** — 记录所有工具调用,标记危险调用(不阻断)
|
|
292
|
+
- **block** — 实时阻断危险工具调用。流式响应中,`StreamingToolGuard` 拦截 SSE 事件,将被阻断的工具调用替换为文本警告。非流式响应中,整个响应在到达客户端之前被阻止。
|
|
293
|
+
|
|
294
|
+
**内置规则(26 条):**
|
|
295
|
+
|
|
296
|
+
| 类别 | 规则 | 严重级别 |
|
|
297
|
+
|------|------|----------|
|
|
298
|
+
| `destructive-fs` | 递归删除根目录/home、通配符递归删除、chmod 777、格式化文件系统、dd 写入块设备 | critical / high |
|
|
299
|
+
| `code-execution` | curl 管道到 shell、wget 管道到 shell、eval() 动态输入、base64 解码执行 | critical / high |
|
|
300
|
+
| `credential-access` | 读取 .env 文件、访问私钥、访问 AWS 凭证、输出敏感环境变量 | high |
|
|
301
|
+
| `network-exfil` | curl POST 发送数据、向裸 IP 传输数据 | medium / high |
|
|
302
|
+
| `git-destructive` | git force push、git reset --hard、git clean -f | high / medium |
|
|
303
|
+
| `package-publish` | npm publish、pip/twine upload | medium |
|
|
304
|
+
| `system-config` | sudo 命令、iptables 修改、systemctl 服务控制 | medium |
|
|
305
|
+
| `file-delete` | 文件/目录删除 (rm) | medium |
|
|
306
|
+
| `file-write-outside` | 写入 /etc/、写入 /usr/ | low |
|
|
307
|
+
|
|
308
|
+
规则存储在 SQLite 中,可通过 Dashboard 管理(启用/禁用、添加自定义规则),无需重启。内置规则在首次启动时自动初始化,可单独禁用但不可删除。
|
|
309
|
+
|
|
310
|
+
支持桌面通知和 Webhook 告警(针对高严重级别匹配)。
|
|
311
|
+
|
|
312
|
+
在 `~/.bastion/config.yaml` 中配置:
|
|
313
|
+
```yaml
|
|
314
|
+
plugins:
|
|
315
|
+
toolGuard:
|
|
316
|
+
enabled: true
|
|
317
|
+
action: "audit" # audit | block
|
|
318
|
+
recordAll: true # 记录所有工具调用(不仅是标记的)
|
|
319
|
+
blockMinSeverity: "critical" # 阻断的最低严重级别(action=block 时生效)
|
|
320
|
+
alertMinSeverity: "high" # 告警的最低严重级别
|
|
321
|
+
alertDesktop: true # macOS 桌面通知
|
|
322
|
+
alertWebhookUrl: "" # Webhook URL(Slack、Discord 等)
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
### Token Optimizer
|
|
326
|
+
- **响应缓存** — 对相同请求进行精确匹配缓存(AES-256-GCM 加密)
|
|
327
|
+
- **空白压缩** — 折叠多余空白以节省 token
|
|
328
|
+
|
|
329
|
+
### Audit Logger
|
|
330
|
+
存储请求/响应内容(静态加密)以供在 Dashboard 中查看。可配置保留期限,自动清理。即使此 plugin 未启用,DLP 命中也会自动记录审计日志。
|
|
331
|
+
|
|
332
|
+
- **摘要** — 始终存储(可配置最大大小),在列表中显示为预览
|
|
333
|
+
- **原始数据** — 完整加密内容,默认启用,可禁用以节省空间
|
|
334
|
+
|
|
335
|
+
## 配置
|
|
336
|
+
|
|
337
|
+
默认配置:`config/default.yaml`。通过创建 `~/.bastion/config.yaml` 来覆盖:
|
|
338
|
+
|
|
339
|
+
```yaml
|
|
340
|
+
server:
|
|
341
|
+
host: "127.0.0.1"
|
|
342
|
+
port: 8420
|
|
343
|
+
|
|
344
|
+
logging:
|
|
345
|
+
level: "info" # debug | info | warn | error
|
|
346
|
+
|
|
347
|
+
plugins:
|
|
348
|
+
metrics:
|
|
349
|
+
enabled: true
|
|
350
|
+
dlp:
|
|
351
|
+
enabled: true
|
|
352
|
+
action: "block" # pass | warn | redact | block
|
|
353
|
+
patterns:
|
|
354
|
+
- "high-confidence"
|
|
355
|
+
- "validated"
|
|
356
|
+
- "context-aware"
|
|
357
|
+
remotePatterns:
|
|
358
|
+
url: ""
|
|
359
|
+
branch: "auto"
|
|
360
|
+
syncOnStart: true
|
|
361
|
+
syncIntervalMinutes: 0
|
|
362
|
+
aiValidation:
|
|
363
|
+
enabled: false
|
|
364
|
+
provider: "anthropic" # anthropic | openai
|
|
365
|
+
model: "claude-haiku-4-5-20241022"
|
|
366
|
+
apiKey: ""
|
|
367
|
+
timeoutMs: 5000
|
|
368
|
+
cacheSize: 500
|
|
369
|
+
semantics:
|
|
370
|
+
sensitivePatterns: []
|
|
371
|
+
nonSensitiveNames: []
|
|
372
|
+
optimizer:
|
|
373
|
+
enabled: true
|
|
374
|
+
cache: true
|
|
375
|
+
cacheTtlSeconds: 300
|
|
376
|
+
trimWhitespace: true
|
|
377
|
+
reorderForCache: true
|
|
378
|
+
audit:
|
|
379
|
+
enabled: true
|
|
380
|
+
retentionHours: 168 # 7 days
|
|
381
|
+
rawData: true # store full encrypted content
|
|
382
|
+
rawMaxBytes: 524288 # 512KB max per entry
|
|
383
|
+
summaryMaxBytes: 1024 # 1KB summary
|
|
384
|
+
toolGuard:
|
|
385
|
+
enabled: true
|
|
386
|
+
action: "audit" # audit | block
|
|
387
|
+
recordAll: true # 记录所有工具调用,不仅是标记的
|
|
388
|
+
blockMinSeverity: "critical" # 阻断的最低严重级别
|
|
389
|
+
alertMinSeverity: "high" # 告警的最低严重级别
|
|
390
|
+
alertDesktop: true
|
|
391
|
+
alertWebhookUrl: ""
|
|
392
|
+
|
|
393
|
+
timeouts:
|
|
394
|
+
upstream: 120000 # 2 minutes
|
|
395
|
+
plugin: 50 # 50ms per plugin
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
环境变量覆盖:
|
|
399
|
+
```bash
|
|
400
|
+
BASTION_PORT=9000 bastion start
|
|
401
|
+
BASTION_HOST=0.0.0.0 bastion start
|
|
402
|
+
BASTION_LOG_LEVEL=debug bastion start
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
## API
|
|
406
|
+
|
|
407
|
+
网关运行时,所有端点可通过 `http://127.0.0.1:8420` 访问。
|
|
408
|
+
|
|
409
|
+
| Method | Endpoint | Description |
|
|
410
|
+
|--------|----------|-------------|
|
|
411
|
+
| `GET` | `/api/stats` | Usage statistics (requests, tokens, cost). Query params: `session_id`, `api_key_hash`, `hours` |
|
|
412
|
+
| `GET` | `/api/sessions` | List tracked sessions |
|
|
413
|
+
| `GET` | `/api/dlp/recent?limit=50&since=ISO` | Recent DLP findings. `since` returns only newer findings (for polling) |
|
|
414
|
+
| `POST` | `/api/dlp/scan` | Standalone DLP scan (body: `{"text": "...", "action": "warn", "trace": true}`) |
|
|
415
|
+
| `GET` | `/api/dlp/patterns` | List all DLP patterns |
|
|
416
|
+
| `POST` | `/api/dlp/patterns` | Add custom pattern |
|
|
417
|
+
| `PUT` | `/api/dlp/patterns/:id` | Update pattern (toggle enabled, edit fields) |
|
|
418
|
+
| `DELETE` | `/api/dlp/patterns/:id` | Delete custom pattern (built-ins cannot be deleted) |
|
|
419
|
+
| `POST` | `/api/dlp/config/apply` | Batch-apply DLP config and record history |
|
|
420
|
+
| `GET` | `/api/dlp/config/history` | Last 10 DLP config changes |
|
|
421
|
+
| `POST` | `/api/dlp/config/restore/:id` | Restore a previous DLP config snapshot |
|
|
422
|
+
| `GET` | `/api/dlp/semantics/builtins` | Read-only built-in semantic rules |
|
|
423
|
+
| `GET` | `/api/dlp/signature` | Signature version info. `?check=true` to check remote for updates |
|
|
424
|
+
| `POST` | `/api/dlp/signature/sync` | Trigger manual sync of remote signature patterns |
|
|
425
|
+
| `GET` | `/api/audit/recent?limit=50` | Recent audit entries |
|
|
426
|
+
| `GET` | `/api/audit/sessions` | Audit sessions list |
|
|
427
|
+
| `GET` | `/api/audit/session/:id` | Parsed timeline for a session |
|
|
428
|
+
| `GET` | `/api/audit/:requestId` | Single request detail (parsed or summary-only fallback) |
|
|
429
|
+
| `GET` | `/api/tool-guard/recent?limit=50` | 最近的工具调用记录 |
|
|
430
|
+
| `GET` | `/api/tool-guard/stats` | 按严重级别、类别、工具名称统计 |
|
|
431
|
+
| `GET` | `/api/tool-guard/session/:id` | 指定会话的工具调用 |
|
|
432
|
+
| `GET` | `/api/tool-guard/rules` | 列出所有规则(内置 + 自定义) |
|
|
433
|
+
| `POST` | `/api/tool-guard/rules` | 添加自定义规则 |
|
|
434
|
+
| `PUT` | `/api/tool-guard/rules/:id` | 更新规则(切换启用、编辑字段) |
|
|
435
|
+
| `DELETE` | `/api/tool-guard/rules/:id` | 删除自定义规则(内置规则不可删除) |
|
|
436
|
+
| `GET` | `/api/tool-guard/alerts` | 最近告警及未确认数量 |
|
|
437
|
+
| `POST` | `/api/tool-guard/alerts/ack` | 确认所有告警 |
|
|
438
|
+
| `GET` | `/api/optimizer/stats` | Cache hit rate and tokens saved |
|
|
439
|
+
| `GET` | `/api/optimizer/recent?limit=50` | Recent optimizer events |
|
|
440
|
+
| `GET` | `/api/config` | Current configuration + plugin status |
|
|
441
|
+
| `PUT` | `/api/config` | Update configuration at runtime |
|
|
442
|
+
|
|
443
|
+
## 文档
|
|
444
|
+
|
|
445
|
+
- [DLP 引擎架构](docs/dlp.zh.md) — 5 层检测管线详解
|
|
446
|
+
- [OpenClaw Docker 集成](docs/openclaw-docker.zh.md) — Docker Compose 配置(全新安装 + 已有环境)
|
|
447
|
+
- [OpenClaw 本地安装](docs/openclaw-local.zh.md) — 使用 Bastion 代理原生运行 OpenClaw
|
|
448
|
+
- [AI Agent 监控](docs/agent-monitoring.zh.md) — 监控任何本地 AI Agent(Claude Code、Cursor、自定义应用)
|
|
449
|
+
- [远程签名库](docs/remote-signatures.zh.md) — 从 Git 仓库远程同步 DLP 模式
|
|
450
|
+
- [OpenClaw DLP 告警 Skill](docs/openclaw-dlp-skill.zh.md) — 让 OpenClaw 通过 Telegram/Discord 通知 DLP 发现
|
|
451
|
+
- [安全调研](docs/security-research.zh.md) — AI Agent 威胁态势、Bastion 能力分析与路线图
|
|
452
|
+
- [Windows 故障排除](docs/windows-troubleshooting.zh.md) — Windows 常见问题及解决方案
|
|
453
|
+
|
|
454
|
+
## 数据存储
|
|
455
|
+
|
|
456
|
+
所有数据存储在本地 `~/.bastion/` 目录下:
|
|
457
|
+
|
|
458
|
+
```
|
|
459
|
+
~/.bastion/
|
|
460
|
+
bastion.db # SQLite database (metrics, cache, DLP events, audit log)
|
|
461
|
+
config.yaml # User config overrides (created by bastion proxy on / dashboard settings)
|
|
462
|
+
ca.key # CA private key
|
|
463
|
+
ca.crt # CA certificate
|
|
464
|
+
certs/ # Generated host certificates
|
|
465
|
+
.key # AES encryption key for cache & audit
|
|
466
|
+
bastion.pid # Daemon PID file
|
|
467
|
+
bastion.log # Daemon log file
|
|
468
|
+
```
|