diff --git a/hscontrol/db/node.go b/hscontrol/db/node.go index b3977214243..001a048de2c 100644 --- a/hscontrol/db/node.go +++ b/hscontrol/db/node.go @@ -206,7 +206,10 @@ func SetTags( tags []string, ) error { if len(tags) == 0 { - return nil + // if no tags are provided, we remove all forced tags + if err := tx.Model(&types.Node{}).Where("id = ?", nodeID).Update("forced_tags", nil).Error; err != nil { + return fmt.Errorf("failed to remove tags for node in the database: %w", err) + } } newTags := types.StringList{} diff --git a/hscontrol/db/node_test.go b/hscontrol/db/node_test.go index 84116f25b62..9ff022871a8 100644 --- a/hscontrol/db/node_test.go +++ b/hscontrol/db/node_test.go @@ -386,6 +386,13 @@ func (s *Suite) TestSetTags(c *check.C) { check.DeepEquals, types.StringList([]string{"tag:bar", "tag:test", "tag:unknown"}), ) + + // test removing tags + err = db.SetTags(node.ID, []string{}) + c.Assert(err, check.IsNil) + node, err = db.getNode("test", "testnode") + c.Assert(err, check.IsNil) + c.Assert(node.ForcedTags, check.DeepEquals, types.StringList([]string{})) } func TestHeadscale_generateGivenName(t *testing.T) {