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
@@ -0,0 +1,116 @@
1
+ """The three store contracts, and lazy access to the backends that ship with sentrykit.
2
+
3
+ The contracts are imported eagerly; the **backends are not**. Two reasons, and the second is
4
+ the one that matters:
5
+
6
+ 1. A backend module reaches back into :mod:`sentrykit.audit` for the record type, and
7
+ :mod:`sentrykit.audit` reaches into :mod:`sentrykit.stores.base` for the sink contract.
8
+ Importing the backends from this package's body would close that loop.
9
+ 2. Entry-point discovery, not a package import, is what makes a backend reachable. The
10
+ registry resolves ``jsonl://`` by exactly the path it resolves a third-party
11
+ ``sentrykit-<x>`` sink — through ``importlib.metadata`` — and if the built-ins needed a
12
+ privileged import to be found, the claim that built-in and third-party backends are
13
+ indistinguishable to the core would simply be false.
14
+
15
+ ``from sentrykit.stores import JsonlAuditSink`` still works: PEP 562 resolves it on first
16
+ access, importing the one module it needs. There are three contracts rather than one because
17
+ they guarantee different things: a policy source is fetched and never written, a grant store
18
+ is mutable data, and an audit sink is append-only.
19
+ """
20
+
21
+ from __future__ import annotations
22
+
23
+ from typing import TYPE_CHECKING, Final
24
+
25
+ from sentrykit.stores.base import (
26
+ AuditSink,
27
+ AuditWindow,
28
+ ContextProvider,
29
+ GrantKind,
30
+ GrantRecord,
31
+ GrantSpec,
32
+ GrantStore,
33
+ NullAuditSink,
34
+ PolicyBundle,
35
+ PolicyProvenance,
36
+ PolicySource,
37
+ SupportsClose,
38
+ )
39
+
40
+ if TYPE_CHECKING: # pragma: no cover - the type checker resolves what __getattr__ defers
41
+ from sentrykit.stores.composite import (
42
+ CompositeAuditSink,
43
+ CompositeGrantStore,
44
+ CompositePolicySource,
45
+ )
46
+ from sentrykit.stores.filesystem import FilesystemPolicySource
47
+ from sentrykit.stores.jsonfile import JsonFileGrantStore
48
+ from sentrykit.stores.jsonl import JsonlAuditSink
49
+ from sentrykit.stores.memory import (
50
+ InMemoryAuditSink,
51
+ InMemoryGrantStore,
52
+ InMemoryTokenVault,
53
+ )
54
+
55
+ __all__ = [
56
+ "AuditSink",
57
+ "AuditWindow",
58
+ "CompositeAuditSink",
59
+ "CompositeGrantStore",
60
+ "CompositePolicySource",
61
+ "ContextProvider",
62
+ "FilesystemPolicySource",
63
+ "GrantKind",
64
+ "GrantRecord",
65
+ "GrantSpec",
66
+ "GrantStore",
67
+ "InMemoryAuditSink",
68
+ "InMemoryGrantStore",
69
+ "InMemoryTokenVault",
70
+ "JsonFileGrantStore",
71
+ "JsonlAuditSink",
72
+ "NullAuditSink",
73
+ "PolicyBundle",
74
+ "PolicyProvenance",
75
+ "PolicySource",
76
+ "SupportsClose",
77
+ ]
78
+
79
+ _LAZY: Final[dict[str, str]] = {
80
+ "CompositeAuditSink": "sentrykit.stores.composite",
81
+ "CompositeGrantStore": "sentrykit.stores.composite",
82
+ "CompositePolicySource": "sentrykit.stores.composite",
83
+ "FilesystemPolicySource": "sentrykit.stores.filesystem",
84
+ "InMemoryAuditSink": "sentrykit.stores.memory",
85
+ "InMemoryGrantStore": "sentrykit.stores.memory",
86
+ "InMemoryTokenVault": "sentrykit.stores.memory",
87
+ "JsonFileGrantStore": "sentrykit.stores.jsonfile",
88
+ "JsonlAuditSink": "sentrykit.stores.jsonl",
89
+ }
90
+ """Backend name to the module that defines it, imported on first access."""
91
+
92
+
93
+ def __getattr__(name: str) -> object:
94
+ """Resolve a backend name by importing only the module that defines it.
95
+
96
+ Args:
97
+ name: The attribute being read.
98
+
99
+ Returns:
100
+ The backend class.
101
+
102
+ Raises:
103
+ AttributeError: For anything that is not a known backend, so a typo still fails the
104
+ way a missing attribute normally does.
105
+ """
106
+ module_name = _LAZY.get(name)
107
+ if module_name is None:
108
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
109
+ from importlib import import_module
110
+
111
+ return getattr(import_module(module_name), name)
112
+
113
+
114
+ def __dir__() -> list[str]:
115
+ """List the eager and lazy names together, so tab-completion sees the backends."""
116
+ return sorted(__all__)