diff --git a/lib/config/configuration.go b/lib/config/configuration.go index ac7e1bb382022..86ea3f3fa1954 100644 --- a/lib/config/configuration.go +++ b/lib/config/configuration.go @@ -1277,16 +1277,23 @@ func applySSHConfig(fc *FileConfig, cfg *servicecfg.Config) (err error) { // getInstallerProxyAddr determines the address of the proxy for discovered // nodes to connect to. func getInstallerProxyAddr(installParams *InstallParams, fc *FileConfig) string { + // Explicit proxy address. if installParams != nil && installParams.PublicProxyAddr != "" { return installParams.PublicProxyAddr } + // Proxy address from config. if fc.ProxyServer != "" { return fc.ProxyServer } if fc.Proxy.Enabled() && len(fc.Proxy.PublicAddr) > 0 { return fc.Proxy.PublicAddr[0] } - return "" + // Possible proxy address for v1/v2 config. + if len(fc.AuthServers) > 0 { + return fc.AuthServers[0] + } + // Probably not a proxy address, but we have nothing better. + return fc.AuthServer } func applyDiscoveryConfig(fc *FileConfig, cfg *servicecfg.Config) error { diff --git a/lib/config/configuration_test.go b/lib/config/configuration_test.go index 877b95e8f58a2..93af69aebc0cb 100644 --- a/lib/config/configuration_test.go +++ b/lib/config/configuration_test.go @@ -4117,3 +4117,79 @@ func TestApplyKubeConfig(t *testing.T) { }) } } + +func TestGetInstallerProxyAddr(t *testing.T) { + t.Parallel() + tests := []struct { + name string + installParams *InstallParams + fc *FileConfig + expectedProxyAddr string + }{ + { + name: "empty", + fc: &FileConfig{}, + expectedProxyAddr: "", + }, + { + name: "explicit proxy addr", + installParams: &InstallParams{ + PublicProxyAddr: "explicit.example.com", + }, + fc: &FileConfig{ + Global: Global{ + ProxyServer: "proxy.example.com", + }, + }, + expectedProxyAddr: "explicit.example.com", + }, + { + name: "proxy server", + fc: &FileConfig{ + Global: Global{ + ProxyServer: "proxy.example.com", + }, + }, + expectedProxyAddr: "proxy.example.com", + }, + { + name: "local proxy service", + fc: &FileConfig{ + Global: Global{ + AuthServer: "auth.example.com", + }, + Proxy: Proxy{ + Service: Service{ + EnabledFlag: "yes", + }, + PublicAddr: apiutils.Strings{"proxy.example.com"}, + }, + }, + expectedProxyAddr: "proxy.example.com", + }, + { + name: "v1/v2 auth servers", + fc: &FileConfig{ + Version: "v2", + Global: Global{ + AuthServers: []string{"proxy.example.com"}, + }, + }, + expectedProxyAddr: "proxy.example.com", + }, + { + name: "auth server", + fc: &FileConfig{ + Global: Global{ + AuthServer: "auth.example.com", + }, + }, + expectedProxyAddr: "auth.example.com", + }, + } + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + assert.Equal(t, tc.expectedProxyAddr, getInstallerProxyAddr(tc.installParams, tc.fc)) + }) + } +}