Skip to content

add --roles flag to tsh request search, that allows listing requestable roles#61457

Merged
tangyatsu merged 1 commit intomasterfrom
tangyatsu/add-ability-to-list-requestable-roles-via-tsh
Nov 21, 2025
Merged

add --roles flag to tsh request search, that allows listing requestable roles#61457
tangyatsu merged 1 commit intomasterfrom
tangyatsu/add-ability-to-list-requestable-roles-via-tsh

Conversation

@tangyatsu
Copy link
Copy Markdown
Contributor

@tangyatsu tangyatsu commented Nov 18, 2025

What

Resolves: #7693

tsh now supports listing requestable roles via tsh request search --roles, enforces mutual exclusivity between --roles and --kind flags, and adds a hint to tsh request new --roles, that suggests using tsh request search --roles when the requested role is not allowed.

changelog: Added --roles flag for tsh request search, allowing users to list all requestable roles. This flag is mutually exclusive with --kind

Manual Tests

A local test cluster was created with a requester role that is allowed to request several other roles.
A test user with the requester role was created.

The following tests were performed:

  • tsh request search returns an error

  • tsh request search --roles succeeds, lists requestable roles

  • tsh request search --kind returns an error

  • tsh request search --kind=db succeeds

  • tsh request search --roles --kind=db returns error

  • tsh request search --roles --kind returns error

  • tsh request new --roles confirmed the new hint suggesting tsh request search --roles

@github-actions github-actions bot added size/md tsh tsh - Teleport's command line tool for logging into nodes running Teleport. labels Nov 18, 2025
@tangyatsu tangyatsu marked this pull request as draft November 18, 2025 19:31
@tangyatsu tangyatsu marked this pull request as ready for review November 18, 2025 20:38
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Nov 18, 2025

Amplify deployment status

Branch Commit Job ID Status Preview Updated (UTC)
tangyatsu/add-ability-to-list-requestable-roles-via-tsh d9d7e1c 8 ✅SUCCEED tangyatsu-add-ability-to-list-requestable-roles-via-tsh 2025-11-21 19:51:58

@tangyatsu tangyatsu force-pushed the tangyatsu/add-ability-to-list-requestable-roles-via-tsh branch from 7604f5a to 044ceb6 Compare November 18, 2025 22:48

var caps *types.AccessCapabilities
err = tc.WithRootClusterClient(cf.Context, func(clt authclient.ClientI) error {
caps, err = clt.GetAccessCapabilities(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

What's the difference between GetAccessCapabilities and ListRequestableRoles?

The latter seems more appropriate (at least in name).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, good point, ListRequestableRoles looks much better here

)

err = tc.WithRootClusterClient(cf.Context, func(clt authclient.ClientI) error {
for {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I would take a look at clientutils.Resources, which is a helper function that implements the pagination loop here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

So, I used clientutils.Resources here instead of my original loop. I also thought about adding a new client method with a suitable signature, something like:

ListRequestableRolesV2(ctx context.Context, pageSize int, pageToken string) (*proto.ListRequestableRolesResponse, error)

but I wasn’t sure. We have examples like:

// ListAccessLists returns a paginated list of access lists. 
ListAccessLists(context.Context, int, string) ([]*accesslist.AccessList, string, error) 
// ListAccessListsV2 returns a filtered and sorted paginated list of access lists. 
ListAccessListsV2(context.Context, *accesslistv1.ListAccessListsV2Request) ([]*accesslist.AccessList, string, error)

And the original ListAccessLists, which had a suitable signature, is now deprecated.

Comment on lines +440 to +445
resp, err := clt.ListRequestableRoles(ctx, req)
if err != nil {
return nil, "", trace.Wrap(err)
}

return resp.Roles, resp.NextPageToken, nil
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If we used the generated Getters which are nil safe we could eliminate a few lines here.

Suggested change
resp, err := clt.ListRequestableRoles(ctx, req)
if err != nil {
return nil, "", trace.Wrap(err)
}
return resp.Roles, resp.NextPageToken, nil
resp, err := clt.ListRequestableRoles(ctx, req)
return resp.GetRoles(), resp.GetNextPageToken(), trace.Wrap(err)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I really like that, I’ll update the PR

@tangyatsu tangyatsu force-pushed the tangyatsu/add-ability-to-list-requestable-roles-via-tsh branch from fe586d9 to d9d7e1c Compare November 21, 2025 19:44
@tangyatsu tangyatsu added this pull request to the merge queue Nov 21, 2025
Merged via the queue into master with commit 32c9270 Nov 21, 2025
45 checks passed
@tangyatsu tangyatsu deleted the tangyatsu/add-ability-to-list-requestable-roles-via-tsh branch November 21, 2025 21:53
@backport-bot-workflows
Copy link
Copy Markdown
Contributor

@tangyatsu See the table below for backport results.

Branch Result
branch/v18 Failed

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

Labels

backport/branch/v18 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.

Add ability to list requestable roles via tsh

4 participants