summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorBrad Fitzpatrick <bradfitz@tailscale.com>2023-01-23 14:55:36 -0800
committerBrad Fitzpatrick <brad@danga.com>2023-01-23 19:12:26 -0800
commitc8db70fd7363fd5cc3b4aa8288edbb56949afdbd (patch)
tree216ab98ab616901affc48ecacaff7a24de3c18ba
parent140b9aad5c7c2540f8284d3affab628e23cd95d4 (diff)
downloadtailscale-c8db70fd7363fd5cc3b4aa8288edbb56949afdbd.tar.xz
tailscale-c8db70fd7363fd5cc3b4aa8288edbb56949afdbd.zip
cmd/tailscale/cli: add debug set-expire command for testing
Updates tailscale/corp#8811 Updates tailscale/corp#8613 Change-Id: I1c87806ca3ccc5c43e7ddbd6b4d521f73f7d29f1 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
-rw-r--r--client/tailscale/localclient.go9
-rw-r--r--cmd/tailscale/cli/debug.go21
-rw-r--r--ipn/localapi/localapi.go4
3 files changed, 34 insertions, 0 deletions
diff --git a/client/tailscale/localclient.go b/client/tailscale/localclient.go
index bd7579078..4d38e7a15 100644
--- a/client/tailscale/localclient.go
+++ b/client/tailscale/localclient.go
@@ -1020,6 +1020,15 @@ func (lc *LocalClient) DebugDERPRegion(ctx context.Context, regionIDOrCode strin
return decodeJSON[*ipnstate.DebugDERPRegionReport](body)
}
+// DebugSetExpireIn marks the current node key to expire in d.
+//
+// This is meant primarily for debug and testing.
+func (lc *LocalClient) DebugSetExpireIn(ctx context.Context, d time.Duration) error {
+ v := url.Values{"expiry": {fmt.Sprint(time.Now().Add(d).Unix())}}
+ _, err := lc.send(ctx, "POST", "/localapi/v0/set-expiry-sooner?"+v.Encode(), 200, nil)
+ return err
+}
+
// WatchIPNBus subscribes to the IPN notification bus. It returns a watcher
// once the bus is connected successfully.
//
diff --git a/cmd/tailscale/cli/debug.go b/cmd/tailscale/cli/debug.go
index 4e22a0688..f6e91b8f4 100644
--- a/cmd/tailscale/cli/debug.go
+++ b/cmd/tailscale/cli/debug.go
@@ -167,6 +167,16 @@ var debugCmd = &ffcli.Command{
})(),
},
{
+ Name: "set-expire",
+ Exec: runSetExpire,
+ ShortHelp: "manipulate node key expiry for testing",
+ FlagSet: (func() *flag.FlagSet {
+ fs := newFlagSet("set-expire")
+ fs.DurationVar(&setExpireArgs.in, "in", 0, "if non-zero, set node key to expire this duration from now")
+ return fs
+ })(),
+ },
+ {
Name: "dev-store-set",
Exec: runDevStoreSet,
ShortHelp: "set a key/value pair during development",
@@ -714,3 +724,14 @@ func runDebugDERP(ctx context.Context, args []string) error {
fmt.Printf("%s\n", must.Get(json.MarshalIndent(st, "", " ")))
return nil
}
+
+var setExpireArgs struct {
+ in time.Duration
+}
+
+func runSetExpire(ctx context.Context, args []string) error {
+ if len(args) != 0 || setExpireArgs.in == 0 {
+ return errors.New("usage --in=<duration>")
+ }
+ return localClient.DebugSetExpireIn(ctx, setExpireArgs.in)
+}
diff --git a/ipn/localapi/localapi.go b/ipn/localapi/localapi.go
index fabc8952c..c46e81dc6 100644
--- a/ipn/localapi/localapi.go
+++ b/ipn/localapi/localapi.go
@@ -1065,6 +1065,10 @@ func (h *Handler) serveDERPMap(w http.ResponseWriter, r *http.Request) {
// serveSetExpirySooner sets the expiry date on the current machine, specified
// by an `expiry` unix timestamp as POST or query param.
func (h *Handler) serveSetExpirySooner(w http.ResponseWriter, r *http.Request) {
+ if !h.PermitWrite {
+ http.Error(w, "access denied", http.StatusForbidden)
+ return
+ }
if r.Method != "POST" {
http.Error(w, "POST required", http.StatusMethodNotAllowed)
return