# Connect to Control

Each **Grey Matter Proxy** connects to the **Grey Matter Control server** with a **bi-directional gRPC stream**. This connection is kept alive as long as both servers are up, and updates to configuration will flow every 30 seconds (default; but configurable) from `gm-control` to each connected `gm-proxy`.

## Set Up the Connection

To properly set up the connection, run `gm-proxy` with the following two environment variables.

```
PROXY_DYNAMIC=true   # To run in dynamic configuration mode

XDS_HOST=<gm-control host>
XDS_PORT=<gm-control port>
```

## Use TLS (Optional)

When connecting to the Envoy management server, proxies may also connect with TLS:

```
PROXY_DYNAMIC=true   # To run in dynamic configuration mode
XDS_ENABLE_TLS=true
XDS_SERVER_CA_PATH-<gm-control trust path>
XDS_SERVER_CERT_PATH=<gm-control certificate path>
XDS_SERVER_KEY_PATH=<gm-control certificate key path>
```

In order for sidecars to connect to Control with TLS, the Control server must also be configured with TLS. See the [Grey Matter Control documentation](https://greymatter.gitbook.io/grey-matter-documentation/1.3/reference/setup/gm-control#TLS-Support) to learn more.

## REST

If Grey Matter Control is using REST instead of gRPC (see [Grey Matter Control REST support](https://greymatter.gitbook.io/grey-matter-documentation/1.3/reference/setup/gm-control#rest-support)), the following environment variables must be set in order to connect:

```
PROXY_REST_DYNAMIC=true

XDS_PORT=<gm-control-http-port>
```

`XDS_PORT` should match the port of the environment variable `GM_CONTROL_XDS_GATEWAY_ADDR` set for Grey Matter Control. By default this value is `50001`.

## Verify Connection

If you receive repeated proxy log messages in the form below, it means that the connection to `gm-control` is failing. Usually this is because the address is incorrect or not addressable. If these logs do not appear, the connection is successful.

{% hint style="info" %}
**Note:** a single, or intermittent, occurrence of this error message often occurs during startup, and is not a concern.
{% endhint %}

```
[2019-10-11 15:21:51.635][8][warning][config] [bazel-out/k8-fastbuild/bin/external/envoy/source/common/config/_virtual_includes/grpc_stream_lib/common/config/grpc_stream.h:102] gRPC config stream closed: 14, no healthy upstream
[2019-10-11 15:21:51.635][8][warning][config] [bazel-out/k8-fastbuild/bin/external/envoy/source/common/config/_virtual_includes/grpc_stream_lib/common/config/grpc_stream.h:56] Unable to establish new stream
```

## Questions

{% hint style="success" %}
**Need help connecting to Grey Matter Control?**

Create an account at [Grey Matter Support](https://support.greymatter.io/support/home) to reach our team.
{% endhint %}
