mirror of
https://github.com/tailscale/tailscale.git
synced 2026-02-09 09:41:49 +01: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>
221 lines
6.9 KiB
Go
221 lines
6.9 KiB
Go
// Copyright (c) Tailscale Inc & contributors
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
// tkatest has functions for creating a mock control server that responds
|
|
// to TKA endpoints.
|
|
package tkatest
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"fmt"
|
|
"iter"
|
|
"log"
|
|
"net/http"
|
|
|
|
"tailscale.com/tailcfg"
|
|
"tailscale.com/tka"
|
|
"tailscale.com/types/key"
|
|
"tailscale.com/types/tkatype"
|
|
)
|
|
|
|
func serverError(w http.ResponseWriter, format string, a ...any) error {
|
|
err := fmt.Sprintf(format, a...)
|
|
http.Error(w, err, 500)
|
|
log.Printf("returning HTTP 500 error: %v", err)
|
|
return errors.New(err)
|
|
}
|
|
|
|
func userError(w http.ResponseWriter, format string, a ...any) error {
|
|
err := fmt.Sprintf(format, a...)
|
|
http.Error(w, err, 400)
|
|
return errors.New(err)
|
|
}
|
|
|
|
// HandleTKAInitBegin handles a request to /machine/tka/init/begin.
|
|
//
|
|
// If the request contains a valid genesis AUM, it sends a response to the
|
|
// client, and returns the AUM to the caller.
|
|
func HandleTKAInitBegin(w http.ResponseWriter, r *http.Request, nodes iter.Seq[*tailcfg.Node]) (*tka.AUM, error) {
|
|
var req *tailcfg.TKAInitBeginRequest
|
|
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
|
return nil, userError(w, "Decode: %v", err)
|
|
}
|
|
var aum tka.AUM
|
|
if err := aum.Unserialize(req.GenesisAUM); err != nil {
|
|
return nil, userError(w, "invalid genesis AUM: %v", err)
|
|
}
|
|
beginResp := tailcfg.TKAInitBeginResponse{}
|
|
for n := range nodes {
|
|
beginResp.NeedSignatures = append(
|
|
beginResp.NeedSignatures,
|
|
tailcfg.TKASignInfo{
|
|
NodeID: n.ID,
|
|
NodePublic: n.Key,
|
|
},
|
|
)
|
|
}
|
|
|
|
w.WriteHeader(200)
|
|
if err := json.NewEncoder(w).Encode(beginResp); err != nil {
|
|
return nil, serverError(w, "Encode: %v", err)
|
|
}
|
|
return &aum, nil
|
|
}
|
|
|
|
// HandleTKAInitFinish handles a request to /machine/tka/init/finish.
|
|
//
|
|
// It sends a response to the client, and gives the caller a list of node
|
|
// signatures to apply.
|
|
//
|
|
// This method assumes that the node signatures are valid, and does not
|
|
// verify them with the supplied public key.
|
|
func HandleTKAInitFinish(w http.ResponseWriter, r *http.Request) (map[tailcfg.NodeID]tkatype.MarshaledSignature, error) {
|
|
var req *tailcfg.TKAInitFinishRequest
|
|
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
|
return nil, userError(w, "Decode: %v", err)
|
|
}
|
|
|
|
w.WriteHeader(200)
|
|
w.Write([]byte("{}"))
|
|
|
|
return req.Signatures, nil
|
|
}
|
|
|
|
// HandleTKABootstrap handles a request to /tka/bootstrap.
|
|
//
|
|
// If the request is valid, it sends a response to the client, and returns
|
|
// the parsed request to the caller.
|
|
func HandleTKABootstrap(w http.ResponseWriter, r *http.Request, resp tailcfg.TKABootstrapResponse) (*tailcfg.TKABootstrapRequest, error) {
|
|
req := new(tailcfg.TKABootstrapRequest)
|
|
if err := json.NewDecoder(r.Body).Decode(req); err != nil {
|
|
return nil, userError(w, "Decode: %v", err)
|
|
}
|
|
if req.Version != tailcfg.CurrentCapabilityVersion {
|
|
return nil, userError(w, "bootstrap CapVer = %v, want %v", req.Version, tailcfg.CurrentCapabilityVersion)
|
|
}
|
|
|
|
w.WriteHeader(200)
|
|
if err := json.NewEncoder(w).Encode(resp); err != nil {
|
|
return nil, serverError(w, "Encode: %v", err)
|
|
}
|
|
return req, nil
|
|
}
|
|
|
|
func HandleTKASyncOffer(w http.ResponseWriter, r *http.Request, authority *tka.Authority, chonk tka.Chonk) error {
|
|
body := new(tailcfg.TKASyncOfferRequest)
|
|
if err := json.NewDecoder(r.Body).Decode(body); err != nil {
|
|
return userError(w, "Decode: %v", err)
|
|
}
|
|
|
|
log.Printf("got sync offer:\n%+v", body)
|
|
|
|
nodeOffer, err := tka.ToSyncOffer(body.Head, body.Ancestors)
|
|
if err != nil {
|
|
return userError(w, "ToSyncOffer: %v", err)
|
|
}
|
|
|
|
controlOffer, err := authority.SyncOffer(chonk)
|
|
if err != nil {
|
|
return serverError(w, "authority.SyncOffer: %v", err)
|
|
}
|
|
sendAUMs, err := authority.MissingAUMs(chonk, nodeOffer)
|
|
if err != nil {
|
|
return serverError(w, "authority.MissingAUMs: %v", err)
|
|
}
|
|
|
|
head, ancestors, err := tka.FromSyncOffer(controlOffer)
|
|
if err != nil {
|
|
return serverError(w, "FromSyncOffer: %v", err)
|
|
}
|
|
resp := tailcfg.TKASyncOfferResponse{
|
|
Head: head,
|
|
Ancestors: ancestors,
|
|
MissingAUMs: make([]tkatype.MarshaledAUM, len(sendAUMs)),
|
|
}
|
|
for i, a := range sendAUMs {
|
|
resp.MissingAUMs[i] = a.Serialize()
|
|
}
|
|
|
|
log.Printf("responding to sync offer with:\n%+v", resp)
|
|
w.WriteHeader(200)
|
|
if err := json.NewEncoder(w).Encode(resp); err != nil {
|
|
return serverError(w, "Encode: %v", err)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// HandleTKASign handles a request to /machine/tka/sign.
|
|
//
|
|
// If the signature request is valid, it sends a response to the client, and
|
|
// gives the caller the signature and public key of the node being signed.
|
|
func HandleTKASign(w http.ResponseWriter, r *http.Request, authority *tka.Authority) (*tkatype.MarshaledSignature, *key.NodePublic, error) {
|
|
req := new(tailcfg.TKASubmitSignatureRequest)
|
|
if err := json.NewDecoder(r.Body).Decode(req); err != nil {
|
|
return nil, nil, userError(w, "Decode: %v", err)
|
|
}
|
|
if req.Version != tailcfg.CurrentCapabilityVersion {
|
|
return nil, nil, userError(w, "sign CapVer = %v, want %v", req.Version, tailcfg.CurrentCapabilityVersion)
|
|
}
|
|
|
|
var sig tka.NodeKeySignature
|
|
if err := sig.Unserialize(req.Signature); err != nil {
|
|
return nil, nil, userError(w, "malformed signature: %v", err)
|
|
}
|
|
var keyBeingSigned key.NodePublic
|
|
if err := keyBeingSigned.UnmarshalBinary(sig.Pubkey); err != nil {
|
|
return nil, nil, userError(w, "malformed signature pubkey: %v", err)
|
|
}
|
|
if err := authority.NodeKeyAuthorized(keyBeingSigned, req.Signature); err != nil {
|
|
return nil, nil, userError(w, "signature does not verify: %v", err)
|
|
}
|
|
|
|
w.WriteHeader(200)
|
|
if err := json.NewEncoder(w).Encode(tailcfg.TKASubmitSignatureResponse{}); err != nil {
|
|
return nil, nil, serverError(w, "Encode: %v", err)
|
|
}
|
|
return &req.Signature, &keyBeingSigned, nil
|
|
}
|
|
|
|
// HandleTKASyncSend handles a request to /machine/tka/send.
|
|
//
|
|
// If the request is valid, it adds the new AUMs to the authority, and sends
|
|
// a response to the client with the new head.
|
|
func HandleTKASyncSend(w http.ResponseWriter, r *http.Request, authority *tka.Authority, chonk tka.Chonk) error {
|
|
body := new(tailcfg.TKASyncSendRequest)
|
|
if err := json.NewDecoder(r.Body).Decode(body); err != nil {
|
|
return userError(w, "Decode: %v", err)
|
|
}
|
|
log.Printf("got sync send:\n%+v", body)
|
|
|
|
var remoteHead tka.AUMHash
|
|
if err := remoteHead.UnmarshalText([]byte(body.Head)); err != nil {
|
|
return userError(w, "head unmarshal: %v", err)
|
|
}
|
|
toApply := make([]tka.AUM, len(body.MissingAUMs))
|
|
for i, a := range body.MissingAUMs {
|
|
if err := toApply[i].Unserialize(a); err != nil {
|
|
return userError(w, "decoding missingAUM[%d]: %v", i, err)
|
|
}
|
|
}
|
|
|
|
if len(toApply) > 0 {
|
|
if err := authority.Inform(chonk, toApply); err != nil {
|
|
return serverError(w, "control.Inform(%+v) failed: %v", toApply, err)
|
|
}
|
|
}
|
|
head, err := authority.Head().MarshalText()
|
|
if err != nil {
|
|
return serverError(w, "head marshal: %v", err)
|
|
}
|
|
|
|
resp := tailcfg.TKASyncSendResponse{
|
|
Head: string(head),
|
|
}
|
|
w.WriteHeader(200)
|
|
if err := json.NewEncoder(w).Encode(resp); err != nil {
|
|
return serverError(w, "Encode: %v", err)
|
|
}
|
|
return nil
|
|
}
|