Skip to content

Commit

Permalink
[Doc] Add guides for TLS SNI support (cpp and python clients) (apache…
Browse files Browse the repository at this point in the history
…#9937)

Co-authored-by: Anonymitaet <anonymitaet_hotmail.com>
  • Loading branch information
Anonymitaet authored Mar 18, 2021
1 parent f49d094 commit 3bb9c54
Showing 1 changed file with 37 additions and 7 deletions.
44 changes: 37 additions & 7 deletions site2/docs/concepts-proxy-sni-routing.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,20 @@ title: Proxy support with SNI routing
sidebar_label: Proxy support with SNI routing
---

## Pulsar Proxy with SNI routing
A proxy server is an intermediary server that forwards requests from multiple clients to different servers across the Internet. The proxy server acts as a "traffic cop" in both forward and reverse proxy scenarios, and benefits your system such as load balancing, performance, security, auto-scaling, and so on.

The proxy in Pulsar acts as a reverse proxy, and creates a gateway in front of brokers. Proxies such as Apache Traffic Server (ATS), HAProxy, Nginx, and Envoy are not supported in Pulsar. These proxy-servers support **SNI routing**. SNI routing is used to route traffic to a destination without terminating the SSL connection. Layer 4 routing provides greater transparency because the outbound connection is determined by examining the destination address in the client TCP packets.

Pulsar clients support [SNI routing protocol](https://github.com/apache/pulsar/wiki/PIP-60:-Support-Proxy-server-with-SNI-routing), so you can connect to brokers through the proxy. This document walks you through how to set up the ATS proxy, enable SNI routing, and connect Pulsar client to the broker through the ATS proxy.
Pulsar clients (Java, C++, Python) support [SNI routing protocol](https://github.com/apache/pulsar/wiki/PIP-60:-Support-Proxy-server-with-SNI-routing), so you can connect to brokers through the proxy. This document walks you through how to set up the ATS proxy, enable SNI routing, and connect Pulsar client to the broker through the ATS proxy.

### ATS-SNI Routing in Pulsar
## ATS-SNI Routing in Pulsar
To support [layer-4 SNI routing](https://docs.trafficserver.apache.org/en/latest/admin-guide/layer-4-routing.en.html) with ATS, the inbound connection must be a TLS connection. Pulsar client supports SNI routing protocol on TLS connection, so when Pulsar clients connect to broker through ATS proxy, Pulsar uses ATS as a reverse proxy.

Pulsar supports SNI routing for geo-replication, so brokers can connect to brokers in other clusters through the ATS proxy.

This section explains how to set up and use ATS as a reverse proxy, so Pulsar clients can connect to brokers through the ATS proxy using the SNI routing protocol on TLS connection.

#### Set up ATS Proxy for layer-4 SNI routing
### Set up ATS Proxy for layer-4 SNI routing
To support layer 4 SNI routing, you need to configure the `records.conf` and `ssl_server_name.conf` files.

![Pulsar client SNI](assets/pulsar-sni-client.png)
Expand Down Expand Up @@ -70,10 +69,14 @@ server_config = {

After you configure the `ssl_server_name.config` and `records.config` files, the ATS-proxy server handles SNI routing and creates TCP tunnel between the client and the broker.

#### Configure Pulsar-client with SNI routing
### Configure Pulsar-client with SNI routing
ATS SNI-routing works only with TLS. You need to enable TLS for the ATS proxy and brokers first, configure the SNI routing protocol, and then connect Pulsar clients to brokers through ATS proxy. Pulsar clients support SNI routing by connecting to the proxy, and sending the target broker URL to the SNI header. This process is processed internally. You only need to configure the following proxy configuration initially when you create a Pulsar client to use the SNI routing protocol.

```
<!--DOCUSAURUS_CODE_TABS-->

<!--Java-->

```java
String brokerServiceUrl = “pulsar+ssl://pulsar-broker-vip:6651/”;
String proxyUrl = “pulsar+ssl://ats-proxy:443”;
ClientBuilder clientBuilder = PulsarClient.builder()
Expand All @@ -92,7 +95,34 @@ clientBuilder.authentication(AuthenticationTls.class.getName(), authParams);
PulsarClient pulsarClient = clientBuilder.build();
```

#### Pulsar geo-replication with SNI routing
<!--C++-->

```c++
ClientConfiguration config = ClientConfiguration();
config.setUseTls(true);
config.setTlsTrustCertsFilePath("/path/to/cacert.pem");
config.setTlsAllowInsecureConnection(false);
config.setAuth(pulsar::AuthTls::create(
"/path/to/client-cert.pem", "/path/to/client-key.pem"););

Client client("pulsar+ssl://ats-proxy:443", config);
```
<!--Python-->
```python
from pulsar import Client, AuthenticationTLS
auth = AuthenticationTLS("/path/to/my-role.cert.pem", "/path/to/my-role.key-pk8.pem")
client = Client("pulsar+ssl://ats-proxy:443",
tls_trust_certs_file_path="/path/to/ca.cert.pem",
tls_allow_insecure_connection=False,
authentication=auth)
```

<!--END_DOCUSAURUS_CODE_TABS-->

### Pulsar geo-replication with SNI routing
You can use the ATS proxy for geo-replication. Pulsar brokers can connect to brokers in geo-replication by using SNI routing. To enable SNI routing for broker connection cross clusters, you need to configure SNI proxy URL to the cluster metadata. If you have configured SNI proxy URL in the cluster metadata, you can connect to broker cross clusters through the proxy over SNI routing.

![Pulsar client SNI](assets/pulsar-sni-geo.png)
Expand Down

0 comments on commit 3bb9c54

Please sign in to comment.