Simplify and clarify configuration

- changed "secure port" to "tls port"
- removed the --create flag for "wwctl configure tls"; made it the default behavior
- fixed a TLS creation bug in "wwctl configure --all"
- added logging to "wwctl configure tls" and "wwctl configure --all" (for the tls case)

Signed-off-by: Jonathon Anderson <janderson@ciq.com>
This commit is contained in:
Jonathon Anderson
2026-03-04 08:18:07 -07:00
parent 6ce3d33f50
commit a886b4958b
13 changed files with 65 additions and 55 deletions

View File

@@ -14,16 +14,44 @@ import (
"time"
warewulfconf "github.com/warewulf/warewulf/internal/pkg/config"
"github.com/warewulf/warewulf/internal/pkg/util"
"github.com/warewulf/warewulf/internal/pkg/wwlog"
)
/*
GenTLSKeys checks for existence of x509 keys and creates them if they don't exist.
*/
// TLS ensures TLS keys exist if TLS is enabled.
// If force is true, regenerates even if keys already exist.
// Returns true if new keys were generated.
func TLS(force bool) (bool, error) {
conf := warewulfconf.Get()
if !conf.Warewulf.EnableTLS() {
return false, nil
}
keystore := path.Join(conf.Paths.Sysconfdir, "warewulf", "tls")
keyFile := path.Join(keystore, "warewulf.key")
certFile := path.Join(keystore, "warewulf.crt")
if !force && util.IsFile(keyFile) && util.IsFile(certFile) {
wwlog.Info("TLS keys already exist in %s", keystore)
return false, nil
}
if err := GenTLSKeys(); err != nil {
return false, err
}
wwlog.Info("TLS keys generated in %s", keystore)
return true, nil
}
// GenTLSKeys generates new TLS keys and certificate unconditionally.
func GenTLSKeys() error {
conf := warewulfconf.Get()
keystore := path.Join(conf.Paths.Sysconfdir, "warewulf", "tls")
if err := os.MkdirAll(keystore, 0755); err != nil {
return fmt.Errorf("could not create keystore directory: %w", err)
}
keyFile := path.Join(keystore, "warewulf.key")
certFile := path.Join(keystore, "warewulf.crt")
wwlog.Verbose("Generating new x509 keys in %s", keystore)