-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Client tools auto update logic for multiple platforms #46587
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| /* | ||
| * Teleport | ||
| * Copyright (C) 2024 Gravitational, Inc. | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| package update | ||
|
|
||
| import ( | ||
| "crypto/tls" | ||
| "crypto/x509" | ||
| "net/http" | ||
| "net/url" | ||
| "time" | ||
|
|
||
| "golang.org/x/net/http/httpproxy" | ||
|
|
||
| apidefaults "github.com/gravitational/teleport/api/defaults" | ||
| tracehttp "github.com/gravitational/teleport/api/observability/tracing/http" | ||
| apiutils "github.com/gravitational/teleport/api/utils" | ||
| ) | ||
|
|
||
| type downloadConfig struct { | ||
| // Insecure turns off TLS certificate verification when enabled. | ||
| Insecure bool | ||
| // Pool defines the set of root CAs to use when verifying server | ||
| // certificates. | ||
| Pool *x509.CertPool | ||
| // Timeout is a timeout for requests. | ||
| Timeout time.Duration | ||
| } | ||
|
|
||
| func newClient(cfg *downloadConfig) *http.Client { | ||
| rt := apiutils.NewHTTPRoundTripper(&http.Transport{ | ||
| TLSClientConfig: &tls.Config{ | ||
| InsecureSkipVerify: cfg.Insecure, | ||
| RootCAs: cfg.Pool, | ||
| }, | ||
| Proxy: func(req *http.Request) (*url.URL, error) { | ||
| return httpproxy.FromEnvironment().ProxyFunc()(req.URL) | ||
| }, | ||
| IdleConnTimeout: apidefaults.DefaultIOTimeout, | ||
| }, nil) | ||
|
|
||
| return &http.Client{ | ||
| Transport: tracehttp.NewTransport(rt), | ||
| Timeout: cfg.Timeout, | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| //go:build webassets_ent | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be better to introduce new build tag for enterprise version instead of reusing this one for web assets? |
||
| // +build webassets_ent | ||
|
|
||
| /* | ||
| * Teleport | ||
| * Copyright (C) 2024 Gravitational, Inc. | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| package update | ||
|
|
||
| func init() { | ||
| featureFlag |= FlagEnt | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| //go:build fips | ||
| // +build fips | ||
|
|
||
| /* | ||
| * Teleport | ||
| * Copyright (C) 2024 Gravitational, Inc. | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| package update | ||
|
|
||
| func init() { | ||
| featureFlag |= FlagFips | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| /* | ||
| * Teleport | ||
| * Copyright (C) 2024 Gravitational, Inc. | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| package main | ||
|
|
||
| import ( | ||
| "errors" | ||
| "fmt" | ||
| "os" | ||
|
|
||
| log "github.com/sirupsen/logrus" | ||
|
|
||
| "github.com/gravitational/teleport/tool/common/update" | ||
| ) | ||
|
|
||
| var version = "development" | ||
|
|
||
| func main() { | ||
| // At process startup, check if a version has already been downloaded to | ||
| // $TELEPORT_HOME/bin or if the user has set the TELEPORT_TOOLS_VERSION | ||
| // environment variable. If so, re-exec that version of {tsh, tctl}. | ||
| toolsVersion, reExec := update.CheckLocal() | ||
| if reExec { | ||
| // Download the version of client tools required by the cluster. This | ||
| // is required if the user passed in the TELEPORT_TOOLS_VERSION | ||
| // explicitly. | ||
| err := update.Download(toolsVersion) | ||
| if errors.Is(err, update.ErrCanceled) { | ||
| os.Exit(0) | ||
| return | ||
| } | ||
| if err != nil { | ||
| log.Fatalf("Failed to download version (%v): %v", toolsVersion, err) | ||
| return | ||
| } | ||
|
|
||
| // Re-execute client tools with the correct version of client tools. | ||
| code, err := update.Exec() | ||
| if err != nil { | ||
| log.Fatalf("Failed to re-exec client tool: %v", err) | ||
| } else { | ||
| os.Exit(code) | ||
| } | ||
| } | ||
| if len(os.Args) > 1 && os.Args[1] == "version" { | ||
| fmt.Printf("Teleport v%v git", version) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| /* | ||
| * Teleport | ||
| * Copyright (C) 2024 Gravitational, Inc. | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| package update | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "io" | ||
| "os" | ||
| "os/signal" | ||
| "strings" | ||
| ) | ||
|
|
||
| var ( | ||
| ErrCanceled = fmt.Errorf("canceled") | ||
| ) | ||
|
|
||
| // cancelableTeeReader is a copy of TeeReader with ability to react on signal notifier | ||
| // to cancel reading process. | ||
| func cancelableTeeReader(r io.Reader, w io.Writer, signals ...os.Signal) io.Reader { | ||
| sigs := make(chan os.Signal, 1) | ||
| signal.Notify(sigs, signals...) | ||
|
|
||
| return &teeReader{r, w, sigs} | ||
| } | ||
|
|
||
| type teeReader struct { | ||
| r io.Reader | ||
| w io.Writer | ||
| sigs chan os.Signal | ||
| } | ||
|
|
||
| func (t *teeReader) Read(p []byte) (n int, err error) { | ||
| select { | ||
| case <-t.sigs: | ||
| return 0, ErrCanceled | ||
| default: | ||
| n, err = t.r.Read(p) | ||
| if n > 0 { | ||
| if n, err := t.w.Write(p[:n]); err != nil { | ||
| return n, err | ||
| } | ||
| } | ||
| } | ||
| return | ||
| } | ||
|
|
||
| type progressWriter struct { | ||
| n int64 | ||
| limit int64 | ||
| } | ||
|
|
||
| func (w *progressWriter) Write(p []byte) (int, error) { | ||
| w.n = w.n + int64(len(p)) | ||
|
|
||
| n := int((w.n*100)/w.limit) / 10 | ||
| bricks := strings.Repeat("▒", n) + strings.Repeat(" ", 10-n) | ||
| fmt.Printf("\rUpdate progress: [" + bricks + "] (Ctrl-C to cancel update)") | ||
|
|
||
| if w.n == w.limit { | ||
| fmt.Printf("\n") | ||
| } | ||
|
|
||
| return len(p), nil | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tool's content should be limited to bootstrapping the CLI and commands. Complex logic should live inlib/.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, will try to split the logic, but it actually interconnected. Locking might be delivered separately, also integration tests kind of heavy. Webclient btw temporally added until this PR is merged