Skip to content

Commit

Permalink
feat: add validation of tags
Browse files Browse the repository at this point in the history
  • Loading branch information
restanrm committed May 13, 2022
1 parent fdbc965 commit 62cfd60
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 2 additions & 0 deletions cmd/headscale/cli/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,8 @@ var tagCmd = &cobra.Command{
fmt.Sprintf("Error while sending tags to headscale: %s", err),
output,
)

return
}

if resp != nil {
Expand Down
12 changes: 8 additions & 4 deletions grpcv1.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (

v1 "github.com/juanfont/headscale/gen/go/headscale/v1"
"github.com/rs/zerolog/log"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"tailscale.com/tailcfg"
)

Expand Down Expand Up @@ -194,10 +196,12 @@ func (api headscaleV1APIServer) SetTags(

for _, tag := range request.GetTags() {
if strings.Index(tag, "tag:") != 0 {
return &v1.SetTagsResponse{Machine: nil, Error: &v1.Error{
Status: 400,
Message: "Invalid tag detected. Each tag must start with the string 'tag:'",
}}, nil
return &v1.SetTagsResponse{
Machine: nil,
}, status.Error(
codes.InvalidArgument,
"Invalid tag detected. Each tag must start with the string 'tag:'",
)
}
}

Expand Down

0 comments on commit 62cfd60

Please sign in to comment.