From feeb5d334b82d678e41b5dcadf17f5ce9276c145 Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Thu, 2 Feb 2023 09:33:48 +0100 Subject: [PATCH] Populate the tags field on node Signed-off-by: Kristoffer Dalby --- flake.nix | 2 +- go.mod | 1 + go.sum | 2 ++ machine.go | 6 ++++++ 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index ec636657..1decac5f 100644 --- a/flake.nix +++ b/flake.nix @@ -36,7 +36,7 @@ # When updating go.mod or go.sum, a new sha will need to be calculated, # update this if you have a mismatch after doing a change to thos files. - vendorSha256 = "sha256-8p5NFxXKaZPsW4B6NMzfi0pqfVroIahSgA0fukvB3JI="; + vendorSha256 = "sha256-fxbEf8x+/HMI85Vo8cxIAEGKTMASuocrt9UBZo+BI58="; ldflags = [ "-s" "-w" "-X github.com/juanfont/headscale/cmd/headscale/cli.Version=v${version}" ]; }; diff --git a/go.mod b/go.mod index f35f19c9..600c349a 100644 --- a/go.mod +++ b/go.mod @@ -25,6 +25,7 @@ require ( github.com/pterm/pterm v0.12.50 github.com/puzpuzpuz/xsync/v2 v2.4.0 github.com/rs/zerolog v1.28.0 + github.com/samber/lo v1.37.0 github.com/spf13/cobra v1.6.1 github.com/spf13/viper v1.14.0 github.com/stretchr/testify v1.8.1 diff --git a/go.sum b/go.sum index 1ee91396..89f50e5f 100644 --- a/go.sum +++ b/go.sum @@ -591,6 +591,8 @@ github.com/rs/zerolog v1.28.0 h1:MirSo27VyNi7RJYP3078AA1+Cyzd2GB66qy3aUHvsWY= github.com/rs/zerolog v1.28.0/go.mod h1:NILgTygv/Uej1ra5XxGf82ZFSLk58MFGAUS2o6usyD0= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/samber/lo v1.37.0 h1:XjVcB8g6tgUp8rsPsJ2CvhClfImrpL04YpQHXeHPhRw= +github.com/samber/lo v1.37.0/go.mod h1:9vaz2O4o8oOnK23pd2TrXufcbdbJIa3b6cstBWKpopA= github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= github.com/seccomp/libseccomp-golang v0.9.2-0.20220502022130-f33da4d89646/go.mod h1:JA8cRccbGaA1s33RQf7Y1+q9gHmZX1yB/z9WDN1C6fg= github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ= diff --git a/machine.go b/machine.go index 754d4546..99a66f09 100644 --- a/machine.go +++ b/machine.go @@ -12,6 +12,7 @@ import ( v1 "github.com/juanfont/headscale/gen/go/headscale/v1" "github.com/rs/zerolog/log" + "github.com/samber/lo" "google.golang.org/protobuf/types/known/timestamppb" "gorm.io/gorm" "tailscale.com/tailcfg" @@ -738,6 +739,9 @@ func (h *Headscale) toNode( online := machine.isOnline() + tags, _ := getTags(h.aclPolicy, machine, h.cfg.OIDC.StripEmaildomain) + tags = lo.Uniq(append(tags, machine.ForcedTags...)) + node := tailcfg.Node{ ID: tailcfg.NodeID(machine.ID), // this is the actual ID StableID: tailcfg.StableNodeID( @@ -759,6 +763,8 @@ func (h *Headscale) toNode( Hostinfo: hostInfo.View(), Created: machine.CreatedAt, + Tags: tags, + PrimaryRoutes: primaryPrefixes, LastSeen: machine.LastSeen,