Skip to content

Commit 6496322

Browse files
committed
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
1 parent 906452a commit 6496322

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

cmd/cloudflared/tunnel/configuration.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
const (
3535
secretValue = "*****"
3636
icmpFunnelTimeout = time.Second * 10
37+
fedRampRegion = "fed" // const string denoting the region used to connect to FEDRamp servers
3738
)
3839

3940
var (
@@ -208,13 +209,27 @@ func prepareTunnelConfig(
208209
log.Warn().Str("edgeIPVersion", edgeIPVersion.String()).Err(err).Msg("Overriding edge-ip-version")
209210
}
210211

212+
region := c.String(flags.Region)
213+
endpoint := namedTunnel.Credentials.Endpoint
214+
var resolvedRegion string
215+
// set resolvedRegion to either the region passed as argument
216+
// or to the endpoint in the credentials.
217+
// Region and endpoint are interchangeable
218+
if region != "" && endpoint != "" {
219+
return nil, nil, fmt.Errorf("region provided with a token that has an endpoint")
220+
} else if region != "" {
221+
resolvedRegion = region
222+
} else if endpoint != "" {
223+
resolvedRegion = endpoint
224+
}
225+
211226
tunnelConfig := &supervisor.TunnelConfig{
212227
GracePeriod: gracePeriod,
213228
ReplaceExisting: c.Bool(flags.Force),
214229
OSArch: info.OSArch(),
215230
ClientID: clientID.String(),
216231
EdgeAddrs: c.StringSlice(flags.Edge),
217-
Region: c.String(flags.Region),
232+
Region: resolvedRegion,
218233
EdgeIPVersion: edgeIPVersion,
219234
EdgeBindAddr: edgeBindAddr,
220235
HAConnections: c.Int(flags.HaConnections),

connection/connection.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ type Credentials struct {
6060
AccountTag string
6161
TunnelSecret []byte
6262
TunnelID uuid.UUID
63+
Endpoint string
6364
}
6465

6566
func (c *Credentials) Auth() pogs.TunnelAuth {
@@ -74,13 +75,16 @@ type TunnelToken struct {
7475
AccountTag string `json:"a"`
7576
TunnelSecret []byte `json:"s"`
7677
TunnelID uuid.UUID `json:"t"`
78+
Endpoint string `json:"e,omitempty"`
7779
}
7880

7981
func (t TunnelToken) Credentials() Credentials {
82+
// nolint: gosimple
8083
return Credentials{
8184
AccountTag: t.AccountTag,
8285
TunnelSecret: t.TunnelSecret,
8386
TunnelID: t.TunnelID,
87+
Endpoint: t.Endpoint,
8488
}
8589
}
8690

supervisor/supervisor.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,7 @@ func (s *Supervisor) startFirstTunnel(
247247
ctx context.Context,
248248
connectedSignal *signal.Signal,
249249
) {
250-
var (
251-
err error
252-
)
250+
var err error
253251
const firstConnIndex = 0
254252
isStaticEdge := len(s.config.EdgeAddrs) > 0
255253
defer func() {
@@ -300,9 +298,7 @@ func (s *Supervisor) startTunnel(
300298
index int,
301299
connectedSignal *signal.Signal,
302300
) {
303-
var (
304-
err error
305-
)
301+
var err error
306302
defer func() {
307303
s.tunnelErrors <- tunnelError{index: index, err: err}
308304
}()

0 commit comments

Comments
 (0)