mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-25 11:05:45 +00:00
cmd/tailscale/cli: support passing network lock keys via files
Fixes tailscale/corp#22356 Change-Id: I959efae716a22bcf582c20d261fb1b57bacf6dd9 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
parent
2506bf5b06
commit
4c2e978f1e
@ -747,7 +747,7 @@ tailscale.com/cmd/k8s-operator dependencies: (generated by github.com/tailscale/
|
|||||||
tailscale.com/taildrop from tailscale.com/ipn/ipnlocal+
|
tailscale.com/taildrop from tailscale.com/ipn/ipnlocal+
|
||||||
tailscale.com/tempfork/heap from tailscale.com/wgengine/magicsock
|
tailscale.com/tempfork/heap from tailscale.com/wgengine/magicsock
|
||||||
tailscale.com/tka from tailscale.com/client/tailscale+
|
tailscale.com/tka from tailscale.com/client/tailscale+
|
||||||
W tailscale.com/tsconst from tailscale.com/net/netmon+
|
tailscale.com/tsconst from tailscale.com/net/netmon+
|
||||||
tailscale.com/tsd from tailscale.com/ipn/ipnlocal+
|
tailscale.com/tsd from tailscale.com/ipn/ipnlocal+
|
||||||
tailscale.com/tsnet from tailscale.com/cmd/k8s-operator+
|
tailscale.com/tsnet from tailscale.com/cmd/k8s-operator+
|
||||||
tailscale.com/tstime from tailscale.com/cmd/k8s-operator+
|
tailscale.com/tstime from tailscale.com/cmd/k8s-operator+
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
"github.com/peterbourgon/ff/v3/ffcli"
|
"github.com/peterbourgon/ff/v3/ffcli"
|
||||||
"tailscale.com/ipn/ipnstate"
|
"tailscale.com/ipn/ipnstate"
|
||||||
"tailscale.com/tka"
|
"tailscale.com/tka"
|
||||||
|
"tailscale.com/tsconst"
|
||||||
"tailscale.com/types/key"
|
"tailscale.com/types/key"
|
||||||
"tailscale.com/types/tkatype"
|
"tailscale.com/types/tkatype"
|
||||||
)
|
)
|
||||||
@ -443,15 +444,33 @@ func runNetworkLockModify(ctx context.Context, addArgs, removeArgs []string) err
|
|||||||
|
|
||||||
var nlSignCmd = &ffcli.Command{
|
var nlSignCmd = &ffcli.Command{
|
||||||
Name: "sign",
|
Name: "sign",
|
||||||
ShortUsage: "tailscale lock sign <node-key> [<rotation-key>] or sign <auth-key>",
|
ShortUsage: "tailscale lock sign <node-key> [<rotation-key>]\ntailscale lock sign <auth-key>",
|
||||||
ShortHelp: "Signs a node or pre-approved auth key",
|
ShortHelp: "Signs a node or pre-approved auth key",
|
||||||
LongHelp: `Either:
|
LongHelp: `Either:
|
||||||
- signs a node key and transmits the signature to the coordination server, or
|
- signs a node key and transmits the signature to the coordination
|
||||||
- signs a pre-approved auth key, printing it in a form that can be used to bring up nodes under tailnet lock`,
|
server, or
|
||||||
|
- signs a pre-approved auth key, printing it in a form that can be
|
||||||
|
used to bring up nodes under tailnet lock
|
||||||
|
|
||||||
|
If any of the key arguments begin with "file:", the key is retrieved from
|
||||||
|
the file at the path specified in the argument suffix.`,
|
||||||
Exec: runNetworkLockSign,
|
Exec: runNetworkLockSign,
|
||||||
}
|
}
|
||||||
|
|
||||||
func runNetworkLockSign(ctx context.Context, args []string) error {
|
func runNetworkLockSign(ctx context.Context, args []string) error {
|
||||||
|
// If any of the arguments start with "file:", replace that argument
|
||||||
|
// with the contents of the file. We do this early, before the check
|
||||||
|
// to see if the first argument is an auth key.
|
||||||
|
for i, arg := range args {
|
||||||
|
if filename, ok := strings.CutPrefix(arg, "file:"); ok {
|
||||||
|
b, err := os.ReadFile(filename)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
args[i] = strings.TrimSpace(string(b))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if len(args) > 0 && strings.HasPrefix(args[0], "tskey-auth-") {
|
if len(args) > 0 && strings.HasPrefix(args[0], "tskey-auth-") {
|
||||||
return runTskeyWrapCmd(ctx, args)
|
return runTskeyWrapCmd(ctx, args)
|
||||||
}
|
}
|
||||||
@ -476,7 +495,7 @@ func runNetworkLockSign(ctx context.Context, args []string) error {
|
|||||||
err := localClient.NetworkLockSign(ctx, nodeKey, []byte(rotationKey.Verifier()))
|
err := localClient.NetworkLockSign(ctx, nodeKey, []byte(rotationKey.Verifier()))
|
||||||
// Provide a better help message for when someone clicks through the signing flow
|
// Provide a better help message for when someone clicks through the signing flow
|
||||||
// on the wrong device.
|
// on the wrong device.
|
||||||
if err != nil && strings.Contains(err.Error(), "this node is not trusted by network lock") {
|
if err != nil && strings.Contains(err.Error(), tsconst.TailnetLockNotTrustedMsg) {
|
||||||
fmt.Fprintln(Stderr, "Error: Signing is not available on this device because it does not have a trusted tailnet lock key.")
|
fmt.Fprintln(Stderr, "Error: Signing is not available on this device because it does not have a trusted tailnet lock key.")
|
||||||
fmt.Fprintln(Stderr)
|
fmt.Fprintln(Stderr)
|
||||||
fmt.Fprintln(Stderr, "Try again on a signing device instead. Tailnet admins can see signing devices on the admin panel.")
|
fmt.Fprintln(Stderr, "Try again on a signing device instead. Tailnet admins can see signing devices on the admin panel.")
|
||||||
|
@ -128,7 +128,7 @@ tailscale.com/cmd/tailscale dependencies: (generated by github.com/tailscale/dep
|
|||||||
tailscale.com/tailcfg from tailscale.com/client/tailscale+
|
tailscale.com/tailcfg from tailscale.com/client/tailscale+
|
||||||
tailscale.com/tempfork/spf13/cobra from tailscale.com/cmd/tailscale/cli/ffcomplete+
|
tailscale.com/tempfork/spf13/cobra from tailscale.com/cmd/tailscale/cli/ffcomplete+
|
||||||
tailscale.com/tka from tailscale.com/client/tailscale+
|
tailscale.com/tka from tailscale.com/client/tailscale+
|
||||||
W tailscale.com/tsconst from tailscale.com/net/netmon+
|
tailscale.com/tsconst from tailscale.com/net/netmon+
|
||||||
tailscale.com/tstime from tailscale.com/control/controlhttp+
|
tailscale.com/tstime from tailscale.com/control/controlhttp+
|
||||||
tailscale.com/tstime/mono from tailscale.com/tstime/rate
|
tailscale.com/tstime/mono from tailscale.com/tstime/rate
|
||||||
tailscale.com/tstime/rate from tailscale.com/cmd/tailscale/cli+
|
tailscale.com/tstime/rate from tailscale.com/cmd/tailscale/cli+
|
||||||
|
@ -338,7 +338,7 @@ tailscale.com/cmd/tailscaled dependencies: (generated by github.com/tailscale/de
|
|||||||
LD tailscale.com/tempfork/gliderlabs/ssh from tailscale.com/ssh/tailssh
|
LD tailscale.com/tempfork/gliderlabs/ssh from tailscale.com/ssh/tailssh
|
||||||
tailscale.com/tempfork/heap from tailscale.com/wgengine/magicsock
|
tailscale.com/tempfork/heap from tailscale.com/wgengine/magicsock
|
||||||
tailscale.com/tka from tailscale.com/client/tailscale+
|
tailscale.com/tka from tailscale.com/client/tailscale+
|
||||||
W tailscale.com/tsconst from tailscale.com/net/netmon+
|
tailscale.com/tsconst from tailscale.com/net/netmon+
|
||||||
tailscale.com/tsd from tailscale.com/cmd/tailscaled+
|
tailscale.com/tsd from tailscale.com/cmd/tailscaled+
|
||||||
tailscale.com/tstime from tailscale.com/control/controlclient+
|
tailscale.com/tstime from tailscale.com/control/controlclient+
|
||||||
tailscale.com/tstime/mono from tailscale.com/net/tstun+
|
tailscale.com/tstime/mono from tailscale.com/net/tstun+
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
"tailscale.com/net/tsaddr"
|
"tailscale.com/net/tsaddr"
|
||||||
"tailscale.com/tailcfg"
|
"tailscale.com/tailcfg"
|
||||||
"tailscale.com/tka"
|
"tailscale.com/tka"
|
||||||
|
"tailscale.com/tsconst"
|
||||||
"tailscale.com/types/key"
|
"tailscale.com/types/key"
|
||||||
"tailscale.com/types/logger"
|
"tailscale.com/types/logger"
|
||||||
"tailscale.com/types/netmap"
|
"tailscale.com/types/netmap"
|
||||||
@ -716,7 +717,7 @@ func (b *LocalBackend) NetworkLockSign(nodeKey key.NodePublic, rotationPublic []
|
|||||||
return key.NodePublic{}, tka.NodeKeySignature{}, errNetworkLockNotActive
|
return key.NodePublic{}, tka.NodeKeySignature{}, errNetworkLockNotActive
|
||||||
}
|
}
|
||||||
if !b.tka.authority.KeyTrusted(nlPriv.KeyID()) {
|
if !b.tka.authority.KeyTrusted(nlPriv.KeyID()) {
|
||||||
return key.NodePublic{}, tka.NodeKeySignature{}, errors.New("this node is not trusted by network lock")
|
return key.NodePublic{}, tka.NodeKeySignature{}, errors.New(tsconst.TailnetLockNotTrustedMsg)
|
||||||
}
|
}
|
||||||
|
|
||||||
p, err := nodeKey.MarshalBinary()
|
p, err := nodeKey.MarshalBinary()
|
||||||
|
@ -9,3 +9,7 @@
|
|||||||
// interfaces on Windows. This is set by the WinTun driver.
|
// interfaces on Windows. This is set by the WinTun driver.
|
||||||
const WintunInterfaceDesc = "Tailscale Tunnel"
|
const WintunInterfaceDesc = "Tailscale Tunnel"
|
||||||
const WintunInterfaceDesc0_14 = "Wintun Userspace Tunnel"
|
const WintunInterfaceDesc0_14 = "Wintun Userspace Tunnel"
|
||||||
|
|
||||||
|
// TailnetLockNotTrustedMsg is the error message used by network lock
|
||||||
|
// and sniffed (via substring) out of an error sent over the network.
|
||||||
|
const TailnetLockNotTrustedMsg = "this node is not trusted by network lock"
|
||||||
|
Loading…
Reference in New Issue
Block a user