Skip to content

feat(consensus/keys): add consensus keys init - #1200

Open
leninmehedy wants to merge 1 commit into
01168-consensus-keys-verifyfrom
01195-consensus-keys-init
Open

leninmehedy wants to merge 1 commit into
01168-consensus-keys-verifyfrom
01195-consensus-keys-init

Conversation

@leninmehedy

@leninmehedy leninmehedy commented Sep 26, 2026 •

Copy link
Copy Markdown
Member

Summary

Fifth PR in the stacked series for epic #1164 — Consensus Node Key & Secret Management. Stacked on #1199 (base branch 01168-consensus-keys-verify).

Adds the one-shot consensus keys init verb — generate a node's key material and create its Kubernetes secrets in a single command — plus makes generation/import/export idempotent with an audit trail.

What's in it

  • consensus keys init --node-id N --keys-dir DIR — runs generate (gossip and gRPC keys) then import, reusing the exact same code paths (no new key logic). It never generates an admin key: if the operator saved the wallet's admin public key as admin.pub in --keys-dir, it is imported too (or required with --admin); otherwise init says no admin key was imported. The output names the exact secrets created. Pass-through flags: --identity, --machine-id, --grpc-cn, --grpc-org, --grpc-dns, --grpc-ip, --grpc-validity-days, --gossip/--tls/--admin, --force. For a DAB join (node-id unknown until assigned) use generate + import separately.
  • Idempotency across the family (this PR + the branches it builds on):
    • generate/init keep an existing key type in --keys-dir instead of regenerating (protecting the gossip identity); --force regenerates.
    • import re-applies identical material as a no-op and refuses a secret whose material differs without --force.
    • export leaves identical files untouched and refuses to clobber differing files without --force.
  • Audit logging — create/skip/overwrite are logged (verb-first messages) with rich structured fields (namespace, nodeId, secret, dir, force).
  • No admin private key is handled: only the admin public key from the wallet (admin.pub) reaches Kubernetes.

Files

File Purpose
cmd/cli/commands/consensus/keys/init.go init subcommand (generate + import, idempotent)
cmd/cli/commands/consensus/keys/init_test.go command tests
cmd/cli/commands/consensus/keys/keys.go wire init
docs/commands/consensus.md init section

Testing

Validated in the UTM VM:

go test -race -cover ./cmd/cli/commands/consensus/keys/... ./internal/consensus/keys/...

All pass.

Update: admin key generation was removed, which the VM run above predates, and the new gRPC certificate options were added after the VM run above. Their tests pass for pkg/internal on macOS and the command tests compile for Linux, but they still need a VM run.

Closes #1195.

@leninmehedy
leninmehedy requested a review from a team as a code owner September 26, 2026 14:43
@swirlds-automation

swirlds-automation commented Sep 26, 2026 •

Copy link
Copy Markdown

✅ Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
✅ Open Source Security 0 0 0 0 0 issues
✅ Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@leninmehedy
leninmehedy added this pull request to stack #1201 September 26, 2026 14:44
@leninmehedy
leninmehedy force-pushed the 01195-consensus-keys-init branch from 33a53e1 to 37dafc9 Compare September 29, 2026 05:13
@leninmehedy
leninmehedy force-pushed the 01195-consensus-keys-init branch from 37dafc9 to f8c7fc2 Compare October 13, 2026 06:27
@leninmehedy
leninmehedy force-pushed the 01195-consensus-keys-init branch from f8c7fc2 to 4978e78 Compare October 13, 2026 10:33
@leninmehedy
leninmehedy force-pushed the 01195-consensus-keys-init branch from 4978e78 to 3a0cd47 Compare October 13, 2026 11:06
@leninmehedy
leninmehedy force-pushed the 01195-consensus-keys-init branch from 3a0cd47 to 1012dbd Compare October 13, 2026 11:29
@leninmehedy
leninmehedy force-pushed the 01195-consensus-keys-init branch from 1012dbd to 276e5c6 Compare October 13, 2026 12:37
@leninmehedy
leninmehedy force-pushed the 01195-consensus-keys-init branch from 276e5c6 to 57cfa24 Compare October 13, 2026 12:52
@leninmehedy
leninmehedy marked this pull request as draft October 20, 2026 06:24
@leninmehedy leninmehedy added the skip-kvm-runner Skip kvm-runner jobs (UAT, integration) in PR checks; for stacked PRs below the top label Oct 21, 2026
@leninmehedy
leninmehedy force-pushed the 01195-consensus-keys-init branch from 57cfa24 to ae9ce29 Compare October 21, 2026 03:38
@leninmehedy
leninmehedy force-pushed the 01195-consensus-keys-init branch from ae9ce29 to 7ecacf3 Compare October 21, 2026 04:44
@leninmehedy
leninmehedy force-pushed the 01195-consensus-keys-init branch from 7ecacf3 to d9f4ac7 Compare October 21, 2026 05:19
Add the one-shot init verb: generate a node's key material into --keys-dir
and create the per-node secrets from it, reusing the generate and import
code paths (no new key logic).

- `consensus keys init --node-id N --keys-dir DIR` (node-id required):
  generate then import. Pass-through flags: --identity, --machine-id,
  --gossip/--tls/--admin selectors, --force.
- Idempotent: an existing key type in --keys-dir is kept (not regenerated),
  and re-applying identical secrets is a no-op; --force regenerates and
  overwrites differing material.
- No admin key is generated: the operator creates it in an external wallet
  and saves its public key as admin.pub in --keys-dir. init imports it when
  present (or with --admin) and otherwise says it was not imported.
- For a DAB join (node-id unknown until assigned) use generate + import
  separately instead.

Refs #1195

Signed-off-by: Lenin Mehedy <lenin.mehedy@hashgraph.com>
@radkomih
radkomih force-pushed the 01195-consensus-keys-init branch from d9f4ac7 to a977157 Compare November 4, 2026 12:46
@radkomih
radkomih marked this pull request as ready for review November 4, 2026 13:06
@radkomih
radkomih requested review from a team as code owners November 4, 2026 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-kvm-runner Skip kvm-runner jobs (UAT, integration) in PR checks; for stacked PRs below the top

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(consensus/keys): 'consensus node keys init' one-shot (generate+import)

2 participants