enable https and key handling

- add key generation and import for warewulfd
- add https port to warewulfd
- configuration optiions for port and

keys
This commit is contained in:
Christian Goll
2025-12-01 16:15:16 +01:00
committed by Jonathon Anderson
parent 856223dadd
commit a1c11db8cc
10 changed files with 429 additions and 0 deletions

View File

@@ -39,6 +39,7 @@ type templateVars struct {
KernelArgs string
KernelVersion string
Root string
Https bool
Tags map[string]string
NetDevs map[string]*node.NetDev
}
@@ -247,6 +248,7 @@ func ProvisionSend(w http.ResponseWriter, req *http.Request) {
Ipaddr: conf.Ipaddr,
Ipaddr6: ipaddr6,
Port: strconv.Itoa(conf.Warewulf.Port),
Https: conf.Warewulf.EnableHttps(),
Authority: authority,
Hostname: remoteNode.Id(),
Hwaddr: rinfo.hwaddr,

View File

@@ -5,6 +5,7 @@ import (
"net/http"
"os"
"os/signal"
"path"
"strconv"
"strings"
"syscall"
@@ -82,6 +83,24 @@ func RunServer() error {
defaultHandler.ServeHTTP(w, r)
}
})
if conf.Warewulf.EnableHttps() {
key := path.Join(conf.Paths.Sysconfdir, "warewulf", "keys", "warewulf.key")
crt := path.Join(conf.Paths.Sysconfdir, "warewulf", "keys", "warewulf.crt")
if !util.IsFile(key) || !util.IsFile(crt) {
wwlog.Error("HTTPS enabled but keys not found in %s", path.Join(conf.Paths.Sysconfdir, "warewulf", "keys"))
} else {
go func() {
wwlog.Info("Starting HTTPS service on port %d", conf.Warewulf.SecurePort)
if err := http.ListenAndServeTLS(":"+strconv.Itoa(conf.Warewulf.SecurePort), crt, key, dispatchHandler); err != nil {
wwlog.Error("Could not start HTTPS service: %s", err)
}
}()
}
}
wwlog.Info("Starting HTTP service on port %d", daemonPort)
if err := http.ListenAndServe(":"+strconv.Itoa(daemonPort), dispatchHandler); err != nil {
return fmt.Errorf("could not start listening service: %w", err)
}