Documentation ¶
Overview ¶
Package xds provides an implementation of a gRPC service that exports Envoy's xDS API for config discovery. Specifically we support the Aggregated Discovery Service (ADS) only as we control all config.
A full description of the XDS protocol can be found at https://www.envoyproxy.io/docs/envoy/latest/api-docs/xds_protocol
xds.Server also support ext_authz network filter API to authorize incoming connections to Envoy.
Index ¶
- Constants
- Variables
- func CustomizeClusterName(clusterName string, chain *structs.CompiledDiscoveryChain) string
- func ToOutlierDetection(p *structs.PassiveHealthCheck) *envoy_cluster_v3.OutlierDetection
- type ACLResolverFunc
- type ADSDeltaStream
- type ADSStream
- type ADSStream_v2
- type ConfigFetcher
- type ConfigManager
- type GatewayConfig
- type HTTPCheckFetcher
- type IndexedResources
- type ProxyConfig
- type ResourceGenerator
- type Server
- type TestADSDeltaStream
- func (s *TestADSDeltaStream) Context() context.Context
- func (s *TestADSDeltaStream) Recv() (*envoy_discovery_v3.DeltaDiscoveryRequest, error)
- func (s *TestADSDeltaStream) RecvMsg(m interface{}) error
- func (s *TestADSDeltaStream) Send(r *envoy_discovery_v3.DeltaDiscoveryResponse) error
- func (s *TestADSDeltaStream) SendHeader(metadata.MD) error
- func (s *TestADSDeltaStream) SendMsg(m interface{}) error
- func (s *TestADSDeltaStream) SetHeader(metadata.MD) error
- func (s *TestADSDeltaStream) SetTrailer(metadata.MD)
- type TestADSStream
- func (s *TestADSStream) Context() context.Context
- func (s *TestADSStream) Recv() (*envoy_api_v2.DiscoveryRequest, error)
- func (s *TestADSStream) RecvMsg(m interface{}) error
- func (s *TestADSStream) Send(r *envoy_api_v2.DiscoveryResponse) error
- func (s *TestADSStream) SendHeader(metadata.MD) error
- func (s *TestADSStream) SendMsg(m interface{}) error
- func (s *TestADSStream) SetHeader(metadata.MD) error
- func (s *TestADSStream) SetTrailer(metadata.MD)
- type TestEnvoy
- func (e *TestEnvoy) Close() error
- func (e *TestEnvoy) SendDeltaReq(t testing.T, typeURL string, req *envoy_discovery_v3.DeltaDiscoveryRequest)
- func (e *TestEnvoy) SendDeltaReqACK(t testing.T, typeURL string, nonce uint64, ack bool, ...)
- func (e *TestEnvoy) SendReq(t testing.T, typeURL string, version, nonce uint64)
Constants ¶
const ( // EndpointType is the TypeURL for Endpoint discovery responses. EndpointType = apiTypePrefix + "envoy.config.endpoint.v3.ClusterLoadAssignment" EndpointType_v2 = apiTypePrefix + "envoy.api.v2.ClusterLoadAssignment" // ClusterType is the TypeURL for Cluster discovery responses. ClusterType = apiTypePrefix + "envoy.config.cluster.v3.Cluster" ClusterType_v2 = apiTypePrefix + "envoy.api.v2.Cluster" // RouteType is the TypeURL for Route discovery responses. RouteType = apiTypePrefix + "envoy.config.route.v3.RouteConfiguration" RouteType_v2 = apiTypePrefix + "envoy.api.v2.RouteConfiguration" // ListenerType is the TypeURL for Listener discovery responses. ListenerType = apiTypePrefix + "envoy.config.listener.v3.Listener" ListenerType_v2 = apiTypePrefix + "envoy.api.v2.Listener" // PublicListenerName is the name we give the public listener in Envoy config. PublicListenerName = "public_listener" // OutboundListenerName is the name we give the outbound Envoy listener when transparent proxy mode is enabled. OutboundListenerName = "outbound_listener" // LocalAppClusterName is the name we give the local application "cluster" in // Envoy config. Note that all cluster names may collide with service names // since we want cluster names and service names to match to enable nice // metrics correlation without massaging prefixes on cluster names. // // We should probably make this more unlikely to collide however changing it // potentially breaks upgrade compatibility without restarting all Envoy's as // it will no longer match their existing cluster name. Changing this will // affect metrics output so could break dashboards (for local app traffic). // // We should probably just make it configurable if anyone actually has // services named "local_app" in the future. LocalAppClusterName = "local_app" // LocalAgentClusterName is the name we give the local agent "cluster" in // Envoy config. Note that all cluster names may collide with service names // since we want cluster names and service names to match to enable nice // metrics correlation without massaging prefixes on cluster names. // // We should probably make this more unlikely to collied however changing it // potentially breaks upgrade compatibility without restarting all Envoy's as // it will no longer match their existing cluster name. Changing this will // affect metrics output so could break dashboards (for local agent traffic). // // We should probably just make it configurable if anyone actually has // services named "local_agent" in the future. LocalAgentClusterName = "local_agent" // OriginalDestinationClusterName is the name we give to the passthrough // cluster which redirects transparently-proxied requests to their original // destination outside the mesh. This cluster prevents Consul from blocking // connections to destinations outside of the catalog when in transparent // proxy mode. OriginalDestinationClusterName = "original-destination" // DefaultAuthCheckFrequency is the default value for // Server.AuthCheckFrequency to use when the zero value is provided. DefaultAuthCheckFrequency = 5 * time.Minute )
const (
UnnamedSubset = ""
)
Variables ¶
var StatsGauges = []prometheus.GaugeDefinition{ { Name: []string{"xds", "server", "streams"}, Help: "Measures the number of active xDS streams handled by the server split by protocol version.", }, }
Functions ¶
func CustomizeClusterName ¶ added in v1.6.0
func CustomizeClusterName(clusterName string, chain *structs.CompiledDiscoveryChain) string
func ToOutlierDetection ¶ added in v1.10.0
func ToOutlierDetection(p *structs.PassiveHealthCheck) *envoy_cluster_v3.OutlierDetection
Return an envoy.OutlierDetection populated by the values from this struct. If all values are zero a default empty OutlierDetection will be returned to enable outlier detection with default values.
Types ¶
type ACLResolverFunc ¶
type ACLResolverFunc func(id string) (acl.Authorizer, error)
ACLResolverFunc is a shim to resolve ACLs. Since ACL enforcement is so far entirely agent-local and all uses private methods this allows a simple shim to be written in the agent package to allow resolving without tightly coupling this to the agent.
type ADSDeltaStream ¶ added in v1.10.0
type ADSDeltaStream = envoy_discovery_v3.AggregatedDiscoveryService_DeltaAggregatedResourcesServer
ADSDeltaStream is a shorter way of referring to this thing...
type ADSStream_v2 ¶ added in v1.10.0
type ADSStream_v2 = envoy_discovery_v2.AggregatedDiscoveryService_StreamAggregatedResourcesServer
type ConfigFetcher ¶ added in v1.6.2
type ConfigFetcher interface {
AdvertiseAddrLAN() string
}
ConfigFetcher is the interface the agent needs to expose for the xDS server to fetch agent config, currently only one field is fetched
type ConfigManager ¶
type ConfigManager interface {
Watch(proxyID structs.ServiceID) (<-chan *proxycfg.ConfigSnapshot, proxycfg.CancelFunc)
}
ConfigManager is the interface xds.Server requires to consume proxy config updates. It's satisfied normally by the agent's proxycfg.Manager, but allows easier testing without several layers of mocked cache, local state and proxycfg.Manager.
type GatewayConfig ¶ added in v1.8.0
type GatewayConfig struct { // BindTaggedAddresses when set will cause all of the services tagged // addresses to have listeners bound to them in addition to the main service // address listener. This is only suitable when the tagged addresses are IP // addresses of network interfaces Envoy can see. i.e. When using DNS names // for those addresses or where an external entity maps that IP to the Envoy // (like AWS EC2 mapping a public IP to the private interface) then this // cannot be used. See the BindAddresses config instead BindTaggedAddresses bool `mapstructure:"envoy_gateway_bind_tagged_addresses" alias:"envoy_mesh_gateway_bind_tagged_addresses"` // BindAddresses additional bind addresses to configure listeners for BindAddresses map[string]structs.ServiceAddress `mapstructure:"envoy_gateway_bind_addresses" alias:"envoy_mesh_gateway_bind_addresses"` // NoDefaultBind indicates that we should not bind to the default address of the // gateway service NoDefaultBind bool `mapstructure:"envoy_gateway_no_default_bind" alias:"envoy_mesh_gateway_no_default_bind"` // DNSDiscoveryType indicates the DNS service discovery type. // See: https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/upstream/service_discovery#arch-overview-service-discovery-types DNSDiscoveryType string `mapstructure:"envoy_dns_discovery_type"` // ConnectTimeoutMs is the number of milliseconds to timeout making a new // connection to this upstream. Defaults to 5000 (5 seconds) if not set. ConnectTimeoutMs int `mapstructure:"connect_timeout_ms"` }
func ParseGatewayConfig ¶ added in v1.8.0
func ParseGatewayConfig(m map[string]interface{}) (GatewayConfig, error)
ParseGatewayConfig returns the GatewayConfig parsed from an opaque map. If an error occurs during parsing, it is returned along with the default config. This allows the caller to choose whether and how to report the error
type HTTPCheckFetcher ¶ added in v1.6.2
type HTTPCheckFetcher interface {
ServiceHTTPBasedChecks(serviceID structs.ServiceID) []structs.CheckType
}
ServiceChecks is the interface the agent needs to expose for the xDS server to fetch a service's HTTP check definitions
type ProxyConfig ¶ added in v1.5.0
type ProxyConfig struct { // PublicListenerJSON is a complete override ("escape hatch") for the // upstream's public listener. The Connect server TLS certificate and // validation context will be injected overriding any TLS settings present. An // AuthZ filter will also be prepended to each filterChain provided to enforce // Connect's access control. // // Note: This escape hatch is compatible with the discovery chain. PublicListenerJSON string `mapstructure:"envoy_public_listener_json"` // LocalClusterJSON is a complete override ("escape hatch") for the // local application cluster. // // Note: This escape hatch is compatible with the discovery chain. LocalClusterJSON string `mapstructure:"envoy_local_cluster_json"` // LocalConnectTimeoutMs is the number of milliseconds to timeout making a new // connection to the local app instance. Defaults to 5000 (5 seconds) if not // set. LocalConnectTimeoutMs int `mapstructure:"local_connect_timeout_ms"` // LocalRequestTimeoutMs is the number of milliseconds to timeout HTTP requests // to the local app instance. If not set, no value is set, Envoy defaults are // respected (15s) LocalRequestTimeoutMs *int `mapstructure:"local_request_timeout_ms"` // Protocol describes the service's protocol. Valid values are "tcp", // "http" and "grpc". Anything else is treated as tcp. This enables // protocol aware features like per-request metrics and connection // pooling, tracing, routing etc. Protocol string `mapstructure:"protocol"` // BindAddress overrides the address the proxy's listener binds to. This // enables proxies in network namespaces to bind to a different address // than the host address. BindAddress string `mapstructure:"bind_address"` // BindPort overrides the port the proxy's listener binds to. This // enable proxies in network namespaces to bind to a different port // than the host port being advertised. BindPort int `mapstructure:"bind_port"` }
ProxyConfig describes the keys we understand from Connect.Proxy.Config. Note that this only includes config keys that affects runtime config delivered by xDS. For Envoy config keys that affect bootstrap generation see command/connect/envoy/bootstrap_config.go.
func ParseProxyConfig ¶ added in v1.5.0
func ParseProxyConfig(m map[string]interface{}) (ProxyConfig, error)
ParseProxyConfig returns the ProxyConfig parsed from the an opaque map. If an error occurs during parsing it is returned along with the default config this allows caller to choose whether and how to report the error.
type ResourceGenerator ¶ added in v1.10.0
type ResourceGenerator struct { Logger hclog.Logger CheckFetcher HTTPCheckFetcher CfgFetcher ConfigFetcher IncrementalXDS bool ProxyFeatures supportedProxyFeatures }
ResourceGenerator is associated with a single gRPC stream and creates xDS resources for a single client.
type Server ¶
type Server struct { Logger hclog.Logger CfgMgr ConfigManager ResolveToken ACLResolverFunc CheckFetcher HTTPCheckFetcher CfgFetcher ConfigFetcher // AuthCheckFrequency is how often we should re-check the credentials used // during a long-lived gRPC Stream after it has been initially established. // This is only used during idle periods of stream interactions (i.e. when // there has been no recent DiscoveryRequest). AuthCheckFrequency time.Duration DisableV2Protocol bool // contains filtered or unexported fields }
Server represents a gRPC server that can handle xDS requests from Envoy. All of it's public members must be set before the gRPC server is started.
A full description of the XDS protocol can be found at https://www.envoyproxy.io/docs/envoy/latest/api-docs/xds_protocol
func NewServer ¶ added in v1.10.0
func NewServer( logger hclog.Logger, cfgMgr ConfigManager, resolveToken ACLResolverFunc, checkFetcher HTTPCheckFetcher, cfgFetcher ConfigFetcher, ) *Server
func (*Server) DeltaAggregatedResources ¶ added in v1.5.2
func (s *Server) DeltaAggregatedResources(stream ADSDeltaStream) error
DeltaAggregatedResources implements envoy_discovery_v3.AggregatedDiscoveryServiceServer
func (*Server) GRPCServer ¶
GRPCServer returns a server instance that can handle xDS requests.
func (*Server) StreamAggregatedResources
deprecated
type TestADSDeltaStream ¶ added in v1.10.0
type TestADSDeltaStream struct {
// contains filtered or unexported fields
}
TestADSDeltaStream mocks discovery.AggregatedDiscoveryService_DeltaAggregatedResourcesServer to allow testing the ADS handler.
func NewTestADSDeltaStream ¶ added in v1.10.0
func NewTestADSDeltaStream(t testing.T, ctx context.Context) *TestADSDeltaStream
func (*TestADSDeltaStream) Context ¶ added in v1.10.0
Context implements grpc.ServerStream as part of ADSDeltaStream
func (*TestADSDeltaStream) Recv ¶ added in v1.10.0
func (s *TestADSDeltaStream) Recv() (*envoy_discovery_v3.DeltaDiscoveryRequest, error)
Recv implements ADSDeltaStream
func (*TestADSDeltaStream) RecvMsg ¶ added in v1.10.0
func (s *TestADSDeltaStream) RecvMsg(m interface{}) error
RecvMsg implements grpc.ServerStream as part of ADSDeltaStream
func (*TestADSDeltaStream) Send ¶ added in v1.10.0
func (s *TestADSDeltaStream) Send(r *envoy_discovery_v3.DeltaDiscoveryResponse) error
Send implements ADSDeltaStream
func (*TestADSDeltaStream) SendHeader ¶ added in v1.10.0
SendHeader implements grpc.ServerStream as part of ADSDeltaStream
func (*TestADSDeltaStream) SendMsg ¶ added in v1.10.0
func (s *TestADSDeltaStream) SendMsg(m interface{}) error
SendMsg implements grpc.ServerStream as part of ADSDeltaStream
func (*TestADSDeltaStream) SetHeader ¶ added in v1.10.0
SetHeader implements grpc.ServerStream as part of ADSDeltaStream
func (*TestADSDeltaStream) SetTrailer ¶ added in v1.10.0
SetTrailer implements grpc.ServerStream as part of ADSDeltaStream
type TestADSStream ¶
type TestADSStream struct {
// contains filtered or unexported fields
}
TestADSStream mocks discovery.AggregatedDiscoveryService_StreamAggregatedResourcesServer to allow testing ADS handler.
func NewTestADSStream ¶
func NewTestADSStream(t testing.T, ctx context.Context) *TestADSStream
NewTestADSStream makes a new TestADSStream
func (*TestADSStream) Recv ¶
func (s *TestADSStream) Recv() (*envoy_api_v2.DiscoveryRequest, error)
Recv implements ADSStream
func (*TestADSStream) RecvMsg ¶
func (s *TestADSStream) RecvMsg(m interface{}) error
RecvMsg implements grpc.ServerStream as part of ADSDeltaStream
func (*TestADSStream) Send ¶
func (s *TestADSStream) Send(r *envoy_api_v2.DiscoveryResponse) error
Send implements ADSStream
func (*TestADSStream) SendHeader ¶
SendHeader implements grpc.ServerStream as part of ADSDeltaStream
func (*TestADSStream) SendMsg ¶
func (s *TestADSStream) SendMsg(m interface{}) error
SendMsg implements grpc.ServerStream as part of ADSDeltaStream
func (*TestADSStream) SetTrailer ¶
SetTrailer implements grpc.ServerStream as part of ADSDeltaStream
type TestEnvoy ¶
type TestEnvoy struct {
// contains filtered or unexported fields
}
TestEnvoy is a helper to simulate Envoy ADS requests.
func NewTestEnvoy ¶
NewTestEnvoy creates a TestEnvoy instance.
func (*TestEnvoy) SendDeltaReq ¶ added in v1.10.0
func (e *TestEnvoy) SendDeltaReq( t testing.T, typeURL string, req *envoy_discovery_v3.DeltaDiscoveryRequest, )
SendDeltaReq sends a delta request from the test server.
NOTE: the input request is mutated before sending by injecting the node.