quaspar-shield-core 0.5.0a2__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.
- quaspar_shield_core-0.5.0a2/LICENSE +202 -0
- quaspar_shield_core-0.5.0a2/MANIFEST.in +4 -0
- quaspar_shield_core-0.5.0a2/PKG-INFO +294 -0
- quaspar_shield_core-0.5.0a2/README.md +278 -0
- quaspar_shield_core-0.5.0a2/RELEASE_NOTES.md +11 -0
- quaspar_shield_core-0.5.0a2/SECURITY.md +5 -0
- quaspar_shield_core-0.5.0a2/examples/summarize_note.py +63 -0
- quaspar_shield_core-0.5.0a2/pyproject.toml +31 -0
- quaspar_shield_core-0.5.0a2/quaspar_shield/__init__.py +20 -0
- quaspar_shield_core-0.5.0a2/quaspar_shield/checkpoints.py +55 -0
- quaspar_shield_core-0.5.0a2/quaspar_shield/cli.py +134 -0
- quaspar_shield_core-0.5.0a2/quaspar_shield/concurrency_check.py +151 -0
- quaspar_shield_core-0.5.0a2/quaspar_shield/containment_check.py +105 -0
- quaspar_shield_core-0.5.0a2/quaspar_shield/default_summarize_note.py +63 -0
- quaspar_shield_core-0.5.0a2/quaspar_shield/demo.py +31 -0
- quaspar_shield_core-0.5.0a2/quaspar_shield/firewall_demo.py +243 -0
- quaspar_shield_core-0.5.0a2/quaspar_shield/firewall_files.py +161 -0
- quaspar_shield_core-0.5.0a2/quaspar_shield/firewall_ingress.py +134 -0
- quaspar_shield_core-0.5.0a2/quaspar_shield/firewall_run.py +220 -0
- quaspar_shield_core-0.5.0a2/quaspar_shield/local_demo.py +76 -0
- quaspar_shield_core-0.5.0a2/quaspar_shield/local_queue.py +135 -0
- quaspar_shield_core-0.5.0a2/quaspar_shield/model_job.py +1250 -0
- quaspar_shield_core-0.5.0a2/quaspar_shield/model_transport.py +349 -0
- quaspar_shield_core-0.5.0a2/quaspar_shield/proposal_check.py +123 -0
- quaspar_shield_core-0.5.0a2/quaspar_shield/review.py +91 -0
- quaspar_shield_core-0.5.0a2/quaspar_shield/sdk.py +273 -0
- quaspar_shield_core-0.5.0a2/quaspar_shield_core.egg-info/PKG-INFO +294 -0
- quaspar_shield_core-0.5.0a2/quaspar_shield_core.egg-info/SOURCES.txt +50 -0
- quaspar_shield_core-0.5.0a2/quaspar_shield_core.egg-info/dependency_links.txt +1 -0
- quaspar_shield_core-0.5.0a2/quaspar_shield_core.egg-info/entry_points.txt +5 -0
- quaspar_shield_core-0.5.0a2/quaspar_shield_core.egg-info/requires.txt +1 -0
- quaspar_shield_core-0.5.0a2/quaspar_shield_core.egg-info/top_level.txt +1 -0
- quaspar_shield_core-0.5.0a2/setup.cfg +4 -0
- quaspar_shield_core-0.5.0a2/tests/test_checkpoints.py +33 -0
- quaspar_shield_core-0.5.0a2/tests/test_cli.py +78 -0
- quaspar_shield_core-0.5.0a2/tests/test_concurrency_check.py +36 -0
- quaspar_shield_core-0.5.0a2/tests/test_containment.py +165 -0
- quaspar_shield_core-0.5.0a2/tests/test_developer_install.py +90 -0
- quaspar_shield_core-0.5.0a2/tests/test_firewall_demo.py +35 -0
- quaspar_shield_core-0.5.0a2/tests/test_firewall_files.py +164 -0
- quaspar_shield_core-0.5.0a2/tests/test_firewall_ingress.py +151 -0
- quaspar_shield_core-0.5.0a2/tests/test_firewall_run.py +82 -0
- quaspar_shield_core-0.5.0a2/tests/test_live_scanner.py +114 -0
- quaspar_shield_core-0.5.0a2/tests/test_local_queue.py +130 -0
- quaspar_shield_core-0.5.0a2/tests/test_model_job.py +633 -0
- quaspar_shield_core-0.5.0a2/tests/test_model_transport.py +127 -0
- quaspar_shield_core-0.5.0a2/tests/test_proposal_check.py +54 -0
- quaspar_shield_core-0.5.0a2/tests/test_review.py +41 -0
- quaspar_shield_core-0.5.0a2/tests/test_routine_queue.py +160 -0
- quaspar_shield_core-0.5.0a2/tests/test_sdist_sample.py +79 -0
- quaspar_shield_core-0.5.0a2/tests/test_sdk.py +175 -0
- quaspar_shield_core-0.5.0a2/tests/test_worker_integrity.py +129 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: quaspar-shield-core
|
|
3
|
+
Version: 0.5.0a2
|
|
4
|
+
Summary: Local per-agent request filtering, file screening, isolated workers, and one host-owned text connector
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
Project-URL: Homepage, https://quaspar.com
|
|
7
|
+
Project-URL: Security, https://quaspar.com/security
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Topic :: Security
|
|
11
|
+
Requires-Python: >=3.11
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Requires-Dist: cryptography>=46
|
|
15
|
+
Dynamic: license-file
|
|
16
|
+
|
|
17
|
+
# Charavyuha by Quaspar
|
|
18
|
+
|
|
19
|
+
Charavyuha is an Apache-2.0 Python library for controlling which signed requests reach your agent. A trusted host enrolls senders, defines the exact work each may do, and runs your handler only after the checks pass. Routine authorized work needs zero review prompts. The optional native worker runs a compatible Python file in an isolated Linux process.
|
|
20
|
+
|
|
21
|
+
## Install and try the signed inbox
|
|
22
|
+
|
|
23
|
+
Use Python 3.11 or newer. When this version is available on PyPI, install it in your virtual environment with `python -m pip install quaspar-shield-core==0.5.0a2`. To install the downloadable alpha directly, extract its ZIP. On Linux use `sha256sum -c SHA256SUMS` to verify the installation guide and both distribution files. From the directory containing the wheel, create a virtual environment and install the wheel. Pip also installs the cryptography dependency.
|
|
24
|
+
|
|
25
|
+
**macOS or Linux**
|
|
26
|
+
|
|
27
|
+
```sh
|
|
28
|
+
python3 -m venv .venv
|
|
29
|
+
. .venv/bin/activate
|
|
30
|
+
python -m pip install ./quaspar_shield_core-0.5.0a2-py3-none-any.whl
|
|
31
|
+
quaspar-shield inbox
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
**Windows PowerShell**
|
|
35
|
+
|
|
36
|
+
```powershell
|
|
37
|
+
py -3 -m venv .venv
|
|
38
|
+
.\.venv\Scripts\python.exe -m pip install .\quaspar_shield_core-0.5.0a2-py3-none-any.whl
|
|
39
|
+
.\.venv\Scripts\quaspar-shield.exe inbox
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
The inbox example uses disposable identities and a local callback. Two signed jobs reach the callback. An unknown sender, a duplicate request, and a request over the shared limit are refused. You can run it without an account, API key or scanner. If you have the source archive instead, pass its `.tar.gz` path to the same pip install command.
|
|
43
|
+
|
|
44
|
+
## Run your first isolated worker on Linux
|
|
45
|
+
|
|
46
|
+
The native profile supports 64-bit x86 Linux with Debian-style system Python. On Debian or Ubuntu the relevant packages are `python3`, `python3-venv`, `bubblewrap`, `util-linux` and `libseccomp2`. Your host policy must allow bubblewrap to create its user namespace. A Linux VM with those prerequisites is an option for developers who use another operating system.
|
|
47
|
+
|
|
48
|
+
```sh
|
|
49
|
+
quaspar-shield
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
This verifies the native sandbox and runs the bundled worker on a synthetic note. A successful job reports an automatic decision, zero review prompts and one local fixture exchange. Your agent can make its first protected run without sending a prompt to an external provider. Use `quaspar-shield doctor` to diagnose host prerequisites.
|
|
53
|
+
|
|
54
|
+
To start from an editable worker, run the following commands anywhere you can write. Open `my_agent.py` to change how it handles the supplied note and response, and run the second command again. The host supplies the attachment and holds the connector credential.
|
|
55
|
+
|
|
56
|
+
```sh
|
|
57
|
+
quaspar-shield init my_agent.py
|
|
58
|
+
quaspar-shield quickstart --agent my_agent.py
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
The native model host snapshots the worker once per job. Both stages execute those bytes, even if a deployment replaces the file while the job is running. For an approved deployment, record the reviewed worker's SHA-256 with its release in trusted host configuration. The following command reads that independently provisioned value from the environment. A mismatch refuses the job before its model worker or connector runs.
|
|
62
|
+
|
|
63
|
+
```sh
|
|
64
|
+
quaspar-shield quickstart --agent my_agent.py --worker-sha256 "${APPROVED_WORKER_SHA256:?Set the reviewed release digest}" --json
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Pinning is optional for local editing. The Python host accepts the same value in `NoteModelHost(..., expected_worker_sha256=...)` with its native worker. A pin authenticates the selected code against a reviewed release. The host continues to treat the text it produces as untrusted.
|
|
68
|
+
|
|
69
|
+
## Connect your existing agent
|
|
70
|
+
|
|
71
|
+
Keep a receiver in the trusted process that owns the action. Route incoming signed requests to its `dispatch` method. The handler below reads an assigned note. In your host, replace that handler with the corresponding agent operation. Enroll the sender’s public key in advance and deliver the receiver’s audience to that sender over your trusted setup channel.
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
import json
|
|
75
|
+
|
|
76
|
+
from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PrivateKey
|
|
77
|
+
from quaspar_shield import Action, sign_action
|
|
78
|
+
from quaspar_shield.firewall_ingress import ReceiverGate
|
|
79
|
+
|
|
80
|
+
# This runnable example creates the sender's key locally. In deployment,
|
|
81
|
+
# the sender keeps its private key and the host enrolls only the public key.
|
|
82
|
+
sender = Ed25519PrivateKey.generate()
|
|
83
|
+
notes = {"daily-note": "The blue folder is on the second shelf."}
|
|
84
|
+
job = Action("my-org", "scheduler", "daily", "note.read", "daily-note", "my-agent")
|
|
85
|
+
gate = ReceiverGate(
|
|
86
|
+
receiver="my-agent",
|
|
87
|
+
tenant="my-org",
|
|
88
|
+
sender_keys={"scheduler": sender.public_key()},
|
|
89
|
+
allowed_actions=[job],
|
|
90
|
+
handler=lambda approved: notes[approved.resource],
|
|
91
|
+
)
|
|
92
|
+
signed_request = sign_action(job, sender, audience=gate.audience)
|
|
93
|
+
print(gate.dispatch(json.dumps(signed_request)))
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Every path to this protected operation needs to pass through the gate. The inbox controls requests within one process. Native worker isolation and attachment scanning each require their own host integration. The managed Quaspar service and its private controls are separate from this alpha.
|
|
97
|
+
|
|
98
|
+
## What each control protects
|
|
99
|
+
|
|
100
|
+
| When your agent handles | What the trusted host enforces | What you configure |
|
|
101
|
+
| --- | --- | --- |
|
|
102
|
+
| A signed request | Sender identity, audience, expiry, exact task permissions, replay protection and per-process traffic limits before the handler | Route every path to the action through the same receiver and keep the handler credentials with the host. |
|
|
103
|
+
| A two-stage note job | The assigned note digest, permitted connector, authorization at dispatch, one worker snapshot and a signed decision receipt | Run a compatible worker with the native Linux host. To enforce a reviewed worker version, supply its approved SHA-256. |
|
|
104
|
+
| An incoming file | Digest match to the authorized action, a clean verdict from the expected scanner, then delivery of those same bytes | Use `ClamAVFileGate.deliver_verified` in the verified handler with a configured local daemon and updated database. |
|
|
105
|
+
| A policy-defined exception | A signed approval for that exact request within its time window | Enroll a separate reviewer key and specify which actions qualify. Routine permitted actions need no prompt. |
|
|
106
|
+
| A literal provider credential in a parsed connector reply | Suppression of the reply, a signed incident receipt and a persistent block for that assignment | Retain the model host's database and keys across restarts. Revoke or rotate a genuinely exposed credential. A reviewer signs recovery after a correction is checked. |
|
|
107
|
+
|
|
108
|
+
A signed authorization describes what may run. Judging the factual accuracy of a summary requires an application-specific check. Keep model output as data and route each subsequent action back through the host. The public package implements these local controls. Behavioral scoring, deception, endpoint rotation and hardware enclave attestation belong to the managed design.
|
|
109
|
+
|
|
110
|
+
## Check security behavior locally
|
|
111
|
+
|
|
112
|
+
### Multiple agents sharing one receiver
|
|
113
|
+
|
|
114
|
+
`python -m quaspar_shield.concurrency_check --identities 1000` enrolls 1,000 distinct synthetic signing keys against one real, in-process receiver. It checks allowed and out-of-scope assignments, holds four handler slots open to test overload, verifies recovery after the burst, and tests a separate shared budget of 32. The report gives observed counts. At saturation, even a valid request can receive `busy`. A quiet authorized job is checked both before and after the burst. The test uses at most 16 threads. Distributed network capacity, availability and fleet-wide rate limiting need separate measurements.
|
|
115
|
+
|
|
116
|
+
### Compare proposals from ChatGPT or Claude
|
|
117
|
+
|
|
118
|
+
Run `python -m quaspar_shield.proposal_check cases` and give the four fictional tasks to the model. Save its plain JSON response as `response.json`. In the following command, use `chatgpt` or `claude` for the operator-supplied source label.
|
|
119
|
+
|
|
120
|
+
```sh
|
|
121
|
+
python -m quaspar_shield.proposal_check check --source claude < response.json
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
The receiver controls enrollment, assignments and policy. The model chooses among two fictional note names. The report records each proposal, whether policy allowed it, and whether the harmless local callback actually ran. The verifier makes zero provider calls. A source label records the operator's attribution. `python -m quaspar_shield.proposal_check fixture` runs the same check with a built-in example.
|
|
125
|
+
|
|
126
|
+
### Contain an incident and verify recovery
|
|
127
|
+
|
|
128
|
+
`python -m quaspar_shield.containment_check` exercises the model connector, native offline worker and signed SQLite ledger with disposable credentials. It simulates a parsed model reply that contains the host’s configured provider credential. The host withholds that reply and commits a signed event and an exact deny rule. It checks the rule before starting new work and again at the transport handoff. Other enrolled assignments retain their existing policy.
|
|
129
|
+
|
|
130
|
+
The rule survives a restart and covers the tenant, agent, workflow, operation, resource and destination. A misleading message alone cannot install or remove it. The rule applies to future dispatches. Requests already handed to the transport may finish. If a real shared credential appears, its owner must revoke or rotate it and investigate every caller that shared it.
|
|
131
|
+
|
|
132
|
+
To release the rule, the trusted host uses `NoteModelHost.active_containment(action)` to obtain the incident ID. The reviewer checks a correction in an isolated environment and signs `containment_release_action(action, incident_id, evidence_sha256)` with the enrolled reviewer key and host audience. The host calls `release_containment` with that authorization. A replay for an earlier incident cannot release a later one. The digest binds the operator's decision to the evidence they reviewed. The drill uses a disposable reviewer and a clean staging fixture to demonstrate this sequence. A deployment keeps the reviewer key separate from the worker. A permanent code change goes through regression tests and normal review.
|
|
133
|
+
|
|
134
|
+
## Run the firewall demo
|
|
135
|
+
|
|
136
|
+
From this directory, install in a Python 3.11 or newer virtual environment.
|
|
137
|
+
|
|
138
|
+
```sh
|
|
139
|
+
python -m venv .venv
|
|
140
|
+
. .venv/bin/activate
|
|
141
|
+
python -m pip install .
|
|
142
|
+
quaspar-shield-demo
|
|
143
|
+
python -m unittest discover -s tests -v
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
The demo creates one receiving agent, enrolls two senders and admits two signed jobs. An unknown sender, a repeated signed job and a request over the shared budget are refused. The local demo generates its own keys and sends no network traffic.
|
|
147
|
+
|
|
148
|
+
### Put the receiving gate ahead of the model
|
|
149
|
+
|
|
150
|
+
Create one `quaspar_shield.firewall_ingress.ReceiverGate` in the trusted host for each receiving agent. Connect the agent's actual message entry point to `gate.dispatch(raw_envelope)`. Enroll trusted sender keys and exact permitted actions during setup, and give enrolled senders the gate's current `audience` through the trusted host. The host owns the callback and its credentials. The gate admits signed requests and invokes only the callback the host configured.
|
|
151
|
+
|
|
152
|
+
The gate limits the combined request rate before parsing or signature verification. It also checks each verified sender's budget and caps the number of concurrent admissions and callbacks. There is no queue of waiting handlers. Signatures expire and replayed requests are rejected. A restart creates a new audience. A handler failure consumes the attempted request; an application with external effects needs its own durable idempotency and reconciliation. Protect transport connections, request size before buffering, read deadlines and upstream bandwidth separately. Different processes have independent budgets. Overload can also delay legitimate senders.
|
|
153
|
+
|
|
154
|
+
### Inspect attachments before the agent receives them
|
|
155
|
+
|
|
156
|
+
On Linux, use `quaspar_shield.firewall_files.ClamAVFileGate` with a host-controlled ClamAV daemon. Pass its absolute Unix socket path and expected service UID. `deliver(content, consumer)` streams the immutable bytes to the scanner and calls the consumer with those same bytes only after an unambiguous clean verdict. A flagged file, missing scanner, wrong daemon UID, timeout, or indeterminate answer withholds the file. Keep all other attachment paths closed to that consumer. The operator provides the scanner, its signature updates, archive handling and size limits.
|
|
157
|
+
|
|
158
|
+
For a signed attachment, pass the resource digest from the verified action to the scanner. In your receiver's host-owned handler, call `scanner.deliver_verified(content, consumer, expected_sha256=action.resource)`. If the retrieved object has different bytes from the one the sender was authorized to inspect, the scanner and the consumer receive no file. Keep the approved object's digest separate from incoming unsigned metadata.
|
|
159
|
+
|
|
160
|
+
`quaspar-shield-demo --clamd-socket /absolute/path/to/clamd.sock --clamd-uid UID` runs the receiving demo and checks a harmless, signed file job. Substitute the local service's real socket path and numeric UID. The protocol fixtures in the test suite exercise clear, flagged, and unavailable results. Those fixtures do not measure malware-detection accuracy.
|
|
161
|
+
|
|
162
|
+
### Run a worker with operating-system isolation
|
|
163
|
+
|
|
164
|
+
On a compatible 64-bit x86 Linux system with Debian-style system Python, bubblewrap, prlimit and libseccomp, use `quaspar-shield-run --self-test` to verify the local worker boundary. Use `quaspar-shield-run agent.py` for a compatible, standalone offline Python file or `quaspar-shield-demo --offline-worker` for a signed job routed through the receiving gate. Charavyuha supplies a read-only program, private scratch space and a clean environment, limits resources and restricts kernel operations. Worker output is untrusted data. The host must launch the worker through Charavyuha. A worker started directly with `python agent.py` runs with its ordinary operating-system permissions. Hosted-model, browser and online-tool access require a separate connector with its own explicit policy.
|
|
165
|
+
|
|
166
|
+
With the scanner and the offline runner both configured, `quaspar-shield-demo --offline-worker --clamd-socket /absolute/path/to/clamd.sock --clamd-uid UID` exercises the combined flow. The receiving gate verifies the signed job, the scanner checks the named attachment and the host gives the isolated worker a read-only copy of the cleared bytes.
|
|
167
|
+
|
|
168
|
+
### What was tested for this alpha
|
|
169
|
+
|
|
170
|
+
On the development host, an allowed signed job completed in the real Linux worker. The worker could use its own scratch directory. The operating system denied the socket and child-process operations exercised by the self-test, and the host-only fixture stayed outside the worker's filesystem view. The worker could read its attachment but could not modify it. The combined signed-job, file-intake and worker flow was also exercised using harmless synthetic scanner replies on connected Unix sockets. A live ClamAV daemon and signature database were unavailable on that host. Before using attachment screening on a deployment, exercise the combined command against that deployment's actual scanner.
|
|
171
|
+
|
|
172
|
+
The firewall protects paths that the host routes through it. Treat a sender's identity, permission to perform a task, scanner verdict and isolated execution as separate controls. A permitted sender can still supply misleading text. Maintain tool restrictions after content reaches a model. Provider-side denial-of-service controls remain important for traffic that can exhaust a public connection before it reaches this process.
|
|
173
|
+
|
|
174
|
+
## Summarize one assigned note
|
|
175
|
+
|
|
176
|
+
On a supported Linux host, this command enrolls an ephemeral developer key, assigns one synthetic note, and runs a replaceable offline agent through one host-owned text connector. The connector in this checkpoint is the OpenAI chat-completions shape. The command uses a deterministic local fixture and does not call OpenAI. A routine job finishes with no review prompt. The printed receipt omits the note, the prompt, and the credential. `response_source` is `fixture`.
|
|
177
|
+
|
|
178
|
+
```sh
|
|
179
|
+
python -m quaspar_shield.model_job --agent examples/summarize_note.py
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
From a wheel installation, `quaspar-shield init my_agent.py` creates the same sample outside the checkout. `quaspar-shield quickstart --agent my_agent.py --json` prints the structured report.
|
|
183
|
+
|
|
184
|
+
A routine job prints `response_source=fixture` and `Review prompts: 0.` The JSON `protections` list is the diagnostic for that run. It names only the controls that executed: identity, policy, the dispatch-time authorization recheck, the native sandbox, the signed ledger, and one fixture exchange. Approval and the file scanner are listed as not used. This model command does not open a scanner socket.
|
|
185
|
+
|
|
186
|
+
On the supported Linux host, `quaspar-shield-run --self-test` must execute the kernel profile. Native CI requires the live file-intake acceptance test, so a missing clamd or signature database fails that job. With a host-controlled ClamAV daemon and signature database, the check records the engine version, signature database version, and database date. It gives the isolated worker the exact clean bytes, withholds the harmless EICAR test file, and launches no worker when the scanner is missing or presents the wrong service identity. The ordinary model command does not open a scanner.
|
|
187
|
+
|
|
188
|
+
Replace `examples/summarize_note.py` to change the worker. The replacement still runs inside the offline profile. It cannot choose the provider, the model, the HTTPS endpoint, or the credential. The host checks the signed job and the note digest before it allows one text request. A changed or out-of-scope request makes no provider call. A repeated signed request does not make a second call. A timeout is recorded for reconciliation and is not retried.
|
|
189
|
+
|
|
190
|
+
```sh
|
|
191
|
+
python -m quaspar_shield.model_job --agent examples/summarize_note.py --check
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
An action the host enrolls as a reviewable exception uses the existing signed approval. This command does not prompt for one. The per-job cost ceiling is not an account-wide budget.
|
|
195
|
+
|
|
196
|
+
## Try the protected case queue
|
|
197
|
+
|
|
198
|
+
Run `python -m quaspar_shield.local_demo` for the existing demonstration of automatic and reviewed actions.
|
|
199
|
+
|
|
200
|
+
The demo routes synthetic cases to their usual destination. It then simulates a volume exception, applies one exact approval, retries the completed request and attempts a prohibited destination. Each successful request writes one row in SQLite. That row is both the queue entry and the record that the request was used. Restarting the host with the same database preserves that record. The demo uses disposable keys for both roles. The separate `quaspar_shield.review` command below supports interactive human review.
|
|
201
|
+
|
|
202
|
+
### Configure the job once
|
|
203
|
+
|
|
204
|
+
This example assumes the host already has its own assignment list and enrolled keys. It derives the routine set from those assignments. Agent input must never populate the trusted lists.
|
|
205
|
+
|
|
206
|
+
```python
|
|
207
|
+
from pathlib import Path
|
|
208
|
+
from quaspar_shield import Action
|
|
209
|
+
from quaspar_shield.local_queue import LocalCaseQueue, ReviewRequired
|
|
210
|
+
|
|
211
|
+
normal = [Action("org-a", "worker", "intake", "case.queue", case_id, "staff-queue")
|
|
212
|
+
for case_id in assigned_case_ids]
|
|
213
|
+
exception = Action("org-a", "worker", "intake", "case.queue", "case-001", "finance-review")
|
|
214
|
+
queue = LocalCaseQueue(
|
|
215
|
+
Path("cases.db"), audience="intake-deployment", allowed_actions=[*normal, exception],
|
|
216
|
+
routine_actions=normal, routine_limit=100, window_seconds=60,
|
|
217
|
+
agent_public_key=worker_public_key, reviewer="supervisor",
|
|
218
|
+
reviewer_public_key=supervisor_public_key,
|
|
219
|
+
)
|
|
220
|
+
try:
|
|
221
|
+
receipt = queue.enqueue(signed_request_json)
|
|
222
|
+
except ReviewRequired as pending:
|
|
223
|
+
# Only this exception is eligible for a review card in the host application.
|
|
224
|
+
show_or_update_review(pending.request_digest, pending.reason)
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
Choose a volume limit from the real workflow's expected load. The example limit of 100 is illustrative. The limit counts successful writes for this deployment, tenant and agent within the rolling window. Each retry is evaluated against the current policy and window. A one-time approval covers the exact request and never widens the routine policy. Setting `routine_limit=None` omits the volume check. Enroll a nonempty routine set to enable automatic execution. Older integrations that supply only `allowed_actions` retain their approval requirements.
|
|
228
|
+
|
|
229
|
+
The queue returns the same request digest for repeated attempts that still need review, so an application can update the same card. A volume spike may include many distinct requests. A host can group those into one incident notification and still require an exact approval for any individual exception it releases. Authentication failures and actions outside the assigned job are refusals. Present only `ReviewRequired` to a human.
|
|
230
|
+
|
|
231
|
+
The queue protects one operation with an effect entirely inside SQLite. An agent with direct write access to the database or access to the reviewer’s signing key can act outside that boundary. To use the same approach with an email or payment provider, the provider credentials and dispatch path must be controlled separately, and approvals must cover all details that affect execution.
|
|
232
|
+
|
|
233
|
+
The host assigns each independent queue a distinct audience and preserves its database. Deleting a queue row or restoring an earlier copy also removes its record of use.
|
|
234
|
+
|
|
235
|
+
To see the underlying signature protocol on its own, run `python -m quaspar_shield.demo`.
|
|
236
|
+
|
|
237
|
+
## Use the SDK
|
|
238
|
+
|
|
239
|
+
```python
|
|
240
|
+
from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PrivateKey
|
|
241
|
+
from quaspar_shield import Action, sign_action, sign_approval, verify_action, verify_approval
|
|
242
|
+
|
|
243
|
+
# Disposable keys for this example. Deployment requires separate owners and enrollment.
|
|
244
|
+
worker = Ed25519PrivateKey.generate()
|
|
245
|
+
reviewer = Ed25519PrivateKey.generate()
|
|
246
|
+
action = Action("org-a", "worker", "intake", "record.release", "case-001", "review-queue")
|
|
247
|
+
request = sign_action(action, worker)
|
|
248
|
+
shown_to_reviewer = verify_action(request, worker.public_key())
|
|
249
|
+
# In a real flow, obtain an explicit decision about all six fields here.
|
|
250
|
+
approval = sign_approval(request, reviewer, reviewer="operator")
|
|
251
|
+
assert verify_approval(approval, request, reviewer.public_key()) == "operator"
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
The SDK defaults to the local audience `quaspar-shield-local`. Each actual deployment needs a unique trusted audience. Pass it as `audience=` to all four action and approval signing and verification functions, and `--audience` to the review CLI. A signature intended for staging must fail in production even if someone accidentally enrolls the same key there.
|
|
255
|
+
|
|
256
|
+
The verifier needs an independent, tenant-scoped key registry and permission map. The host must verify the agent signature and any necessary approval with its own trusted clock before execution and atomically consume the request at its tool boundary. SDK verification by itself has no side effects and stores no replay state. The two-minute validity window uses wall-clock time, with no grace interval. A reviewer who needs longer can review a fresh request.
|
|
257
|
+
|
|
258
|
+
### Offline operator review
|
|
259
|
+
|
|
260
|
+
A reviewer can sign on a separate terminal using an independently provisioned agent public key and their own encrypted Ed25519 PEM. Configure the expected tenant, agent and audience from enrollment. The command displays the audience, six action fields and expiry, then asks the reviewer to type a request-specific confirmation. It writes the signed approval JSON to stdout only after confirmation.
|
|
261
|
+
|
|
262
|
+
```sh
|
|
263
|
+
python -m quaspar_shield.review request.json \
|
|
264
|
+
--tenant org-a --agent worker --reviewer operator \
|
|
265
|
+
--agent-public-key worker-public.pem \
|
|
266
|
+
--reviewer-private-key operator-encrypted.pem > approval.json
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
This authenticates possession of the enrolled review key. Hardware-backed user presence, enterprise login, revocation and org-wide reviewer permissions require a host integration.
|
|
270
|
+
|
|
271
|
+
## Wire format v1
|
|
272
|
+
|
|
273
|
+
The signed bytes are ASCII JSON containing every envelope field except `signature`. Sort keys recursively, use comma and colon separators without spaces, and omit a trailing newline. Identifiers use `[a-z0-9][a-z0-9._-]{0,63}`. Each signature is 128 lowercase hex characters. Each nonce is 16 random bytes encoded in lowercase hex. Time fields are integer UTC Unix seconds. Accept a request only where `issued_at <= now < expires_at`; validity intervals are at most 120 seconds. Use `load_envelope` at transport ingress. It bounds input to 4 KiB and rejects duplicate JSON keys. Signature verification rejects extra fields.
|
|
274
|
+
|
|
275
|
+
| Signed purpose | Additional payload |
|
|
276
|
+
| --- | --- |
|
|
277
|
+
| `quaspar.action` | `audience` and `action` with tenant, agent, workflow, operation, resource and destination |
|
|
278
|
+
| `quaspar.approval` | `reviewer` and `request_digest`, the lowercase SHA-256 digest of the full canonical signed request including its signature |
|
|
279
|
+
|
|
280
|
+
Both have signed fields `version` (integer 1), `purpose`, `nonce`, `issued_at`, and `expires_at`. An approval's entire validity interval must fit inside the request interval. All semantics of a supported tool action must be determined by the signed fields. An adapter that introduces mutable payloads, recipient lists, amounts or other parameters needs a versioned binding covering that content before it can be supported.
|
|
281
|
+
|
|
282
|
+
## Add a restrictive check
|
|
283
|
+
|
|
284
|
+
`layers_allow(action, layers)` applies between one and 32 trusted synchronous Python callables to an already authenticated, in-scope action. Every hook must return the boolean `True`. A veto, an exception or an invalid result blocks the request. For example, a host can add `lambda a: a.destination == "review-queue"` after its own mandatory policy. Hooks run as trusted application code and should return promptly.
|
|
285
|
+
|
|
286
|
+
## Audit checkpoints
|
|
287
|
+
|
|
288
|
+
`quaspar_shield.checkpoints.sign_checkpoint(stream, count, head, signing_key)` signs a named journal head. `verify_checkpoint(proof, pinned_public_key, stream=...)` returns the authenticated event count and chain head. An independent verifier must also recompute the journal and compare both values. Pin the expected stream and signing key through a trusted channel, retain checkpoints separately from the journal, and keep a freshness record. An older, valid signature remains valid. The signed checkpoint authenticates a point in history and does not establish the truth of an event, the identity of a person or the completeness of external tool activity.
|
|
289
|
+
|
|
290
|
+
## Security reports and license
|
|
291
|
+
|
|
292
|
+
Report vulnerabilities privately at bhavesh@quaspar.com. [Quaspar's security policy](https://quaspar.com/security)
|
|
293
|
+
|
|
294
|
+
Distributed under the Apache License, Version 2.0. The license is included with the wheel and source archive.
|