sentrykit 0.1.0rc1__py3-none-any.whl

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 (46) hide show
  1. sentrykit/__init__.py +200 -0
  2. sentrykit/audit.py +967 -0
  3. sentrykit/cedar.py +750 -0
  4. sentrykit/cli.py +1405 -0
  5. sentrykit/config.py +300 -0
  6. sentrykit/constraints.py +928 -0
  7. sentrykit/context.py +393 -0
  8. sentrykit/decorator.py +252 -0
  9. sentrykit/engine.py +1509 -0
  10. sentrykit/envelope.py +513 -0
  11. sentrykit/errors.py +252 -0
  12. sentrykit/integrations/__init__.py +1 -0
  13. sentrykit/integrations/base.py +767 -0
  14. sentrykit/integrations/fastapi.py +361 -0
  15. sentrykit/integrations/flask.py +342 -0
  16. sentrykit/integrations/mcp.py +929 -0
  17. sentrykit/integrations/pydantic_ai.py +728 -0
  18. sentrykit/integrations/tools.py +479 -0
  19. sentrykit/masking.py +459 -0
  20. sentrykit/policy/__init__.py +40 -0
  21. sentrykit/policy/loader.py +764 -0
  22. sentrykit/policy/pack/10-rbac.cedar +9 -0
  23. sentrykit/policy/pack/20-groups.cedar +9 -0
  24. sentrykit/policy/pack/30-ownership.cedar +8 -0
  25. sentrykit/policy/pack/40-delegation.cedar +40 -0
  26. sentrykit/policy/pack/50-expiry.cedar +24 -0
  27. sentrykit/policy/pack/60-break-glass.cedar +34 -0
  28. sentrykit/policy/pack/70-separation-of-duties.cedar +22 -0
  29. sentrykit/policy/pack/80-jit-elevation.cedar +32 -0
  30. sentrykit/policy/pack/entities.json +3 -0
  31. sentrykit/policy/pack/pack.cedarschema +45 -0
  32. sentrykit/policy/pack/templates/time-boxed-grant.cedartemplate +5 -0
  33. sentrykit/py.typed +0 -0
  34. sentrykit/registry.py +666 -0
  35. sentrykit/stores/__init__.py +116 -0
  36. sentrykit/stores/base.py +870 -0
  37. sentrykit/stores/composite.py +635 -0
  38. sentrykit/stores/filesystem.py +400 -0
  39. sentrykit/stores/jsonfile.py +701 -0
  40. sentrykit/stores/jsonl.py +357 -0
  41. sentrykit/stores/memory.py +500 -0
  42. sentrykit-0.1.0rc1.dist-info/METADATA +541 -0
  43. sentrykit-0.1.0rc1.dist-info/RECORD +46 -0
  44. sentrykit-0.1.0rc1.dist-info/WHEEL +4 -0
  45. sentrykit-0.1.0rc1.dist-info/entry_points.txt +20 -0
  46. sentrykit-0.1.0rc1.dist-info/licenses/LICENSE +201 -0
sentrykit/__init__.py ADDED
@@ -0,0 +1,200 @@
1
+ """sentrykit — lightweight, framework-agnostic authorization built on AWS Cedar.
2
+
3
+ Clip :func:`~sentrykit.decorator.protect` onto any callable and sentrykit decides, per call,
4
+ whether the principal may invoke it, which arguments they may pass, and which defaults to
5
+ inject when they pass none.
6
+
7
+ ```python
8
+ from sentrykit import Entity, EntityRef, Principal, establish, install, protect
9
+
10
+ install(
11
+ '''
12
+ @id("support-may-search")
13
+ permit(
14
+ principal in Role::"support",
15
+ action == Action::"tool.search_orders",
16
+ resource == Tool::"orders"
17
+ );
18
+ ''',
19
+ entities=[Entity(EntityRef("Tool", "orders")), Entity(EntityRef("Role", "support"))],
20
+ )
21
+
22
+
23
+ @protect(action='Action::"tool.search_orders"', resource='Tool::"orders"')
24
+ def search_orders(customer_id: str, limit: int = 10) -> dict[str, object]:
25
+ return {"customer_id": customer_id, "limit": limit}
26
+
27
+
28
+ with establish(Principal(id="alice", roles=("support",)), channel="agent"):
29
+ search_orders(customer_id="c-1")
30
+ ```
31
+
32
+ The caller proposes; the policy decides.
33
+ """
34
+
35
+ from __future__ import annotations
36
+
37
+ from sentrykit.audit import AuditTrail, AuthzAuditRecord, ChainVerdict, verify_chain
38
+ from sentrykit.cedar import CedarDecision, CedarRequest, Entity, EntityRef, PolicyEngine
39
+ from sentrykit.config import (
40
+ Settings,
41
+ clear_action_overrides,
42
+ configure,
43
+ get_settings,
44
+ override_action,
45
+ reset_settings,
46
+ settings_for,
47
+ )
48
+ from sentrykit.constraints import (
49
+ ArgumentConstraint,
50
+ ConstraintSet,
51
+ FilterResult,
52
+ RejectedArgument,
53
+ )
54
+ from sentrykit.context import (
55
+ ContextScope,
56
+ Invocation,
57
+ Principal,
58
+ bind_context,
59
+ clear_context,
60
+ current_environment,
61
+ current_principal,
62
+ establish,
63
+ principal_context,
64
+ require_principal,
65
+ )
66
+ from sentrykit.decorator import ProtectedMeta, is_protected, protect, protected_meta
67
+ from sentrykit.engine import (
68
+ ArgumentSpec,
69
+ Governor,
70
+ Plan,
71
+ current_governor,
72
+ get_governor,
73
+ install,
74
+ set_governor,
75
+ use_governor,
76
+ )
77
+ from sentrykit.envelope import AuthzEnvelope, last_envelope
78
+ from sentrykit.errors import (
79
+ ArgumentRejected,
80
+ AuditUnavailable,
81
+ AuthzDenied,
82
+ ConfigurationError,
83
+ DefaultUnavailable,
84
+ NoContext,
85
+ NoValidArguments,
86
+ ReservedKey,
87
+ SentrykitError,
88
+ SignatureDefaultRejected,
89
+ ValidationFailed,
90
+ )
91
+ from sentrykit.masking import Masker, Sensitive
92
+ from sentrykit.policy.loader import (
93
+ LinkedPolicySource,
94
+ PackPolicySource,
95
+ TemplateLink,
96
+ link_template,
97
+ load_pack,
98
+ )
99
+ from sentrykit.registry import (
100
+ available,
101
+ build_audit_sink,
102
+ build_grant_store,
103
+ build_policy_source,
104
+ register_audit_sink,
105
+ register_context_provider,
106
+ register_grant_store,
107
+ register_policy_source,
108
+ )
109
+ from sentrykit.stores.base import (
110
+ AuditSink,
111
+ AuditWindow,
112
+ GrantRecord,
113
+ GrantSpec,
114
+ GrantStore,
115
+ PolicyBundle,
116
+ PolicySource,
117
+ )
118
+
119
+ __all__ = [
120
+ "ArgumentConstraint",
121
+ "ArgumentRejected",
122
+ "ArgumentSpec",
123
+ "AuditSink",
124
+ "AuditTrail",
125
+ "AuditUnavailable",
126
+ "AuditWindow",
127
+ "AuthzAuditRecord",
128
+ "AuthzDenied",
129
+ "AuthzEnvelope",
130
+ "CedarDecision",
131
+ "CedarRequest",
132
+ "ChainVerdict",
133
+ "ConfigurationError",
134
+ "ConstraintSet",
135
+ "ContextScope",
136
+ "DefaultUnavailable",
137
+ "Entity",
138
+ "EntityRef",
139
+ "FilterResult",
140
+ "Governor",
141
+ "GrantRecord",
142
+ "GrantSpec",
143
+ "GrantStore",
144
+ "Invocation",
145
+ "LinkedPolicySource",
146
+ "Masker",
147
+ "NoContext",
148
+ "NoValidArguments",
149
+ "PackPolicySource",
150
+ "Plan",
151
+ "PolicyBundle",
152
+ "PolicyEngine",
153
+ "PolicySource",
154
+ "Principal",
155
+ "ProtectedMeta",
156
+ "RejectedArgument",
157
+ "ReservedKey",
158
+ "Sensitive",
159
+ "SentrykitError",
160
+ "Settings",
161
+ "SignatureDefaultRejected",
162
+ "TemplateLink",
163
+ "ValidationFailed",
164
+ "__version__",
165
+ "available",
166
+ "bind_context",
167
+ "build_audit_sink",
168
+ "build_grant_store",
169
+ "build_policy_source",
170
+ "clear_action_overrides",
171
+ "clear_context",
172
+ "configure",
173
+ "current_environment",
174
+ "current_governor",
175
+ "current_principal",
176
+ "establish",
177
+ "get_governor",
178
+ "get_settings",
179
+ "install",
180
+ "is_protected",
181
+ "last_envelope",
182
+ "link_template",
183
+ "load_pack",
184
+ "override_action",
185
+ "principal_context",
186
+ "protect",
187
+ "protected_meta",
188
+ "register_audit_sink",
189
+ "register_context_provider",
190
+ "register_grant_store",
191
+ "register_policy_source",
192
+ "require_principal",
193
+ "reset_settings",
194
+ "set_governor",
195
+ "settings_for",
196
+ "use_governor",
197
+ "verify_chain",
198
+ ]
199
+
200
+ __version__ = "0.1.0rc1"