mirror of
https://github.com/tailscale/tailscale.git
synced 2026-02-07 22:42:02 -05:00
This file was never truly necessary and has never actually been used in the history of Tailscale's open source releases. A Brief History of AUTHORS files --- The AUTHORS file was a pattern developed at Google, originally for Chromium, then adopted by Go and a bunch of other projects. The problem was that Chromium originally had a copyright line only recognizing Google as the copyright holder. Because Google (and most open source projects) do not require copyright assignemnt for contributions, each contributor maintains their copyright. Some large corporate contributors then tried to add their own name to the copyright line in the LICENSE file or in file headers. This quickly becomes unwieldy, and puts a tremendous burden on anyone building on top of Chromium, since the license requires that they keep all copyright lines intact. The compromise was to create an AUTHORS file that would list all of the copyright holders. The LICENSE file and source file headers would then include that list by reference, listing the copyright holder as "The Chromium Authors". This also become cumbersome to simply keep the file up to date with a high rate of new contributors. Plus it's not always obvious who the copyright holder is. Sometimes it is the individual making the contribution, but many times it may be their employer. There is no way for the proejct maintainer to know. Eventually, Google changed their policy to no longer recommend trying to keep the AUTHORS file up to date proactively, and instead to only add to it when requested: https://opensource.google/docs/releasing/authors. They are also clear that: > Adding contributors to the AUTHORS file is entirely within the > project's discretion and has no implications for copyright ownership. It was primarily added to appease a small number of large contributors that insisted that they be recognized as copyright holders (which was entirely their right to do). But it's not truly necessary, and not even the most accurate way of identifying contributors and/or copyright holders. In practice, we've never added anyone to our AUTHORS file. It only lists Tailscale, so it's not really serving any purpose. It also causes confusion because Tailscalars put the "Tailscale Inc & AUTHORS" header in other open source repos which don't actually have an AUTHORS file, so it's ambiguous what that means. Instead, we just acknowledge that the contributors to Tailscale (whoever they are) are copyright holders for their individual contributions. We also have the benefit of using the DCO (developercertificate.org) which provides some additional certification of their right to make the contribution. The source file changes were purely mechanical with: git ls-files | xargs sed -i -e 's/\(Tailscale Inc &\) AUTHORS/\1 contributors/g' Updates #cleanup Change-Id: Ia101a4a3005adb9118051b3416f5a64a4a45987d Signed-off-by: Will Norris <will@tailscale.com>
154 lines
4.1 KiB
Go
154 lines
4.1 KiB
Go
// Copyright (c) Tailscale Inc & contributors
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
//go:build (linux && !android) || (darwin && !ios) || freebsd || openbsd || plan9
|
|
|
|
package tailssh
|
|
|
|
import (
|
|
"os"
|
|
"os/exec"
|
|
"os/user"
|
|
"path/filepath"
|
|
"runtime"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"go4.org/mem"
|
|
"tailscale.com/envknob"
|
|
"tailscale.com/hostinfo"
|
|
"tailscale.com/util/lineiter"
|
|
"tailscale.com/util/osuser"
|
|
"tailscale.com/version/distro"
|
|
)
|
|
|
|
// userMeta is a wrapper around *user.User with extra fields.
|
|
type userMeta struct {
|
|
user.User
|
|
|
|
// loginShellCached is the user's login shell, if known
|
|
// at the time of userLookup.
|
|
loginShellCached string
|
|
}
|
|
|
|
// GroupIds returns the list of group IDs that the user is a member of.
|
|
func (u *userMeta) GroupIds() ([]string, error) {
|
|
return osuser.GetGroupIds(&u.User)
|
|
}
|
|
|
|
// userLookup is like os/user.Lookup but it returns a *userMeta wrapper
|
|
// around a *user.User with extra fields.
|
|
func userLookup(username string) (*userMeta, error) {
|
|
u, s, err := osuser.LookupByUsernameWithShell(username)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &userMeta{User: *u, loginShellCached: s}, nil
|
|
}
|
|
|
|
func (u *userMeta) LoginShell() string {
|
|
if runtime.GOOS == "plan9" {
|
|
return "/bin/rc"
|
|
}
|
|
if u.loginShellCached != "" {
|
|
// This field should be populated on Linux, at least, because
|
|
// func userLookup on Linux uses "getent" to look up the user
|
|
// and that populates it.
|
|
return u.loginShellCached
|
|
}
|
|
switch runtime.GOOS {
|
|
case "darwin":
|
|
// Note: /Users/username is key, and not the same as u.HomeDir.
|
|
out, _ := exec.Command("dscl", ".", "-read", filepath.Join("/Users", u.Username), "UserShell").Output()
|
|
// out is "UserShell: /bin/bash"
|
|
s, ok := strings.CutPrefix(string(out), "UserShell: ")
|
|
if ok {
|
|
return strings.TrimSpace(s)
|
|
}
|
|
}
|
|
if e := os.Getenv("SHELL"); e != "" {
|
|
return e
|
|
}
|
|
return "/bin/sh"
|
|
}
|
|
|
|
// defaultPathTmpl specifies the default PATH template to use for new sessions.
|
|
//
|
|
// If empty, a default value is used based on the OS & distro to match OpenSSH's
|
|
// usually-hardcoded behavior. (see
|
|
// https://github.com/tailscale/tailscale/issues/5285 for background).
|
|
//
|
|
// The template may contain @{HOME} or @{PAM_USER} which expand to the user's
|
|
// home directory and username, respectively. (PAM is not used, despite the
|
|
// name)
|
|
var defaultPathTmpl = envknob.RegisterString("TAILSCALE_SSH_DEFAULT_PATH")
|
|
|
|
func defaultPathForUser(u *user.User) string {
|
|
if s := defaultPathTmpl(); s != "" {
|
|
return expandDefaultPathTmpl(s, u)
|
|
}
|
|
if runtime.GOOS == "plan9" {
|
|
return "/bin"
|
|
}
|
|
isRoot := u.Uid == "0"
|
|
switch distro.Get() {
|
|
case distro.Debian:
|
|
hi := hostinfo.New()
|
|
if hi.Distro == "ubuntu" {
|
|
// distro.Get's Debian includes Ubuntu. But see if it's actually Ubuntu.
|
|
// Ubuntu doesn't empirically seem to distinguish between root and non-root for the default.
|
|
// And it includes /snap/bin.
|
|
return "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin"
|
|
}
|
|
if isRoot {
|
|
return "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
|
|
}
|
|
return "/usr/local/bin:/usr/bin:/bin:/usr/bn/games"
|
|
case distro.NixOS:
|
|
return defaultPathForUserOnNixOS(u)
|
|
}
|
|
if isRoot {
|
|
return "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
|
|
}
|
|
return "/usr/local/bin:/usr/bin:/bin"
|
|
}
|
|
|
|
func defaultPathForUserOnNixOS(u *user.User) string {
|
|
for lr := range lineiter.File("/etc/pam/environment") {
|
|
lineb, err := lr.Value()
|
|
if err != nil {
|
|
return ""
|
|
}
|
|
if v := pathFromPAMEnvLine(lineb, u); v != "" {
|
|
return v
|
|
}
|
|
}
|
|
return ""
|
|
}
|
|
|
|
func pathFromPAMEnvLine(line []byte, u *user.User) (path string) {
|
|
if !mem.HasPrefix(mem.B(line), mem.S("PATH")) {
|
|
return ""
|
|
}
|
|
rest := strings.TrimSpace(strings.TrimPrefix(string(line), "PATH"))
|
|
if quoted, ok := strings.CutPrefix(rest, "DEFAULT="); ok {
|
|
if path, err := strconv.Unquote(quoted); err == nil {
|
|
return expandDefaultPathTmpl(path, u)
|
|
}
|
|
}
|
|
return ""
|
|
}
|
|
|
|
func expandDefaultPathTmpl(t string, u *user.User) string {
|
|
p := strings.NewReplacer(
|
|
"@{HOME}", u.HomeDir,
|
|
"@{PAM_USER}", u.Username,
|
|
).Replace(t)
|
|
if strings.Contains(p, "@{") {
|
|
// If there are unknown expansions, conservatively fail closed.
|
|
return ""
|
|
}
|
|
return p
|
|
}
|