swarmauri_keyprovider_aws_kms 0.3.4.dev3__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.
- swarmauri_keyprovider_aws_kms-0.11.0.dev1/PKG-INFO +230 -0
- swarmauri_keyprovider_aws_kms-0.11.0.dev1/README.md +192 -0
- {swarmauri_keyprovider_aws_kms-0.3.4.dev3 → swarmauri_keyprovider_aws_kms-0.11.0.dev1}/pyproject.toml +20 -3
- {swarmauri_keyprovider_aws_kms-0.3.4.dev3 → swarmauri_keyprovider_aws_kms-0.11.0.dev1}/swarmauri_keyprovider_aws_kms/AwsKmsKeyProvider.py +79 -27
- swarmauri_keyprovider_aws_kms-0.3.4.dev3/PKG-INFO +0 -152
- swarmauri_keyprovider_aws_kms-0.3.4.dev3/README.md +0 -119
- {swarmauri_keyprovider_aws_kms-0.3.4.dev3 → swarmauri_keyprovider_aws_kms-0.11.0.dev1}/LICENSE +0 -0
- {swarmauri_keyprovider_aws_kms-0.3.4.dev3 → swarmauri_keyprovider_aws_kms-0.11.0.dev1}/swarmauri_keyprovider_aws_kms/__init__.py +0 -0
|
@@ -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
|
+

|
|
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
|
+

|
|
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.
|
|
4
|
-
description = "AWS KMS
|
|
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
|
-
"
|
|
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
|
|
49
|
-
|
|
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
|
|
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,
|
|
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
|
|
70
|
-
|
|
71
|
-
|
|
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(
|
|
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(
|
|
112
|
+
self._kms.create_alias(
|
|
113
|
+
AliasName=alias_name, TargetKeyId=target_key_id
|
|
114
|
+
)
|
|
104
115
|
except ClientError as e:
|
|
105
|
-
if
|
|
106
|
-
|
|
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(
|
|
114
|
-
|
|
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(
|
|
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(
|
|
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(
|
|
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
|
-
|
|
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(
|
|
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
|
|
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(
|
|
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(
|
|
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,
|
|
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)
|
|
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(
|
|
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)
|
|
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 (
|
|
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(
|
|
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,152 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: swarmauri_keyprovider_aws_kms
|
|
3
|
-
Version: 0.3.4.dev3
|
|
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
|
-

|
|
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
|
-
# Swarmauri AWS KMS Key Provider
|
|
49
|
-
|
|
50
|
-
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.
|
|
51
|
-
|
|
52
|
-
## Features
|
|
53
|
-
|
|
54
|
-
- Create RSA, ECC, and AES-256 keys in AWS KMS with deterministic aliasing per `kid` and version.
|
|
55
|
-
- Rotate keys by minting new KMS key versions and updating aliases, while preserving previous versions for auditing or staged cutovers.
|
|
56
|
-
- 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`.
|
|
57
|
-
- Generate cryptographically secure random bytes and perform HKDF expansion with SHA-256 to support envelope encryption and symmetric derivation flows.
|
|
58
|
-
- Destroy keys by scheduling deletion through the KMS API, maintaining Swarmauri tagging metadata for traceability.
|
|
59
|
-
|
|
60
|
-
## Prerequisites
|
|
61
|
-
|
|
62
|
-
- Python 3.10 or newer.
|
|
63
|
-
- `boto3` (installed automatically with this package) and network access to the target AWS region.
|
|
64
|
-
- AWS credentials with permissions such as `kms:CreateKey`, `kms:CreateAlias`, `kms:UpdateAlias`, `kms:DescribeKey`, `kms:GetPublicKey`, `kms:ListAliases`, `kms:ListResourceTags`, and `kms:ScheduleKeyDeletion`.
|
|
65
|
-
- Optional: a custom key policy if you need to delegate key administration to non-root principals; pass it through the `key_policy` constructor argument.
|
|
66
|
-
|
|
67
|
-
## Installation
|
|
68
|
-
|
|
69
|
-
```bash
|
|
70
|
-
# pip
|
|
71
|
-
pip install swarmauri_keyprovider_aws_kms
|
|
72
|
-
|
|
73
|
-
# poetry
|
|
74
|
-
poetry add swarmauri_keyprovider_aws_kms
|
|
75
|
-
|
|
76
|
-
# uv (pyproject-based projects)
|
|
77
|
-
uv add swarmauri_keyprovider_aws_kms
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
## Quickstart: Create, Rotate, and Publish Keys
|
|
81
|
-
|
|
82
|
-
```python
|
|
83
|
-
import asyncio
|
|
84
|
-
from swarmauri_keyprovider_aws_kms import AwsKmsKeyProvider
|
|
85
|
-
from swarmauri_core.key_providers.types import KeyAlg, KeyClass, KeySpec, ExportPolicy
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
async def main() -> None:
|
|
89
|
-
provider = AwsKmsKeyProvider(region="us-east-1", alias_prefix="swarmauri-demo")
|
|
90
|
-
|
|
91
|
-
rsa_spec = KeySpec(
|
|
92
|
-
klass=KeyClass.asymmetric,
|
|
93
|
-
alg=KeyAlg.RSA_PSS_SHA256,
|
|
94
|
-
size_bits=3072,
|
|
95
|
-
export_policy=ExportPolicy.never_export_secret,
|
|
96
|
-
label="api-signing",
|
|
97
|
-
)
|
|
98
|
-
|
|
99
|
-
# Create the initial version (aliases: alias/swarmauri-demo/<kid> and .../v1)
|
|
100
|
-
key_ref = await provider.create_key(rsa_spec)
|
|
101
|
-
print("KID", key_ref.kid, "version", key_ref.version)
|
|
102
|
-
|
|
103
|
-
# Surface the public JWK for JWT signing or JWKS endpoints
|
|
104
|
-
jwk = await provider.get_public_jwk(key_ref.kid)
|
|
105
|
-
print("Public JWK", jwk)
|
|
106
|
-
|
|
107
|
-
# Rotate the key – new CMK in KMS, version alias bump, old alias retained
|
|
108
|
-
rotated = await provider.rotate_key(key_ref.kid)
|
|
109
|
-
print("Rotated to version", rotated.version)
|
|
110
|
-
|
|
111
|
-
# Publish the aggregate JWKS (includes the latest version per kid)
|
|
112
|
-
jwks_payload = await provider.jwks()
|
|
113
|
-
print("JWKS keys", [k["kid"] for k in jwks_payload["keys"]])
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
if __name__ == "__main__":
|
|
117
|
-
asyncio.run(main())
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
## Symmetric Utilities: Random Bytes and HKDF
|
|
121
|
-
|
|
122
|
-
```python
|
|
123
|
-
import asyncio
|
|
124
|
-
from swarmauri_keyprovider_aws_kms import AwsKmsKeyProvider
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
async def derive_data_key() -> bytes:
|
|
128
|
-
provider = AwsKmsKeyProvider(region="us-east-1")
|
|
129
|
-
|
|
130
|
-
master_salt = await provider.random_bytes(32)
|
|
131
|
-
info = b"swarmauri/example"
|
|
132
|
-
|
|
133
|
-
pseudo_random_key = await provider.random_bytes(32)
|
|
134
|
-
derived = await provider.hkdf(
|
|
135
|
-
pseudo_random_key,
|
|
136
|
-
salt=master_salt,
|
|
137
|
-
info=info,
|
|
138
|
-
length=32,
|
|
139
|
-
)
|
|
140
|
-
return derived
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
# asyncio.run(derive_data_key())
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
## Operational Tips
|
|
147
|
-
|
|
148
|
-
- `list_versions(kid)` inspects versioned aliases (`alias/<prefix>/<kid>/vN`); use it before destructive actions to ensure you capture all active CMKs.
|
|
149
|
-
- 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`.
|
|
150
|
-
- 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.
|
|
151
|
-
- 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.
|
|
152
|
-
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-

|
|
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
|
-
# Swarmauri AWS KMS Key Provider
|
|
17
|
-
|
|
18
|
-
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.
|
|
19
|
-
|
|
20
|
-
## Features
|
|
21
|
-
|
|
22
|
-
- Create RSA, ECC, and AES-256 keys in AWS KMS with deterministic aliasing per `kid` and version.
|
|
23
|
-
- Rotate keys by minting new KMS key versions and updating aliases, while preserving previous versions for auditing or staged cutovers.
|
|
24
|
-
- 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`.
|
|
25
|
-
- Generate cryptographically secure random bytes and perform HKDF expansion with SHA-256 to support envelope encryption and symmetric derivation flows.
|
|
26
|
-
- Destroy keys by scheduling deletion through the KMS API, maintaining Swarmauri tagging metadata for traceability.
|
|
27
|
-
|
|
28
|
-
## Prerequisites
|
|
29
|
-
|
|
30
|
-
- Python 3.10 or newer.
|
|
31
|
-
- `boto3` (installed automatically with this package) and network access to the target AWS region.
|
|
32
|
-
- AWS credentials with permissions such as `kms:CreateKey`, `kms:CreateAlias`, `kms:UpdateAlias`, `kms:DescribeKey`, `kms:GetPublicKey`, `kms:ListAliases`, `kms:ListResourceTags`, and `kms:ScheduleKeyDeletion`.
|
|
33
|
-
- Optional: a custom key policy if you need to delegate key administration to non-root principals; pass it through the `key_policy` constructor argument.
|
|
34
|
-
|
|
35
|
-
## Installation
|
|
36
|
-
|
|
37
|
-
```bash
|
|
38
|
-
# pip
|
|
39
|
-
pip install swarmauri_keyprovider_aws_kms
|
|
40
|
-
|
|
41
|
-
# poetry
|
|
42
|
-
poetry add swarmauri_keyprovider_aws_kms
|
|
43
|
-
|
|
44
|
-
# uv (pyproject-based projects)
|
|
45
|
-
uv add swarmauri_keyprovider_aws_kms
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
## Quickstart: Create, Rotate, and Publish Keys
|
|
49
|
-
|
|
50
|
-
```python
|
|
51
|
-
import asyncio
|
|
52
|
-
from swarmauri_keyprovider_aws_kms import AwsKmsKeyProvider
|
|
53
|
-
from swarmauri_core.key_providers.types import KeyAlg, KeyClass, KeySpec, ExportPolicy
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
async def main() -> None:
|
|
57
|
-
provider = AwsKmsKeyProvider(region="us-east-1", alias_prefix="swarmauri-demo")
|
|
58
|
-
|
|
59
|
-
rsa_spec = KeySpec(
|
|
60
|
-
klass=KeyClass.asymmetric,
|
|
61
|
-
alg=KeyAlg.RSA_PSS_SHA256,
|
|
62
|
-
size_bits=3072,
|
|
63
|
-
export_policy=ExportPolicy.never_export_secret,
|
|
64
|
-
label="api-signing",
|
|
65
|
-
)
|
|
66
|
-
|
|
67
|
-
# Create the initial version (aliases: alias/swarmauri-demo/<kid> and .../v1)
|
|
68
|
-
key_ref = await provider.create_key(rsa_spec)
|
|
69
|
-
print("KID", key_ref.kid, "version", key_ref.version)
|
|
70
|
-
|
|
71
|
-
# Surface the public JWK for JWT signing or JWKS endpoints
|
|
72
|
-
jwk = await provider.get_public_jwk(key_ref.kid)
|
|
73
|
-
print("Public JWK", jwk)
|
|
74
|
-
|
|
75
|
-
# Rotate the key – new CMK in KMS, version alias bump, old alias retained
|
|
76
|
-
rotated = await provider.rotate_key(key_ref.kid)
|
|
77
|
-
print("Rotated to version", rotated.version)
|
|
78
|
-
|
|
79
|
-
# Publish the aggregate JWKS (includes the latest version per kid)
|
|
80
|
-
jwks_payload = await provider.jwks()
|
|
81
|
-
print("JWKS keys", [k["kid"] for k in jwks_payload["keys"]])
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
if __name__ == "__main__":
|
|
85
|
-
asyncio.run(main())
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
## Symmetric Utilities: Random Bytes and HKDF
|
|
89
|
-
|
|
90
|
-
```python
|
|
91
|
-
import asyncio
|
|
92
|
-
from swarmauri_keyprovider_aws_kms import AwsKmsKeyProvider
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
async def derive_data_key() -> bytes:
|
|
96
|
-
provider = AwsKmsKeyProvider(region="us-east-1")
|
|
97
|
-
|
|
98
|
-
master_salt = await provider.random_bytes(32)
|
|
99
|
-
info = b"swarmauri/example"
|
|
100
|
-
|
|
101
|
-
pseudo_random_key = await provider.random_bytes(32)
|
|
102
|
-
derived = await provider.hkdf(
|
|
103
|
-
pseudo_random_key,
|
|
104
|
-
salt=master_salt,
|
|
105
|
-
info=info,
|
|
106
|
-
length=32,
|
|
107
|
-
)
|
|
108
|
-
return derived
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
# asyncio.run(derive_data_key())
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
## Operational Tips
|
|
115
|
-
|
|
116
|
-
- `list_versions(kid)` inspects versioned aliases (`alias/<prefix>/<kid>/vN`); use it before destructive actions to ensure you capture all active CMKs.
|
|
117
|
-
- 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`.
|
|
118
|
-
- 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.
|
|
119
|
-
- 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.
|
{swarmauri_keyprovider_aws_kms-0.3.4.dev3 → swarmauri_keyprovider_aws_kms-0.11.0.dev1}/LICENSE
RENAMED
|
File without changes
|