kms

package module
v0.159.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 17, 2026 License: MIT Imports: 23 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Archived. The canonical KMS is luxfi/kms (ghcr.io/luxfi/kms). This repository is kept read-only for history, and because sdk/go v1.1.1 is still resolvable from it. Nothing new should depend on it. What follows describes the retired server.

Hanzo KMS

Hanzo KMS

Secrets, keys, and threshold signing for the Hanzo platform — per-org namespaces, IAM-gated, ZAP-native, MPC-backed. A thin Go server over the canonical luxfi/kms primitives.

Status License Go

What this is

Hanzo KMS is the canonical secret store and signing service for every Hanzo deployment. It holds the per-tenant DEKs that back Hanzo Base, the provider API keys the AI and gateway services consume, certificate material, and validator signing keys.

AI agents are first-class identities: every secret carries a policy that controls whether an agent may read it — auto-approve, requires-approval, or blocked — with a full per-agent audit trail.

All server logic lives in luxfi/kms. This module wires those primitives with Hanzo defaults (IAM at hanzo.id, encrypted-at-rest storage, S3 replication) and adds JWT verification, the audit ledger, version CAS, and header hygiene. It builds as its own app (kms.App), which any host composes, and also ships as a standalone daemon.

Quick start

Build from source — pure Go, no database toolchain required:

make kmsd kms          # builds ./kmsd (daemon) and ./kms (admin CLI)
KMS_ENV=dev ./kmsd     # HTTP on :8443, ZAP on :9999

Or run the container image (pin a released tag — never :latest):

docker run -p 8443:8443 ghcr.io/hanzoai/kms:vX.Y.Z

In any non-dev environment the daemon refuses to boot without full JWT config (KMS_EXPECTED_ISSUER, KMS_EXPECTED_AUDIENCE, KMS_JWKS_URL) — fail-closed by design.

AI access control

Your secrets, your rules. AI agents are first-class citizens — and so is your ability to block them.

  • Per-secret policies — mark any secret requires-approval; a read from any agent triggers a real-time approval prompt.
  • Auto-approve mode — move fast in development, escalate specific secrets to manual sign-off before production.
  • Identity tracking — see exactly which model, tool, or agent accessed which secret, and when.
  • Full audit trail — every AI-originated read is logged with agent identity, timestamp, and reason.
Secret: STRIPE_LIVE_KEY
  policy:  requires-approval
  reader:  agent via hanzo-mcp
  status:  waiting for approval → [approve] [deny]

API surface

Everything is served under /v1/kms — one canonical path per operation, no aliases, no /api/. Every endpoint requires a Hanzo IAM JWT (RS/ES/PS/EdDSA — never HS*, never none) or an explicit admin role.

Group Endpoints
Auth POST /v1/kms/auth/login — machine-identity client credentials → IAM token
Secrets (per-org) GET / POST / PATCH / DELETE /v1/kms/orgs/{org}/secrets/… — env is a first-class key component; writes require an explicit env; PATCH requires version CAS via If-Match
MPC keys POST /v1/kms/keys/generate · /{id}/sign · /{id}/rotate · GET /v1/kms/keys · /v1/kms/status — threshold BLS / round signing via luxfi/mpc
Health GET /healthz — liveness, no auth

A sub-100µs binary ZAP transport (default :9999) mirrors the HTTP surface for in-cluster callers under the identical JWT + role model. The Go client at sdk/go (HTTP with ZAP fallback) is what every other Hanzo service uses to fetch secrets at runtime.

Storage & durability

  • At rest — ZapDB (LSM) at $KMS_DATA_DIR; per-secret 256-bit DEK wrapped under the master key (AES-256-GCM).
  • Replication — age-encrypted incremental + snapshot backups streamed to S3 (off when unset).
  • Audit — buffered SQLite side-table; single writer, never blocks the request path.

Specs

  • HIP-0027 — KMS
  • HIP-0106 — Unified Cloud Binary (kms subsystem)
  • HIP-0302 — Encrypted SQLite + ZapDB durability (DEK source)

Security

Please do not open public GitHub issues for security vulnerabilities. Email security@hanzo.ai with a description and, ideally, a reproduction. We respond quickly.

License

MIT — see LICENSE. Portions are derived from Infisical (MIT, © 2022 Infisical Inc.); see NOTICE. The current request path is a thin wrapper over luxfi/kms; no original upstream server code remains on the wire.


Hanzo — the Open AI Cloud

Open source · every language · on-chain settlement. hanzo.ai · docs.hanzo.ai

SDKs in every language — Python (flagship) · TypeScript · Go · Rust · C++ · Swift · Kotlin · umbrella

Documentation

Overview

KMS is an app. It builds its own zip.App and hands it back, so a host composes it — app.Use(kmsApp) — and nothing of the host's crosses into this module.

It used to be the other way around: Mount(app, deps) took hanzoai/cloud's Deps and an app the host had already built, and an init() pushed itself into cloud's registry so cloud could call it back. That points the dependency the wrong way. It makes the graph circular, since cloud imports kms in order to mount it, and it fixes the set of possible hosts at exactly one — there are two editions of hanzoai/cloud declaring the same module path, so cloud.Deps names a different type in each and a package that takes it can be composed by one of them and never the other.

Of the whole Deps struct this package read two fields: a logger, which luxfi/log already publishes as a process default and Embed already uses, and a data root, which is one string. So the coupling was one string.

The strategy is still "wrap, don't rewrite": kms.Embed already returns an http.Handler carrying every KMS route, the JWT verifier, the audit ledger and the ZAP transport. That handler hangs off a wildcard route through zip's net/http adaptor; health and readiness are native zip handlers.

JWT verification — full RFC 7519 enforcement: signature, alg allowlist, iss, aud, exp. Replaces the unverified-payload parsing that Red demonstrated fully bypassed with a 3-line curl + alg=none token on 2026-04-21.

Contract (by design, no hidden branches):

  1. Authorization: Bearer <token> — else 401
  2. JWT header.alg ∈ {RS256, ES256, EdDSA} — else 401 (no HS*, no none)
  3. Signature verifies against JWKS by kid — else 401
  4. iss == $IAM_ISSUER — else 401
  5. aud ∋ $IAM_AUDIENCE — else 401
  6. exp > now (no leeway) — else 401
  7. nbf ≤ now when present — else 401
  8. sub present — else 401

Any failure logs a structured audit line with the failure class (alg_none, expired, wrong_iss, wrong_aud, jwks_miss, sig, missing_sub). No JWT payload claim is echoed back to the caller or into logs.

Package kms is the in-process Hanzo KMS server. It is a thin wrapper over github.com/luxfi/kms with Hanzo-specific defaults (port 8443, /data/hanzo-kms), explicit IAM/JWKS/issuer/audience config (no defaults — refuses to boot if missing), JWT verification (RFC 7519, no HS*, no alg=none), and identity-header hygiene.

Secrets are stored in ZapDB at cfg.DataDir with optional at-rest encryption via KMS_ENCRYPTION_KEY_B64, and the in-process Replicator streams encrypted backups to S3. They are reached over the ZAP transport, whose authorizer is a signed consensus-authority snapshot (consensus.go) and which is disabled unless that snapshot is present.

There is no HTTP secret plane here. Secret reads and writes over HTTP are served by cloud (apps/kms) on /v1/kms/secrets, which takes the org from the caller's token and folds it into the storage key, so one tenant's path cannot name another's record. This package therefore makes no authorization decision at all: IAM owns identity and permissions, and verifyJWT answers only "who signed this token".

The HTTP surface is health and the IAM client-credentials login proxy. The console is a static site (frontend/) that calls cloud. embed.go owns the route assembly plus the transport wiring, and exposes Embed(ctx, cfg) (*Embedded, error).

JWKS cache — per-env RSA public key resolver for JWT verification.

One cache per process. TTL 15min, serialized refresh, fail-closed on empty/bad JWKS. Same primitives every Hanzo service uses to verify IAM-issued tokens — keep behaviour identical across the platform.

Index

Constants

This section is empty.

Variables

View Source
var Version = "dev"

Version is overridden at build time via -ldflags "-X github.com/hanzoai/kms.Version=...".

Functions

func App added in v0.159.10

func App(root string) (*zip.App, error)

App builds the KMS surface and returns it as a zip.App.

root is the one fact a host supplies: the data root KMS keeps its store under, as root/kms. Empty means KMS resolves its own — $KMS_DATA_DIR, else /data/hanzo-kms — which is what the standalone daemon wants.

Embed runs with SkipListen: whoever composes this app owns the listener, and KMS only contributes routes. Teardown travels with the app rather than with the process — the Embedded handle owns zapdb, the ZAP node, the replicator and the audit ledger, and drains on the app's shutdown hook. zip makes a parent drain the children it composed, so there is no global handle to reach for and nothing a host has to remember to call.

A failed Embed returns an error and no app. There is no mounted-but-broken state to probe for.

func ListenAddr added in v0.159.10

func ListenAddr() string

ListenAddr is where the KMS HTTP surface binds: $KMS_LISTEN, else :8443.

Exported because Embed runs with SkipListen under a host that owns the listener, so the address is resolved in one place and read by both.

Types

type EmbedConfig

type EmbedConfig struct {
	// DataDir is the ZapDB persistence root.
	// Empty → "/data/hanzo-kms" (production default).
	DataDir string

	// HTTPAddr is the bind address for the HTTP server.
	// Empty → ":8443". Use ":0" for an ephemeral port (tests).
	HTTPAddr string

	// IAMEndpoint is the Hanzo IAM origin used for the
	// /v1/kms/auth/login client_credentials proxy. Required.
	IAMEndpoint string

	// JWKSURL is the JWKS endpoint for verifying inbound JWTs.
	// Required when JWTKeySource is empty. Tests can point this at an
	// httptest.Server.
	JWKSURL string

	// JWTKeySource is an alias kept for parity with iam.EmbedConfig
	// and the fused-binary call site. When non-empty, overrides
	// JWKSURL. Empty → JWKSURL or default.
	JWTKeySource string

	// ZAPPort is the ZAP secrets-server listen port.
	// 0 → 9999. Negative disables.
	ZAPPort int

	// NodeID identifies this KMS instance for replication paths and
	// ZAP service discovery. Empty → "hanzo-kms-0".
	NodeID string

	// Env names the deployment environment. All envs (including dev)
	// must supply IAM_ISSUER, IAM_AUDIENCE, IAM_KEYS_URL or boot fails.
	// Empty → "dev".
	Env string

	// ExpectedIssuer is the iss claim a JWT must carry. Empty →
	// $IAM_ISSUER.
	ExpectedIssuer string

	// ExpectedAudience is the aud claim a JWT must carry (comma list
	// allowed). Empty → $IAM_AUDIENCE.
	ExpectedAudience string

	// SkipListen, when true, runs the bootstrap and registers all
	// routes/ZAP handlers, but does NOT bind the HTTP listener.
	// The parent serves the returned HTTPHandler() over its own
	// listener. Tests use this flag.
	SkipListen bool
}

EmbedConfig configures the in-process Hanzo KMS server.

Process-shape fields (DataDir, HTTPAddr, ZAPPort) resolve to the canonical defaults of the kmsd container image. Identity-coupled fields (IAMEndpoint, JWKSURL, ExpectedIssuer, ExpectedAudience) have no defaults — supply them via env or config or Embed refuses to boot.

type Embedded

type Embedded struct {
	// contains filtered or unexported fields
}

Embedded is the handle to a running Hanzo KMS server.

func Embed

func Embed(ctx context.Context, cfg EmbedConfig) (*Embedded, error)

Embed boots the Hanzo KMS server in-process and returns a handle.

Embed is safe to call exactly once per process: it registers process-global JWT verification config. The fused hanzo binary calls Embed once at startup and keeps the handle for the lifetime of the process.

The provided ctx is used for cancellation; if ctx is cancelled before Stop is called, Embed shuts the server down automatically.

func (*Embedded) Custody added in v0.159.10

func (e *Embedded) Custody() (*custody.Store, error)

Custody returns the node identity store backed by this KMS.

It fails when KMS_MASTER_KEY_B64 is absent or malformed, because nothing can be sealed without it and a custody surface that cannot seal must refuse rather than degrade. The same store is returned on every call, so the lock that serializes enrolment and rotation is one lock.

func (*Embedded) HTTPHandler

func (e *Embedded) HTTPHandler() http.Handler

HTTPHandler returns the wrapped HTTP handler (mux + header hygiene + method allowlist). Mount this behind a parent listener (e.g. a fused hanzo binary or hanzoai/gateway).

func (*Embedded) Stop

func (e *Embedded) Stop(ctx context.Context) error

Stop gracefully shuts down the KMS server. Idempotent.

func (*Embedded) ZAPPort

func (e *Embedded) ZAPPort() int

ZAPPort returns the ZAP secrets-server port (0 when disabled).

Directories

Path Synopsis
cmd
kms command
Command kms is the admin CLI for KMS.
Command kms is the admin CLI for KMS.
kms-fetch command
Command kms-fetch is the canonical init-container that materialises secrets from Hanzo KMS into a tmpfs volume the main container reads.
Command kms-fetch is the canonical init-container that materialises secrets from Hanzo KMS into a tmpfs volume the main container reads.
kmsd command
Hanzo KMS daemon.
Hanzo KMS daemon.
smoke-zap command
Package custody holds a node's identity keypair on the node's behalf.
Package custody holds a node's identity keypair on the node's behalf.
sdk
go module

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址