Skip to content

Commit

Permalink
Handle errors in drop priviledges
Browse files Browse the repository at this point in the history
  • Loading branch information
joe4dev committed Oct 4, 2023
1 parent 35e1df2 commit 11d4975
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions cmd/localstack/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,12 @@ func main() {
log.Warnln("Could not change owner of directory /tmp:", err)
}
UserLogger().Debugln("Process running as root user.")
DropPrivileges(lsOpts.User)
UserLogger().Debugln("Process running as non-root user.")
err := DropPrivileges(lsOpts.User)
if err != nil {
log.Warnln("Could not drop root privileges.", err)
} else {
UserLogger().Debugln("Process running as non-root user.")
}
}

logCollector := NewLogCollector()
Expand Down
4 changes: 2 additions & 2 deletions cmd/localstack/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ func UserLogger() *log.Entry {
}
uid := os.Getuid()
uidString := strconv.Itoa(uid)
user, err := user.LookupId(uidString)
userObject, err := user.LookupId(uidString)
if err != nil {
log.Warnln("Could not look up user by uid:", uid, err)
}
return log.WithFields(log.Fields{
"username": user.Username,
"username": userObject.Username,
"uid": uid,
"euid": os.Geteuid(),
"gid": os.Getgid(),
Expand Down

0 comments on commit 11d4975

Please sign in to comment.