Skip to content

[v18] scope aware tsh profiles#64592

Open
williamong-tel wants to merge 2 commits intobranch/v18from
williamo/v18-scope-aware-tsh-profiles
Open

[v18] scope aware tsh profiles#64592
williamong-tel wants to merge 2 commits intobranch/v18from
williamo/v18-scope-aware-tsh-profiles

Conversation

@williamong-tel
Copy link
Contributor

@williamong-tel williamong-tel commented Mar 12, 2026

Backport of #64233

Actual Changes:

Changed references to ScopePin to just Scope in several places. Latest commit contains what needed to change. See adea2a7

Changelog: add scope aware profiles after tsh login

Manual Test Plan

Test Environment

Exercised with multiple teleport clusters locally

Test Cases

  • tsh login --scope - verify that the scopes is persisted in the profiles yaml in the .tsh directory
  • tsh logout & login without the scope removes the scope from the profile
  • relogging in after logging in with a different scope overwrites the scope in the profile
  • After logging into teleport unscoped, running tsh login --scope=/some/scope with no other parameters successfully logs the user into the target scope.
  • After logging into teleport scoped, running tsh login --scope=/some/other/scope with no other parameters successfully switches the user to the new target scope.
  • After logging into teleport scoped, running tsh login --scope=none  and tsh login --scope="" with no other parameters successfully switches the user to unscoped mode.
  • With expired scoped credentials, running tsh login with no parameters successfully reauths the user to the scope they were in before.
  • With expired scoped credentials, running tsh login --scope=none and tsh login --scope="" with no other parameters successfully reauths the user to unscoped mode.
  • With expired unscoped credentials, running tsh login --scope=/some/scope with no other parameters successfully reauths the user to the target scope.
  • With expired scoped credentials at /some/scope, running tsh login --scope=/some/other/scope with no other parameters successfully reauths the user to the new target scope.

* Add scope aware profiles after tsh login

Update tsh.go

fix some minor issues

Update client_store_test.go

fix rebase

Update client_store.go

Add scope changing feature

Update tsh.go

Update tsh.go

* Remove "none" descoping

Update tsh.go

clean up

* nil the scope pin when "" is in the profile instead of scope pin ""
@williamong-tel williamong-tel self-assigned this Mar 12, 2026
@github-actions github-actions bot added size/md tsh tsh - Teleport's command line tool for logging into nodes running Teleport. labels Mar 12, 2026
@github-actions github-actions bot requested a review from kshi36 March 12, 2026 23:18
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: adea2a772b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

// No key ring saved — ReadProfileStatus should return partial status.
status, err := clientStore.ReadProfileStatus(p.Name())
require.NoError(t, err)
require.Nil(t, status.Scope)

Choose a reason for hiding this comment

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

P1 Badge Assert empty scope string instead of nil

ProfileStatus.Scope is a string in this branch, so require.Nil(t, status.Scope) can never be true and this new subtest will fail even when ReadProfileStatus behaves correctly for an unscoped profile. This makes TestPartialProfileStatusScope a permanent false failure in CI; the check should compare against "" (and avoid nil/not-nil assertions for this field) to validate the intended behavior.

Useful? React with 👍 / 👎.

Update client_store_test.go

Update client_store_test.go
@williamong-tel williamong-tel force-pushed the williamo/v18-scope-aware-tsh-profiles branch from adea2a7 to 90709c3 Compare March 12, 2026 23:29
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 90709c3c44

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

// client is already logged in and profile is not expired
if profile != nil && !profile.IsExpired(time.Now()) {
// client is already logged in and profile is not expired and scope hasn't changed
if profile != nil && !profile.IsExpired(time.Now()) && !scopeChanged {

Choose a reason for hiding this comment

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

P2 Badge Run update check before relogin on scope changes

This new guard makes scope-changing logins skip the branch that contains the fallback autoupdatetools.CheckAndUpdateRemote call, while the earlier profile == nil update 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 forced profile=nil and always performed the update check first.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport size/md tsh tsh - Teleport's command line tool for logging into nodes running Teleport.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant