ten-grd 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ten_grd-0.2.0/LICENSE +201 -0
- ten_grd-0.2.0/PKG-INFO +180 -0
- ten_grd-0.2.0/README.md +152 -0
- ten_grd-0.2.0/pyproject.toml +30 -0
- ten_grd-0.2.0/setup.cfg +4 -0
- ten_grd-0.2.0/src/ten_grd/__init__.py +17 -0
- ten_grd-0.2.0/src/ten_grd/adapters.py +48 -0
- ten_grd-0.2.0/src/ten_grd/client.py +61 -0
- ten_grd-0.2.0/src/ten_grd/context.py +49 -0
- ten_grd-0.2.0/src/ten_grd/engine.py +154 -0
- ten_grd-0.2.0/src/ten_grd/exceptions.py +25 -0
- ten_grd-0.2.0/src/ten_grd/integrations/__init__.py +1 -0
- ten_grd-0.2.0/src/ten_grd/integrations/_shared.py +53 -0
- ten_grd-0.2.0/src/ten_grd/integrations/cache.py +126 -0
- ten_grd-0.2.0/src/ten_grd/integrations/langchain.py +89 -0
- ten_grd-0.2.0/src/ten_grd/integrations/postgres.py +55 -0
- ten_grd-0.2.0/src/ten_grd/integrations/qdrant.py +124 -0
- ten_grd-0.2.0/src/ten_grd/integrations/semantic_cache.py +67 -0
- ten_grd-0.2.0/src/ten_grd/integrations/sql.py +53 -0
- ten_grd-0.2.0/src/ten_grd/integrations/sqlite.py +63 -0
- ten_grd-0.2.0/src/ten_grd/operations.py +113 -0
- ten_grd-0.2.0/src/ten_grd/predicates.py +87 -0
- ten_grd-0.2.0/src/ten_grd.egg-info/PKG-INFO +180 -0
- ten_grd-0.2.0/src/ten_grd.egg-info/SOURCES.txt +31 -0
- ten_grd-0.2.0/src/ten_grd.egg-info/dependency_links.txt +1 -0
- ten_grd-0.2.0/src/ten_grd.egg-info/requires.txt +23 -0
- ten_grd-0.2.0/src/ten_grd.egg-info/top_level.txt +1 -0
- ten_grd-0.2.0/tests/test_cache_adapter.py +125 -0
- ten_grd-0.2.0/tests/test_incident_patterns.py +60 -0
- ten_grd-0.2.0/tests/test_isolation.py +287 -0
- ten_grd-0.2.0/tests/test_langchain_adapter.py +60 -0
- ten_grd-0.2.0/tests/test_retrieval_adapter.py +131 -0
- ten_grd-0.2.0/tests/test_storage_adapters.py +109 -0
ten_grd-0.2.0/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
|
|
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 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
|
|
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
|
+
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 [yyyy] [name of copyright owner]
|
|
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.
|
ten_grd-0.2.0/PKG-INFO
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ten-grd
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Tenant isolation guards for developers building agentic tools
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
Project-URL: Repository, https://github.com/Ikurira/10_grd
|
|
7
|
+
Requires-Python: >=3.10
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Requires-Dist: z3-solver<6,>=4.13
|
|
11
|
+
Provides-Extra: dev
|
|
12
|
+
Requires-Dist: pytest<10,>=8; extra == "dev"
|
|
13
|
+
Requires-Dist: fakeredis<3,>=2.30; extra == "dev"
|
|
14
|
+
Provides-Extra: postgres
|
|
15
|
+
Requires-Dist: psycopg[binary]<4,>=3.2; extra == "postgres"
|
|
16
|
+
Provides-Extra: qdrant
|
|
17
|
+
Requires-Dist: qdrant-client<2,>=1.15; extra == "qdrant"
|
|
18
|
+
Provides-Extra: redis
|
|
19
|
+
Requires-Dist: redis<9,>=5; extra == "redis"
|
|
20
|
+
Provides-Extra: langchain
|
|
21
|
+
Requires-Dist: langchain-core<2,>=1; extra == "langchain"
|
|
22
|
+
Provides-Extra: all
|
|
23
|
+
Requires-Dist: psycopg[binary]<4,>=3.2; extra == "all"
|
|
24
|
+
Requires-Dist: qdrant-client<2,>=1.15; extra == "all"
|
|
25
|
+
Requires-Dist: redis<9,>=5; extra == "all"
|
|
26
|
+
Requires-Dist: langchain-core<2,>=1; extra == "all"
|
|
27
|
+
Dynamic: license-file
|
|
28
|
+
|
|
29
|
+
# Tennant Guard (10-grd)
|
|
30
|
+
|
|
31
|
+
Tenant isolation primitives for developers building agentic tools in any environment.
|
|
32
|
+
|
|
33
|
+
GRD keeps the authenticated tenant scope attached to protected data operations.
|
|
34
|
+
Its Z3 engine checks whether a supported selector can include foreign-owned or
|
|
35
|
+
unlabeled data. The guarded client adds tenant scope, checks before execution,
|
|
36
|
+
and validates complete result batches before returning them.
|
|
37
|
+
|
|
38
|
+
This is a standalone project with its own audience and architecture. It has no
|
|
39
|
+
dependency on invariant-sast or AWS.
|
|
40
|
+
|
|
41
|
+
## Install from source
|
|
42
|
+
|
|
43
|
+
Requires Python 3.10 or later:
|
|
44
|
+
|
|
45
|
+
```sh
|
|
46
|
+
git clone https://github.com/Ikurira/10_grd.git
|
|
47
|
+
cd 10_grd
|
|
48
|
+
python -m pip install -e ".[dev]"
|
|
49
|
+
python -m pytest
|
|
50
|
+
python examples/agent_memory.py
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
The distribution is named `ten-grd`; the Python import is `ten_grd`.
|
|
54
|
+
This repository does not imply that a release has been published to PyPI.
|
|
55
|
+
|
|
56
|
+
## Use in an agent memory tool
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
from ten_grd import InMemoryAdapter, TenantContext, TenantGuard, tenant_scope
|
|
60
|
+
|
|
61
|
+
memory = TenantGuard(InMemoryAdapter())
|
|
62
|
+
|
|
63
|
+
# Your host authenticates the subject and validates tenant membership first.
|
|
64
|
+
with tenant_scope(TenantContext("acme", "alice", "request-1")):
|
|
65
|
+
memory.put("plan", {"text": "Acme's private plan"}, metadata={"kind": "plan"})
|
|
66
|
+
assert memory.get("plan").data["text"] == "Acme's private plan"
|
|
67
|
+
|
|
68
|
+
with tenant_scope(TenantContext("other", "bob", "request-2")):
|
|
69
|
+
assert memory.get("plan") is None
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Tenant IDs in these examples are already authenticated by the host.
|
|
73
|
+
Constructing TenantContext validates identifier format; it does **not**
|
|
74
|
+
authenticate a user or establish tenant membership. Never construct it from an
|
|
75
|
+
unchecked prompt, tool argument, or request field.
|
|
76
|
+
|
|
77
|
+
Tool implementations can call `memory.get`, `search`, `put`, and `delete`
|
|
78
|
+
inside the host-established scope. A tool argument cannot override the tenant
|
|
79
|
+
parameter because the guarded methods expose no such parameter.
|
|
80
|
+
|
|
81
|
+
## Try tenant-scoped RAG
|
|
82
|
+
|
|
83
|
+
Run a local vector retrieval and answer assembly example without API keys:
|
|
84
|
+
|
|
85
|
+
```sh
|
|
86
|
+
python -m pip install -e ".[qdrant]"
|
|
87
|
+
python examples/tenant_rag.py
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
The example seeds two tenants with the same document ID. A foreign document has
|
|
91
|
+
the closest vector, but only the active tenant's document reaches the answer.
|
|
92
|
+
It also demonstrates an OR expression attempting to widen access and an explicit
|
|
93
|
+
foreign-tenant selector returning no documents. Fixed vectors and extractive
|
|
94
|
+
answers keep the demo reproducible; production embeddings and LLM generation
|
|
95
|
+
remain host integrations. Retrieved content is still untrusted input.
|
|
96
|
+
|
|
97
|
+
See the [developer adoption roadmap](docs/roadmap.md) for release priorities.
|
|
98
|
+
The [local validation report](docs/validation.md) records tested versions,
|
|
99
|
+
results, and outstanding live-service coverage.
|
|
100
|
+
|
|
101
|
+
## Selectors and formal checks
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
from ten_grd import Eq, Or, VerificationStatus, Z3InvariantEngine
|
|
105
|
+
|
|
106
|
+
engine = Z3InvariantEngine(timeout_ms=1000)
|
|
107
|
+
context = TenantContext("acme", "alice", "request-3")
|
|
108
|
+
|
|
109
|
+
safe = engine.verify_selector(context, Eq("tenant_id", "acme"))
|
|
110
|
+
assert safe.status is VerificationStatus.PROVEN
|
|
111
|
+
|
|
112
|
+
unsafe = engine.verify_selector(
|
|
113
|
+
context, Or((Eq("tenant_id", "acme"), Eq("tenant_id", "other")))
|
|
114
|
+
)
|
|
115
|
+
assert unsafe.status is VerificationStatus.VIOLATION
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
The public selector language supports Eq, And, Or, and Not over string metadata.
|
|
119
|
+
Missing fields are modeled explicitly. Raw SQL, filter strings, caller-supplied
|
|
120
|
+
`filter_applied` flags, and unsupported expression types are not security evidence.
|
|
121
|
+
|
|
122
|
+
The guarded client always places user selectors beneath its own tenant predicate.
|
|
123
|
+
A user selector that requests another tenant returns no data; it never replaces
|
|
124
|
+
the mandatory tenant restriction.
|
|
125
|
+
|
|
126
|
+
## What this release protects
|
|
127
|
+
|
|
128
|
+
The included in-memory adapter provides atomic, tenant-partitioned create/replace,
|
|
129
|
+
read, search, and delete operations. Record ownership is separate from user data.
|
|
130
|
+
Payloads are JSON snapshots; reserved metadata cannot override tenant identity.
|
|
131
|
+
Context uses contextvars; the engine creates a separate Z3 context per check.
|
|
132
|
+
|
|
133
|
+
Only PROVEN permits execution. SAT is a violation; UNKNOWN (including solver
|
|
134
|
+
timeouts), unsupported expressions, and errors deny. Result validation occurs
|
|
135
|
+
before returning a batch. There is no runtime soft-fail option.
|
|
136
|
+
|
|
137
|
+
## Assurance boundary
|
|
138
|
+
|
|
139
|
+
A proof applies to the supported selector model. It does not prove arbitrary
|
|
140
|
+
agent code, backend implementations, prompts, or deployment security. An empty
|
|
141
|
+
selector can be safely unsatisfiable; this is not evidence of useful access.
|
|
142
|
+
|
|
143
|
+
The host authentication boundary, enforcement client, and storage adapter are
|
|
144
|
+
trusted. An in-process SDK cannot prevent hostile application code from using
|
|
145
|
+
raw credentials or bypassing the client. Custom adapters must execute exactly the
|
|
146
|
+
checked operation and uphold ownership atomically. Read-result validation cannot
|
|
147
|
+
undo an unsafe write by a faulty adapter.
|
|
148
|
+
|
|
149
|
+
Version 0.2 adds SQLite/PostgreSQL storage, Qdrant retrieval, Redis exact caching,
|
|
150
|
+
Qdrant semantic caching, and LangChain tools. See [integration setup and assurance
|
|
151
|
+
boundaries](docs/integrations.md). Authentication remains the host responsibility.
|
|
152
|
+
See [the specification](docs/technical-specification.md) and
|
|
153
|
+
[the threat model](docs/threat-model.md) for extension requirements.
|
|
154
|
+
|
|
155
|
+
## Incident-inspired regression requirements
|
|
156
|
+
|
|
157
|
+
The [security regression guide](docs/security-regression-guide.md) uses verified
|
|
158
|
+
Spring AI filter-injection and LiteLLM cache-isolation advisories to define
|
|
159
|
+
general attack patterns and adapter acceptance criteria. These are regression
|
|
160
|
+
guides, not claims of complete CVE mitigation or certification of affected third-party products.
|
|
161
|
+
|
|
162
|
+
## Integrations
|
|
163
|
+
|
|
164
|
+
Install optional backends with `python -m pip install -e ".[all]"`.
|
|
165
|
+
See [the integration guide](docs/integrations.md) for usage, supported semantics,
|
|
166
|
+
server-backed test setup, and deployment requirements.
|
|
167
|
+
|
|
168
|
+
## Development
|
|
169
|
+
|
|
170
|
+
```sh
|
|
171
|
+
python -m pip install -e ".[dev]"
|
|
172
|
+
python -m pytest -q
|
|
173
|
+
python -m compileall -q src examples
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
Tests cover foreign access, tenant scope injection, result leakage, write
|
|
177
|
+
partitioning, async/thread isolation, inconclusive solvers, evidence binding,
|
|
178
|
+
immutable snapshots, and differential checks of generated selector expressions.
|
|
179
|
+
|
|
180
|
+
Licensed under Apache-2.0.
|
ten_grd-0.2.0/README.md
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
# Tennant Guard (10-grd)
|
|
2
|
+
|
|
3
|
+
Tenant isolation primitives for developers building agentic tools in any environment.
|
|
4
|
+
|
|
5
|
+
GRD keeps the authenticated tenant scope attached to protected data operations.
|
|
6
|
+
Its Z3 engine checks whether a supported selector can include foreign-owned or
|
|
7
|
+
unlabeled data. The guarded client adds tenant scope, checks before execution,
|
|
8
|
+
and validates complete result batches before returning them.
|
|
9
|
+
|
|
10
|
+
This is a standalone project with its own audience and architecture. It has no
|
|
11
|
+
dependency on invariant-sast or AWS.
|
|
12
|
+
|
|
13
|
+
## Install from source
|
|
14
|
+
|
|
15
|
+
Requires Python 3.10 or later:
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
git clone https://github.com/Ikurira/10_grd.git
|
|
19
|
+
cd 10_grd
|
|
20
|
+
python -m pip install -e ".[dev]"
|
|
21
|
+
python -m pytest
|
|
22
|
+
python examples/agent_memory.py
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
The distribution is named `ten-grd`; the Python import is `ten_grd`.
|
|
26
|
+
This repository does not imply that a release has been published to PyPI.
|
|
27
|
+
|
|
28
|
+
## Use in an agent memory tool
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
from ten_grd import InMemoryAdapter, TenantContext, TenantGuard, tenant_scope
|
|
32
|
+
|
|
33
|
+
memory = TenantGuard(InMemoryAdapter())
|
|
34
|
+
|
|
35
|
+
# Your host authenticates the subject and validates tenant membership first.
|
|
36
|
+
with tenant_scope(TenantContext("acme", "alice", "request-1")):
|
|
37
|
+
memory.put("plan", {"text": "Acme's private plan"}, metadata={"kind": "plan"})
|
|
38
|
+
assert memory.get("plan").data["text"] == "Acme's private plan"
|
|
39
|
+
|
|
40
|
+
with tenant_scope(TenantContext("other", "bob", "request-2")):
|
|
41
|
+
assert memory.get("plan") is None
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Tenant IDs in these examples are already authenticated by the host.
|
|
45
|
+
Constructing TenantContext validates identifier format; it does **not**
|
|
46
|
+
authenticate a user or establish tenant membership. Never construct it from an
|
|
47
|
+
unchecked prompt, tool argument, or request field.
|
|
48
|
+
|
|
49
|
+
Tool implementations can call `memory.get`, `search`, `put`, and `delete`
|
|
50
|
+
inside the host-established scope. A tool argument cannot override the tenant
|
|
51
|
+
parameter because the guarded methods expose no such parameter.
|
|
52
|
+
|
|
53
|
+
## Try tenant-scoped RAG
|
|
54
|
+
|
|
55
|
+
Run a local vector retrieval and answer assembly example without API keys:
|
|
56
|
+
|
|
57
|
+
```sh
|
|
58
|
+
python -m pip install -e ".[qdrant]"
|
|
59
|
+
python examples/tenant_rag.py
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
The example seeds two tenants with the same document ID. A foreign document has
|
|
63
|
+
the closest vector, but only the active tenant's document reaches the answer.
|
|
64
|
+
It also demonstrates an OR expression attempting to widen access and an explicit
|
|
65
|
+
foreign-tenant selector returning no documents. Fixed vectors and extractive
|
|
66
|
+
answers keep the demo reproducible; production embeddings and LLM generation
|
|
67
|
+
remain host integrations. Retrieved content is still untrusted input.
|
|
68
|
+
|
|
69
|
+
See the [developer adoption roadmap](docs/roadmap.md) for release priorities.
|
|
70
|
+
The [local validation report](docs/validation.md) records tested versions,
|
|
71
|
+
results, and outstanding live-service coverage.
|
|
72
|
+
|
|
73
|
+
## Selectors and formal checks
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
from ten_grd import Eq, Or, VerificationStatus, Z3InvariantEngine
|
|
77
|
+
|
|
78
|
+
engine = Z3InvariantEngine(timeout_ms=1000)
|
|
79
|
+
context = TenantContext("acme", "alice", "request-3")
|
|
80
|
+
|
|
81
|
+
safe = engine.verify_selector(context, Eq("tenant_id", "acme"))
|
|
82
|
+
assert safe.status is VerificationStatus.PROVEN
|
|
83
|
+
|
|
84
|
+
unsafe = engine.verify_selector(
|
|
85
|
+
context, Or((Eq("tenant_id", "acme"), Eq("tenant_id", "other")))
|
|
86
|
+
)
|
|
87
|
+
assert unsafe.status is VerificationStatus.VIOLATION
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
The public selector language supports Eq, And, Or, and Not over string metadata.
|
|
91
|
+
Missing fields are modeled explicitly. Raw SQL, filter strings, caller-supplied
|
|
92
|
+
`filter_applied` flags, and unsupported expression types are not security evidence.
|
|
93
|
+
|
|
94
|
+
The guarded client always places user selectors beneath its own tenant predicate.
|
|
95
|
+
A user selector that requests another tenant returns no data; it never replaces
|
|
96
|
+
the mandatory tenant restriction.
|
|
97
|
+
|
|
98
|
+
## What this release protects
|
|
99
|
+
|
|
100
|
+
The included in-memory adapter provides atomic, tenant-partitioned create/replace,
|
|
101
|
+
read, search, and delete operations. Record ownership is separate from user data.
|
|
102
|
+
Payloads are JSON snapshots; reserved metadata cannot override tenant identity.
|
|
103
|
+
Context uses contextvars; the engine creates a separate Z3 context per check.
|
|
104
|
+
|
|
105
|
+
Only PROVEN permits execution. SAT is a violation; UNKNOWN (including solver
|
|
106
|
+
timeouts), unsupported expressions, and errors deny. Result validation occurs
|
|
107
|
+
before returning a batch. There is no runtime soft-fail option.
|
|
108
|
+
|
|
109
|
+
## Assurance boundary
|
|
110
|
+
|
|
111
|
+
A proof applies to the supported selector model. It does not prove arbitrary
|
|
112
|
+
agent code, backend implementations, prompts, or deployment security. An empty
|
|
113
|
+
selector can be safely unsatisfiable; this is not evidence of useful access.
|
|
114
|
+
|
|
115
|
+
The host authentication boundary, enforcement client, and storage adapter are
|
|
116
|
+
trusted. An in-process SDK cannot prevent hostile application code from using
|
|
117
|
+
raw credentials or bypassing the client. Custom adapters must execute exactly the
|
|
118
|
+
checked operation and uphold ownership atomically. Read-result validation cannot
|
|
119
|
+
undo an unsafe write by a faulty adapter.
|
|
120
|
+
|
|
121
|
+
Version 0.2 adds SQLite/PostgreSQL storage, Qdrant retrieval, Redis exact caching,
|
|
122
|
+
Qdrant semantic caching, and LangChain tools. See [integration setup and assurance
|
|
123
|
+
boundaries](docs/integrations.md). Authentication remains the host responsibility.
|
|
124
|
+
See [the specification](docs/technical-specification.md) and
|
|
125
|
+
[the threat model](docs/threat-model.md) for extension requirements.
|
|
126
|
+
|
|
127
|
+
## Incident-inspired regression requirements
|
|
128
|
+
|
|
129
|
+
The [security regression guide](docs/security-regression-guide.md) uses verified
|
|
130
|
+
Spring AI filter-injection and LiteLLM cache-isolation advisories to define
|
|
131
|
+
general attack patterns and adapter acceptance criteria. These are regression
|
|
132
|
+
guides, not claims of complete CVE mitigation or certification of affected third-party products.
|
|
133
|
+
|
|
134
|
+
## Integrations
|
|
135
|
+
|
|
136
|
+
Install optional backends with `python -m pip install -e ".[all]"`.
|
|
137
|
+
See [the integration guide](docs/integrations.md) for usage, supported semantics,
|
|
138
|
+
server-backed test setup, and deployment requirements.
|
|
139
|
+
|
|
140
|
+
## Development
|
|
141
|
+
|
|
142
|
+
```sh
|
|
143
|
+
python -m pip install -e ".[dev]"
|
|
144
|
+
python -m pytest -q
|
|
145
|
+
python -m compileall -q src examples
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Tests cover foreign access, tenant scope injection, result leakage, write
|
|
149
|
+
partitioning, async/thread isolation, inconclusive solvers, evidence binding,
|
|
150
|
+
immutable snapshots, and differential checks of generated selector expressions.
|
|
151
|
+
|
|
152
|
+
Licensed under Apache-2.0.
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "ten-grd"
|
|
7
|
+
version = "0.2.0"
|
|
8
|
+
description = "Tenant isolation guards for developers building agentic tools"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = "Apache-2.0"
|
|
12
|
+
dependencies = ["z3-solver>=4.13,<6"]
|
|
13
|
+
|
|
14
|
+
[project.optional-dependencies]
|
|
15
|
+
dev = ["pytest>=8,<10", "fakeredis>=2.30,<3"]
|
|
16
|
+
postgres = ["psycopg[binary]>=3.2,<4"]
|
|
17
|
+
qdrant = ["qdrant-client>=1.15,<2"]
|
|
18
|
+
redis = ["redis>=5,<9"]
|
|
19
|
+
langchain = ["langchain-core>=1,<2"]
|
|
20
|
+
all = ["psycopg[binary]>=3.2,<4", "qdrant-client>=1.15,<2", "redis>=5,<9", "langchain-core>=1,<2"]
|
|
21
|
+
|
|
22
|
+
[project.urls]
|
|
23
|
+
Repository = "https://github.com/Ikurira/10_grd"
|
|
24
|
+
|
|
25
|
+
[tool.setuptools.packages.find]
|
|
26
|
+
where = ["src"]
|
|
27
|
+
|
|
28
|
+
[tool.pytest.ini_options]
|
|
29
|
+
testpaths = ["tests"]
|
|
30
|
+
pythonpath = ["src"]
|
ten_grd-0.2.0/setup.cfg
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"""Tennant Guard: tenant isolation primitives for agentic developers."""
|
|
2
|
+
from .adapters import InMemoryAdapter, IsolationAdapter
|
|
3
|
+
from .client import TenantGuard
|
|
4
|
+
from .context import TenantContext, current_context, tenant_scope
|
|
5
|
+
from .engine import VerificationResult, VerificationStatus, Z3InvariantEngine
|
|
6
|
+
from .exceptions import (GuardError, InvalidContextError, InvalidOperationError,
|
|
7
|
+
IsolationViolationError, VerificationError, AdapterError)
|
|
8
|
+
from .predicates import And, Eq, Not, Or
|
|
9
|
+
|
|
10
|
+
__version__ = "0.2.0"
|
|
11
|
+
__all__ = [
|
|
12
|
+
"TenantGuard", "TenantContext", "tenant_scope", "current_context",
|
|
13
|
+
"InMemoryAdapter", "IsolationAdapter", "Z3InvariantEngine",
|
|
14
|
+
"VerificationResult", "VerificationStatus", "Eq", "And", "Or", "Not",
|
|
15
|
+
"GuardError", "InvalidContextError", "InvalidOperationError",
|
|
16
|
+
"IsolationViolationError", "VerificationError", "AdapterError",
|
|
17
|
+
]
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"""Trusted adapter contract and atomic, in-memory reference implementation."""
|
|
2
|
+
from threading import RLock
|
|
3
|
+
from typing import Protocol
|
|
4
|
+
|
|
5
|
+
from .exceptions import InvalidOperationError, IsolationViolationError
|
|
6
|
+
from .operations import Operation, OperationKind, Record
|
|
7
|
+
from .predicates import matches
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class IsolationAdapter(Protocol):
|
|
11
|
+
"""Implementations must preserve the exact checked operation semantics.
|
|
12
|
+
|
|
13
|
+
An adapter is trusted enforcement code, not an untrusted plugin. Backend
|
|
14
|
+
implementations must bind ownership atomically and document model fidelity.
|
|
15
|
+
"""
|
|
16
|
+
def execute(self, operation: Operation) -> tuple[Record, ...]: ...
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class InMemoryAdapter:
|
|
20
|
+
"""Reference metadata semantics; intentionally not a persistent backend."""
|
|
21
|
+
|
|
22
|
+
def __init__(self):
|
|
23
|
+
self._records: dict[tuple[str, str], Record] = {}
|
|
24
|
+
self._lock = RLock()
|
|
25
|
+
|
|
26
|
+
def execute(self, operation: Operation) -> tuple[Record, ...]:
|
|
27
|
+
if type(operation) is not Operation:
|
|
28
|
+
raise InvalidOperationError("Expected an Operation")
|
|
29
|
+
operation.validate()
|
|
30
|
+
with self._lock:
|
|
31
|
+
if operation.kind is OperationKind.SEARCH:
|
|
32
|
+
return tuple(record for record in self._records.values()
|
|
33
|
+
if record.tenant_id == operation.tenant_id
|
|
34
|
+
and matches(operation.selector, record.fields()))
|
|
35
|
+
key = (operation.tenant_id, operation.record_id)
|
|
36
|
+
if operation.kind is OperationKind.PUT:
|
|
37
|
+
record = operation.record
|
|
38
|
+
if (record.tenant_id != operation.tenant_id
|
|
39
|
+
or not matches(operation.selector, record.fields())):
|
|
40
|
+
raise IsolationViolationError("Write does not satisfy its checked scope")
|
|
41
|
+
self._records[key] = record
|
|
42
|
+
return (record,)
|
|
43
|
+
record = self._records.get(key)
|
|
44
|
+
if record is None or not matches(operation.selector, record.fields()):
|
|
45
|
+
return ()
|
|
46
|
+
if operation.kind is OperationKind.DELETE:
|
|
47
|
+
del self._records[key]
|
|
48
|
+
return (record,)
|