Skip to content
Closed
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
2 changes: 1 addition & 1 deletion .requirements
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@

APISIX_PACKAGE_NAME=apisix

APISIX_RUNTIME=1.5.0
APISIX_RUNTIME=1.5.1
APISIX_DASHBOARD_COMMIT=e5e1457ed972a0dc9634a84ee58bb9aa5a6fa4af
4 changes: 2 additions & 2 deletions apisix/cli/ngx_tpl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ stream {
{% if server_group.tcp_enable_ssl then %}
ssl_certificate {* ssl.ssl_cert *};
ssl_certificate_key {* ssl.ssl_cert_key *};
{% if stream_ssl_session_ticket_takeover and not server_group.tls_mixed then %}
{% if ssl_session_ticket_takeover and not server_group.tls_mixed then %}
# session tickets only with the shared keys, see the ssl-session-ticket plugin
ssl_session_tickets off;
apisix_ssl_session_ticket_takeover on;
Expand Down Expand Up @@ -308,7 +308,7 @@ stream {

ssl_certificate {* ssl.ssl_cert *};
ssl_certificate_key {* ssl.ssl_cert_key *};
{% if stream_ssl_session_ticket_takeover then %}
{% if ssl_session_ticket_takeover then %}
# session tickets only with the shared keys, see the ssl-session-ticket plugin
ssl_session_tickets off;
apisix_ssl_session_ticket_takeover on;
Expand Down
41 changes: 1 addition & 40 deletions apisix/cli/ops.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ local print = print
local type = type
local tostring = tostring
local tonumber = tonumber
local select = select
local io_open = io.open
local execute = os.execute
local os_rename = os.rename
Expand Down Expand Up @@ -176,26 +175,6 @@ local function parse_listen_addr(addr)
end


-- Whether a snippet of nginx_config sets the native session ticket keys, which
-- conflict with the takeover of the keys: the business listeners of that
-- subsystem then keep the native session tickets of NGINX.
local function sets_ticket_key(...)
for i = 1, select("#", ...) do
local snippet = select(i, ...)
if type(snippet) == "string" then
for line in snippet:gmatch("[^\n]+") do
line = line:gsub("#.*", "")
if line:find("%f[%w_]ssl_session_ticket_key%f[^%w_]") then
return true
end
end
end
end

return false
end


local function help()
print([[
Usage: apisix [action] <argument>
Expand Down Expand Up @@ -870,23 +849,6 @@ Please modify "admin_key" in conf/config.yaml .
zipkin_set_ngx_var = yaml_conf.plugin_attr["zipkin"].set_ngx_var
end

local http_takeover = env.ssl_session_ticket_takeover
local stream_takeover = env.ssl_session_ticket_takeover
local ngx_conf = yaml_conf.nginx_config or {}
if http_takeover and sets_ticket_key(ngx_conf.http_configuration_snippet,
ngx_conf.http_server_configuration_snippet) then
http_takeover = false
stderr:write("WARNING: nginx_config sets ssl_session_ticket_key, the business ",
"HTTPS listeners keep the native session tickets and do not use ",
"the keys of the ssl-session-ticket plugin\n")
end
if stream_takeover and sets_ticket_key(ngx_conf.stream_configuration_snippet) then
stream_takeover = false
stderr:write("WARNING: nginx_config sets ssl_session_ticket_key, the Stream TLS ",
"listeners keep the native session tickets and do not use the keys ",
"of the ssl-session-ticket plugin\n")
end

-- Using template.render
local sys_conf = {
lua_path = env.pkg_path_org,
Expand All @@ -895,8 +857,7 @@ Please modify "admin_key" in conf/config.yaml .
apisix_lua_home = env.apisix_home,
deployment_role = env.deployment_role,
use_apisix_base = env.use_apisix_base,
ssl_session_ticket_takeover = http_takeover,
stream_ssl_session_ticket_takeover = stream_takeover,
ssl_session_ticket_takeover = env.ssl_session_ticket_takeover,
error_log = {level = "warn"},
enable_http = enable_http,
enable_stream = enable_stream,
Expand Down
6 changes: 3 additions & 3 deletions ci/linux-install-openresty.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,19 @@ else
sudo apt-get -y update --fix-missing
sudo apt-get install -y build-essential gcc g++ cpanminus libxml2-dev libxslt-dev

if [ "$APISIX_RUNTIME" != "1.5.0" ]; then
if [ "$APISIX_RUNTIME" != "1.5.1" ]; then
echo "Please update the apisix-runtime-debug checksum for APISIX_RUNTIME=$APISIX_RUNTIME" >&2
exit 1
fi

case "$ARCH" in
x86_64|amd64)
DEB_ARCH="amd64"
EXPECTED_SHA256="f671140787ce707297739f6ab1a380cd9e1cdbbf1936677332d9b8d400ff6f20"
EXPECTED_SHA256="f4a40eab84afe77213cea78b0db1432c8df1ce7d130756da90cbda0b5fee291a"
;;
arm64|aarch64)
DEB_ARCH="arm64"
EXPECTED_SHA256="7d17cca6891e7c7a86e61795348760c4be56be6f9a36e937e921ab166489c006"
EXPECTED_SHA256="94acfcb9a769d535b2c2ffff864a21f1381973eb0ae929d020adfefafa887a01"
;;
*)
echo "Unsupported architecture: $ARCH" >&2
Expand Down
3 changes: 2 additions & 1 deletion docs/en/latest/plugins/ssl-session-ticket.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ The local switch `apisix.ssl.ssl_session_tickets` decides whether the business l

This takeover needs an APISIX Runtime whose `apisix-nginx-module` provides it. With an older APISIX Runtime, the listeners keep the behavior of the previous versions: the keys are published, but the TLS listeners do not use them and the Control API reports `module_not_active`.

When a snippet of `nginx_config` sets the native `ssl_session_ticket_key` (`http_configuration_snippet` or `http_server_configuration_snippet` for the HTTPS listeners, `stream_configuration_snippet` for the Stream TLS listeners), the listeners of that subsystem keep the native session tickets of NGINX with that key file and do not use the shared keys. `apisix init` prints a warning about it.
These listeners ignore a native `ssl_session_ticket_key`, whether a snippet of `nginx_config` sets it or a file that a snippet includes: NGINX logs an error, `ignoring "ssl_session_ticket_key" (takeover configured at ...)`, and the listeners only use the shared keys. To keep the keys of such a file, submit them as external keys.

## Generated Keys

Expand Down Expand Up @@ -278,6 +278,7 @@ With an APISIX Runtime that takes over the session ticket keys:
* The Stream TLS listeners used the native session tickets of NGINX, with random keys of each worker process. They now only issue tickets with the shared keys, and keep a session cache (`shared:STREAM_SSL:20m`): without keys, a Stream TLS session only resumes on the node that created it.
* The Admin API is not affected: it still uses the native session tickets of NGINX only when `apisix.ssl.ssl_session_tickets` is explicitly true.
* A configuration that had the session tickets on does not get them back by itself: enable the Plugin and provide keys, see [Example Usage](#example-usage).
* A native `ssl_session_ticket_key` of the business listeners is ignored, with an error in the log. Its keys can be submitted as external keys.

## Security

Expand Down
3 changes: 2 additions & 1 deletion docs/zh/latest/plugins/ssl-session-ticket.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ worker 会在一秒内应用新的密钥集合,并在每个新连接到达 Cli

该接管需要 `apisix-nginx-module` 提供这一能力的 APISIX Runtime。使用较早的 APISIX Runtime 时,监听保持之前版本的行为:密钥照常发布,但 TLS 监听不使用它们,Control API 报告 `module_not_active`。

如果 `nginx_config` 的配置片段设置了原生的 `ssl_session_ticket_key`(HTTPS 监听对应 `http_configuration_snippet` 或 `http_server_configuration_snippet`,Stream TLS 监听对应 `stream_configuration_snippet`),该子系统的监听保留 NGINX 原生的 session ticket,使用该密钥文件,不使用共享密钥。`apisix init` 会输出警告。
这些监听会忽略原生的 `ssl_session_ticket_key`,无论它直接写在 `nginx_config` 的配置片段里,还是来自配置片段 include 的文件:NGINX 记录一条错误日志 `ignoring "ssl_session_ticket_key" (takeover configured at ...)`,这些监听只使用共享密钥。如需继续使用该文件中的密钥,请将它们作为外部密钥提交。

## 内置生成

Expand Down Expand Up @@ -279,6 +279,7 @@ standalone 配置中的密钥是明文,APISIX 不会加密它们,请保护
* Stream TLS 监听以前使用 NGINX 原生的 session ticket,每个 worker 进程各自使用随机密钥;现在只用共享密钥签发 ticket,并带有会话缓存(`shared:STREAM_SSL:20m`):没有密钥时,Stream TLS 会话只能在创建它的节点上恢复。
* Admin API 不受影响:仍然只在 `apisix.ssl.ssl_session_tickets` 显式为 true 时使用 NGINX 原生的 session ticket。
* 以前打开了 session ticket 的配置不会自动恢复 ticket:请启用插件并提供密钥,参见[使用示例](#使用示例)。
* 业务监听上原生的 `ssl_session_ticket_key` 会被忽略,并在日志中记录错误。其中的密钥可以作为外部密钥提交。

## 安全

Expand Down
85 changes: 68 additions & 17 deletions t/cli/test_ssl_session_ticket_takeover.sh
Original file line number Diff line number Diff line change
Expand Up @@ -151,31 +151,82 @@ if ssl_session_ticket_takeover; then
check false off off off 1
echo "passed: the business TLS listeners take over their session ticket keys"

# a native key file set in a snippet keeps the native session tickets of
# the listeners of that subsystem, which would conflict with the takeover
# a native key file, set in a snippet or included from another file, is
# ignored: the listeners start, NGINX logs an error and the shared keys
# issue the tickets
mkdir -p logs
head -c 80 /dev/urandom > logs/ticket.key
write_conf true
echo "
echo "ssl_session_ticket_key $PWD/logs/ticket.key;" > logs/ticket.conf
shared=$(printf 'ticket-name-0001%064d' 0 | base64 -w0)
json_file() {
awk 'BEGIN { printf "\"" } { printf "%s\\n", $0 } END { printf "\"" }' "$1"
}
etcdctl put /apisix/ssls/1 "{\"cert\": $(json_file t/certs/apisix.crt), \
\"key\": $(json_file t/certs/apisix.key), \"snis\": [\"test.com\"]}" > /dev/null
etcdctl put /apisix/stream_routes/1 \
'{"upstream": {"nodes": {"127.0.0.1:2379": 1}, "type": "roundrobin"}}' > /dev/null
etcdctl put /apisix/plugin_metadata/ssl-session-ticket \
"{\"id\":\"ssl-session-ticket\",\"keys\":[\"$shared\"],\
\"origin\":{\"source\":\"external\",\"disabled\":false}}" > /dev/null

# the name of the key of the TLSv1.2 ticket of a new session, if any
ticket_of() {
printf 'Q\n' | timeout 10 openssl s_client -connect "127.0.0.1:$1" -servername test.com \
-tls1_2 -sess_out logs/sess > /dev/null 2>&1 || true
openssl sess_id -in logs/sess -noout -text 2> /dev/null \
| grep -A1 'TLS session ticket:' | grep -Eo 'ticket-name-[0-9]{4}' || true
}
resumed() {
printf 'Q\n' | timeout 10 openssl s_client -connect "127.0.0.1:$1" -servername test.com \
-tls1_2 -sess_in logs/sess 2>&1 | grep -q '^Reused,'
}

for line in "ssl_session_ticket_key $PWD/logs/ticket.key;" "include $PWD/logs/ticket.conf;"; do
write_conf true
echo "
ssl-session-ticket:
enabled: true
key_source: external
nginx_config:
http_server_configuration_snippet: |
ssl_session_ticket_key $PWD/logs/ticket.key;
$line
stream_configuration_snippet: |
ssl_session_ticket_key $PWD/logs/ticket.key;
$line
" >> conf/config.yaml
out=$(make init 2>&1)
for listeners in "business HTTPS" "Stream TLS"; do
if ! echo "$out" | grep -q "the $listeners listeners keep the native session tickets"; then
echo "failed: no warning about the native keys of the $listeners listeners"
make init
expect "listen 0[.]0[.]0[.]0:9443 +ssl +default_server" off 1
expect "listen 9100 +ssl" off 1
rm -f logs/error.log
make run
for port in 9443 9100; do
deadline=$(( $(date +%s) + 20 ))
until [ "$(ticket_of $port)" = ticket-name-0001 ]; do
if [ "$(date +%s)" -ge "$deadline" ]; then
echo "failed: $port issues no ticket with the shared key ($line)"
tail -n 30 logs/error.log
exit 1
fi
sleep 0.5
done
if ! resumed $port; then
echo "failed: a session of $port does not resume ($line)"
exit 1
fi
done
# one per listener: the HTTPS, the Stream TLS and the mixed Stream ones
count=$(grep -c '\[error\].*ignoring "ssl_session_ticket_key" (takeover configured at' \
logs/error.log || true)
if [ "$count" -lt 3 ]; then
echo "failed: $count errors about the ignored ssl_session_ticket_key ($line)"
exit 1
fi
make stop
sleep 1
done
expect "listen 0[.]0[.]0[.]0:9443 +ssl +default_server" on 0
expect "listen 9100 +ssl" none 0
expect "listen unix:[^ ]*stls-t[0-9]*[.]sock +ssl" none 0
make run
sleep 1
make stop
echo "passed: a native key file keeps the native session tickets"
etcdctl del /apisix/ssls/1 > /dev/null
etcdctl del /apisix/stream_routes/1 > /dev/null
etcdctl del /apisix/plugin_metadata/ssl-session-ticket > /dev/null
echo "passed: a native key file, set or included, is ignored for the shared keys"
else
# as before: native tickets on the business HTTPS listener and the Admin
# API when explicitly asked, Stream TLS at the native default
Expand Down
Loading