Skip to content

Commit a5e69bc

Browse files
committed
ipn/ipnauth: don't crash on OpenBSD trying to log username of unknown peer
We never implemented the peercred package on OpenBSD (and I just tried again and failed), but we've always documented that the creds pointer can be nil for operating systems where we can't map the unix socket back to its UID. On those platforms, we set the default unix socket permissions such that only the admin can open it anyway and we don't have a read-only vs read-write distinction. OpenBSD was always in that camp, where any access to Tailscale's unix socket meant full access. But during some refactoring, we broke OpenBSD in that we started assuming during one logging path (during login) that Creds was non-nil when looking up an ipnauth.Actor's username, which wasn't relevant (it was called from a function "maybeUsernameOf" anyway, which threw away errors). Verified on an OpenBSD VM. We don't have any OpenBSD integration tests yet. Fixes tailscale#17209 Updates tailscale#17221 (cherry picked from commit 8ec07b5, without the one semantic change, limiting it to just the safest part of the fix) Change-Id: I473c5903dfaa645694bcc75e7f5d484f3dd6044d Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
1 parent 912a84e commit a5e69bc

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

ipn/ipnauth/ipnauth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ type ConnIdentity struct {
6464

6565
// Fields used when NotWindows:
6666
isUnixSock bool // Conn is a *net.UnixConn
67-
creds *peercred.Creds // or nil
67+
creds *peercred.Creds // or nil if peercred.Get was not implemented on this OS
6868

6969
// Used on Windows:
7070
// TODO(bradfitz): merge these into the peercreds package and

ipn/ipnserver/actor.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,11 @@ func (a *actor) Username() (string, error) {
145145
defer tok.Close()
146146
return tok.Username()
147147
case "darwin", "linux", "illumos", "solaris", "openbsd":
148-
uid, ok := a.ci.Creds().UserID()
148+
creds := a.ci.Creds()
149+
if creds == nil {
150+
return "", errors.New("peer credentials not implemented on this OS")
151+
}
152+
uid, ok := creds.UserID()
149153
if !ok {
150154
return "", errors.New("missing user ID")
151155
}

0 commit comments

Comments
 (0)