Skip to content

Commit 03d9553

Browse files
build custom SSL images; add SSL tests (TeslaGov#126)
1 parent 032fa5c commit 03d9553

15 files changed

+442
-192
lines changed

.github/workflows/ci.yml renamed to .github/workflows/make-releases.yml

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ name: CI
33
on:
44
push:
55
branches:
6-
- 'master'
6+
- master
77
paths:
88
- src/**
99
pull_request:
1010
branches:
11-
- 'master'
11+
- master
1212
paths:
1313
- src/**
1414
workflow_dispatch:
@@ -18,24 +18,26 @@ jobs:
1818
name: "NGINX: ${{ matrix.nginx-version }}; libjwt: ${{ matrix.libjwt-version }}"
1919
strategy:
2020
matrix:
21-
# Each nginx version to build against
21+
# NGINX versions to build/test against
2222
nginx-version: ['1.20.2', '1.22.1', '1.24.0', '1.25.3']
23+
2324
# The following versions of libjwt are compatible:
2425
# * v1.0 - v1.12.0
2526
# * v1.12.1 - v1.14.0
2627
# * v1.15.0+
2728
# At the time of writing this:
2829
# * Debian and Ubuntu's repos have v1.10.2
2930
# * EPEL has v1.12.1
30-
# This compilles against each version prior to a breaking change and the latest release
31+
# This compiles against each version prior to a breaking change and the latest release
3132
libjwt-version: ['1.12.0', '1.14.0', '1.15.3']
3233
runs-on: ubuntu-latest
3334
steps:
34-
- name: Checkout code
35+
- name: Checkout Code
3536
uses: actions/checkout@v3
3637
with:
3738
path: 'ngx-http-auth-jwt-module'
3839

40+
# TODO cache the build result so we don't have to do this every time?
3941
- name: Download jansson
4042
uses: actions/checkout@v3
4143
with:
@@ -50,7 +52,8 @@ jobs:
5052
make && \
5153
make check && \
5254
sudo make install
53-
55+
56+
# TODO cache the build result so we don't have to do this every time?
5457
- name: Download libjwt
5558
uses: actions/checkout@v3
5659
with:
@@ -71,20 +74,22 @@ jobs:
7174
mkdir nginx
7275
curl -O http://nginx.org/download/nginx-${{matrix.nginx-version}}.tar.gz
7376
tar -xzf nginx-${{matrix.nginx-version}}.tar.gz --strip-components 1 -C nginx
74-
75-
- name: Run configure
77+
78+
- name: Configure NGINX
7679
working-directory: ./nginx
7780
run: |
7881
BUILD_FLAGS=''
7982
MAJ=$(echo ${{matrix.nginx-version}} | cut -f1 -d.)
8083
MIN=$(echo ${{matrix.nginx-version}} | cut -f2 -d.)
8184
REV=$(echo ${{matrix.nginx-version}} | cut -f3 -d.)
85+
8286
if [ "${MAJ}" -gt 1 ] || [ "${MAJ}" -eq 1 -a "${MIN}" -ge 23 ]; then
83-
BUILD_FLAGS="${BUILD_FLAGS} --with-cc-opt='-DNGX_LINKED_LIST_COOKIES=1'"
87+
BUILD_FLAGS="${BUILD_FLAGS} --with-cc-opt='-DNGX_LINKED_LIST_COOKIES=1'"
8488
fi
85-
./configure --with-compat --add-dynamic-module=../ngx-http-auth-jwt-module ${BUILD_FLAGS}
8689
87-
- name: Run make
90+
./configure --with-compat --add-dynamic-module=../ngx-http-auth-jwt-module ${BUILD_FLAGS}
91+
92+
- name: Make Modules
8893
working-directory: ./nginx
8994
run: make modules
9095

Dockerfile

Lines changed: 0 additions & 59 deletions
This file was deleted.

nginx.dockerfile

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
ARG BASE_IMAGE
2+
ARG NGINX_VERSION
3+
4+
5+
FROM ${BASE_IMAGE} as ngx_http_auth_jwt_builder_base
6+
LABEL stage=ngx_http_auth_jwt_builder
7+
RUN <<`
8+
apt-get update
9+
apt-get install -y curl build-essential
10+
`
11+
12+
13+
FROM ngx_http_auth_jwt_builder_base as ngx_http_auth_jwt_builder_module
14+
LABEL stage=ngx_http_auth_jwt_builder
15+
ENV PATH "${PATH}:/etc/nginx"
16+
ENV LD_LIBRARY_PATH=/usr/local/lib
17+
ARG NGINX_VERSION
18+
RUN <<`
19+
set -e
20+
apt-get install -y libjwt-dev libjwt0 libjansson-dev libjansson4 libpcre2-dev zlib1g-dev libpcre3-dev
21+
mkdir -p /root/build/ngx-http-auth-jwt-module
22+
`
23+
WORKDIR /root/build/ngx-http-auth-jwt-module
24+
ADD config ./
25+
ADD src/*.h src/*.c ./src/
26+
WORKDIR /root/build
27+
RUN <<`
28+
set -e
29+
mkdir nginx
30+
curl -O http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz
31+
tar -xzf nginx-${NGINX_VERSION}.tar.gz --strip-components 1 -C nginx
32+
`
33+
WORKDIR /root/build/nginx
34+
RUN <<`
35+
set -e
36+
BUILD_FLAGS=''
37+
MAJ=$(echo ${NGINX_VERSION} | cut -f1 -d.)
38+
MIN=$(echo ${NGINX_VERSION} | cut -f2 -d.)
39+
REV=$(echo ${NGINX_VERSION} | cut -f3 -d.)
40+
41+
# NGINX 1.23.0+ changes cookies to use a linked list, and renames `cookies` to `cookie`
42+
if [ "${MAJ}" -gt 1 ] || [ "${MAJ}" -eq 1 -a "${MIN}" -ge 23 ]; then
43+
BUILD_FLAGS="${BUILD_FLAGS} --with-cc-opt='-DNGX_LINKED_LIST_COOKIES=1'"
44+
fi
45+
46+
./configure \
47+
--prefix=/etc/nginx \
48+
--sbin-path=/usr/sbin/nginx \
49+
--modules-path=/usr/lib64/nginx/modules \
50+
--conf-path=/etc/nginx/nginx.conf \
51+
--error-log-path=/var/log/nginx/error.log \
52+
--http-log-path=/var/log/nginx/access.log \
53+
--pid-path=/var/run/nginx.pid \
54+
--lock-path=/var/run/nginx.lock \
55+
--http-client-body-temp-path=/var/cache/nginx/client_temp \
56+
--http-proxy-temp-path=/var/cache/nginx/proxy_temp \
57+
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
58+
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
59+
--http-scgi-temp-path=/var/cache/nginx/scgi_temp \
60+
--user=nginx \
61+
--group=nginx \
62+
--with-compat \
63+
--with-debug \
64+
--with-file-aio \
65+
--with-threads \
66+
--with-http_addition_module \
67+
--with-http_auth_request_module \
68+
--with-http_dav_module \
69+
--with-http_flv_module \
70+
--with-http_gunzip_module \
71+
--with-http_gzip_static_module \
72+
--with-http_mp4_module \
73+
--with-http_random_index_module \
74+
--with-http_realip_module \
75+
--with-http_secure_link_module \
76+
--with-http_slice_module \
77+
--with-http_ssl_module \
78+
--with-http_stub_status_module \
79+
--with-http_sub_module \
80+
--with-http_v2_module \
81+
--with-mail \
82+
--with-mail_ssl_module \
83+
--with-stream \
84+
--with-stream_realip_module \
85+
--with-stream_ssl_module \
86+
--with-stream_ssl_preread_module \
87+
--with-cc-opt='-g -O2 -ffile-prefix-map=/data/builder/debuild/nginx-1.25.4/debian/debuild-base/nginx-1.25.4=. -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fPIC' \
88+
--with-ld-opt='-Wl,-z,relro -Wl,-z,now -Wl,--as-needed -pie' \
89+
--add-dynamic-module=../ngx-http-auth-jwt-module \
90+
${BUILD_FLAGS}
91+
# --with-openssl=/usr/local \
92+
`
93+
RUN make modules
94+
RUN make install
95+
WORKDIR /usr/lib64/nginx/modules
96+
RUN cp /root/build/nginx/objs/ngx_http_auth_jwt_module.so .
97+
RUN rm -rf /root/build
98+
RUN adduser --system --no-create-home --shell /bin/false --group --disabled-login nginx
99+
RUN mkdir -p /var/cache/nginx /var/log/nginx
100+
WORKDIR /etc/nginx
101+
102+
FROM ngx_http_auth_jwt_builder_module AS ngx_http_auth_jwt_nginx
103+
LABEL maintainer="TeslaGov" email="[email protected]"
104+
ARG NGINX_VERSION
105+
RUN <<`
106+
set -e
107+
108+
apt-get update
109+
apt-get install -y libjansson4 libjwt0
110+
apt-get clean
111+
`
112+
COPY <<` /etc/nginx/nginx.conf
113+
user nginx;
114+
pid /var/run/nginx.pid;
115+
116+
load_module /usr/lib64/nginx/modules/ngx_http_auth_jwt_module.so;
117+
118+
worker_processes 1;
119+
120+
events {
121+
worker_connections 1024;
122+
}
123+
124+
http {
125+
include mime.types;
126+
default_type application/octet-stream;
127+
128+
log_format main '$$remote_addr - $$remote_user [$$time_local] "$$request" '
129+
'$$status $$body_bytes_sent "$$http_referer" '
130+
'"$$http_user_agent" "$$http_x_forwarded_for"';
131+
132+
access_log /var/log/nginx/access.log main;
133+
include conf.d/*.conf;
134+
}
135+
`
136+
ENTRYPOINT ["nginx", "-g", "daemon off;"]

openssl.dockerfile

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
ARG BASE_IMAGE
2+
3+
FROM ${BASE_IMAGE}
4+
ARG SRC_DIR=/tmp/openssl-src
5+
ARG OUT_DIR=/usr/local/.openssl
6+
ARG SSL_VERSION
7+
RUN <<`
8+
set -e
9+
apt-get update
10+
apt-get install -y curl build-essential libssl-dev libz-dev
11+
apt-get remove -y openssl
12+
apt-get clean
13+
`
14+
WORKDIR ${SRC_DIR}
15+
RUN <<`
16+
set -e
17+
curl --silent -O https://www.openssl.org/source/openssl-${SSL_VERSION}.tar.gz
18+
tar -xf openssl-${SSL_VERSION}.tar.gz --strip-components=1
19+
`
20+
RUN ./config --prefix=${OUT_DIR} --openssldir=${OUT_DIR} shared zlib
21+
RUN <<`
22+
set -e
23+
make
24+
make test
25+
make install
26+
`
27+
RUN <<`
28+
set -e
29+
echo "${OUT_DIR}/lib" > /etc/ld.so.conf.d/openssl-${SSL_VERSION}.conf
30+
ldconfig
31+
32+
ln -sf ${OUT_DIR}/bin/openssl /usr/bin/openssl
33+
ln -sf ${OUT_DIR}/lib64/libssl.so.3 /lib/x86_64-linux-gnu/libssl.so.3
34+
ln -sf ${OUT_DIR}/lib64/libcrypto.so.3 /lib/x86_64-linux-gnu/libcrypto.so.3
35+
`
36+
WORKDIR /
37+
#RUN rm -rf ${SRC_DIR}

0 commit comments

Comments
 (0)