Skip to content

Commit c37d7ef

Browse files
rshanm8xkrithikx
authored andcommitted
QATAPP-32770: Dockerfile support with QAT Crypto & Compression acceleration
Co-authored-by: Krithika Kumaravelu <[email protected]> Signed-off-by: Rajesh Shanmugam <[email protected]>
1 parent 94fdd8d commit c37d7ef

File tree

4 files changed

+352
-0
lines changed

4 files changed

+352
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ and [QATzip](https://github.com/intel/QATzip#installation-instructions) installa
9999
* Refer QAT Settings [here](https://intel.github.io/quickassist/GSG/2.X/installation.html#running-applications-as-non-root-user) for running Nginx
100100
under non-root user.
101101

102+
Also there is dockerfile available for Async mode nginx with QATlib which can be built into docker images. Please refer [here](dockerfiles/README.md) for more details.
103+
102104
## Testing
103105

104106
### Official Unit tests

dockerfiles/Dockerfile

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
#==========================================================================
2+
# \
3+
# \
4+
# BSD LICENSE \
5+
# \
6+
# Copyright(c) 2024 Intel Corporation. \
7+
# All rights reserved. \
8+
# \
9+
# Redistribution and use in source and binary forms, with or without \
10+
# modification, are permitted provided that the following conditions \
11+
# are met: \
12+
# \
13+
# * Redistributions of source code must retain the above copyright \
14+
# notice, this list of conditions and the following disclaimer. \
15+
# * Redistributions in binary form must reproduce the above copyright \
16+
# notice, this list of conditions and the following disclaimer in \
17+
# the documentation and/or other materials provided with the \
18+
# distribution. \
19+
# * Neither the name of Intel Corporation nor the names of its \
20+
# contributors may be used to endorse or promote products derived \
21+
# from this software without specific prior written permission. \
22+
# \
23+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \
24+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT \
25+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR \
26+
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT \
27+
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, \
28+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT \
29+
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, \
30+
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY \
31+
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \
32+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \
33+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \
34+
# \
35+
# \
36+
#==========================================================================
37+
38+
ARG UBUNTU_BASE=ubuntu:22.04
39+
FROM ${UBUNTU_BASE} AS builder
40+
41+
ARG OPENSSL_VERSION="openssl-3.0.15"
42+
ARG QATLIB_VERSION="24.02.0"
43+
ARG QAT_ENGINE_VERSION="v1.6.2"
44+
ARG IPSEC_MB_VERSION="v1.5"
45+
ARG IPP_CRYPTO_VERSION="ippcp_2021.12.1"
46+
ARG QATZIP_VERSION="v1.2.0"
47+
ARG ASYNC_NGINX_VERSION="v0.5.2"
48+
ARG GID
49+
ENV DEBIAN_FRONTEND=noninteractive
50+
51+
# Install required packages
52+
RUN apt-get update && \
53+
apt-get install -y apt-utils
54+
55+
# Upgrade all other packages
56+
RUN apt-get upgrade -y && \
57+
apt-get install -y \
58+
libudev-dev \
59+
make \
60+
gcc \
61+
g++ \
62+
nasm \
63+
pkg-config \
64+
libssl-dev \
65+
libpcre3-dev \
66+
zlib1g-dev \
67+
libreadline-dev \
68+
lua5.4 \
69+
liblua5.4-dev \
70+
nasm \
71+
autoconf \
72+
automake \
73+
cmake \
74+
git \
75+
ca-certificates \
76+
liblz4-dev \
77+
libtool && \
78+
git clone --depth 1 -b $OPENSSL_VERSION https://github.com/openssl/openssl.git && \
79+
git clone --depth 1 -b $QAT_ENGINE_VERSION https://github.com/intel/QAT_Engine && \
80+
git clone --depth 1 -b $IPP_CRYPTO_VERSION https://github.com/intel/ipp-crypto && \
81+
git clone --depth 1 -b $IPSEC_MB_VERSION https://github.com/intel/intel-ipsec-mb && \
82+
git clone --depth 1 -b $QATLIB_VERSION https://github.com/intel/qatlib && \
83+
git clone --depth 1 -b $QATZIP_VERSION https://github.com/intel/QATzip.git && \
84+
git clone --depth 1 -b $ASYNC_NGINX_VERSION https://github.com/intel/asynch_mode_nginx
85+
86+
# Create a non-root user and group
87+
RUN groupadd -r appuser && useradd -r -g appuser -s /bin/bash appuser
88+
89+
# Build and Install OpenSSL
90+
WORKDIR /openssl
91+
RUN ./config && \
92+
make -j && \
93+
make install -j
94+
95+
# Build and Install QATLib
96+
WORKDIR /qatlib
97+
RUN ./autogen.sh && \
98+
./configure --enable-systemd=no && \
99+
make -j && \
100+
make install samples-install && \
101+
groupadd qat -g ${GID} && \
102+
usermod -a -G qat appuser
103+
104+
# Build and Install Crypto-MB
105+
WORKDIR /ipp-crypto/sources/ippcp/crypto_mb
106+
RUN cmake . -B"../build" \
107+
-DOPENSSL_INCLUDE_DIR=/usr/local/include \
108+
-DOPENSSL_LIBRARIES=/usr/local/lib64 \
109+
-DOPENSSL_ROOT_DIR=/openssl
110+
111+
WORKDIR /ipp-crypto/sources/ippcp/build
112+
RUN make crypto_mb -j && make install -j
113+
114+
# Building the Ipsec-MB
115+
WORKDIR /intel-ipsec-mb
116+
RUN make -j && make install LIB_INSTALL_DIR=/usr/local/lib
117+
118+
# Build & Install QATEngine
119+
WORKDIR /QAT_Engine
120+
RUN ./autogen.sh && \
121+
./configure \
122+
--with-openssl_install_dir=/usr/local/ \
123+
--with-qat-hw-dir=/usr/local/ \
124+
--enable-qat_sw && \
125+
make -j && make install -j
126+
127+
# Build & Install QATzip
128+
WORKDIR /QATzip
129+
RUN ./autogen.sh && \
130+
./configure && \
131+
make -j && make install -j
132+
133+
# Build & Install Asynch_mode_nginx
134+
WORKDIR /asynch_mode_nginx
135+
RUN ./configure \
136+
--prefix=/var/www \
137+
--conf-path=/usr/share/nginx/conf/nginx.conf \
138+
--sbin-path=/usr/bin/ \
139+
--with-http_ssl_module \
140+
--with-http_stub_status_module \
141+
--add-dynamic-module=modules/nginx_qatzip_module \
142+
--add-dynamic-module=modules/nginx_qat_module/ \
143+
--with-cc-opt="-DNGX_SECURE_MEM -I/usr/local/include -I/usr/local/include/qat -Wno-error=deprecated-declarations" \
144+
--with-ld-opt="-Wl,-rpath=/usr/local/lib64 -L/usr/local/lib64 -L/QATzip/src -lqatzip -lz" && \
145+
make -j && \
146+
make install -j
147+
148+
#Added to remove libc library for vulnerability issue
149+
RUN apt-get purge -y linux-libc-dev
150+
151+
FROM ${UBUNTU_BASE}
152+
153+
COPY --from=builder /usr/local/lib/libqat.so.4.2.0 /usr/lib/
154+
COPY --from=builder /usr/local/lib/libusdm.so.0.1.0 /usr/lib/
155+
COPY --from=builder /usr/local/lib/libIPSec_MB.so.1.5.0 /usr/lib/x86_64-linux-gnu/
156+
COPY --from=builder /usr/local/lib64/libcrypto.so.3 /usr/lib/x86_64-linux-gnu/
157+
COPY --from=builder /usr/local/lib/libcrypto_mb.so.11.15 /usr/lib/x86_64-linux-gnu/
158+
COPY --from=builder /usr/local/bin/openssl /usr/bin/
159+
COPY --from=builder /usr/local/lib64/engines-3/qatengine.so /usr/lib/x86_64-linux-gnu/engines-3/qatengine.so
160+
COPY --from=builder /var/www/ /var/www/
161+
COPY --from=builder /usr/bin/nginx /usr/bin/nginx
162+
COPY --from=builder /usr/share/nginx/conf/* /usr/share/nginx/conf/
163+
COPY --from=builder /usr/share/nginx/conf/nginx.conf /usr/share/nginx/conf/nginx.conf
164+
COPY --from=builder /usr/local/lib/libqatzip.so.3.0.3 /usr/lib/x86_64-linux-gnu/
165+
COPY --from=builder /usr/local/bin/qzip /usr/bin/qzip
166+
COPY --from=builder /usr/local/bin/qatzip-test /usr/bin/qatzip-test
167+
COPY --from=builder /etc/group /etc/group
168+
COPY --from=builder /etc/passwd /etc/passwd
169+
RUN touch /var/www/logs/error.log /var/www/logs/nginx.pid /var/www/logs/access.log && chown appuser /var/www/logs/error.log /var/www/logs/nginx.pid /var/www/logs/access.log
170+
171+
RUN ldconfig
172+
173+
# Create necessary directories and set permissions
174+
RUN chown -R appuser:appuser /usr/share/nginx /var/www/ /usr/bin/nginx /usr/bin/qzip && \
175+
chmod -R 777 /usr/share/nginx /var/www/ /usr/bin/nginx /usr/bin/qzip
176+
177+
RUN mkdir -p /var/www/client_body_temp /var/www/proxy_temp /var/www/scgi_temp /var/www/uwsgi_temp /var/www/fastcgi_temp /var/www/html/basic_status && \
178+
chown -R appuser:appuser /var/www/client_body_temp /var/www/proxy_temp /var/www/scgi_temp /var/www/uwsgi_temp /var/www/fastcgi_temp /var/www/html/basic_status && \
179+
chmod 755 /var/www/client_body_temp /var/www/proxy_temp /var/www/scgi_temp /var/www/uwsgi_temp /var/www/fastcgi_temp /var/www/html/basic_status
180+
181+
#Switch to non-root user
182+
USER appuser
183+
184+
ENV OPENSSL_ENGINES="/usr/lib/x86_64-linux-gnu/engines-3/"
185+
ENV LD_LIBRARY_PATH="/usr/lib/x86_64-linux-gnu/"
186+
ENV QAT_POLICY=1
187+
188+
#Expose ports
189+
EXPOSE 8080
190+
191+
CMD ["/usr/bin/nginx", "-g", "daemon off;"]

dockerfiles/README.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Intel® QuickAssist Technology(QAT) Async Mode Nginx\* Container support
2+
3+
Async Mode Nginx Dockerfile contains Crypto and Compression acceleration with both QAT_HW and QAT_SW which can be built into docker images on the platforms with [Intel® QuickAssist 4xxx Series](https://www.intel.com/content/www/us/en/products/details/processors/xeon/scalable.html) QAT device.
4+
5+
This Dockerfile(qat_crypto_base+compression/Dockerfile) with qatengine is built and validated on top of OpenSSL-3.0.15, QAT_HW(qatlib intree driver) and QAT_SW with software versions mentioned in [software_requirements](../README.md#software_requirements) section.
6+
7+
## Docker setup and testing
8+
9+
Refer [here](https://intel.github.io/quickassist/AppNotes/Containers/setup.html)
10+
for setting up the host for QAT_HW (qatlib intree) if the platform has QAT 4xxx Hardware
11+
device. Stop QAT service if any running on the host.
12+
13+
### QAT_HW settings
14+
15+
Follow the below steps to enable required service. The service can be asym only, sym only or both
16+
in step 2 depending on the particular use case. Configure the required service only to get best performance.
17+
18+
1. Bring down the QAT devices
19+
```
20+
for i in `lspci -D -d :4940| awk '{print $1}'`; do echo down > /sys/bus/pci/devices/$i/qat/state;done
21+
```
22+
23+
2. Set up the required crypto or compression service(s)
24+
To enable crypto service use "sym;asym"
25+
```
26+
for i in `lspci -D -d :4940| awk '{print $1}'`; do echo "sym;asym" > /sys/bus/pci/devices/$i/qat/cfg_services;done
27+
```
28+
To enable compression service use "dc" or both means "dc;sym" / "dc;asym" update accordingly in above command.
29+
30+
3. Bring up the QAT devices
31+
```
32+
for i in `lspci -D -d :4940| awk '{print $1}'`; do echo up> /sys/bus/pci/devices/$i/qat/state;done
33+
```
34+
35+
4. Check the status of the QAT devices
36+
```
37+
for i in `lspci -D -d :4940| awk '{print $1}'`; do cat /sys/bus/pci/devices/$i/qat/state;done
38+
```
39+
40+
5. Enable VF for the PF in the host
41+
```
42+
for i in `lspci -D -d :4940| awk '{print $1}'`; do echo 16|sudo tee /sys/bus/pci/devices/$i/sriov_numvfs; done
43+
```
44+
45+
6. Add QAT group and Permission to the VF devices in the host
46+
```
47+
chown root.qat /dev/vfio/*
48+
chmod 660 /dev/vfio/*
49+
```
50+
51+
### Generate certificates
52+
53+
Create the TLS key and certificate for enabling encryption
54+
55+
```
56+
openssl genrsa -out rsa1k.key.pem 1024
57+
openssl req -new -x509 -key rsa1k.key.pem -out rsa1k.cert.pem -days 360 -subj "/C=US/ST=State/L=Locality/O=Company/OU=Section/CN=(1024 bit RSA)/[email protected]"
58+
```
59+
Note: Replace <path> for the absolute path where you want to save the file(/etc/ssl/certs/).
60+
61+
### Image creation
62+
63+
Docker images can be build using the below command with appropiate image name.
64+
65+
```
66+
docker build --build-arg GID=$(getent group qat | cut -d ':' -f 3) -t <docker_image_name> <path-to-dockerfile> --no-cache
67+
```
68+
Note: GID is the group id of qat group in the host.
69+
70+
### Test using Async Nginx\* crypto utility
71+
72+
```
73+
Server command: docker run --rm -it --cpuset-cpus <2-n+1> --cap-add=IPC_LOCK --security-opt seccomp=unconfined --security-opt apparmor=unconfined $(for i in `ls /dev/vfio/*`; do echo --device $i; done) --env QAT_POLICY=1 --ulimit memlock=524288000:524288000 -v /usr/share/nginx/:/usr/share/nginx/ -v /etc/ssl/certs/:/etc/ssl/certs/ -v /var/www/html/:/var/www/html/ -v /var/www/logs/:/var/www/logs/ -d -p 8080:8080 <docker_image_name>
74+
75+
Client command: openssl s_time -connect <server_ip>:8080 -new -cipher AES128-GCM-SHA256 -www /10mb_file.html -time 5
76+
```
77+
Note: n is number of process or thread. 8080 port to be used for starting the async nginx container using -v /usr/share/nginx/, /etc/ssl/certs/, /var/www/html/ and /var/www/logs/.
78+

dockerfiles/nginx.conf_qat

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
worker_processes 1;
2+
master_process on;
3+
load_module /var/www/modules/ngx_http_qatzip_filter_module.so;
4+
load_module /var/www/modules/ngx_ssl_engine_qat_module.so;
5+
6+
ssl_engine {
7+
use_engine qatengine;
8+
default_algorithms ALL;
9+
#default_algorithms RSA,EC,DH,DSA,PKEY; // For Assymmetric PKE only offload
10+
#default algorithm CIPHERS; // For symmetric Ciphers only Offload
11+
qat_engine {
12+
qat_sw_fallback off;
13+
qat_offload_mode async;
14+
qat_notify_mode poll;
15+
qat_poll_mode heuristic;
16+
}
17+
}
18+
19+
worker_rlimit_nofile 1000000;
20+
21+
events {
22+
use epoll;
23+
worker_connections 204800;
24+
multi_accept on;
25+
accept_mutex on;
26+
}
27+
28+
http {
29+
include mime.types;
30+
default_type application/octet-stream;
31+
sendfile on;
32+
keepalive_timeout 0;
33+
keepalive_requests 0;
34+
ssl_buffer_size 65536;
35+
gzip_http_version 1.0;
36+
37+
gzip_proxied any;
38+
qatzip_sw no;
39+
qatzip_min_length 128;
40+
qatzip_comp_level 4;
41+
qatzip_buffers 16 8k;
42+
qatzip_types text/css text/javascript text/xml text/plain text/x-component application/javascript application/json application/xml application/rss+xml font/truetype font/opentype application/vnd.ms-fontobject image/svg+xml application/octet-stream image/jpeg;
43+
qatzip_chunk_size 64k;
44+
qatzip_stream_size 256k;
45+
qatzip_sw_threshold 256;
46+
47+
server {
48+
listen 8080 backlog=131072 reuseport so_keepalive=off ssl; // For crypto or crypto + compression
49+
#listen 8080; // For compression alone
50+
server_name localhost;
51+
52+
sendfile on;
53+
keepalive_timeout 0s;
54+
tcp_nopush on;
55+
tcp_nodelay on;
56+
ssl_verify_client off;
57+
ssl_session_tickets on;
58+
access_log off;
59+
lingering_close off;
60+
lingering_time 1;
61+
62+
ssl_certificate /etc/ssl/certs/TestServer.cert.pem;
63+
ssl_certificate_key /etc/ssl/certs/TestServer.key.pem;
64+
ssl_session_cache off;
65+
ssl_dhparam /etc/ssl/certs/dhparam8k.pem;
66+
ssl_asynch on;
67+
ssl_buffer_size 64k;
68+
ssl_session_timeout 300s;
69+
ssl_protocols TLSv1.3;
70+
ssl_ciphers ALL;
71+
ssl_prefer_server_ciphers on;
72+
73+
location / {
74+
index index.html index.htm;
75+
}
76+
77+
error_page 500 502 503 504 /50x.html;
78+
location = /50x.html {
79+
}
80+
}
81+
}

0 commit comments

Comments
 (0)