types/persist: add AttestationKey (#17281)
Extend Persist with AttestationKey to record a hardware-backed attestation key for the node's identity. Add a flag to tailscaled to allow users to control the use of hardware-backed keys to bind node identity to individual machines. Updates tailscale/corp#31269 Change-Id: Idcf40d730a448d85f07f1bebf387f086d4c58be3 Signed-off-by: Patrick O'Doherty <patrick@tailscale.com>
This commit is contained in:
committed by
GitHub
parent
a2dc517d7d
commit
e45557afc0
@@ -121,7 +121,12 @@ func gen(buf *bytes.Buffer, it *codegen.ImportTracker, typ *types.Named) {
|
||||
continue
|
||||
}
|
||||
if !hasBasicUnderlying(ft) {
|
||||
writef("dst.%s = *src.%s.Clone()", fname, fname)
|
||||
// don't dereference if the underlying type is an interface
|
||||
if _, isInterface := ft.Underlying().(*types.Interface); isInterface {
|
||||
writef("if src.%s != nil { dst.%s = src.%s.Clone() }", fname, fname, fname)
|
||||
} else {
|
||||
writef("dst.%s = *src.%s.Clone()", fname, fname)
|
||||
}
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,3 +59,52 @@ func TestSliceContainer(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestInterfaceContainer(t *testing.T) {
|
||||
examples := []struct {
|
||||
name string
|
||||
in *clonerex.InterfaceContainer
|
||||
}{
|
||||
{
|
||||
name: "nil",
|
||||
in: nil,
|
||||
},
|
||||
{
|
||||
name: "zero",
|
||||
in: &clonerex.InterfaceContainer{},
|
||||
},
|
||||
{
|
||||
name: "with_interface",
|
||||
in: &clonerex.InterfaceContainer{
|
||||
Interface: &clonerex.CloneableImpl{Value: 42},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "with_nil_interface",
|
||||
in: &clonerex.InterfaceContainer{
|
||||
Interface: nil,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, ex := range examples {
|
||||
t.Run(ex.name, func(t *testing.T) {
|
||||
out := ex.in.Clone()
|
||||
if !reflect.DeepEqual(ex.in, out) {
|
||||
t.Errorf("Clone() = %v, want %v", out, ex.in)
|
||||
}
|
||||
|
||||
// Verify no aliasing: modifying the clone should not affect the original
|
||||
if ex.in != nil && ex.in.Interface != nil {
|
||||
if impl, ok := out.Interface.(*clonerex.CloneableImpl); ok {
|
||||
impl.Value = 999
|
||||
if origImpl, ok := ex.in.Interface.(*clonerex.CloneableImpl); ok {
|
||||
if origImpl.Value == 999 {
|
||||
t.Errorf("Clone() aliased memory with original")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright (c) Tailscale Inc & AUTHORS
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
//go:generate go run tailscale.com/cmd/cloner -clonefunc=true -type SliceContainer
|
||||
//go:generate go run tailscale.com/cmd/cloner -clonefunc=true -type SliceContainer,InterfaceContainer
|
||||
|
||||
// Package clonerex is an example package for the cloner tool.
|
||||
package clonerex
|
||||
@@ -9,3 +9,26 @@ package clonerex
|
||||
type SliceContainer struct {
|
||||
Slice []*int
|
||||
}
|
||||
|
||||
// Cloneable is an interface with a Clone method.
|
||||
type Cloneable interface {
|
||||
Clone() Cloneable
|
||||
}
|
||||
|
||||
// CloneableImpl is a concrete type that implements Cloneable.
|
||||
type CloneableImpl struct {
|
||||
Value int
|
||||
}
|
||||
|
||||
func (c *CloneableImpl) Clone() Cloneable {
|
||||
if c == nil {
|
||||
return nil
|
||||
}
|
||||
return &CloneableImpl{Value: c.Value}
|
||||
}
|
||||
|
||||
// InterfaceContainer has a pointer to an interface field, which tests
|
||||
// the special handling for interface types in the cloner.
|
||||
type InterfaceContainer struct {
|
||||
Interface Cloneable
|
||||
}
|
||||
|
||||
@@ -35,9 +35,28 @@ var _SliceContainerCloneNeedsRegeneration = SliceContainer(struct {
|
||||
Slice []*int
|
||||
}{})
|
||||
|
||||
// Clone makes a deep copy of InterfaceContainer.
|
||||
// The result aliases no memory with the original.
|
||||
func (src *InterfaceContainer) Clone() *InterfaceContainer {
|
||||
if src == nil {
|
||||
return nil
|
||||
}
|
||||
dst := new(InterfaceContainer)
|
||||
*dst = *src
|
||||
if src.Interface != nil {
|
||||
dst.Interface = src.Interface.Clone()
|
||||
}
|
||||
return dst
|
||||
}
|
||||
|
||||
// A compilation failure here means this code must be regenerated, with the command at the top of this file.
|
||||
var _InterfaceContainerCloneNeedsRegeneration = InterfaceContainer(struct {
|
||||
Interface Cloneable
|
||||
}{})
|
||||
|
||||
// Clone duplicates src into dst and reports whether it succeeded.
|
||||
// To succeed, <src, dst> must be of types <*T, *T> or <*T, **T>,
|
||||
// where T is one of SliceContainer.
|
||||
// where T is one of SliceContainer,InterfaceContainer.
|
||||
func Clone(dst, src any) bool {
|
||||
switch src := src.(type) {
|
||||
case *SliceContainer:
|
||||
@@ -49,6 +68,15 @@ func Clone(dst, src any) bool {
|
||||
*dst = src.Clone()
|
||||
return true
|
||||
}
|
||||
case *InterfaceContainer:
|
||||
switch dst := dst.(type) {
|
||||
case *InterfaceContainer:
|
||||
*dst = *src.Clone()
|
||||
return true
|
||||
case **InterfaceContainer:
|
||||
*dst = src.Clone()
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -132,7 +132,7 @@ tailscale.com/cmd/derper dependencies: (generated by github.com/tailscale/depawa
|
||||
tailscale.com/types/logger from tailscale.com/cmd/derper+
|
||||
tailscale.com/types/netmap from tailscale.com/ipn
|
||||
tailscale.com/types/opt from tailscale.com/envknob+
|
||||
tailscale.com/types/persist from tailscale.com/ipn
|
||||
tailscale.com/types/persist from tailscale.com/ipn+
|
||||
tailscale.com/types/preftype from tailscale.com/ipn
|
||||
tailscale.com/types/ptr from tailscale.com/hostinfo+
|
||||
tailscale.com/types/result from tailscale.com/util/lineiter
|
||||
|
||||
@@ -59,16 +59,17 @@ tailscale.com/cmd/stund dependencies: (generated by github.com/tailscale/depawar
|
||||
tailscale.com/net/stunserver from tailscale.com/cmd/stund
|
||||
tailscale.com/net/tsaddr from tailscale.com/tsweb
|
||||
tailscale.com/syncs from tailscale.com/metrics+
|
||||
tailscale.com/tailcfg from tailscale.com/version
|
||||
tailscale.com/tailcfg from tailscale.com/version+
|
||||
tailscale.com/tsweb from tailscale.com/cmd/stund+
|
||||
tailscale.com/tsweb/promvarz from tailscale.com/cmd/stund
|
||||
tailscale.com/tsweb/varz from tailscale.com/tsweb+
|
||||
tailscale.com/types/dnstype from tailscale.com/tailcfg
|
||||
tailscale.com/types/ipproto from tailscale.com/tailcfg
|
||||
tailscale.com/types/key from tailscale.com/tailcfg
|
||||
tailscale.com/types/key from tailscale.com/tailcfg+
|
||||
tailscale.com/types/lazy from tailscale.com/version+
|
||||
tailscale.com/types/logger from tailscale.com/tsweb+
|
||||
tailscale.com/types/opt from tailscale.com/envknob+
|
||||
tailscale.com/types/persist from tailscale.com/feature
|
||||
tailscale.com/types/ptr from tailscale.com/tailcfg+
|
||||
tailscale.com/types/result from tailscale.com/util/lineiter
|
||||
tailscale.com/types/structs from tailscale.com/tailcfg+
|
||||
|
||||
@@ -162,7 +162,7 @@ tailscale.com/cmd/tailscale dependencies: (generated by github.com/tailscale/dep
|
||||
tailscale.com/types/netmap from tailscale.com/ipn+
|
||||
tailscale.com/types/nettype from tailscale.com/net/netcheck+
|
||||
tailscale.com/types/opt from tailscale.com/client/tailscale+
|
||||
tailscale.com/types/persist from tailscale.com/ipn
|
||||
tailscale.com/types/persist from tailscale.com/ipn+
|
||||
tailscale.com/types/preftype from tailscale.com/cmd/tailscale/cli+
|
||||
tailscale.com/types/ptr from tailscale.com/hostinfo+
|
||||
tailscale.com/types/result from tailscale.com/util/lineiter
|
||||
|
||||
@@ -52,6 +52,7 @@ import (
|
||||
"tailscale.com/syncs"
|
||||
"tailscale.com/tsd"
|
||||
"tailscale.com/types/flagtype"
|
||||
"tailscale.com/types/key"
|
||||
"tailscale.com/types/logger"
|
||||
"tailscale.com/types/logid"
|
||||
"tailscale.com/util/osshare"
|
||||
@@ -111,19 +112,20 @@ var args struct {
|
||||
// or comma-separated list thereof.
|
||||
tunname string
|
||||
|
||||
cleanUp bool
|
||||
confFile string // empty, file path, or "vm:user-data"
|
||||
debug string
|
||||
port uint16
|
||||
statepath string
|
||||
encryptState boolFlag
|
||||
statedir string
|
||||
socketpath string
|
||||
birdSocketPath string
|
||||
verbose int
|
||||
socksAddr string // listen address for SOCKS5 server
|
||||
httpProxyAddr string // listen address for HTTP proxy server
|
||||
disableLogs bool
|
||||
cleanUp bool
|
||||
confFile string // empty, file path, or "vm:user-data"
|
||||
debug string
|
||||
port uint16
|
||||
statepath string
|
||||
encryptState boolFlag
|
||||
statedir string
|
||||
socketpath string
|
||||
birdSocketPath string
|
||||
verbose int
|
||||
socksAddr string // listen address for SOCKS5 server
|
||||
httpProxyAddr string // listen address for HTTP proxy server
|
||||
disableLogs bool
|
||||
hardwareAttestation boolFlag
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -204,6 +206,9 @@ func main() {
|
||||
flag.BoolVar(&printVersion, "version", false, "print version information and exit")
|
||||
flag.BoolVar(&args.disableLogs, "no-logs-no-support", false, "disable log uploads; this also disables any technical support")
|
||||
flag.StringVar(&args.confFile, "config", "", "path to config file, or 'vm:user-data' to use the VM's user-data (EC2)")
|
||||
if buildfeatures.HasTPM {
|
||||
flag.Var(&args.hardwareAttestation, "hardware-attestation", "use hardware-backed keys to bind node identity to this device when supported by the OS and hardware. Uses TPM 2.0 on Linux and Windows; SecureEnclave on macOS and iOS; and Keystore on Android")
|
||||
}
|
||||
if f, ok := hookRegisterOutboundProxyFlags.GetOk(); ok {
|
||||
f()
|
||||
}
|
||||
@@ -667,6 +672,9 @@ func getLocalBackend(ctx context.Context, logf logger.Logf, logID logid.PublicID
|
||||
log.Fatalf("failed to start netstack: %v", err)
|
||||
}
|
||||
}
|
||||
if buildfeatures.HasTPM && args.hardwareAttestation.v {
|
||||
lb.SetHardwareAttested()
|
||||
}
|
||||
return lb, nil
|
||||
}
|
||||
|
||||
@@ -879,9 +887,26 @@ func applyIntegrationTestEnvKnob() {
|
||||
}
|
||||
}
|
||||
|
||||
// handleTPMFlags validates the --encrypt-state flag if set, and defaults
|
||||
// state encryption on if it's supported and compatible with other settings.
|
||||
// handleTPMFlags validates the --encrypt-state and --hardware-attestation flags
|
||||
// if set, and defaults both to on if supported and compatible with other
|
||||
// settings.
|
||||
func handleTPMFlags() {
|
||||
switch {
|
||||
case args.hardwareAttestation.v:
|
||||
if _, err := key.NewEmptyHardwareAttestationKey(); err == key.ErrUnsupported {
|
||||
log.SetFlags(0)
|
||||
log.Fatalf("--hardware-attestation is not supported on this platform or in this build of tailscaled")
|
||||
}
|
||||
case !args.hardwareAttestation.set:
|
||||
policyHWAttestation, _ := policyclient.Get().GetBoolean(pkey.HardwareAttestation, feature.HardwareAttestationAvailable())
|
||||
if !policyHWAttestation {
|
||||
break
|
||||
}
|
||||
if feature.TPMAvailable() {
|
||||
args.hardwareAttestation.v = true
|
||||
}
|
||||
}
|
||||
|
||||
switch {
|
||||
case args.encryptState.v:
|
||||
// Explicitly enabled, validate.
|
||||
|
||||
Reference in New Issue
Block a user