Skip to content

Commit b0049ec

Browse files
authored
Remove the custom current user lookup function (#52144)
We added this function to mitigate slow user.Current() calls in Windows Active Directory environments. Go 1.24 ships with an optimized verison of user.Current, rendering this utility unnecessary. Closes #41922
1 parent d717473 commit b0049ec

File tree

9 files changed

+20
-125
lines changed

9 files changed

+20
-125
lines changed

api/profile/profile.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"io/fs"
2424
"net"
2525
"os"
26+
"os/user"
2627
"path/filepath"
2728
"strings"
2829
"time"
@@ -32,7 +33,6 @@ import (
3233
"gopkg.in/yaml.v2"
3334

3435
"github.com/gravitational/teleport/api/defaults"
35-
"github.com/gravitational/teleport/api/utils"
3636
"github.com/gravitational/teleport/api/utils/keypaths"
3737
"github.com/gravitational/teleport/api/utils/keys"
3838
"github.com/gravitational/teleport/api/utils/sshutils"
@@ -359,7 +359,7 @@ func defaultProfilePath() string {
359359
}
360360

361361
home = os.TempDir()
362-
if u, err := utils.CurrentUser(); err == nil && u.HomeDir != "" {
362+
if u, err := user.Current(); err == nil && u.HomeDir != "" {
363363
home = u.HomeDir
364364
}
365365
return filepath.Join(home, profileDir)

api/utils/user.go

-64
This file was deleted.

api/utils/user_test.go

-44
This file was deleted.

docs/pages/faq.mdx

+8-5
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,14 @@ are not logged in to Teleport or may not have access to a browser.
7878

7979
## `tsh` is very slow on Windows, what to do?
8080

81-
If your host machine is joined to an Active Directory domain, you might find user lookups take a
82-
lot longer than you expect. The number of Active Directory accounts that must be scanned to
83-
perform a user lookup can cause tsh to hang waiting to get information about the current user.
84-
To fix this issue, you can use environment variables to set default account information for your
85-
Teleport user. If you are experiencing long lookup times on Windows, do the following:
81+
If your host machine is joined to an Active Directory domain, you might find
82+
user lookups take a lot longer than you expect. If possible, we recommend
83+
updating `tsh` to v18 or later, which contains an optimized user lookup
84+
algorithm.
85+
86+
If upgrading is not possible, you can use environment variables to set default
87+
account information for your Teleport user. If you are experiencing long lookup
88+
times on Windows, do the following:
8689

8790
- Either set the `TELEPORT_USER` environment variable or set the `--user` flag to the name of your Teleport user.
8891
- Either set the `TELEPORT_LOGIN` environment variable or set the `--login` flag to the name of current host user. This setting can be overridden if you open a new SSH session on a machine as a different user.

lib/client/api.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"net"
3232
"net/url"
3333
"os"
34+
"os/user"
3435
"path/filepath"
3536
"runtime"
3637
"slices"
@@ -4866,7 +4867,7 @@ func connectToSSHAgent() agent.ExtendedAgent {
48664867

48674868
// Username returns the current user's username
48684869
func Username() (string, error) {
4869-
u, err := apiutils.CurrentUser()
4870+
u, err := user.Current()
48704871
if err != nil {
48714872
return "", trace.Wrap(err)
48724873
}

lib/client/db/mysql/optionfile.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ package mysql
2020

2121
import (
2222
"os"
23+
"os/user"
2324
"path/filepath"
2425
"strconv"
2526
"strings"
2627

2728
"github.com/gravitational/trace"
2829
"gopkg.in/ini.v1"
2930

30-
"github.com/gravitational/teleport/api/utils"
3131
"github.com/gravitational/teleport/lib/client/db/profile"
3232
)
3333

@@ -51,7 +51,7 @@ type OptionFile struct {
5151
func DefaultConfigPath() (string, error) {
5252
home, err := os.UserHomeDir()
5353
if err != nil || home == "" {
54-
usr, err := utils.CurrentUser()
54+
usr, err := user.Current()
5555
if err != nil {
5656
return "", trace.ConvertSystemError(err)
5757
}

lib/client/db/postgres/servicefile.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ package postgres
2020

2121
import (
2222
"os"
23+
"os/user"
2324
"path/filepath"
2425
"strconv"
2526
"strings"
2627

2728
"github.com/gravitational/trace"
2829
"gopkg.in/ini.v1"
2930

30-
"github.com/gravitational/teleport/api/utils"
3131
"github.com/gravitational/teleport/lib/client/db/profile"
3232
)
3333

@@ -52,7 +52,7 @@ func defaultConfigPath() (string, error) {
5252
// TODO(r0mant): Check PGSERVICEFILE and PGSYSCONFDIR env vars as well.
5353
home, err := os.UserHomeDir()
5454
if err != nil || home == "" {
55-
usr, err := utils.CurrentUser()
55+
usr, err := user.Current()
5656
if err != nil {
5757
return "", trace.ConvertSystemError(err)
5858
}

lib/utils/agentconn/agent_windows.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,13 @@ import (
2929
"net"
3030
"os"
3131
"os/exec"
32+
"os/user"
3233
"regexp"
3334
"strconv"
3435
"strings"
3536

3637
"github.com/Microsoft/go-winio"
3738
"github.com/gravitational/trace"
38-
39-
apiutils "github.com/gravitational/teleport/api/utils"
4039
)
4140

4241
const namedPipe = `\\.\pipe\openssh-ssh-agent`
@@ -104,7 +103,7 @@ func dialCygwin(socket string) (net.Conn, error) {
104103
}
105104
key := sockMatches[3]
106105

107-
u, err := apiutils.CurrentUser()
106+
u, err := user.Current()
108107
if err != nil {
109108
return nil, trace.Wrap(err)
110109
}

tool/tsh/common/tsh.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"os"
3232
"os/exec"
3333
"os/signal"
34+
"os/user"
3435
"path/filepath"
3536
"regexp"
3637
"runtime"
@@ -66,7 +67,6 @@ import (
6667
"github.com/gravitational/teleport/api/types/accesslist"
6768
apievents "github.com/gravitational/teleport/api/types/events"
6869
"github.com/gravitational/teleport/api/types/wrappers"
69-
apiutils "github.com/gravitational/teleport/api/utils"
7070
"github.com/gravitational/teleport/api/utils/keys"
7171
"github.com/gravitational/teleport/api/utils/prompt"
7272
"github.com/gravitational/teleport/lib/asciitable"
@@ -3813,7 +3813,7 @@ func onSSHLatency(cf *CLIConf) error {
38133813
func runLocalCommand(hostLogin string, command []string) error {
38143814
if len(command) == 0 {
38153815
if hostLogin == "" {
3816-
user, err := apiutils.CurrentUser()
3816+
user, err := user.Current()
38173817
if err != nil {
38183818
return trace.Wrap(err)
38193819
}

0 commit comments

Comments
 (0)