mirror of
https://github.com/tailscale/tailscale.git
synced 2026-11-20 00:31:17 -08:00
ssh/tailssh: accept an empty --groups= in the incubator
Fixes #22158 Change-Id: I238244c34c96c444c258b9e006c0084f4aa8db27 Signed-off-by: Philip Taron <[email protected]>
This commit is contained in:
1 parent
07915ae481
commit
6fa10dae73
3 files changed
+40
-9
No files matched your search
@@ -355,12 +355,16 @@ func parseIncubatorArgs(args []string) (incubatorArgs, error) {
|
||||
flags.IntVar(&ia.envFD, "env-fd", -1, "file descriptor to read the forwarded environment from (JSON array of KEY=VALUE pairs)")
|
||||
flags.Parse(args)
|
||||
|
||||
for g := range strings.SplitSeq(groups, ",") {
|
||||
gid, err := strconv.Atoi(g)
|
||||
if err != nil {
|
||||
return ia, fmt.Errorf("unable to parse group id %q: %w", g, err)
|
||||
// A user without supplementary groups gets an empty --groups=, which is
|
||||
// no groups rather than a single empty group ID.
|
||||
if groups != "" {
|
||||
for g := range strings.SplitSeq(groups, ",") {
|
||||
gid, err := strconv.Atoi(g)
|
||||
if err != nil {
|
||||
return ia, fmt.Errorf("unable to parse group id %q: %w", g, err)
|
||||
}
|
||||
ia.gids = append(ia.gids, gid)
|
||||
}
|
||||
ia.gids = append(ia.gids, gid)
|
||||
}
|
||||
|
||||
// envFD comes from an ExtraFiles entry, so it must never name stdin/out/err
|
||||
|
||||
@@ -261,6 +261,34 @@ func TestParseIncubatorArgsEnvFD(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestParseIncubatorArgsGroups verifies that --groups accepts an empty list,
|
||||
// which a user with no supplementary groups yields, but still rejects empty
|
||||
// entries within a list.
|
||||
func TestParseIncubatorArgsGroups(t *testing.T) {
|
||||
for _, tt := range []struct {
|
||||
groups string
|
||||
want []int
|
||||
}{
|
||||
{"", nil},
|
||||
{"1000", []int{1000}},
|
||||
{"1000,1001", []int{1000, 1001}},
|
||||
} {
|
||||
ia, err := parseIncubatorArgs([]string{"--groups=" + tt.groups})
|
||||
if err != nil {
|
||||
t.Errorf("--groups=%s: got error %v, want nil", tt.groups, err)
|
||||
continue
|
||||
}
|
||||
if !slices.Equal(ia.gids, tt.want) {
|
||||
t.Errorf("--groups=%s: got gids %v, want %v", tt.groups, ia.gids, tt.want)
|
||||
}
|
||||
}
|
||||
for _, groups := range []string{"1000,x", "1000,,1001", "1000,"} {
|
||||
if _, err := parseIncubatorArgs([]string{"--groups=" + groups}); err == nil {
|
||||
t.Errorf("--groups=%s: got nil error, want rejection", groups)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestLoadForwardedEnvLegacyEncodedEnv covers the deprecated --encoded-env
|
||||
// compatibility path: an outdated parent tailscaled passes the accepted
|
||||
// environment as a quoted JSON argv flag, and the child must still decode it
|
||||
|
||||
@@ -214,10 +214,9 @@ func newMonitorSessionServerFor(
|
||||
if rule != nil {
|
||||
sc.mappedLocalUser = rule.SSHUsers["test"]
|
||||
}
|
||||
// The bound user's groups, like clientAuth would have captured them
|
||||
// (the incubator argv's --groups must be non-empty): for a conn bound
|
||||
// to another uid use that user's own primary group, not the test
|
||||
// process's (root-run) groups.
|
||||
// The bound user's groups, like clientAuth would have captured them:
|
||||
// for a conn bound to another uid use that user's own primary group,
|
||||
// not the test process's (root-run) groups.
|
||||
if um.Uid == strconv.Itoa(os.Getuid()) {
|
||||
for _, g := range testGroups(t) {
|
||||
sc.userGroupIDs = append(sc.userGroupIDs, strconv.Itoa(g))
|
||||
|
||||
Reference in new issue
Block a user