Use ephemeral SSH keys per rebuild instead of static config keys
build-and-push / test (push) Successful in 9m57s
build-and-push / build-and-push (push) Has been cancelled

Generate a fresh ed25519 key pair at rebuild time, inject the public key
into the Proxmox answer file, use the private key for cluster join over
SSH, then remove the key from both the remote host and the database.
This eliminates the need to manage static SSH keys in config/secrets.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-03 21:09:22 -04:00
parent aec31b9f8b
commit b23ef64ee1
13 changed files with 191 additions and 68 deletions
+21 -1
View File
@@ -22,6 +22,16 @@ type HostOrchestrator struct {
ServerTypes *config.ServerTypeRegistry
}
// PrepareRebuild generates an ephemeral SSH key pair and stores it on the host.
// The public key will be injected into the Proxmox answer file.
func (o *HostOrchestrator) PrepareRebuild(ctx context.Context, hostID int64) error {
kp, err := GenerateEphemeralKey()
if err != nil {
return err
}
return o.Hosts.SetEphemeralKey(ctx, hostID, kp.PrivateKey, kp.PublicKey)
}
func (o *HostOrchestrator) HandlePhoneHome(ctx context.Context, hostID int64, ip string, hardwareID string) {
if err := o.Hosts.UpdateIP(ctx, hostID, ip, hardwareID); err != nil {
log.Printf("host %d: failed to update IP: %v", hostID, err)
@@ -47,17 +57,27 @@ func (o *HostOrchestrator) postPhoneHome(hostID int64, ip string, hardwareID str
return
}
privateKey, publicKey, err := o.Hosts.GetEphemeralKey(ctx, hostID)
if err != nil || privateKey == "" {
log.Printf("host %d: no ephemeral key available: %v", hostID, err)
o.Runner.FailHost(ctx, hostID, "no ephemeral SSH key")
return
}
if _, err := o.Runner.Transition(ctx, hostID, statemachine.TriggerClusterJoinStart); err != nil {
log.Printf("host %d: cluster join start transition failed: %v", hostID, err)
return
}
if err := o.Cluster.Join(ctx, ip); err != nil {
if err := o.Cluster.Join(ctx, ip, privateKey, publicKey); err != nil {
log.Printf("host %d: cluster join failed: %v", hostID, err)
o.Runner.FailHost(ctx, hostID, "cluster join: "+err.Error())
return
}
// Key has been removed from the remote host; clear it from the DB
_ = o.Hosts.ClearEphemeralKey(ctx, hostID)
if err := o.registerInfra(ctx, host, ip, hardwareID); err != nil {
log.Printf("host %d: infra registration failed: %v", hostID, err)
o.Runner.FailHost(ctx, hostID, "infra registration: "+err.Error())