opsentry 1.8.4__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.
Files changed (72) hide show
  1. opsentry-1.8.4/LICENSE +190 -0
  2. opsentry-1.8.4/PKG-INFO +211 -0
  3. opsentry-1.8.4/README.md +184 -0
  4. opsentry-1.8.4/pyproject.toml +93 -0
  5. opsentry-1.8.4/setup.cfg +4 -0
  6. opsentry-1.8.4/src/opsentry/VERSION +1 -0
  7. opsentry-1.8.4/src/opsentry/__init__.py +5 -0
  8. opsentry-1.8.4/src/opsentry/cli.py +354 -0
  9. opsentry-1.8.4/src/opsentry/config/__init__.py +0 -0
  10. opsentry-1.8.4/src/opsentry/config/generate.py +454 -0
  11. opsentry-1.8.4/src/opsentry/config/hook_templates/block-dangerous-commands.sh.j2 +102 -0
  12. opsentry-1.8.4/src/opsentry/config/hook_templates/block-data-exfiltration.sh.j2 +94 -0
  13. opsentry-1.8.4/src/opsentry/config/hook_templates/block-environment-escape.sh.j2 +99 -0
  14. opsentry-1.8.4/src/opsentry/config/hook_templates/block-git-commands.sh.j2 +46 -0
  15. opsentry-1.8.4/src/opsentry/config/hook_templates/block-package-install.sh.j2 +95 -0
  16. opsentry-1.8.4/src/opsentry/config/hook_templates/block-pii-leakage.sh.j2 +100 -0
  17. opsentry-1.8.4/src/opsentry/config/hook_templates/block-scope-escape.sh.j2 +115 -0
  18. opsentry-1.8.4/src/opsentry/config/hook_templates/block-sensitive-files.sh.j2 +97 -0
  19. opsentry-1.8.4/src/opsentry/config/init_wizard.py +212 -0
  20. opsentry-1.8.4/src/opsentry/config/rule_texts/01_sensitive_files.md +15 -0
  21. opsentry-1.8.4/src/opsentry/config/rule_texts/02_client_data.md +10 -0
  22. opsentry-1.8.4/src/opsentry/config/rule_texts/03_credentials.md +17 -0
  23. opsentry-1.8.4/src/opsentry/config/rule_texts/04_sql_safety.md +33 -0
  24. opsentry-1.8.4/src/opsentry/config/rule_texts/05_dangerous_code.md +29 -0
  25. opsentry-1.8.4/src/opsentry/config/rule_texts/06_frontend_xss.md +9 -0
  26. opsentry-1.8.4/src/opsentry/config/rule_texts/07_git_operations_block_all.md +13 -0
  27. opsentry-1.8.4/src/opsentry/config/rule_texts/07_git_operations_read_only.md +18 -0
  28. opsentry-1.8.4/src/opsentry/config/rule_texts/08_destructive_commands.md +12 -0
  29. opsentry-1.8.4/src/opsentry/config/rule_texts/09_database_safety.md +17 -0
  30. opsentry-1.8.4/src/opsentry/config/rule_texts/10_network_requests.md +10 -0
  31. opsentry-1.8.4/src/opsentry/config/rule_texts/11_code_quality.md +13 -0
  32. opsentry-1.8.4/src/opsentry/config/rule_texts/12_data_exfiltration.md +10 -0
  33. opsentry-1.8.4/src/opsentry/config/rule_texts/13_package_install.md +9 -0
  34. opsentry-1.8.4/src/opsentry/config/rule_texts/14_scope_boundaries.md +8 -0
  35. opsentry-1.8.4/src/opsentry/config/rule_texts/15_env_isolation.md +9 -0
  36. opsentry-1.8.4/src/opsentry/config/rule_texts/16_resource_limits.md +8 -0
  37. opsentry-1.8.4/src/opsentry/config/rule_texts/17_compliance_privacy.md +9 -0
  38. opsentry-1.8.4/src/opsentry/config/rule_texts/18_when_in_doubt.md +10 -0
  39. opsentry-1.8.4/src/opsentry/config/sandbox_generate.py +213 -0
  40. opsentry-1.8.4/src/opsentry/config/sandbox_templates/SANDBOX-README.md.j2 +184 -0
  41. opsentry-1.8.4/src/opsentry/config/sandbox_templates/docker-sandbox.Dockerfile.j2 +40 -0
  42. opsentry-1.8.4/src/opsentry/config/sandbox_templates/docker-sandbox.compose.yml.j2 +67 -0
  43. opsentry-1.8.4/src/opsentry/config/sandbox_templates/linux-bwrap.sh.j2 +131 -0
  44. opsentry-1.8.4/src/opsentry/config/sandbox_templates/macos-sandbox.sb.j2 +119 -0
  45. opsentry-1.8.4/src/opsentry/config/schema.py +202 -0
  46. opsentry-1.8.4/src/opsentry/config/templates/generic.yaml +101 -0
  47. opsentry-1.8.4/src/opsentry/deployment/.claude/commands/code-health.md +42 -0
  48. opsentry-1.8.4/src/opsentry/deployment/.claude/commands/governance-check.md +29 -0
  49. opsentry-1.8.4/src/opsentry/deployment/.claude/commands/security-audit.md +41 -0
  50. opsentry-1.8.4/src/opsentry/deployment/baseline.py +440 -0
  51. opsentry-1.8.4/src/opsentry/deployment/blocklog_audit.py +506 -0
  52. opsentry-1.8.4/src/opsentry/deployment/claude/CLAUDE.md +300 -0
  53. opsentry-1.8.4/src/opsentry/deployment/claude/hooks/block-dangerous-commands.sh +106 -0
  54. opsentry-1.8.4/src/opsentry/deployment/claude/hooks/block-data-exfiltration.sh +99 -0
  55. opsentry-1.8.4/src/opsentry/deployment/claude/hooks/block-environment-escape.sh +96 -0
  56. opsentry-1.8.4/src/opsentry/deployment/claude/hooks/block-git-commands.sh +37 -0
  57. opsentry-1.8.4/src/opsentry/deployment/claude/hooks/block-package-install.sh +103 -0
  58. opsentry-1.8.4/src/opsentry/deployment/claude/hooks/block-pii-leakage.sh +86 -0
  59. opsentry-1.8.4/src/opsentry/deployment/claude/hooks/block-scope-escape.sh +210 -0
  60. opsentry-1.8.4/src/opsentry/deployment/claude/hooks/block-sensitive-files.sh +97 -0
  61. opsentry-1.8.4/src/opsentry/deployment/claude/settings.json +72 -0
  62. opsentry-1.8.4/src/opsentry/deployment/install.sh +343 -0
  63. opsentry-1.8.4/src/opsentry/deployment/patrol.sh +282 -0
  64. opsentry-1.8.4/src/opsentry/deployment/test.sh +728 -0
  65. opsentry-1.8.4/src/opsentry/deployment/update.sh +19 -0
  66. opsentry-1.8.4/src/opsentry/deployment/verify.sh +201 -0
  67. opsentry-1.8.4/src/opsentry.egg-info/PKG-INFO +211 -0
  68. opsentry-1.8.4/src/opsentry.egg-info/SOURCES.txt +70 -0
  69. opsentry-1.8.4/src/opsentry.egg-info/dependency_links.txt +1 -0
  70. opsentry-1.8.4/src/opsentry.egg-info/entry_points.txt +2 -0
  71. opsentry-1.8.4/src/opsentry.egg-info/requires.txt +2 -0
  72. opsentry-1.8.4/src/opsentry.egg-info/top_level.txt +1 -0
opsentry-1.8.4/LICENSE ADDED
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to the Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by the Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding any notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2026 OpSight Intelligence
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
@@ -0,0 +1,211 @@
1
+ Metadata-Version: 2.4
2
+ Name: opsentry
3
+ Version: 1.8.4
4
+ Summary: AI agent security guardrails for engineering teams
5
+ Author-email: OpSight Intelligence <utku@opsightintel.com>
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/opsight-intelligence/opsentry
8
+ Project-URL: Documentation, https://github.com/opsight-intelligence/opsentry#readme
9
+ Project-URL: Repository, https://github.com/opsight-intelligence/opsentry
10
+ Project-URL: Issues, https://github.com/opsight-intelligence/opsentry/issues
11
+ Keywords: security,guardrails,claude-code,ai-agent,devsecops
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: Apache Software License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Security
20
+ Classifier: Topic :: Software Development :: Quality Assurance
21
+ Requires-Python: >=3.10
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+ Requires-Dist: PyYAML>=6.0
25
+ Requires-Dist: Jinja2>=3.1
26
+ Dynamic: license-file
27
+
28
+ # OpSight OpSentry
29
+
30
+ Three layers of defense for AI coding agents — **detect**, **prevent**, and **make dangerous actions architecturally impossible**.
31
+
32
+ Competitors match patterns and lose the arms race. OpSentry makes entire attack classes impossible.
33
+
34
+ Built by [OpSight Intelligence](https://github.com/opsight-intelligence).
35
+
36
+ ## Quick Start
37
+
38
+ ```bash
39
+ # pip (recommended)
40
+ pip install opsentry && opsentry install
41
+
42
+ # Homebrew
43
+ brew tap opsight-intelligence/opsentry && brew install opsentry && opsentry install
44
+
45
+ # Git clone
46
+ git clone https://github.com/opsight-intelligence/opsentry.git && cd opsentry && ./install.sh
47
+
48
+ # GitHub Action (CI/CD)
49
+ # uses: opsight-intelligence/opsentry-action@v1
50
+ ```
51
+
52
+ Restart Claude Code after installation.
53
+
54
+ ## New in v1.8
55
+
56
+ - **168 tests** (101 functional + 67 adversarial red-team) — up from 155 in v1.7. [red team log](https://github.com/opsight-intelligence/opsentry/blob/main/docs/red-team-log.md)
57
+ - **Precision path matching** — `block-scope-escape.sh` rewritten with word-boundary regex and `realpath` symlink resolution. Project-local `.claude/` directories, `~/Library/` on macOS, `/var/folders/` (macOS temp), and filenames like `foo.bashrc.bak` are no longer over-blocked. Attack 3 protection is preserved and now also catches symlink-based bypass attempts against `$HOME/.claude/`.
58
+ - **Configuration baseline integrity** — `install.sh` writes a SHA-256 manifest of the guardrail-controlled subset of `CLAUDE.md` and `settings.json` to `~/.claude/.opsentry-baseline.json`, locked with filesystem immutability. `opsentry patrol` re-verifies on every run and flags drift as a FAIL finding. User customizations (custom deny rules, custom hook matchers) are preserved — only the guardrail subset is hashed.
59
+ - **Block log pattern analysis** — `opsentry patrol` now scans `~/.claude/guardrail-blocks.log` for five attack signatures beyond simple counts: repeat offender (same hook 5+/1h), rapid burst (5+ blocks in any 30s window), multi-hook coverage (3+ distinct hooks in 1h), exfiltration cluster (`block-sensitive-files` + `block-data-exfiltration` within 5 minutes), and self-modification attempts (Attack 3 active exploitation signal).
60
+ - **Patrol bug fixes** — no longer aborts mid-execution when drift is detected (fixed `set -euo pipefail` interaction with `verify.sh` failures); no longer crashes on macOS due to the GNU-only `grep -oP` flag in the block log section.
61
+
62
+ ## v1.7 highlights (still current)
63
+
64
+ - **Protection levels** — `strict` / `balanced` / `permissive` in `guardrails.yaml`
65
+ - **Filesystem immutability** — `chflags uchg` (macOS) / `chattr +i` (Linux) locks guardrail files
66
+ - **Compliance Patrol** — `opsentry patrol` with schedulable daily audits
67
+ - **pip install** — `pip install opsentry` ships the CLI, deployment scripts, and config generator
68
+ - **Red-team hardening** — all 8 hooks hardened against adversarial bypass vectors (67 red-team test cases)
69
+
70
+ Full release history: [CHANGELOG.md](./CHANGELOG.md)
71
+
72
+ ## What Gets Installed
73
+
74
+ | File | Location | Purpose |
75
+ |------|----------|---------|
76
+ | `CLAUDE.md` | `~/.claude/CLAUDE.md` | Behavioral rules Claude Code follows every session |
77
+ | `settings.json` | `~/.claude/settings.json` | Hard deny rules for sensitive file access and dangerous commands |
78
+ | `block-sensitive-files.sh` | `~/.claude/hooks/` | Blocks reading .env, credentials, secrets, certificates |
79
+ | `block-dangerous-commands.sh` | `~/.claude/hooks/` | Blocks rm -rf, sudo, chmod 777, DROP TABLE, etc. |
80
+ | `block-git-commands.sh` | `~/.claude/hooks/` | Blocks all git command execution |
81
+ | `block-data-exfiltration.sh` | `~/.claude/hooks/` | Blocks curl/wget uploads, base64 of secrets, /tmp writes, netcat |
82
+ | `block-package-install.sh` | `~/.claude/hooks/` | Blocks pip/npm/gem installs from untrusted sources |
83
+ | `block-scope-escape.sh` | `~/.claude/hooks/` | Blocks self-modification of ~/.claude/ and system paths |
84
+ | `block-environment-escape.sh` | `~/.claude/hooks/` | Blocks ssh, docker run/exec, terraform apply/destroy, kubectl |
85
+ | `block-pii-leakage.sh` | `~/.claude/hooks/` | Blocks writing SSNs, credit card numbers, Korean RRNs into code |
86
+
87
+ ## How OpSentry Defends Your Environment
88
+
89
+ ### Layer 1 — Runtime Guardrails (Detect)
90
+
91
+ Pre-execution pattern matching blocks known attack vectors before they run. 8 hook scripts, 203 tests, battle-tested against 8 red team attacks.
92
+
93
+ - **CLAUDE.md** — behavioral rules Claude reads at session start (18 mandatory security sections)
94
+ - **settings.json** — hard deny rules in Claude Code's permission system
95
+ - **Hook scripts** — deterministic bash enforcement that inspects every tool call
96
+
97
+ ### Layer 2 — CI/CD Analysis (Prevent)
98
+
99
+ Cross-file AST composition analysis catches exfiltration patterns that span multiple files at PR time. Import-graph-aware — detects when file-read, network-send, and sensitive-path references are assembled across imports.
100
+
101
+ - **SEC-012** — cross-file exfiltration composition analysis (42 tests)
102
+ - **SEC-013** — network exposure scanning (23 dangerous ports)
103
+ - **Auto-fix** — `eval()` → `ast.literal_eval()`, bare `except:` → specific exceptions
104
+ - **Merge gating** — critical/high findings block PR merge
105
+
106
+ ### Layer 3 — Sandbox Profiles (Make Impossible)
107
+
108
+ Generated platform-specific sandbox configs that make dangerous actions impossible at the OS level. Not pattern matching — capability removal.
109
+
110
+ - **macOS** — `sandbox-exec` SBPL profiles that deny read/write at the kernel level
111
+ - **Linux** — bubblewrap wrapper scripts that shadow sensitive directories with empty mounts
112
+ - **Docker** — Dockerfile + Compose with `cap_drop: ALL`, read-only root, network isolation
113
+
114
+ ```bash
115
+ # Generate sandbox profiles from your guardrails.yaml
116
+ opsentry sandbox generate --platform all --output-dir ./sandbox-profiles/
117
+ ```
118
+
119
+ | Attack Class | How the Sandbox Defeats It |
120
+ |---|---|
121
+ | Credential file read (`.env`, `~/.aws/`) | Denied at kernel level, regardless of command syntax |
122
+ | Guardrail self-destruction (`~/.claude/`) | Outside the sandbox namespace — invisible |
123
+ | Data exfiltration via network | Network denied by default or allowlisted |
124
+ | Persistence (cron, launchd, systemd) | Write access to persistence dirs denied |
125
+ | Fork bombs / resource exhaustion | Process and memory limits enforced |
126
+
127
+ You own the sandbox runtime — OpSentry provides the security intelligence. No vendor lock-in.
128
+
129
+ ## Updating
130
+
131
+ When rules are updated in this repo, every developer should pull and re-run:
132
+
133
+ ```bash
134
+ cd ai-guardrails
135
+ ./update.sh
136
+ ```
137
+
138
+ ## Verifying Installation
139
+
140
+ To check that all guardrails are properly installed and unmodified:
141
+
142
+ ```bash
143
+ ./verify.sh
144
+ ```
145
+
146
+ ## Prerequisites
147
+
148
+ - **jq** is required by the hook scripts. Install with:
149
+ - macOS: `brew install jq`
150
+ - Ubuntu/Debian: `sudo apt install jq`
151
+ - Windows (WSL): `sudo apt install jq`
152
+
153
+ ## What Is Blocked
154
+
155
+ ### Sensitive Files
156
+ All `.env` files, credential configs, SSL certificates, SSH keys, cloud provider configs, database connection files, and anything in `secrets/`, `credentials/`, `private/`, or `keys/` directories.
157
+
158
+ ### Dangerous Commands
159
+ `rm -rf`, `sudo`, `chmod 777`, `kill -9`, disk operations (`mkfs`, `dd`, `fdisk`), pipe-to-shell (`curl | bash`), and database destruction commands (`DROP TABLE`, `TRUNCATE`, `DELETE` without WHERE).
160
+
161
+ ### Git Commands
162
+ All git commands are blocked from agent execution. The agent will write git commands as text for the developer to review and run manually.
163
+
164
+ ### Data Exfiltration
165
+ Curl/wget file uploads, base64 encoding of sensitive files, writes to /tmp or /dev/shm, clipboard exfiltration of secrets, and netcat outbound channels.
166
+
167
+ ### Package Installs from Untrusted Sources
168
+ pip/npm/gem/go installs from git URLs, custom registries, or direct download links. Standard registry installs are allowed.
169
+
170
+ ### Scope and Environment Escape
171
+ Self-modification of `~/.claude/`, writes to system paths (`/etc`, `/usr`, shell configs), ssh/scp to remote hosts, docker run/exec/build, destructive terraform/kubectl commands.
172
+
173
+ ### PII in Source Code
174
+ US Social Security Numbers, credit card numbers (Visa, Mastercard, Amex, Discover), and Korean Resident Registration Numbers are blocked from being written into code. Synthetic test values (000-00-0000, 555-55-5555) are allowed.
175
+
176
+ ### Client Data
177
+ The CLAUDE.md includes strict rules against including client confidential data (company names, internal identifiers, business metrics) in any outputs.
178
+
179
+ ## Customisation
180
+
181
+ - To add new file patterns to block, edit `claude/hooks/block-sensitive-files.sh` and `claude/settings.json`
182
+ - To add new dangerous commands, edit `claude/hooks/block-dangerous-commands.sh`
183
+ - To add new PII patterns, edit `claude/hooks/block-pii-leakage.sh`
184
+ - To add new exfiltration vectors, edit `claude/hooks/block-data-exfiltration.sh`
185
+ - To change behavioral rules, edit `claude/CLAUDE.md`
186
+ - After changes, run `./ai-guardrails/test.sh` to validate, then `./ai-guardrails/install.sh` to deploy locally
187
+
188
+ ## Troubleshooting
189
+
190
+ **Hooks not firing?**
191
+ Run `/hooks` inside Claude Code to check if hooks are registered. Verify scripts are executable: `ls -la ~/.claude/hooks/`
192
+
193
+ **"jq: command not found" errors?**
194
+ Install jq — see Prerequisites above.
195
+
196
+ **Developer modified their settings.json?**
197
+ Run `./verify.sh` to check for differences. Run `./install.sh` to reset.
198
+
199
+ ## Questions or Issues
200
+
201
+ Open an issue on [GitHub](https://github.com/opsight-intelligence/opsentry/issues) or reach out to the OpSight team.
202
+
203
+ ## Branch guard (pre-push hook)
204
+
205
+ This repo's `main`/`develop` are protected by a client-side `pre-push` hook (the org is on GitHub Free, which has no server-side branch protection on private repos). The hook lives in `.git/hooks/`, so it is **not** version-controlled — **re-run the installer in every fresh clone**, from your `opsight-company` checkout:
206
+
207
+ ```sh
208
+ bash scripts/git-hooks/install-hooks.sh /path/to/this-repo
209
+ ```
210
+
211
+ It only guards `opsight-intelligence` remotes. For an intentional release push, override with `OPSIGHT_ALLOW_PROTECTED_PUSH=1 git push ...`. All changes go through a `feature/`/`bugfix/` branch → PR into `develop`.
@@ -0,0 +1,184 @@
1
+ # OpSight OpSentry
2
+
3
+ Three layers of defense for AI coding agents — **detect**, **prevent**, and **make dangerous actions architecturally impossible**.
4
+
5
+ Competitors match patterns and lose the arms race. OpSentry makes entire attack classes impossible.
6
+
7
+ Built by [OpSight Intelligence](https://github.com/opsight-intelligence).
8
+
9
+ ## Quick Start
10
+
11
+ ```bash
12
+ # pip (recommended)
13
+ pip install opsentry && opsentry install
14
+
15
+ # Homebrew
16
+ brew tap opsight-intelligence/opsentry && brew install opsentry && opsentry install
17
+
18
+ # Git clone
19
+ git clone https://github.com/opsight-intelligence/opsentry.git && cd opsentry && ./install.sh
20
+
21
+ # GitHub Action (CI/CD)
22
+ # uses: opsight-intelligence/opsentry-action@v1
23
+ ```
24
+
25
+ Restart Claude Code after installation.
26
+
27
+ ## New in v1.8
28
+
29
+ - **168 tests** (101 functional + 67 adversarial red-team) — up from 155 in v1.7. [red team log](https://github.com/opsight-intelligence/opsentry/blob/main/docs/red-team-log.md)
30
+ - **Precision path matching** — `block-scope-escape.sh` rewritten with word-boundary regex and `realpath` symlink resolution. Project-local `.claude/` directories, `~/Library/` on macOS, `/var/folders/` (macOS temp), and filenames like `foo.bashrc.bak` are no longer over-blocked. Attack 3 protection is preserved and now also catches symlink-based bypass attempts against `$HOME/.claude/`.
31
+ - **Configuration baseline integrity** — `install.sh` writes a SHA-256 manifest of the guardrail-controlled subset of `CLAUDE.md` and `settings.json` to `~/.claude/.opsentry-baseline.json`, locked with filesystem immutability. `opsentry patrol` re-verifies on every run and flags drift as a FAIL finding. User customizations (custom deny rules, custom hook matchers) are preserved — only the guardrail subset is hashed.
32
+ - **Block log pattern analysis** — `opsentry patrol` now scans `~/.claude/guardrail-blocks.log` for five attack signatures beyond simple counts: repeat offender (same hook 5+/1h), rapid burst (5+ blocks in any 30s window), multi-hook coverage (3+ distinct hooks in 1h), exfiltration cluster (`block-sensitive-files` + `block-data-exfiltration` within 5 minutes), and self-modification attempts (Attack 3 active exploitation signal).
33
+ - **Patrol bug fixes** — no longer aborts mid-execution when drift is detected (fixed `set -euo pipefail` interaction with `verify.sh` failures); no longer crashes on macOS due to the GNU-only `grep -oP` flag in the block log section.
34
+
35
+ ## v1.7 highlights (still current)
36
+
37
+ - **Protection levels** — `strict` / `balanced` / `permissive` in `guardrails.yaml`
38
+ - **Filesystem immutability** — `chflags uchg` (macOS) / `chattr +i` (Linux) locks guardrail files
39
+ - **Compliance Patrol** — `opsentry patrol` with schedulable daily audits
40
+ - **pip install** — `pip install opsentry` ships the CLI, deployment scripts, and config generator
41
+ - **Red-team hardening** — all 8 hooks hardened against adversarial bypass vectors (67 red-team test cases)
42
+
43
+ Full release history: [CHANGELOG.md](./CHANGELOG.md)
44
+
45
+ ## What Gets Installed
46
+
47
+ | File | Location | Purpose |
48
+ |------|----------|---------|
49
+ | `CLAUDE.md` | `~/.claude/CLAUDE.md` | Behavioral rules Claude Code follows every session |
50
+ | `settings.json` | `~/.claude/settings.json` | Hard deny rules for sensitive file access and dangerous commands |
51
+ | `block-sensitive-files.sh` | `~/.claude/hooks/` | Blocks reading .env, credentials, secrets, certificates |
52
+ | `block-dangerous-commands.sh` | `~/.claude/hooks/` | Blocks rm -rf, sudo, chmod 777, DROP TABLE, etc. |
53
+ | `block-git-commands.sh` | `~/.claude/hooks/` | Blocks all git command execution |
54
+ | `block-data-exfiltration.sh` | `~/.claude/hooks/` | Blocks curl/wget uploads, base64 of secrets, /tmp writes, netcat |
55
+ | `block-package-install.sh` | `~/.claude/hooks/` | Blocks pip/npm/gem installs from untrusted sources |
56
+ | `block-scope-escape.sh` | `~/.claude/hooks/` | Blocks self-modification of ~/.claude/ and system paths |
57
+ | `block-environment-escape.sh` | `~/.claude/hooks/` | Blocks ssh, docker run/exec, terraform apply/destroy, kubectl |
58
+ | `block-pii-leakage.sh` | `~/.claude/hooks/` | Blocks writing SSNs, credit card numbers, Korean RRNs into code |
59
+
60
+ ## How OpSentry Defends Your Environment
61
+
62
+ ### Layer 1 — Runtime Guardrails (Detect)
63
+
64
+ Pre-execution pattern matching blocks known attack vectors before they run. 8 hook scripts, 203 tests, battle-tested against 8 red team attacks.
65
+
66
+ - **CLAUDE.md** — behavioral rules Claude reads at session start (18 mandatory security sections)
67
+ - **settings.json** — hard deny rules in Claude Code's permission system
68
+ - **Hook scripts** — deterministic bash enforcement that inspects every tool call
69
+
70
+ ### Layer 2 — CI/CD Analysis (Prevent)
71
+
72
+ Cross-file AST composition analysis catches exfiltration patterns that span multiple files at PR time. Import-graph-aware — detects when file-read, network-send, and sensitive-path references are assembled across imports.
73
+
74
+ - **SEC-012** — cross-file exfiltration composition analysis (42 tests)
75
+ - **SEC-013** — network exposure scanning (23 dangerous ports)
76
+ - **Auto-fix** — `eval()` → `ast.literal_eval()`, bare `except:` → specific exceptions
77
+ - **Merge gating** — critical/high findings block PR merge
78
+
79
+ ### Layer 3 — Sandbox Profiles (Make Impossible)
80
+
81
+ Generated platform-specific sandbox configs that make dangerous actions impossible at the OS level. Not pattern matching — capability removal.
82
+
83
+ - **macOS** — `sandbox-exec` SBPL profiles that deny read/write at the kernel level
84
+ - **Linux** — bubblewrap wrapper scripts that shadow sensitive directories with empty mounts
85
+ - **Docker** — Dockerfile + Compose with `cap_drop: ALL`, read-only root, network isolation
86
+
87
+ ```bash
88
+ # Generate sandbox profiles from your guardrails.yaml
89
+ opsentry sandbox generate --platform all --output-dir ./sandbox-profiles/
90
+ ```
91
+
92
+ | Attack Class | How the Sandbox Defeats It |
93
+ |---|---|
94
+ | Credential file read (`.env`, `~/.aws/`) | Denied at kernel level, regardless of command syntax |
95
+ | Guardrail self-destruction (`~/.claude/`) | Outside the sandbox namespace — invisible |
96
+ | Data exfiltration via network | Network denied by default or allowlisted |
97
+ | Persistence (cron, launchd, systemd) | Write access to persistence dirs denied |
98
+ | Fork bombs / resource exhaustion | Process and memory limits enforced |
99
+
100
+ You own the sandbox runtime — OpSentry provides the security intelligence. No vendor lock-in.
101
+
102
+ ## Updating
103
+
104
+ When rules are updated in this repo, every developer should pull and re-run:
105
+
106
+ ```bash
107
+ cd ai-guardrails
108
+ ./update.sh
109
+ ```
110
+
111
+ ## Verifying Installation
112
+
113
+ To check that all guardrails are properly installed and unmodified:
114
+
115
+ ```bash
116
+ ./verify.sh
117
+ ```
118
+
119
+ ## Prerequisites
120
+
121
+ - **jq** is required by the hook scripts. Install with:
122
+ - macOS: `brew install jq`
123
+ - Ubuntu/Debian: `sudo apt install jq`
124
+ - Windows (WSL): `sudo apt install jq`
125
+
126
+ ## What Is Blocked
127
+
128
+ ### Sensitive Files
129
+ All `.env` files, credential configs, SSL certificates, SSH keys, cloud provider configs, database connection files, and anything in `secrets/`, `credentials/`, `private/`, or `keys/` directories.
130
+
131
+ ### Dangerous Commands
132
+ `rm -rf`, `sudo`, `chmod 777`, `kill -9`, disk operations (`mkfs`, `dd`, `fdisk`), pipe-to-shell (`curl | bash`), and database destruction commands (`DROP TABLE`, `TRUNCATE`, `DELETE` without WHERE).
133
+
134
+ ### Git Commands
135
+ All git commands are blocked from agent execution. The agent will write git commands as text for the developer to review and run manually.
136
+
137
+ ### Data Exfiltration
138
+ Curl/wget file uploads, base64 encoding of sensitive files, writes to /tmp or /dev/shm, clipboard exfiltration of secrets, and netcat outbound channels.
139
+
140
+ ### Package Installs from Untrusted Sources
141
+ pip/npm/gem/go installs from git URLs, custom registries, or direct download links. Standard registry installs are allowed.
142
+
143
+ ### Scope and Environment Escape
144
+ Self-modification of `~/.claude/`, writes to system paths (`/etc`, `/usr`, shell configs), ssh/scp to remote hosts, docker run/exec/build, destructive terraform/kubectl commands.
145
+
146
+ ### PII in Source Code
147
+ US Social Security Numbers, credit card numbers (Visa, Mastercard, Amex, Discover), and Korean Resident Registration Numbers are blocked from being written into code. Synthetic test values (000-00-0000, 555-55-5555) are allowed.
148
+
149
+ ### Client Data
150
+ The CLAUDE.md includes strict rules against including client confidential data (company names, internal identifiers, business metrics) in any outputs.
151
+
152
+ ## Customisation
153
+
154
+ - To add new file patterns to block, edit `claude/hooks/block-sensitive-files.sh` and `claude/settings.json`
155
+ - To add new dangerous commands, edit `claude/hooks/block-dangerous-commands.sh`
156
+ - To add new PII patterns, edit `claude/hooks/block-pii-leakage.sh`
157
+ - To add new exfiltration vectors, edit `claude/hooks/block-data-exfiltration.sh`
158
+ - To change behavioral rules, edit `claude/CLAUDE.md`
159
+ - After changes, run `./ai-guardrails/test.sh` to validate, then `./ai-guardrails/install.sh` to deploy locally
160
+
161
+ ## Troubleshooting
162
+
163
+ **Hooks not firing?**
164
+ Run `/hooks` inside Claude Code to check if hooks are registered. Verify scripts are executable: `ls -la ~/.claude/hooks/`
165
+
166
+ **"jq: command not found" errors?**
167
+ Install jq — see Prerequisites above.
168
+
169
+ **Developer modified their settings.json?**
170
+ Run `./verify.sh` to check for differences. Run `./install.sh` to reset.
171
+
172
+ ## Questions or Issues
173
+
174
+ Open an issue on [GitHub](https://github.com/opsight-intelligence/opsentry/issues) or reach out to the OpSight team.
175
+
176
+ ## Branch guard (pre-push hook)
177
+
178
+ This repo's `main`/`develop` are protected by a client-side `pre-push` hook (the org is on GitHub Free, which has no server-side branch protection on private repos). The hook lives in `.git/hooks/`, so it is **not** version-controlled — **re-run the installer in every fresh clone**, from your `opsight-company` checkout:
179
+
180
+ ```sh
181
+ bash scripts/git-hooks/install-hooks.sh /path/to/this-repo
182
+ ```
183
+
184
+ It only guards `opsight-intelligence` remotes. For an intentional release push, override with `OPSIGHT_ALLOW_PROTECTED_PUSH=1 git push ...`. All changes go through a `feature/`/`bugfix/` branch → PR into `develop`.