swarmauri_keyprovider_aws_kms 0.3.4.dev2__tar.gz → 0.11.0.dev1__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,230 @@
1
+ Metadata-Version: 2.4
2
+ Name: swarmauri_keyprovider_aws_kms
3
+ Version: 0.11.0.dev1
4
+ Summary: AWS KMS-backed Swarmauri key provider for non-exportable key creation, alias-based rotation, KeyRef metadata, and public JWKS publishing.
5
+ License-Expression: Apache-2.0
6
+ License-File: LICENSE
7
+ Keywords: swarmauri,swarmauri keyprovider,key provider,keyprovider,aws,kms,aws kms,key management service,jwks,jwk,key rotation,non exportable keys,pki,cryptography,cloud kms,composable intelligence
8
+ Author: Jacob Stewart
9
+ Author-email: jacob@swarmauri.com
10
+ Requires-Python: >=3.10,<3.15
11
+ Classifier: License :: OSI Approved :: Apache Software License
12
+ Classifier: Natural Language :: English
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Intended Audience :: Information Technology
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Topic :: Security
18
+ Classifier: Topic :: Security :: Cryptography
19
+ Classifier: Topic :: Software Development :: Libraries
20
+ Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
21
+ Classifier: Programming Language :: Python
22
+ Classifier: Programming Language :: Python :: 3
23
+ Classifier: Programming Language :: Python :: 3 :: Only
24
+ Classifier: Programming Language :: Python :: 3.10
25
+ Classifier: Programming Language :: Python :: 3.11
26
+ Classifier: Programming Language :: Python :: 3.12
27
+ Classifier: Programming Language :: Python :: 3.13
28
+ Classifier: Programming Language :: Python :: 3.14
29
+ Provides-Extra: perf
30
+ Requires-Dist: boto3 (>=1.28.0)
31
+ Requires-Dist: cryptography
32
+ Requires-Dist: pytest-benchmark (>=4.0.0) ; extra == "perf"
33
+ Requires-Dist: swarmauri_base
34
+ Requires-Dist: swarmauri_core
35
+ Requires-Dist: swarmauri_standard
36
+ Description-Content-Type: text/markdown
37
+
38
+ ![Swarmauri Logo](https://raw.githubusercontent.com/swarmauri/swarmauri-sdk/master/assets/swarmauri_sdk_brand.png)
39
+
40
+ <p align="center">
41
+ <a href="https://pepy.tech/project/swarmauri_keyprovider_aws_kms/">
42
+ <img src="https://static.pepy.tech/badge/swarmauri_keyprovider_aws_kms/month" alt="PyPI - Downloads"/></a>
43
+ <a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/community/swarmauri_keyprovider_aws_kms/">
44
+ <img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/community/swarmauri_keyprovider_aws_kms.svg"/></a>
45
+ <a href="https://pypi.org/project/swarmauri_keyprovider_aws_kms/">
46
+ <img src="https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12%20%7C%203.13%20%7C%203.14-blue" alt="PyPI - Python Version"/></a>
47
+ <a href="https://pypi.org/project/swarmauri_keyprovider_aws_kms/">
48
+ <img src="https://img.shields.io/pypi/l/swarmauri_keyprovider_aws_kms" alt="PyPI - License"/></a>
49
+ <a href="https://pypi.org/project/swarmauri_keyprovider_aws_kms/">
50
+ <img src="https://img.shields.io/pypi/v/swarmauri_keyprovider_aws_kms?label=swarmauri_keyprovider_aws_kms&color=green" alt="PyPI - swarmauri_keyprovider_aws_kms"/></a>
51
+ <a href="https://discord.gg/N4UpBuQv8T">
52
+ <img src="https://img.shields.io/badge/Discord-Join%20Chat-5865F2?logo=discord&logoColor=white" alt="Discord"/></a></p>
53
+
54
+ # Swarmauri AWS KMS Key Provider
55
+
56
+ `swarmauri_keyprovider_aws_kms` provides `AwsKmsKeyProvider`, a Swarmauri key provider backed by [AWS Key Management Service](https://docs.aws.amazon.com/kms/latest/APIReference/). It creates non-exportable AWS KMS keys, maintains stable and versioned aliases, returns Swarmauri `KeyRef` metadata, publishes public JWK/JWKS material for asymmetric keys, and supports rotation and scheduled deletion workflows.
57
+
58
+ ## Why Swarmauri AWS KMS Key Provider?
59
+
60
+ Use this package when Swarmauri applications need AWS-managed key material without returning private keys to application memory. The provider maps Swarmauri `KeySpec` values to AWS KMS `KeySpec` and `KeyUsage`, keeps versioned aliases for rotation, and exposes public key metadata in a shape that downstream token, signing, and verifier components can consume.
61
+
62
+ ## FAQ
63
+
64
+ ### Q: Does this provider export private key material?
65
+
66
+ A: No. AWS KMS keys created by this provider are represented as non-exportable `KeyRef` objects. `get_key(include_secret=True)` still returns metadata and public material where available, not private material.
67
+
68
+ ### Q: Which AWS KMS key types are supported?
69
+
70
+ A: The provider supports symmetric AES-256-GCM through `SYMMETRIC_DEFAULT`, RSA OAEP SHA-256, RSA PSS SHA-256, and ECDSA P-256 SHA-256. RSA sizes map to AWS-supported 2048, 3072, or 4096 bit keys.
71
+
72
+ ### Q: How does rotation work?
73
+
74
+ A: `rotate_key(kid)` creates a new KMS key with the same algorithm metadata, creates a new `alias/<prefix>/<kid>/vN` alias, and repoints `alias/<prefix>/<kid>` to the latest version. Older version aliases remain available.
75
+
76
+ ### Q: Does this package call AWS KMS Sign, Encrypt, or Decrypt?
77
+
78
+ A: No. This package manages keys and public metadata. Use a signing, encryption, or envelope-encryption component for cryptographic operations that call KMS runtime APIs.
79
+
80
+ ## Features
81
+
82
+ - `AwsKmsKeyProvider` registered under the `swarmauri.key_providers` entry point.
83
+ - AWS KMS key creation through `boto3`.
84
+ - Stable latest aliases and version aliases per `kid`.
85
+ - Rotation by creating a new KMS key version and updating aliases.
86
+ - `KeyRef` metadata with KMS key ID, region, label, algorithm, version, public PEM when supported, and fingerprint.
87
+ - Public JWK conversion for RSA and P-256 public keys.
88
+ - JWKS aggregation for latest key versions.
89
+ - Scheduled key deletion with AWS KMS deletion windows.
90
+ - Local `random_bytes()` and HKDF helpers.
91
+ - Python 3.10, 3.11, 3.12, 3.13, and 3.14 support.
92
+
93
+ ## Prerequisites
94
+
95
+ - AWS credentials resolvable by `boto3`.
96
+ - IAM permissions for the KMS operations you use, commonly `kms:CreateKey`, `kms:CreateAlias`, `kms:UpdateAlias`, `kms:ListAliases`, `kms:DescribeKey`, `kms:ListResourceTags`, `kms:GetPublicKey`, and `kms:ScheduleKeyDeletion`.
97
+ - An AWS region such as `us-east-1`.
98
+ - Optional custom key policy when account defaults are not enough for your access model.
99
+
100
+ ## Installation
101
+
102
+ Install with `uv`:
103
+
104
+ ```bash
105
+ uv add swarmauri_keyprovider_aws_kms
106
+ ```
107
+
108
+ Install with `pip`:
109
+
110
+ ```bash
111
+ pip install swarmauri_keyprovider_aws_kms
112
+ ```
113
+
114
+ ## Usage
115
+
116
+ Create and rotate a non-exportable AWS KMS key:
117
+
118
+ ```python
119
+ import asyncio
120
+
121
+ from swarmauri_keyprovider_aws_kms import AwsKmsKeyProvider
122
+ from swarmauri_core.key_providers.types import (
123
+ ExportPolicy,
124
+ KeyAlg,
125
+ KeyClass,
126
+ KeySpec,
127
+ )
128
+
129
+
130
+ async def main() -> None:
131
+ provider = AwsKmsKeyProvider(
132
+ region="us-east-1",
133
+ alias_prefix="swarmauri-prod",
134
+ )
135
+ spec = KeySpec(
136
+ klass=KeyClass.asymmetric,
137
+ alg=KeyAlg.RSA_PSS_SHA256,
138
+ size_bits=3072,
139
+ export_policy=ExportPolicy.never_export_secret,
140
+ label="jwt-signing",
141
+ )
142
+
143
+ key_ref = await provider.create_key(spec)
144
+ rotated = await provider.rotate_key(key_ref.kid)
145
+
146
+ print(key_ref.kid, key_ref.version)
147
+ print(rotated.kid, rotated.version)
148
+
149
+
150
+ asyncio.run(main())
151
+ ```
152
+
153
+ Publish public JWK metadata for verifiers:
154
+
155
+ ```python
156
+ import asyncio
157
+
158
+ from swarmauri_keyprovider_aws_kms import AwsKmsKeyProvider
159
+
160
+
161
+ async def main() -> None:
162
+ provider = AwsKmsKeyProvider(region="us-east-1", alias_prefix="swarmauri-prod")
163
+
164
+ jwk = await provider.get_public_jwk("jwt-signing-kid")
165
+ jwks = await provider.jwks(prefix_kids="jwt")
166
+
167
+ print(jwk["kid"])
168
+ print([key["kid"] for key in jwks["keys"]])
169
+
170
+
171
+ asyncio.run(main())
172
+ ```
173
+
174
+ Use local random bytes and HKDF helpers:
175
+
176
+ ```python
177
+ import asyncio
178
+
179
+ from swarmauri_keyprovider_aws_kms import AwsKmsKeyProvider
180
+
181
+
182
+ async def main() -> None:
183
+ provider = AwsKmsKeyProvider(region="us-east-1")
184
+ salt = await provider.random_bytes(32)
185
+ secret = await provider.random_bytes(32)
186
+ derived = await provider.hkdf(
187
+ secret,
188
+ salt=salt,
189
+ info=b"swarmauri/aws-kms/example",
190
+ length=32,
191
+ )
192
+
193
+ print(len(derived))
194
+
195
+
196
+ asyncio.run(main())
197
+ ```
198
+
199
+ ## Related Packages
200
+
201
+ Key provider packages:
202
+
203
+ - [swarmauri_keyprovider_gcpkms](https://pypi.org/project/swarmauri_keyprovider_gcpkms/)
204
+ - [swarmauri_keyprovider_vaulttransit](https://pypi.org/project/swarmauri_keyprovider_vaulttransit/)
205
+ - [swarmauri_keyprovider_file](https://pypi.org/project/swarmauri_keyprovider_file/)
206
+ - [swarmauri_keyprovider_local](https://pypi.org/project/swarmauri_keyprovider_local/)
207
+ - [swarmauri_keyprovider_inmemory](https://pypi.org/project/swarmauri_keyprovider_inmemory/)
208
+ - [swarmauri_keyprovider_remote_jwks](https://pypi.org/project/swarmauri_keyprovider_remote_jwks/)
209
+
210
+ Foundational packages:
211
+
212
+ - [swarmauri_core](https://pypi.org/project/swarmauri_core/) defines key provider types.
213
+ - [swarmauri_base](https://pypi.org/project/swarmauri_base/) provides `KeyProviderBase`.
214
+ - [swarmauri_standard](https://pypi.org/project/swarmauri_standard/) provides standard Swarmauri components.
215
+ - [swarmauri](https://pypi.org/project/swarmauri/) provides namespace imports and plugin discovery.
216
+
217
+ ## Best Practices
218
+
219
+ - Use narrow IAM permissions and explicit key policies for production accounts.
220
+ - Treat scheduled deletion as destructive; inspect `list_versions(kid)` before calling `destroy_key()`.
221
+ - Cache JWKS responses in verifier services, but refresh after planned rotations.
222
+ - Use clear `alias_prefix` values per environment to avoid mixing development and production keys.
223
+ - Keep cryptographic operations in dedicated signing or encryption components that can enforce operation-specific policy.
224
+
225
+ ## License
226
+
227
+ Apache-2.0
228
+
229
+
230
+
@@ -0,0 +1,192 @@
1
+ ![Swarmauri Logo](https://raw.githubusercontent.com/swarmauri/swarmauri-sdk/master/assets/swarmauri_sdk_brand.png)
2
+
3
+ <p align="center">
4
+ <a href="https://pepy.tech/project/swarmauri_keyprovider_aws_kms/">
5
+ <img src="https://static.pepy.tech/badge/swarmauri_keyprovider_aws_kms/month" alt="PyPI - Downloads"/></a>
6
+ <a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/community/swarmauri_keyprovider_aws_kms/">
7
+ <img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/community/swarmauri_keyprovider_aws_kms.svg"/></a>
8
+ <a href="https://pypi.org/project/swarmauri_keyprovider_aws_kms/">
9
+ <img src="https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12%20%7C%203.13%20%7C%203.14-blue" alt="PyPI - Python Version"/></a>
10
+ <a href="https://pypi.org/project/swarmauri_keyprovider_aws_kms/">
11
+ <img src="https://img.shields.io/pypi/l/swarmauri_keyprovider_aws_kms" alt="PyPI - License"/></a>
12
+ <a href="https://pypi.org/project/swarmauri_keyprovider_aws_kms/">
13
+ <img src="https://img.shields.io/pypi/v/swarmauri_keyprovider_aws_kms?label=swarmauri_keyprovider_aws_kms&color=green" alt="PyPI - swarmauri_keyprovider_aws_kms"/></a>
14
+ <a href="https://discord.gg/N4UpBuQv8T">
15
+ <img src="https://img.shields.io/badge/Discord-Join%20Chat-5865F2?logo=discord&logoColor=white" alt="Discord"/></a></p>
16
+
17
+ # Swarmauri AWS KMS Key Provider
18
+
19
+ `swarmauri_keyprovider_aws_kms` provides `AwsKmsKeyProvider`, a Swarmauri key provider backed by [AWS Key Management Service](https://docs.aws.amazon.com/kms/latest/APIReference/). It creates non-exportable AWS KMS keys, maintains stable and versioned aliases, returns Swarmauri `KeyRef` metadata, publishes public JWK/JWKS material for asymmetric keys, and supports rotation and scheduled deletion workflows.
20
+
21
+ ## Why Swarmauri AWS KMS Key Provider?
22
+
23
+ Use this package when Swarmauri applications need AWS-managed key material without returning private keys to application memory. The provider maps Swarmauri `KeySpec` values to AWS KMS `KeySpec` and `KeyUsage`, keeps versioned aliases for rotation, and exposes public key metadata in a shape that downstream token, signing, and verifier components can consume.
24
+
25
+ ## FAQ
26
+
27
+ ### Q: Does this provider export private key material?
28
+
29
+ A: No. AWS KMS keys created by this provider are represented as non-exportable `KeyRef` objects. `get_key(include_secret=True)` still returns metadata and public material where available, not private material.
30
+
31
+ ### Q: Which AWS KMS key types are supported?
32
+
33
+ A: The provider supports symmetric AES-256-GCM through `SYMMETRIC_DEFAULT`, RSA OAEP SHA-256, RSA PSS SHA-256, and ECDSA P-256 SHA-256. RSA sizes map to AWS-supported 2048, 3072, or 4096 bit keys.
34
+
35
+ ### Q: How does rotation work?
36
+
37
+ A: `rotate_key(kid)` creates a new KMS key with the same algorithm metadata, creates a new `alias/<prefix>/<kid>/vN` alias, and repoints `alias/<prefix>/<kid>` to the latest version. Older version aliases remain available.
38
+
39
+ ### Q: Does this package call AWS KMS Sign, Encrypt, or Decrypt?
40
+
41
+ A: No. This package manages keys and public metadata. Use a signing, encryption, or envelope-encryption component for cryptographic operations that call KMS runtime APIs.
42
+
43
+ ## Features
44
+
45
+ - `AwsKmsKeyProvider` registered under the `swarmauri.key_providers` entry point.
46
+ - AWS KMS key creation through `boto3`.
47
+ - Stable latest aliases and version aliases per `kid`.
48
+ - Rotation by creating a new KMS key version and updating aliases.
49
+ - `KeyRef` metadata with KMS key ID, region, label, algorithm, version, public PEM when supported, and fingerprint.
50
+ - Public JWK conversion for RSA and P-256 public keys.
51
+ - JWKS aggregation for latest key versions.
52
+ - Scheduled key deletion with AWS KMS deletion windows.
53
+ - Local `random_bytes()` and HKDF helpers.
54
+ - Python 3.10, 3.11, 3.12, 3.13, and 3.14 support.
55
+
56
+ ## Prerequisites
57
+
58
+ - AWS credentials resolvable by `boto3`.
59
+ - IAM permissions for the KMS operations you use, commonly `kms:CreateKey`, `kms:CreateAlias`, `kms:UpdateAlias`, `kms:ListAliases`, `kms:DescribeKey`, `kms:ListResourceTags`, `kms:GetPublicKey`, and `kms:ScheduleKeyDeletion`.
60
+ - An AWS region such as `us-east-1`.
61
+ - Optional custom key policy when account defaults are not enough for your access model.
62
+
63
+ ## Installation
64
+
65
+ Install with `uv`:
66
+
67
+ ```bash
68
+ uv add swarmauri_keyprovider_aws_kms
69
+ ```
70
+
71
+ Install with `pip`:
72
+
73
+ ```bash
74
+ pip install swarmauri_keyprovider_aws_kms
75
+ ```
76
+
77
+ ## Usage
78
+
79
+ Create and rotate a non-exportable AWS KMS key:
80
+
81
+ ```python
82
+ import asyncio
83
+
84
+ from swarmauri_keyprovider_aws_kms import AwsKmsKeyProvider
85
+ from swarmauri_core.key_providers.types import (
86
+ ExportPolicy,
87
+ KeyAlg,
88
+ KeyClass,
89
+ KeySpec,
90
+ )
91
+
92
+
93
+ async def main() -> None:
94
+ provider = AwsKmsKeyProvider(
95
+ region="us-east-1",
96
+ alias_prefix="swarmauri-prod",
97
+ )
98
+ spec = KeySpec(
99
+ klass=KeyClass.asymmetric,
100
+ alg=KeyAlg.RSA_PSS_SHA256,
101
+ size_bits=3072,
102
+ export_policy=ExportPolicy.never_export_secret,
103
+ label="jwt-signing",
104
+ )
105
+
106
+ key_ref = await provider.create_key(spec)
107
+ rotated = await provider.rotate_key(key_ref.kid)
108
+
109
+ print(key_ref.kid, key_ref.version)
110
+ print(rotated.kid, rotated.version)
111
+
112
+
113
+ asyncio.run(main())
114
+ ```
115
+
116
+ Publish public JWK metadata for verifiers:
117
+
118
+ ```python
119
+ import asyncio
120
+
121
+ from swarmauri_keyprovider_aws_kms import AwsKmsKeyProvider
122
+
123
+
124
+ async def main() -> None:
125
+ provider = AwsKmsKeyProvider(region="us-east-1", alias_prefix="swarmauri-prod")
126
+
127
+ jwk = await provider.get_public_jwk("jwt-signing-kid")
128
+ jwks = await provider.jwks(prefix_kids="jwt")
129
+
130
+ print(jwk["kid"])
131
+ print([key["kid"] for key in jwks["keys"]])
132
+
133
+
134
+ asyncio.run(main())
135
+ ```
136
+
137
+ Use local random bytes and HKDF helpers:
138
+
139
+ ```python
140
+ import asyncio
141
+
142
+ from swarmauri_keyprovider_aws_kms import AwsKmsKeyProvider
143
+
144
+
145
+ async def main() -> None:
146
+ provider = AwsKmsKeyProvider(region="us-east-1")
147
+ salt = await provider.random_bytes(32)
148
+ secret = await provider.random_bytes(32)
149
+ derived = await provider.hkdf(
150
+ secret,
151
+ salt=salt,
152
+ info=b"swarmauri/aws-kms/example",
153
+ length=32,
154
+ )
155
+
156
+ print(len(derived))
157
+
158
+
159
+ asyncio.run(main())
160
+ ```
161
+
162
+ ## Related Packages
163
+
164
+ Key provider packages:
165
+
166
+ - [swarmauri_keyprovider_gcpkms](https://pypi.org/project/swarmauri_keyprovider_gcpkms/)
167
+ - [swarmauri_keyprovider_vaulttransit](https://pypi.org/project/swarmauri_keyprovider_vaulttransit/)
168
+ - [swarmauri_keyprovider_file](https://pypi.org/project/swarmauri_keyprovider_file/)
169
+ - [swarmauri_keyprovider_local](https://pypi.org/project/swarmauri_keyprovider_local/)
170
+ - [swarmauri_keyprovider_inmemory](https://pypi.org/project/swarmauri_keyprovider_inmemory/)
171
+ - [swarmauri_keyprovider_remote_jwks](https://pypi.org/project/swarmauri_keyprovider_remote_jwks/)
172
+
173
+ Foundational packages:
174
+
175
+ - [swarmauri_core](https://pypi.org/project/swarmauri_core/) defines key provider types.
176
+ - [swarmauri_base](https://pypi.org/project/swarmauri_base/) provides `KeyProviderBase`.
177
+ - [swarmauri_standard](https://pypi.org/project/swarmauri_standard/) provides standard Swarmauri components.
178
+ - [swarmauri](https://pypi.org/project/swarmauri/) provides namespace imports and plugin discovery.
179
+
180
+ ## Best Practices
181
+
182
+ - Use narrow IAM permissions and explicit key policies for production accounts.
183
+ - Treat scheduled deletion as destructive; inspect `list_versions(kid)` before calling `destroy_key()`.
184
+ - Cache JWKS responses in verifier services, but refresh after planned rotations.
185
+ - Use clear `alias_prefix` values per environment to avoid mixing development and production keys.
186
+ - Keep cryptographic operations in dedicated signing or encryption components that can enforce operation-specific policy.
187
+
188
+ ## License
189
+
190
+ Apache-2.0
191
+
192
+
@@ -1,7 +1,7 @@
1
1
  [project]
2
2
  name = "swarmauri_keyprovider_aws_kms"
3
- version = "0.3.4.dev2"
4
- description = "AWS KMS KeyProvider for Swarmauri"
3
+ version = "0.11.0.dev1"
4
+ description = "AWS KMS-backed Swarmauri key provider for non-exportable key creation, alias-based rotation, KeyRef metadata, and public JWKS publishing."
5
5
  license = "Apache-2.0"
6
6
  readme = "README.md"
7
7
  repository = "http://github.com/swarmauri/swarmauri-sdk"
@@ -11,6 +11,11 @@ classifiers = [
11
11
  "Natural Language :: English",
12
12
  "Development Status :: 3 - Alpha",
13
13
  "Intended Audience :: Developers",
14
+ "Intended Audience :: Information Technology",
15
+ "Operating System :: OS Independent",
16
+ "Topic :: Security",
17
+ "Topic :: Security :: Cryptography",
18
+ "Topic :: Software Development :: Libraries",
14
19
  "Topic :: Software Development :: Libraries :: Application Frameworks",
15
20
  "Programming Language :: Python",
16
21
  "Programming Language :: Python :: 3",
@@ -31,9 +36,21 @@ dependencies = [
31
36
  ]
32
37
  keywords = [
33
38
  "swarmauri",
39
+ "swarmauri keyprovider",
40
+ "key provider",
34
41
  "keyprovider",
35
42
  "aws",
36
43
  "kms",
44
+ "aws kms",
45
+ "key management service",
46
+ "jwks",
47
+ "jwk",
48
+ "key rotation",
49
+ "non exportable keys",
50
+ "pki",
51
+ "cryptography",
52
+ "cloud kms",
53
+ "composable intelligence",
37
54
  ]
38
55
 
39
56
  [project.optional-dependencies]
@@ -78,7 +95,7 @@ dev = [
78
95
  "pytest-xdist>=3.6.1",
79
96
  "pytest-json-report>=1.5.0",
80
97
  "python-dotenv",
81
- "requests>=2.32.3",
98
+ "httpx>=0.27",
82
99
  "flake8>=7.0",
83
100
  "pytest-timeout>=2.3.1",
84
101
  "ruff>=0.9.9",
@@ -45,14 +45,18 @@ class AwsKmsKeyProvider(KeyProviderBase):
45
45
  - Creates new KMS CMKs per (kid, version); maintains stable alias:
46
46
  alias/<alias_prefix>/<kid> -> latest version
47
47
  alias/<alias_prefix>/<kid>/v<ver> -> specific version
48
- - Rotation = create new KMS key (same alg/usage), bump /vN alias, repoint "latest".
49
- - get_key(include_secret=...) never returns private material (KMS non-exportable).
48
+ - Rotation = create new KMS key (same alg/usage), bump /vN alias, repoint
49
+ "latest".
50
+ - get_key(include_secret=...) never returns private material (KMS
51
+ non-exportable).
50
52
  - get_public_jwk() parses GetPublicKey DER to RFC 7517 JWK.
51
- - jwks() publishes latest per 'kid' (resolved via stable alias) with kid.version.
53
+ - jwks() publishes latest per 'kid' (resolved via stable alias) with
54
+ kid.version.
52
55
 
53
56
  IAM needed (minimum):
54
57
  kms:CreateKey, kms:CreateAlias, kms:UpdateAlias, kms:ListAliases,
55
- kms:DescribeKey, kms:ListResourceTags, kms:GetPublicKey, kms:ScheduleKeyDeletion
58
+ kms:DescribeKey, kms:ListResourceTags, kms:GetPublicKey,
59
+ kms:ScheduleKeyDeletion
56
60
  """
57
61
 
58
62
  type: Literal["AwsKmsKeyProvider"] = "AwsKmsKeyProvider"
@@ -66,9 +70,12 @@ class AwsKmsKeyProvider(KeyProviderBase):
66
70
  ):
67
71
  """
68
72
  region: AWS region name (e.g., "us-east-1")
69
- alias_prefix: alias namespace (no 'alias/' prefix here). Final aliases look like:
70
- 'alias/<alias_prefix>/<kid>' and 'alias/<alias_prefix>/<kid>/v<ver>'
71
- key_policy: optional explicit key policy JSON; if None, KMS uses account default.
73
+ alias_prefix: alias namespace (no 'alias/' prefix here). Final aliases
74
+ look like:
75
+ 'alias/<alias_prefix>/<kid>' and
76
+ 'alias/<alias_prefix>/<kid>/v<ver>'
77
+ key_policy: optional explicit key policy JSON; if None, KMS uses
78
+ account default.
72
79
  """
73
80
  super().__init__()
74
81
  self._region = region
@@ -98,31 +105,48 @@ class AwsKmsKeyProvider(KeyProviderBase):
98
105
  def _alias_version(self, kid: str, version: int) -> str:
99
106
  return f"alias/{self._alias_prefix}/{kid}/v{version}"
100
107
 
101
- def _create_or_update_alias(self, alias_name: str, target_key_id: str) -> None:
108
+ def _create_or_update_alias(
109
+ self, alias_name: str, target_key_id: str
110
+ ) -> None:
102
111
  try:
103
- self._kms.create_alias(AliasName=alias_name, TargetKeyId=target_key_id)
112
+ self._kms.create_alias(
113
+ AliasName=alias_name, TargetKeyId=target_key_id
114
+ )
104
115
  except ClientError as e:
105
- if e.response.get("Error", {}).get("Code") == "AlreadyExistsException":
106
- self._kms.update_alias(AliasName=alias_name, TargetKeyId=target_key_id)
116
+ if (
117
+ e.response.get("Error", {}).get("Code")
118
+ == "AlreadyExistsException"
119
+ ):
120
+ self._kms.update_alias(
121
+ AliasName=alias_name, TargetKeyId=target_key_id
122
+ )
107
123
  else:
108
124
  raise
109
125
 
110
126
  def _kms_spec_for_alg(self, spec: KeySpec) -> _KmsSpec:
111
127
  if spec.klass == KeyClass.symmetric:
112
128
  if spec.alg != KeyAlg.AES256_GCM:
113
- raise ValueError(f"Unsupported symmetric alg for AWS KMS: {spec.alg}")
114
- return _KmsSpec(KeySpec="SYMMETRIC_DEFAULT", KeyUsage="ENCRYPT_DECRYPT")
129
+ raise ValueError(
130
+ f"Unsupported symmetric alg for AWS KMS: {spec.alg}"
131
+ )
132
+ return _KmsSpec(
133
+ KeySpec="SYMMETRIC_DEFAULT", KeyUsage="ENCRYPT_DECRYPT"
134
+ )
115
135
 
116
136
  if spec.alg == KeyAlg.RSA_OAEP_SHA256:
117
137
  bits = spec.size_bits or 3072
118
138
  if bits not in (2048, 3072, 4096):
119
- raise ValueError("AWS KMS RSA supports 2048/3072/4096 bit sizes")
139
+ raise ValueError(
140
+ "AWS KMS RSA supports 2048/3072/4096 bit sizes"
141
+ )
120
142
  return _KmsSpec(KeySpec=f"RSA_{bits}", KeyUsage="ENCRYPT_DECRYPT")
121
143
 
122
144
  if spec.alg == KeyAlg.RSA_PSS_SHA256:
123
145
  bits = spec.size_bits or 3072
124
146
  if bits not in (2048, 3072, 4096):
125
- raise ValueError("AWS KMS RSA supports 2048/3072/4096 bit sizes")
147
+ raise ValueError(
148
+ "AWS KMS RSA supports 2048/3072/4096 bit sizes"
149
+ )
126
150
  return _KmsSpec(KeySpec=f"RSA_{bits}", KeyUsage="SIGN_VERIFY")
127
151
 
128
152
  if spec.alg == KeyAlg.ECDSA_P256_SHA256:
@@ -230,7 +254,9 @@ class AwsKmsKeyProvider(KeyProviderBase):
230
254
  ],
231
255
  }
232
256
  if spec.label:
233
- kwargs["Tags"].append({"TagKey": "saur:label", "TagValue": spec.label})
257
+ kwargs["Tags"].append(
258
+ {"TagKey": "saur:label", "TagValue": spec.label}
259
+ )
234
260
  if self._key_policy:
235
261
  kwargs["Policy"] = self._key_policy
236
262
 
@@ -247,7 +273,10 @@ class AwsKmsKeyProvider(KeyProviderBase):
247
273
  self, spec: KeySpec, material: bytes, *, public: Optional[bytes] = None
248
274
  ) -> KeyRef:
249
275
  raise NotImplementedError(
250
- "AWS KMS does not support importing private keys via this provider; use create_key()."
276
+ (
277
+ "AWS KMS does not support importing private keys via this "
278
+ "provider; use create_key()."
279
+ )
251
280
  )
252
281
 
253
282
  async def rotate_key(
@@ -267,11 +296,15 @@ class AwsKmsKeyProvider(KeyProviderBase):
267
296
 
268
297
  alg = KeyAlg(current_alg)
269
298
  size_bits = (spec_overrides or {}).get("size_bits")
270
- label = (spec_overrides or {}).get("label", current_tags.get("saur:label"))
299
+ label = (spec_overrides or {}).get(
300
+ "label", current_tags.get("saur:label")
301
+ )
271
302
  uses = ()
272
303
  new_spec = KeySpec(
273
304
  klass=(
274
- KeyClass.symmetric if alg == KeyAlg.AES256_GCM else KeyClass.asymmetric
305
+ KeyClass.symmetric
306
+ if alg == KeyAlg.AES256_GCM
307
+ else KeyClass.asymmetric
275
308
  ),
276
309
  alg=alg,
277
310
  size_bits=size_bits,
@@ -306,7 +339,9 @@ class AwsKmsKeyProvider(KeyProviderBase):
306
339
  resp = self._kms.create_key(**kwargs)
307
340
  new_key_id = resp["KeyMetadata"]["KeyId"]
308
341
 
309
- self._create_or_update_alias(self._alias_version(kid, next_version), new_key_id)
342
+ self._create_or_update_alias(
343
+ self._alias_version(kid, next_version), new_key_id
344
+ )
310
345
  self._create_or_update_alias(self._alias_latest(kid), new_key_id)
311
346
 
312
347
  return self._keyref_from_key_id(
@@ -316,7 +351,9 @@ class AwsKmsKeyProvider(KeyProviderBase):
316
351
  tags={t["TagKey"]: t["TagValue"] for t in kwargs["Tags"]},
317
352
  )
318
353
 
319
- async def destroy_key(self, kid: str, version: Optional[int] = None) -> bool:
354
+ async def destroy_key(
355
+ self, kid: str, version: Optional[int] = None
356
+ ) -> bool:
320
357
  try:
321
358
  if version is None:
322
359
  for ver in await self.list_versions(kid):
@@ -337,10 +374,16 @@ class AwsKmsKeyProvider(KeyProviderBase):
337
374
  return False
338
375
 
339
376
  async def get_key(
340
- self, kid: str, version: Optional[int] = None, *, include_secret: bool = False
377
+ self,
378
+ kid: str,
379
+ version: Optional[int] = None,
380
+ *,
381
+ include_secret: bool = False,
341
382
  ) -> KeyRef:
342
383
  alias_name = (
343
- self._alias_version(kid, version) if version else self._alias_latest(kid)
384
+ self._alias_version(kid, version)
385
+ if version
386
+ else self._alias_latest(kid)
344
387
  )
345
388
  alias_desc = self._find_alias(alias_name)
346
389
  key_id = alias_desc["TargetKeyId"]
@@ -370,9 +413,13 @@ class AwsKmsKeyProvider(KeyProviderBase):
370
413
  out.sort()
371
414
  return tuple(out)
372
415
 
373
- async def get_public_jwk(self, kid: str, version: Optional[int] = None) -> dict:
416
+ async def get_public_jwk(
417
+ self, kid: str, version: Optional[int] = None
418
+ ) -> dict:
374
419
  alias_name = (
375
- self._alias_version(kid, version) if version else self._alias_latest(kid)
420
+ self._alias_version(kid, version)
421
+ if version
422
+ else self._alias_latest(kid)
376
423
  )
377
424
  alias_desc = self._find_alias(alias_name)
378
425
  key_id = alias_desc["TargetKeyId"]
@@ -388,7 +435,10 @@ class AwsKmsKeyProvider(KeyProviderBase):
388
435
  return self._public_jwk_from_der(pk, jwk_kid)
389
436
  except ClientError as e:
390
437
  code = e.response.get("Error", {}).get("Code")
391
- if code in ("UnsupportedOperationException", "IncorrectKeySpecException"):
438
+ if code in (
439
+ "UnsupportedOperationException",
440
+ "IncorrectKeySpecException",
441
+ ):
392
442
  return {"kty": "oct", "alg": "A256GCM", "kid": jwk_kid}
393
443
  raise
394
444
 
@@ -424,7 +474,9 @@ class AwsKmsKeyProvider(KeyProviderBase):
424
474
  async def random_bytes(self, n: int) -> bytes:
425
475
  return os.urandom(n)
426
476
 
427
- async def hkdf(self, ikm: bytes, *, salt: bytes, info: bytes, length: int) -> bytes:
477
+ async def hkdf(
478
+ self, ikm: bytes, *, salt: bytes, info: bytes, length: int
479
+ ) -> bytes:
428
480
  from cryptography.hazmat.primitives.kdf.hkdf import HKDF
429
481
  from cryptography.hazmat.primitives import hashes
430
482
 
@@ -1,153 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: swarmauri_keyprovider_aws_kms
3
- Version: 0.3.4.dev2
4
- Summary: AWS KMS KeyProvider for Swarmauri
5
- License-Expression: Apache-2.0
6
- License-File: LICENSE
7
- Keywords: swarmauri,keyprovider,aws,kms
8
- Author: Jacob Stewart
9
- Author-email: jacob@swarmauri.com
10
- Requires-Python: >=3.10,<3.15
11
- Classifier: License :: OSI Approved :: Apache Software License
12
- Classifier: Natural Language :: English
13
- Classifier: Development Status :: 3 - Alpha
14
- Classifier: Intended Audience :: Developers
15
- Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
16
- Classifier: Programming Language :: Python
17
- Classifier: Programming Language :: Python :: 3
18
- Classifier: Programming Language :: Python :: 3 :: Only
19
- Classifier: Programming Language :: Python :: 3.10
20
- Classifier: Programming Language :: Python :: 3.11
21
- Classifier: Programming Language :: Python :: 3.12
22
- Classifier: Programming Language :: Python :: 3.13
23
- Classifier: Programming Language :: Python :: 3.14
24
- Provides-Extra: perf
25
- Requires-Dist: boto3 (>=1.28.0)
26
- Requires-Dist: cryptography
27
- Requires-Dist: pytest-benchmark (>=4.0.0) ; extra == "perf"
28
- Requires-Dist: swarmauri_base
29
- Requires-Dist: swarmauri_core
30
- Requires-Dist: swarmauri_standard
31
- Description-Content-Type: text/markdown
32
-
33
- ![Swarmauri Logo](https://raw.githubusercontent.com/swarmauri/swarmauri-sdk/master/assets/swarmauri_sdk_brand.png)
34
-
35
- <p align="center">
36
- <a href="https://pepy.tech/project/swarmauri_keyprovider_aws_kms/">
37
- <img src="https://static.pepy.tech/badge/swarmauri_keyprovider_aws_kms/month" alt="PyPI - Downloads"/></a>
38
- <a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/community/swarmauri_keyprovider_aws_kms/">
39
- <img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/community/swarmauri_keyprovider_aws_kms.svg"/></a>
40
- <a href="https://pypi.org/project/swarmauri_keyprovider_aws_kms/">
41
- <img src="https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12%20%7C%203.13%20%7C%203.14-blue" alt="PyPI - Python Version"/></a>
42
- <a href="https://pypi.org/project/swarmauri_keyprovider_aws_kms/">
43
- <img src="https://img.shields.io/pypi/l/swarmauri_keyprovider_aws_kms" alt="PyPI - License"/></a>
44
- <a href="https://pypi.org/project/swarmauri_keyprovider_aws_kms/">
45
- <img src="https://img.shields.io/pypi/v/swarmauri_keyprovider_aws_kms?label=swarmauri_keyprovider_aws_kms&color=green" alt="PyPI - swarmauri_keyprovider_aws_kms"/></a>
46
- </p>
47
- ---
48
-
49
- # Swarmauri AWS KMS Key Provider
50
-
51
- Community plugin providing an AWS Key Management Service (KMS) backed `KeyProvider` for Swarmauri. It manages non-exportable customer managed keys (CMKs), exposes JWKS for downstream services, and handles key rotation workflows aligned with AWS best practices.
52
-
53
- ## Features
54
-
55
- - Create RSA, ECC, and AES-256 keys in AWS KMS with deterministic aliasing per `kid` and version.
56
- - Rotate keys by minting new KMS key versions and updating aliases, while preserving previous versions for auditing or staged cutovers.
57
- - Describe keys through `KeyRef` objects, including public PEM material when the key spec allows export, and RFC 7517-compliant JWKs via `get_public_jwk`/`jwks`.
58
- - Generate cryptographically secure random bytes and perform HKDF expansion with SHA-256 to support envelope encryption and symmetric derivation flows.
59
- - Destroy keys by scheduling deletion through the KMS API, maintaining Swarmauri tagging metadata for traceability.
60
-
61
- ## Prerequisites
62
-
63
- - Python 3.10 or newer.
64
- - `boto3` (installed automatically with this package) and network access to the target AWS region.
65
- - AWS credentials with permissions such as `kms:CreateKey`, `kms:CreateAlias`, `kms:UpdateAlias`, `kms:DescribeKey`, `kms:GetPublicKey`, `kms:ListAliases`, `kms:ListResourceTags`, and `kms:ScheduleKeyDeletion`.
66
- - Optional: a custom key policy if you need to delegate key administration to non-root principals; pass it through the `key_policy` constructor argument.
67
-
68
- ## Installation
69
-
70
- ```bash
71
- # pip
72
- pip install swarmauri_keyprovider_aws_kms
73
-
74
- # poetry
75
- poetry add swarmauri_keyprovider_aws_kms
76
-
77
- # uv (pyproject-based projects)
78
- uv add swarmauri_keyprovider_aws_kms
79
- ```
80
-
81
- ## Quickstart: Create, Rotate, and Publish Keys
82
-
83
- ```python
84
- import asyncio
85
- from swarmauri_keyprovider_aws_kms import AwsKmsKeyProvider
86
- from swarmauri_core.key_providers.types import KeyAlg, KeyClass, KeySpec, ExportPolicy
87
-
88
-
89
- async def main() -> None:
90
- provider = AwsKmsKeyProvider(region="us-east-1", alias_prefix="swarmauri-demo")
91
-
92
- rsa_spec = KeySpec(
93
- klass=KeyClass.asymmetric,
94
- alg=KeyAlg.RSA_PSS_SHA256,
95
- size_bits=3072,
96
- export_policy=ExportPolicy.never_export_secret,
97
- label="api-signing",
98
- )
99
-
100
- # Create the initial version (aliases: alias/swarmauri-demo/<kid> and .../v1)
101
- key_ref = await provider.create_key(rsa_spec)
102
- print("KID", key_ref.kid, "version", key_ref.version)
103
-
104
- # Surface the public JWK for JWT signing or JWKS endpoints
105
- jwk = await provider.get_public_jwk(key_ref.kid)
106
- print("Public JWK", jwk)
107
-
108
- # Rotate the key – new CMK in KMS, version alias bump, old alias retained
109
- rotated = await provider.rotate_key(key_ref.kid)
110
- print("Rotated to version", rotated.version)
111
-
112
- # Publish the aggregate JWKS (includes the latest version per kid)
113
- jwks_payload = await provider.jwks()
114
- print("JWKS keys", [k["kid"] for k in jwks_payload["keys"]])
115
-
116
-
117
- if __name__ == "__main__":
118
- asyncio.run(main())
119
- ```
120
-
121
- ## Symmetric Utilities: Random Bytes and HKDF
122
-
123
- ```python
124
- import asyncio
125
- from swarmauri_keyprovider_aws_kms import AwsKmsKeyProvider
126
-
127
-
128
- async def derive_data_key() -> bytes:
129
- provider = AwsKmsKeyProvider(region="us-east-1")
130
-
131
- master_salt = await provider.random_bytes(32)
132
- info = b"swarmauri/example"
133
-
134
- pseudo_random_key = await provider.random_bytes(32)
135
- derived = await provider.hkdf(
136
- pseudo_random_key,
137
- salt=master_salt,
138
- info=info,
139
- length=32,
140
- )
141
- return derived
142
-
143
-
144
- # asyncio.run(derive_data_key())
145
- ```
146
-
147
- ## Operational Tips
148
-
149
- - `list_versions(kid)` inspects versioned aliases (`alias/<prefix>/<kid>/vN`); use it before destructive actions to ensure you capture all active CMKs.
150
- - Destroying a key schedules deletion for 7 days. Plan rotations ahead of time so dependent systems can migrate to the new version before you call `destroy_key`.
151
- - Tag metadata persisted by the provider (`saur:kid`, `saur:version`, `saur:alg`, optional `saur:label`) enables inventory checks—query them from the AWS console or CLI when auditing.
152
- - For high-throughput signing, ensure your IAM policies, KMS quotas, and region placement match latency expectations; consider caching public JWKs from `jwks()` in your verifier services.
153
-
@@ -1,120 +0,0 @@
1
- ![Swarmauri Logo](https://raw.githubusercontent.com/swarmauri/swarmauri-sdk/master/assets/swarmauri_sdk_brand.png)
2
-
3
- <p align="center">
4
- <a href="https://pepy.tech/project/swarmauri_keyprovider_aws_kms/">
5
- <img src="https://static.pepy.tech/badge/swarmauri_keyprovider_aws_kms/month" alt="PyPI - Downloads"/></a>
6
- <a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/community/swarmauri_keyprovider_aws_kms/">
7
- <img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/community/swarmauri_keyprovider_aws_kms.svg"/></a>
8
- <a href="https://pypi.org/project/swarmauri_keyprovider_aws_kms/">
9
- <img src="https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12%20%7C%203.13%20%7C%203.14-blue" alt="PyPI - Python Version"/></a>
10
- <a href="https://pypi.org/project/swarmauri_keyprovider_aws_kms/">
11
- <img src="https://img.shields.io/pypi/l/swarmauri_keyprovider_aws_kms" alt="PyPI - License"/></a>
12
- <a href="https://pypi.org/project/swarmauri_keyprovider_aws_kms/">
13
- <img src="https://img.shields.io/pypi/v/swarmauri_keyprovider_aws_kms?label=swarmauri_keyprovider_aws_kms&color=green" alt="PyPI - swarmauri_keyprovider_aws_kms"/></a>
14
- </p>
15
- ---
16
-
17
- # Swarmauri AWS KMS Key Provider
18
-
19
- Community plugin providing an AWS Key Management Service (KMS) backed `KeyProvider` for Swarmauri. It manages non-exportable customer managed keys (CMKs), exposes JWKS for downstream services, and handles key rotation workflows aligned with AWS best practices.
20
-
21
- ## Features
22
-
23
- - Create RSA, ECC, and AES-256 keys in AWS KMS with deterministic aliasing per `kid` and version.
24
- - Rotate keys by minting new KMS key versions and updating aliases, while preserving previous versions for auditing or staged cutovers.
25
- - Describe keys through `KeyRef` objects, including public PEM material when the key spec allows export, and RFC 7517-compliant JWKs via `get_public_jwk`/`jwks`.
26
- - Generate cryptographically secure random bytes and perform HKDF expansion with SHA-256 to support envelope encryption and symmetric derivation flows.
27
- - Destroy keys by scheduling deletion through the KMS API, maintaining Swarmauri tagging metadata for traceability.
28
-
29
- ## Prerequisites
30
-
31
- - Python 3.10 or newer.
32
- - `boto3` (installed automatically with this package) and network access to the target AWS region.
33
- - AWS credentials with permissions such as `kms:CreateKey`, `kms:CreateAlias`, `kms:UpdateAlias`, `kms:DescribeKey`, `kms:GetPublicKey`, `kms:ListAliases`, `kms:ListResourceTags`, and `kms:ScheduleKeyDeletion`.
34
- - Optional: a custom key policy if you need to delegate key administration to non-root principals; pass it through the `key_policy` constructor argument.
35
-
36
- ## Installation
37
-
38
- ```bash
39
- # pip
40
- pip install swarmauri_keyprovider_aws_kms
41
-
42
- # poetry
43
- poetry add swarmauri_keyprovider_aws_kms
44
-
45
- # uv (pyproject-based projects)
46
- uv add swarmauri_keyprovider_aws_kms
47
- ```
48
-
49
- ## Quickstart: Create, Rotate, and Publish Keys
50
-
51
- ```python
52
- import asyncio
53
- from swarmauri_keyprovider_aws_kms import AwsKmsKeyProvider
54
- from swarmauri_core.key_providers.types import KeyAlg, KeyClass, KeySpec, ExportPolicy
55
-
56
-
57
- async def main() -> None:
58
- provider = AwsKmsKeyProvider(region="us-east-1", alias_prefix="swarmauri-demo")
59
-
60
- rsa_spec = KeySpec(
61
- klass=KeyClass.asymmetric,
62
- alg=KeyAlg.RSA_PSS_SHA256,
63
- size_bits=3072,
64
- export_policy=ExportPolicy.never_export_secret,
65
- label="api-signing",
66
- )
67
-
68
- # Create the initial version (aliases: alias/swarmauri-demo/<kid> and .../v1)
69
- key_ref = await provider.create_key(rsa_spec)
70
- print("KID", key_ref.kid, "version", key_ref.version)
71
-
72
- # Surface the public JWK for JWT signing or JWKS endpoints
73
- jwk = await provider.get_public_jwk(key_ref.kid)
74
- print("Public JWK", jwk)
75
-
76
- # Rotate the key – new CMK in KMS, version alias bump, old alias retained
77
- rotated = await provider.rotate_key(key_ref.kid)
78
- print("Rotated to version", rotated.version)
79
-
80
- # Publish the aggregate JWKS (includes the latest version per kid)
81
- jwks_payload = await provider.jwks()
82
- print("JWKS keys", [k["kid"] for k in jwks_payload["keys"]])
83
-
84
-
85
- if __name__ == "__main__":
86
- asyncio.run(main())
87
- ```
88
-
89
- ## Symmetric Utilities: Random Bytes and HKDF
90
-
91
- ```python
92
- import asyncio
93
- from swarmauri_keyprovider_aws_kms import AwsKmsKeyProvider
94
-
95
-
96
- async def derive_data_key() -> bytes:
97
- provider = AwsKmsKeyProvider(region="us-east-1")
98
-
99
- master_salt = await provider.random_bytes(32)
100
- info = b"swarmauri/example"
101
-
102
- pseudo_random_key = await provider.random_bytes(32)
103
- derived = await provider.hkdf(
104
- pseudo_random_key,
105
- salt=master_salt,
106
- info=info,
107
- length=32,
108
- )
109
- return derived
110
-
111
-
112
- # asyncio.run(derive_data_key())
113
- ```
114
-
115
- ## Operational Tips
116
-
117
- - `list_versions(kid)` inspects versioned aliases (`alias/<prefix>/<kid>/vN`); use it before destructive actions to ensure you capture all active CMKs.
118
- - Destroying a key schedules deletion for 7 days. Plan rotations ahead of time so dependent systems can migrate to the new version before you call `destroy_key`.
119
- - Tag metadata persisted by the provider (`saur:kid`, `saur:version`, `saur:alg`, optional `saur:label`) enables inventory checks—query them from the AWS console or CLI when auditing.
120
- - For high-throughput signing, ensure your IAM policies, KMS quotas, and region placement match latency expectations; consider caching public JWKs from `jwks()` in your verifier services.