2023-01-27 21:37:20 +00:00
|
|
|
// Copyright (c) Tailscale Inc & AUTHORS
|
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
2022-11-21 17:00:20 +00:00
|
|
|
|
|
|
|
//go:build !windows
|
|
|
|
|
|
|
|
package ipnauth
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
|
2024-02-14 03:12:03 +00:00
|
|
|
"github.com/tailscale/peercred"
|
2022-11-21 17:00:20 +00:00
|
|
|
"tailscale.com/types/logger"
|
|
|
|
)
|
|
|
|
|
|
|
|
// GetConnIdentity extracts the identity information from the connection
|
|
|
|
// based on the user who owns the other end of the connection.
|
|
|
|
// and couldn't. The returned connIdentity has NotWindows set to true.
|
|
|
|
func GetConnIdentity(_ logger.Logf, c net.Conn) (ci *ConnIdentity, err error) {
|
|
|
|
ci = &ConnIdentity{conn: c, notWindows: true}
|
|
|
|
_, ci.isUnixSock = c.(*net.UnixConn)
|
|
|
|
ci.creds, _ = peercred.Get(c)
|
|
|
|
return ci, nil
|
|
|
|
}
|
ipn, safesocket: use Windows token in LocalAPI
On Windows, the idiomatic way to check access on a named pipe is for
the server to impersonate the client on its current OS thread, perform
access checks using the client's access token, and then revert the OS
thread's access token back to its true self.
The access token is a better representation of the client's rights than just
a username/userid check, as it represents the client's effective rights
at connection time, which might differ from their normal rights.
This patch updates safesocket to do the aforementioned impersonation,
extract the token handle, and then revert the impersonation. We retain
the token handle for the remaining duration of the connection (the token
continues to be valid even after we have reverted back to self).
Since the token is a property of the connection, I changed ipnauth to wrap
the concrete net.Conn to include the token. I then plumbed that change
through ipnlocal, ipnserver, and localapi as necessary.
I also added a PermitLocalAdmin flag to the localapi Handler which I intend
to use for controlling access to a few new localapi endpoints intended
for configuring auto-update.
Updates https://github.com/tailscale/tailscale/issues/755
Signed-off-by: Aaron Klotz <aaron@tailscale.com>
2023-10-25 20:48:05 +00:00
|
|
|
|
|
|
|
// WindowsToken is unsupported when GOOS != windows and always returns
|
|
|
|
// ErrNotImplemented.
|
|
|
|
func (ci *ConnIdentity) WindowsToken() (WindowsToken, error) {
|
|
|
|
return nil, ErrNotImplemented
|
|
|
|
}
|