Skip to content

Upgrade libraries to pass the test #292

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
4a9f3cc
Store expiry date to the storage
ryokdy Sep 4, 2017
87953af
Fix test
ryokdy Sep 4, 2017
812f682
Change repository
ryokdy Sep 4, 2017
c48b202
Do not use ssl verification
ryokdy Sep 4, 2017
6bb07db
Merge auto-ssl/lua-resty-auto-ssl
ryokdy Jun 26, 2020
45bf5a9
Merge pull request #1 from ryokdy/merge-mar-2020
ryokdy Jun 26, 2020
ac034e5
Unlock the certificate renewal lock when verify_domain returns false
ryokdy Sep 8, 2020
f4d8a72
Merge branch 'merge-mar-2020'
ryokdy Oct 22, 2020
666e006
Remove wrong return value
ryokdy Oct 22, 2020
b591d76
Add test code which uses the original allow_domain function. This for…
ryokdy Oct 22, 2020
fa52b00
Add test code which uses the original allow_domain function. This for…
ryokdy Oct 22, 2020
6b440dc
Remove whitespaces
ryokdy Oct 22, 2020
3836379
Bump dehydrated to v0.7.1
cgunther Jul 14, 2023
20eaa9e
Merge pull request #1 from cgunther/dehydrated-0.7.1
randomthingsandstuff Aug 6, 2023
8369f26
Merge remote-tracking branch 'upstream/master'
ryokdy Nov 20, 2023
57c0880
Bump openresty to v1.21.4
ryokdy Nov 21, 2023
06030ed
Install ngrok from tar ball
ryokdy Nov 21, 2023
5aabc2b
Install ngrok via apt for Ubuntu
Nov 22, 2023
ee6975b
Dehydrated 0.71 needs hexdump
Nov 22, 2023
df87e4c
Merge remote-tracking branch 'origin/openresty-1-21' into openresty-1.21
ryokdy Nov 22, 2023
b03f517
Prevent too many request error due to race conditions
ryokdy Nov 22, 2023
c079506
Remove unused variable
ryokdy Nov 22, 2023
6b8c217
Remove custom code
ryokdy Nov 22, 2023
c04dfa7
Remove custom code
ryokdy Nov 22, 2023
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 .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- centos
- alpine
- ubuntu
- openresty1.13
- openresty1.21
- lua51
steps:
- uses: actions/checkout@v1
Expand Down
9 changes: 5 additions & 4 deletions Dockerfile-test
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
FROM openresty/openresty:1.15.8.1-4-centos
FROM openresty/openresty:1.21.4.1-0-centos

# Runtime dependencies
RUN yum -y install \
bash \
coreutils \
curl \
diffutils \
grep \
Expand All @@ -25,8 +24,10 @@ RUN yum -y install epel-release && \
lua \
procps-ng \
redis \
sudo \
https://bin.equinox.io/a/6iuHhJeWypm/ngrok-2.3.34-linux-amd64.rpm
sudo
RUN curl -fsSL -o /tmp/ngrok.tar.gz https://bin.equinox.io/c/bNyj1mQVY4c/ngrok-v3-stable-linux-amd64.tgz && \
tar -xvf /tmp/ngrok.tar.gz -C /usr/local/bin/ && \
rm -f /tmp/ngrok.tar.gz

RUN mkdir /app
WORKDIR /app
Expand Down
9 changes: 4 additions & 5 deletions Dockerfile-test-alpine
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM openresty/openresty:1.15.8.2-1-alpine-fat
FROM openresty/openresty:1.21.4.1-0-alpine-fat

RUN mkdir /app
WORKDIR /app
Expand Down Expand Up @@ -27,11 +27,10 @@ RUN apk add --no-cache \
redis \
sudo \
tzdata \
wget && \
curl -fsSL -o /tmp/ngrok.tar.gz https://bin.equinox.io/a/naDTyS8Kyxv/ngrok-2.3.34-linux-386.tar.gz && \
wget
RUN curl -fsSL -o /tmp/ngrok.tar.gz https://bin.equinox.io/c/bNyj1mQVY4c/ngrok-v3-stable-linux-386.tgz && \
tar -xvf /tmp/ngrok.tar.gz -C /usr/local/bin/ && \
rm -f /tmp/ngrok.tar.gz && \
chmod +x /usr/local/bin/ngrok
rm -f /tmp/ngrok.tar.gz

COPY Makefile /app/Makefile
RUN make install-test-deps
Expand Down
9 changes: 5 additions & 4 deletions Dockerfile-test-lua51
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
FROM openresty/openresty:1.11.2.1-centos
FROM openresty/openresty:1.21.4.1-0-centos

# Runtime dependencies
RUN yum -y install \
bash \
coreutils \
curl \
diffutils \
grep \
Expand All @@ -22,8 +21,10 @@ RUN yum -y install epel-release && \
lua \
procps-ng \
redis \
sudo \
https://bin.equinox.io/a/6iuHhJeWypm/ngrok-2.3.34-linux-amd64.rpm
sudo
RUN curl -fsSL -o /tmp/ngrok.tar.gz https://bin.equinox.io/c/bNyj1mQVY4c/ngrok-v3-stable-linux-amd64.tgz && \
tar -xvf /tmp/ngrok.tar.gz -C /usr/local/bin/ && \
rm -f /tmp/ngrok.tar.gz

ENV PATH /usr/local/openresty/luajit/bin:/usr/local/openresty/bin:/usr/local/openresty/nginx/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
ENV TEST_NGINX_RESOLVER 127.0.0.11 ipv6=off
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
FROM openresty/openresty:1.13.6.2-2-centos
FROM openresty/openresty:1.21.4.1-0-centos

# Runtime dependencies
RUN yum -y install \
bash \
coreutils \
curl \
diffutils \
grep \
Expand All @@ -22,8 +21,10 @@ RUN yum -y install epel-release && \
lua \
procps-ng \
redis \
sudo \
https://bin.equinox.io/a/6iuHhJeWypm/ngrok-2.3.34-linux-amd64.rpm
sudo
RUN curl -fsSL -o /tmp/ngrok.tar.gz https://bin.equinox.io/c/bNyj1mQVY4c/ngrok-v3-stable-linux-amd64.tgz && \
tar -xvf /tmp/ngrok.tar.gz -C /usr/local/bin/ && \
rm -f /tmp/ngrok.tar.gz

RUN mkdir /app
WORKDIR /app
Expand Down
17 changes: 10 additions & 7 deletions Dockerfile-test-ubuntu
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
FROM openresty/openresty:1.15.8.2-1-bionic
FROM openresty/openresty:1.21.4.1-0-jammy

ENV DEBIAN_FRONTEND noninteractive

# Runtime dependencies
RUN apt-get update && \
apt-get -y install \
bash \
coreutils \
curl \
diffutils \
grep \
Expand All @@ -22,13 +21,17 @@ RUN apt-get update && \
apt-get -y install \
git \
lsof \
lua5.2 \
lua5.4 \
redis-server \
sudo \
tzdata && \
curl -fsSL -o /tmp/ngrok.deb https://bin.equinox.io/a/b2wQezFbsHk/ngrok-2.3.34-linux-amd64.deb && \
dpkg -i /tmp/ngrok.deb || apt-get -fy install && \
rm -f /tmp/ngrok.deb
tzdata \
bsdmainutils
RUN curl -s https://ngrok-agent.s3.amazonaws.com/ngrok.asc | \
sudo tee /etc/apt/trusted.gpg.d/ngrok.asc >/dev/null && \
echo "deb https://ngrok-agent.s3.amazonaws.com buster main" | \
sudo tee /etc/apt/sources.list.d/ngrok.list && \
sudo apt update && \
sudo apt install ngrok

RUN mkdir /app
WORKDIR /app
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ROOT_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
BUILD_DIR?=$(ROOT_DIR)/build

DEHYDRATED_VERSION:=05eda91a2fbaed1e13c733230238fc68475c535e
DEHYDRATED_VERSION:=ea841998631561543357f032fa7c06598c34d517
LUA_RESTY_SHELL_VERSION:=955243d70506c21e7cc29f61d745d1a8a718994f
SOCKPROC_VERSION:=92aba736027bb5d96e190b71555857ac5bb6b2be

Expand Down Expand Up @@ -95,11 +95,11 @@ install-test-deps:
luarocks --tree=/tmp/resty-auto-ssl-test-luarocks install busted 2.0.0-1
luarocks --tree=/tmp/resty-auto-ssl-test-luarocks install etlua 1.3.0-1
luarocks --tree=/tmp/resty-auto-ssl-test-luarocks install inspect 3.1.1-0
luarocks --tree=/tmp/resty-auto-ssl-test-luarocks install lua-resty-http 0.15-0
luarocks --tree=/tmp/resty-auto-ssl-test-luarocks install lua-resty-http 0.17.1-0
luarocks --tree=/tmp/resty-auto-ssl-test-luarocks install luacheck 0.23.0-1
luarocks --tree=/tmp/resty-auto-ssl-test-luarocks install luaposix 34.1.1-1
luarocks --tree=/tmp/resty-auto-ssl-test-luarocks install penlight 1.5.4-1
luarocks install luarocks-fetch-gitrec && luarocks --tree=/tmp/resty-auto-ssl-test-luarocks install process 1.9.0-1
luarocks install luarocks-fetch-gitrec && luarocks --tree=/tmp/resty-auto-ssl-test-luarocks install process 1.9.1-1
luarocks --tree=/tmp/resty-auto-ssl-test-luarocks install shell-games 1.0.1-1

lint:
Expand Down
8 changes: 4 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ services:
- ubuntu_build_cache:/app/build
sysctls:
net.core.somaxconn: 1024
openresty1.13:
openresty1.21:
build:
context: .
dockerfile: Dockerfile-test-openresty1.13
dockerfile: Dockerfile-test-openresty1.21
volumes:
- .:/app
- openresty1.13_build_cache:/app/build
- openresty1.21_build_cache:/app/build
sysctls:
net.core.somaxconn: 1024
lua51:
Expand All @@ -59,5 +59,5 @@ volumes:
centos_build_cache:
alpine_build_cache:
ubuntu_build_cache:
openresty1.13_build_cache:
openresty1.21_build_cache:
lua51_build_cache:
41 changes: 37 additions & 4 deletions lib/resty/auto-ssl/ssl_certificate.lua
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,24 @@ local function get_ocsp_response(fullchain_der, auto_ssl_instance)
return ocsp_resp
end

local function set_ocsp_stapling(domain, cert_der, auto_ssl_instance)
-- Fetch the OCSP stapling response from the cache, or make the request to
-- fetch it.
local function get_ocsp_response_unlock(local_lock)
local _, local_unlock_err = local_lock:unlock()
if local_unlock_err then
ngx.log(ngx.ERR, "auto-ssl: failed to unlock: ", local_unlock_err)
end
end

local function get_ocsp_response_lock(domain, cert_der, auto_ssl_instance)
-- Before issuing a cert, create a local lock to ensure multiple workers
-- don't simultaneously try to get OCSP response for the same cert.
local local_lock, new_local_lock_err = lock:new("auto_ssl", { exptime = 30, timeout = 5 })
if new_local_lock_err then
return nil, "auto-ssl: failed to create lock: " .. (new_local_lock_err or "")
end
local _, local_lock_err = local_lock:lock("set_ocsp_stapling:" .. domain)
if local_lock_err then
return nil, "auto-ssl: failed to obtain lock: " .. (local_lock_err or "")
end
local ocsp_resp = ngx.shared.auto_ssl:get("domain:ocsp:" .. domain)
if not ocsp_resp then
-- If the certificate was just issued on the current request, wait 1 second
Expand All @@ -222,7 +237,8 @@ local function set_ocsp_stapling(domain, cert_der, auto_ssl_instance)
local ocsp_response_err
ocsp_resp, ocsp_response_err = get_ocsp_response(cert_der["fullchain_der"], auto_ssl_instance)
if ocsp_response_err then
return false, "failed to get ocsp response: " .. (ocsp_response_err or "")
get_ocsp_response_unlock(local_lock)
return nil, "failed to get ocsp response: " .. (ocsp_response_err or "")
end

-- Cache the OCSP stapling response for 1 hour (this is what nginx does by
Expand All @@ -235,6 +251,23 @@ local function set_ocsp_stapling(domain, cert_der, auto_ssl_instance)
end
end

get_ocsp_response_unlock(local_lock)

return ocsp_resp
end

local function set_ocsp_stapling(domain, cert_der, auto_ssl_instance)
-- Fetch the OCSP stapling response from the cache, or make the request to
-- fetch it.
local ocsp_resp = ngx.shared.auto_ssl:get("domain:ocsp:" .. domain)
if not ocsp_resp then
local ocsp_response_err
ocsp_resp, ocsp_response_err = get_ocsp_response_lock(domain, cert_der, auto_ssl_instance)
if not ocsp_resp then
return false, ocsp_response_err
end
end

-- Set the OCSP stapling response.
local ok, ocsp_status_err = ocsp.set_ocsp_status_resp(ocsp_resp)
if not ok then
Expand Down
32 changes: 32 additions & 0 deletions spec/certs/letsencrypt-stg-root-x1.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
-----BEGIN CERTIFICATE-----
MIIFmDCCA4CgAwIBAgIQU9C87nMpOIFKYpfvO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RLAgMBAAGjQjBAMA4GA1UdDwEB/wQEAwIBBjAPBgNVHRMB
Af8EBTADAQH/MB0GA1UdDgQWBBS182Xy/rAKkh/7PH3zRKCsYyXDFDANBgkqhkiG
9w0BAQsFAAOCAgEAncDZNytDbrrVe68UT6py1lfF2h6Tm2p8ro42i87WWyP2LK8Y
nLHC0hvNfWeWmjZQYBQfGC5c7aQRezak+tHLdmrNKHkn5kn+9E9LCjCaEsyIIn2j
qdHlAkepu/C3KnNtVx5tW07e5bvIjJScwkCDbP3akWQixPpRFAsnP+ULx7k0aO1x
qAeaAhQ2rgo1F58hcflgqKTXnpPM02intVfiVVkX5GXpJjK5EoQtLceyGOrkxlM/
sTPq4UrnypmsqSagWV3HcUlYtDinc+nukFk6eR4XkzXBbwKajl0YjztfrCIHOn5Q
CJL6TERVDbM/aAPly8kJ1sWGLuvvWYzMYgLzDul//rUF10gEMWaXVZV51KpS9DY/
5CunuvCXmEQJHo7kGcViT7sETn6Jz9KOhvYcXkJ7po6d93A/jy4GKPIPnsKKNEmR
xUuXY4xRdh45tMJnLTUDdC9FIU0flTeO9/vNpVA8OPU1i14vCz+MU8KX1bV3GXm/
fxlB7VBBjX9v5oUep0o/j68R/iDlCOM4VVfRa8gX6T2FU7fNdatvGro7uQzIvWof
gN9WUwCbEMBy/YhBSrXycKA8crgGg3x1mIsopn88JKwmMBa68oS7EHM9w7C4y71M
7DiA+/9Qdp9RBWJpTS9i/mDnJg1xvo8Xz49mrrgfmcAXTCJqXi24NatI3Oc=
-----END CERTIFICATE-----
56 changes: 0 additions & 56 deletions spec/certs/letsencrypt_staging_chain.pem

This file was deleted.

2 changes: 1 addition & 1 deletion spec/config/busted-nginx.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
lua_ssl_trusted_certificate /app/spec/certs/letsencrypt_staging_chain.pem;
lua_ssl_trusted_certificate /app/spec/certs/letsencrypt-stg-root-x1.pem;
lua_ssl_verify_depth 5;
lua_shared_dict test_counts 128k;
2 changes: 1 addition & 1 deletion spec/proxy_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe("proxy", function()
local error_log = server.read_error_log()
assert.matches("auto-ssl: issuing new certificate for " .. server.ngrok_hostname, error_log, nil, true)
assert.matches("http proxy auth: Basic ZGVtbzp0ZXN0", error_log, nil, true)
assert.matches("auto-ssl: failed to set ocsp stapling for " .. server.ngrok_hostname .. " - continuing anyway - failed to get ocsp response: OCSP responder returns bad response body (http://ocsp.stg-int-x1.letsencrypt.org): ,", error_log, nil, true)
assert.matches("auto-ssl: failed to set ocsp stapling for " .. server.ngrok_hostname .. " - continuing anyway - failed to get ocsp response: OCSP responder returns bad response body (http://stg-e1.o.lencr.org): ,", error_log, nil, true)
assert.Not.matches("[warn]", error_log, nil, true)
assert.matches("[error]", error_log, nil, true)
assert.Not.matches("[alert]", error_log, nil, true)
Expand Down
6 changes: 3 additions & 3 deletions spec/support/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ end
local function start_ngrok()
if not _M.ngrok_hostname then
assert(dir.makepath(_M.ngrok_test_dir))
local ngrok_process, exec_err = process.exec("ngrok", { "http", "9080", "--log", _M.ngrok_test_dir .. "/ngrok.log", "--log-format", "logfmt", "--log-level", "debug" })
local ngrok_process, exec_err = process.exec("ngrok", { "http", "9080", "--scheme", "http", "--log", _M.ngrok_test_dir .. "/ngrok.log", "--log-format", "logfmt", "--log-level", "debug" })
assert(not exec_err, exec_err)
_M.ngrok_process = ngrok_process

local log = log_tail.new(_M.ngrok_test_dir .. "/ngrok.log")
local ok, output = log:read_until("start tunnel listen.*Hostname:[a-z0-9]+.ngrok.io")
local ok, output = log:read_until("started tunnel.*url=https?://[a-z0-9-]+.ngrok.io")
if not ok then
print(ngrok_process:stdout())
print(ngrok_process:stderr())
Expand All @@ -68,7 +68,7 @@ local function start_ngrok()
error("ngrok did not startup as expected")
end

local matches, match_err = ngx.re.match(output, "Hostname:([a-z0-9]+.ngrok.io)", "jo")
local matches, match_err = ngx.re.match(output, "url=https?://([a-z0-9-]+.ngrok.io)", "jo")
assert(not match_err, match_err)
_M.ngrok_hostname = matches[1]
end
Expand Down