util/winutil/s4u: log when a logon uses the linked administrator token

Whether Login swaps a UAC-filtered token for its linked full token depends
on the account: the built-in Administrator is never filtered, domain
accounts' network logons are not filtered, and other local Administrators
members are. Log which happened, and any failure to get the linked token,
so a session running with fewer rights than expected can be explained from
the log.

Updates #4697

Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
Change-Id: I2c4e6a8b0d3f5a7c9e1b3d5f7a9c1e3b5d7f9a1c
This commit is contained in:
Brad Fitzpatrick committed 2026-11-13 02:13:25 +00:00
1 parent 24ff282afe
commit 2711281ce4
1 file changed
+13 -3
+13 -3
View File
@@ -135,7 +135,7 @@ func Login(logf logger.Logf, srcName string, u *user.User, capLevel CapabilityLe
return nil, err
}
if capLevel == CapCreateProcess {
token = maybeLinkedToken(token)
token = maybeLinkedToken(logfOrDiscard(logf), u, token)
}
tokenCloseOnce := sync.OnceFunc(func() { token.Close() })
defer func() {
@@ -193,15 +193,25 @@ func Login(logf logger.Logf, srcName string, u *user.User, capLevel CapabilityLe
// UAC-filtered token, closing token, and otherwise returns token unchanged.
// The caller must hold SeTcbPrivilege for the linked token to be a usable
// primary token rather than an identification-level one.
func maybeLinkedToken(token windows.Token) windows.Token {
//
// UAC filters the logon of a local Administrators member other than the
// built-in Administrator (see LocalAccountTokenFilterPolicy); domain
// accounts' network logons are not filtered, so for them this is a no-op.
func maybeLinkedToken(logf logger.Logf, u *user.User, token windows.Token) windows.Token {
limited, err := winutil.IsTokenLimited(token)
if err != nil || !limited {
if err != nil {
logf("(s4u) IsTokenLimited(%q): %v", u.Username, err)
return token
}
if !limited {
return token
}
linked, err := token.GetLinkedToken()
if err != nil {
logf("(s4u) GetLinkedToken(%q): %v; using the UAC-filtered token", u.Username, err)
return token
}
logf("(s4u) using the linked (unfiltered) administrator token for %q", u.Username)
token.Close()
return linked
}