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

Only call 'user.Current' when we really need to #24156

Merged
merged 1 commit into from
Apr 13, 2023

Conversation

capnspacehook
Copy link
Contributor

Calling 'user.Current' can be extremely slow in some instances, so avoid it when possible.

Updates https://github.com/gravitational/customer-sensitive-requests/issues/25.

@github-actions github-actions bot added size/sm tsh tsh - Teleport's command line tool for logging into nodes running Teleport. labels Apr 5, 2023
@github-actions github-actions bot requested review from mdwn and smallinsky April 5, 2023 19:47
Copy link
Collaborator

@r0mant r0mant left a comment

Choose a reason for hiding this comment

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

@capnspacehook Before we merge this, let's cut a dev release with this change and share it with the customer. Drone is having some issues atm though, I'll let you know when it's ready. For now I'll add do-not-merge label.

Copy link
Contributor

@russjones russjones left a comment

Choose a reason for hiding this comment

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

@capnspacehook Can we provide an actionable error message if user.Current() is slow for users here as well?

This is a good workaround, but it's not clear that the user will ever know if/when to use this workaround.

@capnspacehook
Copy link
Contributor Author

@russjones replaced all os/user.Current calls that are used by tsh with a wrapper that returns an error after a timeout on Windows.

api/utils/user.go Outdated Show resolved Hide resolved
api/utils/user.go Outdated Show resolved Hide resolved
api/utils/user.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@r0mant r0mant left a comment

Choose a reason for hiding this comment

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

In addition to the comments, please add test coverage.

api/utils/user.go Outdated Show resolved Hide resolved
api/utils/user.go Outdated Show resolved Hide resolved
tool/tsh/tsh.go Outdated Show resolved Hide resolved
@capnspacehook capnspacehook force-pushed the capnspacehook/avoid-user-current branch from fe31c6b to 891dec9 Compare April 10, 2023 18:03
Calling 'user.Current' can be extremely slow in some instances, so avoid
it when possible.
@capnspacehook capnspacehook force-pushed the capnspacehook/avoid-user-current branch from 9d9580d to a563375 Compare April 11, 2023 16:12
@capnspacehook capnspacehook added this pull request to the merge queue Apr 13, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Apr 13, 2023
@capnspacehook capnspacehook added this pull request to the merge queue Apr 13, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Apr 13, 2023
@capnspacehook capnspacehook added this pull request to the merge queue Apr 13, 2023
Merged via the queue into master with commit 94bacee Apr 13, 2023
20 checks passed
@capnspacehook capnspacehook deleted the capnspacehook/avoid-user-current branch April 13, 2023 21:32
@public-teleport-github-review-bot

@capnspacehook See the table below for backport results.

Branch Result
branch/v12 Create PR

zmb3 added a commit that referenced this pull request May 9, 2023
In #24156 we removed a lot of unnecessary calls to user.Current,
which can take a long time in Active Directory environments.

This commit removes a few other uses of user.Current where we were
doing a full user lookup only to find the user's home directory,
which is usually more readily available via the environment.
zmb3 added a commit that referenced this pull request May 9, 2023
In #24156 we removed a lot of unnecessary calls to user.Current,
which can take a long time in Active Directory environments.

This commit removes a few other uses of user.Current where we were
doing a full user lookup only to find the user's home directory,
which is usually more readily available via the environment.
zmb3 added a commit that referenced this pull request May 11, 2023
In #24156 we removed a lot of unnecessary calls to user.Current,
which can take a long time in Active Directory environments.

This commit removes a few other uses of user.Current where we were
doing a full user lookup only to find the user's home directory,
which is usually more readily available via the environment.
zmb3 added a commit that referenced this pull request May 11, 2023
In #24156 we removed a lot of unnecessary calls to user.Current,
which can take a long time in Active Directory environments.

This commit removes a few other uses of user.Current where we were
doing a full user lookup only to find the user's home directory,
which is usually more readily available via the environment.
zmb3 added a commit that referenced this pull request May 11, 2023
* User os.UserHomeDir where possible

In #24156 we removed a lot of unnecessary calls to user.Current,
which can take a long time in Active Directory environments.

This commit removes a few other uses of user.Current where we were
doing a full user lookup only to find the user's home directory,
which is usually more readily available via the environment.

* Fix tsh profile dir

This fixes a bug introduced in #25950
michellescripts pushed a commit that referenced this pull request May 11, 2023
* User os.UserHomeDir where possible

In #24156 we removed a lot of unnecessary calls to user.Current,
which can take a long time in Active Directory environments.

This commit removes a few other uses of user.Current where we were
doing a full user lookup only to find the user's home directory,
which is usually more readily available via the environment.

* Fix tsh profile dir

This fixes a bug introduced in #25950
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/sm 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.

None yet

5 participants