mirror of
https://github.com/tailscale/tailscale.git
synced 2026-11-24 02:31:18 -08:00
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 <[email protected]>
(cherry picked from commit 4777494982)
This commit is contained in:
1 parent
8b27acf17f
commit
b9684f847f
2 files changed
+45
No files matched your search
@@ -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()
|
||||
|
||||
@@ -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{
|
||||
|
||||
Reference in new issue
Block a user