|
| 1 | +--- |
| 2 | +title: HTTP/3 Protocol |
| 3 | +--- |
| 4 | + |
| 5 | +<!-- |
| 6 | +# |
| 7 | +# Licensed to the Apache Software Foundation (ASF) under one or more |
| 8 | +# contributor license agreements. See the NOTICE file distributed with |
| 9 | +# this work for additional information regarding copyright ownership. |
| 10 | +# The ASF licenses this file to You under the Apache License, Version 2.0 |
| 11 | +# (the "License"); you may not use this file except in compliance with |
| 12 | +# the License. You may obtain a copy of the License at |
| 13 | +# |
| 14 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 15 | +# |
| 16 | +# Unless required by applicable law or agreed to in writing, software |
| 17 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 18 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 19 | +# See the License for the specific language governing permissions and |
| 20 | +# limitations under the License. |
| 21 | +# |
| 22 | +--> |
| 23 | + |
| 24 | +[HTTP/3](https://en.wikipedia.org/wiki/HTTP/3) is the third major version of the Hypertext Transfer Protocol (HTTP). Unlike its predecessors which rely on TCP, HTTP/3 is based on [QUIC (Quick UDP Internet Connections) protocol](https://en.wikipedia.org/wiki/QUIC). It brings several benefits that collectively result in reduced latency and improved performance: |
| 25 | + |
| 26 | +* enabling seamless transition between different network connections, such as switching from Wi-Fi to mobile data. |
| 27 | +* eliminating head-of-line blocking, so that a lost packet does not block all streams. |
| 28 | +* negotiating TLS versions at the same time as the TLS handshakes, allowing for faster connections. |
| 29 | +* providing encryption by default, ensuring that all data transmitted over an HTTP/3 connection is protected and confidential. |
| 30 | +* providing zero round-trip time (0-RTT) when communicating with servers that clients already established connections to. |
| 31 | + |
| 32 | +APISIX currently supports HTTP/3 connections between downstream clients and APISIX. HTTP/3 connections with upstream services are not yet supported, and contributions are welcomed. |
| 33 | + |
| 34 | +:::caution |
| 35 | + |
| 36 | +This feature is currently experimental and not recommended for production use. |
| 37 | + |
| 38 | +::: |
| 39 | + |
| 40 | +This document will show you how to configure APISIX to enable HTTP/3 connections between client and APISIX and document a few known issues. |
| 41 | + |
| 42 | +## Usage |
| 43 | + |
| 44 | +### Enable HTTP/3 in APISIX |
| 45 | + |
| 46 | +Enable HTTP/3 on port `9443` (or a different port) by adding the following configurations to APISIX's `config.yaml` configuration file: |
| 47 | + |
| 48 | +```yaml title="config.yaml" |
| 49 | +apisix: |
| 50 | + ssl: |
| 51 | + listen: |
| 52 | + - port: 9443 |
| 53 | + enable_http3: true |
| 54 | + ssl_protocols: TLSv1.3 |
| 55 | +``` |
| 56 | +
|
| 57 | +:::info |
| 58 | +
|
| 59 | +If you are deploying APISIX using Docker, make sure to allow UDP in the HTTP3 port, such as `-p 9443:9443/udp`. |
| 60 | + |
| 61 | +::: |
| 62 | + |
| 63 | +Then reload APISIX for configuration changes to take effect: |
| 64 | + |
| 65 | +```shell |
| 66 | +apisix reload |
| 67 | +``` |
| 68 | + |
| 69 | +### Generate Certificates and Keys |
| 70 | + |
| 71 | +HTTP/3 requires TLS. You can leverage the purchased certificates or self-generate them, whichever applicable. |
| 72 | + |
| 73 | +To self-generate, first generate the certificate authority (CA) key and certificate: |
| 74 | + |
| 75 | +```shell |
| 76 | +openssl genrsa -out ca.key 2048 && \ |
| 77 | + openssl req -new -sha256 -key ca.key -out ca.csr -subj "/CN=ROOTCA" && \ |
| 78 | + openssl x509 -req -days 36500 -sha256 -extensions v3_ca -signkey ca.key -in ca.csr -out ca.crt |
| 79 | +``` |
| 80 | + |
| 81 | +Next, generate the key and certificate with a common name for APISIX, and sign with the CA certificate: |
| 82 | + |
| 83 | +```shell |
| 84 | +openssl genrsa -out server.key 2048 && \ |
| 85 | + openssl req -new -sha256 -key server.key -out server.csr -subj "/CN=test.com" && \ |
| 86 | + openssl x509 -req -days 36500 -sha256 -extensions v3_req \ |
| 87 | + -CA ca.crt -CAkey ca.key -CAserial ca.srl -CAcreateserial \ |
| 88 | + -in server.csr -out server.crt |
| 89 | +``` |
| 90 | + |
| 91 | +### Configure HTTPS |
| 92 | + |
| 93 | +Optionally load the content stored in `server.crt` and `server.key` into shell variables: |
| 94 | + |
| 95 | +```shell |
| 96 | +server_cert=$(cat server.crt) |
| 97 | +server_key=$(cat server.key) |
| 98 | +``` |
| 99 | + |
| 100 | +Create an SSL certificate object to save the server certificate and its key: |
| 101 | + |
| 102 | +```shell |
| 103 | +curl -i "http://127.0.0.1:9180/apisix/admin/ssls" -X PUT -d ' |
| 104 | +{ |
| 105 | + "id": "quickstart-tls-client-ssl", |
| 106 | + "sni": "test.com", |
| 107 | + "cert": "'"${server_cert}"'", |
| 108 | + "key": "'"${server_key}"'" |
| 109 | +}' |
| 110 | +``` |
| 111 | + |
| 112 | +### Create a Route |
| 113 | + |
| 114 | +Create a sample route to `httpbin.org`: |
| 115 | + |
| 116 | +```shell |
| 117 | +curl "http://127.0.0.1:9180/apisix/admin/routes" -X PUT -d ' |
| 118 | +{ |
| 119 | + "id":"httpbin-route", |
| 120 | + "uri":"/get", |
| 121 | + "upstream": { |
| 122 | + "type":"roundrobin", |
| 123 | + "nodes": { |
| 124 | + "httpbin.org:80": 1 |
| 125 | + } |
| 126 | + } |
| 127 | +}' |
| 128 | +``` |
| 129 | + |
| 130 | +### Verify HTTP/3 Connections |
| 131 | + |
| 132 | +Install [static-curl](https://github.com/stunnel/static-curl) or any other curl executable that has HTTP/3 support. |
| 133 | + |
| 134 | +Send a request to the route: |
| 135 | + |
| 136 | +```shell |
| 137 | +curl -kv --http3-only \ |
| 138 | + -H "Host: test.com" \ |
| 139 | + --resolve "test.com:9443:127.0.0.1" "https://test.com:9443/get" |
| 140 | +``` |
| 141 | + |
| 142 | +You should receive an `HTTP/3 200` response similar to the following: |
| 143 | + |
| 144 | +```text |
| 145 | +* Added test.com:9443:127.0.0.1 to DNS cache |
| 146 | +* Hostname test.com was found in DNS cache |
| 147 | +* Trying 127.0.0.1:9443... |
| 148 | +* QUIC cipher selection: TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_CCM_SHA256 |
| 149 | +* Skipped certificate verification |
| 150 | +* Connected to test.com (127.0.0.1) port 9443 |
| 151 | +* using HTTP/3 |
| 152 | +* [HTTP/3] [0] OPENED stream for https://test.com:9443/get |
| 153 | +* [HTTP/3] [0] [:method: GET] |
| 154 | +* [HTTP/3] [0] [:scheme: https] |
| 155 | +* [HTTP/3] [0] [:authority: test.com] |
| 156 | +* [HTTP/3] [0] [:path: /get] |
| 157 | +* [HTTP/3] [0] [user-agent: curl/8.7.1] |
| 158 | +* [HTTP/3] [0] [accept: */*] |
| 159 | +> GET /get HTTP/3 |
| 160 | +> Host: test.com |
| 161 | +> User-Agent: curl/8.7.1 |
| 162 | +> Accept: */* |
| 163 | +> |
| 164 | +* Request completely sent off |
| 165 | +< HTTP/3 200 |
| 166 | +... |
| 167 | +{ |
| 168 | + "args": {}, |
| 169 | + "headers": { |
| 170 | + "Accept": "*/*", |
| 171 | + "Content-Length": "0", |
| 172 | + "Host": "test.com", |
| 173 | + "User-Agent": "curl/8.7.1", |
| 174 | + "X-Amzn-Trace-Id": "Root=1-6656013a-27da6b6a34d98e3e79baaf5b", |
| 175 | + "X-Forwarded-Host": "test.com" |
| 176 | + }, |
| 177 | + "origin": "172.19.0.1, 123.40.79.456", |
| 178 | + "url": "http://test.com/get" |
| 179 | +} |
| 180 | +* Connection #0 to host test.com left intact |
| 181 | +``` |
| 182 | + |
| 183 | +## Known Issues |
| 184 | + |
| 185 | +- For APISIX-3.9, test cases of Tongsuo will fail because the Tongsuo does not support QUIC TLS. |
| 186 | +- APISIX-3.9 is based on NGINX-1.25.3 with vulnerabilities in HTTP/3 (CVE-2024-24989, CVE-2024-24990). |
0 commit comments