Skip to main content

Swarmauri Vault Transit Key Provider

Project description

Swarmauri Logo

PyPI - Downloads Hits PyPI - Python Version PyPI - License PyPI - swarmauri_keyprovider_vaulttransit


Swarmauri Vault Transit Key Provider

HashiCorp Vault Transit engine integration for the Swarmauri key provider interface. Manage hardware-protected keys through Vault, expose public JWK(S) material, rotate versions, and consume Vault RNG and HKDF services without leaving Swarmauri.

Features

  • Create and rotate symmetric (aes256-gcm96) and asymmetric (rsa-3072, ecdsa-p256, ed25519) keys via Vault Transit.
  • Export public keys in JWK/JWKS form using the built-in get_public_jwk/jwks helpers.
  • Perform signing, verification, encryption, decryption, wrapping, and unwrapping through Vault's REST API.
  • Generate cryptographically secure random bytes either from Vault's RNG or local entropy (configurable with prefer_vault_rng).
  • Run HKDF derivations with SHA-256 to support envelope encryption or key diversification workflows.

Prerequisites

  • Python 3.10 or newer.
  • Running HashiCorp Vault instance with the Transit secrets engine enabled and a mount path you can access (default transit).
  • Vault token with capabilities such as transit/keys/* for read, create, update, delete, and transit/random/* if you plan to use Vault RNG.
  • The hvac client library (installed automatically with this package) unless you inject a custom Vault client.

Installation

# pip
pip install swarmauri_keyprovider_vaulttransit

# poetry
poetry add swarmauri_keyprovider_vaulttransit

# uv (pyproject-based projects)
uv add swarmauri_keyprovider_vaulttransit

Quickstart: Create and Rotate a Signing Key

import asyncio
from swarmauri_core.key_providers.types import KeyAlg, KeySpec, ExportPolicy
from swarmauri_keyprovider_vaulttransit import VaultTransitKeyProvider


async def main() -> None:
    provider = VaultTransitKeyProvider(
        url="http://localhost:8200",
        token="swarmauri-dev-token",
        mount="transit",
        verify=False,
    )

    spec = KeySpec(
        alg=KeyAlg.ED25519,
        export_policy=ExportPolicy.never_export_secret,
        label="agents-signing",
    )

    key_ref = await provider.create_key(spec)
    print("Created key", key_ref.kid, "version", key_ref.version)

    jwk = await provider.get_public_jwk(key_ref.kid, key_ref.version)
    print("Public JWK", jwk)

    rotated = await provider.rotate_key(key_ref.kid)
    print("Rotated to version", rotated.version)

    jwks_payload = await provider.jwks()
    print("JWKS contains", [entry["kid"] for entry in jwks_payload["keys"]])


if __name__ == "__main__":
    asyncio.run(main())

Encrypt, Wrap, and Derive Keys

import asyncio
from swarmauri_keyprovider_vaulttransit import VaultTransitKeyProvider


async def encrypt_and_wrap() -> None:
    provider = VaultTransitKeyProvider(
        url="http://localhost:8200",
        token="swarmauri-dev-token",
        prefer_vault_rng=True,
    )

    plaintext = b"vault keeps my secrets"
    aad = b"tenant::demo"

    ciphertext = await provider.encrypt("aes-encryption", plaintext, associated_data=aad)
    decrypted = await provider.decrypt("aes-encryption", ciphertext, associated_data=aad)
    assert decrypted == plaintext

    dek = await provider.random_bytes(32)
    wrapped = await provider.wrap("rsa-wrap-key", dek)
    unwrapped = await provider.unwrap("rsa-wrap-key", wrapped)
    assert unwrapped == dek

    derived = await provider.hkdf(
        ikm=dek,
        salt=b"vault-salt",
        info=b"swarmauri/derivation",
        length=32,
    )
    print("Derived key length", len(derived))


# asyncio.run(encrypt_and_wrap())

Configuration Reference

  • url – Vault server address (e.g., https://vault.example.com:8200).
  • token – Vault token or wrapped token with permissions for the Transit mount.
  • mount – Transit engine mount path; defaults to transit.
  • namespace – Optional Vault Enterprise namespace header.
  • verify – TLS verification flag or CA bundle path.
  • prefer_vault_rng – When True, random_bytes uses Vault's RNG; otherwise falls back to os.urandom.
  • client – Provide a pre-configured hvac.Client if you manage authentication externally.

Want to help?

If you want to contribute to swarmauri-sdk, read up on our guidelines for contributing.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file swarmauri_keyprovider_vaulttransit-0.9.3.dev22.tar.gz.

File metadata

  • Download URL: swarmauri_keyprovider_vaulttransit-0.9.3.dev22.tar.gz
  • Upload date:
  • Size: 11.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for swarmauri_keyprovider_vaulttransit-0.9.3.dev22.tar.gz
Algorithm Hash digest
SHA256 2fce9201c289bcffe089cdd73637118f65bfaf504c88d007a90a5a30d0c0f15f
MD5 3b973c8b0cc69d73e88172359493bdb0
BLAKE2b-256 a10dea84c2f8283aced1a0044dc654b23f2da6234d3434efc6e722f51500b436

See more details on using hashes here.

File details

Details for the file swarmauri_keyprovider_vaulttransit-0.9.3.dev22-py3-none-any.whl.

File metadata

  • Download URL: swarmauri_keyprovider_vaulttransit-0.9.3.dev22-py3-none-any.whl
  • Upload date:
  • Size: 12.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for swarmauri_keyprovider_vaulttransit-0.9.3.dev22-py3-none-any.whl
Algorithm Hash digest
SHA256 2e0b7908b8375cfd0e7890560378bd0e16d4d158f25f8854fc98b604477caf1c
MD5 b35db3d426d1499bb4d0a75689a6532f
BLAKE2b-256 58fb248f57a77c0d87bf829f79b0518ef3eec0e684ec50e5b165bb8d77bf5b63

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page