Merge pull request #719 from hpcng/hashConf

more secure edit command
This commit is contained in:
Christian Goll
2023-04-11 11:44:01 +02:00
committed by GitHub
13 changed files with 761 additions and 434 deletions

View File

@@ -35,6 +35,7 @@ func CobraRunE(vars *variables) func(cmd *cobra.Command, args []string) error {
set := wwapiv1.NodeAddParameter{
NodeConfYaml: string(buffer[:]),
NodeNames: args,
Force: true,
}
return apinode.NodeAdd(&set)
}

View File

@@ -29,11 +29,11 @@ var (
},
}
SetYes bool
SetForce bool // currently unused
SetForce bool // no hash checking, so always using force
)
func init() {
baseCmd.PersistentFlags().BoolVarP(&SetForce, "force", "f", false, "Force node delete")
SetForce = true
baseCmd.PersistentFlags().BoolVarP(&SetYes, "yes", "y", false, "Set 'yes' to all questions asked")
}
@@ -41,4 +41,4 @@ func init() {
// GetRootCommand returns the root cobra.Command for the application.
func GetCommand() *cobra.Command {
return baseCmd
}
}

View File

@@ -88,12 +88,20 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
if !yes {
break
}
err = apinode.NodeDelete(&wwapiv1.NodeDeleteParameter{NodeNames: nodeList, Force: true})
err = apinode.NodeDelete(&wwapiv1.NodeDeleteParameter{
NodeNames: nodeList,
Hash: nodeListMsg.Hash,
})
if err != nil {
wwlog.Verbose("Problem deleting nodes before modification %s")
wwlog.Error("Problem deleting nodes before modification: %s", err)
return err
}
buffer, _ = yaml.Marshal(modifiedNodeMap)
err = apinode.NodeAddFromYaml(&wwapiv1.NodeYaml{NodeConfMapYaml: string(buffer)})
newHash := apinode.Hash()
err = apinode.NodeAddFromYaml(&wwapiv1.NodeYaml{
NodeConfMapYaml: string(buffer),
Hash: newHash.Hash,
})
if err != nil {
wwlog.Error("Got following problem when writing back yaml: %s", err)
os.Exit(1)

View File

@@ -8,6 +8,8 @@ import (
"os"
"strings"
apinode "github.com/hpcng/warewulf/internal/pkg/api/node"
apiprofile "github.com/hpcng/warewulf/internal/pkg/api/profile"
"github.com/hpcng/warewulf/internal/pkg/api/routes/wwapiv1"
apiutil "github.com/hpcng/warewulf/internal/pkg/api/util"
@@ -88,12 +90,19 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
if !yes {
break
}
err = apiprofile.ProfileDelete(&wwapiv1.NodeDeleteParameter{NodeNames: nodeList, Force: true})
err = apiprofile.ProfileDelete(&wwapiv1.NodeDeleteParameter{
NodeNames: nodeList,
Hash: profileListMsg.Hash,
})
if err != nil {
wwlog.Verbose("Problem deleting nodes before modification %s")
}
buffer, _ = yaml.Marshal(modifiedProfileMap)
err = apiprofile.ProfileAddFromYaml(&wwapiv1.NodeYaml{NodeConfMapYaml: string(buffer)})
newHash := apinode.Hash()
err = apiprofile.ProfileAddFromYaml(&wwapiv1.NodeAddParameter{
NodeConfYaml: string(buffer),
Hash: newHash.Hash,
})
if err != nil {
wwlog.Error("Got following problem when writing back yaml: %s", err)
os.Exit(1)