permdiff 0.1.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.
Files changed (203) hide show
  1. permdiff-0.1.0/.gitignore +14 -0
  2. permdiff-0.1.0/LICENSE +202 -0
  3. permdiff-0.1.0/PKG-INFO +196 -0
  4. permdiff-0.1.0/README.md +164 -0
  5. permdiff-0.1.0/pyproject.toml +118 -0
  6. permdiff-0.1.0/src/permdiff/__init__.py +26 -0
  7. permdiff-0.1.0/src/permdiff/_proc.py +69 -0
  8. permdiff-0.1.0/src/permdiff/api.py +203 -0
  9. permdiff-0.1.0/src/permdiff/cli/__init__.py +1 -0
  10. permdiff-0.1.0/src/permdiff/cli/_render.py +115 -0
  11. permdiff-0.1.0/src/permdiff/cli/check.py +50 -0
  12. permdiff-0.1.0/src/permdiff/cli/convert.py +62 -0
  13. permdiff-0.1.0/src/permdiff/cli/demo.py +90 -0
  14. permdiff-0.1.0/src/permdiff/cli/diff.py +91 -0
  15. permdiff-0.1.0/src/permdiff/cli/init.py +43 -0
  16. permdiff-0.1.0/src/permdiff/cli/main.py +85 -0
  17. permdiff-0.1.0/src/permdiff/cli/render.py +80 -0
  18. permdiff-0.1.0/src/permdiff/cli/schema.py +14 -0
  19. permdiff-0.1.0/src/permdiff/cli/settings.py +316 -0
  20. permdiff-0.1.0/src/permdiff/cli/setup.py +27 -0
  21. permdiff-0.1.0/src/permdiff/config/__init__.py +17 -0
  22. permdiff-0.1.0/src/permdiff/config/load.py +144 -0
  23. permdiff-0.1.0/src/permdiff/config/model.py +67 -0
  24. permdiff-0.1.0/src/permdiff/config/write.py +52 -0
  25. permdiff-0.1.0/src/permdiff/demo/__init__.py +15 -0
  26. permdiff-0.1.0/src/permdiff/demo/corpus.jsonl +200 -0
  27. permdiff-0.1.0/src/permdiff/demo/engine.py +85 -0
  28. permdiff-0.1.0/src/permdiff/demo/policy_base/agent.cedar +19 -0
  29. permdiff-0.1.0/src/permdiff/demo/policy_base/agent.rego +23 -0
  30. permdiff-0.1.0/src/permdiff/demo/policy_base/rules.py +22 -0
  31. permdiff-0.1.0/src/permdiff/demo/policy_base/schema.cedarschema +11 -0
  32. permdiff-0.1.0/src/permdiff/demo/policy_head/agent.cedar +30 -0
  33. permdiff-0.1.0/src/permdiff/demo/policy_head/agent.rego +47 -0
  34. permdiff-0.1.0/src/permdiff/demo/policy_head/rules.py +31 -0
  35. permdiff-0.1.0/src/permdiff/demo/policy_head/schema.cedarschema +11 -0
  36. permdiff-0.1.0/src/permdiff/errors.py +39 -0
  37. permdiff-0.1.0/src/permdiff/evaluators/__init__.py +7 -0
  38. permdiff-0.1.0/src/permdiff/evaluators/base.py +61 -0
  39. permdiff-0.1.0/src/permdiff/evaluators/cedar/__init__.py +24 -0
  40. permdiff-0.1.0/src/permdiff/evaluators/cedar/evaluator.py +160 -0
  41. permdiff-0.1.0/src/permdiff/evaluators/cedar/loader.py +127 -0
  42. permdiff-0.1.0/src/permdiff/evaluators/cedar/request.py +137 -0
  43. permdiff-0.1.0/src/permdiff/evaluators/opa/__init__.py +16 -0
  44. permdiff-0.1.0/src/permdiff/evaluators/opa/binary.py +195 -0
  45. permdiff-0.1.0/src/permdiff/evaluators/opa/capabilities.py +76 -0
  46. permdiff-0.1.0/src/permdiff/evaluators/opa/evaluator.py +283 -0
  47. permdiff-0.1.0/src/permdiff/evaluators/opa/mapping.py +86 -0
  48. permdiff-0.1.0/src/permdiff/evaluators/opa/ndcache.py +72 -0
  49. permdiff-0.1.0/src/permdiff/evaluators/opa/shim.py +105 -0
  50. permdiff-0.1.0/src/permdiff/evaluators/python_callable.py +65 -0
  51. permdiff-0.1.0/src/permdiff/evaluators/registry.py +109 -0
  52. permdiff-0.1.0/src/permdiff/importers/__init__.py +7 -0
  53. permdiff-0.1.0/src/permdiff/importers/base.py +40 -0
  54. permdiff-0.1.0/src/permdiff/importers/custody.py +167 -0
  55. permdiff-0.1.0/src/permdiff/importers/filters.py +84 -0
  56. permdiff-0.1.0/src/permdiff/importers/jsonl.py +57 -0
  57. permdiff-0.1.0/src/permdiff/importers/limits.py +30 -0
  58. permdiff-0.1.0/src/permdiff/importers/lines.py +67 -0
  59. permdiff-0.1.0/src/permdiff/importers/otel/__init__.py +85 -0
  60. permdiff-0.1.0/src/permdiff/importers/otel/anyvalue.py +51 -0
  61. permdiff-0.1.0/src/permdiff/importers/otel/fallback.py +85 -0
  62. permdiff-0.1.0/src/permdiff/importers/otel/mapping.py +150 -0
  63. permdiff-0.1.0/src/permdiff/importers/otel/spans.py +84 -0
  64. permdiff-0.1.0/src/permdiff/importers/registry.py +113 -0
  65. permdiff-0.1.0/src/permdiff/models/__init__.py +39 -0
  66. permdiff-0.1.0/src/permdiff/models/base.py +11 -0
  67. permdiff-0.1.0/src/permdiff/models/decision.py +98 -0
  68. permdiff-0.1.0/src/permdiff/models/limits.py +33 -0
  69. permdiff-0.1.0/src/permdiff/models/report.py +57 -0
  70. permdiff-0.1.0/src/permdiff/models/toolcall.py +91 -0
  71. permdiff-0.1.0/src/permdiff/models/transition.py +48 -0
  72. permdiff-0.1.0/src/permdiff/policy/__init__.py +23 -0
  73. permdiff-0.1.0/src/permdiff/policy/git.py +83 -0
  74. permdiff-0.1.0/src/permdiff/policy/source.py +126 -0
  75. permdiff-0.1.0/src/permdiff/py.typed +0 -0
  76. permdiff-0.1.0/src/permdiff/redact/__init__.py +7 -0
  77. permdiff-0.1.0/src/permdiff/redact/redactor.py +206 -0
  78. permdiff-0.1.0/src/permdiff/replay/__init__.py +7 -0
  79. permdiff-0.1.0/src/permdiff/replay/runner.py +114 -0
  80. permdiff-0.1.0/src/permdiff/report/__init__.py +34 -0
  81. permdiff-0.1.0/src/permdiff/report/exit_codes.py +61 -0
  82. permdiff-0.1.0/src/permdiff/report/grouping.py +143 -0
  83. permdiff-0.1.0/src/permdiff/report/json_.py +86 -0
  84. permdiff-0.1.0/src/permdiff/report/markdown.py +134 -0
  85. permdiff-0.1.0/src/permdiff/report/sarif.py +172 -0
  86. permdiff-0.1.0/src/permdiff/report/summary.py +77 -0
  87. permdiff-0.1.0/src/permdiff/report/terminal.py +149 -0
  88. permdiff-0.1.0/src/permdiff/report/view.py +88 -0
  89. permdiff-0.1.0/src/permdiff/schemas/__init__.py +47 -0
  90. permdiff-0.1.0/src/permdiff/schemas/decision.json +75 -0
  91. permdiff-0.1.0/src/permdiff/schemas/report.json +733 -0
  92. permdiff-0.1.0/src/permdiff/schemas/toolcall.json +261 -0
  93. permdiff-0.1.0/tests/__init__.py +0 -0
  94. permdiff-0.1.0/tests/conftest.py +176 -0
  95. permdiff-0.1.0/tests/fixtures/__init__.py +0 -0
  96. permdiff-0.1.0/tests/fixtures/cedar/basic/entities.json +5 -0
  97. permdiff-0.1.0/tests/fixtures/cedar/basic/policy.cedar +37 -0
  98. permdiff-0.1.0/tests/fixtures/cedar/basic/schema.cedarschema +4 -0
  99. permdiff-0.1.0/tests/fixtures/cedar/broken/policy.cedar +1 -0
  100. permdiff-0.1.0/tests/fixtures/custody/README.md +1 -0
  101. permdiff-0.1.0/tests/fixtures/custody/all_types.jsonl +8 -0
  102. permdiff-0.1.0/tests/fixtures/custody/digest_only.jsonl +1 -0
  103. permdiff-0.1.0/tests/fixtures/custody/invalid.jsonl +4 -0
  104. permdiff-0.1.0/tests/fixtures/custody/unknown_schema.jsonl +1 -0
  105. permdiff-0.1.0/tests/fixtures/opa/bad_builtin/agent.rego +9 -0
  106. permdiff-0.1.0/tests/fixtures/opa/basic/agent.rego +27 -0
  107. permdiff-0.1.0/tests/fixtures/opa/bool/agent.rego +7 -0
  108. permdiff-0.1.0/tests/fixtures/opa/hours/agent.rego +11 -0
  109. permdiff-0.1.0/tests/fixtures/opa/http/agent.rego +10 -0
  110. permdiff-0.1.0/tests/fixtures/opa/rand/agent.rego +9 -0
  111. permdiff-0.1.0/tests/fixtures/opa/undefined/agent.rego +5 -0
  112. permdiff-0.1.0/tests/fixtures/opa/v0/agent.rego +5 -0
  113. permdiff-0.1.0/tests/fixtures/otel/README.md +1 -0
  114. permdiff-0.1.0/tests/fixtures/otel/execute_tool.json +222 -0
  115. permdiff-0.1.0/tests/fixtures/otel/execute_tool.jsonl +2 -0
  116. permdiff-0.1.0/tests/fixtures/otel/parent_fallback.json +338 -0
  117. permdiff-0.1.0/tests/fixtures/py_engine/__init__.py +0 -0
  118. permdiff-0.1.0/tests/fixtures/py_engine/rules.py +69 -0
  119. permdiff-0.1.0/tests/golden/json_report.json +726 -0
  120. permdiff-0.1.0/tests/golden/markdown_report.md +77 -0
  121. permdiff-0.1.0/tests/golden/opa_demo_transitions.json +202 -0
  122. permdiff-0.1.0/tests/golden/sarif_report.sarif +331 -0
  123. permdiff-0.1.0/tests/golden/terminal_full.txt +31 -0
  124. permdiff-0.1.0/tests/golden/terminal_quiet.txt +12 -0
  125. permdiff-0.1.0/tests/integration/__init__.py +0 -0
  126. permdiff-0.1.0/tests/integration/test_cli_check.py +53 -0
  127. permdiff-0.1.0/tests/integration/test_cli_config.py +133 -0
  128. permdiff-0.1.0/tests/integration/test_cli_convert.py +100 -0
  129. permdiff-0.1.0/tests/integration/test_cli_demo.py +75 -0
  130. permdiff-0.1.0/tests/integration/test_cli_diff.py +330 -0
  131. permdiff-0.1.0/tests/integration/test_cli_opa.py +115 -0
  132. permdiff-0.1.0/tests/integration/test_demo_cedar.py +48 -0
  133. permdiff-0.1.0/tests/integration/test_demo_opa.py +92 -0
  134. permdiff-0.1.0/tests/redaction_harness.py +57 -0
  135. permdiff-0.1.0/tests/report_fixtures.py +111 -0
  136. permdiff-0.1.0/tests/slow/__init__.py +0 -0
  137. permdiff-0.1.0/tests/slow/test_cedar_100k.py +51 -0
  138. permdiff-0.1.0/tests/slow/test_jsonl_100k.py +43 -0
  139. permdiff-0.1.0/tests/slow/test_opa_100k.py +45 -0
  140. permdiff-0.1.0/tests/strategies.py +64 -0
  141. permdiff-0.1.0/tests/unit/__init__.py +0 -0
  142. permdiff-0.1.0/tests/unit/bench/__init__.py +0 -0
  143. permdiff-0.1.0/tests/unit/bench/test_bench.py +81 -0
  144. permdiff-0.1.0/tests/unit/cli/__init__.py +0 -0
  145. permdiff-0.1.0/tests/unit/cli/test_render_cmd.py +83 -0
  146. permdiff-0.1.0/tests/unit/cli/test_schema_cmd.py +23 -0
  147. permdiff-0.1.0/tests/unit/config/__init__.py +0 -0
  148. permdiff-0.1.0/tests/unit/config/test_load.py +132 -0
  149. permdiff-0.1.0/tests/unit/demo/__init__.py +0 -0
  150. permdiff-0.1.0/tests/unit/demo/test_corpus.py +44 -0
  151. permdiff-0.1.0/tests/unit/demo/test_engine.py +109 -0
  152. permdiff-0.1.0/tests/unit/evaluators/__init__.py +0 -0
  153. permdiff-0.1.0/tests/unit/evaluators/cedar/__init__.py +0 -0
  154. permdiff-0.1.0/tests/unit/evaluators/cedar/test_cedar.py +253 -0
  155. permdiff-0.1.0/tests/unit/evaluators/opa/__init__.py +0 -0
  156. permdiff-0.1.0/tests/unit/evaluators/opa/test_binary.py +194 -0
  157. permdiff-0.1.0/tests/unit/evaluators/opa/test_capabilities.py +61 -0
  158. permdiff-0.1.0/tests/unit/evaluators/opa/test_evaluator.py +293 -0
  159. permdiff-0.1.0/tests/unit/evaluators/opa/test_mapping.py +88 -0
  160. permdiff-0.1.0/tests/unit/evaluators/opa/test_ndcache.py +81 -0
  161. permdiff-0.1.0/tests/unit/evaluators/opa/test_shim.py +74 -0
  162. permdiff-0.1.0/tests/unit/evaluators/test_base.py +50 -0
  163. permdiff-0.1.0/tests/unit/evaluators/test_python_callable.py +118 -0
  164. permdiff-0.1.0/tests/unit/evaluators/test_registry.py +97 -0
  165. permdiff-0.1.0/tests/unit/importers/__init__.py +0 -0
  166. permdiff-0.1.0/tests/unit/importers/otel/__init__.py +0 -0
  167. permdiff-0.1.0/tests/unit/importers/otel/test_anyvalue.py +40 -0
  168. permdiff-0.1.0/tests/unit/importers/otel/test_fallback.py +54 -0
  169. permdiff-0.1.0/tests/unit/importers/otel/test_importer.py +119 -0
  170. permdiff-0.1.0/tests/unit/importers/test_custody.py +120 -0
  171. permdiff-0.1.0/tests/unit/importers/test_filters.py +105 -0
  172. permdiff-0.1.0/tests/unit/importers/test_jsonl.py +180 -0
  173. permdiff-0.1.0/tests/unit/importers/test_registry.py +119 -0
  174. permdiff-0.1.0/tests/unit/models/__init__.py +0 -0
  175. permdiff-0.1.0/tests/unit/models/test_decision.py +89 -0
  176. permdiff-0.1.0/tests/unit/models/test_report.py +30 -0
  177. permdiff-0.1.0/tests/unit/models/test_toolcall.py +157 -0
  178. permdiff-0.1.0/tests/unit/models/test_transition.py +95 -0
  179. permdiff-0.1.0/tests/unit/policy/__init__.py +0 -0
  180. permdiff-0.1.0/tests/unit/policy/test_git.py +92 -0
  181. permdiff-0.1.0/tests/unit/policy/test_source.py +145 -0
  182. permdiff-0.1.0/tests/unit/redact/__init__.py +0 -0
  183. permdiff-0.1.0/tests/unit/redact/test_redactor.py +261 -0
  184. permdiff-0.1.0/tests/unit/replay/__init__.py +0 -0
  185. permdiff-0.1.0/tests/unit/replay/test_runner.py +179 -0
  186. permdiff-0.1.0/tests/unit/report/__init__.py +0 -0
  187. permdiff-0.1.0/tests/unit/report/test_exit_codes.py +73 -0
  188. permdiff-0.1.0/tests/unit/report/test_grouping.py +98 -0
  189. permdiff-0.1.0/tests/unit/report/test_json.py +79 -0
  190. permdiff-0.1.0/tests/unit/report/test_markdown.py +143 -0
  191. permdiff-0.1.0/tests/unit/report/test_sarif.py +131 -0
  192. permdiff-0.1.0/tests/unit/report/test_summary.py +28 -0
  193. permdiff-0.1.0/tests/unit/report/test_terminal.py +160 -0
  194. permdiff-0.1.0/tests/unit/report/test_view.py +76 -0
  195. permdiff-0.1.0/tests/unit/schemas/__init__.py +0 -0
  196. permdiff-0.1.0/tests/unit/schemas/test_schema.py +66 -0
  197. permdiff-0.1.0/tests/unit/test_api.py +163 -0
  198. permdiff-0.1.0/tests/unit/test_cli_main.py +90 -0
  199. permdiff-0.1.0/tests/unit/test_errors.py +25 -0
  200. permdiff-0.1.0/tests/unit/test_hardening.py +65 -0
  201. permdiff-0.1.0/tests/unit/test_proc.py +54 -0
  202. permdiff-0.1.0/tests/unit/test_version.py +24 -0
  203. permdiff-0.1.0/tests/vendor/sarif-schema-2.1.0.json +2915 -0
@@ -0,0 +1,14 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ .venv/
4
+ .mypy_cache/
5
+ .ruff_cache/
6
+ .pytest_cache/
7
+ .hypothesis/
8
+ .coverage
9
+ coverage.xml
10
+ htmlcov/
11
+ dist/
12
+ build/
13
+ *.egg-info/
14
+ .DS_Store
permdiff-0.1.0/LICENSE ADDED
@@ -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,196 @@
1
+ Metadata-Version: 2.5
2
+ Name: permdiff
3
+ Version: 0.1.0
4
+ Summary: terraform plan for AI agent permission changes: replay recorded tool calls against a policy at two git refs and report what changes
5
+ Project-URL: Homepage, https://github.com/smhasan94/permdiff
6
+ Project-URL: Repository, https://github.com/smhasan94/permdiff
7
+ Project-URL: Issues, https://github.com/smhasan94/permdiff/issues
8
+ Author: Sharukh Hasan
9
+ License-Expression: Apache-2.0
10
+ License-File: LICENSE
11
+ Keywords: ai-agents,authorization,cedar,ci,mcp,opa,policy,rego
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Environment :: Console
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Intended Audience :: System Administrators
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Programming Language :: Python :: 3.14
22
+ Classifier: Topic :: Security
23
+ Classifier: Topic :: Software Development :: Quality Assurance
24
+ Classifier: Typing :: Typed
25
+ Requires-Python: >=3.11.4
26
+ Requires-Dist: click<9,>=8.1
27
+ Requires-Dist: pydantic<3,>=2.7
28
+ Requires-Dist: rich<16,>=13
29
+ Provides-Extra: cedar
30
+ Requires-Dist: cedarpy~=4.12; extra == 'cedar'
31
+ Description-Content-Type: text/markdown
32
+
33
+ # permdiff
34
+
35
+ `terraform plan` for AI agent permission changes.
36
+
37
+ permdiff replays a corpus of recorded agent tool calls against an authorization
38
+ policy at two git refs and reports which calls change decision: what becomes
39
+ denied, what becomes allowed, what now needs human approval, and what could not
40
+ be evaluated. It never calls a model. It replays decisions.
41
+
42
+ ```
43
+ $ permdiff diff --base origin/main --head HEAD --traces traces/*.jsonl
44
+
45
+ permdiff: origin/main → HEAD (4,812 calls, 2026-09-18 → 2026-09-25)
46
+ newly DENIED 37 aws.ec2.terminate_instance
47
+ newly ALLOWED 2 github.delete_branch ⚠ widening
48
+ now REQUIRE_APPROVAL 118 stripe.refund
49
+ can't evaluate 9 missing context: principal.department
50
+ unchanged 4,646
51
+ ```
52
+
53
+ ## Status
54
+
55
+ 0.1.0, prepared and awaiting publication (see `docs/release.md`). Progress by epic is
56
+ in `docs/03-epics.md`; changes in `CHANGELOG.md`.
57
+
58
+ ## Install
59
+
60
+ ```
61
+ pip install permdiff
62
+ ```
63
+
64
+ Python 3.11 or newer.
65
+
66
+ ## Quickstart
67
+
68
+ **1. Try it on the bundled example (30 seconds).**
69
+
70
+ ```
71
+ permdiff demo
72
+ ```
73
+
74
+ This diffs two bundled policy versions over a synthetic 200-call corpus and
75
+ prints one widening group (`github.delete_branch` newly allowed outside
76
+ prod), two tightening groups, and a can't-evaluate group where the new policy
77
+ needs a `department` attribute the traces lack. It exits `2` because a
78
+ widening was found. Nothing is downloaded and no network is used.
79
+
80
+ The demo uses the pinned OPA binary when it is installed and otherwise the
81
+ bundled Python engine. To see the Rego version:
82
+
83
+ ```
84
+ permdiff setup opa # downloads opa 1.21.0 into your user cache, checksum verified
85
+ permdiff demo --engine opa
86
+ ```
87
+
88
+ **2. Point it at your own policy and traces.**
89
+
90
+ ```
91
+ permdiff diff --base origin/main --head HEAD --policy policy/ \
92
+ --engine opa --decision data.agent.authz.decision \
93
+ --traces traces/*.jsonl
94
+ ```
95
+
96
+ With `--engine opa` every trace becomes `input`, `time.now_ns()` returns the
97
+ trace's timestamp, and the decision rule may return an object
98
+ (`{"effect": "allow|deny|require_approval", "reason": "...", "rule": "..."}`),
99
+ a boolean, or an effect string. `{"effect": "error", "kind": "missing_context",
100
+ "reason": "principal.attrs.department"}` reports a call the policy cannot
101
+ decide. Rules that stay undefined count as `deny` (`--undefined error` to
102
+ flag them instead). OPA runs with `http.send`, `net.lookup_ip_addr`,
103
+ `rand.intn`, `uuid.rfc4122`, and `opa.runtime` removed from its capabilities;
104
+ a policy that uses one is reported as nondeterministic for every call unless
105
+ you replay recorded values with `--nd-cache decision-log.json` (OPA's
106
+ `nd_builtin_cache` shape). `permdiff check` validates traces and compiles both
107
+ refs without diffing, which is what CI runs first.
108
+
109
+ **3. Put it in CI.**
110
+
111
+ ```yaml
112
+ name: permdiff
113
+ on: pull_request
114
+ permissions:
115
+ contents: read
116
+ pull-requests: write
117
+ jobs:
118
+ permdiff:
119
+ runs-on: ubuntu-latest
120
+ steps:
121
+ - uses: actions/checkout@v7
122
+ with: { fetch-depth: 0 }
123
+ - uses: smhasan94/permdiff@v0
124
+ with:
125
+ traces: traces/*.jsonl
126
+ ```
127
+
128
+ The action runs `permdiff check`, then `diff`, and upserts one PR comment marked
129
+ `<!-- permdiff -->` that updates in place on every push. The check fails on
130
+ widening (`fail-on: widen`). Fork PRs, whose token is read-only, get the same
131
+ report in the job summary and as an artifact. `sarif: "true"` adds a SARIF file
132
+ for `github/codeql-action/upload-sarif@v4`. Inputs and outputs are in
133
+ [docs/action.md](docs/action.md). Save the flags once with `permdiff init` and
134
+ commit `permdiff.toml`; flags override environment variables
135
+ (`PERMDIFF_REPORT_FAIL_ON=none`) which override the file.
136
+
137
+ For a Python policy adapter instead:
138
+
139
+ ```
140
+ permdiff diff --base origin/main --head HEAD --policy policy/ \
141
+ --engine python:authz.permdiff_adapter:evaluate \
142
+ --traces traces/*.jsonl
143
+ ```
144
+
145
+ `diff` replays every trace against the policy at both refs and prints the
146
+ summary block above. Exit code `2` means the run matched `--fail-on`
147
+ (`widen` by default), `1` means permdiff itself failed, `0` means nothing
148
+ matched. `--head WORKTREE` uses the uncommitted policy in your working tree.
149
+
150
+ Traces are JSONL, one `ToolCall` per line; `permdiff schema toolcall` prints
151
+ the JSON Schema. Reports redact argument values by default; `--show-args`
152
+ reveals named keys and `--redact none` shows everything for local use.
153
+
154
+ `--format markdown|json|sarif` and `permdiff render --from-json` produce the
155
+ other outputs; `permdiff schema report` prints the JSON report's schema. The
156
+ Cedar engine and the Custody and OpenTelemetry importers arrive in the next
157
+ epics. The design is in `docs/01-overview.md`.
158
+
159
+ ## Engines
160
+
161
+ `--engine cedar` (`pip install "permdiff[cedar]"`) loads `*.cedar` files, one
162
+ `*.cedarschema`, and `entities.json` from the policy path, validates the policies
163
+ against the schema, and evaluates every trace as a Cedar request built from the
164
+ `[cedar]` templates (`principal`, `action`, `resource`; defaults
165
+ `User::"{principal.id}"`, `Action::"{tool.name}"`, `Resource::"{resource.id}"`).
166
+ The request context is the call's arguments plus its trace context, plus
167
+ `context.call.{principal,agent,tool,resource}` and `context.now` (the trace
168
+ timestamp as a Cedar `datetime`). A deny whose forbids all carry
169
+ `@require_approval("reason")` is reported as require-approval; a missing
170
+ attribute or entity is can't-evaluate naming it. `permdiff demo --engine cedar`
171
+ runs the bundled Cedar variant.
172
+
173
+ ## Performance
174
+
175
+ 100,000 calls end to end (import, both refs, classify, markdown) on an Apple
176
+ M-series laptop, `python -m bench.run --n 100000`:
177
+
178
+ | Engine | Import | Diff (both refs) | Report | Total | Peak RSS |
179
+ |---|---:|---:|---:|---:|---:|
180
+ | Python callable | 2.4 s | 2.8 s | 0.15 s | 6.5 s | 799 MB |
181
+ | OPA 1.21.0 | 2.5 s | 8.0 s | 0.17 s | 11.8 s | 965 MB |
182
+
183
+ Cedar evaluates 100,000 calls per ref in about 12 s through cedarpy. CI runs the
184
+ benchmark on every push and fails on a 1.5x regression against `bench/baseline.json`.
185
+
186
+ `--engine opa` runs a pinned OPA binary (1.21.0, SHA-256 verified on
187
+ download; override with `--opa-bin` or `PERMDIFF_OPA_BIN`).
188
+
189
+ `--engine python:module.path:callable` calls your own Python function with
190
+ signature `(call: ToolCall, policy_dir: Path) -> Decision | str` for every
191
+ trace. **This imports and runs arbitrary code from the current environment**
192
+ with your permissions; point it only at code you would run directly.
193
+
194
+ ## License
195
+
196
+ Apache-2.0.
@@ -0,0 +1,164 @@
1
+ # permdiff
2
+
3
+ `terraform plan` for AI agent permission changes.
4
+
5
+ permdiff replays a corpus of recorded agent tool calls against an authorization
6
+ policy at two git refs and reports which calls change decision: what becomes
7
+ denied, what becomes allowed, what now needs human approval, and what could not
8
+ be evaluated. It never calls a model. It replays decisions.
9
+
10
+ ```
11
+ $ permdiff diff --base origin/main --head HEAD --traces traces/*.jsonl
12
+
13
+ permdiff: origin/main → HEAD (4,812 calls, 2026-09-18 → 2026-09-25)
14
+ newly DENIED 37 aws.ec2.terminate_instance
15
+ newly ALLOWED 2 github.delete_branch ⚠ widening
16
+ now REQUIRE_APPROVAL 118 stripe.refund
17
+ can't evaluate 9 missing context: principal.department
18
+ unchanged 4,646
19
+ ```
20
+
21
+ ## Status
22
+
23
+ 0.1.0, prepared and awaiting publication (see `docs/release.md`). Progress by epic is
24
+ in `docs/03-epics.md`; changes in `CHANGELOG.md`.
25
+
26
+ ## Install
27
+
28
+ ```
29
+ pip install permdiff
30
+ ```
31
+
32
+ Python 3.11 or newer.
33
+
34
+ ## Quickstart
35
+
36
+ **1. Try it on the bundled example (30 seconds).**
37
+
38
+ ```
39
+ permdiff demo
40
+ ```
41
+
42
+ This diffs two bundled policy versions over a synthetic 200-call corpus and
43
+ prints one widening group (`github.delete_branch` newly allowed outside
44
+ prod), two tightening groups, and a can't-evaluate group where the new policy
45
+ needs a `department` attribute the traces lack. It exits `2` because a
46
+ widening was found. Nothing is downloaded and no network is used.
47
+
48
+ The demo uses the pinned OPA binary when it is installed and otherwise the
49
+ bundled Python engine. To see the Rego version:
50
+
51
+ ```
52
+ permdiff setup opa # downloads opa 1.21.0 into your user cache, checksum verified
53
+ permdiff demo --engine opa
54
+ ```
55
+
56
+ **2. Point it at your own policy and traces.**
57
+
58
+ ```
59
+ permdiff diff --base origin/main --head HEAD --policy policy/ \
60
+ --engine opa --decision data.agent.authz.decision \
61
+ --traces traces/*.jsonl
62
+ ```
63
+
64
+ With `--engine opa` every trace becomes `input`, `time.now_ns()` returns the
65
+ trace's timestamp, and the decision rule may return an object
66
+ (`{"effect": "allow|deny|require_approval", "reason": "...", "rule": "..."}`),
67
+ a boolean, or an effect string. `{"effect": "error", "kind": "missing_context",
68
+ "reason": "principal.attrs.department"}` reports a call the policy cannot
69
+ decide. Rules that stay undefined count as `deny` (`--undefined error` to
70
+ flag them instead). OPA runs with `http.send`, `net.lookup_ip_addr`,
71
+ `rand.intn`, `uuid.rfc4122`, and `opa.runtime` removed from its capabilities;
72
+ a policy that uses one is reported as nondeterministic for every call unless
73
+ you replay recorded values with `--nd-cache decision-log.json` (OPA's
74
+ `nd_builtin_cache` shape). `permdiff check` validates traces and compiles both
75
+ refs without diffing, which is what CI runs first.
76
+
77
+ **3. Put it in CI.**
78
+
79
+ ```yaml
80
+ name: permdiff
81
+ on: pull_request
82
+ permissions:
83
+ contents: read
84
+ pull-requests: write
85
+ jobs:
86
+ permdiff:
87
+ runs-on: ubuntu-latest
88
+ steps:
89
+ - uses: actions/checkout@v7
90
+ with: { fetch-depth: 0 }
91
+ - uses: smhasan94/permdiff@v0
92
+ with:
93
+ traces: traces/*.jsonl
94
+ ```
95
+
96
+ The action runs `permdiff check`, then `diff`, and upserts one PR comment marked
97
+ `<!-- permdiff -->` that updates in place on every push. The check fails on
98
+ widening (`fail-on: widen`). Fork PRs, whose token is read-only, get the same
99
+ report in the job summary and as an artifact. `sarif: "true"` adds a SARIF file
100
+ for `github/codeql-action/upload-sarif@v4`. Inputs and outputs are in
101
+ [docs/action.md](docs/action.md). Save the flags once with `permdiff init` and
102
+ commit `permdiff.toml`; flags override environment variables
103
+ (`PERMDIFF_REPORT_FAIL_ON=none`) which override the file.
104
+
105
+ For a Python policy adapter instead:
106
+
107
+ ```
108
+ permdiff diff --base origin/main --head HEAD --policy policy/ \
109
+ --engine python:authz.permdiff_adapter:evaluate \
110
+ --traces traces/*.jsonl
111
+ ```
112
+
113
+ `diff` replays every trace against the policy at both refs and prints the
114
+ summary block above. Exit code `2` means the run matched `--fail-on`
115
+ (`widen` by default), `1` means permdiff itself failed, `0` means nothing
116
+ matched. `--head WORKTREE` uses the uncommitted policy in your working tree.
117
+
118
+ Traces are JSONL, one `ToolCall` per line; `permdiff schema toolcall` prints
119
+ the JSON Schema. Reports redact argument values by default; `--show-args`
120
+ reveals named keys and `--redact none` shows everything for local use.
121
+
122
+ `--format markdown|json|sarif` and `permdiff render --from-json` produce the
123
+ other outputs; `permdiff schema report` prints the JSON report's schema. The
124
+ Cedar engine and the Custody and OpenTelemetry importers arrive in the next
125
+ epics. The design is in `docs/01-overview.md`.
126
+
127
+ ## Engines
128
+
129
+ `--engine cedar` (`pip install "permdiff[cedar]"`) loads `*.cedar` files, one
130
+ `*.cedarschema`, and `entities.json` from the policy path, validates the policies
131
+ against the schema, and evaluates every trace as a Cedar request built from the
132
+ `[cedar]` templates (`principal`, `action`, `resource`; defaults
133
+ `User::"{principal.id}"`, `Action::"{tool.name}"`, `Resource::"{resource.id}"`).
134
+ The request context is the call's arguments plus its trace context, plus
135
+ `context.call.{principal,agent,tool,resource}` and `context.now` (the trace
136
+ timestamp as a Cedar `datetime`). A deny whose forbids all carry
137
+ `@require_approval("reason")` is reported as require-approval; a missing
138
+ attribute or entity is can't-evaluate naming it. `permdiff demo --engine cedar`
139
+ runs the bundled Cedar variant.
140
+
141
+ ## Performance
142
+
143
+ 100,000 calls end to end (import, both refs, classify, markdown) on an Apple
144
+ M-series laptop, `python -m bench.run --n 100000`:
145
+
146
+ | Engine | Import | Diff (both refs) | Report | Total | Peak RSS |
147
+ |---|---:|---:|---:|---:|---:|
148
+ | Python callable | 2.4 s | 2.8 s | 0.15 s | 6.5 s | 799 MB |
149
+ | OPA 1.21.0 | 2.5 s | 8.0 s | 0.17 s | 11.8 s | 965 MB |
150
+
151
+ Cedar evaluates 100,000 calls per ref in about 12 s through cedarpy. CI runs the
152
+ benchmark on every push and fails on a 1.5x regression against `bench/baseline.json`.
153
+
154
+ `--engine opa` runs a pinned OPA binary (1.21.0, SHA-256 verified on
155
+ download; override with `--opa-bin` or `PERMDIFF_OPA_BIN`).
156
+
157
+ `--engine python:module.path:callable` calls your own Python function with
158
+ signature `(call: ToolCall, policy_dir: Path) -> Decision | str` for every
159
+ trace. **This imports and runs arbitrary code from the current environment**
160
+ with your permissions; point it only at code you would run directly.
161
+
162
+ ## License
163
+
164
+ Apache-2.0.