tba-contracts-authorization 0.4.0.dev3__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.
- tba_contracts_authorization-0.4.0.dev3/PKG-INFO +18 -0
- tba_contracts_authorization-0.4.0.dev3/README.md +3 -0
- tba_contracts_authorization-0.4.0.dev3/pyproject.toml +15 -0
- tba_contracts_authorization-0.4.0.dev3/src/tba_contracts_authorization/__init__.py +139 -0
- tba_contracts_authorization-0.4.0.dev3/src/tba_contracts_authorization/py.typed +1 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tba-contracts-authorization
|
|
3
|
+
Version: 0.4.0.dev3
|
|
4
|
+
Summary: Canonical platform authorization request, role, grant, and decision contracts.
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
Requires-Python: >=3.10,<3.15
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
|
|
15
|
+
# tba-contracts-authorization
|
|
16
|
+
|
|
17
|
+
Transport-neutral contracts shared by policy administration, decision, enforcement, and UI clients.
|
|
18
|
+
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "tba-contracts-authorization"
|
|
3
|
+
version = "0.4.0.dev3"
|
|
4
|
+
description = "Canonical platform authorization request, role, grant, and decision contracts."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.10,<3.15"
|
|
7
|
+
license = "Apache-2.0"
|
|
8
|
+
dependencies = []
|
|
9
|
+
|
|
10
|
+
[build-system]
|
|
11
|
+
requires = ["poetry-core>=1.0.0"]
|
|
12
|
+
build-backend = "poetry.core.masonry.api"
|
|
13
|
+
|
|
14
|
+
[tool.poetry]
|
|
15
|
+
packages = [{ include = "tba_contracts_authorization", from = "src" }]
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"""Canonical, transport-neutral platform authorization contracts."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass, field
|
|
6
|
+
from datetime import datetime
|
|
7
|
+
from enum import Enum
|
|
8
|
+
from typing import Mapping
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def _required(value: str, label: str) -> str:
|
|
12
|
+
normalized = value.strip()
|
|
13
|
+
if not normalized:
|
|
14
|
+
raise ValueError(f"{label} is required")
|
|
15
|
+
return normalized
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class AuthorizationEffect(str, Enum):
|
|
19
|
+
ALLOW = "allow"
|
|
20
|
+
DENY = "deny"
|
|
21
|
+
INDETERMINATE = "indeterminate"
|
|
22
|
+
NOT_APPLICABLE = "not_applicable"
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
@dataclass(frozen=True, slots=True)
|
|
26
|
+
class PrincipalRef:
|
|
27
|
+
principal_id: str
|
|
28
|
+
principal_type: str
|
|
29
|
+
tenant_id: str | None = None
|
|
30
|
+
attributes: Mapping[str, object] = field(default_factory=dict)
|
|
31
|
+
|
|
32
|
+
def __post_init__(self) -> None:
|
|
33
|
+
object.__setattr__(self, "principal_id", _required(self.principal_id, "principal_id"))
|
|
34
|
+
object.__setattr__(self, "principal_type", _required(self.principal_type, "principal_type"))
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
@dataclass(frozen=True, slots=True)
|
|
38
|
+
class ResourceRef:
|
|
39
|
+
resource_type: str
|
|
40
|
+
resource_id: str
|
|
41
|
+
tenant_id: str
|
|
42
|
+
scope_path: tuple[str, ...] = ()
|
|
43
|
+
attributes: Mapping[str, object] = field(default_factory=dict)
|
|
44
|
+
|
|
45
|
+
def __post_init__(self) -> None:
|
|
46
|
+
object.__setattr__(self, "resource_type", _required(self.resource_type, "resource_type"))
|
|
47
|
+
object.__setattr__(self, "resource_id", _required(self.resource_id, "resource_id"))
|
|
48
|
+
object.__setattr__(self, "tenant_id", _required(self.tenant_id, "tenant_id"))
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
@dataclass(frozen=True, slots=True)
|
|
52
|
+
class AuthenticationContext:
|
|
53
|
+
acr: str | None = None
|
|
54
|
+
amr: tuple[str, ...] = ()
|
|
55
|
+
authenticated_at: datetime | None = None
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
@dataclass(frozen=True, slots=True)
|
|
59
|
+
class AuthorizationRequest:
|
|
60
|
+
principal: PrincipalRef
|
|
61
|
+
action: str
|
|
62
|
+
resource: ResourceRef
|
|
63
|
+
authentication: AuthenticationContext = field(default_factory=AuthenticationContext)
|
|
64
|
+
environment: Mapping[str, object] = field(default_factory=dict)
|
|
65
|
+
correlation_id: str | None = None
|
|
66
|
+
|
|
67
|
+
def __post_init__(self) -> None:
|
|
68
|
+
object.__setattr__(self, "action", _required(self.action, "action"))
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
@dataclass(frozen=True, slots=True)
|
|
72
|
+
class ActionDefinition:
|
|
73
|
+
key: str
|
|
74
|
+
resource_type: str
|
|
75
|
+
description: str = ""
|
|
76
|
+
required_acr: str | None = None
|
|
77
|
+
|
|
78
|
+
def __post_init__(self) -> None:
|
|
79
|
+
object.__setattr__(self, "key", _required(self.key, "action key"))
|
|
80
|
+
object.__setattr__(self, "resource_type", _required(self.resource_type, "resource_type"))
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
@dataclass(frozen=True, slots=True)
|
|
84
|
+
class RoleDefinition:
|
|
85
|
+
role_id: str
|
|
86
|
+
name: str
|
|
87
|
+
tenant_id: str
|
|
88
|
+
actions: tuple[str, ...] = ()
|
|
89
|
+
|
|
90
|
+
def __post_init__(self) -> None:
|
|
91
|
+
object.__setattr__(self, "role_id", _required(self.role_id, "role_id"))
|
|
92
|
+
object.__setattr__(self, "name", _required(self.name, "name"))
|
|
93
|
+
object.__setattr__(self, "tenant_id", _required(self.tenant_id, "tenant_id"))
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
@dataclass(frozen=True, slots=True)
|
|
97
|
+
class RoleGrant:
|
|
98
|
+
grant_id: str
|
|
99
|
+
tenant_id: str
|
|
100
|
+
principal: PrincipalRef
|
|
101
|
+
role_id: str
|
|
102
|
+
resource: ResourceRef
|
|
103
|
+
valid_from: datetime | None = None
|
|
104
|
+
expires_at: datetime | None = None
|
|
105
|
+
revoked_at: datetime | None = None
|
|
106
|
+
conditions: Mapping[str, object] = field(default_factory=dict)
|
|
107
|
+
effect: AuthorizationEffect | str = AuthorizationEffect.ALLOW
|
|
108
|
+
|
|
109
|
+
def __post_init__(self) -> None:
|
|
110
|
+
object.__setattr__(self, "grant_id", _required(self.grant_id, "grant_id"))
|
|
111
|
+
object.__setattr__(self, "tenant_id", _required(self.tenant_id, "tenant_id"))
|
|
112
|
+
object.__setattr__(self, "role_id", _required(self.role_id, "role_id"))
|
|
113
|
+
object.__setattr__(self, "effect", AuthorizationEffect(self.effect))
|
|
114
|
+
if self.valid_from and self.expires_at and self.expires_at <= self.valid_from:
|
|
115
|
+
raise ValueError("expires_at must be later than valid_from")
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
@dataclass(frozen=True, slots=True)
|
|
119
|
+
class AuthorizationDecision:
|
|
120
|
+
decision_id: str
|
|
121
|
+
effect: AuthorizationEffect
|
|
122
|
+
reason_code: str
|
|
123
|
+
matched_role_ids: tuple[str, ...] = ()
|
|
124
|
+
matched_grant_ids: tuple[str, ...] = ()
|
|
125
|
+
matched_policy_versions: tuple[str, ...] = ()
|
|
126
|
+
obligations: tuple[str, ...] = ()
|
|
127
|
+
missing_facts: tuple[str, ...] = ()
|
|
128
|
+
evaluated_at: datetime | None = None
|
|
129
|
+
|
|
130
|
+
@property
|
|
131
|
+
def allowed(self) -> bool:
|
|
132
|
+
return self.effect is AuthorizationEffect.ALLOW
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
__all__ = [
|
|
136
|
+
"ActionDefinition", "AuthenticationContext", "AuthorizationDecision",
|
|
137
|
+
"AuthorizationEffect", "AuthorizationRequest", "PrincipalRef", "ResourceRef",
|
|
138
|
+
"RoleDefinition", "RoleGrant",
|
|
139
|
+
]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|