From 98e7983bf5f60b4f94c5d63713d728a77e26fe35 Mon Sep 17 00:00:00 2001 From: Kenneth Bingham Date: Wed, 13 Mar 2024 23:11:45 -0400 Subject: [PATCH] fall back to env var USER when /etc/passwd and stdlib faculties fail to resolve the UID --- CHANGELOG.md | 2 ++ cmd/zrok/enable.go | 12 +++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 368e6e82..d806ef42 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ FIX: Also update the Python SDK to include the permission mode and access grants fields on the `ShareRequest` (https://github.com/openziti/zrok/issues/432) +FIX: Add a way to find the username on Linux when /etc/passwd and stdlib can't resolve the UID (https://github.com/openziti/zrok/issues/454) + ## v0.4.26 FEATURE: New _permission modes_ available for shares. _Open permission mode_ retains the behavior of previous zrok releases and is the default setting. _Closed permission mode_ (`--closed`) only allows a share to be accessed (`zrok access`) by users who have been granted access with the `--access-grant` flag. See the documentation at (https://docs.zrok.io/docs/guides/permission-modes/) (https://github.com/openziti/zrok/issues/432) diff --git a/cmd/zrok/enable.go b/cmd/zrok/enable.go index fb49533f..ab24f0d2 100644 --- a/cmd/zrok/enable.go +++ b/cmd/zrok/enable.go @@ -56,13 +56,19 @@ func (cmd *enableCommand) run(_ *cobra.Command, args []string) { if err != nil { panic(err) } + var username string user, err := user2.Current() if err != nil { - panic(err) + username := os.Getenv("USER") + if username == "" { + logrus.Panicf("unable to determine the current user: %v", err) + } + } else { + username = user.Username } - hostDetail = fmt.Sprintf("%v; %v", user.Username, hostDetail) + hostDetail = fmt.Sprintf("%v; %v", username, hostDetail) if cmd.description == "@" { - cmd.description = fmt.Sprintf("%v@%v", user.Username, hostName) + cmd.description = fmt.Sprintf("%v@%v", username, hostName) } zrok, err := env.Client() if err != nil {