@aporthq/aport-agent-guardrails 1.0.8

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.
Files changed (237) hide show
  1. package/LICENSE +217 -0
  2. package/README.md +481 -0
  3. package/bin/agent-guardrails +133 -0
  4. package/bin/aport-create-passport.sh +444 -0
  5. package/bin/aport-cursor-hook.sh +90 -0
  6. package/bin/aport-guardrail-api.sh +108 -0
  7. package/bin/aport-guardrail-bash.sh +394 -0
  8. package/bin/aport-guardrail-v2.sh +5 -0
  9. package/bin/aport-guardrail.sh +5 -0
  10. package/bin/aport-resolve-paths.sh +71 -0
  11. package/bin/aport-status.sh +276 -0
  12. package/bin/frameworks/crewai.sh +49 -0
  13. package/bin/frameworks/cursor.sh +95 -0
  14. package/bin/frameworks/langchain.sh +48 -0
  15. package/bin/frameworks/n8n.sh +36 -0
  16. package/bin/frameworks/openclaw.sh +19 -0
  17. package/bin/lib/allowlist.sh +18 -0
  18. package/bin/lib/common.sh +28 -0
  19. package/bin/lib/config.sh +46 -0
  20. package/bin/lib/constants.sh +232 -0
  21. package/bin/lib/detect.sh +65 -0
  22. package/bin/lib/error.sh +269 -0
  23. package/bin/lib/passport.sh +19 -0
  24. package/bin/lib/templates/.gitkeep +1 -0
  25. package/bin/lib/templates/config.yaml +6 -0
  26. package/bin/lib/validation.sh +206 -0
  27. package/bin/openclaw +660 -0
  28. package/docs/ADDING_A_FRAMEWORK.md +87 -0
  29. package/docs/AGENTS.md.example +40 -0
  30. package/docs/CODE_REVIEW.md +192 -0
  31. package/docs/DEPLOYMENT_READINESS.md +81 -0
  32. package/docs/FAQ_SECURITY_SCANNERS.md +373 -0
  33. package/docs/FRAMEWORK_ROADMAP.md +41 -0
  34. package/docs/HOSTED_PASSPORT_SETUP.md +362 -0
  35. package/docs/IMPLEMENTING_YOUR_OWN_EVALUATOR.md +433 -0
  36. package/docs/OPENCLAW_COMPATIBILITY.md +73 -0
  37. package/docs/OPENCLAW_LOCAL_INTEGRATION.md +596 -0
  38. package/docs/OPENCLAW_TOOLS_AND_POLICIES.md +54 -0
  39. package/docs/QUICKSTART.md +470 -0
  40. package/docs/QUICKSTART_OPENCLAW_PLUGIN.md +470 -0
  41. package/docs/README.md +28 -0
  42. package/docs/RELEASE.md +87 -0
  43. package/docs/REPO_LAYOUT.md +47 -0
  44. package/docs/SKILLS_ECOSYSTEM_ANALYSIS_FEB17.md +1260 -0
  45. package/docs/TOOL_POLICY_MAPPING.md +46 -0
  46. package/docs/UPGRADE.md +46 -0
  47. package/docs/VERIFICATION_METHODS.md +97 -0
  48. package/docs/assets/README.md +8 -0
  49. package/docs/assets/porter.svg +54 -0
  50. package/docs/development/ERROR_CODES.md +616 -0
  51. package/docs/frameworks/GITHUB_ISSUE_PROPOSALS.md +1105 -0
  52. package/docs/frameworks/crewai.md +114 -0
  53. package/docs/frameworks/cursor.md +159 -0
  54. package/docs/frameworks/langchain.md +72 -0
  55. package/docs/frameworks/n8n.md +40 -0
  56. package/docs/frameworks/openclaw.md +40 -0
  57. package/docs/launch/ADD_APORT_AWESOME_LISTS_INSTRUCTIONS.md +146 -0
  58. package/docs/launch/ANNOUNCEMENT_GUIDE.md +266 -0
  59. package/docs/launch/AWESOME_REPOS.md +53 -0
  60. package/docs/launch/CURSOR_VSCODE_HOOKS_RESEARCH.md +77 -0
  61. package/docs/launch/DEMO_TERMINAL_OUTPUT.txt +48 -0
  62. package/docs/launch/DRY_AND_PLAN_CHECKLIST.md +47 -0
  63. package/docs/launch/EVIDENCE_README.md +61 -0
  64. package/docs/launch/EVIDENCE_TERMINAL_CAPTURE.txt +10 -0
  65. package/docs/launch/FRAMEWORK_SUPPORT_PLAN.md +1640 -0
  66. package/docs/launch/LAUNCH_READINESS_CHECKLIST.md +237 -0
  67. package/docs/launch/LAUNCH_STRATEGY_SUMMARY.md +464 -0
  68. package/docs/launch/OPENCLAW_FEEDBACK_AND_FIXES.md +85 -0
  69. package/docs/launch/POST_1_VALENTINE_IMPROVED.md +233 -0
  70. package/docs/launch/POST_2_GUARDRAIL_IMPROVED.md +369 -0
  71. package/docs/launch/PRE_LAUNCH_FIXES.md +766 -0
  72. package/docs/launch/QUICK_LAUNCH_CHECKLIST.md +400 -0
  73. package/docs/launch/READINESS_SUMMARY.md +262 -0
  74. package/docs/launch/README.md +68 -0
  75. package/docs/launch/USER_STORIES.md +327 -0
  76. package/docs/launch/scripts/add-aport-awesome-pr.sh +69 -0
  77. package/docs/operations/MONITORING.md +588 -0
  78. package/docs/reviews/2026-02-18-staff-review.md +268 -0
  79. package/extensions/openclaw-aport/README.md +415 -0
  80. package/extensions/openclaw-aport/index.js +625 -0
  81. package/extensions/openclaw-aport/openclaw-aport.js +7 -0
  82. package/extensions/openclaw-aport/openclaw.plugin.json +46 -0
  83. package/extensions/openclaw-aport/package.json +36 -0
  84. package/extensions/openclaw-aport/test.js +307 -0
  85. package/external/aport-policies/README.md +363 -0
  86. package/external/aport-policies/agent.session.create.v1/README.md +345 -0
  87. package/external/aport-policies/agent.session.create.v1/policy.json +162 -0
  88. package/external/aport-policies/agent.tool.register.v1/README.md +361 -0
  89. package/external/aport-policies/agent.tool.register.v1/policy.json +172 -0
  90. package/external/aport-policies/code.release.publish.v1/README.md +51 -0
  91. package/external/aport-policies/code.release.publish.v1/policy.json +121 -0
  92. package/external/aport-policies/code.repository.merge.v1/README.md +287 -0
  93. package/external/aport-policies/code.repository.merge.v1/express.example.js +332 -0
  94. package/external/aport-policies/code.repository.merge.v1/fastapi.example.py +370 -0
  95. package/external/aport-policies/code.repository.merge.v1/policy.json +162 -0
  96. package/external/aport-policies/data.export.create.v1/README.md +226 -0
  97. package/external/aport-policies/data.export.create.v1/express.example.js +172 -0
  98. package/external/aport-policies/data.export.create.v1/fastapi.example.py +165 -0
  99. package/external/aport-policies/data.export.create.v1/policy.json +133 -0
  100. package/external/aport-policies/data.report.ingest.v1/README.md +134 -0
  101. package/external/aport-policies/data.report.ingest.v1/express.example.js +105 -0
  102. package/external/aport-policies/data.report.ingest.v1/minimal-example.js +68 -0
  103. package/external/aport-policies/data.report.ingest.v1/policy.json +174 -0
  104. package/external/aport-policies/finance.crypto.trade.v1/README.md +146 -0
  105. package/external/aport-policies/finance.crypto.trade.v1/express.example.js +109 -0
  106. package/external/aport-policies/finance.crypto.trade.v1/minimal-example.js +65 -0
  107. package/external/aport-policies/finance.crypto.trade.v1/policy.json +176 -0
  108. package/external/aport-policies/finance.payment.charge.v1/README.md +326 -0
  109. package/external/aport-policies/finance.payment.charge.v1/express.example.js +250 -0
  110. package/external/aport-policies/finance.payment.charge.v1/fastapi.example.py +227 -0
  111. package/external/aport-policies/finance.payment.charge.v1/minimal-example.js +64 -0
  112. package/external/aport-policies/finance.payment.charge.v1/policy.json +224 -0
  113. package/external/aport-policies/finance.payment.charge.v1/tests/contexts.jsonl +12 -0
  114. package/external/aport-policies/finance.payment.charge.v1/tests/expected.jsonl +12 -0
  115. package/external/aport-policies/finance.payment.charge.v1/tests/passport.instance.json +42 -0
  116. package/external/aport-policies/finance.payment.charge.v1/tests/passport.template.json +40 -0
  117. package/external/aport-policies/finance.payment.charge.v1/tests/payments-charge-policy.test.js +817 -0
  118. package/external/aport-policies/finance.payment.charge.v1/tests/test_payments_charge_policy.py +486 -0
  119. package/external/aport-policies/finance.payment.payout.v1/README.md +78 -0
  120. package/external/aport-policies/finance.payment.payout.v1/policy.json +181 -0
  121. package/external/aport-policies/finance.payment.refund.v1/README.md +275 -0
  122. package/external/aport-policies/finance.payment.refund.v1/express.example.js +167 -0
  123. package/external/aport-policies/finance.payment.refund.v1/fastapi.example.py +136 -0
  124. package/external/aport-policies/finance.payment.refund.v1/minimal-example.js +183 -0
  125. package/external/aport-policies/finance.payment.refund.v1/policy.json +216 -0
  126. package/external/aport-policies/finance.payment.refund.v1/tests/refunds-policy.test.js +924 -0
  127. package/external/aport-policies/finance.payment.refund.v1/tests/test_refunds_policy.py +778 -0
  128. package/external/aport-policies/finance.transaction.execute.v1/README.md +309 -0
  129. package/external/aport-policies/finance.transaction.execute.v1/express.example.js +261 -0
  130. package/external/aport-policies/finance.transaction.execute.v1/fastapi.example.py +231 -0
  131. package/external/aport-policies/finance.transaction.execute.v1/minimal-example.js +78 -0
  132. package/external/aport-policies/finance.transaction.execute.v1/policy.json +189 -0
  133. package/external/aport-policies/finance.transaction.execute.v1/tests/contexts.jsonl +12 -0
  134. package/external/aport-policies/finance.transaction.execute.v1/tests/expected.jsonl +12 -0
  135. package/external/aport-policies/finance.transaction.execute.v1/tests/passport.instance.json +42 -0
  136. package/external/aport-policies/finance.transaction.execute.v1/tests/passport.template.json +42 -0
  137. package/external/aport-policies/finance.transaction.execute.v1/tests/test_transactions_policy.py +214 -0
  138. package/external/aport-policies/finance.transaction.execute.v1/tests/transactions-policy.test.js +306 -0
  139. package/external/aport-policies/governance.data.access.v1/README.md +292 -0
  140. package/external/aport-policies/governance.data.access.v1/express.example.js +321 -0
  141. package/external/aport-policies/governance.data.access.v1/fastapi.example.py +279 -0
  142. package/external/aport-policies/governance.data.access.v1/minimal-example.js +65 -0
  143. package/external/aport-policies/governance.data.access.v1/policy.json +208 -0
  144. package/external/aport-policies/governance.data.access.v1/tests/contexts.jsonl +12 -0
  145. package/external/aport-policies/governance.data.access.v1/tests/data-access-policy.test.js +308 -0
  146. package/external/aport-policies/governance.data.access.v1/tests/expected.jsonl +12 -0
  147. package/external/aport-policies/governance.data.access.v1/tests/passport.instance.json +56 -0
  148. package/external/aport-policies/governance.data.access.v1/tests/passport.template.json +56 -0
  149. package/external/aport-policies/governance.data.access.v1/tests/test_data_access_policy.py +214 -0
  150. package/external/aport-policies/legal.contract.review.v1/README.md +109 -0
  151. package/external/aport-policies/legal.contract.review.v1/policy.json +378 -0
  152. package/external/aport-policies/legal.contract.review.v1/tests/legal-contract-review-policy.test.js +609 -0
  153. package/external/aport-policies/legal.contract.review.v1/tests/passport.template.json +49 -0
  154. package/external/aport-policies/mcp.tool.execute.v1/README.md +301 -0
  155. package/external/aport-policies/mcp.tool.execute.v1/policy.json +141 -0
  156. package/external/aport-policies/messaging.message.send.v1/README.md +230 -0
  157. package/external/aport-policies/messaging.message.send.v1/express.example.js +183 -0
  158. package/external/aport-policies/messaging.message.send.v1/fastapi.example.py +193 -0
  159. package/external/aport-policies/messaging.message.send.v1/policy.json +144 -0
  160. package/external/aport-policies/policy-template.json +107 -0
  161. package/external/aport-policies/system.command.execute.v1/README.md +275 -0
  162. package/external/aport-policies/system.command.execute.v1/policy.json +146 -0
  163. package/external/aport-spec/CONTRIBUTING.md +273 -0
  164. package/external/aport-spec/LICENSE +21 -0
  165. package/external/aport-spec/README.md +168 -0
  166. package/external/aport-spec/conformance/README.md +294 -0
  167. package/external/aport-spec/conformance/cases/data.export.v1/contexts/allow_users.json +6 -0
  168. package/external/aport-spec/conformance/cases/data.export.v1/contexts/deny_pii.json +6 -0
  169. package/external/aport-spec/conformance/cases/data.export.v1/expected/allow_users.decision.json +19 -0
  170. package/external/aport-spec/conformance/cases/data.export.v1/expected/deny_pii.decision.json +19 -0
  171. package/external/aport-spec/conformance/cases/data.export.v1/passports/template.json +29 -0
  172. package/external/aport-spec/conformance/cases/payments.refunds.v1/contexts/allow_50usd.json +9 -0
  173. package/external/aport-spec/conformance/cases/payments.refunds.v1/contexts/deny_150usd.json +9 -0
  174. package/external/aport-spec/conformance/cases/payments.refunds.v1/contexts/deny_currency.json +9 -0
  175. package/external/aport-spec/conformance/cases/payments.refunds.v1/expected/allow_50usd.decision.json +19 -0
  176. package/external/aport-spec/conformance/cases/payments.refunds.v1/expected/deny_150usd.decision.json +19 -0
  177. package/external/aport-spec/conformance/cases/payments.refunds.v1/expected/deny_currency.decision.json +19 -0
  178. package/external/aport-spec/conformance/cases/payments.refunds.v1/passports/template.json +42 -0
  179. package/external/aport-spec/conformance/package.json +44 -0
  180. package/external/aport-spec/conformance/pnpm-lock.yaml +642 -0
  181. package/external/aport-spec/conformance/src/cases.ts +371 -0
  182. package/external/aport-spec/conformance/src/ed25519.ts +167 -0
  183. package/external/aport-spec/conformance/src/jcs.ts +85 -0
  184. package/external/aport-spec/conformance/src/runner.ts +533 -0
  185. package/external/aport-spec/conformance/src/validators.ts +185 -0
  186. package/external/aport-spec/conformance/test-runner.js +315 -0
  187. package/external/aport-spec/conformance/tsconfig.json +21 -0
  188. package/external/aport-spec/error-schema.json +192 -0
  189. package/external/aport-spec/index.json +12 -0
  190. package/external/aport-spec/integrations/clawmoat/README.md +12 -0
  191. package/external/aport-spec/integrations/shield/README.md +245 -0
  192. package/external/aport-spec/integrations/shield/adapters/index.js +116 -0
  193. package/external/aport-spec/integrations/shield/adapters/system-command-execute.js +133 -0
  194. package/external/aport-spec/integrations/shield/test/README.md +58 -0
  195. package/external/aport-spec/integrations/shield/test/shield.md +40 -0
  196. package/external/aport-spec/integrations/shield/test/test-shield-to-verify.js +274 -0
  197. package/external/aport-spec/metrics-schema.json +504 -0
  198. package/external/aport-spec/oap/CHANGELOG.md +54 -0
  199. package/external/aport-spec/oap/VERSION.md +40 -0
  200. package/external/aport-spec/oap/capability-registry.md +229 -0
  201. package/external/aport-spec/oap/conformance.md +257 -0
  202. package/external/aport-spec/oap/decision-schema.json +114 -0
  203. package/external/aport-spec/oap/examples/context.refund.usd.50.json +9 -0
  204. package/external/aport-spec/oap/examples/decision.allow.sample.json +20 -0
  205. package/external/aport-spec/oap/examples/decision.deny.sample.json +23 -0
  206. package/external/aport-spec/oap/examples/passport.instance.v1.json +50 -0
  207. package/external/aport-spec/oap/examples/passport.template.v1.json +71 -0
  208. package/external/aport-spec/oap/oap-spec.md +426 -0
  209. package/external/aport-spec/oap/passport-schema.json +396 -0
  210. package/external/aport-spec/oap/security.md +213 -0
  211. package/external/aport-spec/oap/vc/context-oap-v1.jsonld +137 -0
  212. package/external/aport-spec/oap/vc/examples/oap-decision-vc.json +37 -0
  213. package/external/aport-spec/oap/vc/examples/oap-passport-vc.json +68 -0
  214. package/external/aport-spec/oap/vc/tools/INTEGRATION.md +375 -0
  215. package/external/aport-spec/oap/vc/tools/README.md +278 -0
  216. package/external/aport-spec/oap/vc/tools/examples/decision-to-vc.js +66 -0
  217. package/external/aport-spec/oap/vc/tools/examples/passport-to-vc.js +83 -0
  218. package/external/aport-spec/oap/vc/tools/examples/vc-to-decision.js +77 -0
  219. package/external/aport-spec/oap/vc/tools/examples/vc-to-passport.js +94 -0
  220. package/external/aport-spec/oap/vc/tools/package.json +38 -0
  221. package/external/aport-spec/oap/vc/tools/pnpm-lock.yaml +472 -0
  222. package/external/aport-spec/oap/vc/tools/src/cli.ts +226 -0
  223. package/external/aport-spec/oap/vc/tools/src/crypto-utils.ts +427 -0
  224. package/external/aport-spec/oap/vc/tools/src/index.ts +653 -0
  225. package/external/aport-spec/oap/vc/tools/src/test.ts +148 -0
  226. package/external/aport-spec/oap/vc/tools/src/vp.ts +382 -0
  227. package/external/aport-spec/oap/vc/tools/test-simple.js +214 -0
  228. package/external/aport-spec/oap/vc/tools/tsconfig.json +19 -0
  229. package/external/aport-spec/oap/vc/vc-mapping.md +443 -0
  230. package/external/aport-spec/passport-schema.json +586 -0
  231. package/external/aport-spec/rate-limiting.md +136 -0
  232. package/external/aport-spec/transport-profile.md +325 -0
  233. package/external/aport-spec/webhook-spec.md +314 -0
  234. package/package.json +70 -0
  235. package/skills/aport-agent-guardrail/SKILL.md +314 -0
  236. package/src/evaluator.js +252 -0
  237. package/src/server/index.js +72 -0
@@ -0,0 +1,588 @@
1
+ # Monitoring & Alerting Guide
2
+
3
+ This guide covers monitoring, metrics, logging, and alerting for APort Agent Guardrails in production environments.
4
+
5
+ ## Table of Contents
6
+
7
+ - [Overview](#overview)
8
+ - [Key Metrics](#key-metrics)
9
+ - [Logging](#logging)
10
+ - [Alerting Thresholds](#alerting-thresholds)
11
+ - [Example Dashboards](#example-dashboards)
12
+ - [Example Alert Rules](#example-alert-rules)
13
+ - [Troubleshooting](#troubleshooting)
14
+
15
+ ---
16
+
17
+ ## Overview
18
+
19
+ ### Monitoring Architecture
20
+
21
+ ```
22
+ ┌─────────────────┐
23
+ │ AI Agent │
24
+ │ (LangChain, │
25
+ │ CrewAI, etc) │
26
+ └────────┬────────┘
27
+
28
+
29
+ ┌─────────────────┐ ┌──────────────┐
30
+ │ APort Guardrail │──────▶│ Audit Log │
31
+ │ Evaluator │ │ (JSON/text) │
32
+ └────────┬────────┘ └──────────────┘
33
+
34
+ ├──────▶ Metrics (Prometheus/StatsD)
35
+ ├──────▶ Logs (stdout/file/syslog)
36
+ └──────▶ Traces (OpenTelemetry)
37
+ ```
38
+
39
+ ### Observability Pillars
40
+
41
+ 1. **Metrics**: Quantitative measurements (latency, throughput, errors)
42
+ 2. **Logs**: Detailed event records (decisions, denials, errors)
43
+ 3. **Traces**: Distributed request tracking (coming soon)
44
+ 4. **Audit Trail**: Security events for compliance
45
+
46
+ ---
47
+
48
+ ## Key Metrics
49
+
50
+ ### Authorization Metrics
51
+
52
+ #### `aport_authorization_decisions_total`
53
+ **Type**: Counter
54
+ **Labels**: `result=[allow|deny]`, `policy_pack`, `agent_id`, `tool_name`
55
+ **Description**: Total number of authorization decisions
56
+
57
+ **Alert**: Spike in denials may indicate attack or misconfiguration
58
+
59
+ ```promql
60
+ # Rate of denials
61
+ rate(aport_authorization_decisions_total{result="deny"}[5m])
62
+ ```
63
+
64
+ #### `aport_authorization_duration_seconds`
65
+ **Type**: Histogram
66
+ **Labels**: `policy_pack`, `agent_id`, `mode=[local|api]`
67
+ **Description**: Authorization decision latency
68
+
69
+ **Alert**: High latency affects agent performance
70
+
71
+ ```promql
72
+ # P95 latency
73
+ histogram_quantile(0.95, rate(aport_authorization_duration_seconds_bucket[5m]))
74
+ ```
75
+
76
+ #### `aport_policy_evaluation_errors_total`
77
+ **Type**: Counter
78
+ **Labels**: `policy_pack`, `error_code`
79
+ **Description**: Policy evaluation errors
80
+
81
+ **Alert**: Errors may indicate policy bugs
82
+
83
+ ```promql
84
+ # Error rate
85
+ rate(aport_policy_evaluation_errors_total[5m])
86
+ ```
87
+
88
+ ### Performance Metrics
89
+
90
+ #### `aport_passport_load_duration_seconds`
91
+ **Type**: Histogram
92
+ **Description**: Time to load and validate passport
93
+
94
+ ```promql
95
+ # Slow passport loads
96
+ histogram_quantile(0.95, rate(aport_passport_load_duration_seconds_bucket[5m])) > 0.1
97
+ ```
98
+
99
+ #### `aport_policy_load_duration_seconds`
100
+ **Type**: Histogram
101
+ **Labels**: `policy_pack`
102
+ **Description**: Time to load policy pack
103
+
104
+ #### `aport_subprocess_call_duration_seconds`
105
+ **Type**: Histogram
106
+ **Description**: Subprocess call duration (bash guardrail)
107
+
108
+ ### API Metrics
109
+
110
+ #### `aport_api_requests_total`
111
+ **Type**: Counter
112
+ **Labels**: `endpoint`, `status_code`, `agent_id`
113
+ **Description**: Total API requests to APort API
114
+
115
+ ```promql
116
+ # API error rate
117
+ rate(aport_api_requests_total{status_code=~"5.."}[5m])
118
+ ```
119
+
120
+ #### `aport_api_request_duration_seconds`
121
+ **Type**: Histogram
122
+ **Labels**: `endpoint`
123
+ **Description**: API request latency
124
+
125
+ #### `aport_api_rate_limit_exceeded_total`
126
+ **Type**: Counter
127
+ **Labels**: `agent_id`
128
+ **Description**: Rate limit exceeded events
129
+
130
+ **Alert**: High rate limiting may indicate misconfiguration or attack
131
+
132
+ ### Cache Metrics
133
+
134
+ #### `aport_cache_hits_total`
135
+ **Type**: Counter
136
+ **Labels**: `cache_type=[passport|policy|config]`
137
+ **Description**: Cache hits
138
+
139
+ #### `aport_cache_misses_total`
140
+ **Type**: Counter
141
+ **Labels**: `cache_type=[passport|policy|config]`
142
+ **Description**: Cache misses
143
+
144
+ **Useful**: Cache hit rate
145
+ ```promql
146
+ sum(rate(aport_cache_hits_total[5m])) / (sum(rate(aport_cache_hits_total[5m])) + sum(rate(aport_cache_misses_total[5m])))
147
+ ```
148
+
149
+ ### Security Metrics
150
+
151
+ #### `aport_security_events_total`
152
+ **Type**: Counter
153
+ **Labels**: `event_type=[command_injection|path_traversal|validation_failure]`, `agent_id`
154
+ **Description**: Security events detected
155
+
156
+ **Alert**: Security events require immediate investigation
157
+
158
+ ```promql
159
+ # Command injection attempts
160
+ rate(aport_security_events_total{event_type="command_injection"}[5m]) > 0
161
+ ```
162
+
163
+ #### `aport_passport_validation_failures_total`
164
+ **Type**: Counter
165
+ **Labels**: `reason=[expired|revoked|invalid|missing_capability]`
166
+ **Description**: Passport validation failures
167
+
168
+ ---
169
+
170
+ ## Logging
171
+
172
+ ### Log Levels
173
+
174
+ - **DEBUG**: All operations, including context data (use with caution)
175
+ - **INFO**: Authorization decisions, policy loads, cache operations
176
+ - **WARN**: Rate limits, slow operations, deprecations
177
+ - **ERROR**: Failures, exceptions, security events
178
+
179
+ ### Log Format
180
+
181
+ #### Text Format (Default)
182
+ ```
183
+ 2026-02-19T10:30:00Z [INFO] [evaluator] Authorization decision: tool=system.command.execute agent_id=ap_abc123 decision=ALLOW policy=system.command.execute.v1 latency=47ms request_id=req_123
184
+ ```
185
+
186
+ #### JSON Format (Structured)
187
+ ```json
188
+ {
189
+ "timestamp": "2026-02-19T10:30:00.123Z",
190
+ "level": "INFO",
191
+ "component": "evaluator",
192
+ "event": "authorization_decision",
193
+ "agent_id": "ap_abc123",
194
+ "tool_name": "system.command.execute",
195
+ "decision": "ALLOW",
196
+ "policy_pack": "system.command.execute.v1",
197
+ "latency_ms": 47,
198
+ "request_id": "req_xyz789"
199
+ }
200
+ ```
201
+
202
+ ### Configuration
203
+
204
+ **Environment Variables**:
205
+ - `APORT_LOG_LEVEL`: DEBUG, INFO, WARN, ERROR (default: INFO)
206
+ - `APORT_LOG_FORMAT`: text, json (default: text)
207
+ - `APORT_STRUCTURED_LOGGING`: Enable JSON logging (0/1)
208
+
209
+ ### Important Events to Monitor
210
+
211
+ #### Authorization Denials
212
+ ```json
213
+ {
214
+ "event": "authorization_denied",
215
+ "policy_pack": "system.command.execute.v1",
216
+ "reason": "Command not in allowed list",
217
+ "command": "rm -rf /",
218
+ "agent_id": "ap_abc123"
219
+ }
220
+ ```
221
+
222
+ #### Security Events
223
+ ```json
224
+ {
225
+ "event": "security_event",
226
+ "event_type": "command_injection_detected",
227
+ "input": "rm; malicious",
228
+ "agent_id": "ap_abc123",
229
+ "blocked": true
230
+ }
231
+ ```
232
+
233
+ #### Slow Operations
234
+ ```json
235
+ {
236
+ "event": "slow_operation",
237
+ "operation": "policy_evaluation",
238
+ "latency_ms": 523,
239
+ "threshold_ms": 200,
240
+ "policy_pack": "system.command.execute.v1"
241
+ }
242
+ ```
243
+
244
+ ---
245
+
246
+ ## Alerting Thresholds
247
+
248
+ ### Critical Alerts
249
+
250
+ #### High Error Rate
251
+ **Condition**: Error rate > 5% for 5 minutes
252
+ **Severity**: P1 (Critical)
253
+ **Action**: Investigate immediately
254
+
255
+ ```promql
256
+ (sum(rate(aport_authorization_decisions_total{result="error"}[5m])) /
257
+ sum(rate(aport_authorization_decisions_total[5m]))) > 0.05
258
+ ```
259
+
260
+ #### Security Event Detected
261
+ **Condition**: Any command injection or path traversal attempt
262
+ **Severity**: P1 (Critical)
263
+ **Action**: Security team investigation
264
+
265
+ ```promql
266
+ rate(aport_security_events_total{event_type=~"command_injection|path_traversal"}[5m]) > 0
267
+ ```
268
+
269
+ #### API Down
270
+ **Condition**: API error rate > 50% for 2 minutes
271
+ **Severity**: P1 (Critical)
272
+ **Action**: Check API status, failover to local mode
273
+
274
+ ```promql
275
+ (sum(rate(aport_api_requests_total{status_code=~"5.."}[2m])) /
276
+ sum(rate(aport_api_requests_total[2m]))) > 0.5
277
+ ```
278
+
279
+ ### High Priority Alerts
280
+
281
+ #### High Denial Rate
282
+ **Condition**: Denial rate > 20% for 15 minutes
283
+ **Severity**: P2 (High)
284
+ **Action**: Check for policy misconfiguration or legitimate threats
285
+
286
+ ```promql
287
+ (sum(rate(aport_authorization_decisions_total{result="deny"}[15m])) /
288
+ sum(rate(aport_authorization_decisions_total[15m]))) > 0.2
289
+ ```
290
+
291
+ #### High Latency
292
+ **Condition**: P95 latency > 500ms for 10 minutes
293
+ **Severity**: P2 (High)
294
+ **Action**: Check system load, optimize policies
295
+
296
+ ```promql
297
+ histogram_quantile(0.95, rate(aport_authorization_duration_seconds_bucket[10m])) > 0.5
298
+ ```
299
+
300
+ #### Rate Limiting Active
301
+ **Condition**: Rate limit hits > 10/minute per agent
302
+ **Severity**: P2 (High)
303
+ **Action**: Investigate agent behavior, adjust limits if legitimate
304
+
305
+ ```promql
306
+ rate(aport_api_rate_limit_exceeded_total[1m]) > 10
307
+ ```
308
+
309
+ ### Medium Priority Alerts
310
+
311
+ #### Cache Hit Rate Low
312
+ **Condition**: Cache hit rate < 80% for 30 minutes
313
+ **Severity**: P3 (Medium)
314
+ **Action**: Review cache TTL configuration
315
+
316
+ ```promql
317
+ (sum(rate(aport_cache_hits_total[30m])) /
318
+ (sum(rate(aport_cache_hits_total[30m])) + sum(rate(aport_cache_misses_total[30m])))) < 0.8
319
+ ```
320
+
321
+ #### Passport Validation Failures
322
+ **Condition**: > 5 passport failures per hour
323
+ **Severity**: P3 (Medium)
324
+ **Action**: Check for expired passports
325
+
326
+ ```promql
327
+ rate(aport_passport_validation_failures_total[1h]) > 5
328
+ ```
329
+
330
+ ---
331
+
332
+ ## Example Dashboards
333
+
334
+ ### Grafana Dashboard
335
+
336
+ #### Overview Panel
337
+ - **Total Decisions** (gauge): `sum(aport_authorization_decisions_total)`
338
+ - **Allow/Deny Rate** (time series): `rate(aport_authorization_decisions_total[5m]) by (result)`
339
+ - **P95 Latency** (gauge): `histogram_quantile(0.95, rate(aport_authorization_duration_seconds_bucket[5m]))`
340
+
341
+ #### Performance Panel
342
+ - **Latency Distribution** (heatmap): `aport_authorization_duration_seconds`
343
+ - **Throughput** (time series): `sum(rate(aport_authorization_decisions_total[5m]))`
344
+ - **Cache Hit Rate** (gauge)
345
+
346
+ #### Security Panel
347
+ - **Security Events** (time series): `rate(aport_security_events_total[5m]) by (event_type)`
348
+ - **Top Denied Agents** (table): `topk(10, sum by (agent_id) (aport_authorization_decisions_total{result="deny"}))`
349
+
350
+ #### API Panel
351
+ - **API Error Rate** (time series): `rate(aport_api_requests_total{status_code=~"5.."}[5m])`
352
+ - **API Latency** (time series): `histogram_quantile(0.95, rate(aport_api_request_duration_seconds_bucket[5m]))`
353
+
354
+ ### Example Grafana JSON
355
+ ```json
356
+ {
357
+ "dashboard": {
358
+ "title": "APort Agent Guardrails",
359
+ "panels": [
360
+ {
361
+ "title": "Authorization Decisions",
362
+ "targets": [{
363
+ "expr": "sum(rate(aport_authorization_decisions_total[5m])) by (result)"
364
+ }]
365
+ },
366
+ {
367
+ "title": "P95 Latency",
368
+ "targets": [{
369
+ "expr": "histogram_quantile(0.95, rate(aport_authorization_duration_seconds_bucket[5m]))"
370
+ }]
371
+ }
372
+ ]
373
+ }
374
+ }
375
+ ```
376
+
377
+ ---
378
+
379
+ ## Example Alert Rules
380
+
381
+ ### Prometheus AlertManager Rules
382
+
383
+ ```yaml
384
+ groups:
385
+ - name: aport_guardrails
386
+ interval: 30s
387
+ rules:
388
+ - alert: APortHighErrorRate
389
+ expr: |
390
+ (sum(rate(aport_authorization_decisions_total{result="error"}[5m])) /
391
+ sum(rate(aport_authorization_decisions_total[5m]))) > 0.05
392
+ for: 5m
393
+ labels:
394
+ severity: critical
395
+ annotations:
396
+ summary: "APort guardrail error rate is high"
397
+ description: "Error rate is {{ $value | humanizePercentage }}. Investigate immediately."
398
+ runbook_url: "https://github.com/aporthq/aport-agent-guardrails/blob/main/docs/operations/RUNBOOK.md#high-error-rate"
399
+
400
+ - alert: APortSecurityEvent
401
+ expr: rate(aport_security_events_total[5m]) > 0
402
+ for: 1m
403
+ labels:
404
+ severity: critical
405
+ annotations:
406
+ summary: "Security event detected: {{ $labels.event_type }}"
407
+ description: "Agent {{ $labels.agent_id }} triggered security event: {{ $labels.event_type }}"
408
+ runbook_url: "https://github.com/aporthq/aport-agent-guardrails/blob/main/docs/operations/RUNBOOK.md#security-event"
409
+
410
+ - alert: APortHighLatency
411
+ expr: histogram_quantile(0.95, rate(aport_authorization_duration_seconds_bucket[10m])) > 0.5
412
+ for: 10m
413
+ labels:
414
+ severity: warning
415
+ annotations:
416
+ summary: "APort guardrail latency is high"
417
+ description: "P95 latency is {{ $value | humanizeDuration }}. Check system load."
418
+
419
+ - alert: APortAPIDown
420
+ expr: |
421
+ (sum(rate(aport_api_requests_total{status_code=~"5.."}[2m])) /
422
+ sum(rate(aport_api_requests_total[2m]))) > 0.5
423
+ for: 2m
424
+ labels:
425
+ severity: critical
426
+ annotations:
427
+ summary: "APort API is down or returning errors"
428
+ description: "API error rate is {{ $value | humanizePercentage }}. Consider failover to local mode."
429
+ ```
430
+
431
+ ### PagerDuty Integration
432
+
433
+ ```yaml
434
+ receivers:
435
+ - name: 'aport-critical'
436
+ pagerduty_configs:
437
+ - service_key: '<YOUR_PAGERDUTY_KEY>'
438
+ description: '{{ .GroupLabels.alertname }}: {{ .CommonAnnotations.summary }}'
439
+ ```
440
+
441
+ ---
442
+
443
+ ## Troubleshooting
444
+
445
+ ### High Latency
446
+
447
+ **Symptoms**: P95 latency > 200ms
448
+
449
+ **Possible Causes**:
450
+ 1. Slow disk I/O (passport/policy loading)
451
+ 2. Complex policy evaluation
452
+ 3. Slow API calls
453
+ 4. Insufficient caching
454
+
455
+ **Investigation**:
456
+ ```bash
457
+ # Check slow operations in logs
458
+ grep "slow_operation" /var/log/aport/audit.log
459
+
460
+ # Check file system performance
461
+ iostat -x 1
462
+
463
+ # Check API latency
464
+ curl -w "@curl-format.txt" -o /dev/null -s https://api.aport.io/health
465
+ ```
466
+
467
+ **Resolution**:
468
+ - Enable caching: `APORT_ENABLE_CACHING=1`
469
+ - Increase cache TTL: `APORT_PASSPORT_CACHE_TTL=120`
470
+ - Use local mode instead of API mode
471
+ - Optimize policy complexity
472
+
473
+ ### High Denial Rate
474
+
475
+ **Symptoms**: Denial rate > 20%
476
+
477
+ **Possible Causes**:
478
+ 1. Policy too restrictive
479
+ 2. Attack in progress
480
+ 3. Agent misconfiguration
481
+
482
+ **Investigation**:
483
+ ```bash
484
+ # Check denial reasons
485
+ jq '.reasons[] | select(.code | startswith("oap.policy")) | .message' /var/log/aport/audit.log | sort | uniq -c
486
+
487
+ # Check top denied agents
488
+ jq 'select(.decision == "DENY") | .agent_id' /var/log/aport/audit.log | sort | uniq -c | sort -rn | head -10
489
+ ```
490
+
491
+ **Resolution**:
492
+ - Review policy rules
493
+ - Check if denials are legitimate (security events)
494
+ - Update agent configuration
495
+ - Add missing capabilities to passports
496
+
497
+ ### Security Events
498
+
499
+ **Symptoms**: `security_event` logs appearing
500
+
501
+ **Immediate Actions**:
502
+ 1. Block agent if attack confirmed
503
+ 2. Review recent agent activity
504
+ 3. Check for compromised credentials
505
+ 4. Review security policies
506
+
507
+ **Investigation**:
508
+ ```bash
509
+ # List all security events
510
+ grep "security_event" /var/log/aport/audit.log | jq .
511
+
512
+ # Check specific agent's history
513
+ grep "agent_id.*ap_abc123" /var/log/aport/audit.log | jq .
514
+ ```
515
+
516
+ ---
517
+
518
+ ## Integration Examples
519
+
520
+ ### Datadog
521
+
522
+ ```python
523
+ from datadog import initialize, statsd
524
+
525
+ initialize(statsd_host='localhost', statsd_port=8125)
526
+
527
+ # Increment decision counter
528
+ statsd.increment('aport.authorization.decisions', tags=[f'result:{decision}', f'agent_id:{agent_id}'])
529
+
530
+ # Record latency
531
+ statsd.histogram('aport.authorization.duration', duration_ms, tags=[f'policy_pack:{policy_pack}'])
532
+ ```
533
+
534
+ ### Splunk
535
+
536
+ ```bash
537
+ # Forward APort logs to Splunk
538
+ tail -f /var/log/aport/audit.log | /opt/splunkforwarder/bin/splunk add oneshot -
539
+ ```
540
+
541
+ Splunk Query:
542
+ ```spl
543
+ index=aport event="authorization_decision"
544
+ | stats count by result, policy_pack
545
+ | where count > 100
546
+ ```
547
+
548
+ ### ELK Stack
549
+
550
+ Filebeat configuration:
551
+ ```yaml
552
+ filebeat.inputs:
553
+ - type: log
554
+ paths:
555
+ - /var/log/aport/audit.log
556
+ json.keys_under_root: true
557
+ json.add_error_key: true
558
+
559
+ output.elasticsearch:
560
+ hosts: ["localhost:9200"]
561
+ index: "aport-%{+yyyy.MM.dd}"
562
+ ```
563
+
564
+ Kibana Query:
565
+ ```
566
+ event:"authorization_denied" AND agent_id:"ap_*"
567
+ ```
568
+
569
+ ---
570
+
571
+ ## Best Practices
572
+
573
+ 1. **Always Enable Structured Logging** in production (`APORT_LOG_FORMAT=json`)
574
+ 2. **Set Appropriate Log Levels**: INFO for production, DEBUG only when troubleshooting
575
+ 3. **Monitor Security Events**: Alert on any command injection or path traversal attempts
576
+ 4. **Track Latency**: Alert on P95 > 200ms
577
+ 5. **Review Audit Logs Weekly**: Look for patterns in denials
578
+ 6. **Set Up Alerting**: Critical alerts to PagerDuty, warnings to Slack
579
+ 7. **Regular Dashboard Reviews**: Weekly team reviews of key metrics
580
+
581
+ ---
582
+
583
+ ## See Also
584
+
585
+ - [Configuration Guide](../user/CONFIGURATION.md)
586
+ - [Security Policy](../../SECURITY.md)
587
+ - [Troubleshooting Guide](../user/TROUBLESHOOTING.md)
588
+ - [Error Codes](../development/ERROR_CODES.md)