Files
kms/cmd/kmsd/main.go
zeekayandGitHub e9a83302c1 feat: cloud Mount() per HIP-0106 (#10)
* docs(llm): explicit Upstream attribution line

LICENSE-attested or repo-attested upstream is now called out at the
top of LLM.md alongside the project description, so downstream
audits (universe/docs/PRODUCTS.md) can rely on a single canonical
location for the OSS lineage statement.

* feat: cloud Mount() per HIP-0106

Adds pkg/kms.Mount(*zip.App, cloud.Deps) error so the unified Hanzo
Cloud binary can blank-import and register the in-process KMS
server alongside every other Hanzo subsystem.

- pkg/kms/mount.go: native /v1/kms/health + /v1/kms/readyz zip
  handlers and zip.AdaptNetHTTP wrap of the existing Embed mux at
  /v1/kms/* + /healthz. init() registers with cloud.Register("kms",
  10, …) so blank import wires the subsystem in.
- cmd/kmsd: rewritten as a HIP-0106 thin shim — cloud.LoadConfig +
  cloud.BuildDeps + zip.New + kms.Mount + app.Listen. The Embed
  surface is unchanged; only assembly moves through zip.
- schema/kms.zap: minimal Health ZAP interface; full secret/key
  surfaces land in follow-up PRs.

Standalone kmsd binary still ships via the existing Dockerfile and
CI workflow.

* refactor: collapse pkg/kms/ → root for clean import path

Subsystem code lives in package kms at repo root. Importers now use
`github.com/hanzoai/kms` (no /pkg/kms/ nesting). Standalone shim moved
to cmd/kms/ where applicable.

Per Hanzo Go-stdlib pattern: repo IS the package.

* refactor: flatten import path — github.com/hanzoai/cloud (drop /pkg/cloud)
2026-05-18 23:37:41 -07:00

83 lines
2.2 KiB
Go

// Hanzo KMS daemon — HIP-0106 thin shim.
//
// All assembly logic, route handlers, JWT verification, audit log,
// version CAS, and ZAP transport live in pkg/kms. This binary just:
//
// - Loads config via cloud.LoadConfig() (env + flags).
// - Builds shared deps via cloud.BuildDeps(cfg).
// - Spins up a zip.App, calls kms.Mount(app, deps) — the same Mount
// the unified cloud binary calls — and listens on cfg.ListenAddr.
//
// The fused cloud binary mounts pkg/kms via blank import + init()
// registration. This shim exists for standalone deploys (Dockerfile,
// k8s sidecars) where running the whole cloud surface is overkill.
package main
import (
"context"
"fmt"
"os"
"os/signal"
"syscall"
"time"
"github.com/hanzoai/cloud"
"github.com/hanzoai/zip"
"github.com/hanzoai/zip/middleware"
"github.com/luxfi/log"
kms "github.com/hanzoai/kms"
)
// version is overridden at build time via -ldflags "-X main.version=...".
// We propagate it into the package-level kms.Version so /healthz and
// /v1/kms/health report the same string.
var version = "dev"
func main() {
kms.Version = version
cfg := cloud.LoadConfig()
if err := cfg.Validate(); err != nil {
fmt.Fprintf(os.Stderr, "config: %v\n", err)
os.Exit(1)
}
deps := cloud.BuildDeps(cfg)
app := zip.New(zip.Config{
Logger: deps.Logger,
AppName: "kms",
})
app.Use(middleware.Recover())
app.Use(middleware.RequestID())
app.Use(middleware.Logger(deps.Logger))
if err := kms.Mount(app, deps); err != nil {
log.Crit("kms: mount", "err", err)
}
// Listen in a goroutine so we can intercept SIGINT/SIGTERM and
// drain the in-process server gracefully via kms.Shutdown.
listenErr := make(chan error, 1)
go func() {
log.Info("kms: listening", "addr", cfg.ListenAddr)
listenErr <- app.Listen(cfg.ListenAddr)
}()
sig := make(chan os.Signal, 1)
signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM)
select {
case s := <-sig:
log.Info("kms: shutting down", "signal", s)
case err := <-listenErr:
log.Crit("kms: listen failed", "err", err)
}
stopCtx, stopCancel := context.WithTimeout(context.Background(), 10*time.Second)
defer stopCancel()
_ = kms.Shutdown(stopCtx)
_ = app.ShutdownWithContext(stopCtx)
}