2018-05-29 21:07:40 +00:00
|
|
|
---
|
2020-09-01 15:14:13 +00:00
|
|
|
layout: commands
|
2020-04-07 18:55:19 +00:00
|
|
|
page_title: 'Commands: Connect Proxy'
|
2018-05-29 21:07:40 +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
|
2023-05-05 17:41:40 +00:00
|
|
|
Consul service mesh.
|
2018-05-29 21:07:40 +00:00
|
|
|
---
|
|
|
|
|
|
|
|
# Consul Connect Proxy
|
|
|
|
|
|
|
|
Command: `consul connect proxy`
|
|
|
|
|
|
|
|
The connect proxy command is used to run Consul's built-in mTLS proxy for
|
2023-05-05 17:41:40 +00:00
|
|
|
use with Consul service mesh. This can be used in production to enable a mesh-unaware
|
|
|
|
application to accept and establish mesh-based connections. This proxy
|
|
|
|
can also be used in development to connect to mesh-enabled services.
|
2018-05-29 21:07:40 +00:00
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
|
|
|
Usage: `consul connect proxy [options]`
|
|
|
|
|
2022-07-27 06:17:11 +00:00
|
|
|
#### Command Options
|
2018-05-29 21:07:40 +00:00
|
|
|
|
2020-04-07 18:55:19 +00:00
|
|
|
- `-sidecar-for` - The _ID_ (not name if they differ) of the service instance
|
2018-10-11 09:44:42 +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
|
2018-10-11 09:44:42 +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
|
|
|
This can also be specified via the `CONNECT_SIDECAR_FOR` environment variable.
|
2018-10-11 09:44:42 +00:00
|
|
|
|
2020-04-07 18:55:19 +00:00
|
|
|
- `-proxy-id` - The [proxy
|
2023-01-25 16:52:43 +00:00
|
|
|
service](/consul/docs/connect/registration/service-registration) ID on the
|
2021-08-02 19:50:51 +00:00
|
|
|
local agent. This must already be present on the local agent. This option
|
|
|
|
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
|
|
|
- `-log-level` - Specifies the log level.
|
2018-10-11 09:44:42 +00:00
|
|
|
|
2020-04-07 18:55:19 +00:00
|
|
|
- `-pprof-addr` - Enable debugging via pprof. Providing a host:port (or just ':port')
|
2018-10-11 09:44:42 +00:00
|
|
|
enables profiling HTTP endpoints on that address.
|
|
|
|
|
2020-04-07 18:55:19 +00:00
|
|
|
- `-service` - Name of the service this proxy is representing. This service
|
2018-05-29 21:07:40 +00:00
|
|
|
doesn't need to actually exist in the Consul catalog, but proper ACL
|
2018-10-11 09:44:42 +00:00
|
|
|
permissions (`service:write`) are required. This and the remaining options can
|
|
|
|
be used to setup a proxy that is not registered already with local config
|
2023-01-25 16:52:43 +00:00
|
|
|
[useful for development](/consul/docs/connect/dev).
|
2018-05-29 21:07:40 +00:00
|
|
|
|
2020-04-07 18:55:19 +00:00
|
|
|
- `-upstream` - Upstream service to support connecting to. The format should be
|
2018-05-29 21:07:40 +00:00
|
|
|
'name:addr', such as 'db:8181'. This will make 'db' available on port 8181.
|
|
|
|
When a regular TCP connection is made to port 8181, the proxy will service
|
2023-05-05 17:41:40 +00:00
|
|
|
discover "db" and establish a Consul service mesh mTLS connection identifying as
|
2018-05-29 21:07:40 +00:00
|
|
|
the `-service` value. This flag can be repeated multiple times.
|
|
|
|
|
2020-04-07 18:55:19 +00:00
|
|
|
- `-listen` - Address to listen for inbound connections to the proxied service.
|
2018-05-29 21:07:40 +00:00
|
|
|
Must be specified with -service and -service-addr. If this isn't specified,
|
|
|
|
an inbound listener is not started.
|
|
|
|
|
2020-04-07 18:55:19 +00:00
|
|
|
- `-service-addr` - Address of the local service to proxy. Required for
|
2018-05-29 21:07:40 +00:00
|
|
|
`-listen`.
|
|
|
|
|
2020-04-07 18:55:19 +00:00
|
|
|
- `-register` - Self-register with the local Consul agent, making this
|
2023-05-05 17:41:40 +00:00
|
|
|
proxy available as mesh-capable service in the catalog. This is only
|
2018-05-29 21:07:40 +00:00
|
|
|
useful with `-listen`.
|
|
|
|
|
2020-04-07 18:55:19 +00:00
|
|
|
- `-register-id` - Optional ID suffix for the service when `-register` is set to
|
|
|
|
disambiguate the service ID. By default the service ID is `<service>-proxy`
|
2018-10-11 09:44:42 +00:00
|
|
|
where `<service>` is the `-service` value. In most cases it is now preferable
|
2023-01-25 16:52:43 +00:00
|
|
|
to use [`consul services register`](/consul/commands/services/register) to
|
2018-10-11 09:44:42 +00:00
|
|
|
register a fully configured proxy instance rather than specify config and
|
|
|
|
registration via this command.
|
2018-05-29 21:07:40 +00:00
|
|
|
|
2022-07-27 06:17:11 +00:00
|
|
|
#### API Options
|
|
|
|
|
|
|
|
@include 'http_api_options_client.mdx'
|
|
|
|
|
|
|
|
@include 'http_api_options_server.mdx'
|
|
|
|
|
2018-05-29 21:07:40 +00:00
|
|
|
## Examples
|
|
|
|
|
|
|
|
The example below shows how to start a local proxy for establishing outbound
|
|
|
|
connections to "db" representing the frontend service. Once running, any
|
|
|
|
process that creates a TCP connection to the specified port (8181) will
|
|
|
|
establish a mutual TLS connection to "db" identified as "frontend".
|
|
|
|
|
2020-05-19 18:32:38 +00:00
|
|
|
```shell-session
|
2018-05-29 21:07:40 +00:00
|
|
|
$ consul connect proxy -service frontend -upstream db:8181
|
|
|
|
```
|
|
|
|
|
|
|
|
The next example starts a local proxy that also accepts inbound connections
|
|
|
|
on port 8443, authorizes the connection, then proxies it to port 8080:
|
|
|
|
|
2020-05-19 18:32:38 +00:00
|
|
|
```shell-session
|
2018-05-29 21:07:40 +00:00
|
|
|
$ consul connect proxy \
|
|
|
|
-service frontend \
|
|
|
|
-service-addr 127.0.0.1:8080 \
|
|
|
|
-listen ':8443'
|
|
|
|
```
|