可以跑步
stunnel
作为非根。
我修改了
Dockerfile
和入口点脚本,以定义的用户身份启动进程,将文件/文件夹所有权更新为提供的用户,并跳过的setid/setgid参数
锡锡锡锡合金
这样它就不会试图更改进程所有者。
此外,我需要更新stunnel配置中的PID位置。
Dockerfile(码头文件)-
FROM quay.io/oauth2-proxy/oauth2-proxy:v7.3.0 as builder
FROM alpine:3
COPY --from=builder /etc/nsswitch.conf /etc/nsswitch.conf
COPY --from=builder /bin/oauth2-proxy /bin/oauth2-proxy
COPY --from=builder /etc/ssl/private/jwt_signing_key.pem /etc/ssl/private/jwt_signing_key.pem
ARG STUNNEL_VERSION=${STUNNEL_VERSION:-5.66-r0}
ARG LIBRESSL_VERSION=${LIBRESSL_VERSION:-3.6.1-r0}
# UID/GID 65532 is also known as nonroot user in distroless image
ARG APP_USER=${APP_USER:-65532}
RUN apk update && apk add --no-cache openssl stunnel=${STUNNEL_VERSION} libressl==${LIBRESSL_VERSION}
ENV ACCEPT_IP=0.0.0.0 \
ACCEPT_PORT=8080 \
SERVICE=httpsconnect \
DESTINATION_PORT=443 \
DESTINATION_HOST=0.0.0.0 \
CLIENT=yes \
STUNNEL_VERSION=${STUNNEL_VERSION} \
APP_USER=${APP_USER}
COPY --chown=${APP_USER}:${APP_USER} docker-entrypoint.sh /
RUN rm /etc/stunnel/stunnel.conf && \
chmod +x /docker-entrypoint.sh && \
mkdir -p /var/log/stunnel && \
chown ${APP_USER}:${APP_USER} /etc/stunnel
USER ${APP_USER}:${APP_USER}
ENTRYPOINT [ "./docker-entrypoint.sh" ]
入口点(改编自另一个示例)
#!/bin/sh
to_file() {
TEXT="${1}"
FILE="${2}"
ECHO="$(command -v echo)"
${ECHO} "${TEXT}" >> "${FILE}"
}
cd /etc/stunnel
if [ -f stunnel.conf ]
then
rm -f stunnel.conf
fi
to_file "
foreground = yes
pid = /etc/stunnel/stunnel.pid
debug = info
output = /etc/stunnel/stunnel.log
socket = l:TCP_NODELAY=1
socket = r:TCP_NODELAY=1
cert = /etc/stunnel/stunnel.pem
client = ${CLIENT:-no}" "stunnel.conf"
for DOM in $(echo $SNI | sed "s/,/ /g")
do
to_file "SNI = ${DOM:-}" "stunnel.conf"
done
to_file "TIMEOUTbusy = 600
TIMEOUTclose = 600
TIMEOUTconnect = 600
TIMEOUTidle = 600
[${SERVICE}]
accept = ${ACCEPT_IP}:${ACCEPT_PORT}
connect = ${DESTINATION_HOST}:${DESTINATION_PORT}" "stunnel.conf"
if ! [ -f stunnel.pem ]
then
openssl req -x509 -nodes -newkey rsa:2048 -days 3650 -subj '/CN=stunnel' \
-keyout stunnel.pem -out stunnel.pem
chmod 600 stunnel.pem
fi
echo "# # # ACTIVE CONFIG # # #"
cat "stunnel.conf"
echo "# # # ACTIVE CONFIG # # #"
echo "Starting stunnel..."
exec stunnel &
echo "Starting oauth2-proxy..."
exec /bin/oauth2-proxy "$@"