Skip to content

Commit 977abb0

Browse files
authored
Merge branch 'TeslaGov:master' into master
2 parents a2379dd + 16b0369 commit 977abb0

23 files changed

+805
-202
lines changed

.github/workflows/make-releases.yml

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
paths:
8+
- src/**
9+
pull_request:
10+
branches:
11+
- master
12+
paths:
13+
- src/**
14+
workflow_dispatch:
15+
16+
jobs:
17+
build:
18+
name: "NGINX: ${{ matrix.nginx-version }}; libjwt: ${{ matrix.libjwt-version }}"
19+
strategy:
20+
matrix:
21+
# NGINX versions to build/test against
22+
nginx-version: ['1.20.2', '1.22.1', '1.24.0', '1.25.3']
23+
24+
# The following versions of libjwt are compatible:
25+
# * v1.0 - v1.12.0
26+
# * v1.12.1 - v1.14.0
27+
# * v1.15.0+
28+
# At the time of writing this:
29+
# * Debian and Ubuntu's repos have v1.10.2
30+
# * EPEL has v1.12.1
31+
# This compiles against each version prior to a breaking change and the latest release
32+
libjwt-version: ['1.12.0', '1.14.0', '1.15.3']
33+
runs-on: ubuntu-latest
34+
steps:
35+
- name: Checkout Code
36+
uses: actions/checkout@v3
37+
with:
38+
path: 'ngx-http-auth-jwt-module'
39+
40+
# TODO cache the build result so we don't have to do this every time?
41+
- name: Download jansson
42+
uses: actions/checkout@v3
43+
with:
44+
repository: 'akheron/jansson'
45+
ref: 'v2.14'
46+
path: 'jansson'
47+
48+
- name: Build jansson
49+
working-directory: ./jansson
50+
run: |
51+
cmake . -DJANSSON_BUILD_SHARED_LIBS=1 -DJANSSON_BUILD_DOCS=OFF && \
52+
make && \
53+
make check && \
54+
sudo make install
55+
56+
# TODO cache the build result so we don't have to do this every time?
57+
- name: Download libjwt
58+
uses: actions/checkout@v3
59+
with:
60+
repository: 'benmcollins/libjwt'
61+
ref: 'v${{matrix.libjwt-version}}'
62+
path: 'libjwt'
63+
64+
- name: Build libjwt
65+
working-directory: ./libjwt
66+
run: |
67+
autoreconf -i && \
68+
./configure && \
69+
make all && \
70+
sudo make install
71+
72+
- name: Download NGINX
73+
run: |
74+
mkdir nginx
75+
curl -O http://nginx.org/download/nginx-${{matrix.nginx-version}}.tar.gz
76+
tar -xzf nginx-${{matrix.nginx-version}}.tar.gz --strip-components 1 -C nginx
77+
78+
- name: Configure NGINX
79+
working-directory: ./nginx
80+
run: |
81+
BUILD_FLAGS=''
82+
MAJ=$(echo ${{matrix.nginx-version}} | cut -f1 -d.)
83+
MIN=$(echo ${{matrix.nginx-version}} | cut -f2 -d.)
84+
REV=$(echo ${{matrix.nginx-version}} | cut -f3 -d.)
85+
86+
if [ "${MAJ}" -gt 1 ] || [ "${MAJ}" -eq 1 -a "${MIN}" -ge 23 ]; then
87+
BUILD_FLAGS="${BUILD_FLAGS} --with-cc-opt='-DNGX_LINKED_LIST_COOKIES=1'"
88+
fi
89+
90+
./configure --with-compat --add-dynamic-module=../ngx-http-auth-jwt-module ${BUILD_FLAGS}
91+
92+
- name: Make Modules
93+
working-directory: ./nginx
94+
run: make modules
95+
96+
- name: Create release archive
97+
run: |
98+
cp ./nginx/objs/ngx_http_auth_jwt_module.so ./
99+
tar czf ngx_http_auth_jwt_module_libjwt_${{matrix.libjwt-version}}_nginx_${{matrix.nginx-version}}.tgz ngx_http_auth_jwt_module.so
100+
101+
- name: Upload build artifact
102+
uses: actions/upload-artifact@v3
103+
with:
104+
if-no-files-found: error
105+
name: ngx_http_auth_jwt_module_libjwt_${{matrix.libjwt-version}}_nginx_${{matrix.nginx-version}}.tgz
106+
path: ngx_http_auth_jwt_module_libjwt_${{matrix.libjwt-version}}_nginx_${{matrix.nginx-version}}.tgz
107+
108+
update_releases_page:
109+
name: Upload builds to Releases
110+
if: github.event_name != 'pull_request'
111+
needs:
112+
- build
113+
runs-on: ubuntu-latest
114+
permissions:
115+
contents: write
116+
steps:
117+
- name: Set up variables
118+
id: vars
119+
run: |
120+
echo "date_now=$(date --rfc-3339=seconds)" >> "${GITHUB_OUTPUT}"
121+
122+
- name: Download build artifacts from previous jobs
123+
uses: actions/download-artifact@v3
124+
with:
125+
path: artifacts
126+
127+
- name: Upload builds to Releases
128+
uses: ncipollo/release-action@v1
129+
with:
130+
allowUpdates: true
131+
artifactErrorsFailBuild: true
132+
artifacts: artifacts/*/*
133+
body: |
134+
> [!WARNING]
135+
> This is an automatically generated pre-release version of the module, which includes the latest master branch changes.
136+
> Please report any bugs you find to the issue tracker.
137+
138+
- Build Date: `${{ steps.vars.outputs.date_now }}`
139+
- Commit: ${{ github.sha }}
140+
name: 'Development build: ${{ github.ref_name }}@${{ github.sha }}'
141+
prerelease: true
142+
removeArtifacts: true
143+
tag: dev-build

Dockerfile

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

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,13 @@ This module requires several new `nginx.conf` directives, which can be specified
3131

3232
## Algorithms
3333

34-
The default algorithm is `HS256`, for symmetric key validation. When using one of the `HS*` algorithms, the value for `auth_jwt_key` should be specified in binhex format. It is recommended to use at least 256 bits of data (32 pairs of hex characters or 64 characters in total) as in the example above. Note that using more than 512 bits will not increase the security. For key guidelines please see [NIST Special Publication 800-107 Recommendation for Applications Using Approved Hash Algorithms](https://csrc.nist.gov/publications/detail/sp/800-107/rev-1/final), Section 5.3.2 The HMAC Key.
34+
The default algorithm is `HS256`, for symmetric key validation. When using one of the `HS*` algorithms, the value for `auth_jwt_key` should be specified in binhex format. It is recommended to use at least 256 bits of data (32 pairs of hex characters or 64 characters in total). Note that using more than 512 bits will not increase the security. For key guidelines please see [NIST Special Publication 800-107 Recommendation for Applications Using Approved Hash Algorithms](https://csrc.nist.gov/publications/detail/sp/800-107/rev-1/final), Section 5.3.2 The HMAC Key.
35+
36+
To generate a 256-bit key (32 pairs of hex characters; 64 characters in total):
37+
38+
```bash
39+
openssl rand -hex 32
40+
```
3541

3642
### Additional Supported Algorithms
3743

@@ -225,7 +231,7 @@ The tests use a customized NGINX image, distinct from the main image, as well as
225231

226232
After making changes and finding that some tests fail, it can be difficult to understand why. By default, logs are written to Docker's internal log mechanism, but they won't be persisted after the test run completes and the containers are removed.
227233

228-
In order to persist logs, you can configure the log driver to use. You can do this by setting the environment variable `LOG_DRIVER` before running the tests. On Linux/Unix systems, you can use the driver `journald`, as follows:
234+
If you'd like to persist logs across test runs, you can configure the log driver to use `journald` (on Linux/Unix systems for example). You can do this by setting the environment variable `LOG_DRIVER` before running the tests:
229235

230236
```shell
231237
# need to rebuild the test runner with the proper log driver

nginx.dockerfile

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

0 commit comments

Comments
 (0)