-
Notifications
You must be signed in to change notification settings - Fork 2.1k
[teleport-update] Version reporting and deprecated upgrader management #50266
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
Merged
+411
−48
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
e2d79a4
wip
sclevine 9b85e0f
telemetry
sclevine d97c35a
abs
sclevine ab5fecf
fix
sclevine 78d047a
tests
sclevine 0c36daa
Disable deprecated timer
sclevine b6fee98
keep schedule on non-suffixed
sclevine 1eb891a
Update maintenance.go
sclevine 1f32dd0
Update lib/autoupdate/agent/setup.go
sclevine 84555ff
update warnings
sclevine 6686d64
feedback pt 1
sclevine 1c47493
feedback pt 2
sclevine 2279845
headers
sclevine 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
|
sclevine marked this conversation as resolved.
|
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) 2025 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 agent | ||
|
|
||
| import ( | ||
| "os" | ||
| "path/filepath" | ||
| "strings" | ||
|
|
||
| "github.com/gravitational/trace" | ||
| ) | ||
|
|
||
| // IsManagedByUpdater returns true if the local Teleport binary is managed by teleport-update. | ||
| // Note that true may be returned even if auto-updates is disabled or the version is pinned. | ||
| // The binary is considered managed if it lives under /opt/teleport, but not within the package | ||
|
codingllama marked this conversation as resolved.
|
||
| // path at /opt/teleport/system. | ||
| func IsManagedByUpdater() (bool, error) { | ||
| teleportPath, err := os.Readlink("/proc/self/exe") | ||
| if err != nil { | ||
| return false, trace.Wrap(err, "cannot find Teleport binary") | ||
| } | ||
| // Check if current binary is under the updater-managed path. | ||
| managed, err := hasParentDir(teleportPath, teleportOptDir) | ||
| if err != nil { | ||
| return false, trace.Wrap(err) | ||
| } | ||
| if !managed { | ||
| return false, nil | ||
| } | ||
| // Return false if the binary is under the updater-managed path, but in the system prefix reserved for the package. | ||
| system, err := hasParentDir(teleportPath, filepath.Join(teleportOptDir, systemNamespace)) | ||
| return !system, err | ||
| } | ||
|
|
||
| // IsManagedAndDefault returns true if the local Teleport binary is both managed by teleport-update | ||
| // and the default installation (with teleport.service as the unit file name). | ||
| // The binary is considered managed and default if it lives within /opt/teleport/default. | ||
| func IsManagedAndDefault() (bool, error) { | ||
| teleportPath, err := os.Readlink("/proc/self/exe") | ||
| if err != nil { | ||
| return false, trace.Wrap(err, "cannot find Teleport binary") | ||
| } | ||
| return hasParentDir(teleportPath, filepath.Join(teleportOptDir, defaultNamespace)) | ||
| } | ||
|
|
||
| // hasParentDir returns true if dir is any parent directory of parent. | ||
| // hasParentDir does not resolve symlinks, and requires that files be represented the same way in dir and parent. | ||
| func hasParentDir(dir, parent string) (bool, error) { | ||
| // Note that os.Stat + os.SameFile would be more reliable, | ||
| // but does not work well for arbitrarily nested subdirectories. | ||
| absDir, err := filepath.Abs(dir) | ||
| if err != nil { | ||
| return false, trace.Wrap(err, "cannot get absolute path for directory %s", dir) | ||
| } | ||
| absParent, err := filepath.Abs(parent) | ||
| if err != nil { | ||
| return false, trace.Wrap(err, "cannot get absolute path for parent directory %s", dir) | ||
| } | ||
| sep := string(filepath.Separator) | ||
| if !strings.HasSuffix(absParent, sep) { | ||
| absParent += sep | ||
| } | ||
| return strings.HasPrefix(absDir, absParent), nil | ||
| } | ||
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,109 @@ | ||
| /* | ||
| * Teleport | ||
| * Copyright (C) 2025 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 agent | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestHasParentDir(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| path string | ||
| parent string | ||
| wantResult bool | ||
| }{ | ||
| { | ||
| name: "Has valid parent directory", | ||
| path: "/opt/teleport/dir/test", | ||
| parent: "/opt/teleport", | ||
| wantResult: true, | ||
| }, | ||
| { | ||
| name: "Has valid parent directory with slash", | ||
| path: "/opt/teleport/dir/test", | ||
| parent: "/opt/teleport/", | ||
| wantResult: true, | ||
| }, | ||
| { | ||
| name: "Parent directory is root", | ||
| path: "/opt/teleport/dir", | ||
| parent: "/", | ||
| wantResult: true, | ||
| }, | ||
| { | ||
| name: "Parent is the same as the path", | ||
| path: "/opt/teleport/dir", | ||
| parent: "/opt/teleport/dir", | ||
| wantResult: false, | ||
| }, | ||
| { | ||
| name: "Parent the same as the path but without slash", | ||
| path: "/opt/teleport/dir/", | ||
| parent: "/opt/teleport/dir", | ||
| wantResult: false, | ||
| }, | ||
| { | ||
| name: "Parent the same as the path but with slash", | ||
| path: "/opt/teleport/dir", | ||
| parent: "/opt/teleport/dir/", | ||
| wantResult: false, | ||
| }, | ||
| { | ||
| name: "Parent is substring of the path", | ||
| path: "/opt/teleport/dir-place", | ||
| parent: "/opt/teleport/dir", | ||
| wantResult: false, | ||
| }, | ||
| { | ||
| name: "Parent is in path", | ||
| path: "/opt/teleport", | ||
| parent: "/opt/teleport/dir", | ||
| wantResult: false, | ||
| }, | ||
| { | ||
| name: "Empty parent", | ||
| path: "/opt/teleport/dir", | ||
| parent: "", | ||
| wantResult: false, | ||
| }, | ||
| { | ||
| name: "Empty path", | ||
| path: "", | ||
| parent: "/opt/teleport", | ||
| wantResult: false, | ||
| }, | ||
| { | ||
| name: "Both empty", | ||
| path: "", | ||
| parent: "", | ||
| wantResult: false, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| result, err := hasParentDir(tt.path, tt.parent) | ||
| require.NoError(t, err) | ||
| require.Equal(t, tt.wantResult, result) | ||
| }) | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.