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

[client] Allow ssh to rootless netbird #3173

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions client/ssh/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,27 @@ import (
"fmt"
"net"
"net/netip"
"os"
"os/exec"
"runtime"

"github.com/netbirdio/netbird/util"
)

func isRoot() bool {
Copy link
Collaborator

Choose a reason for hiding this comment

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

non-blocker, but we could call this isRootExecution or isElevatedExecution

return os.Geteuid() == 0
}

func getLoginCmd(user string, remoteAddr net.Addr) (loginPath string, args []string, err error) {
if !isRoot() {
shell := getUserShell(user)
if shell == "" {
shell = "/bin/sh"
}

return shell, []string{"-l"}, nil
}

loginPath, err = exec.LookPath("login")
if err != nil {
return "", nil, err
Expand Down
4 changes: 4 additions & 0 deletions client/ssh/lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,9 @@ package ssh
import "os/user"

func userNameLookup(username string) (*user.User, error) {
if username == "" || (username == "root" && !isRoot()) {
return user.Current()
}

return user.Lookup(username)
}
4 changes: 4 additions & 0 deletions client/ssh/lookup_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import (
)

func userNameLookup(username string) (*user.User, error) {
if username == "" || (username == "root" && !isRoot()) {
return user.Current()
}

var userObject *user.User
userObject, err := user.Lookup(username)
if err != nil && err.Error() == user.UnknownUserError(username).Error() {
Expand Down
Loading