b23ef64ee1
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>
45 lines
1.5 KiB
Go
45 lines
1.5 KiB
Go
package pxe
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"provisioning/internal/config"
|
|
"provisioning/internal/model"
|
|
)
|
|
|
|
func GenerateAnswerFile(host *model.Host, serverType model.ServerType, cfg *config.Config, sshPublicKey string) string {
|
|
var b strings.Builder
|
|
|
|
b.WriteString("[global]\n")
|
|
b.WriteString(`keyboard = "en-us"` + "\n")
|
|
b.WriteString(`country = "us"` + "\n")
|
|
b.WriteString(fmt.Sprintf("fqdn = \"%s.thewrightserver.net\"\n", host.Hostname))
|
|
b.WriteString(`mailto = "admin@thewrightserver.net"` + "\n")
|
|
b.WriteString(`timezone = "America/Indiana/Indianapolis"` + "\n")
|
|
b.WriteString(fmt.Sprintf("root-password-hashed = \"%s\"\n", cfg.Credentials.RootPasswordHash))
|
|
b.WriteString(fmt.Sprintf("root-ssh-keys = [\"%s\"]\n", strings.TrimSpace(sshPublicKey)))
|
|
b.WriteString("\n")
|
|
|
|
b.WriteString("[network]\n")
|
|
b.WriteString(`source = "from-dhcp"` + "\n")
|
|
b.WriteString("\n")
|
|
|
|
b.WriteString("[disk-setup]\n")
|
|
b.WriteString(`filesystem = "zfs"` + "\n")
|
|
b.WriteString(`zfs.raid = "raid0"` + "\n")
|
|
b.WriteString(fmt.Sprintf("disk-list = [\"%s\"]\n", serverType.BootDisk))
|
|
b.WriteString("\n")
|
|
|
|
b.WriteString("[post-installation-webhook]\n")
|
|
b.WriteString(fmt.Sprintf("url = \"%s/api/hosts/%d/installed\"\n", cfg.Server.PublicURL, host.ID))
|
|
b.WriteString("\n")
|
|
|
|
b.WriteString("[first-boot]\n")
|
|
b.WriteString(`source = "from-url"` + "\n")
|
|
b.WriteString(fmt.Sprintf("url = \"%s/api/hosts/%d/first-boot-script\"\n", cfg.Server.PublicURL, host.ID))
|
|
b.WriteString(`ordering = "after-network"` + "\n")
|
|
|
|
return b.String()
|
|
}
|