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

Reorganize tctl commands to not require an auth client by default #48894

Merged
merged 14 commits into from
Dec 17, 2024

Conversation

vapopov
Copy link
Contributor

@vapopov vapopov commented Nov 13, 2024

In this PR added ability to declare tctl commands which not required auth client such as version command

Related: #47692 (comment)

@github-actions github-actions bot requested a review from Joerger November 13, 2024 14:37
@github-actions github-actions bot added tctl tctl - Teleport admin tool tsh tsh - Teleport's command line tool for logging into nodes running Teleport. labels Nov 13, 2024
@github-actions github-actions bot requested a review from r0mant November 13, 2024 14:37
@vapopov vapopov force-pushed the vapopov/reorgonize-tctl-commands branch from ceef55e to 3d57ff8 Compare November 13, 2024 14:37
@vapopov vapopov force-pushed the vapopov/reorgonize-tctl-commands branch from 3d57ff8 to fa9f372 Compare November 13, 2024 14:39
@zmb3
Copy link
Collaborator

zmb3 commented Nov 13, 2024

I don't love this approach but I'm struggling to come up with a better idea at the moment.. 🤔

@vapopov
Copy link
Contributor Author

vapopov commented Nov 13, 2024

I don't love this approach but I'm struggling to come up with a better idea at the moment.. 🤔

@zmb3 I tried couple other options but they also look not perfect, like to make auth client initialization as lazy loading so only commands which requires auth going to init connection, and another one - not return error if auth client failed to init, so in commands client might be nil

TryRun(ctx context.Context, cmd string, client *authclient.Client)

Copy link
Contributor

@rosstimothy rosstimothy left a comment

Choose a reason for hiding this comment

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

I agree with Zac, I'm not particularly fond of splitting up the commands. We could potentially expand on your suggestion to have the client be lazily constructed and instead of

TryRun(ctx context.Context, cmd string, client *authclient.Client)

we could do

TryRun(ctx context.Context, cmd string, clientFunc func() *authclient.Client)

In that scenario, the logic of building the client can stay where it is, but only be executed if the command requires an authenticated connection to the cluster.

tool/tctl/common/tctl.go Outdated Show resolved Hide resolved
tool/tctl/common/tctl.go Outdated Show resolved Hide resolved
tool/tctl/common/cmds.go Outdated Show resolved Hide resolved
@vapopov vapopov added the no-changelog Indicates that a PR does not require a changelog entry label Nov 15, 2024
@vapopov
Copy link
Contributor Author

vapopov commented Nov 15, 2024

I've refactored to have separate auth client initialization after command matching
commands that do not require an authentication client: tctl version|top|fido2|touchid|webauthnwin

@vapopov vapopov requested review from rosstimothy and zmb3 November 18, 2024 21:50
Copy link
Collaborator

@zmb3 zmb3 left a comment

Choose a reason for hiding this comment

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

I'm liking this approach better. 👍

tool/tctl/common/acl_command.go Outdated Show resolved Hide resolved
switch cmd {
case a.authGenerate.FullCommand():
err = a.GenerateKeys(ctx, client)
client, clientClose, err := clientFunc(ctx)
Copy link
Collaborator

Choose a reason for hiding this comment

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

There's a lot of repeated code here. Would it be simpler to run the clientFunc prior to the switch?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this case we init auth client (start checking profile folder, establish connection, request ping) before actual matching the command has to be run. We need to identify what command it is by FullCommand() and then each command decides if auth client is required

tool/tctl/common/client/auth.go Outdated Show resolved Hide resolved
tool/tctl/common/client/auth.go Outdated Show resolved Hide resolved
tool/tctl/common/config/profile.go Outdated Show resolved Hide resolved
@vapopov vapopov force-pushed the vapopov/reorgonize-tctl-commands branch from 7240ab5 to b6fe948 Compare November 21, 2024 19:02
@vapopov vapopov requested a review from zmb3 November 25, 2024 19:44
@vapopov
Copy link
Contributor Author

vapopov commented Dec 2, 2024

would appreciate of review of this PR

Copy link
Contributor

@Joerger Joerger left a comment

Choose a reason for hiding this comment

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

LGTM, approach seems reasonable. Just left a suggestion for the naming.

tool/tctl/common/access_request_command.go Outdated Show resolved Hide resolved
@vapopov vapopov force-pushed the vapopov/reorgonize-tctl-commands branch from 0569781 to c68f24f Compare December 6, 2024 01:34
@vapopov
Copy link
Contributor Author

vapopov commented Dec 9, 2024

one more review by any chance

@vapopov vapopov requested a review from espadolini December 11, 2024 16:56
Copy link
Contributor

@hugoShaka hugoShaka left a comment

Choose a reason for hiding this comment

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

LGTM once comments are resolved

tool/tctl/common/client/auth.go Show resolved Hide resolved
tool/tctl/common/client/auth.go Outdated Show resolved Hide resolved
tool/tctl/common/admin_action_test.go Outdated Show resolved Hide resolved
Comment on lines +38 to +39
func (c *fido2Command) TryRun(ctx context.Context, cmd string, _ commonclient.InitFunc) (match bool, err error) {
return c.impl.TryRun(ctx, cmd)
Copy link
Contributor

Choose a reason for hiding this comment

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

This PR makes the fido2 command work even without a valid client, nice :)

tool/tctl/common/auth_command.go Outdated Show resolved Hide resolved
tool/tctl/common/plugin/plugins_command.go Outdated Show resolved Hide resolved
@vapopov vapopov force-pushed the vapopov/reorgonize-tctl-commands branch from 70123e6 to 4b1e596 Compare December 17, 2024 19:52
@vapopov vapopov changed the title Reorganize tctl commands to have commands not required auth client Reorganize tctl commands to not require an auth client by default Dec 17, 2024
@vapopov vapopov added this pull request to the merge queue Dec 17, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Dec 17, 2024
@vapopov vapopov added this pull request to the merge queue Dec 17, 2024
Merged via the queue into master with commit 45f29a8 Dec 17, 2024
42 checks passed
@vapopov vapopov deleted the vapopov/reorgonize-tctl-commands branch December 17, 2024 21:13
vapopov added a commit that referenced this pull request Jan 10, 2025
…8894)

* Reorganize tctl commands to have commands not required auth client

* Replace auth client with lazy loading approach

* Fix linter warning

* Replace camel case in import alias
Replace logrus to use slog

* Rename close function

* Refactor plugin commands to use interface of auth client and plugin client
Code review changes

* Refactor workload identity commands

* Add access to global config for the commands

* Add test checking all tctl commands match process

* Fix golangci-lint warnings
vapopov added a commit that referenced this pull request Jan 11, 2025
…8894)

* Reorganize tctl commands to have commands not required auth client

* Replace auth client with lazy loading approach

* Fix linter warning

* Replace camel case in import alias
Replace logrus to use slog

* Rename close function

* Refactor plugin commands to use interface of auth client and plugin client
Code review changes

* Refactor workload identity commands

* Add access to global config for the commands

* Add test checking all tctl commands match process

* Fix golangci-lint warnings
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/sm tctl tctl - Teleport admin tool 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.

5 participants