Skip to content

Commit

Permalink
alts: re-add vmOnGCP and once globals for easier testing (#4284)
Browse files Browse the repository at this point in the history
  • Loading branch information
dfawley authored Mar 23, 2021
1 parent d26af8e commit b331a48
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions credentials/alts/alts.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"errors"
"fmt"
"net"
"sync"
"time"

"google.golang.org/grpc/credentials"
Expand All @@ -54,6 +55,8 @@ const (
)

var (
vmOnGCP bool
once sync.Once
maxRPCVersion = &altspb.RpcProtocolVersions_Version{
Major: protocolVersionMaxMajor,
Minor: protocolVersionMaxMinor,
Expand Down Expand Up @@ -147,6 +150,9 @@ func NewServerCreds(opts *ServerOptions) credentials.TransportCredentials {
}

func newALTS(side core.Side, accounts []string, hsAddress string) credentials.TransportCredentials {
once.Do(func() {
vmOnGCP = googlecloud.OnGCE()
})
if hsAddress == "" {
hsAddress = hypervisorHandshakerServiceAddress
}
Expand All @@ -163,7 +169,7 @@ func newALTS(side core.Side, accounts []string, hsAddress string) credentials.Tr

// ClientHandshake implements the client side handshake protocol.
func (g *altsTC) ClientHandshake(ctx context.Context, addr string, rawConn net.Conn) (_ net.Conn, _ credentials.AuthInfo, err error) {
if !googlecloud.OnGCE() {
if !vmOnGCP {
return nil, nil, ErrUntrustedPlatform
}

Expand Down Expand Up @@ -218,7 +224,7 @@ func (g *altsTC) ClientHandshake(ctx context.Context, addr string, rawConn net.C

// ServerHandshake implements the server side ALTS handshaker.
func (g *altsTC) ServerHandshake(rawConn net.Conn) (_ net.Conn, _ credentials.AuthInfo, err error) {
if !googlecloud.OnGCE() {
if !vmOnGCP {
return nil, nil, ErrUntrustedPlatform
}
// Connecting to ALTS handshaker service.
Expand Down

0 comments on commit b331a48

Please sign in to comment.