2018-10-11 09:44:42 +00:00
---
2020-09-01 15:14:13 +00:00
layout: commands
2021-04-09 18:48:10 +00:00
page_title: 'Commands: Connect Envoy'
sidebar_title: envoy
description: The connect envoy subcommand is used to generate a bootstrap configuration for Envoy.
2018-10-11 09:44:42 +00:00
---
# Consul Connect Envoy
Command: `consul connect envoy`
The connect Envoy command is used to generate a bootstrap configuration for
[Envoy proxy](https://envoyproxy.io) for use with [Consul
2023-01-25 16:52:43 +00:00
Connect](/consul/docs/connect/).
2018-10-11 09:44:42 +00:00
2022-12-09 01:15:58 +00:00
Refer to the [examples](#examples) for guidance on common use cases,
such as [launching a service instance's sidecar proxy
when ACLs are enabled](#sidecar-proxy-with-acls-enabled).
2020-09-18 15:11:48 +00:00
The default behavior is to generate the necessary bootstrap configuration for
2020-03-09 17:58:29 +00:00
Envoy based on the environment variables and options provided and by talking to
2018-10-11 09:44:42 +00:00
the local Consul agent. It `exec`s an external Envoy binary with that
configuration leaving the Envoy process running in the foreground. An error is
returned on operating systems other than linux or macOS since Envoy does not
build for other platforms currently.
If the `-bootstrap` option is specified, the bootstrap config is generated in
the same way and then printed to stdout. This allows it to be redirected to a
2022-01-12 23:05:01 +00:00
file and used with `envoy --config-path bootstrap.json`. This works on all operating
2018-10-11 09:44:42 +00:00
systems allowing configuration to be generated on a host that Envoy doesn't
build on but then used in a virtualized environment that can run Envoy.
## Usage
Usage: `consul connect envoy [options] [-- pass-through options]`
2019-07-08 23:40:57 +00:00
#### Envoy Options for both Sidecars and Gateways
2018-10-11 09:44:42 +00:00
2023-01-25 16:52:43 +00:00
- `-proxy-id` - The [proxy service](/consul/docs/connect/registration/service-registration) ID.
2020-05-13 17:56:53 +00:00
This service ID must already be registered with the local agent unless a gateway is being
2021-08-02 19:50:51 +00:00
registered with the `-register` flag. As of Consul 1.8.0, this can also be
specified via the `CONNECT_PROXY_ID` environment variable.
2018-10-11 09:44:42 +00:00
2020-04-07 18:55:19 +00:00
- `-envoy-binary` - The full path to a specific Envoy binary to exec. By
default the current `$PATH` is searched for `envoy`.
2018-10-11 09:44:42 +00:00
2020-04-07 18:55:19 +00:00
- `-admin-bind` - The `host:port` to bind Envoy's admin HTTP API. Default is
`localhost:19000`. Envoy requires that this be enabled. The host part must be
resolvable DNS name or IP address.
2018-10-11 09:44:42 +00:00
2020-04-07 18:55:19 +00:00
- `-bootstrap` - If present, the command will simply output the generated
bootstrap config to stdout in JSON protobuf form. This can be directed to a
2022-01-12 23:05:01 +00:00
file and used to start Envoy with `envoy --config-path bootstrap.json`.
2018-10-11 09:44:42 +00:00
2020-04-07 18:55:19 +00:00
~> **Security Note:** If ACLs are enabled the bootstrap JSON will contain the
ACL token from `-token` or the environment and so should be handled as a secret.
This token grants the identity of any service it has `service:write` permission
for and so can be used to access any upstream service that that service is
2023-01-25 16:52:43 +00:00
allowed to access by [Connect intentions](/consul/docs/connect/intentions).
2018-10-11 09:44:42 +00:00
2020-04-07 18:55:19 +00:00
- `-envoy-version` - The version of envoy that is being started. Default is
2022-09-14 20:20:16 +00:00
`1.23.1`. This is required so that the correct configuration can be generated.
2020-02-10 19:53:04 +00:00
2022-11-18 20:36:20 +00:00
- `-grpc-ca-file` - Path to a CA file to use for TLS when communicating with the
Consul agent through xDS. This can also be specified via the CONSUL_GRPC_CACERT
environment variable.
- `-grpc-ca-path` - Path to a directory of CA certificates to use for TLS when
communicating with the Consul agent through xDS. This can also be specified via
the CONSUL_GRPC_CAPATH environment variable.
2020-09-18 15:11:48 +00:00
- `-no-central-config` - By default the proxy's bootstrap configuration can be
2020-12-08 23:24:36 +00:00
customized centrally. This requires that the command run on the same agent
as the proxy will and that the agent is reachable when the command is run.
In cases where either assumption is violated this flag will prevent the
command attempting to resolve config from the local agent.
2020-09-18 15:11:48 +00:00
2023-01-19 21:54:11 +00:00
- `-envoy-ready-bind-address` - By default the proxy does not have a readiness probe
configured on it. This flag in conjunction with the `envoy-ready-bind-port` flag
configures where the envoy readiness probe is configured on the proxy. A `/ready` HTTP
endpoint will be instantiated at the specified address and port. When configured, Consul
uses `/ready` HTTP endpoints to check proxy health.
- `-envoy-ready-bind-port` - By default the proxy does not have a readiness probe
configured on it. This flag in conjunction with the `envoy-ready-bind-address` flag
configures where the envoy readiness probe is configured on the proxy. A `/ready` HTTP
endpoint will be instantiated at the specified address and port. When configured, Consul
uses `/ready` HTTP endpoints to check proxy health.
2021-03-04 22:15:47 +00:00
- `-prometheus-backend-port` - Sets the backend port for the "prometheus_backend"
cluster that `envoy_prometheus_bind_addr` will point to. Without this flag,
`envoy_prometheus_bind_addr` would point to the "self_admin" cluster where Envoy metrics
are exposed. The metrics merging feature in consul-k8s uses this to point to the
merged metrics endpoint combining Envoy and service metrics.
Only applicable when `envoy_prometheus_bind_addr` is set in proxy config.
- `-prometheus-scrape-path` - Sets the path where Envoy will expose metrics on the
`envoy_prometheus_bind_addr` listener. Default is `/metrics`. For example, if `envoy_prometheus_bind_addr`
2021-04-09 18:48:10 +00:00
is `0.0.0.0:20200`, and this flag is set to `/scrape-metrics`, prometheus metrics would
2021-03-04 22:15:47 +00:00
be scrapable at `0.0.0.0:20200/scrape-metrics`.
Only applicable when `envoy_prometheus_bind_addr` is set in proxy config.
2022-06-27 16:33:27 +00:00
- `-prometheus-ca-file` - Path to a CA file for Envoy to use when serving TLS on
the Prometheus metrics endpoint. Only applicable when `envoy_prometheus_bind_addr`
is set in proxy config.
- `-prometheus-ca-path` - Path to a directory of CA certificates for Envoy to use when
serving the Prometheus metrics endpoint. Only applicable when `envoy_prometheus_bind_addr`
is set in proxy config.
- `-prometheus-cert-file` - Path to a certificate file for Envoy to use when serving
TLS on the Prometheus metrics endpoint. Only applicable when `envoy_prometheus_bind_addr`
is set in proxy config.
- `-prometheus-key-file` - Path to a private key file for Envoy to use when serving
TLS on the Prometheus metrics endpoint. Only applicable when `envoy_prometheus_bind_addr`
is set in proxy config.
2022-12-20 17:58:19 +00:00
- `-ignore-envoy-compatibility` - If set to `true`, this flag ignores the Envoy version
compatibility check. We recommend setting this flag to `false` to ensure
compatibility with Envoy and prevent potential issues. Default is `false`.
2020-04-07 18:55:19 +00:00
- `-- [pass-through options]` - Any options given after a double dash are passed
directly through to the `envoy` invocation. See [Envoy's
documentation](https://www.envoyproxy.io/docs) for more details. The command
always specifies `--config-file` and `--v2-config-only` and by default passes
2020-04-13 21:24:10 +00:00
`--disable-hot-restart` see [hot restart](#envoy-hot-restart).
2018-10-11 09:44:42 +00:00
2023-01-31 21:30:20 +00:00
- `-enable-config-gen-logging` - This flag enables debug message logging when generating the Envoy bootstrap configuration to help troubleshoot issues. Logs output to `stderr`. For more information about generating the Envoy bootstrap configuration, refer to [Envoy proxy configuration](/consul/docs/connect/proxies/envoy#bootstrap-configuration).
2019-07-08 23:40:57 +00:00
#### Envoy Sidecar Proxy Options
2020-04-07 18:55:19 +00:00
- `-sidecar-for` - The _ID_ (not name if they differ) of the service instance
2019-07-08 23:40:57 +00:00
this proxy will represent. The target service doesn't need to exist on the
local agent yet but a [sidecar proxy
2023-01-25 16:52:43 +00:00
registration](/consul/docs/connect/registration/service-registration) with
2019-07-08 23:40:57 +00:00
`proxy.destination_service_id` equal to the passed value must be present. If
multiple proxy registrations targeting the same local service instance are
present the command will error and `-proxy-id` should be used instead.
2021-08-02 19:50:51 +00:00
As of Consul 1.8.0, this can also be specified via the `CONNECT_SIDECAR_FOR`
environment variable.
2019-07-08 23:40:57 +00:00
2020-04-07 18:55:19 +00:00
-> **Note:** If ACLs are enabled, a token granting `service:write` for the
_target_ service (configured in `proxy.destination_service_name`) must be
passed using the `-token` option or `CONSUL_HTTP_TOKEN` environment variable.
This token authorizes the proxy to obtain TLS certificates representing the
target service.
2019-07-08 23:40:57 +00:00
2020-04-02 18:52:11 +00:00
#### Envoy Gateway Options
2019-07-08 23:40:57 +00:00
2020-04-07 18:55:19 +00:00
- `-gateway` - Flag to indicate that Envoy should be configured as a Gateway.
2020-05-13 21:29:40 +00:00
Must be one of: `terminating`, `ingress`, or `mesh`.
2020-04-02 18:52:11 +00:00
If multiple gateways are managed by the same local agent then
2019-07-08 23:40:57 +00:00
`-proxy-id` should be used as well to specify the instance this represents.
2020-04-07 18:55:19 +00:00
- `-register` - Indicates that the gateway service should be registered
2019-07-08 23:40:57 +00:00
with the local agent instead of expecting it to already exist. This flag
is unused for traditional sidecar proxies.
2020-04-07 18:55:19 +00:00
- `-address` - The address to advertise for services within the local datacenter
2020-04-02 18:52:11 +00:00
to use to reach the gateway instance. This flag is used in combination with
2019-07-08 23:40:57 +00:00
`-register`. This takes the form of `<ip address>:<port>` but also supports go-sockaddr
templates.
2021-08-12 21:56:07 +00:00
If Envoy is configured as a terminating or mesh gateway, traffic from services
within the mesh will be received at the specified IP and port.
If Envoy is configured as an ingress gateway, a `/ready` HTTP endpoint will be
instantiated at the specified IP and port. Consul uses `/ready` HTTP endpoints
to check gateway health. The specified IP will also be used by the ingress
gateway when instantiating user-defined listeners configured in the
2023-01-25 16:52:43 +00:00
[ingress gateway](/consul/docs/connect/gateways/ingress-gateway) configuration entry.
2021-08-12 21:56:07 +00:00
~> **Note**: Ensure that user-defined ingress gateway listeners use a
different port than the port specified in `-address` so that they do not
conflict with the health check endpoint.
2023-01-19 21:54:11 +00:00
- `-admin-access-log-path` -
2023-01-25 16:52:43 +00:00
**Deprecated in Consul 1.15.0 in favor of [`proxy-defaults` access logs](/consul/docs/connect/config-entries/proxy-defaults#accesslogs).**
2023-01-11 16:41:02 +00:00
The path to write the access log for the administration
2020-09-18 15:11:48 +00:00
server. If no access log is desired specify `/dev/null`. By default it will
use `/dev/null`.
2021-08-12 21:56:07 +00:00
- `-bind-address` - The bind address to use instead of the default binding rules.
Specified as `<name>=<ip>:<port>` pairs. This flag may be used multiple times
2020-09-18 15:11:48 +00:00
to add multiple bind addresses.
- `-expose-servers` - Expose the servers for WAN federation via this mesh
gateway.
2020-04-07 18:55:19 +00:00
- `-wan-address` - The address to advertise for services within remote datacenters
2020-04-02 18:52:11 +00:00
to use to reach the gateway instance. This flag is used in combination with
2019-07-08 23:40:57 +00:00
`-register`. This takes the form of `<ip address>:<port>` but also supports go-sockaddr
templates.
2020-04-07 18:55:19 +00:00
- `-service` - The name of the gateway service to register. This flag is used
2019-07-08 23:40:57 +00:00
in combination with `-register`.
2020-04-07 18:55:19 +00:00
- `-deregister-after-critical` - The amount of time the gateway services health check can
2019-07-08 23:40:57 +00:00
be failing before being deregistered. This flag is used in combination with `-register`
2020-09-18 15:11:48 +00:00
#### Enterprise Options
2022-07-27 06:17:11 +00:00
@include 'http_api_partition_options.mdx'
2020-09-18 15:11:48 +00:00
@include 'http_api_namespace_options.mdx'
2022-07-27 06:17:11 +00:00
#### API Options
The standard API options are used to connect to the local agent to discover the
proxy configuration needed.
- `-grpc-addr=<addr>` - Address of the Consul agent with `grpc` port. This can
be an IP address or DNS address, but it must include the port. This can also
be specified via the CONSUL_GRPC_ADDR environment variable. In Consul 1.3 and
later, the default value is 127.0.0.1:8502, and https can optionally
be used instead. The scheme can also be set to HTTPS by setting the
environment variable CONSUL_HTTP_SSL=true. This may be a unix domain socket
using `unix:///path/to/socket` if the [agent is configured to
2023-01-25 16:52:43 +00:00
listen](/consul/docs/agent/config/config-files#addresses) that way.
2022-07-27 06:17:11 +00:00
-> **Note:** gRPC uses the same TLS
settings as the HTTPS API. If HTTPS is enabled then gRPC will require HTTPS
as well.
@include 'http_api_options_client.mdx'
2021-12-15 01:55:21 +00:00
2018-10-11 09:44:42 +00:00
## Examples
2019-05-15 15:01:19 +00:00
Assume a local service instance is registered on the local agent with a
2018-10-11 09:44:42 +00:00
sidecar proxy (using the [sidecar service
2023-01-25 16:52:43 +00:00
registration](/consul/docs/connect/registration/service-registration) helper) as below.
2018-10-11 09:44:42 +00:00
```hcl
service {
name = "web"
port = 8080
connect { sidecar_service {} }
}
```
2022-12-09 01:15:58 +00:00
### Basic sidecar proxy
2019-07-08 23:40:57 +00:00
2018-10-11 09:44:42 +00:00
The sidecar Envoy process can be started with.
2020-05-19 18:32:38 +00:00
```shell-session
2018-10-11 09:44:42 +00:00
$ consul connect envoy -sidecar-for web
```
This example assumes that the correct [environment variables](#api-options) are
used to set the local agent connection information and ACL token, or that the
agent is using all-default configuration.
2022-12-09 01:15:58 +00:00
### Sidecar proxy with ACLs enabled
In secure deployments, Consul's ACL system is enabled with a default `deny` policy.
To access Consul API resources, an API request must present a Consul ACL token
with the necessary privileges. If ACLs are enabled, you must provide an ACL token to the sidecar proxy. The token must grant the proxy privileges to register itself and the service it fronts and to access all potential upstreams of that service.
We recommend [using a service identity](/consul/commands/acl/token/create#create-a-token-for-a-service)
to directly create a token with the privileges necessary for a service and its sidecar proxy,
rather than creating a unique ACL policy for every service.
After creating a token using a service identity, provide the token when
launching the Envoy sidecar proxy instance with the `consul connect envoy` command.
You can provide the token through an environment variable or CLI flag.
Environment variables:
- [`CONSUL_HTTP_TOKEN`](/consul/commands#consul_http_token) or
- [`CONSUL_HTTP_TOKEN_FILE`](/consul/commands#consul_http_token_file)
CLI flags:
- [`-token`](/consul/commands/connect/envoy#token) or
- [`-token-file`](/consul/commands/connect/envoy#token-file)
```shell-session
$ export CONSUL_HTTP_TOKEN="<secret-id-of-token-with-service-identity-for-web>"
$ consul connect envoy -sidecar-for web
```
2019-07-08 23:40:57 +00:00
### Additional Envoy Arguments
2018-10-11 09:44:42 +00:00
To pass additional arguments directly to Envoy, for example output logging
level, you can use:
2020-05-19 18:32:38 +00:00
```shell-session
2022-01-12 23:05:01 +00:00
$ consul connect envoy -sidecar-for web -- --log-level debug
2018-10-11 09:44:42 +00:00
```
2019-07-08 23:40:57 +00:00
### Multiple Proxy Instances
2018-10-11 09:44:42 +00:00
To run multiple different proxy instances on the same host, you will
need to use `-admin-bind` on all but one to ensure they don't attempt to bind to
the same port as in the following example.
2020-05-19 18:32:38 +00:00
```shell-session
2018-10-11 09:44:42 +00:00
$ consul connect envoy -sidecar-for db -admin-bind localhost:19001
```
2019-07-08 23:40:57 +00:00
### Mesh Gateways
2020-05-13 21:29:40 +00:00
The mesh gateway Envoy process can be auto-registered and started with the following command.
2019-07-08 23:40:57 +00:00
2020-05-19 18:32:38 +00:00
```shell-session
2020-04-02 18:52:11 +00:00
$ consul connect envoy -gateway=mesh -register \
2019-07-08 23:40:57 +00:00
-address '{{ GetInterfaceIP "eth0" }}:8443' \
-wan-address '{{ GetInterfaceIP "eth1" }}:8443'
```
2020-04-02 18:52:11 +00:00
### Terminating Gateways
2020-05-13 21:29:40 +00:00
The terminating gateway Envoy process can be auto-registered and started with the following command.
2020-04-02 18:52:11 +00:00
2020-05-19 18:32:38 +00:00
```shell-session
2020-05-13 21:29:40 +00:00
$ consul connect envoy -gateway=terminating -register -service my-gateway \
2020-04-02 18:52:11 +00:00
-address '{{ GetInterfaceIP "eth0" }}:8443'
```
2020-05-13 21:29:40 +00:00
### Ingress Gateways
The ingress gateway Envoy process can be auto-registered and started with the following command.
2020-05-19 18:32:38 +00:00
```shell-session
2020-05-13 21:29:40 +00:00
$ consul connect envoy -gateway=ingress -register -service ingress-service \
-address '{{ GetInterfaceIP "eth0" }}:8888'
```
2018-10-11 09:44:42 +00:00
## Exec Security Details
The command needs to pass the bootstrap config through to Envoy. Envoy currently
only supports passing this as a file path or passing a whole string on the
command line with `--config-yaml`. Since the bootstrap needs to contain the ACL
token to authorize the proxy, this secret needs careful handling.
Passing a secret via command option is unacceptable as on many unix systems
these are readable to any user on the host for example via `/proc` or via a
setuid process like `ps`.
Creating a temporary file is more secure in that it can only be read by the
current user but risks leaving secret material on disk for an unbounded length
of time and in a location that is opaque to the operator.
To work around these issues, the command currently creates a temporary file and
immediately unlinks it so it can't be read by any other process that doesn't
already have the file descriptor. It then writes the bootstrap JSON, and unsets
the CLOEXEC bit on the file handle so that it remains available to the Envoy
process after exec. Finally it `exec`s Envoy with `--config-file /dev/fd/X`
where `X` is the the file descriptor number of the temp file.
This ensures that Envoy can read the file without any other normal user process
being able to (assuming they don't have privileged access to /proc). Once the
Envoy process stops, there is no longer any reference to the file to clean up.
## Envoy Hot Restart
Envoy supports hot restart which requires simple external coordination. By
default, this command will add `--disable-hot-restart` when it runs Envoy.
The reason for this default behavior is to make it easy to test and run local
demonstrations with multiple Envoy instances outside of cgroups or network
namespaces.
To use hot restart, Envoy needs to be started with either the `--restart-epoch`
option. If this command detects that option in the pass-through flags it will
_not_ add `--disable-hot-restart` allowing hot restart to work normally.
The only difference to note over running Envoy directly is that
`--restart-epoch` must be explicitly set to `0` for the initial launch of the
Envoy instance to avoid disabling hot restart entirely. The official
2019-05-15 15:01:19 +00:00
`hot-restarter.py` always sets this option so should work as recommended.