TUN-7333: Default features checkable at runtime across all packages

This commit is contained in:
Devin Carr 2023-03-29 13:12:32 -07:00
parent b5e03dd66c
commit bbc8d9431b
4 changed files with 45 additions and 18 deletions

View File

@ -28,6 +28,7 @@ import (
"github.com/cloudflare/cloudflared/cmd/cloudflared/updater" "github.com/cloudflare/cloudflared/cmd/cloudflared/updater"
"github.com/cloudflare/cloudflared/config" "github.com/cloudflare/cloudflared/config"
"github.com/cloudflare/cloudflared/connection" "github.com/cloudflare/cloudflared/connection"
"github.com/cloudflare/cloudflared/features"
"github.com/cloudflare/cloudflared/ingress" "github.com/cloudflare/cloudflared/ingress"
"github.com/cloudflare/cloudflared/logger" "github.com/cloudflare/cloudflared/logger"
"github.com/cloudflare/cloudflared/management" "github.com/cloudflare/cloudflared/management"
@ -398,8 +399,11 @@ func StartServer(
} }
} }
mgmt := management.New(c.String("management-hostname")) localRules := []ingress.Rule{}
localRules := []ingress.Rule{ingress.NewManagementRule(mgmt)} if features.Contains(features.FeatureManagementLogs) {
mgmt := management.New(c.String("management-hostname"))
localRules = []ingress.Rule{ingress.NewManagementRule(mgmt)}
}
orchestrator, err := orchestration.NewOrchestrator(ctx, orchestratorConfig, tunnelConfig.Tags, localRules, tunnelConfig.Log) orchestrator, err := orchestration.NewOrchestrator(ctx, orchestratorConfig, tunnelConfig.Tags, localRules, tunnelConfig.Log)
if err != nil { if err != nil {
return err return err

View File

@ -25,6 +25,7 @@ import (
"github.com/cloudflare/cloudflared/connection" "github.com/cloudflare/cloudflared/connection"
"github.com/cloudflare/cloudflared/edgediscovery" "github.com/cloudflare/cloudflared/edgediscovery"
"github.com/cloudflare/cloudflared/edgediscovery/allregions" "github.com/cloudflare/cloudflared/edgediscovery/allregions"
"github.com/cloudflare/cloudflared/features"
"github.com/cloudflare/cloudflared/ingress" "github.com/cloudflare/cloudflared/ingress"
"github.com/cloudflare/cloudflared/orchestration" "github.com/cloudflare/cloudflared/orchestration"
"github.com/cloudflare/cloudflared/supervisor" "github.com/cloudflare/cloudflared/supervisor"
@ -40,8 +41,7 @@ var (
serviceUrl = developerPortal + "/reference/service/" serviceUrl = developerPortal + "/reference/service/"
argumentsUrl = developerPortal + "/reference/arguments/" argumentsUrl = developerPortal + "/reference/arguments/"
secretFlags = [2]*altsrc.StringFlag{credentialsContentsFlag, tunnelTokenFlag} secretFlags = [2]*altsrc.StringFlag{credentialsContentsFlag, tunnelTokenFlag}
defaultFeatures = []string{supervisor.FeatureAllowRemoteConfig, supervisor.FeatureSerializedHeaders, supervisor.FeatureDatagramV2, supervisor.FeatureQUICSupportEOF}
configFlags = []string{"autoupdate-freq", "no-autoupdate", "retries", "protocol", "loglevel", "transport-loglevel", "origincert", "metrics", "metrics-update-freq", "edge-ip-version", "edge-bind-address"} configFlags = []string{"autoupdate-freq", "no-autoupdate", "retries", "protocol", "loglevel", "transport-loglevel", "origincert", "metrics", "metrics-update-freq", "edge-ip-version", "edge-bind-address"}
) )
@ -216,13 +216,13 @@ func prepareTunnelConfig(
transportProtocol = connection.QUIC.String() transportProtocol = connection.QUIC.String()
} }
features := dedup(append(c.StringSlice("features"), defaultFeatures...)) clientFeatures := dedup(append(c.StringSlice("features"), features.DefaultFeatures...))
if needPQ { if needPQ {
features = append(features, supervisor.FeaturePostQuantum) clientFeatures = append(clientFeatures, features.FeaturePostQuantum)
} }
namedTunnel.Client = tunnelpogs.ClientInfo{ namedTunnel.Client = tunnelpogs.ClientInfo{
ClientID: clientID[:], ClientID: clientID[:],
Features: features, Features: clientFeatures,
Version: info.Version(), Version: info.Version(),
Arch: info.OSArch(), Arch: info.OSArch(),
} }

29
features/features.go Normal file
View File

@ -0,0 +1,29 @@
package features
const (
FeatureSerializedHeaders = "serialized_headers"
FeatureQuickReconnects = "quick_reconnects"
FeatureAllowRemoteConfig = "allow_remote_config"
FeatureDatagramV2 = "support_datagram_v2"
FeaturePostQuantum = "postquantum"
FeatureQUICSupportEOF = "support_quic_eof"
FeatureManagementLogs = "management_logs"
)
var (
DefaultFeatures = []string{
FeatureAllowRemoteConfig,
FeatureSerializedHeaders,
FeatureDatagramV2,
FeatureQUICSupportEOF,
}
)
func Contains(feature string) bool {
for _, f := range DefaultFeatures {
if f == feature {
return true
}
}
return false
}

View File

@ -19,6 +19,7 @@ import (
"github.com/cloudflare/cloudflared/connection" "github.com/cloudflare/cloudflared/connection"
"github.com/cloudflare/cloudflared/edgediscovery" "github.com/cloudflare/cloudflared/edgediscovery"
"github.com/cloudflare/cloudflared/edgediscovery/allregions" "github.com/cloudflare/cloudflared/edgediscovery/allregions"
"github.com/cloudflare/cloudflared/features"
"github.com/cloudflare/cloudflared/h2mux" "github.com/cloudflare/cloudflared/h2mux"
"github.com/cloudflare/cloudflared/ingress" "github.com/cloudflare/cloudflared/ingress"
"github.com/cloudflare/cloudflared/orchestration" "github.com/cloudflare/cloudflared/orchestration"
@ -31,14 +32,7 @@ import (
) )
const ( const (
dialTimeout = 15 * time.Second dialTimeout = 15 * time.Second
FeatureSerializedHeaders = "serialized_headers"
FeatureQuickReconnects = "quick_reconnects"
FeatureAllowRemoteConfig = "allow_remote_config"
FeatureDatagramV2 = "support_datagram_v2"
FeaturePostQuantum = "postquantum"
FeatureQUICSupportEOF = "support_quic_eof"
FeatureManagementLogs = "management_logs"
) )
type TunnelConfig struct { type TunnelConfig struct {
@ -112,11 +106,11 @@ func (c *TunnelConfig) connectionOptions(originLocalAddr string, numPreviousAtte
} }
func (c *TunnelConfig) SupportedFeatures() []string { func (c *TunnelConfig) SupportedFeatures() []string {
features := []string{FeatureSerializedHeaders} supported := []string{features.FeatureSerializedHeaders}
if c.NamedTunnel == nil { if c.NamedTunnel == nil {
features = append(features, FeatureQuickReconnects) supported = append(supported, features.FeatureQuickReconnects)
} }
return features return supported
} }
func StartTunnelDaemon( func StartTunnelDaemon(