Skip to content

Commit

Permalink
Improve proxy address sourcing for VM auto-discovery (gravitational#3…
Browse files Browse the repository at this point in the history
…0884)

This change adds a few more places for the Discovery service to get
the Teleport cluster's public proxy address for VM discovery.
  • Loading branch information
atburke authored Aug 24, 2023
1 parent 57ad7fc commit 6c1a0d3
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/config/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
76 changes: 76 additions & 0 deletions lib/config/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
}
}

0 comments on commit 6c1a0d3

Please sign in to comment.