Skip to content

Commit

Permalink
cmd/tailscale,ipn: add auto-update flag and pref
Browse files Browse the repository at this point in the history
The flag is hidden and a noop for now. Adding propagation to tailscaled
and persistence only.

Updates #6907

Signed-off-by: Andrew Lytvynov <awly@tailscale.com>
  • Loading branch information
awly committed Aug 11, 2023
1 parent c40d095 commit 19dcf91
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions cmd/tailscale/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,7 @@ func TestUpdatePrefs(t *testing.T) {
AdvertiseRoutesSet: true,
AdvertiseTagsSet: true,
AllowSingleHostsSet: true,
AutoUpdatesSet: true,
ControlURLSet: true,
CorpDNSSet: true,
ExitNodeAllowLANAccessSet: true,
Expand Down
6 changes: 6 additions & 0 deletions cmd/tailscale/cli/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ func newUpFlagSet(goos string, upArgs *upArgsT, cmd string) *flag.FlagSet {
upf.StringVar(&upArgs.hostname, "hostname", "", "hostname to use instead of the one provided by the OS")
upf.StringVar(&upArgs.advertiseRoutes, "advertise-routes", "", "routes to advertise to other nodes (comma-separated, e.g. \"10.0.0.0/8,192.168.0.0/24\") or empty string to not advertise routes")
upf.BoolVar(&upArgs.advertiseDefaultRoute, "advertise-exit-node", false, "offer to be an exit node for internet traffic for the tailnet")
upf.BoolVar(&upArgs.autoUpdates, "auto-updates", false, "HIDDEN: automatically update to the latest available version in the background")
if safesocket.GOOSUsesPeerCreds(goos) {
upf.StringVar(&upArgs.opUser, "operator", "", "Unix username to allow to operate on tailscaled without sudo")
}
Expand Down Expand Up @@ -171,6 +172,7 @@ type upArgsT struct {
timeout time.Duration
acceptedRisks string
profileName string
autoUpdates bool
}

func (a upArgsT) getAuthKey() (string, error) {
Expand Down Expand Up @@ -280,6 +282,7 @@ func prefsFromUpArgs(upArgs upArgsT, warnf logger.Logf, st *ipnstate.Status, goo
prefs.ForceDaemon = upArgs.forceDaemon
prefs.OperatorUser = upArgs.opUser
prefs.ProfileName = upArgs.profileName
prefs.AutoUpdates = upArgs.autoUpdates

if goos == "linux" {
prefs.NoSNAT = !upArgs.snat
Expand Down Expand Up @@ -712,6 +715,7 @@ func init() {
addPrefFlagMapping("operator", "OperatorUser")
addPrefFlagMapping("ssh", "RunSSH")
addPrefFlagMapping("nickname", "ProfileName")
addPrefFlagMapping("auto-updates", "AutoUpdates")
}

func addPrefFlagMapping(flagName string, prefNames ...string) {
Expand Down Expand Up @@ -952,6 +956,8 @@ func prefsToFlags(env upCheckEnv, prefs *ipn.Prefs) (flagVal map[string]any) {
set(prefs.NetfilterMode.String())
case "unattended":
set(prefs.ForceDaemon)
case "auto-updates":
set(prefs.AutoUpdates)
}
})
return ret
Expand Down
1 change: 1 addition & 0 deletions ipn/ipn_clone.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions ipn/ipn_view.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion ipn/prefs.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ type Prefs struct {
// and CLI.
ProfileName string `json:",omitempty"`

// AutoUpdates specifies whether background auto-updates are enabled. When
// enabled, tailscaled will periodically check for available updates and
// apply them.
AutoUpdates bool

// The Persist field is named 'Config' in the file for backward
// compatibility with earlier versions.
// TODO(apenwarr): We should move this out of here, it's not a pref.
Expand Down Expand Up @@ -228,6 +233,7 @@ type MaskedPrefs struct {
NetfilterModeSet bool `json:",omitempty"`
OperatorUserSet bool `json:",omitempty"`
ProfileNameSet bool `json:",omitempty"`
AutoUpdatesSet bool `json:",omitempty"`
}

// ApplyEdits mutates p, assigning fields from m.Prefs for each MaskedPrefs
Expand Down Expand Up @@ -333,6 +339,9 @@ func (p *Prefs) pretty(goos string) string {
if p.ShieldsUp {
sb.WriteString("shields=true ")
}
if p.AutoUpdates {
sb.WriteString("autoUpdates=true ")
}
if p.ExitNodeIP.IsValid() {
fmt.Fprintf(&sb, "exit=%v lan=%t ", p.ExitNodeIP, p.ExitNodeAllowLANAccess)
} else if !p.ExitNodeID.IsZero() {
Expand Down Expand Up @@ -413,7 +422,8 @@ func (p *Prefs) Equals(p2 *Prefs) bool {
compareIPNets(p.AdvertiseRoutes, p2.AdvertiseRoutes) &&
compareStrings(p.AdvertiseTags, p2.AdvertiseTags) &&
p.Persist.Equals(p2.Persist) &&
p.ProfileName == p2.ProfileName
p.ProfileName == p2.ProfileName &&
p.AutoUpdates == p2.AutoUpdates
}

func compareIPNets(a, b []netip.Prefix) bool {
Expand Down
11 changes: 11 additions & 0 deletions ipn/prefs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func TestPrefsEqual(t *testing.T) {
"NetfilterMode",
"OperatorUser",
"ProfileName",
"AutoUpdates",
"Persist",
}
if have := fieldsOf(reflect.TypeOf(Prefs{})); !reflect.DeepEqual(have, prefsHandles) {
Expand Down Expand Up @@ -288,6 +289,16 @@ func TestPrefsEqual(t *testing.T) {
&Prefs{ProfileName: "home"},
false,
},
{
&Prefs{AutoUpdates: true},
&Prefs{AutoUpdates: false},
false,
},
{
&Prefs{AutoUpdates: true},
&Prefs{AutoUpdates: true},
true,
},
}
for i, tt := range tests {
got := tt.a.Equals(tt.b)
Expand Down

0 comments on commit 19dcf91

Please sign in to comment.