mirror of
https://github.com/tailscale/tailscale.git
synced 2026-11-20 08:41:19 -08:00
ssh/tailssh: treat numerically-zero uids as root in isRootUser
An NSS uid like "00" passed the string != "0" check but parses to 0 in the incubator, so a session could bypass non-root checks and run as root. Compare the uid numerically instead; non-numeric uids keep the previous behavior. Updates tailscale/corp#50380 Signed-off-by: James Tucker <[email protected]>
This commit is contained in:
1 parent
3e61adf832
commit
d90ffb62af
3 files changed
+38
-2
No files matched your search
@@ -1415,3 +1415,28 @@ func mockRecordingServer(t *testing.T, handleRecord http.HandlerFunc) *httptest.
|
||||
t.Cleanup(srv.Close)
|
||||
return srv
|
||||
}
|
||||
|
||||
func TestIsRootUser(t *testing.T) {
|
||||
tests := []struct {
|
||||
uid, username string
|
||||
want bool
|
||||
}{
|
||||
{uid: "0", username: "root", want: true},
|
||||
{uid: "0", username: "alice", want: true},
|
||||
// A non-canonical numeric uid 0 is also root.
|
||||
{uid: "00", username: "alice", want: true},
|
||||
{uid: "00000000", username: "alice", want: true},
|
||||
{uid: "1000", username: "root", want: true},
|
||||
{uid: "1000", username: "alice", want: false},
|
||||
{uid: "1", username: "daemon", want: false},
|
||||
// Non-numeric uids keep the string behavior.
|
||||
{uid: "notanumber", username: "root", want: true},
|
||||
{uid: "notanumber", username: "alice", want: false},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
got := isRootUser(&userMeta{User: user.User{Uid: tt.uid, Username: tt.username}})
|
||||
if got != tt.want {
|
||||
t.Errorf("isRootUser(uid=%q, username=%q) = %v; want %v", tt.uid, tt.username, got, tt.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,17 @@ func (u *userMeta) GroupIds() ([]string, error) {
|
||||
|
||||
// isRootUser reports whether u is the superuser.
|
||||
func isRootUser(u *userMeta) bool {
|
||||
return u.Uid == "0" || u.Username == "root"
|
||||
if u.Username == "root" {
|
||||
return true
|
||||
}
|
||||
// Compare the uid numerically: a non-canonical uid like "00" also
|
||||
// denotes root, and must not bypass the non-root checks that later
|
||||
// parse the uid numerically (e.g. the incubator's --uid). Non-numeric
|
||||
// uids keep the previous string behavior (not root).
|
||||
if uid, err := strconv.ParseUint(u.Uid, 10, 32); err == nil {
|
||||
return uid == 0
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (u *userMeta) LoginShell() string {
|
||||
|
||||
+2
-1
@@ -17,6 +17,7 @@ import (
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
"unicode"
|
||||
"unicode/utf8"
|
||||
|
||||
"tailscale.com/version/distro"
|
||||
@@ -272,7 +273,7 @@ func checkParsedGetentField(s string) bool {
|
||||
return false
|
||||
}
|
||||
for _, r := range s {
|
||||
if r < ' ' || r == 0x7f || r == utf8.RuneError {
|
||||
if unicode.IsControl(r) || r == utf8.RuneError {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user