Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Bump net-url to 1.2-1 [PR #1606](https://github.com/3scale/APIcast/pull/1606)
- Bump argparse to 0.7.2 [PR #1607](https://github.com/3scale/APIcast/pull/1607)
- Add `whitelist_deny_unmatched` option to keycloak_role_check policy [PR #1605](https://github.com/3scale/APIcast/pull/1605) [THREESCALE-11887](https://redhat.atlassian.net/browse/THREESCALE-11887)
- Add `APICAST_HTTP2` to toggle http/2 [PR #1617](https://github.com/3scale/APIcast/pull/1617) [THREESCALE-17104](https://redhat.atlassian.net/browse/THREESCALE-17104)

### Removed

Expand Down
9 changes: 9 additions & 0 deletions doc/parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,15 @@ If this parameter has `1` as its value, it is possible to include an additional

Enables verification of client certificates. You can verify client certificates TLS Client Certificate Validation policy.

### `APICAST_HTTP2`

**Default:** true
**Values:** boolean
**Example:** "false"

Enables HTTP/2 support on the HTTPS listener (`APICAST_HTTPS_PORT`). Set to
`false` or `0` to disable it and fall back to HTTP/1.1.

### `all_proxy`, `ALL_PROXY`

**Default:** no value
Expand Down
3 changes: 3 additions & 0 deletions gateway/http.d/apicast.conf.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,17 @@ server {
{%- assign https_port = env.APICAST_HTTPS_PORT %}
{%- assign http_proxy_protocol = env.APICAST_HTTP_PROXY_PROTOCOL %}
{%- assign https_proxy_protocol = env.APICAST_HTTPS_PROXY_PROTOCOL %}
{%- assign http2 = env.APICAST_HTTP2 %}

{% if http_port != https_port -%}
listen {{ http_port }} {% if http_proxy_protocol %}proxy_protocol {% endif %};
{% endif %}

{% if https_port -%}
listen {{ https_port }} ssl {% if https_proxy_protocol %}proxy_protocol{% endif %};
{% if http2 != "false" and http2 != "0" -%}
http2 on;
{%- endif %}

ssl_protocols TLSv1.2 TLSv1.3;
{%- assign https_certificate = env.APICAST_HTTPS_CERTIFICATE -%}
Expand Down
83 changes: 80 additions & 3 deletions t/apicast-http2.t
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ that is not https or HTTP2 enabled.
'APICAST_SSL_CERT_FILE_CA' => "$Test::Nginx::Util::ServRoot/html/ca.crt",
'APICAST_HTTPS_CERTIFICATE' => "$Test::Nginx::Util::ServRoot/html/server.crt",
'APICAST_HTTPS_CERTIFICATE_KEY' => "$Test::Nginx::Util::ServRoot/html/server.key",
'APICAST_WORKERS' => 2,
)
--- backend
location /transactions/authrep.xml {
Expand Down Expand Up @@ -113,6 +114,7 @@ $Test::Nginx::Util::ENDPOINT_SSL_PORT = Test::APIcast::get_random_port();
'APICAST_SSL_CERT_FILE_CA' => "$Test::Nginx::Util::ServRoot/html/ca.crt",
'APICAST_HTTPS_CERTIFICATE' => "$Test::Nginx::Util::ServRoot/html/server.crt",
'APICAST_HTTPS_CERTIFICATE_KEY' => "$Test::Nginx::Util::ServRoot/html/server.key",
'APICAST_WORKERS' => 2,
)
--- backend
location /transactions/authrep.xml {
Expand Down Expand Up @@ -155,7 +157,8 @@ EOF
--- custom_config eval
<<EOF
server {
listen $Test::Nginx::Util::ENDPOINT_SSL_PORT ssl http2;
listen $Test::Nginx::Util::ENDPOINT_SSL_PORT ssl;
http2 on;
ssl_certificate $Test::Nginx::Util::ServRoot/html/server.crt;
ssl_certificate_key $Test::Nginx::Util::ServRoot/html/server.key;

Expand Down Expand Up @@ -198,6 +201,7 @@ $Test::Nginx::Util::ENDPOINT_SSL_PORT = Test::APIcast::get_random_port();
'APICAST_PROXY_HTTPS_CERTIFICATE_KEY' => "$Test::Nginx::Util::ServRoot/html/client.key",
'APICAST_PROXY_HTTPS_PASSWORD_FILE' => "$Test::Nginx::Util::ServRoot/html/passwords.file",
'APICAST_PROXY_HTTPS_SESSION_REUSE' => 'on',
'APICAST_WORKERS' => 2,
)
--- backend
location /transactions/authrep.xml {
Expand Down Expand Up @@ -240,7 +244,8 @@ EOF
--- custom_config eval
<<EOF
server {
listen $Test::Nginx::Util::ENDPOINT_SSL_PORT ssl http2;
listen $Test::Nginx::Util::ENDPOINT_SSL_PORT ssl;
http2 on;

ssl_certificate $Test::Nginx::Util::ServRoot/html/server.crt;
ssl_certificate_key $Test::Nginx::Util::ServRoot/html/server.key;
Expand Down Expand Up @@ -287,6 +292,7 @@ $Test::Nginx::Util::ENDPOINT_SSL_PORT = Test::APIcast::get_random_port();
'APICAST_SSL_CERT_FILE_CA' => "$Test::Nginx::Util::ServRoot/html/ca.crt",
'APICAST_HTTPS_CERTIFICATE' => "$Test::Nginx::Util::ServRoot/html/server.crt",
'APICAST_HTTPS_CERTIFICATE_KEY' => "$Test::Nginx::Util::ServRoot/html/server.key",
'APICAST_WORKERS' => 2,
)
--- backend
location /transactions/authrep.xml {
Expand Down Expand Up @@ -341,7 +347,8 @@ EOF
--- custom_config eval
<<EOF
server {
listen $Test::Nginx::Util::ENDPOINT_SSL_PORT ssl http2;
listen $Test::Nginx::Util::ENDPOINT_SSL_PORT ssl;
http2 on;
ssl_certificate $Test::Nginx::Util::ServRoot/html/server.crt;
ssl_certificate_key $Test::Nginx::Util::ServRoot/html/server.key;

Expand Down Expand Up @@ -375,3 +382,73 @@ content_by_lua_block {
--- user_files fixture=CA/files.pl eval
--- no_error_log
[error]


=== TEST 5: APICAST_HTTP2=false disables HTTP2 termination.
This test disables HTTP2 termination on endpoint via APICAST_HTTP2 env var
and proxies to an api_backend that is not https or HTTP2 enabled.
The connection should be downgraded to http/1.1
--- env eval
(
'APICAST_HTTPS_PORT' => $ENV{APICAST_HTTPS_RANDOM_PORT},
'APICAST_HTTP2' => 'false',
'APICAST_WORKERS' => 2,
'APICAST_SSL_CERT_FILE_CA' => "$Test::Nginx::Util::ServRoot/html/ca.crt",
'APICAST_HTTPS_CERTIFICATE' => "$Test::Nginx::Util::ServRoot/html/server.crt",
'APICAST_HTTPS_CERTIFICATE_KEY' => "$Test::Nginx::Util::ServRoot/html/server.key",
)
--- backend
location /transactions/authrep.xml {
content_by_lua_block {
ngx.exit(200)
}
}
--- configuration
{
"services": [
{
"id": 42,
"backend_version": 1,
"backend_authentication_type": "service_token",
"backend_authentication_value": "token-value",
"proxy": {
"api_backend": "http://test:$TEST_NGINX_SERVER_PORT/",
"policy_chain": [
{
"name": "apicast.policy.apicast"
}
],
"proxy_rules": [
{
"pattern": "/",
"http_method": "GET",
"metric_system_name": "hits",
"delta": 1
}
]
}
}
]
}
--- upstream
location / {
content_by_lua_block {
ngx.say('yay, api backend');
}
}
--- test
content_by_lua_block {
local request = require("request")
local resty_env = require 'resty.env'

local https_port = resty_env.get('APICAST_HTTPS_PORT')
local uri = "https://localhost:".. https_port .."/?user_key=foo"
local req = request.request(uri, "get", "./t/fixtures/CA/ca-bundle.crt")
assert(req, "Request failed")
req:expect200()
req:expectHTTP1()
req:expectBody('yay, api backend\n')
}
--- user_files fixture=CA/files.pl eval
--- no_error_log
[error]
4 changes: 4 additions & 0 deletions t/helpers/request.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ function response:expectHTTP2()
assert.same(self:is_http2_request(), true, "Is not http2 connection")
end

function response:expectHTTP1()
assert.same(self:is_http2_request(), false, "Is not http1 connection")
end

function response:expectBody(body)
assert.same(self:body(), body, "BODY content mistmatch")
end
Expand Down
Loading