summaryrefslogtreecommitdiffhomepage
path: root/ipn/ipnlocal/local.go
diff options
context:
space:
mode:
authorBrad Fitzpatrick <bradfitz@tailscale.com>2022-03-19 21:23:42 -0700
committerBrad Fitzpatrick <bradfitz@tailscale.com>2022-03-20 13:01:18 -0700
commitccdc41988c4c3113e60c2aa27aa393d3b15e4f2e (patch)
tree8840e9ea61032fd3bff3a038a1f636d107a2cc9b /ipn/ipnlocal/local.go
parentbfb4a4d9e9b48acc3e9de8a3b2b67f1f31143b57 (diff)
downloadtailscale-bradfitz/cli_admin.tar.xz
tailscale-bradfitz/cli_admin.zip
cmd/tailscale, ipn/ipn{local,server}: add start of CLI admin API + over Noisebradfitz/cli_admin
Change-Id: I2936f6baf50e7eeac7190051adba493d4245b3ea Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
Diffstat (limited to 'ipn/ipnlocal/local.go')
-rw-r--r--ipn/ipnlocal/local.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/ipn/ipnlocal/local.go b/ipn/ipnlocal/local.go
index bcad6c64a..d235df451 100644
--- a/ipn/ipnlocal/local.go
+++ b/ipn/ipnlocal/local.go
@@ -12,6 +12,7 @@ import (
"io"
"net"
"net/http"
+ "net/url"
"os"
"os/exec"
"os/user"
@@ -3253,3 +3254,38 @@ func (b *LocalBackend) DoNoiseRequest(req *http.Request) (*http.Response, error)
}
return cc.DoNoiseRequest(req)
}
+
+// ProxyAPIRequestOverNoise sends Tailscale API request r over the
+// Noise channel, authenticated as the current node+machine key, to
+// the control plane and copies its response back to w.
+func (b *LocalBackend) ProxyAPIRequestOverNoise(w http.ResponseWriter, r *http.Request) {
+ var nodePub key.NodePublic
+ b.mu.Lock()
+ if nm := b.netMap; nm != nil {
+ nodePub = nm.NodeKey
+ }
+ b.mu.Unlock()
+ if nodePub.IsZero() {
+ http.Error(w, "no node public key", http.StatusBadGateway)
+ return
+ }
+
+ outR := r.Clone(r.Context())
+ outR.RequestURI = ""
+ outR.URL.Scheme = "https"
+ outR.URL.Host = "unused"
+
+ outR.SetBasicAuth(url.QueryEscape(nodePub.String()), "")
+ res, err := b.DoNoiseRequest(outR)
+ if err != nil {
+ http.Error(w, "failed to make backend noise request: "+err.Error(), http.StatusBadGateway)
+ return
+ }
+ for k, vv := range res.Header {
+ for _, v := range vv {
+ w.Header().Add(k, v)
+ }
+ }
+ w.WriteHeader(res.StatusCode)
+ io.Copy(w, res.Body)
+}