Skip to content

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

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

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 then import, reusing the exact same code paths (no new key logic). The output names the exact secrets created. Pass-through flags: --identity, --machine-id, --admin-algo, --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).
  • Admin private key stays in --keys-dir (operator custody); only the public key 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: 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
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,
  --admin-algo, --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.
- Admin private key stays in --keys-dir (operator custody); only the public
  key is pushed to Kubernetes.
- 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>
@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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

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