ipn: only send services in Hostinfo if Tailnet has opted-in to services collection (#1107)

Signed-off-by: Sonia Appasamy <sonia@tailscale.com>
This commit is contained in:
Sonia Appasamy 2021-01-11 17:24:32 -05:00 committed by GitHub
parent f85769b1ed
commit 024671406b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 25 deletions

View File

@ -765,6 +765,7 @@ func (c *Direct) sendMapRequest(ctx context.Context, maxPolls int, cb func(*Netw
DNS: resp.DNSConfig, DNS: resp.DNSConfig,
Hostinfo: resp.Node.Hostinfo, Hostinfo: resp.Node.Hostinfo,
PacketFilter: lastParsedPacketFilter, PacketFilter: lastParsedPacketFilter,
CollectServices: resp.CollectServices,
DERPMap: lastDERPMap, DERPMap: lastDERPMap,
Debug: resp.Debug, Debug: resp.Debug,
} }

View File

@ -39,6 +39,12 @@ type NetworkMap struct {
Hostinfo tailcfg.Hostinfo Hostinfo tailcfg.Hostinfo
PacketFilter []filter.Match PacketFilter []filter.Match
// CollectServices reports whether this node's Tailnet has
// requested that info about services be included in HostInfo.
// If set, Hostinfo.ShieldsUp blocks services collection; that
// takes precedence over this field.
CollectServices bool
// DERPMap is the last DERP server map received. It's reused // DERPMap is the last DERP server map received. It's reused
// between updates and should not be modified. // between updates and should not be modified.
DERPMap *tailcfg.DERPMap DERPMap *tailcfg.DERPMap

View File

@ -1015,16 +1015,18 @@ func (b *LocalBackend) parseWgStatusLocked(s *wgengine.Status) (ret EngineStatus
return ret return ret
} }
// shieldsAreUp returns whether user preferences currently request // shouldUploadServices reports whether this node should include services
// "shields up" mode, which disallows all inbound connections. // in Hostinfo. When the user preferences currently request "shields up"
func (b *LocalBackend) shieldsAreUp() bool { // mode, all inbound connections are refused, so services are not reported.
// Otherwise, shouldUploadServices respects NetMap.CollectServices.
func (b *LocalBackend) shouldUploadServices() bool {
b.mu.Lock() b.mu.Lock()
defer b.mu.Unlock() defer b.mu.Unlock()
if b.prefs == nil { if b.prefs == nil || b.netMap == nil {
return true // default to safest setting return false // default to safest setting
} }
return b.prefs.ShieldsUp return !b.prefs.ShieldsUp && b.netMap.CollectServices
} }
func (b *LocalBackend) SetCurrentUserID(uid string) { func (b *LocalBackend) SetCurrentUserID(uid string) {
@ -1124,9 +1126,7 @@ func (b *LocalBackend) SetPrefs(newp *Prefs) {
// painstakingly constructing it in twelvety other places. // painstakingly constructing it in twelvety other places.
func (b *LocalBackend) doSetHostinfoFilterServices(hi *tailcfg.Hostinfo) { func (b *LocalBackend) doSetHostinfoFilterServices(hi *tailcfg.Hostinfo) {
hi2 := *hi hi2 := *hi
if b.shieldsAreUp() { if !b.shouldUploadServices() {
// No local services are available, since ShieldsUp will block
// them all.
hi2.Services = []tailcfg.Service{} hi2.Services = []tailcfg.Service{}
} }

View File

@ -665,6 +665,10 @@ type MapResponse struct {
// forms are coming later. // forms are coming later.
Domain string Domain string
// CollectServices reports whether this node's Tailnet has
// requested that info about services be included in HostInfo.
CollectServices bool `json:",omitempty"`
// PacketFilter are the firewall rules. // PacketFilter are the firewall rules.
// //
// For MapRequest.Version >= 6, a nil value means the most // For MapRequest.Version >= 6, a nil value means the most