swarmauri_keyprovider_hierarchical 0.3.0.dev4__tar.gz → 0.3.0.dev32__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.
@@ -0,0 +1,213 @@
1
+ Metadata-Version: 2.4
2
+ Name: swarmauri_keyprovider_hierarchical
3
+ Version: 0.3.0.dev32
4
+ Summary: Hierarchical key provider for Swarmauri
5
+ License-Expression: Apache-2.0
6
+ License-File: LICENSE
7
+ Keywords: swarmauri,sdk,standards,keyprovider,hierarchical,key-management
8
+ Author: Jacob Stewart
9
+ Author-email: jacob@swarmauri.com
10
+ Requires-Python: >=3.10,<3.13
11
+ Classifier: License :: OSI Approved :: Apache Software License
12
+ Classifier: Natural Language :: English
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Development Status :: 3 - Alpha
18
+ Classifier: Topic :: Security :: Cryptography
19
+ Classifier: Intended Audience :: Developers
20
+ Classifier: Programming Language :: Python
21
+ Classifier: Programming Language :: Python :: 3
22
+ Classifier: Programming Language :: Python :: 3 :: Only
23
+ Provides-Extra: aws
24
+ Provides-Extra: pkcs11
25
+ Requires-Dist: boto3 ; extra == "aws"
26
+ Requires-Dist: pkcs11 ; extra == "pkcs11"
27
+ Requires-Dist: swarmauri_base
28
+ Requires-Dist: swarmauri_core
29
+ Requires-Dist: swarmauri_keyprovider_local
30
+ Description-Content-Type: text/markdown
31
+
32
+ ![Swarmauri Logo](https://github.com/swarmauri/swarmauri-sdk/blob/3d4d1cfa949399d7019ae9d8f296afba773dfb7f/assets/swarmauri.brand.theme.svg)
33
+
34
+
35
+ <p align="center">
36
+ <a href="https://pypi.org/project/swarmauri_keyprovider_hierarchical/">
37
+ <img src="https://img.shields.io/pypi/dm/swarmauri_keyprovider_hierarchical" alt="PyPI - Downloads"/></a>
38
+ <a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_keyprovider_hierarchical/">
39
+ <img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_keyprovider_hierarchical.svg"/></a>
40
+ <a href="https://pypi.org/project/swarmauri_keyprovider_hierarchical/">
41
+ <img src="https://img.shields.io/pypi/pyversions/swarmauri_keyprovider_hierarchical" alt="PyPI - Python Version"/></a>
42
+ <a href="https://pypi.org/project/swarmauri_keyprovider_hierarchical/">
43
+ <img src="https://img.shields.io/pypi/l/swarmauri_keyprovider_hierarchical" alt="PyPI - License"/></a>
44
+ <a href="https://pypi.org/project/swarmauri_keyprovider_hierarchical/">
45
+ <img src="https://img.shields.io/pypi/v/swarmauri_keyprovider_hierarchical?label=swarmauri_keyprovider_hierarchical&color=green" alt="PyPI - swarmauri_keyprovider_hierarchical"/></a>
46
+ </p>
47
+
48
+ ---
49
+
50
+ # Swarmauri Hierarchical Key Provider
51
+
52
+ Plugin providing a policy-driven composite key provider capable of routing
53
+ key operations across multiple child providers. It implements the
54
+ `IKeyProvider` interface and exposes a single `HierarchicalKeyProvider`
55
+ class.
56
+
57
+ ## Overview
58
+
59
+ `HierarchicalKeyProvider` composes a mapping of named child providers and
60
+ routes every key operation to the correct child according to declarative
61
+ policies. It offers:
62
+
63
+ - **Create/import routing** – specify ordered [`CreateRule`](#routing-policy)
64
+ objects that match key class, algorithm, usage, or export policy. The first
65
+ rule that matches a `KeySpec` wins.
66
+ - **Automatic discovery** – when looking up an unknown key identifier (KID)
67
+ the provider probes each child until it finds the owning provider and caches
68
+ the association for future calls.
69
+ - **Persistent indexing** – optionally persist the learned KID → provider map
70
+ to JSON via the `index_file` argument so the routing cache survives process
71
+ restarts.
72
+ - **Capability passthrough** – rotate, destroy, list, JWKS, HKDF, and random
73
+ byte requests are forwarded transparently to the owning (or designated)
74
+ child provider. JWKS responses are merged across children while avoiding
75
+ duplicate KIDs.
76
+ - **Heuristic fallback** – if no policy matches a create/import request the
77
+ provider falls back to sensible defaults: asymmetric keys prefer children
78
+ named like KMS/PKCS#11, symmetric keys prefer local/file providers, and
79
+ otherwise the first registered child is used.
80
+
81
+ ## Installation
82
+
83
+ Choose the installer that matches your workflow.
84
+
85
+ ### pip
86
+
87
+ ```bash
88
+ pip install swarmauri_keyprovider_hierarchical
89
+ ```
90
+
91
+ ### Poetry
92
+
93
+ ```bash
94
+ poetry add swarmauri_keyprovider_hierarchical
95
+ ```
96
+
97
+ ### uv
98
+
99
+ ```bash
100
+ uv venv # create (or reuse) a virtual environment
101
+ source .venv/bin/activate
102
+ uv pip install swarmauri_keyprovider_hierarchical
103
+ ```
104
+
105
+ If you are already inside a uv-managed environment you can shorten the last
106
+ two steps to `uv pip install swarmauri_keyprovider_hierarchical`.
107
+
108
+ ## Quickstart
109
+
110
+ The example below wires two `LocalKeyProvider` instances behind a
111
+ `HierarchicalKeyProvider`. Symmetric keys are routed to a local provider while
112
+ asymmetric keys land on a provider named `kms`. The composite provider also
113
+ serves random bytes and JWKS responses for all children.
114
+
115
+ <!-- example-start -->
116
+ ```python
117
+ """Create keys across multiple providers with policy-driven routing."""
118
+
119
+ import asyncio
120
+
121
+ from swarmauri_keyprovider_hierarchical import HierarchicalKeyProvider, CreateRule
122
+ from swarmauri_keyprovider_local import LocalKeyProvider
123
+ from swarmauri_core.key_providers.types import (
124
+ ExportPolicy,
125
+ KeyAlg,
126
+ KeyClass,
127
+ KeySpec,
128
+ KeyUse,
129
+ )
130
+
131
+
132
+ async def main() -> None:
133
+ children = {
134
+ "kms": LocalKeyProvider(),
135
+ "local": LocalKeyProvider(),
136
+ }
137
+ provider = HierarchicalKeyProvider(
138
+ children,
139
+ create_policy=[
140
+ CreateRule(provider="kms", klass=KeyClass.asymmetric),
141
+ CreateRule(provider="local", klass=KeyClass.symmetric),
142
+ ],
143
+ randomness_provider="local", # designate a child for random_bytes
144
+ )
145
+
146
+ symmetric_spec = KeySpec(
147
+ klass=KeyClass.symmetric,
148
+ alg=KeyAlg.AES256_GCM,
149
+ uses=(KeyUse.ENCRYPT, KeyUse.DECRYPT),
150
+ export_policy=ExportPolicy.SECRET_WHEN_ALLOWED,
151
+ )
152
+ asymmetric_spec = KeySpec(
153
+ klass=KeyClass.asymmetric,
154
+ alg=KeyAlg.ED25519,
155
+ uses=(KeyUse.SIGN, KeyUse.VERIFY),
156
+ export_policy=ExportPolicy.PUBLIC_ONLY,
157
+ )
158
+
159
+ symmetric_ref = await provider.create_key(symmetric_spec)
160
+ asymmetric_ref = await provider.create_key(asymmetric_spec)
161
+ random_token = await provider.random_bytes(16)
162
+ jwks = await provider.jwks()
163
+
164
+ print(f"Symmetric key kid: {symmetric_ref.kid}")
165
+ print(f"Asymmetric key kid: {asymmetric_ref.kid}")
166
+ print(f"Random token length: {len(random_token)} bytes")
167
+ print(f"JWKS entries: {len(jwks['keys'])}")
168
+
169
+
170
+ if __name__ == "__main__":
171
+ asyncio.run(main())
172
+ ```
173
+ <!-- example-end -->
174
+
175
+ Running the script prints the generated key identifiers, confirms the random
176
+ token length, and shows how many public keys were merged into the JWKS
177
+ document.
178
+
179
+ ## Routing policy
180
+
181
+ `CreateRule` is a dataclass that narrows matching by any combination of
182
+ attributes:
183
+
184
+ - `provider` (required): the name of the child provider to route to.
185
+ - `klass`: limit matches to a specific `KeyClass` (symmetric or asymmetric).
186
+ - `algs`: iterable of allowed `KeyAlg` values.
187
+ - `uses`: iterable of desired `KeyUse` values; at least one requested use must
188
+ intersect with the spec.
189
+ - `export_policies`: iterable of `ExportPolicy` values.
190
+
191
+ Rules are evaluated in order, and the first match wins. When an import policy
192
+ is not supplied, create rules are re-used for imports.
193
+
194
+ ## Index persistence & discovery
195
+
196
+ Pass `index_file` to persist the in-memory KID → provider cache as JSON. On
197
+ startup, any known mappings are re-loaded (invalid provider names are skipped).
198
+ When a lookup is made for an unknown KID the provider probes each child with a
199
+ `get_key` call; if a child recognizes the KID the mapping is remembered and
200
+ future calls avoid probing. Destroying a key (without specifying a version)
201
+ removes the cached entry.
202
+
203
+ ## Randomness & key derivation
204
+
205
+ Use the `randomness_provider` and `derivation_provider` keyword arguments to
206
+ pin those helper methods to a specific child. If they are omitted the first
207
+ registered provider is used for both random bytes and HKDF requests.
208
+
209
+ ## Want to help?
210
+
211
+ If you want to contribute to swarmauri-sdk, read up on our
212
+ [guidelines for contributing](https://github.com/swarmauri/swarmauri-sdk/blob/master/CONTRIBUTING.md)
213
+ that will help you get started.
@@ -0,0 +1,182 @@
1
+ ![Swarmauri Logo](https://github.com/swarmauri/swarmauri-sdk/blob/3d4d1cfa949399d7019ae9d8f296afba773dfb7f/assets/swarmauri.brand.theme.svg)
2
+
3
+
4
+ <p align="center">
5
+ <a href="https://pypi.org/project/swarmauri_keyprovider_hierarchical/">
6
+ <img src="https://img.shields.io/pypi/dm/swarmauri_keyprovider_hierarchical" alt="PyPI - Downloads"/></a>
7
+ <a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_keyprovider_hierarchical/">
8
+ <img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_keyprovider_hierarchical.svg"/></a>
9
+ <a href="https://pypi.org/project/swarmauri_keyprovider_hierarchical/">
10
+ <img src="https://img.shields.io/pypi/pyversions/swarmauri_keyprovider_hierarchical" alt="PyPI - Python Version"/></a>
11
+ <a href="https://pypi.org/project/swarmauri_keyprovider_hierarchical/">
12
+ <img src="https://img.shields.io/pypi/l/swarmauri_keyprovider_hierarchical" alt="PyPI - License"/></a>
13
+ <a href="https://pypi.org/project/swarmauri_keyprovider_hierarchical/">
14
+ <img src="https://img.shields.io/pypi/v/swarmauri_keyprovider_hierarchical?label=swarmauri_keyprovider_hierarchical&color=green" alt="PyPI - swarmauri_keyprovider_hierarchical"/></a>
15
+ </p>
16
+
17
+ ---
18
+
19
+ # Swarmauri Hierarchical Key Provider
20
+
21
+ Plugin providing a policy-driven composite key provider capable of routing
22
+ key operations across multiple child providers. It implements the
23
+ `IKeyProvider` interface and exposes a single `HierarchicalKeyProvider`
24
+ class.
25
+
26
+ ## Overview
27
+
28
+ `HierarchicalKeyProvider` composes a mapping of named child providers and
29
+ routes every key operation to the correct child according to declarative
30
+ policies. It offers:
31
+
32
+ - **Create/import routing** – specify ordered [`CreateRule`](#routing-policy)
33
+ objects that match key class, algorithm, usage, or export policy. The first
34
+ rule that matches a `KeySpec` wins.
35
+ - **Automatic discovery** – when looking up an unknown key identifier (KID)
36
+ the provider probes each child until it finds the owning provider and caches
37
+ the association for future calls.
38
+ - **Persistent indexing** – optionally persist the learned KID → provider map
39
+ to JSON via the `index_file` argument so the routing cache survives process
40
+ restarts.
41
+ - **Capability passthrough** – rotate, destroy, list, JWKS, HKDF, and random
42
+ byte requests are forwarded transparently to the owning (or designated)
43
+ child provider. JWKS responses are merged across children while avoiding
44
+ duplicate KIDs.
45
+ - **Heuristic fallback** – if no policy matches a create/import request the
46
+ provider falls back to sensible defaults: asymmetric keys prefer children
47
+ named like KMS/PKCS#11, symmetric keys prefer local/file providers, and
48
+ otherwise the first registered child is used.
49
+
50
+ ## Installation
51
+
52
+ Choose the installer that matches your workflow.
53
+
54
+ ### pip
55
+
56
+ ```bash
57
+ pip install swarmauri_keyprovider_hierarchical
58
+ ```
59
+
60
+ ### Poetry
61
+
62
+ ```bash
63
+ poetry add swarmauri_keyprovider_hierarchical
64
+ ```
65
+
66
+ ### uv
67
+
68
+ ```bash
69
+ uv venv # create (or reuse) a virtual environment
70
+ source .venv/bin/activate
71
+ uv pip install swarmauri_keyprovider_hierarchical
72
+ ```
73
+
74
+ If you are already inside a uv-managed environment you can shorten the last
75
+ two steps to `uv pip install swarmauri_keyprovider_hierarchical`.
76
+
77
+ ## Quickstart
78
+
79
+ The example below wires two `LocalKeyProvider` instances behind a
80
+ `HierarchicalKeyProvider`. Symmetric keys are routed to a local provider while
81
+ asymmetric keys land on a provider named `kms`. The composite provider also
82
+ serves random bytes and JWKS responses for all children.
83
+
84
+ <!-- example-start -->
85
+ ```python
86
+ """Create keys across multiple providers with policy-driven routing."""
87
+
88
+ import asyncio
89
+
90
+ from swarmauri_keyprovider_hierarchical import HierarchicalKeyProvider, CreateRule
91
+ from swarmauri_keyprovider_local import LocalKeyProvider
92
+ from swarmauri_core.key_providers.types import (
93
+ ExportPolicy,
94
+ KeyAlg,
95
+ KeyClass,
96
+ KeySpec,
97
+ KeyUse,
98
+ )
99
+
100
+
101
+ async def main() -> None:
102
+ children = {
103
+ "kms": LocalKeyProvider(),
104
+ "local": LocalKeyProvider(),
105
+ }
106
+ provider = HierarchicalKeyProvider(
107
+ children,
108
+ create_policy=[
109
+ CreateRule(provider="kms", klass=KeyClass.asymmetric),
110
+ CreateRule(provider="local", klass=KeyClass.symmetric),
111
+ ],
112
+ randomness_provider="local", # designate a child for random_bytes
113
+ )
114
+
115
+ symmetric_spec = KeySpec(
116
+ klass=KeyClass.symmetric,
117
+ alg=KeyAlg.AES256_GCM,
118
+ uses=(KeyUse.ENCRYPT, KeyUse.DECRYPT),
119
+ export_policy=ExportPolicy.SECRET_WHEN_ALLOWED,
120
+ )
121
+ asymmetric_spec = KeySpec(
122
+ klass=KeyClass.asymmetric,
123
+ alg=KeyAlg.ED25519,
124
+ uses=(KeyUse.SIGN, KeyUse.VERIFY),
125
+ export_policy=ExportPolicy.PUBLIC_ONLY,
126
+ )
127
+
128
+ symmetric_ref = await provider.create_key(symmetric_spec)
129
+ asymmetric_ref = await provider.create_key(asymmetric_spec)
130
+ random_token = await provider.random_bytes(16)
131
+ jwks = await provider.jwks()
132
+
133
+ print(f"Symmetric key kid: {symmetric_ref.kid}")
134
+ print(f"Asymmetric key kid: {asymmetric_ref.kid}")
135
+ print(f"Random token length: {len(random_token)} bytes")
136
+ print(f"JWKS entries: {len(jwks['keys'])}")
137
+
138
+
139
+ if __name__ == "__main__":
140
+ asyncio.run(main())
141
+ ```
142
+ <!-- example-end -->
143
+
144
+ Running the script prints the generated key identifiers, confirms the random
145
+ token length, and shows how many public keys were merged into the JWKS
146
+ document.
147
+
148
+ ## Routing policy
149
+
150
+ `CreateRule` is a dataclass that narrows matching by any combination of
151
+ attributes:
152
+
153
+ - `provider` (required): the name of the child provider to route to.
154
+ - `klass`: limit matches to a specific `KeyClass` (symmetric or asymmetric).
155
+ - `algs`: iterable of allowed `KeyAlg` values.
156
+ - `uses`: iterable of desired `KeyUse` values; at least one requested use must
157
+ intersect with the spec.
158
+ - `export_policies`: iterable of `ExportPolicy` values.
159
+
160
+ Rules are evaluated in order, and the first match wins. When an import policy
161
+ is not supplied, create rules are re-used for imports.
162
+
163
+ ## Index persistence & discovery
164
+
165
+ Pass `index_file` to persist the in-memory KID → provider cache as JSON. On
166
+ startup, any known mappings are re-loaded (invalid provider names are skipped).
167
+ When a lookup is made for an unknown KID the provider probes each child with a
168
+ `get_key` call; if a child recognizes the KID the mapping is remembered and
169
+ future calls avoid probing. Destroying a key (without specifying a version)
170
+ removes the cached entry.
171
+
172
+ ## Randomness & key derivation
173
+
174
+ Use the `randomness_provider` and `derivation_provider` keyword arguments to
175
+ pin those helper methods to a specific child. If they are omitted the first
176
+ registered provider is used for both random bytes and HKDF requests.
177
+
178
+ ## Want to help?
179
+
180
+ If you want to contribute to swarmauri-sdk, read up on our
181
+ [guidelines for contributing](https://github.com/swarmauri/swarmauri-sdk/blob/master/CONTRIBUTING.md)
182
+ that will help you get started.
@@ -1,11 +1,11 @@
1
1
  [project]
2
2
  name = "swarmauri_keyprovider_hierarchical"
3
- version = "0.3.0.dev4"
3
+ version = "0.3.0.dev32"
4
4
  description = "Hierarchical key provider for Swarmauri"
5
5
  license = "Apache-2.0"
6
6
  readme = "README.md"
7
7
  requires-python = ">=3.10,<3.13"
8
- authors = [{ name = "Swarmauri", email = "opensource@swarmauri.com" }]
8
+ authors = [{ name = "Jacob Stewart", email = "jacob@swarmauri.com" }]
9
9
  classifiers = [
10
10
  "License :: OSI Approved :: Apache Software License",
11
11
  "Natural Language :: English",
@@ -16,12 +16,23 @@ classifiers = [
16
16
  "Development Status :: 3 - Alpha",
17
17
  "Topic :: Security :: Cryptography",
18
18
  "Intended Audience :: Developers",
19
+ "Programming Language :: Python",
20
+ "Programming Language :: Python :: 3",
21
+ "Programming Language :: Python :: 3 :: Only",
19
22
  ]
20
23
  dependencies = [
21
24
  "swarmauri_core",
22
25
  "swarmauri_base",
23
26
  "swarmauri_keyprovider_local",
24
27
  ]
28
+ keywords = [
29
+ 'swarmauri',
30
+ 'sdk',
31
+ 'standards',
32
+ 'keyprovider',
33
+ 'hierarchical',
34
+ 'key-management',
35
+ ]
25
36
 
26
37
  [project.optional-dependencies]
27
38
  aws = ["boto3"]
@@ -40,6 +51,7 @@ markers = [
40
51
  "perf: Performance tests",
41
52
  "func: Functional tests",
42
53
  "rfc: RFC compliance tests",
54
+ "example: Documentation examples",
43
55
  ]
44
56
  benchmark_min_rounds = 1
45
57
  timeout = 300
@@ -14,9 +14,15 @@ from typing import (
14
14
  Literal,
15
15
  )
16
16
 
17
- from swarmauri_base.keys.KeyProviderBase import KeyProviderBase
18
- from swarmauri_core.keys.IKeyProvider import IKeyProvider
19
- from swarmauri_core.keys.types import KeySpec, KeyAlg, KeyClass, ExportPolicy, KeyUse
17
+ from swarmauri_base.key_providers.KeyProviderBase import KeyProviderBase
18
+ from swarmauri_core.key_providers.IKeyProvider import IKeyProvider
19
+ from swarmauri_core.key_providers.types import (
20
+ KeySpec,
21
+ KeyAlg,
22
+ KeyClass,
23
+ ExportPolicy,
24
+ KeyUse,
25
+ )
20
26
  from swarmauri_core.crypto.types import KeyRef
21
27
 
22
28
 
@@ -1,41 +0,0 @@
1
- Metadata-Version: 2.3
2
- Name: swarmauri_keyprovider_hierarchical
3
- Version: 0.3.0.dev4
4
- Summary: Hierarchical key provider for Swarmauri
5
- License: Apache-2.0
6
- Author: Swarmauri
7
- Author-email: opensource@swarmauri.com
8
- Requires-Python: >=3.10,<3.13
9
- Classifier: License :: OSI Approved :: Apache Software License
10
- Classifier: Natural Language :: English
11
- Classifier: Programming Language :: Python :: 3.10
12
- Classifier: Programming Language :: Python :: 3.11
13
- Classifier: Programming Language :: Python :: 3.12
14
- Classifier: Programming Language :: Python :: 3.13
15
- Classifier: Development Status :: 3 - Alpha
16
- Classifier: Topic :: Security :: Cryptography
17
- Classifier: Intended Audience :: Developers
18
- Provides-Extra: aws
19
- Provides-Extra: pkcs11
20
- Requires-Dist: boto3 ; extra == "aws"
21
- Requires-Dist: pkcs11 ; extra == "pkcs11"
22
- Requires-Dist: swarmauri_base
23
- Requires-Dist: swarmauri_core
24
- Requires-Dist: swarmauri_keyprovider_local
25
- Description-Content-Type: text/markdown
26
-
27
- ![Swamauri Logo](https://res.cloudinary.com/dbjmpekvl/image/upload/v1730099724/Swarmauri-logo-lockup-2048x757_hww01w.png)
28
-
29
- # Swarmauri Hierarchical Key Provider
30
-
31
- Plugin providing a policy-driven composite key provider capable of routing
32
- key operations across multiple child providers. It implements the
33
- `IKeyProvider` interface and exposes a single `HierarchicalKeyProvider`
34
- class.
35
-
36
- ## Installation
37
-
38
- ```bash
39
- pip install swarmauri_keyprovider_hierarchical
40
- ```
41
-
@@ -1,14 +0,0 @@
1
- ![Swamauri Logo](https://res.cloudinary.com/dbjmpekvl/image/upload/v1730099724/Swarmauri-logo-lockup-2048x757_hww01w.png)
2
-
3
- # Swarmauri Hierarchical Key Provider
4
-
5
- Plugin providing a policy-driven composite key provider capable of routing
6
- key operations across multiple child providers. It implements the
7
- `IKeyProvider` interface and exposes a single `HierarchicalKeyProvider`
8
- class.
9
-
10
- ## Installation
11
-
12
- ```bash
13
- pip install swarmauri_keyprovider_hierarchical
14
- ```