trimgate 0.0.1__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 (53) hide show
  1. trimgate-0.0.1/.github/workflows/ci.yml +68 -0
  2. trimgate-0.0.1/.gitignore +10 -0
  3. trimgate-0.0.1/CHANGELOG.md +43 -0
  4. trimgate-0.0.1/CONTRIBUTING.md +40 -0
  5. trimgate-0.0.1/LICENSE +201 -0
  6. trimgate-0.0.1/LICENSES/CC-BY-4.0.txt +29 -0
  7. trimgate-0.0.1/NOTICE +13 -0
  8. trimgate-0.0.1/PKG-INFO +183 -0
  9. trimgate-0.0.1/README.md +159 -0
  10. trimgate-0.0.1/SECURITY.md +27 -0
  11. trimgate-0.0.1/docs/azure-setup.md +86 -0
  12. trimgate-0.0.1/examples/azure/run_live.py +66 -0
  13. trimgate-0.0.1/examples/azure/seed_index.py +108 -0
  14. trimgate-0.0.1/examples/quickstart/access-matrix.yaml +12 -0
  15. trimgate-0.0.1/examples/quickstart/corpus.labeled.jsonl +4 -0
  16. trimgate-0.0.1/examples/quickstart/probes.yaml +24 -0
  17. trimgate-0.0.1/pyproject.toml +63 -0
  18. trimgate-0.0.1/src/trimgate/__init__.py +10 -0
  19. trimgate-0.0.1/src/trimgate/adapter.py +63 -0
  20. trimgate-0.0.1/src/trimgate/adapters/__init__.py +1 -0
  21. trimgate-0.0.1/src/trimgate/adapters/azure.py +113 -0
  22. trimgate-0.0.1/src/trimgate/cli.py +223 -0
  23. trimgate-0.0.1/src/trimgate/corpus.py +76 -0
  24. trimgate-0.0.1/src/trimgate/demo.py +46 -0
  25. trimgate-0.0.1/src/trimgate/diff.py +19 -0
  26. trimgate-0.0.1/src/trimgate/engine.py +114 -0
  27. trimgate-0.0.1/src/trimgate/fake.py +32 -0
  28. trimgate-0.0.1/src/trimgate/matrix.py +67 -0
  29. trimgate-0.0.1/src/trimgate/plugin.py +118 -0
  30. trimgate-0.0.1/src/trimgate/probe.py +72 -0
  31. trimgate-0.0.1/src/trimgate/py.typed +0 -0
  32. trimgate-0.0.1/src/trimgate/receipt.py +129 -0
  33. trimgate-0.0.1/src/trimgate/runner.py +55 -0
  34. trimgate-0.0.1/src/trimgate/signing.py +73 -0
  35. trimgate-0.0.1/tests/conftest.py +1 -0
  36. trimgate-0.0.1/tests/golden/receipt_clean.json +1 -0
  37. trimgate-0.0.1/tests/golden/receipt_leaky.json +1 -0
  38. trimgate-0.0.1/tests/test_azure_adapter.py +92 -0
  39. trimgate-0.0.1/tests/test_cli.py +122 -0
  40. trimgate-0.0.1/tests/test_corpus.py +24 -0
  41. trimgate-0.0.1/tests/test_determinism.py +29 -0
  42. trimgate-0.0.1/tests/test_diff.py +27 -0
  43. trimgate-0.0.1/tests/test_engine.py +119 -0
  44. trimgate-0.0.1/tests/test_fake_adapter.py +29 -0
  45. trimgate-0.0.1/tests/test_golden.py +36 -0
  46. trimgate-0.0.1/tests/test_loaders.py +109 -0
  47. trimgate-0.0.1/tests/test_matrix.py +20 -0
  48. trimgate-0.0.1/tests/test_plugin.py +68 -0
  49. trimgate-0.0.1/tests/test_probe.py +34 -0
  50. trimgate-0.0.1/tests/test_receipt.py +79 -0
  51. trimgate-0.0.1/tests/test_runner.py +106 -0
  52. trimgate-0.0.1/tests/test_signing.py +45 -0
  53. trimgate-0.0.1/tests/test_signing_cli.py +106 -0
@@ -0,0 +1,68 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+
8
+ permissions:
9
+ contents: read
10
+
11
+ jobs:
12
+ test:
13
+ runs-on: ${{ matrix.os }}
14
+ strategy:
15
+ fail-fast: false
16
+ matrix:
17
+ os: [ubuntu-latest, windows-latest]
18
+ python-version: ["3.11", "3.12", "3.13"]
19
+ steps:
20
+ - uses: actions/checkout@v4
21
+ - uses: actions/setup-python@v5
22
+ with:
23
+ python-version: ${{ matrix.python-version }}
24
+ - run: python -m pip install --upgrade pip
25
+ - run: pip install -e ".[dev]"
26
+ - name: Lint
27
+ run: |
28
+ ruff check .
29
+ ruff format --check .
30
+ - name: Type check
31
+ run: mypy
32
+ - name: Test
33
+ # Floor is conservative: the pytest11 plugin imports trimgate before
34
+ # coverage starts, so module-level lines read as missed. Executed-code
35
+ # coverage is far higher.
36
+ run: pytest --cov=trimgate --cov-branch --cov-fail-under=70 -q
37
+
38
+ azure-typecheck:
39
+ # The azure extra is type-checked and tested separately so a regression in
40
+ # the azure module cannot hide behind ignore_missing_imports.
41
+ runs-on: ubuntu-latest
42
+ steps:
43
+ - uses: actions/checkout@v4
44
+ - uses: actions/setup-python@v5
45
+ with:
46
+ python-version: "3.12"
47
+ - run: python -m pip install --upgrade pip
48
+ - run: pip install -e ".[dev,azure]"
49
+ - run: mypy
50
+ - run: pytest -q
51
+
52
+ build:
53
+ # Verify the artifact users actually install: build the wheel, install it
54
+ # clean, and confirm the CLI runs and the py.typed marker shipped.
55
+ runs-on: ubuntu-latest
56
+ steps:
57
+ - uses: actions/checkout@v4
58
+ - uses: actions/setup-python@v5
59
+ with:
60
+ python-version: "3.12"
61
+ - run: python -m pip install --upgrade pip build
62
+ - run: python -m build --wheel
63
+ - name: Install from wheel and smoke-test
64
+ run: |
65
+ python -m venv /tmp/fresh
66
+ /tmp/fresh/bin/pip install dist/*.whl
67
+ /tmp/fresh/bin/trimgate --help
68
+ /tmp/fresh/bin/python -c "import importlib.resources as r; assert (r.files('trimgate') / 'py.typed').is_file(), 'py.typed missing from wheel'"
@@ -0,0 +1,10 @@
1
+ .venv/
2
+ __pycache__/
3
+ *.pyc
4
+ *.egg-info/
5
+ build/
6
+ dist/
7
+ .pytest_cache/
8
+ .mypy_cache/
9
+ .coverage
10
+ htmlcov/
@@ -0,0 +1,43 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented here. The format is based on
4
+ [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres
5
+ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [Unreleased]
8
+
9
+ ### Added
10
+
11
+ - Deterministic core: access-matrix, labeled corpus, probe/probeset (stable hash),
12
+ binary PASS/LEAK engine, and runner.
13
+ - `trimgate` CLI: `run`, `diff` (trim gap), `keygen`, `verify`.
14
+ - pytest plugin (`pytest --trimgate`) collecting `*.trimgate.yaml` suites into one
15
+ test node per probe.
16
+ - Ed25519 signed receipts with a canonical (JCS-subset) JSON form. The signed
17
+ payload binds the adapter spec, a timestamp, a nonce, and the signer key
18
+ fingerprint; `verify --expect-fingerprint` pins the trusted signer.
19
+ - Azure AI Search + Entra reference adapter behind the `[azure]` extra, with a
20
+ hardened OData filter (per-group `eq`; rejection of unsafe group ids and unsafe
21
+ field names; empty-group fail-close; audit-sized top-k) and a live filter-shape
22
+ smoke test.
23
+ - PEP 561 `py.typed`, CI jobs for the azure extra and a build/install-from-wheel
24
+ smoke test, coverage gate, `SECURITY.md`, `CONTRIBUTING.md`.
25
+
26
+ ### Security
27
+
28
+ - Reject duplicate chunk-IDs in the corpus (a public copy of a secret id could
29
+ otherwise authorize the secret — a false pass on a real leak).
30
+ - Validate matrix/corpus at load (scalar-where-list, dangling group references,
31
+ malformed rows) so a config typo cannot silently produce a green run.
32
+ - A run that audited nothing (zero probes, or every probe skipped) is a hard
33
+ error, not a pass.
34
+ - `trimgate verify` exits non-zero for a validly-signed receipt whose verdict is
35
+ not `pass`, and warns when the signer is not pinned with `--expect-fingerprint`.
36
+ - `canonical_json` rejects floats and non-finite values.
37
+ - `load_corpus` rejects non-string `chunk_id`/`label` and duplicate JSON keys.
38
+ - Strict base64 decoding of signatures.
39
+
40
+ ### Notes
41
+
42
+ Pre-1.0: schema, receipt format, and CLI may change. See the README "Limitations"
43
+ section for what the auditor does and does not catch.
@@ -0,0 +1,40 @@
1
+ # Contributing to TrimGate
2
+
3
+ Thanks for your interest. TrimGate is a soundness-critical tool, so the bar for
4
+ trust-path changes is high: every change to the engine, runner, loaders, signing,
5
+ or adapters needs tests.
6
+
7
+ ## Development setup
8
+
9
+ ```console
10
+ python -m venv .venv
11
+ . .venv/bin/activate # Windows: .venv\Scripts\activate
12
+ pip install -e ".[dev]" # add ,azure to work on the Azure adapter
13
+ ```
14
+
15
+ ## Before you push
16
+
17
+ All of these must pass (CI enforces them):
18
+
19
+ ```console
20
+ ruff check .
21
+ ruff format --check .
22
+ mypy
23
+ pytest --cov=trimgate --cov-branch -q
24
+ ```
25
+
26
+ ## Expectations
27
+
28
+ - **Test-driven.** Write the failing test first, especially for any trust-path
29
+ change. A bug fix lands with a regression test that fails without the fix.
30
+ - **Fail closed.** Ambiguity (unknown id, malformed input, adapter error) must be
31
+ an error, never a silent pass. New code must not introduce a false-pass path.
32
+ - **Conventional Commits** for messages (`feat:`, `fix:`, `docs:`, `test:`, ...).
33
+ - **Update the CHANGELOG** `Unreleased` section.
34
+ - **PR checklist:** tests pass, coverage holds, types clean, docs updated, and any
35
+ new claim in the README is honest about what is and is not guaranteed.
36
+
37
+ ## Corpus contributions
38
+
39
+ The evaluation corpus and examples are CC-BY-4.0 and must be fully synthetic — no
40
+ real PII, customer names, or third-party-copyrighted text.
trimgate-0.0.1/LICENSE ADDED
@@ -0,0 +1,201 @@
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 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 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 Derivative
95
+ 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 those 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 do
117
+ not modify the License. You may add Your own attribution notices
118
+ within Derivative Works that You distribute, alongside or as an
119
+ addendum to the NOTICE text from the Work, provided that such
120
+ additional attribution notices cannot be construed as modifying
121
+ 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
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Mohamed Azahrioui
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,29 @@
1
+ Creative Commons Attribution 4.0 International (CC-BY-4.0)
2
+ SPDX-License-Identifier: CC-BY-4.0
3
+
4
+ The TrimGate evaluation corpus and examples (the contents of examples/ and any
5
+ bundled labeled corpora, access matrices, and probe sets) are licensed under the
6
+ Creative Commons Attribution 4.0 International License.
7
+
8
+ You are free to:
9
+ - Share: copy and redistribute the material in any medium or format.
10
+ - Adapt: remix, transform, and build upon the material for any purpose,
11
+ even commercially.
12
+
13
+ Under the following term:
14
+ - Attribution: You must give appropriate credit (to "TrimGate, Mohamed
15
+ Azahrioui"), provide a link to this license, and indicate if changes were
16
+ made. You may do so in any reasonable manner, but not in any way that
17
+ suggests the licensor endorses you or your use.
18
+
19
+ No additional restrictions: You may not apply legal terms or technological
20
+ measures that legally restrict others from doing anything the license permits.
21
+
22
+ All corpus content is synthetic (invented tenants, fabricated documents); it
23
+ contains no real personal data or third-party copyrighted text.
24
+
25
+ The full legal code is available at:
26
+ https://creativecommons.org/licenses/by/4.0/legalcode
27
+
28
+ A human-readable summary (not a substitute for the license) is at:
29
+ https://creativecommons.org/licenses/by/4.0/
trimgate-0.0.1/NOTICE ADDED
@@ -0,0 +1,13 @@
1
+ TrimGate
2
+ Copyright 2026 Mohamed Azahrioui
3
+
4
+ This product includes software developed by Mohamed Azahrioui.
5
+
6
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not
7
+ use the code in this product except in compliance with the License. A copy of
8
+ the License is provided in the LICENSE file and at
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ The evaluation corpus and examples (the contents of examples/ and any bundled
12
+ labeled corpora) are licensed separately under CC-BY-4.0; see
13
+ LICENSES/CC-BY-4.0.txt.
@@ -0,0 +1,183 @@
1
+ Metadata-Version: 2.5
2
+ Name: trimgate
3
+ Version: 0.0.1
4
+ Summary: Deterministic, test-time auditor that checks an enterprise RAG pipeline does not surface a chunk to an unauthorized identity.
5
+ Author: Mohamed Azahrioui
6
+ License-Expression: Apache-2.0 AND CC-BY-4.0
7
+ License-File: LICENSE
8
+ License-File: LICENSES/CC-BY-4.0.txt
9
+ License-File: NOTICE
10
+ Keywords: access-control,auditor,ci,pytest,rag,security-trimming
11
+ Requires-Python: >=3.11
12
+ Requires-Dist: cryptography>=42.0
13
+ Requires-Dist: pyyaml>=6.0
14
+ Provides-Extra: azure
15
+ Requires-Dist: azure-identity>=1.15; extra == 'azure'
16
+ Requires-Dist: azure-search-documents>=11.4; extra == 'azure'
17
+ Provides-Extra: dev
18
+ Requires-Dist: mypy>=1.11; extra == 'dev'
19
+ Requires-Dist: pytest-cov>=5.0; extra == 'dev'
20
+ Requires-Dist: pytest>=8.0; extra == 'dev'
21
+ Requires-Dist: ruff>=0.6; extra == 'dev'
22
+ Requires-Dist: types-pyyaml; extra == 'dev'
23
+ Description-Content-Type: text/markdown
24
+
25
+ # TrimGate
26
+
27
+ > the access-control unit test for enterprise RAG
28
+
29
+ [![CI](https://github.com/MoAz06/trimgate/actions/workflows/ci.yml/badge.svg)](https://github.com/MoAz06/trimgate/actions/workflows/ci.yml)
30
+ [![License](https://img.shields.io/badge/code-Apache--2.0-blue.svg)](LICENSE)
31
+ [![Corpus](https://img.shields.io/badge/corpus-CC--BY--4.0-green.svg)](LICENSES/CC-BY-4.0.txt)
32
+
33
+
34
+ TrimGate is a deterministic, test-time auditor for Retrieval-Augmented Generation
35
+ pipelines. For each test identity and probe it checks
36
+
37
+ ```
38
+ retrieved(query, identity) is a subset of authorized(identity)
39
+ ```
40
+
41
+ where `authorized(identity)` is computed from a **declared** access-matrix, not
42
+ from the system under test. Any chunk outside the authorized set is a leak; a leak
43
+ fails the run with a non-zero exit code. There is no LLM and no randomness in the
44
+ trust path: the verdict is pure set arithmetic.
45
+
46
+ It is an **auditor, not an enforcer** — it never sits in the live request path. It
47
+ proves *conformance to the declared policy*, not that the policy itself is
48
+ correct, and it is only as good as the access-matrix and labeled corpus you give
49
+ it. That honesty is the point: the output is evidence for your auditor, never a
50
+ certificate. See [Limitations](#limitations) for what it does and does not catch.
51
+
52
+ This is v1, built against the reconciled contract in the project handoff doc
53
+ (section 0). Status: deterministic core, pytest plugin, signed receipts, and the
54
+ Azure + Entra adapter are implemented and exercised against a live Free-tier Azure
55
+ AI Search index (a filter-shape check — see [Limitations](#limitations)).
56
+
57
+ ## Quickstart
58
+
59
+ ```console
60
+ pip install -e ".[dev]"
61
+
62
+ # Run the bundled quickstart against a deliberately leaky demo adapter.
63
+ # A leak always exits non-zero (1 = leak, 2 = fail-closed error), so it gates CI
64
+ # without any extra flag.
65
+ trimgate run \
66
+ --adapter trimgate.demo:leaky_adapter \
67
+ --matrix examples/quickstart/access-matrix.yaml \
68
+ --corpus examples/quickstart/corpus.labeled.jsonl \
69
+ --probes examples/quickstart/probes.yaml
70
+ # -> bob leaks the finance chunk; exit code 1
71
+
72
+ # Swap to trimgate.demo:clean_adapter for a passing run (exit 0).
73
+ ```
74
+
75
+ The per-identity trim gap (which chunks an identity could improperly reach):
76
+
77
+ ```console
78
+ trimgate diff --adapter trimgate.demo:leaky_adapter \
79
+ --matrix examples/quickstart/access-matrix.yaml \
80
+ --corpus examples/quickstart/corpus.labeled.jsonl \
81
+ --probes examples/quickstart/probes.yaml
82
+ ```
83
+
84
+ ### As a pytest plugin
85
+
86
+ Drop a `*.trimgate.yaml` suite file next to your tests and run `pytest
87
+ --trimgate`. Each probe becomes one test node that fails on a leak:
88
+
89
+ ```yaml
90
+ # security/quickstart.trimgate.yaml
91
+ adapter: myapp.tests:make_adapter # MODULE:ATTR (class or factory)
92
+ matrix: security/access-matrix.yaml
93
+ corpus: security/corpus.labeled.jsonl
94
+ probes:
95
+ - {id: P-001, identity: alice, probe_class: retrieval, query: "..."}
96
+ ```
97
+
98
+ ## Signed receipts
99
+
100
+ The receipt is serialized with a canonical JSON form (a JCS-compatible subset, not
101
+ a full RFC 8785 implementation — verifiers must use the bundled serializer).
102
+ Signing it with Ed25519 makes the verdict tamper-evident and verifiable offline:
103
+
104
+ ```console
105
+ trimgate keygen --private signing.pem --public signing.pub
106
+
107
+ trimgate run --adapter ... --matrix ... --corpus ... --probes ... \
108
+ --out receipt.json --sign --key signing.pem # writes receipt.json + receipt.json.sig
109
+
110
+ # verify exits 0 only when the signature is valid AND the audit verdict is pass.
111
+ # Without --expect-fingerprint it prints an UNTRUSTED warning (tamper-evidence only):
112
+ trimgate verify receipt.json --public signing.pub
113
+ # Pin the trusted signer's fingerprint (printed by verify above) to enforce authenticity:
114
+ trimgate verify receipt.json --public signing.pub --expect-fingerprint <fp>
115
+ ```
116
+
117
+ The signed payload binds the adapter spec, a timestamp, a nonce, and the signer's
118
+ key fingerprint, so a receipt names *which* system it audited, *when*, and *who*
119
+ signed it (and a zero-probe run is a hard error, not a pass). Editing a signed
120
+ receipt — e.g. flipping `fail` to `pass` — makes `verify` fail.
121
+
122
+ **Authenticity requires pinning.** Bare `verify` only proves the receipt was
123
+ signed by the holder of the supplied key; an adversary can sign their own forged
124
+ receipt with their own key. To prove the receipt came from a *trusted* signer, the
125
+ verifier must pin that signer's fingerprint via `--expect-fingerprint`, obtained
126
+ out-of-band. The public key is not trust on its own.
127
+
128
+ ## Azure AI Search adapter
129
+
130
+ The reference adapter reproduces Azure AI Search + Entra security trimming: it
131
+ resolves an identity to its Entra group ids and applies the OData intersection
132
+ filter so only authorized chunks are retrieved. Install the optional extra:
133
+
134
+ ```console
135
+ pip install "trimgate[azure]"
136
+ ```
137
+
138
+ ```python
139
+ from trimgate.adapters.azure import AzureSearchAdapter, make_search_client
140
+
141
+ adapter = AzureSearchAdapter(
142
+ make_search_client(endpoint="https://<svc>.search.windows.net", index_name="<index>"),
143
+ group_resolver=resolve_entra_groups, # identity id -> [group object ids]
144
+ )
145
+ ```
146
+
147
+ `make_search_client` defaults to `DefaultAzureCredential` (managed identity) on
148
+ Basic tier and above; the Free tier requires an API key (`AzureKeyCredential`).
149
+ The adapter is duck-typed against the search client, so it unit-tests with a fake
150
+ client and needs no live tenant. Group ids are validated (commas/quotes/control
151
+ characters are rejected) and the audit retrieves a large top-k so a low-ranked
152
+ unauthorized chunk cannot be truncated out of view. See
153
+ [docs/azure-setup.md](docs/azure-setup.md) for a live walkthrough.
154
+
155
+ ## Limitations
156
+
157
+ TrimGate is deliberately scoped. It does **not** yet cover:
158
+
159
+ - **Policy shape.** The access-matrix is a flat `group -> labels` union. It cannot
160
+ express deny rules, per-user exceptions, legal holds, or label hierarchy. If your
161
+ real ACL uses those, TrimGate cannot represent the policy and would mis-audit the
162
+ excepted documents — declare such cases out of scope rather than trusting a pass.
163
+ - **Retrieval shape.** The soundness check assumes single-stage retrieval over the
164
+ full filtered candidate set. Rerankers, hybrid fusion, citation/answer
165
+ post-processing, and small top-k windows can each hide a leak; the Azure adapter
166
+ defaults to a large top-k but you must size it above what the filter can return.
167
+ - **Adapter fidelity.** The audit is only as faithful as the adapter. The reference
168
+ Azure adapter *rebuilds* the production OData filter, so it best catches drift
169
+ that lives outside that filter (e.g. stale index ACLs); an over-broad filter is
170
+ caught only if the unauthorized chunks are actually surfaced (hence large top-k).
171
+ - **The live Azure example is a filter-shape smoke test**, not proof of real Entra
172
+ enforcement: the seed tags and the `group_resolver` share invented ids, and on
173
+ Free-tier key auth there is no identity-based enforcement in the loop. It proves
174
+ the filter agrees with the matrix, not that production token-to-group resolution
175
+ is correct.
176
+ - **Receipt authenticity needs out-of-band key pinning** (see above).
177
+
178
+ ## License
179
+
180
+ Dual-licensed by artifact type:
181
+
182
+ - **Code** (`src/`, `tests/`) under **Apache-2.0** (see [LICENSE](LICENSE) and [NOTICE](NOTICE)).
183
+ - **Corpus / examples** under **CC-BY-4.0** (see [LICENSES/CC-BY-4.0.txt](LICENSES/CC-BY-4.0.txt)).