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.dev20.tar.gz.

File metadata

  • Download URL: swarmauri_keyprovider_vaulttransit-0.9.3.dev20.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.dev20.tar.gz
Algorithm Hash digest
SHA256 6ac59324e3743ae116cb8eee5b859119d7dbfe0df3bb5c7f1585c127fefe6ff9
MD5 9056a9f3e56c50070f3fcc2fe24d812d
BLAKE2b-256 5c738d70e3968e55f888e7a4e7ea11a44e7ba4aa1a2b80dd14ffbd6a4601693f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: swarmauri_keyprovider_vaulttransit-0.9.3.dev20-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.dev20-py3-none-any.whl
Algorithm Hash digest
SHA256 62ea6fcb2db3ef5ff815e4ba8448c602298ee38fe6b77a642745b5f570fb0a9d
MD5 ad6e6fee65b9fba3703f0c0ad3bfdd36
BLAKE2b-256 ba84f8c7f4897e253cbece36181eb3786575ad44008cf6f9a4b59f615b66e508

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