Skip to content

Commit

Permalink
Reuse insecure flag for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vapopov committed Oct 25, 2024
1 parent 4edd36a commit 9f6c224
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion integration/autoupdate/tools/updater/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ var (
)

func main() {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
ctx, _ = signal.NotifyContext(ctx, syscall.SIGINT, syscall.SIGTERM)

Expand Down
3 changes: 2 additions & 1 deletion lib/autoupdate/tools/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func (u *Updater) CheckLocal() (version string, reExec bool, err error) {
// the `webapi/find` handler, which stores information about the required client tools version to
// operate with this cluster. It returns the semantic version that needs updating and whether
// re-execution is necessary, by re-execution flag we understand that update and re-execute is required.
func (u *Updater) CheckRemote(ctx context.Context, proxyAddr string) (version string, reExec bool, err error) {
func (u *Updater) CheckRemote(ctx context.Context, proxyAddr string, insecure bool) (version string, reExec bool, err error) {
// Check if the user has requested a specific version of client tools.
requestedVersion := os.Getenv(teleportToolsVersionEnv)
switch requestedVersion {
Expand Down Expand Up @@ -179,6 +179,7 @@ func (u *Updater) CheckRemote(ctx context.Context, proxyAddr string) (version st
ProxyAddr: proxyAddr,
Pool: certPool,
Timeout: 30 * time.Second,
Insecure: insecure,
})
if err != nil {
return "", false, trace.Wrap(err)
Expand Down
2 changes: 1 addition & 1 deletion lib/client/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ func RetryWithRelogin(ctx context.Context, tc *TeleportClient, fn func() error,
return trace.Wrap(err)
}
updater := tools.NewUpdater(tools.DefaultClientTools(), toolsDir, teleport.Version)
toolsVersion, reExec, err := updater.CheckRemote(ctx, tc.WebProxyAddr)
toolsVersion, reExec, err := updater.CheckRemote(ctx, tc.WebProxyAddr, tc.InsecureSkipVerify)
if err != nil {
return trace.Wrap(err)
}
Expand Down
12 changes: 6 additions & 6 deletions tool/tsh/common/tsh.go
Original file line number Diff line number Diff line change
Expand Up @@ -1878,7 +1878,7 @@ func onLogin(cf *CLIConf) error {
// The user is not logged in and has typed in `tsh --proxy=... login`, if
// the running binary needs to be updated, update and re-exec.
if profile == nil {
if err := updateAndRun(cf.Context, tc.WebProxyAddr); err != nil {
if err := updateAndRun(cf.Context, tc.WebProxyAddr, tc.InsecureSkipVerify); err != nil {
return trace.Wrap(err)
}
}
Expand All @@ -1896,7 +1896,7 @@ func onLogin(cf *CLIConf) error {

// The user has typed `tsh login`, if the running binary needs to
// be updated, update and re-exec.
if err := updateAndRun(cf.Context, tc.WebProxyAddr); err != nil {
if err := updateAndRun(cf.Context, tc.WebProxyAddr, tc.InsecureSkipVerify); err != nil {
return trace.Wrap(err)
}

Expand All @@ -1916,7 +1916,7 @@ func onLogin(cf *CLIConf) error {

// The user has typed `tsh login`, if the running binary needs to
// be updated, update and re-exec.
if err := updateAndRun(cf.Context, tc.WebProxyAddr); err != nil {
if err := updateAndRun(cf.Context, tc.WebProxyAddr, tc.InsecureSkipVerify); err != nil {
return trace.Wrap(err)
}

Expand Down Expand Up @@ -1992,7 +1992,7 @@ func onLogin(cf *CLIConf) error {
default:
// The user is logged in and has typed in `tsh --proxy=... login`, if
// the running binary needs to be updated, update and re-exec.
if err := updateAndRun(context.Background(), tc.WebProxyAddr); err != nil {
if err := updateAndRun(context.Background(), tc.WebProxyAddr, tc.InsecureSkipVerify); err != nil {
return trace.Wrap(err)
}
}
Expand Down Expand Up @@ -5558,7 +5558,7 @@ const (
"https://goteleport.com/docs/access-controls/guides/headless/#troubleshooting"
)

func updateAndRun(ctx context.Context, proxy string) error {
func updateAndRun(ctx context.Context, proxy string, insecure bool) error {
// The user has typed a command like `tsh ssh ...` without being logged in,
// if the running binary needs to be updated, update and re-exec.
//
Expand All @@ -5570,7 +5570,7 @@ func updateAndRun(ctx context.Context, proxy string) error {
return trace.Wrap(err)
}
updater := tools.NewUpdater(tools.DefaultClientTools(), toolsDir, teleport.Version)
toolsVersion, reExec, err := updater.CheckRemote(ctx, proxy)
toolsVersion, reExec, err := updater.CheckRemote(ctx, proxy, insecure)
if err != nil {
return trace.Wrap(err)
}
Expand Down

0 comments on commit 9f6c224

Please sign in to comment.