Skip to content

Commit a0f6eb9

Browse files
committed
TUN-5992: Use QUIC protocol for remotely managed tunnels when protocol is unspecified
1 parent 12302ba commit a0f6eb9

File tree

4 files changed

+24
-18
lines changed

4 files changed

+24
-18
lines changed

cmd/cloudflared/tunnel/configuration.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,9 @@ func prepareTunnelConfig(
214214
ingressRules ingress.Ingress
215215
classicTunnel *connection.ClassicTunnelProperties
216216
)
217+
218+
transportProtocol := c.String("protocol")
219+
217220
cfg := config.GetConfiguration()
218221
if isNamedTunnel {
219222
clientUUID, err := uuid.NewRandom()
@@ -223,8 +226,11 @@ func prepareTunnelConfig(
223226
log.Info().Msgf("Generated Connector ID: %s", clientUUID)
224227
features := append(c.StringSlice("features"), supervisor.FeatureSerializedHeaders)
225228
if c.IsSet(TunnelTokenFlag) {
229+
if transportProtocol == connection.AutoSelectFlag {
230+
transportProtocol = connection.QUIC.String()
231+
}
226232
features = append(features, supervisor.FeatureAllowRemoteConfig)
227-
log.Info().Msg("Will be fetching remotely managed configuration from Cloudflare API")
233+
log.Info().Msg("Will be fetching remotely managed configuration from Cloudflare API. Defaulting to protocol: quic")
228234
}
229235
namedTunnel.Client = tunnelpogs.ClientInfo{
230236
ClientID: clientUUID[:],
@@ -268,7 +274,7 @@ func prepareTunnelConfig(
268274
}
269275

270276
warpRoutingEnabled := isWarpRoutingEnabled(cfg.WarpRouting, isNamedTunnel)
271-
protocolSelector, err := connection.NewProtocolSelector(c.String("protocol"), warpRoutingEnabled, namedTunnel, edgediscovery.ProtocolPercentage, supervisor.ResolveTTL, log)
277+
protocolSelector, err := connection.NewProtocolSelector(transportProtocol, warpRoutingEnabled, namedTunnel, edgediscovery.ProtocolPercentage, supervisor.ResolveTTL, log)
272278
if err != nil {
273279
return nil, nil, err
274280
}

cmd/cloudflared/tunnel/subcommands.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ var (
134134
}
135135
selectProtocolFlag = altsrc.NewStringFlag(&cli.StringFlag{
136136
Name: "protocol",
137-
Value: "auto",
137+
Value: connection.AutoSelectFlag,
138138
Aliases: []string{"p"},
139139
Usage: fmt.Sprintf("Protocol implementation to connect with Cloudflare's edge network. %s", connection.AvailableProtocolFlagMessage),
140140
EnvVars: []string{"TUNNEL_TRANSPORT_PROTOCOL"},

connection/protocol.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const (
1919
edgeH2TLSServerName = "h2.cftunnel.com"
2020
// edgeQUICServerName is the server name to establish quic connection with edge.
2121
edgeQUICServerName = "quic.cftunnel.com"
22-
autoSelectFlag = "auto"
22+
AutoSelectFlag = "auto"
2323
)
2424

2525
var (
@@ -247,7 +247,7 @@ func selectNamedTunnelProtocols(
247247

248248
// If the user does not pick (hopefully the majority) then we use the one derived from the TXT DNS record and
249249
// fallback on failures.
250-
if protocolFlag == autoSelectFlag {
250+
if protocolFlag == AutoSelectFlag {
251251
return newAutoProtocolSelector(protocol, []Protocol{QUIC, HTTP2, H2mux}, threshold, fetchFunc, ttl, log), nil
252252
}
253253

@@ -272,7 +272,7 @@ func selectWarpRoutingProtocols(
272272

273273
// If the user does not pick (hopefully the majority) then we use the one derived from the TXT DNS record and
274274
// fallback on failures.
275-
if protocolFlag == autoSelectFlag {
275+
if protocolFlag == AutoSelectFlag {
276276
return newAutoProtocolSelector(protocol, []Protocol{QUICWarp, HTTP2Warp}, threshold, fetchFunc, ttl, log), nil
277277
}
278278

connection/protocol_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,14 @@ func TestNewProtocolSelector(t *testing.T) {
9191
},
9292
{
9393
name: "named tunnel quic and http2 disabled",
94-
protocol: "auto",
94+
protocol: AutoSelectFlag,
9595
expectedProtocol: H2mux,
9696
fetchFunc: mockFetcher(false, edgediscovery.ProtocolPercent{Protocol: "http2", Percentage: -1}, edgediscovery.ProtocolPercent{Protocol: "quic", Percentage: -1}),
9797
namedTunnelConfig: testNamedTunnelProperties,
9898
},
9999
{
100100
name: "named tunnel quic disabled",
101-
protocol: "auto",
101+
protocol: AutoSelectFlag,
102102
expectedProtocol: HTTP2,
103103
// Hasfallback true is because if http2 fails, then we further fallback to h2mux.
104104
hasFallback: true,
@@ -108,21 +108,21 @@ func TestNewProtocolSelector(t *testing.T) {
108108
},
109109
{
110110
name: "named tunnel auto all http2 disabled",
111-
protocol: "auto",
111+
protocol: AutoSelectFlag,
112112
expectedProtocol: H2mux,
113113
fetchFunc: mockFetcher(false, edgediscovery.ProtocolPercent{Protocol: "http2", Percentage: -1}),
114114
namedTunnelConfig: testNamedTunnelProperties,
115115
},
116116
{
117117
name: "named tunnel auto to h2mux",
118-
protocol: "auto",
118+
protocol: AutoSelectFlag,
119119
expectedProtocol: H2mux,
120120
fetchFunc: mockFetcher(false, edgediscovery.ProtocolPercent{Protocol: "http2", Percentage: 0}),
121121
namedTunnelConfig: testNamedTunnelProperties,
122122
},
123123
{
124124
name: "named tunnel auto to http2",
125-
protocol: "auto",
125+
protocol: AutoSelectFlag,
126126
expectedProtocol: HTTP2,
127127
hasFallback: true,
128128
expectedFallback: H2mux,
@@ -131,7 +131,7 @@ func TestNewProtocolSelector(t *testing.T) {
131131
},
132132
{
133133
name: "named tunnel auto to quic",
134-
protocol: "auto",
134+
protocol: AutoSelectFlag,
135135
expectedProtocol: QUIC,
136136
hasFallback: true,
137137
expectedFallback: HTTP2,
@@ -167,7 +167,7 @@ func TestNewProtocolSelector(t *testing.T) {
167167
},
168168
{
169169
name: "warp routing quic",
170-
protocol: "auto",
170+
protocol: AutoSelectFlag,
171171
expectedProtocol: QUICWarp,
172172
hasFallback: true,
173173
expectedFallback: HTTP2Warp,
@@ -177,7 +177,7 @@ func TestNewProtocolSelector(t *testing.T) {
177177
},
178178
{
179179
name: "warp routing auto",
180-
protocol: "auto",
180+
protocol: AutoSelectFlag,
181181
expectedProtocol: HTTP2Warp,
182182
hasFallback: false,
183183
fetchFunc: mockFetcher(false, edgediscovery.ProtocolPercent{Protocol: "http2", Percentage: 100}),
@@ -186,7 +186,7 @@ func TestNewProtocolSelector(t *testing.T) {
186186
},
187187
{
188188
name: "warp routing auto- quic",
189-
protocol: "auto",
189+
protocol: AutoSelectFlag,
190190
expectedProtocol: QUICWarp,
191191
hasFallback: true,
192192
expectedFallback: HTTP2Warp,
@@ -209,7 +209,7 @@ func TestNewProtocolSelector(t *testing.T) {
209209
},
210210
{
211211
name: "named tunnel fetch error",
212-
protocol: "auto",
212+
protocol: AutoSelectFlag,
213213
fetchFunc: mockFetcher(true),
214214
namedTunnelConfig: testNamedTunnelProperties,
215215
expectedProtocol: HTTP2,
@@ -237,7 +237,7 @@ func TestNewProtocolSelector(t *testing.T) {
237237

238238
func TestAutoProtocolSelectorRefresh(t *testing.T) {
239239
fetcher := dynamicMockFetcher{}
240-
selector, err := NewProtocolSelector("auto", noWarpRoutingEnabled, testNamedTunnelProperties, fetcher.fetch(), testNoTTL, &log)
240+
selector, err := NewProtocolSelector(AutoSelectFlag, noWarpRoutingEnabled, testNamedTunnelProperties, fetcher.fetch(), testNoTTL, &log)
241241
assert.NoError(t, err)
242242
assert.Equal(t, H2mux, selector.Current())
243243

@@ -297,7 +297,7 @@ func TestHTTP2ProtocolSelectorRefresh(t *testing.T) {
297297
func TestProtocolSelectorRefreshTTL(t *testing.T) {
298298
fetcher := dynamicMockFetcher{}
299299
fetcher.protocolPercents = edgediscovery.ProtocolPercents{edgediscovery.ProtocolPercent{Protocol: "quic", Percentage: 100}}
300-
selector, err := NewProtocolSelector("auto", noWarpRoutingEnabled, testNamedTunnelProperties, fetcher.fetch(), time.Hour, &log)
300+
selector, err := NewProtocolSelector(AutoSelectFlag, noWarpRoutingEnabled, testNamedTunnelProperties, fetcher.fetch(), time.Hour, &log)
301301
assert.NoError(t, err)
302302
assert.Equal(t, QUIC, selector.Current())
303303

0 commit comments

Comments
 (0)