ipn: another controlplane synonym

This one doesn't bother me so much, as long term we want a synonym here.

Fixes #2384
Fixes #2386

Signed-off-by: David Crawshaw <crawshaw@tailscale.com>
This commit is contained in:
David Crawshaw 2021-07-11 21:46:50 -07:00 committed by David Crawshaw
parent 4c0494185b
commit 87481282eb
4 changed files with 39 additions and 11 deletions

View File

@ -735,7 +735,7 @@ func TestUpdatePrefs(t *testing.T) {
wantSimpleUp: true, wantSimpleUp: true,
wantJustEditMP: &ipn.MaskedPrefs{WantRunningSet: true}, wantJustEditMP: &ipn.MaskedPrefs{WantRunningSet: true},
}, },
/* TODO(crawshaw): fix, #2384 { {
name: "control_synonym", name: "control_synonym",
flags: []string{}, flags: []string{},
curPrefs: &ipn.Prefs{ curPrefs: &ipn.Prefs{
@ -745,7 +745,22 @@ func TestUpdatePrefs(t *testing.T) {
env: upCheckEnv{backendState: "Running"}, env: upCheckEnv{backendState: "Running"},
wantSimpleUp: true, wantSimpleUp: true,
wantJustEditMP: &ipn.MaskedPrefs{WantRunningSet: true}, wantJustEditMP: &ipn.MaskedPrefs{WantRunningSet: true},
},*/ },
{
name: "change_login_server",
flags: []string{"--login-server=https://localhost:1000"},
curPrefs: &ipn.Prefs{
ControlURL: "https://login.tailscale.com",
Persist: &persist.Persist{LoginName: "crawshaw.github"},
AllowSingleHosts: true,
CorpDNS: true,
NetfilterMode: preftype.NetfilterOn,
},
env: upCheckEnv{backendState: "Running"},
wantSimpleUp: true,
wantJustEditMP: &ipn.MaskedPrefs{WantRunningSet: true},
wantErrSubtr: "can't change --login-server without --force-reauth",
},
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {

View File

@ -259,7 +259,8 @@ func updatePrefs(prefs, curPrefs *ipn.Prefs, env upCheckEnv) (simpleUp bool, jus
} }
} }
controlURLChanged := curPrefs.ControlURL != prefs.ControlURL controlURLChanged := curPrefs.ControlURL != prefs.ControlURL &&
!(ipn.IsLoginServerSynonym(curPrefs.ControlURL) && ipn.IsLoginServerSynonym(prefs.ControlURL))
if controlURLChanged && env.backendState == ipn.Running.String() && !env.upArgs.forceReauth { if controlURLChanged && env.backendState == ipn.Running.String() && !env.upArgs.forceReauth {
return false, nil, fmt.Errorf("can't change --login-server without --force-reauth") return false, nil, fmt.Errorf("can't change --login-server without --force-reauth")
} }
@ -399,7 +400,7 @@ func runUp(ctx context.Context, args []string) error {
startLoginInteractive() startLoginInteractive()
case ipn.NeedsMachineAuth: case ipn.NeedsMachineAuth:
printed = true printed = true
fmt.Fprintf(os.Stderr, "\nTo authorize your machine, visit (as admin):\n\n\t%s/admin/machines\n\n", upArgs.server) fmt.Fprintf(os.Stderr, "\nTo authorize your machine, visit (as admin):\n\n\t%s\n\n", prefs.AdminPageURL())
case ipn.Starting, ipn.Running: case ipn.Starting, ipn.Running:
// Done full authentication process // Done full authentication process
if printed { if printed {
@ -608,7 +609,7 @@ func checkForAccidentalSettingReverts(newPrefs, curPrefs *ipn.Prefs, env upCheck
if reflect.DeepEqual(valCur, valNew) { if reflect.DeepEqual(valCur, valNew) {
continue continue
} }
if flagName == "login-server" && isLoginServerSynonym(valCur) && isLoginServerSynonym(valNew) { if flagName == "login-server" && ipn.IsLoginServerSynonym(valCur) && ipn.IsLoginServerSynonym(valNew) {
continue continue
} }
missing = append(missing, fmtFlagValueArg(flagName, valCur)) missing = append(missing, fmtFlagValueArg(flagName, valCur))
@ -657,10 +658,6 @@ func applyImplicitPrefs(prefs, oldPrefs *ipn.Prefs, curUser string) {
} }
} }
func isLoginServerSynonym(val interface{}) bool {
return val == "https://login.tailscale.com" || val == "https://controlplane.tailscale.com"
}
func flagAppliesToOS(flag, goos string) bool { func flagAppliesToOS(flag, goos string) bool {
switch flag { switch flag {
case "netfilter-mode", "snat-subnet-routes": case "netfilter-mode", "snat-subnet-routes":

View File

@ -156,7 +156,7 @@ func (h *Handle) Expiry() time.Time {
} }
func (h *Handle) AdminPageURL() string { func (h *Handle) AdminPageURL() string {
return h.prefsCache.ControlURLOrDefault() + "/admin/machines" return h.prefsCache.AdminPageURL()
} }
func (h *Handle) StartLoginInteractive() { func (h *Handle) StartLoginInteractive() {

View File

@ -25,11 +25,17 @@
//go:generate go run tailscale.com/cmd/cloner -type=Prefs -output=prefs_clone.go //go:generate go run tailscale.com/cmd/cloner -type=Prefs -output=prefs_clone.go
// DefaultControlURL returns the URL base of the control plane // DefaultControlURL is the URL base of the control plane
// ("coordination server") for use when no explicit one is configured. // ("coordination server") for use when no explicit one is configured.
// The default control plane is the hosted version run by Tailscale.com. // The default control plane is the hosted version run by Tailscale.com.
const DefaultControlURL = "https://controlplane.tailscale.com" const DefaultControlURL = "https://controlplane.tailscale.com"
// IsLoginServerSynonym reports whether a URL is a drop-in replacement
// for the primary Tailscale login server.
func IsLoginServerSynonym(val interface{}) bool {
return val == "https://login.tailscale.com" || val == "https://controlplane.tailscale.com"
}
// Prefs are the user modifiable settings of the Tailscale node agent. // Prefs are the user modifiable settings of the Tailscale node agent.
type Prefs struct { type Prefs struct {
// ControlURL is the URL of the control server to use. // ControlURL is the URL of the control server to use.
@ -405,6 +411,16 @@ func (p *Prefs) ControlURLOrDefault() string {
return DefaultControlURL return DefaultControlURL
} }
// AdminPageURL returns the admin web site URL for the current ControlURL.
func (p *Prefs) AdminPageURL() string {
url := p.ControlURLOrDefault()
if IsLoginServerSynonym(url) {
// TODO(crawshaw): In future release, make this https://console.tailscale.com
url = "https://login.tailscale.com"
}
return url + "/admin/machines"
}
// PrefsFromBytes deserializes Prefs from a JSON blob. If // PrefsFromBytes deserializes Prefs from a JSON blob. If
// enforceDefaults is true, Prefs.RouteAll and Prefs.AllowSingleHosts // enforceDefaults is true, Prefs.RouteAll and Prefs.AllowSingleHosts
// are forced on. // are forced on.