keynetra 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 (172) hide show
  1. keynetra-0.1.0/LICENSE +201 -0
  2. keynetra-0.1.0/PKG-INFO +26 -0
  3. keynetra-0.1.0/README.md +238 -0
  4. keynetra-0.1.0/integrations/__init__.py +1 -0
  5. keynetra-0.1.0/integrations/interfaces.py +29 -0
  6. keynetra-0.1.0/integrations/opa_rego_adapter.py +19 -0
  7. keynetra-0.1.0/integrations/openfga_adapter.py +19 -0
  8. keynetra-0.1.0/integrations/terraform_provider.py +18 -0
  9. keynetra-0.1.0/keynetra/__init__.py +5 -0
  10. keynetra-0.1.0/keynetra/api/__init__.py +1 -0
  11. keynetra-0.1.0/keynetra/api/dependencies.py +140 -0
  12. keynetra-0.1.0/keynetra/api/errors.py +31 -0
  13. keynetra-0.1.0/keynetra/api/main.py +208 -0
  14. keynetra-0.1.0/keynetra/api/middleware/__init__.py +0 -0
  15. keynetra-0.1.0/keynetra/api/middleware/errors.py +101 -0
  16. keynetra-0.1.0/keynetra/api/middleware/idempotency.py +126 -0
  17. keynetra-0.1.0/keynetra/api/middleware/logging.py +47 -0
  18. keynetra-0.1.0/keynetra/api/middleware/request_id.py +34 -0
  19. keynetra-0.1.0/keynetra/api/middleware/tenant.py +45 -0
  20. keynetra-0.1.0/keynetra/api/middleware/versioning.py +62 -0
  21. keynetra-0.1.0/keynetra/api/pagination.py +30 -0
  22. keynetra-0.1.0/keynetra/api/responses.py +28 -0
  23. keynetra-0.1.0/keynetra/api/router.py +6 -0
  24. keynetra-0.1.0/keynetra/api/routes/__init__.py +1 -0
  25. keynetra-0.1.0/keynetra/api/routes/access.py +308 -0
  26. keynetra-0.1.0/keynetra/api/routes/acl.py +126 -0
  27. keynetra-0.1.0/keynetra/api/routes/admin_auth.py +70 -0
  28. keynetra-0.1.0/keynetra/api/routes/audit.py +59 -0
  29. keynetra-0.1.0/keynetra/api/routes/auth_model.py +90 -0
  30. keynetra-0.1.0/keynetra/api/routes/dev.py +52 -0
  31. keynetra-0.1.0/keynetra/api/routes/health.py +74 -0
  32. keynetra-0.1.0/keynetra/api/routes/metrics.py +12 -0
  33. keynetra-0.1.0/keynetra/api/routes/permissions.py +183 -0
  34. keynetra-0.1.0/keynetra/api/routes/playground.py +63 -0
  35. keynetra-0.1.0/keynetra/api/routes/policies.py +233 -0
  36. keynetra-0.1.0/keynetra/api/routes/relationships.py +92 -0
  37. keynetra-0.1.0/keynetra/api/routes/roles.py +241 -0
  38. keynetra-0.1.0/keynetra/api/routes/simulation.py +116 -0
  39. keynetra-0.1.0/keynetra/api/service_modes.py +45 -0
  40. keynetra-0.1.0/keynetra/cli.py +989 -0
  41. keynetra-0.1.0/keynetra/config/__init__.py +1 -0
  42. keynetra-0.1.0/keynetra/config/admin_auth.py +147 -0
  43. keynetra-0.1.0/keynetra/config/config_loader.py +139 -0
  44. keynetra-0.1.0/keynetra/config/file_loaders.py +246 -0
  45. keynetra-0.1.0/keynetra/config/policies.py +7 -0
  46. keynetra-0.1.0/keynetra/config/rate_limit.py +174 -0
  47. keynetra-0.1.0/keynetra/config/redis_client.py +19 -0
  48. keynetra-0.1.0/keynetra/config/sample_data.py +100 -0
  49. keynetra-0.1.0/keynetra/config/security.py +171 -0
  50. keynetra-0.1.0/keynetra/config/settings.py +255 -0
  51. keynetra-0.1.0/keynetra/config/tenancy.py +58 -0
  52. keynetra-0.1.0/keynetra/domain/__init__.py +0 -0
  53. keynetra-0.1.0/keynetra/domain/models/__init__.py +1 -0
  54. keynetra-0.1.0/keynetra/domain/models/acl.py +30 -0
  55. keynetra-0.1.0/keynetra/domain/models/audit.py +33 -0
  56. keynetra-0.1.0/keynetra/domain/models/auth_model.py +28 -0
  57. keynetra-0.1.0/keynetra/domain/models/base.py +7 -0
  58. keynetra-0.1.0/keynetra/domain/models/idempotency.py +30 -0
  59. keynetra-0.1.0/keynetra/domain/models/policy_versioning.py +47 -0
  60. keynetra-0.1.0/keynetra/domain/models/rbac.py +58 -0
  61. keynetra-0.1.0/keynetra/domain/models/relationship.py +32 -0
  62. keynetra-0.1.0/keynetra/domain/models/tenant.py +15 -0
  63. keynetra-0.1.0/keynetra/domain/pagination.py +22 -0
  64. keynetra-0.1.0/keynetra/domain/schemas/__init__.py +1 -0
  65. keynetra-0.1.0/keynetra/domain/schemas/access.py +63 -0
  66. keynetra-0.1.0/keynetra/domain/schemas/api.py +33 -0
  67. keynetra-0.1.0/keynetra/domain/schemas/management.py +98 -0
  68. keynetra-0.1.0/keynetra/domain/schemas/modeling.py +44 -0
  69. keynetra-0.1.0/keynetra/engine/__init__.py +17 -0
  70. keynetra-0.1.0/keynetra/engine/compiled/__init__.py +14 -0
  71. keynetra-0.1.0/keynetra/engine/compiled/decision_graph.py +72 -0
  72. keynetra-0.1.0/keynetra/engine/compiled/policy_compiler.py +67 -0
  73. keynetra-0.1.0/keynetra/engine/keynetra_engine.py +829 -0
  74. keynetra-0.1.0/keynetra/engine/model_graph/__init__.py +13 -0
  75. keynetra-0.1.0/keynetra/engine/model_graph/graph_executor.py +9 -0
  76. keynetra-0.1.0/keynetra/engine/model_graph/permission_graph.py +116 -0
  77. keynetra-0.1.0/keynetra/headless.py +102 -0
  78. keynetra-0.1.0/keynetra/infrastructure/__init__.py +0 -0
  79. keynetra-0.1.0/keynetra/infrastructure/cache/__init__.py +0 -0
  80. keynetra-0.1.0/keynetra/infrastructure/cache/access_index_cache.py +144 -0
  81. keynetra-0.1.0/keynetra/infrastructure/cache/acl_cache.py +110 -0
  82. keynetra-0.1.0/keynetra/infrastructure/cache/backends.py +109 -0
  83. keynetra-0.1.0/keynetra/infrastructure/cache/decision_cache.py +108 -0
  84. keynetra-0.1.0/keynetra/infrastructure/cache/policy_cache.py +77 -0
  85. keynetra-0.1.0/keynetra/infrastructure/cache/policy_distribution.py +51 -0
  86. keynetra-0.1.0/keynetra/infrastructure/cache/relationship_cache.py +75 -0
  87. keynetra-0.1.0/keynetra/infrastructure/cache/user_cache.py +58 -0
  88. keynetra-0.1.0/keynetra/infrastructure/errors.py +13 -0
  89. keynetra-0.1.0/keynetra/infrastructure/logging.py +93 -0
  90. keynetra-0.1.0/keynetra/infrastructure/metrics.py +15 -0
  91. keynetra-0.1.0/keynetra/infrastructure/repositories/__init__.py +17 -0
  92. keynetra-0.1.0/keynetra/infrastructure/repositories/acl.py +112 -0
  93. keynetra-0.1.0/keynetra/infrastructure/repositories/audit.py +125 -0
  94. keynetra-0.1.0/keynetra/infrastructure/repositories/auth_models.py +68 -0
  95. keynetra-0.1.0/keynetra/infrastructure/repositories/idempotency.py +86 -0
  96. keynetra-0.1.0/keynetra/infrastructure/repositories/policies.py +316 -0
  97. keynetra-0.1.0/keynetra/infrastructure/repositories/relationships.py +249 -0
  98. keynetra-0.1.0/keynetra/infrastructure/repositories/tenants.py +68 -0
  99. keynetra-0.1.0/keynetra/infrastructure/repositories/users.py +75 -0
  100. keynetra-0.1.0/keynetra/infrastructure/storage/__init__.py +0 -0
  101. keynetra-0.1.0/keynetra/infrastructure/storage/session.py +91 -0
  102. keynetra-0.1.0/keynetra/main.py +8 -0
  103. keynetra-0.1.0/keynetra/migrations.py +31 -0
  104. keynetra-0.1.0/keynetra/modeling/__init__.py +10 -0
  105. keynetra-0.1.0/keynetra/modeling/model_validator.py +47 -0
  106. keynetra-0.1.0/keynetra/modeling/permission_compiler.py +76 -0
  107. keynetra-0.1.0/keynetra/modeling/schema_parser.py +160 -0
  108. keynetra-0.1.0/keynetra/observability/__init__.py +33 -0
  109. keynetra-0.1.0/keynetra/observability/http_metrics.py +48 -0
  110. keynetra-0.1.0/keynetra/observability/metrics.py +235 -0
  111. keynetra-0.1.0/keynetra/services/__init__.py +1 -0
  112. keynetra-0.1.0/keynetra/services/access_indexer.py +275 -0
  113. keynetra-0.1.0/keynetra/services/attribute_validation.py +31 -0
  114. keynetra-0.1.0/keynetra/services/audit.py +9 -0
  115. keynetra-0.1.0/keynetra/services/authorization.py +812 -0
  116. keynetra-0.1.0/keynetra/services/doctor.py +177 -0
  117. keynetra-0.1.0/keynetra/services/impact_analysis.py +161 -0
  118. keynetra-0.1.0/keynetra/services/interfaces.py +454 -0
  119. keynetra-0.1.0/keynetra/services/policies.py +164 -0
  120. keynetra-0.1.0/keynetra/services/policy_dsl.py +61 -0
  121. keynetra-0.1.0/keynetra/services/policy_lint.py +75 -0
  122. keynetra-0.1.0/keynetra/services/policy_simulator.py +75 -0
  123. keynetra-0.1.0/keynetra/services/policy_testing.py +183 -0
  124. keynetra-0.1.0/keynetra/services/relationships.py +101 -0
  125. keynetra-0.1.0/keynetra/services/resilience.py +38 -0
  126. keynetra-0.1.0/keynetra/services/revisions.py +28 -0
  127. keynetra-0.1.0/keynetra/services/seeding.py +220 -0
  128. keynetra-0.1.0/keynetra/version.py +4 -0
  129. keynetra-0.1.0/keynetra.egg-info/PKG-INFO +26 -0
  130. keynetra-0.1.0/keynetra.egg-info/SOURCES.txt +170 -0
  131. keynetra-0.1.0/keynetra.egg-info/dependency_links.txt +1 -0
  132. keynetra-0.1.0/keynetra.egg-info/entry_points.txt +2 -0
  133. keynetra-0.1.0/keynetra.egg-info/requires.txt +20 -0
  134. keynetra-0.1.0/keynetra.egg-info/top_level.txt +2 -0
  135. keynetra-0.1.0/pyproject.toml +89 -0
  136. keynetra-0.1.0/setup.cfg +4 -0
  137. keynetra-0.1.0/tests/test_access_index.py +99 -0
  138. keynetra-0.1.0/tests/test_access_routes_tenant.py +69 -0
  139. keynetra-0.1.0/tests/test_acl.py +408 -0
  140. keynetra-0.1.0/tests/test_admin_audit.py +178 -0
  141. keynetra-0.1.0/tests/test_admin_login.py +73 -0
  142. keynetra-0.1.0/tests/test_api.py +353 -0
  143. keynetra-0.1.0/tests/test_api_contract.py +106 -0
  144. keynetra-0.1.0/tests/test_auth_model.py +78 -0
  145. keynetra-0.1.0/tests/test_bootstrap_and_config_coverage.py +155 -0
  146. keynetra-0.1.0/tests/test_cli_benchmark.py +41 -0
  147. keynetra-0.1.0/tests/test_cli_coverage_branches.py +128 -0
  148. keynetra-0.1.0/tests/test_compiled_policies.py +60 -0
  149. keynetra-0.1.0/tests/test_consistency_revisions.py +93 -0
  150. keynetra-0.1.0/tests/test_doctor.py +76 -0
  151. keynetra-0.1.0/tests/test_engine.py +110 -0
  152. keynetra-0.1.0/tests/test_file_loaders_coverage.py +133 -0
  153. keynetra-0.1.0/tests/test_headless_modes.py +253 -0
  154. keynetra-0.1.0/tests/test_idempotency.py +95 -0
  155. keynetra-0.1.0/tests/test_impact_analysis.py +164 -0
  156. keynetra-0.1.0/tests/test_integrations_scaffolding.py +30 -0
  157. keynetra-0.1.0/tests/test_management_routes_coverage.py +157 -0
  158. keynetra-0.1.0/tests/test_metrics_endpoint.py +64 -0
  159. keynetra-0.1.0/tests/test_migration_utils.py +20 -0
  160. keynetra-0.1.0/tests/test_pagination_versioning_security.py +111 -0
  161. keynetra-0.1.0/tests/test_playground.py +34 -0
  162. keynetra-0.1.0/tests/test_policy_lint.py +48 -0
  163. keynetra-0.1.0/tests/test_policy_simulation.py +176 -0
  164. keynetra-0.1.0/tests/test_policy_state_canary.py +58 -0
  165. keynetra-0.1.0/tests/test_policy_testing.py +119 -0
  166. keynetra-0.1.0/tests/test_redis_multi_node.py +175 -0
  167. keynetra-0.1.0/tests/test_release_hardening.py +991 -0
  168. keynetra-0.1.0/tests/test_resilience_cli.py +153 -0
  169. keynetra-0.1.0/tests/test_security_config_module.py +89 -0
  170. keynetra-0.1.0/tests/test_services_caching.py +216 -0
  171. keynetra-0.1.0/tests/test_small_coverage_boost.py +45 -0
  172. keynetra-0.1.0/tests/test_strict_tenancy.py +70 -0
keynetra-0.1.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.
@@ -0,0 +1,26 @@
1
+ Metadata-Version: 2.4
2
+ Name: keynetra
3
+ Version: 0.1.0
4
+ Requires-Python: >=3.11
5
+ License-File: LICENSE
6
+ Requires-Dist: fastapi>=0.115
7
+ Requires-Dist: uvicorn[standard]>=0.30
8
+ Requires-Dist: gunicorn>=22.0
9
+ Requires-Dist: pydantic>=2.7
10
+ Requires-Dist: pydantic-settings>=2.3
11
+ Requires-Dist: python-jose[cryptography]>=3.3
12
+ Requires-Dist: PyYAML>=6.0
13
+ Requires-Dist: typer>=0.12
14
+ Requires-Dist: rich>=13.7
15
+ Requires-Dist: pyfiglet>=1.0.2
16
+ Requires-Dist: prometheus-client>=0.21
17
+ Requires-Dist: prometheus-fastapi-instrumentator>=7.0
18
+ Requires-Dist: opentelemetry-api>=1.25
19
+ Requires-Dist: opentelemetry-sdk>=1.25
20
+ Requires-Dist: opentelemetry-instrumentation-fastapi>=0.46b0
21
+ Requires-Dist: sqlalchemy>=2.0
22
+ Requires-Dist: alembic>=1.13
23
+ Requires-Dist: psycopg[binary]>=3.1
24
+ Requires-Dist: redis>=5.0
25
+ Requires-Dist: httpx>=0.27
26
+ Dynamic: license-file
@@ -0,0 +1,238 @@
1
+ <p align="center">
2
+ <img src="./data/imgs/logo.png" alt="KeyNetra Logo" width="220" />
3
+ </p>
4
+ <p align="center">
5
+ <img src="https://readme-typing-svg.demolab.com?font=Fira+Code&size=25&pause=1100&center=true&vCenter=true&width=900&lines=Deterministic+Authorization+Control+Plane;RBAC+%2B+ACL+%2B+ReBAC+for+modern+apps;FastAPI+API%2C+CLI%2C+Caching%2C+Observability" alt="KeyNetra animated typing banner" />
6
+ </p>
7
+ <div align="center">
8
+
9
+ [![CI](https://github.com/keynetra/keynetra/actions/workflows/ci.yml/badge.svg)](https://github.com/keynetra/keynetra/actions/workflows/ci.yml)
10
+ [![Release](https://github.com/keynetra/keynetra/actions/workflows/release.yml/badge.svg)](https://github.com/keynetra/keynetra/actions/workflows/release.yml)
11
+ [![Docker Hub](https://img.shields.io/docker/pulls/keynetra/keynetra?label=docker%20pulls)](https://hub.docker.com/r/keynetra/keynetra)
12
+ [![Python](https://img.shields.io/badge/python-3.11%2B-blue)](./pyproject.toml)
13
+ [![License](https://img.shields.io/badge/license-Apache--2.0-green)](./LICENSE)
14
+ [![OpenAPI](https://img.shields.io/badge/OpenAPI-3.1-orange)](./contracts/openapi/openapi.json)
15
+
16
+ </div>
17
+
18
+ # KeyNetra
19
+
20
+ Policy-driven authorization control plane for applications that need deterministic, explainable access decisions across RBAC, ACL, and ReBAC.
21
+
22
+ ## What KeyNetra Provides
23
+
24
+ - Authorization engine with deterministic evaluation and explain traces
25
+ - FastAPI API server and operational CLI
26
+ - Multi-tenant policy evaluation with strict tenancy controls
27
+ - Policy lifecycle operations (validation, compile, simulation, impact analysis)
28
+ - Caching and access indexing for low-latency checks
29
+ - Structured logging, metrics, and dashboard-ready monitoring
30
+ - Deployment assets for Docker, Kubernetes, and Helm
31
+
32
+ ## Architecture
33
+
34
+ Layering is enforced through import contracts:
35
+
36
+ - `keynetra.api` -> transport only
37
+ - `keynetra.services` -> orchestration and runtime flow
38
+ - `keynetra.engine` -> pure policy decision logic
39
+ - `keynetra.domain` -> shared models/schemas
40
+ - `keynetra.infrastructure` -> repositories, storage, cache adapters
41
+ - `keynetra.config` -> configuration loading and guardrails
42
+
43
+ Detailed architecture notes: [`ARCHITECTURE.md`](./ARCHITECTURE.md)
44
+
45
+ ## Quick Start (Local)
46
+
47
+ ### 1) Setup
48
+
49
+ ```bash
50
+ python3.11 -m venv .venv
51
+ source .venv/bin/activate
52
+ pip install --upgrade pip
53
+ pip install -r requirements.txt -r requirements-dev.txt
54
+ pip install -e .
55
+ cp .env.example .env
56
+ ```
57
+
58
+ ### 2) Run API
59
+
60
+ ```bash
61
+ keynetra serve --host 0.0.0.0 --port 8080
62
+ ```
63
+
64
+ ### 3) Health and Docs
65
+
66
+ ```bash
67
+ curl -i http://localhost:8080/health/ready
68
+ open http://localhost:8080/docs
69
+ ```
70
+
71
+ ### 4) First Authorization Check
72
+
73
+ ```bash
74
+ curl -s -X POST http://localhost:8080/check-access \
75
+ -H "Content-Type: application/json" \
76
+ -H "X-API-Key: devkey" \
77
+ -H "X-Tenant-Id: acme" \
78
+ -d '{
79
+ "user": {"id": "u1", "role": "admin"},
80
+ "action": "read",
81
+ "resource": {"resource_type": "document", "resource_id": "doc-1"},
82
+ "context": {}
83
+ }'
84
+ ```
85
+
86
+ ## CLI Usage
87
+
88
+ Entrypoint is standardized to `keynetra`:
89
+
90
+ ```bash
91
+ keynetra --help
92
+ keynetra check-openapi
93
+ keynetra migrate --confirm-destructive
94
+ keynetra doctor --service core
95
+ ```
96
+
97
+ ## API Surface (Core)
98
+
99
+ - `POST /check-access`
100
+ - `POST /check-access-batch`
101
+ - `POST /simulate`
102
+ - `POST /simulate-policy`
103
+ - `POST /impact-analysis`
104
+ - `GET /health`, `GET /health/ready`, `GET /metrics`
105
+
106
+ OpenAPI contracts:
107
+
108
+ - [`contracts/openapi/openapi.json`](./contracts/openapi/openapi.json)
109
+ - [`contracts/openapi/keynetra-v0.1.0.yaml`](./contracts/openapi/keynetra-v0.1.0.yaml)
110
+
111
+ ## Multi-Tenant and Security
112
+
113
+ - Tenant-aware request flow and storage isolation
114
+ - Strict tenancy mode available via `KEYNETRA_STRICT_TENANCY=true`
115
+ - API key and JWT auth support
116
+ - Admin auth flow for privileged operations
117
+ - Rate limiting and request correlation IDs
118
+
119
+ See [`SECURITY.md`](./SECURITY.md) for security policy and reporting.
120
+
121
+ ## Observability and Monitoring
122
+
123
+ KeyNetra exposes Prometheus metrics at `GET /metrics` including:
124
+
125
+ - HTTP request count/latency/error metrics
126
+ - Authorization decision and stage latency metrics
127
+ - Cache hit/miss metrics
128
+ - DB query latency metrics
129
+ - Tenant activity dimensions
130
+
131
+ Monitoring assets:
132
+
133
+ - Prometheus config: [`monitoring/prometheus/prometheus.yml`](./monitoring/prometheus/prometheus.yml)
134
+ - Grafana dashboard: [`monitoring/grafana/dashboards/keynetra-overview.json`](./monitoring/grafana/dashboards/keynetra-overview.json)
135
+ - Grafana provisioning: [`monitoring/grafana/provisioning`](./monitoring/grafana/provisioning)
136
+
137
+ ## Deployment
138
+
139
+ ### Docker
140
+
141
+ ```bash
142
+ docker build -t keynetra:test .
143
+ docker run --rm -p 8080:8080 --env-file .env keynetra:test
144
+ ```
145
+
146
+ ### Docker Compose (Full Dev/Obs Stack)
147
+
148
+ ```bash
149
+ docker compose up --build
150
+ ```
151
+
152
+ Includes:
153
+
154
+ - KeyNetra API
155
+ - PostgreSQL
156
+ - Redis
157
+ - Prometheus
158
+ - Grafana
159
+ - node-exporter
160
+ - Loki
161
+
162
+ ### Kubernetes
163
+
164
+ ```bash
165
+ kubectl apply -f deploy/kubernetes/
166
+ ```
167
+
168
+ ### Helm
169
+
170
+ ```bash
171
+ helm install keynetra ./deploy/helm/keynetra
172
+ ```
173
+
174
+ More deployment detail: [`DEPLOYMENT.md`](./DEPLOYMENT.md)
175
+
176
+ ## SDKs
177
+
178
+ SDKs are maintained separately from this engine repository.
179
+
180
+ - Python SDK package: `keynetra-client`
181
+ - SDK guide: [`SDK_GUIDE.md`](./SDK_GUIDE.md)
182
+
183
+ Example (Python SDK):
184
+
185
+ ```python
186
+ from keynetra_client import KeyNetraClient
187
+
188
+ client = KeyNetraClient("http://localhost:8080")
189
+ decision = client.check_access(
190
+ user={"id": "alice"},
191
+ action="read",
192
+ resource={"type": "document", "id": "doc-1"},
193
+ )
194
+ print(decision.allowed)
195
+ ```
196
+
197
+ ## Developer Workflow
198
+
199
+ ```bash
200
+ ruff check .
201
+ black --check .
202
+ pytest
203
+ lint-imports --config .importlinter
204
+ ```
205
+
206
+ Convenience commands are available in [`Makefile`](./Makefile).
207
+
208
+ ## Documentation Index
209
+
210
+ - [`ARCHITECTURE.md`](./ARCHITECTURE.md)
211
+ - [`DEPLOYMENT.md`](./DEPLOYMENT.md)
212
+ - [`SDK_GUIDE.md`](./SDK_GUIDE.md)
213
+ - [`CONTRIBUTING.md`](./CONTRIBUTING.md)
214
+ - [`CODE_OF_CONDUCT.md`](./CODE_OF_CONDUCT.md)
215
+ - [`SECURITY.md`](./SECURITY.md)
216
+ - [`CHANGELOG.md`](./CHANGELOG.md)
217
+ - [`docs/README.md`](./docs/README.md)
218
+
219
+ ## Contributing
220
+
221
+ Contributions are welcome. Start with [`CONTRIBUTING.md`](./CONTRIBUTING.md) and [`CODE_OF_CONDUCT.md`](./CODE_OF_CONDUCT.md).
222
+
223
+ ## License
224
+
225
+ Apache-2.0. See [`LICENSE`](./LICENSE).
226
+
227
+ ## Citation
228
+
229
+ ```bibtex
230
+ @software{keynetra_2026,
231
+ title = {KeyNetra},
232
+ author = {KeyNetra Community},
233
+ year = {2026},
234
+ version = {0.1.0-beta},
235
+ url = {https://github.com/keynetra/keynetra}
236
+ }
237
+ ```
238
+ <p align="center">Made with love ❤️ for KeyNetra Community. </p>
@@ -0,0 +1 @@
1
+ """External integration adapters for KeyNetra policy ecosystem."""
@@ -0,0 +1,29 @@
1
+ from __future__ import annotations
2
+
3
+ from dataclasses import dataclass
4
+ from typing import Protocol
5
+
6
+
7
+ @dataclass(frozen=True)
8
+ class TupleRecord:
9
+ subject: str
10
+ relation: str
11
+ object: str
12
+
13
+
14
+ class TupleStoreAdapter(Protocol):
15
+ def import_tuples(self, tuples: list[TupleRecord]) -> int: ...
16
+
17
+ def export_tuples(self) -> list[TupleRecord]: ...
18
+
19
+
20
+ class PolicyAdapter(Protocol):
21
+ def import_policies(self, payload: str) -> int: ...
22
+
23
+ def export_policies(self) -> str: ...
24
+
25
+
26
+ class TerraformResourceAdapter(Protocol):
27
+ def plan(self) -> dict[str, object]: ...
28
+
29
+ def apply(self) -> dict[str, object]: ...
@@ -0,0 +1,19 @@
1
+ from __future__ import annotations
2
+
3
+ from dataclasses import dataclass
4
+
5
+ from integrations.interfaces import PolicyAdapter
6
+
7
+
8
+ @dataclass
9
+ class OPARegoPolicyAdapter(PolicyAdapter):
10
+ """Minimal OPA/Rego policy adapter scaffold."""
11
+
12
+ _rego: str = ""
13
+
14
+ def import_policies(self, payload: str) -> int:
15
+ self._rego = payload
16
+ return len(payload.splitlines()) if payload else 0
17
+
18
+ def export_policies(self) -> str:
19
+ return self._rego
@@ -0,0 +1,19 @@
1
+ from __future__ import annotations
2
+
3
+ from dataclasses import dataclass, field
4
+
5
+ from integrations.interfaces import TupleRecord, TupleStoreAdapter
6
+
7
+
8
+ @dataclass
9
+ class InMemoryOpenFGATupleAdapter(TupleStoreAdapter):
10
+ """Starter adapter for OpenFGA tuple import/export workflows."""
11
+
12
+ tuples: list[TupleRecord] = field(default_factory=list)
13
+
14
+ def import_tuples(self, tuples: list[TupleRecord]) -> int:
15
+ self.tuples.extend(tuples)
16
+ return len(tuples)
17
+
18
+ def export_tuples(self) -> list[TupleRecord]:
19
+ return list(self.tuples)
@@ -0,0 +1,18 @@
1
+ from __future__ import annotations
2
+
3
+ from dataclasses import dataclass
4
+
5
+ from integrations.interfaces import TerraformResourceAdapter
6
+
7
+
8
+ @dataclass
9
+ class TerraformPolicyResourceAdapter(TerraformResourceAdapter):
10
+ """Placeholder adapter boundary for Terraform-managed policy resources."""
11
+
12
+ policy_count: int = 0
13
+
14
+ def plan(self) -> dict[str, object]:
15
+ return {"changes": self.policy_count, "resource": "keynetra_policy"}
16
+
17
+ def apply(self) -> dict[str, object]:
18
+ return {"applied": True, "resource_count": self.policy_count}
@@ -0,0 +1,5 @@
1
+ """keynetra top-level package."""
2
+
3
+ from keynetra.headless import KeyNetra
4
+
5
+ __all__ = ["KeyNetra"]
@@ -0,0 +1 @@
1
+ """API routes package."""