TUN-9007: modify logic to resolve region when the tunnel token has an endpoint field
## Summary Within the work of FEDRamp it is necessary to change the HA SD lookup to use as srv `fed-v2-origintunneld` This work assumes that the tunnel token has an optional endpoint field which will be used to modify the behaviour of the HA SD lookup. Finally, the presence of the endpoint will override region to _fed_ and fail if any value is passed for the flag region. Closes TUN-9007
This commit is contained in:
parent
906452a9c9
commit
6496322bee
|
@ -34,6 +34,7 @@ import (
|
||||||
const (
|
const (
|
||||||
secretValue = "*****"
|
secretValue = "*****"
|
||||||
icmpFunnelTimeout = time.Second * 10
|
icmpFunnelTimeout = time.Second * 10
|
||||||
|
fedRampRegion = "fed" // const string denoting the region used to connect to FEDRamp servers
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -208,13 +209,27 @@ func prepareTunnelConfig(
|
||||||
log.Warn().Str("edgeIPVersion", edgeIPVersion.String()).Err(err).Msg("Overriding edge-ip-version")
|
log.Warn().Str("edgeIPVersion", edgeIPVersion.String()).Err(err).Msg("Overriding edge-ip-version")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
region := c.String(flags.Region)
|
||||||
|
endpoint := namedTunnel.Credentials.Endpoint
|
||||||
|
var resolvedRegion string
|
||||||
|
// set resolvedRegion to either the region passed as argument
|
||||||
|
// or to the endpoint in the credentials.
|
||||||
|
// Region and endpoint are interchangeable
|
||||||
|
if region != "" && endpoint != "" {
|
||||||
|
return nil, nil, fmt.Errorf("region provided with a token that has an endpoint")
|
||||||
|
} else if region != "" {
|
||||||
|
resolvedRegion = region
|
||||||
|
} else if endpoint != "" {
|
||||||
|
resolvedRegion = endpoint
|
||||||
|
}
|
||||||
|
|
||||||
tunnelConfig := &supervisor.TunnelConfig{
|
tunnelConfig := &supervisor.TunnelConfig{
|
||||||
GracePeriod: gracePeriod,
|
GracePeriod: gracePeriod,
|
||||||
ReplaceExisting: c.Bool(flags.Force),
|
ReplaceExisting: c.Bool(flags.Force),
|
||||||
OSArch: info.OSArch(),
|
OSArch: info.OSArch(),
|
||||||
ClientID: clientID.String(),
|
ClientID: clientID.String(),
|
||||||
EdgeAddrs: c.StringSlice(flags.Edge),
|
EdgeAddrs: c.StringSlice(flags.Edge),
|
||||||
Region: c.String(flags.Region),
|
Region: resolvedRegion,
|
||||||
EdgeIPVersion: edgeIPVersion,
|
EdgeIPVersion: edgeIPVersion,
|
||||||
EdgeBindAddr: edgeBindAddr,
|
EdgeBindAddr: edgeBindAddr,
|
||||||
HAConnections: c.Int(flags.HaConnections),
|
HAConnections: c.Int(flags.HaConnections),
|
||||||
|
|
|
@ -60,6 +60,7 @@ type Credentials struct {
|
||||||
AccountTag string
|
AccountTag string
|
||||||
TunnelSecret []byte
|
TunnelSecret []byte
|
||||||
TunnelID uuid.UUID
|
TunnelID uuid.UUID
|
||||||
|
Endpoint string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Credentials) Auth() pogs.TunnelAuth {
|
func (c *Credentials) Auth() pogs.TunnelAuth {
|
||||||
|
@ -74,13 +75,16 @@ type TunnelToken struct {
|
||||||
AccountTag string `json:"a"`
|
AccountTag string `json:"a"`
|
||||||
TunnelSecret []byte `json:"s"`
|
TunnelSecret []byte `json:"s"`
|
||||||
TunnelID uuid.UUID `json:"t"`
|
TunnelID uuid.UUID `json:"t"`
|
||||||
|
Endpoint string `json:"e,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t TunnelToken) Credentials() Credentials {
|
func (t TunnelToken) Credentials() Credentials {
|
||||||
|
// nolint: gosimple
|
||||||
return Credentials{
|
return Credentials{
|
||||||
AccountTag: t.AccountTag,
|
AccountTag: t.AccountTag,
|
||||||
TunnelSecret: t.TunnelSecret,
|
TunnelSecret: t.TunnelSecret,
|
||||||
TunnelID: t.TunnelID,
|
TunnelID: t.TunnelID,
|
||||||
|
Endpoint: t.Endpoint,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -247,9 +247,7 @@ func (s *Supervisor) startFirstTunnel(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
connectedSignal *signal.Signal,
|
connectedSignal *signal.Signal,
|
||||||
) {
|
) {
|
||||||
var (
|
var err error
|
||||||
err error
|
|
||||||
)
|
|
||||||
const firstConnIndex = 0
|
const firstConnIndex = 0
|
||||||
isStaticEdge := len(s.config.EdgeAddrs) > 0
|
isStaticEdge := len(s.config.EdgeAddrs) > 0
|
||||||
defer func() {
|
defer func() {
|
||||||
|
@ -300,9 +298,7 @@ func (s *Supervisor) startTunnel(
|
||||||
index int,
|
index int,
|
||||||
connectedSignal *signal.Signal,
|
connectedSignal *signal.Signal,
|
||||||
) {
|
) {
|
||||||
var (
|
var err error
|
||||||
err error
|
|
||||||
)
|
|
||||||
defer func() {
|
defer func() {
|
||||||
s.tunnelErrors <- tunnelError{index: index, err: err}
|
s.tunnelErrors <- tunnelError{index: index, err: err}
|
||||||
}()
|
}()
|
||||||
|
|
Loading…
Reference in New Issue