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):
- Authorization: Bearer <token> — else 401
- JWT header.alg ∈ {RS256, ES256, EdDSA} — else 401 (no HS*, no none)
- Signature verifies against JWKS by kid — else 401
- iss == $IAM_ISSUER — else 401
- aud ∋ $IAM_AUDIENCE — else 401
- exp > now (no leeway) — else 401
- nbf ≤ now when present — else 401
- 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 ¶
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
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
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 ¶
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).
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
|