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.
- sentrykit/__init__.py +200 -0
- sentrykit/audit.py +967 -0
- sentrykit/cedar.py +750 -0
- sentrykit/cli.py +1405 -0
- sentrykit/config.py +300 -0
- sentrykit/constraints.py +928 -0
- sentrykit/context.py +393 -0
- sentrykit/decorator.py +252 -0
- sentrykit/engine.py +1509 -0
- sentrykit/envelope.py +513 -0
- sentrykit/errors.py +252 -0
- sentrykit/integrations/__init__.py +1 -0
- sentrykit/integrations/base.py +767 -0
- sentrykit/integrations/fastapi.py +361 -0
- sentrykit/integrations/flask.py +342 -0
- sentrykit/integrations/mcp.py +929 -0
- sentrykit/integrations/pydantic_ai.py +728 -0
- sentrykit/integrations/tools.py +479 -0
- sentrykit/masking.py +459 -0
- sentrykit/policy/__init__.py +40 -0
- sentrykit/policy/loader.py +764 -0
- sentrykit/policy/pack/10-rbac.cedar +9 -0
- sentrykit/policy/pack/20-groups.cedar +9 -0
- sentrykit/policy/pack/30-ownership.cedar +8 -0
- sentrykit/policy/pack/40-delegation.cedar +40 -0
- sentrykit/policy/pack/50-expiry.cedar +24 -0
- sentrykit/policy/pack/60-break-glass.cedar +34 -0
- sentrykit/policy/pack/70-separation-of-duties.cedar +22 -0
- sentrykit/policy/pack/80-jit-elevation.cedar +32 -0
- sentrykit/policy/pack/entities.json +3 -0
- sentrykit/policy/pack/pack.cedarschema +45 -0
- sentrykit/policy/pack/templates/time-boxed-grant.cedartemplate +5 -0
- sentrykit/py.typed +0 -0
- sentrykit/registry.py +666 -0
- sentrykit/stores/__init__.py +116 -0
- sentrykit/stores/base.py +870 -0
- sentrykit/stores/composite.py +635 -0
- sentrykit/stores/filesystem.py +400 -0
- sentrykit/stores/jsonfile.py +701 -0
- sentrykit/stores/jsonl.py +357 -0
- sentrykit/stores/memory.py +500 -0
- sentrykit-0.1.0rc1.dist-info/METADATA +541 -0
- sentrykit-0.1.0rc1.dist-info/RECORD +46 -0
- sentrykit-0.1.0rc1.dist-info/WHEEL +4 -0
- sentrykit-0.1.0rc1.dist-info/entry_points.txt +20 -0
- 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__)
|