Skip to content
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

Add teleport-update binary scaffolding and disable command #46418

Merged
merged 28 commits into from
Oct 10, 2024

Conversation

sclevine
Copy link
Member

@sclevine sclevine commented Sep 10, 2024

This PR contains scaffolding and config file management for the teleport-update binary described by #40190.

The teleport-update binary will be used to enable, disable, and trigger automatic Teleport agent updates. The new auto-updates system manages a local installation of the cluster-specified version of Teleport stored in /var/lib/teleport/versions.

This is the first in a series of PRs extracted and tested from this proof-of-concept: #46357

The disable command is not useful without enable, but it is implemented to drive out configuration management.

RFD: #47126
Goal (internal): https://github.com/gravitational/cloud/issues/10289

Example:

root@71aeb39eabec:/# cat /var/lib/teleport/versions/updates.yaml
version: v1
kind: updates
spec:
    proxy: example.com
    group: ""
    url_template: ""
    enabled: true
    active_version: 16.2.0
root@71aeb39eabec:/# ./teleport/teleport-update disable
root@71aeb39eabec:/# ./teleport/teleport-update disable
2024-09-10T01:19:16Z INFO [UPDATER]   Automatic updates already disabled teleport-update/main.go:272
root@71aeb39eabec:/# cat /var/lib/teleport/versions/updates.yaml
version: v1
kind: updates
spec:
    proxy: example.com
    group: ""
    url_template: ""
    enabled: false
    active_version: 16.2.0
root@71aeb39eabec:/# rm /var/lib/teleport/versions/updates.yaml
root@71aeb39eabec:/# ./teleport/teleport-update disable
2024-09-10T01:20:18Z INFO [UPDATER]   Automatic updates already disabled teleport-update/main.go:272

Copy link

The PR changelog entry failed validation: Changelog entry not found in the PR body. Please add a "no-changelog" label to the PR, or changelog lines starting with changelog: followed by the changelog entries for the PR.

@sclevine sclevine added the no-changelog Indicates that a PR does not require a changelog entry label Sep 10, 2024
@espadolini
Copy link
Contributor

AFAIK there were some concerns about new binaries that had a name that had teleport as a prefix in our build process. cc @fheinecke

tool/teleport-update/main.go Outdated Show resolved Hide resolved
tool/teleport-update/main.go Outdated Show resolved Hide resolved
tool/teleport-update/main.go Outdated Show resolved Hide resolved
tool/teleport-update/main.go Outdated Show resolved Hide resolved
Proxy: func(req *http.Request) (*url.URL, error) {
return httpproxy.FromEnvironment().ProxyFunc()(req.URL)
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we gain much from using x/net/http/httpproxy over just http.ProxyFromEnvironment?

Copy link
Member Author

@sclevine sclevine Sep 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied the webclient for consistency:

func newWebClient(cfg *Config) (*http.Client, error) {
if err := cfg.CheckAndSetDefaults(); err != nil {
return nil, trace.Wrap(err)
}
rt := utils.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: defaults.DefaultIOTimeout,
}, nil)
return &http.Client{
Transport: tracehttp.NewTransport(rt),
Timeout: cfg.Timeout,
}, nil
}

Would you prefer I use http.ProxyFromEnvironment instead?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should definitely update the webclient too, that's quite inefficient - the standard library uses a sync.Once to store the returned ProxyFunc() from the vendored copy of x/net/http/httpproxy.

FWIW I would just take the lib/defaults.Transport() and add the TLSClientConfig to it unless there's a reason to avoid that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The webclient uses tracehttp -- should I avoid that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switched to the defaults transport to merge -- let me know if I should bring tracehttp back in the future. Not sure If we need the telemetry provided by that package.

tool/teleport-update/main.go Outdated Show resolved Hide resolved

app := libutils.InitCLIParser("teleport-updater", appHelp).Interspersed(false)
app.Flag("debug", "Verbose logging to stdout.").Short('d').BoolVar(&ccfg.Debug)
app.Flag("data-dir", "Directory to store teleport versions. Access to this directory should be limited.").StringVar(&ccfg.DataDir)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer the config file to be an option (containing the path to a data dir) rather than the data dir being an option and the config file being in a fixed position in the data dir, but that's sort of a matter of style.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From an end-user perspective, this should always be the equivalent of /var/lib/teleport. Users shouldn't have to worry about multiple data directories. The directory is shared with Teleport, because there is (limited) interaction between the tools (e.g., DB backups, host UUID)

Additionally, the data directory contains more than just the config file (e.g., teleport versions, DB backups, DB metadata files).

@fheinecke
Copy link
Contributor

Thanks for catching this @espadolini. It's probably not a huge issue here if we throughly test all releases and processes (dev workflows, releases, etc.) first. I was apprehensive about this with fdpass because we were on a very fast timetable and it added unnecessary risk.

@sclevine
Copy link
Member Author

sclevine commented Oct 8, 2024

@hugoShaka mind giving this another review?

@sclevine sclevine force-pushed the sclevine/teleport-update-scaffold branch from 3e7b2e2 to 02476f1 Compare October 8, 2024 02:24
tool/teleport-update/main.go Show resolved Hide resolved
@sclevine
Copy link
Member Author

sclevine commented Oct 9, 2024

Looking for an additional review 🙂

tool/teleport-update/main.go Show resolved Hide resolved
Proxy: func(req *http.Request) (*url.URL, error) {
return httpproxy.FromEnvironment().ProxyFunc()(req.URL)
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should definitely update the webclient too, that's quite inefficient - the standard library uses a sync.Once to store the returned ProxyFunc() from the vendored copy of x/net/http/httpproxy.

FWIW I would just take the lib/defaults.Transport() and add the TLSClientConfig to it unless there's a reason to avoid that.

@sclevine sclevine force-pushed the sclevine/teleport-update-scaffold branch from 1c1e7d5 to 9cfde07 Compare October 10, 2024 18:35
@sclevine sclevine added this pull request to the merge queue Oct 10, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 10, 2024
@sclevine sclevine added this pull request to the merge queue Oct 10, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 10, 2024
@sclevine sclevine added this pull request to the merge queue Oct 10, 2024
Merged via the queue into master with commit aae732a Oct 10, 2024
41 checks passed
@sclevine sclevine deleted the sclevine/teleport-update-scaffold branch October 10, 2024 19:44
mvbrock pushed a commit that referenced this pull request Oct 16, 2024
* Add main.go

* wip

* group flag

* wip

* wip

* mvp

* wip

* separate files

* cleanup

* jitter

* scaffold only

* remove teleport changes

* remove teleport changes - group

* test

* test lock

* remove edition

* feedback

* clarify default data dir

* cleanup

* move version to status

* consistent naming for update.yaml

* improve lock test

* explain lint

* use shared locking logic

* fix test

* Move disable logic to lib

* feedback

* switch to default transport
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-changelog Indicates that a PR does not require a changelog entry size/md
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants