2018-10-11 09:44:42 +00:00
|
|
|
---
|
2020-04-07 18:55:19 +00:00
|
|
|
layout: docs
|
|
|
|
page_title: 'Commands: Connect Proxy'
|
2020-04-13 18:40:26 +00:00
|
|
|
sidebar_title: envoy
|
2018-10-11 09:44:42 +00:00
|
|
|
description: >
|
2020-04-07 18:55:19 +00:00
|
|
|
The connect proxy subcommand is used to run the built-in mTLS proxy for
|
|
|
|
Connect.
|
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
|
|
|
|
Connect](/docs/connect/).
|
|
|
|
|
|
|
|
The default behaviour 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
|
|
|
|
file and used with `envoy -c bootstrap.json`. This works on all operating
|
|
|
|
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]`
|
|
|
|
|
|
|
|
#### API Options
|
|
|
|
|
|
|
|
The standard API options are used to connect to the local agent to discover the
|
|
|
|
proxy configuration needed.
|
|
|
|
|
2020-04-07 18:55:19 +00:00
|
|
|
- `-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
|
2020-04-09 23:46:54 +00:00
|
|
|
listen](/docs/agent/options#addresses) that way.
|
2018-10-11 09:44:42 +00:00
|
|
|
|
2019-07-08 23:40:57 +00:00
|
|
|
-> **Note:** gRPC uses the same TLS
|
2020-04-07 18:55:19 +00:00
|
|
|
settings as the HTTPS API. If HTTPS is enabled then gRPC will require HTTPS
|
|
|
|
as well.
|
2018-10-11 09:44:42 +00:00
|
|
|
|
2020-04-07 18:55:19 +00:00
|
|
|
@include 'http_api_options_client.mdx'
|
2018-10-11 09:44:42 +00:00
|
|
|
|
2019-07-08 23:40:57 +00:00
|
|
|
#### Envoy Options for both Sidecars and Gateways
|
2018-10-11 09:44:42 +00:00
|
|
|
|
2020-05-13 17:56:53 +00:00
|
|
|
- `-proxy-id` - The [proxy service](/docs/connect/registration/service-registration) ID.
|
|
|
|
This service ID must already be registered with the local agent unless a gateway is being
|
|
|
|
registered with the `-register` flag.
|
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
|
|
|
|
file and used to start Envoy with `envoy -c 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
|
2020-04-09 23:46:54 +00:00
|
|
|
allowed to access by [Connect intentions](/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
|
|
|
|
`1.13.0`. This is required so that the correct configuration can be generated.
|
2020-02-10 19:53:04 +00:00
|
|
|
|
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
|
|
|
|
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
|
2020-04-09 23:46:54 +00:00
|
|
|
registration](/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.
|
|
|
|
|
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.
|
|
|
|
|
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`
|
|
|
|
|
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
|
2020-04-09 23:46:54 +00:00
|
|
|
registration](/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 {} }
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2019-07-08 23:40:57 +00:00
|
|
|
### Basic Sidecar Proxy
|
|
|
|
|
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.
|
|
|
|
|
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
|
2018-10-11 09:44:42 +00:00
|
|
|
$ consul connect envoy -sidecar-for web -- -l debug
|
|
|
|
```
|
|
|
|
|
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.
|