From b9684f847fe2d7e41fc29aee3c64cccfd66be259 Mon Sep 17 00:00:00 2001 From: James Tucker Date: Fri, 23 Oct 2026 23:51:50 +0000 Subject: [PATCH] ssh/tailssh: pin rejection-banner content to policy-derived facts A policy rejection names the requested sshUser: that name is the client's own request and reflects only tailnet policy (the client's own ACL view), never a local-host fact, so naming it leaks nothing. What a client-visible rejection must never depend on is server-side local-user information: local-user lookup failures send one fixed message for every failure cause, with the underlying error logged server-side only, so the client cannot tell "no such local user" from any other lookup failure and no banner is a username-existence oracle. Pin both properties in TestSSHAuthFlow: the user-mismatch cases, including a rule whose "=" mapping forces a local lookup of a user that does not exist, all name the requested user identically, and an accept rule whose mapped local user fails lookup gets the fixed lookup-failure banner. Updates tailscale/corp#50380 Signed-off-by: James Tucker (cherry picked from commit 4777494982c5696c467ee0db8fbec3bfca8e3f53) --- ssh/tailssh/tailssh.go | 10 ++++++++++ ssh/tailssh/tailssh_test.go | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/ssh/tailssh/tailssh.go b/ssh/tailssh/tailssh.go index 26fba8486..40c2cbd62 100644 --- a/ssh/tailssh/tailssh.go +++ b/ssh/tailssh/tailssh.go @@ -349,6 +349,12 @@ func (c *conn) clientAuth(cm ssh.ConnMetadata) (perms *ssh.Permissions, retErr e case accepted: // do nothing case rejectedUser: + // The banner names the requested user: that name is the client's + // own request and reflects only tailnet policy (the client's own + // ACL view), never a local-host fact, so naming it leaks nothing. + // The local-user lookup paths below must not vary with the failure + // cause, so no banner is a username-existence oracle; the attempted + // user is logged server-side (matchRule's vlogf). return nil, c.errBanner(fmt.Sprintf("tailnet policy does not permit you to SSH as user %q", c.info.sshUser), nil) case rejected, noPolicy: return nil, c.errBanner("tailnet policy does not permit you to SSH to this node", fmt.Errorf("failed to evaluate policy, result: %s", result)) @@ -363,6 +369,10 @@ func (c *conn) clientAuth(cm ssh.ConnMetadata) (perms *ssh.Permissions, retErr e // hold and delegate URL (if necessary). lu, err := userLookup(localUser) if err != nil { + // One fixed client-visible message for every lookup failure + // cause; the underlying error is logged server-side only, so + // the banner reveals nothing about local users beyond the name + // the policy already mapped for this client. return nil, c.errBanner(fmt.Sprintf("failed to look up local user %q ", localUser), err) } gids, err := lu.GroupIds() diff --git a/ssh/tailssh/tailssh_test.go b/ssh/tailssh/tailssh_test.go index eb0109e5c..bb4343fca 100644 --- a/ssh/tailssh/tailssh_test.go +++ b/ssh/tailssh/tailssh_test.go @@ -825,6 +825,13 @@ func TestSSHAuthFlow(t *testing.T) { Message: "autogroup:nonroot", }) autogroupNonrootRule.SSHUsers = map[string]string{"*": "="} + // Maps the requested user to a local user that does not exist, so the + // post-accept local-user lookup fails; pins that the client-visible + // banner is the fixed lookup-failure message, never the error cause. + lookupFailRule := newSSHRule(&tailcfg.SSHAction{ + Accept: true, + }) + lookupFailRule.SSHUsers = map[string]string{"alice": "no-such-local-user-tailssh-test"} tests := []struct { name string @@ -919,6 +926,34 @@ func TestSSHAuthFlow(t *testing.T) { authErr: true, wantBanners: []string{`tailscale: tailnet policy does not permit you to SSH as user "+0"` + "\n"}, }, + { + // The "=" mapping forces a local lookup of a user that does not + // exist; the banner must be the same policy-rejection shape as + // the other user-mismatch cases, never a lookup-failure variant. + name: "user-mismatch-no-such-local-user", + sshUser: "no-such-local-user-tailssh-test", + state: &localState{ + sshEnabled: true, + varRoot: varRoot, + matchingRule: autogroupNonrootRule, + }, + authErr: true, + wantBanners: []string{`tailscale: tailnet policy does not permit you to SSH as user "no-such-local-user-tailssh-test"` + "\n"}, + }, + { + // Accepted by policy, but the mapped local user does not exist: + // the client sees one fixed message regardless of why the + // lookup failed (the cause goes to the server log only). + name: "accept-local-user-lookup-fails", + sshUser: "alice", + state: &localState{ + sshEnabled: true, + varRoot: varRoot, + matchingRule: lookupFailRule, + }, + authErr: true, + wantBanners: []string{`tailscale: failed to look up local user "no-such-local-user-tailssh-test" ` + "\n"}, + }, { name: "accept", state: &localState{