added hash check for node edit

Signed-off-by: Christian Goll <cgoll@suse.de>
This commit is contained in:
Christian Goll
2023-02-28 15:58:44 +01:00
parent ee4f9d53d6
commit b4acf0fdf2
10 changed files with 604 additions and 432 deletions

View File

@@ -1,6 +1,7 @@
package apinode
import (
"encoding/hex"
"encoding/json"
"fmt"
"net/http"
@@ -29,7 +30,10 @@ func NodeAdd(nap *wwapiv1.NodeAddParameter) (err error) {
if err != nil {
return errors.Wrap(err, "failed to open node database")
}
dbHash := nodeDB.Hash()
if hex.EncodeToString(dbHash[:]) != nap.Hash && !nap.Force {
return fmt.Errorf("got wrong hash, not modifying node database")
}
node_args := hostlist.Expand(nap.NodeNames)
var nodeConf node.NodeConf
err = yaml.Unmarshal([]byte(nap.NodeConfYaml), &nodeConf)
@@ -95,6 +99,10 @@ func NodeDelete(ndp *wwapiv1.NodeDeleteParameter) (err error) {
wwlog.Error("Failed to open node database: %s", err)
return
}
dbHash := nodeDB.Hash()
if hex.EncodeToString(dbHash[:]) != ndp.Hash && !ndp.Force {
return fmt.Errorf("got wrong hash, not modifying node database")
}
for _, n := range nodeList {
err := nodeDB.DelNode(n.Id.Get())
@@ -133,6 +141,13 @@ func NodeDeleteParameterCheck(ndp *wwapiv1.NodeDeleteParameter, console bool) (n
wwlog.Error("Failed to open node database: %s", err)
return
}
dbHash := nodeDB.Hash()
if hex.EncodeToString(dbHash[:]) != ndp.Hash && !ndp.Force {
wwlog.Debug("got hash: %s", ndp.Hash)
wwlog.Debug("actual hash: %s", hex.EncodeToString(dbHash[:]))
err = fmt.Errorf("got wrong hash, not modifying node database")
return
}
nodes, err := nodeDB.FindAllNodes()
if err != nil {