Skip to main content

Azure Key Vault certificate utilities for the Swarmauri ecosystem

Project description

Swarmauri Logo

PyPI - Downloads Hits PyPI - Python Version PyPI - License PyPI - swarmauri_certs_azure


swarmauri_certs_azure

Community-maintained utilities for working with X.509 certificates via Azure Key Vault.

Features

  • AzureKeyVaultCertService adapter that plugs into Swarmauri's certificate service architecture.
  • RFC-aligned helpers for serial number generation (RFC 5280), PEM formatting (RFC 7468), and PKCS#10 CSR creation (RFC 2986).
  • Native DefaultAzureCredential support so you can reuse the same authentication chain across tools.
  • Works with RSA 2048-bit key material—perfect for Key Vault-backed certificate issuance flows.

Prerequisites

  • Python 3.10 or newer.
  • An Azure Key Vault enabled for the Certificates and Keys resource providers.
  • Exportable RSA key material (PEM) or an Azure Key Vault key that can be exported for CSR signing.
  • Azure credentials configured for DefaultAzureCredential (e.g., AZURE_CLIENT_ID, managed identity, or CLI login).

Installation

# pip
pip install swarmauri_certs_azure

# poetry
poetry add swarmauri_certs_azure

# uv (pyproject-based projects)
uv add swarmauri_certs_azure

Quickstart

Generate a CSR using AzureKeyVaultCertService and store it for downstream issuance:

import asyncio
from pathlib import Path

from azure.identity import DefaultAzureCredential

from swarmauri_certs_azure.certs import AzureKeyVaultCertService
from swarmauri_core.crypto.types import KeyRef


async def main() -> None:
    service = AzureKeyVaultCertService(
        vault_url="https://example-vault.vault.azure.net/",
        credential=DefaultAzureCredential(),
    )

    key_ref = KeyRef(material=Path("app-private-key.pem").read_bytes())
    csr_bytes = await service.create_csr(
        key=key_ref,
        subject={"CN": "app.example.com"},
        san={"dns": ["app.example.com", "www.app.example.com"]},
    )

    Path("app.csr").write_bytes(csr_bytes)
    print("CSR written to app.csr")


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

Integrate with Azure Certificate Workflows

After generating the CSR, import it into Azure Key Vault or an external CA:

from pathlib import Path

from azure.identity import DefaultAzureCredential
from azure.keyvault.certificates import CertificateClient

vault_url = "https://example-vault.vault.azure.net/"
client = CertificateClient(vault_url=vault_url, credential=DefaultAzureCredential())

csr_bytes = Path("app.csr").read_bytes()

poller = client.begin_create_certificate(
    certificate_name="app-cert",
    policy={
        "contentType": "application/x-pem-file",
        "csr": csr_bytes,
    },
)

certificate = poller.result()
print("Certificate operation state:", certificate.properties.x509_thumbprint)

For external issuance, submit app.csr to your CA, then store the returned certificate chain back in Key Vault using set_certificate_contacts and import_certificate.

Testing

Run tests with:

uv run --package swarmauri_certs_azure --directory community pytest

Best Practices

  • Prefer managed identities or workload identity federation over client secrets in production.
  • Scope Key Vault permissions tightly (get, sign, unwrapKey) for the keys used by this service.
  • Rotate keys and certificates ahead of expiry; the helper functions simplify CSR generation for renewals.
  • Persist generated CSRs and issued certificates securely to aid in auditing and disaster recovery.

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

swarmauri_certs_azure-0.3.0.dev22.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

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

swarmauri_certs_azure-0.3.0.dev22-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file swarmauri_certs_azure-0.3.0.dev22.tar.gz.

File metadata

  • Download URL: swarmauri_certs_azure-0.3.0.dev22.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.27 {"installer":{"name":"uv","version":"0.9.27","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_certs_azure-0.3.0.dev22.tar.gz
Algorithm Hash digest
SHA256 7b78c45b8402c470b59507c0d65326e6cc88c0898d378f059409688cd94e222b
MD5 c5f2795b369bf1cc7873496369df0edf
BLAKE2b-256 e0206d1c9461320a6ea655711b719e69d378c3358ac7dbce93668b75fbc12e43

See more details on using hashes here.

File details

Details for the file swarmauri_certs_azure-0.3.0.dev22-py3-none-any.whl.

File metadata

  • Download URL: swarmauri_certs_azure-0.3.0.dev22-py3-none-any.whl
  • Upload date:
  • Size: 9.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.27 {"installer":{"name":"uv","version":"0.9.27","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_certs_azure-0.3.0.dev22-py3-none-any.whl
Algorithm Hash digest
SHA256 14b98ec5f5545bb9e2637a3d26fdf8e34587af401486deb6c9c40475d27b0d90
MD5 198fe61f28241f866a72bb196c01f373
BLAKE2b-256 4cedf79b6982fdb0740c00a059c0bd7412e120de0597e8f4c2a64c56f2a8eed6

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