use EUID if $USER is unset or does not resolve to a POSIX account

This commit is contained in:
Kenneth Bingham 2025-05-02 13:21:34 -04:00
parent 3f5db643aa
commit 4342dbe89d
No known key found for this signature in database
GPG Key ID: 31709281860130B6
2 changed files with 12 additions and 7 deletions

View File

@ -1,5 +1,9 @@
# CHANGELOG # CHANGELOG
## v1.0.5
FIX: `zrok enable` now handles the case where the user ID does not resolve to a username when generating the default environment description (https://github.com/openziti/zrok/issues/959)
## v1.0.4 ## v1.0.4
FIX: `zrok admin bootstrap` and `zrok enable` functionality were broken in `v1.0.3`. A bad combination of dependencies caused issues with marshalling data from the associated controller endpoints FIX: `zrok admin bootstrap` and `zrok enable` functionality were broken in `v1.0.3`. A bad combination of dependencies caused issues with marshalling data from the associated controller endpoints

View File

@ -56,14 +56,15 @@ func (cmd *enableCommand) run(_ *cobra.Command, args []string) {
panic(err) panic(err)
} }
var username string var username string
user, err := user2.Current() userObj, err := user2.Current()
if err != nil { if err == nil && userObj.Username != "" {
username := os.Getenv("USER") username = userObj.Username
if username == "" {
logrus.Panicf("unable to determine the current user: %v", err)
}
} else { } else {
username = user.Username username = os.Getenv("USER")
if username == "" {
username = fmt.Sprintf("user-%d", os.Geteuid())
logrus.Warnf("unable to determine the current user, using effective UID: %v", err)
}
} }
hostDetail = fmt.Sprintf("%v; %v", username, hostDetail) hostDetail = fmt.Sprintf("%v; %v", username, hostDetail)
if cmd.description == "<user>@<hostname>" { if cmd.description == "<user>@<hostname>" {