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:
@@ -261,7 +261,7 @@ func CobraRunE(cmd *cobra.Command, args []string) (err error) {
|
||||
port := conf.Warewulf.Port
|
||||
scheme := "http"
|
||||
if conf.Warewulf.EnableTLS() {
|
||||
port = conf.Warewulf.SecurePort
|
||||
port = conf.Warewulf.TlsPort
|
||||
scheme = "https"
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
package configure
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
warewulfconf "github.com/warewulf/warewulf/internal/pkg/config"
|
||||
"github.com/warewulf/warewulf/internal/pkg/configure"
|
||||
"github.com/warewulf/warewulf/internal/pkg/util"
|
||||
"github.com/warewulf/warewulf/internal/pkg/wwlog"
|
||||
)
|
||||
|
||||
@@ -23,17 +20,8 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
if allFunctions {
|
||||
keystore := path.Join(conf.Paths.Sysconfdir, "warewulf", "tls")
|
||||
keyFile := path.Join(keystore, "warewulf.key")
|
||||
certFile := path.Join(keystore, "warewulf.crt")
|
||||
|
||||
if !util.IsFile(keyFile) || !util.IsFile(certFile) {
|
||||
err = configure.GenTLSKeys()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
fmt.Printf("Keys already exist in %s\n", keystore)
|
||||
if _, err = configure.TLS(false); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = configure.WAREWULFD()
|
||||
|
||||
@@ -19,10 +19,6 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
conf := config.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")
|
||||
|
||||
@@ -75,21 +71,21 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
if util.IsFile(keyFile) && util.IsFile(certFile) && !force {
|
||||
if create {
|
||||
fmt.Fprintf(cmd.OutOrStdout(), "Keys already exist in %s\n", keystore)
|
||||
if !conf.Warewulf.EnableTLS() {
|
||||
fmt.Fprintf(cmd.OutOrStdout(), "TLS is not enabled in warewulf.conf\n")
|
||||
return nil
|
||||
}
|
||||
|
||||
created, err := configure.TLS(force)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if created {
|
||||
if err := configure.WAREWULFD(); err != nil {
|
||||
return fmt.Errorf("failed to restart warewulfd: %w", err)
|
||||
}
|
||||
} else {
|
||||
if create {
|
||||
if err := configure.GenTLSKeys(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := configure.WAREWULFD(); err != nil {
|
||||
return fmt.Errorf("failed to restart warewulfd: %w", err)
|
||||
}
|
||||
} else {
|
||||
return fmt.Errorf("keys not found in: %s", keystore)
|
||||
}
|
||||
fmt.Fprintf(cmd.OutOrStdout(), "Keys already exist in %s\n", keystore)
|
||||
}
|
||||
|
||||
w := tabwriter.NewWriter(cmd.OutOrStdout(), 0, 0, 2, ' ', 0)
|
||||
|
||||
@@ -14,6 +14,9 @@ func Test_Keys(t *testing.T) {
|
||||
env := testenv.New(t)
|
||||
defer env.RemoveAll()
|
||||
|
||||
// Enable TLS in the test config
|
||||
env.WriteFile("etc/warewulf/warewulf.conf", "warewulf:\n tls: true\n")
|
||||
|
||||
// Define a keystore path within the test environment
|
||||
keystoreRelPath := "etc/warewulf/tls"
|
||||
keystorePath := env.GetPath(keystoreRelPath)
|
||||
@@ -24,11 +27,10 @@ func Test_Keys(t *testing.T) {
|
||||
t.Run("keys create", func(t *testing.T) {
|
||||
baseCmd := GetCommand()
|
||||
// Reset flags
|
||||
create = true
|
||||
importPath = ""
|
||||
exportPath = ""
|
||||
|
||||
baseCmd.SetArgs([]string{"--create"})
|
||||
baseCmd.SetArgs([]string{})
|
||||
buf := new(bytes.Buffer)
|
||||
baseCmd.SetOut(buf)
|
||||
baseCmd.SetErr(buf)
|
||||
@@ -43,11 +45,10 @@ func Test_Keys(t *testing.T) {
|
||||
t.Run("keys exist check", func(t *testing.T) {
|
||||
baseCmd := GetCommand()
|
||||
// Reset flags
|
||||
create = true // Even with create, it should say they exist
|
||||
importPath = ""
|
||||
exportPath = ""
|
||||
|
||||
baseCmd.SetArgs([]string{"--create"})
|
||||
baseCmd.SetArgs([]string{})
|
||||
buf := new(bytes.Buffer)
|
||||
baseCmd.SetOut(buf)
|
||||
baseCmd.SetErr(buf)
|
||||
@@ -61,7 +62,6 @@ func Test_Keys(t *testing.T) {
|
||||
t.Run("keys display", func(t *testing.T) {
|
||||
baseCmd := GetCommand()
|
||||
// Reset flags
|
||||
create = false
|
||||
importPath = ""
|
||||
exportPath = ""
|
||||
|
||||
@@ -88,7 +88,6 @@ func Test_Keys(t *testing.T) {
|
||||
|
||||
baseCmd := GetCommand()
|
||||
// Reset flags
|
||||
create = false
|
||||
importPath = ""
|
||||
exportPath = exportFullPath
|
||||
|
||||
|
||||
@@ -18,14 +18,12 @@ var (
|
||||
}
|
||||
importPath string
|
||||
exportPath string
|
||||
create bool
|
||||
force bool
|
||||
)
|
||||
|
||||
func init() {
|
||||
baseCmd.PersistentFlags().StringVar(&importPath, "import", "", "Import keys from directory")
|
||||
baseCmd.PersistentFlags().StringVar(&exportPath, "export", "", "Export keys to directory")
|
||||
baseCmd.PersistentFlags().BoolVar(&create, "create", false, "Create keys if they do not exist")
|
||||
baseCmd.PersistentFlags().BoolVarP(&force, "force", "f", false, "Enforce creation of keys even if they exist")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user