-
Notifications
You must be signed in to change notification settings - Fork 2k
[v18] scope aware tsh profiles #64592
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
Open
williamong-tel
wants to merge
2
commits into
branch/v18
Choose a base branch
from
williamo/v18-scope-aware-tsh-profiles
base: branch/v18
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 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
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,127 @@ | ||
| /* | ||
| * Teleport | ||
| * Copyright (C) 2026 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 common | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
|
|
||
| "github.com/gravitational/teleport/lib/client" | ||
| ) | ||
|
|
||
| func TestResolveDesiredScope(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| cf *CLIConf | ||
| profile *client.ProfileStatus | ||
| wantScope string | ||
| wantScopeChange bool | ||
| }{ | ||
| { | ||
| name: "no flag, no profile -> empty scope, no change", | ||
| cf: &CLIConf{}, | ||
| profile: nil, | ||
| wantScope: "", | ||
| wantScopeChange: false, | ||
| }, | ||
| { | ||
| name: "no flag, unscoped profile -> inherit empty, no change", | ||
| cf: &CLIConf{}, | ||
| profile: &client.ProfileStatus{}, | ||
| wantScope: "", | ||
| wantScopeChange: false, | ||
| }, | ||
| { | ||
| name: "no flag, scoped profile -> inherit scope, no change", | ||
| cf: &CLIConf{}, | ||
| profile: &client.ProfileStatus{Scope: "/staging/west"}, | ||
| wantScope: "/staging/west", | ||
| wantScopeChange: false, | ||
| }, | ||
| { | ||
| name: "explicit scope, no profile -> set scope, changed", | ||
| cf: &CLIConf{ | ||
| Scope: "/staging/east", | ||
| ScopeSetByUser: true, | ||
| }, | ||
| profile: nil, | ||
| wantScope: "/staging/east", | ||
| wantScopeChange: true, | ||
| }, | ||
| { | ||
| name: "explicit scope, unscoped profile -> set scope, changed", | ||
| cf: &CLIConf{ | ||
| Scope: "/staging/east", | ||
| ScopeSetByUser: true, | ||
| }, | ||
| profile: &client.ProfileStatus{}, | ||
| wantScope: "/staging/east", | ||
| wantScopeChange: true, | ||
| }, | ||
| { | ||
| name: "explicit scope, same scoped profile -> same scope, no change", | ||
| cf: &CLIConf{ | ||
| Scope: "/staging/east", | ||
| ScopeSetByUser: true, | ||
| }, | ||
| profile: &client.ProfileStatus{Scope: "/staging/east"}, | ||
| wantScope: "/staging/east", | ||
| wantScopeChange: false, | ||
| }, | ||
| { | ||
| name: "explicit scope, different scoped profile -> new scope, changed", | ||
| cf: &CLIConf{ | ||
| Scope: "/staging/east", | ||
| ScopeSetByUser: true, | ||
| }, | ||
| profile: &client.ProfileStatus{Scope: "/staging/west"}, | ||
| wantScope: "/staging/east", | ||
| wantScopeChange: true, | ||
| }, | ||
| { | ||
| name: "descope with empty string, scoped profile -> empty, changed", | ||
| cf: &CLIConf{ | ||
| Scope: "", | ||
| ScopeSetByUser: true, | ||
| }, | ||
| profile: &client.ProfileStatus{Scope: "/staging/west"}, | ||
| wantScope: "", | ||
| wantScopeChange: true, | ||
| }, | ||
| { | ||
| name: "descope with empty string, unscoped profile -> empty, no change", | ||
| cf: &CLIConf{ | ||
| Scope: "", | ||
| ScopeSetByUser: true, | ||
| }, | ||
| profile: &client.ProfileStatus{Scope: ""}, | ||
| wantScope: "", | ||
| wantScopeChange: false, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| gotScope, gotChanged := resolveScope(tt.cf, tt.profile) | ||
| require.Equal(t, tt.wantScope, gotScope) | ||
| require.Equal(t, tt.wantScopeChange, gotChanged) | ||
| }) | ||
| } | ||
| } |
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
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.
This new guard makes scope-changing logins skip the branch that contains the fallback
autoupdatetools.CheckAndUpdateRemotecall, while the earlierprofile == nilupdate path is also skipped because an unexpired profile exists. In practice,tsh login --scope=/new(or--scope="") from an existing valid session now reauthenticates without any managed update check, which regresses the previous behavior where scoped logins forcedprofile=niland always performed the update check first.Useful? React with 👍 / 👎.