@@ -37,6 +37,7 @@ import (
3737	"github.com/gravitational/teleport/api/client" 
3838	"github.com/gravitational/teleport/api/client/proto" 
3939	"github.com/gravitational/teleport/api/client/webclient" 
40+ 	joinv1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/join/v1" 
4041	"github.com/gravitational/teleport/api/observability/tracing" 
4142	"github.com/gravitational/teleport/api/types" 
4243	"github.com/gravitational/teleport/api/utils/aws" 
@@ -191,7 +192,7 @@ type RegisterParams struct {
191192	BoundKeypairParams  * BoundKeypairParams 
192193}
193194
194- func  (r  * RegisterParams ) checkAndSetDefaults () error  {
195+ func  (r  * RegisterParams ) CheckAndSetDefaults () error  {
195196	if  r .Clock  ==  nil  {
196197		r .Clock  =  clockwork .NewRealClock ()
197198	}
@@ -264,7 +265,7 @@ func Register(ctx context.Context, params RegisterParams) (result *RegisterResul
264265	ctx , span  :=  tracer .Start (ctx , "Register" )
265266	defer  func () { tracing .EndSpan (span , err ) }()
266267
267- 	if  err  :=  params .checkAndSetDefaults (); err  !=  nil  {
268+ 	if  err  :=  params .CheckAndSetDefaults (); err  !=  nil  {
268269		return  nil , trace .Wrap (err )
269270	}
270271	// Read in the token. The token can either be passed in or come from a file 
@@ -378,7 +379,7 @@ func Register(ctx context.Context, params RegisterParams) (result *RegisterResul
378379		if  params .GetHostCredentials  ==  nil  {
379380			slog .DebugContext (ctx , "Missing client, it is not possible to register through proxy." )
380381			registerMethods  =  []registerMethod {registerThroughAuth }
381- 		} else  if  authServerIsProxy (params .AuthServers ) {
382+ 		} else  if  LooksLikeProxy (params .AuthServers ) {
382383			slog .DebugContext (ctx , "The first specified auth server appears to be a proxy." )
383384			registerMethods  =  []registerMethod {registerThroughProxy , registerThroughAuth }
384385		}
@@ -399,9 +400,9 @@ func Register(ctx context.Context, params RegisterParams) (result *RegisterResul
399400	return  nil , trace .NewAggregate (collectedErrs ... )
400401}
401402
402- // authServerIsProxy  returns true if the first specified auth server 
403+ // LooksLikeProxy  returns true if the first specified auth server 
403404// to register with appears to be a proxy. 
404- func  authServerIsProxy (servers  []utils.NetAddr ) bool  {
405+ func  LooksLikeProxy (servers  []utils.NetAddr ) bool  {
405406	if  len (servers ) ==  0  {
406407		return  false 
407408	}
@@ -506,25 +507,7 @@ func registerThroughAuth(
506507	ctx , span  :=  tracer .Start (ctx , "registerThroughAuth" )
507508	defer  func () { tracing .EndSpan (span , err ) }()
508509
509- 	var  client  * authclient.Client 
510- 	// Build a client for the Auth Server with different certificate validation 
511- 	// depending on the configured values for Insecure, CAPins and CAPath. 
512- 	switch  {
513- 	case  params .Insecure :
514- 		slog .WarnContext (ctx , "Insecure mode enabled. Auth Server cert will not be validated and CAPins and CAPath value will be ignored." )
515- 		client , err  =  insecureRegisterClient (ctx , params )
516- 	case  len (params .CAPins ) !=  0 :
517- 		// CAPins takes precedence over CAPath 
518- 		client , err  =  pinRegisterClient (ctx , params )
519- 	case  params .CAPath  !=  "" :
520- 		client , err  =  caPathRegisterClient (ctx , params )
521- 	default :
522- 		// We fall back to insecure mode here - this is a little odd but is 
523- 		// necessary to preserve the behavior of registration. At a later date, 
524- 		// we may consider making this an error asking the user to provide 
525- 		// Insecure, CAPins or CAPath. 
526- 		client , err  =  insecureRegisterClient (ctx , params )
527- 	}
510+ 	client , err  :=  NewAuthClient (ctx , params )
528511	if  err  !=  nil  {
529512		return  nil , trace .Wrap (err , "building auth client" )
530513	}
@@ -540,6 +523,7 @@ type AuthJoinClient interface {
540523	joinServiceClient 
541524	RegisterUsingToken (ctx  context.Context , req  * types.RegisterUsingTokenRequest ) (* proto.Certs , error )
542525	Ping (ctx  context.Context ) (proto.PingResponse , error )
526+ 	JoinV1Client () joinv1.JoinServiceClient 
543527}
544528
545529func  registerThroughAuthClient (
@@ -593,6 +577,28 @@ func getHostAddresses(params RegisterParams) []string {
593577	return  utils .NetAddrsToStrings (params .AuthServers )
594578}
595579
580+ // NewAuthClient returns a new auth client built according to the register 
581+ // params, preferring the authenticate the server via CA pins or a CA path and 
582+ // falling back to an insecure connection, unless insecure mode was explicitly enabled. 
583+ func  NewAuthClient (ctx  context.Context , params  RegisterParams ) (* authclient.Client , error ) {
584+ 	switch  {
585+ 	case  params .Insecure :
586+ 		slog .WarnContext (ctx , "Insecure mode enabled. Auth Server cert will not be validated and CAPins and CAPath value will be ignored." )
587+ 		return  insecureRegisterClient (ctx , params )
588+ 	case  len (params .CAPins ) !=  0 :
589+ 		// CAPins takes precedence over CAPath 
590+ 		return  pinRegisterClient (ctx , params )
591+ 	case  params .CAPath  !=  "" :
592+ 		return  caPathRegisterClient (ctx , params )
593+ 	default :
594+ 		// We fall back to insecure mode here - this is a little odd but is 
595+ 		// necessary to preserve the behavior of registration. At a later date, 
596+ 		// we may consider making this an error asking the user to provide 
597+ 		// Insecure, CAPins or CAPath. 
598+ 		return  insecureRegisterClient (ctx , params )
599+ 	}
600+ }
601+ 
596602// insecureRegisterClient attempts to connects to the Auth Server using the 
597603// CA on disk. If no CA is found on disk, Teleport will not verify the Auth 
598604// Server it is connecting to. 
0 commit comments