@@ -32,7 +32,6 @@ import (
3232 "github.com/cloudflare/cloudflared/supervisor"
3333 "github.com/cloudflare/cloudflared/tlsconfig"
3434 tunnelpogs "github.com/cloudflare/cloudflared/tunnelrpc/pogs"
35- "github.com/cloudflare/cloudflared/validation"
3635)
3736
3837const LogFieldOriginCertPath = "originCertPath"
4342 serviceUrl = developerPortal + "/reference/service/"
4443 argumentsUrl = developerPortal + "/reference/arguments/"
4544
46- LogFieldHostname = "hostname"
47-
4845 secretFlags = [2 ]* altsrc.StringFlag {credentialsContentsFlag , tunnelTokenFlag }
4946 defaultFeatures = []string {supervisor .FeatureAllowRemoteConfig , supervisor .FeatureSerializedHeaders , supervisor .FeatureDatagramV2 , supervisor .FeatureQUICSupportEOF }
5047
@@ -127,7 +124,7 @@ func isSecretEnvVar(key string) bool {
127124}
128125
129126func dnsProxyStandAlone (c * cli.Context , namedTunnel * connection.NamedTunnelProperties ) bool {
130- return c .IsSet ("proxy-dns" ) && (! c .IsSet ("hostname" ) && ! c . IsSet ( " tag" ) && ! c .IsSet ("hello-world" ) && namedTunnel == nil )
127+ return c .IsSet ("proxy-dns" ) && (! c .IsSet ("tag" ) && ! c .IsSet ("hello-world" ) && namedTunnel == nil )
131128}
132129
133130func findOriginCert (originCertPath string , log * zerolog.Logger ) (string , error ) {
@@ -193,37 +190,19 @@ func prepareTunnelConfig(
193190 observer * connection.Observer ,
194191 namedTunnel * connection.NamedTunnelProperties ,
195192) (* supervisor.TunnelConfig , * orchestration.Config , error ) {
196- isNamedTunnel := namedTunnel != nil
197-
198- configHostname := c .String ("hostname" )
199- hostname , err := validation .ValidateHostname (configHostname )
193+ clientID , err := uuid .NewRandom ()
200194 if err != nil {
201- log .Err (err ).Str (LogFieldHostname , configHostname ).Msg ("Invalid hostname" )
202- return nil , nil , errors .Wrap (err , "Invalid hostname" )
203- }
204- clientID := c .String ("id" )
205- if ! c .IsSet ("id" ) {
206- clientID , err = generateRandomClientID (log )
207- if err != nil {
208- return nil , nil , err
209- }
195+ return nil , nil , errors .Wrap (err , "can't generate connector UUID" )
210196 }
211-
197+ log . Info (). Msgf ( "Generated Connector ID: %s" , clientID )
212198 tags , err := NewTagSliceFromCLI (c .StringSlice ("tag" ))
213199 if err != nil {
214200 log .Err (err ).Msg ("Tag parse failure" )
215201 return nil , nil , errors .Wrap (err , "Tag parse failure" )
216202 }
217-
218- tags = append (tags , tunnelpogs.Tag {Name : "ID" , Value : clientID })
219-
220- var (
221- ingressRules ingress.Ingress
222- classicTunnel * connection.ClassicTunnelProperties
223- )
203+ tags = append (tags , tunnelpogs.Tag {Name : "ID" , Value : clientID .String ()})
224204
225205 transportProtocol := c .String ("protocol" )
226-
227206 needPQ := c .Bool ("post-quantum" )
228207 if needPQ {
229208 if FipsEnabled {
@@ -238,79 +217,52 @@ func prepareTunnelConfig(
238217
239218 protocolFetcher := edgediscovery .ProtocolPercentage
240219
241- cfg := config .GetConfiguration ()
242- if isNamedTunnel {
243- clientUUID , err := uuid .NewRandom ()
244- if err != nil {
245- return nil , nil , errors .Wrap (err , "can't generate connector UUID" )
246- }
247- log .Info ().Msgf ("Generated Connector ID: %s" , clientUUID )
248- features := append (c .StringSlice ("features" ), defaultFeatures ... )
249- if needPQ {
250- features = append (features , supervisor .FeaturePostQuantum )
251- }
252- if c .IsSet (TunnelTokenFlag ) {
253- if transportProtocol == connection .AutoSelectFlag {
254- protocolFetcher = func () (edgediscovery.ProtocolPercents , error ) {
255- // If the Tunnel is remotely managed and no protocol is set, we prefer QUIC, but still allow fall-back.
256- preferQuic := []edgediscovery.ProtocolPercent {
257- {
258- Protocol : connection .QUIC .String (),
259- Percentage : 100 ,
260- },
261- {
262- Protocol : connection .HTTP2 .String (),
263- Percentage : 100 ,
264- },
265- }
266- return preferQuic , nil
220+ features := append (c .StringSlice ("features" ), defaultFeatures ... )
221+ if needPQ {
222+ features = append (features , supervisor .FeaturePostQuantum )
223+ }
224+ if c .IsSet (TunnelTokenFlag ) {
225+ if transportProtocol == connection .AutoSelectFlag {
226+ protocolFetcher = func () (edgediscovery.ProtocolPercents , error ) {
227+ // If the Tunnel is remotely managed and no protocol is set, we prefer QUIC, but still allow fall-back.
228+ preferQuic := []edgediscovery.ProtocolPercent {
229+ {
230+ Protocol : connection .QUIC .String (),
231+ Percentage : 100 ,
232+ },
233+ {
234+ Protocol : connection .HTTP2 .String (),
235+ Percentage : 100 ,
236+ },
267237 }
238+ return preferQuic , nil
268239 }
269- log .Info ().Msg ("Will be fetching remotely managed configuration from Cloudflare API. Defaulting to protocol: quic" )
270- }
271- namedTunnel .Client = tunnelpogs.ClientInfo {
272- ClientID : clientUUID [:],
273- Features : dedup (features ),
274- Version : info .Version (),
275- Arch : info .OSArch (),
276- }
277- ingressRules , err = ingress .ParseIngress (cfg )
278- if err != nil && err != ingress .ErrNoIngressRules {
279- return nil , nil , err
280- }
281- if ! ingressRules .IsEmpty () && c .IsSet ("url" ) {
282- return nil , nil , ingress .ErrURLIncompatibleWithIngress
283- }
284- } else {
285-
286- originCertPath := c .String ("origincert" )
287- originCertLog := log .With ().
288- Str (LogFieldOriginCertPath , originCertPath ).
289- Logger ()
290-
291- originCert , err := getOriginCert (originCertPath , & originCertLog )
292- if err != nil {
293- return nil , nil , errors .Wrap (err , "Error getting origin cert" )
294- }
295-
296- classicTunnel = & connection.ClassicTunnelProperties {
297- Hostname : hostname ,
298- OriginCert : originCert ,
299- // turn off use of reconnect token and auth refresh when using named tunnels
300- UseReconnectToken : ! isNamedTunnel && c .Bool ("use-reconnect-token" ),
301240 }
241+ log .Info ().Msg ("Will be fetching remotely managed configuration from Cloudflare API. Defaulting to protocol: quic" )
302242 }
303-
304- // Convert single-origin configuration into multi-origin configuration.
305- if ingressRules .IsEmpty () {
306- ingressRules , err = ingress .NewSingleOrigin (c , ! isNamedTunnel )
243+ namedTunnel .Client = tunnelpogs.ClientInfo {
244+ ClientID : clientID [:],
245+ Features : dedup (features ),
246+ Version : info .Version (),
247+ Arch : info .OSArch (),
248+ }
249+ cfg := config .GetConfiguration ()
250+ ingressRules , err := ingress .ParseIngress (cfg )
251+ if err != nil && err != ingress .ErrNoIngressRules {
252+ return nil , nil , err
253+ }
254+ // Only for quick tunnels will we attempt to parse the --url flag for a tunnel ingress rule
255+ if ingressRules .IsEmpty () && c .IsSet ("url" ) && namedTunnel .QuickTunnelUrl != "" {
256+ ingressRules , err = ingress .NewSingleOrigin (c , true )
307257 if err != nil {
308258 return nil , nil , err
309259 }
310260 }
261+ if ingressRules .IsEmpty () {
262+ return nil , nil , ingress .ErrNoIngressRules
263+ }
311264
312- warpRoutingEnabled := isWarpRoutingEnabled (cfg .WarpRouting , isNamedTunnel )
313- protocolSelector , err := connection .NewProtocolSelector (transportProtocol , warpRoutingEnabled , namedTunnel , protocolFetcher , supervisor .ResolveTTL , log , c .Bool ("post-quantum" ))
265+ protocolSelector , err := connection .NewProtocolSelector (transportProtocol , cfg .WarpRouting .Enabled , namedTunnel , protocolFetcher , supervisor .ResolveTTL , log , c .Bool ("post-quantum" ))
314266 if err != nil {
315267 return nil , nil , err
316268 }
@@ -362,7 +314,7 @@ func prepareTunnelConfig(
362314 GracePeriod : gracePeriod ,
363315 ReplaceExisting : c .Bool ("force" ),
364316 OSArch : info .OSArch (),
365- ClientID : clientID ,
317+ ClientID : clientID . String () ,
366318 EdgeAddrs : c .StringSlice ("edge" ),
367319 Region : c .String ("region" ),
368320 EdgeIPVersion : edgeIPVersion ,
@@ -379,7 +331,6 @@ func prepareTunnelConfig(
379331 Retries : uint (c .Int ("retries" )),
380332 RunFromTerminal : isRunningFromTerminal (),
381333 NamedTunnel : namedTunnel ,
382- ClassicTunnel : classicTunnel ,
383334 MuxerConfig : muxerConfig ,
384335 ProtocolSelector : protocolSelector ,
385336 EdgeTLSConfigs : edgeTLSConfigs ,
@@ -421,10 +372,6 @@ func gracePeriod(c *cli.Context) (time.Duration, error) {
421372 return period , nil
422373}
423374
424- func isWarpRoutingEnabled (warpConfig config.WarpRoutingConfig , isNamedTunnel bool ) bool {
425- return warpConfig .Enabled && isNamedTunnel
426- }
427-
428375func isRunningFromTerminal () bool {
429376 return terminal .IsTerminal (int (os .Stdout .Fd ()))
430377}
0 commit comments