magma-plugin — HashiCorp go-plugin handshake + mTLS bootstrap + gRPC client lifecycle + subprocess management for Terraform / OpenTofu providers.
Load-bearing layer per theory/MAGMA.md §IV. Spawn a provider
binary, complete the go-plugin handshake (magic cookie validation,
stdout-handshake-line parse, mTLS cert exchange), and return a
typed Plugin handle ready for gRPC calls.
Handshake protocol:
- Parent generates a self-signed cert + key via rcgen; DER-encodes
the cert; base64-encodes it; sets the env:
PLUGIN_MIN_PORT,PLUGIN_MAX_PORT(port range)<MAGIC_COOKIE_KEY>= cookie valuePLUGIN_PROTOCOL_VERSIONS=5,6PLUGIN_CLIENT_CERT=<base64 PEM>
- Parent spawns provider as subprocess.
- Provider validates magic cookie; exits 1 if mismatch.
- Provider generates its own self-signed leaf cert, binds to a
port in the allowed range, prints one handshake line:
CORE_PROTOCOL|APP_PROTOCOL|NETWORK|ADDRESS|PROTO_TYPE|CERT. - Parent parses the line, builds a tonic gRPC
Channelto the address. Production builds layer mTLS via tokio-rustls usingparent_cert(own identity) +provider_cert(trusted root); M0 ships the plain TCP dial — the cert exchange happens but encryption layering ships in M0.x once tonic's TLS config is pinned to a known-good rustls version pair. - Subsequent calls go over the gRPC channel.
- Parent sends SIGTERM (then SIGKILL after grace period) on Drop.