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>
194 lines
6.3 KiB
Go
194 lines
6.3 KiB
Go
// Copyright (c) Tailscale Inc & contributors
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
package tsweb
|
|
|
|
import (
|
|
"expvar"
|
|
"fmt"
|
|
"html"
|
|
"io"
|
|
"net/http"
|
|
"net/url"
|
|
"os"
|
|
"runtime"
|
|
|
|
"tailscale.com/feature"
|
|
"tailscale.com/tsweb/varz"
|
|
"tailscale.com/version"
|
|
)
|
|
|
|
// DebugHandler is an http.Handler that serves a debugging "homepage",
|
|
// and provides helpers to register more debug endpoints and reports.
|
|
//
|
|
// The rendered page consists of three sections: informational
|
|
// key/value pairs, links to other pages, and additional
|
|
// program-specific HTML. Callers can add to these sections using the
|
|
// KV, URL and Section helpers respectively.
|
|
//
|
|
// Additionally, the Handle method offers a shorthand for correctly
|
|
// registering debug handlers and cross-linking them from /debug/.
|
|
type DebugHandler struct {
|
|
mux *http.ServeMux // where this handler is registered
|
|
kvs []func(io.Writer) // output one <li>...</li> each, see KV()
|
|
urls []string // one <li>...</li> block with link each
|
|
sections []func(io.Writer, *http.Request) // invoked in registration order prior to outputting </body>
|
|
title string // title displayed on index page
|
|
}
|
|
|
|
// PrometheusHandler is an optional hook to enable native Prometheus
|
|
// support in the debug handler. It is disabled by default. Import the
|
|
// tailscale.com/tsweb/promvarz package to enable this feature.
|
|
var PrometheusHandler feature.Hook[func(*DebugHandler)]
|
|
|
|
// Debugger returns the DebugHandler registered on mux at /debug/,
|
|
// creating it if necessary.
|
|
func Debugger(mux *http.ServeMux) *DebugHandler {
|
|
h, pat := mux.Handler(&http.Request{URL: &url.URL{Path: "/debug/"}})
|
|
if d, ok := h.(*DebugHandler); ok && pat == "/debug/" {
|
|
return d
|
|
}
|
|
ret := &DebugHandler{
|
|
mux: mux,
|
|
title: fmt.Sprintf("%s debug", version.CmdName()),
|
|
}
|
|
mux.Handle("/debug/", ret)
|
|
|
|
ret.KVFunc("Uptime", func() any { return varz.Uptime() })
|
|
ret.KV("Version", version.Long())
|
|
ret.Handle("vars", "Metrics (Go)", expvar.Handler())
|
|
if PrometheusHandler.IsSet() {
|
|
PrometheusHandler.Get()(ret)
|
|
} else {
|
|
ret.Handle("varz", "Metrics (Prometheus)", http.HandlerFunc(varz.Handler))
|
|
}
|
|
|
|
addProfilingHandlers(ret)
|
|
ret.Handle("gc", "force GC", http.HandlerFunc(gcHandler))
|
|
hostname, err := os.Hostname()
|
|
if err == nil {
|
|
ret.KV("Machine", hostname)
|
|
}
|
|
return ret
|
|
}
|
|
|
|
// ServeHTTP implements http.Handler.
|
|
func (d *DebugHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
if !AllowDebugAccess(r) {
|
|
http.Error(w, "debug access denied", http.StatusForbidden)
|
|
return
|
|
}
|
|
if r.URL.Path != "/debug/" {
|
|
// Sub-handlers are handled by the parent mux directly.
|
|
http.NotFound(w, r)
|
|
return
|
|
}
|
|
|
|
AddBrowserHeaders(w)
|
|
f := func(format string, args ...any) { fmt.Fprintf(w, format, args...) }
|
|
f("<html><body><h1>%s</h1><ul>", html.EscapeString(d.title))
|
|
for _, kv := range d.kvs {
|
|
kv(w)
|
|
}
|
|
for _, url := range d.urls {
|
|
io.WriteString(w, url)
|
|
}
|
|
for _, section := range d.sections {
|
|
section(w, r)
|
|
}
|
|
}
|
|
|
|
func (d *DebugHandler) handle(slug string, handler http.Handler) string {
|
|
href := "/debug/" + slug
|
|
d.mux.Handle(href, Protected(debugBrowserHeaderHandler(handler)))
|
|
return href
|
|
}
|
|
|
|
// Handle registers handler at /debug/<slug> and adds a link to it
|
|
// on /debug/ with the provided description.
|
|
func (d *DebugHandler) Handle(slug, desc string, handler http.Handler) {
|
|
href := d.handle(slug, handler)
|
|
d.URL(href, desc)
|
|
}
|
|
|
|
// Handle registers handler at /debug/<slug> and adds a link to it
|
|
// on /debug/ with the provided description.
|
|
func (d *DebugHandler) HandleFunc(slug, desc string, handler http.HandlerFunc) {
|
|
d.Handle(slug, desc, handler)
|
|
}
|
|
|
|
// HandleSilent registers handler at /debug/<slug>. It does not add
|
|
// a descriptive entry in /debug/ for it. This should be used
|
|
// sparingly, for things that need to be registered but would pollute
|
|
// the list of debug links.
|
|
func (d *DebugHandler) HandleSilent(slug string, handler http.Handler) {
|
|
d.handle(slug, handler)
|
|
}
|
|
|
|
// HandleSilent registers handler at /debug/<slug>. It does not add
|
|
// a descriptive entry in /debug/ for it. This should be used
|
|
// sparingly, for things that need to be registered but would pollute
|
|
// the list of debug links.
|
|
func (d *DebugHandler) HandleSilentFunc(slug string, handler http.HandlerFunc) {
|
|
d.HandleSilent(slug, handler)
|
|
}
|
|
|
|
// KV adds a key/value list item to /debug/.
|
|
func (d *DebugHandler) KV(k string, v any) {
|
|
val := html.EscapeString(fmt.Sprintf("%v", v))
|
|
d.kvs = append(d.kvs, func(w io.Writer) {
|
|
fmt.Fprintf(w, "<li><b>%s:</b> %s</li>", k, val)
|
|
})
|
|
}
|
|
|
|
// KVFunc adds a key/value list item to /debug/. v is called on every
|
|
// render of /debug/.
|
|
func (d *DebugHandler) KVFunc(k string, v func() any) {
|
|
d.kvs = append(d.kvs, func(w io.Writer) {
|
|
val := html.EscapeString(fmt.Sprintf("%v", v()))
|
|
fmt.Fprintf(w, "<li><b>%s:</b> %s</li>", k, val)
|
|
})
|
|
}
|
|
|
|
// URL adds a URL and description list item to /debug/.
|
|
func (d *DebugHandler) URL(url, desc string) {
|
|
if desc != "" {
|
|
desc = " (" + desc + ")"
|
|
}
|
|
d.urls = append(d.urls, fmt.Sprintf(`<li><a href="%s">%s</a>%s</li>`, url, url, html.EscapeString(desc)))
|
|
}
|
|
|
|
// Section invokes f on every render of /debug/ to add supplemental
|
|
// HTML to the page body.
|
|
func (d *DebugHandler) Section(f func(w io.Writer, r *http.Request)) {
|
|
d.sections = append(d.sections, f)
|
|
}
|
|
|
|
// Title sets the title at the top of the debug page.
|
|
func (d *DebugHandler) Title(title string) {
|
|
d.title = title
|
|
}
|
|
|
|
func gcHandler(w http.ResponseWriter, r *http.Request) {
|
|
w.Write([]byte("running GC...\n"))
|
|
if f, ok := w.(http.Flusher); ok {
|
|
f.Flush()
|
|
}
|
|
runtime.GC()
|
|
w.Write([]byte("Done.\n"))
|
|
}
|
|
|
|
// debugBrowserHeaderHandler is a wrapper around BrowserHeaderHandler with a
|
|
// more relaxed Content-Security-Policy that's acceptable for internal debug
|
|
// pages. It should not be used on any public-facing handlers!
|
|
func debugBrowserHeaderHandler(h http.Handler) http.Handler {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
AddBrowserHeaders(w)
|
|
// The only difference from AddBrowserHeaders is that this policy
|
|
// allows inline CSS styles. They make debug pages much easier to
|
|
// prototype, while the risk of user-injected CSS is relatively low.
|
|
w.Header().Set("Content-Security-Policy", "default-src 'self'; frame-ancestors 'none'; form-action 'self'; base-uri 'self'; block-all-mixed-content; object-src 'none'; style-src 'self' 'unsafe-inline'")
|
|
h.ServeHTTP(w, r)
|
|
})
|
|
}
|