Tenant .htaccess files that say `Options +FollowSymLinks` / `All` / `Includes` (stock CodeIgniter 4, Joomla, OpenCart, Magento) answer 500 on the shared tier since the AllowOverride Options= lockdown. A small loadable module, built against the distribution httpd-devel (stock AlmaLinux httpd RPMs stay): - WHPHtaccessOptionsRemap On: rewrites the Options line in .htaccess before the core parses it (FollowSymLinks -> SymLinksIfOwnerMatch, Includes -> IncludesNOEXEC, positive ExecCGI dropped), so those files work while the core's own owner-match symlink check stays in charge. Covers nested <If>. - WHPOwnerGuard Log|On: fstat() owner check on the file descriptor actually served (the Bluehost/cPanel SymlinkProtect idea, as an output filter); closes the SymLinksIfOwnerMatch check-then-open race and the swapped public_html case. Ships in Log mode. DRAFT: measured locally only, see the WHP-side write-up. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0185ukXi4YX5FxJGqhi6qab6
92 lines
4.5 KiB
Docker
92 lines
4.5 KiB
Docker
# Base image. CI passes BASE_IMAGE=almalinux/10-base@sha256:<digest>, resolved
|
|
# DIRECTLY from Docker Hub in the same run (.gitea/scripts/resolve-base-image.sh),
|
|
# so the pkg-cache registry mirror can only serve content-addressed blobs.
|
|
# Local builds use the tag. docs/pkg-cache.md "Base-image digest pinning".
|
|
ARG BASE_IMAGE=almalinux/10-base
|
|
|
|
# Build stage for mod_whp_symlink (src/mod_whp_symlink/): compiled against the
|
|
# distribution httpd-devel, so the runtime keeps the stock AlmaLinux httpd RPMs
|
|
# and their security updates. Nothing from this stage but the .so (and the
|
|
# httpd version it was built against) reaches the image.
|
|
FROM ${BASE_IMAGE} AS modbuild
|
|
ARG PKG_CACHE=
|
|
COPY ./scripts/pkg-cache-repos.sh /usr/local/sbin/pkg-cache-repos.sh
|
|
COPY ./keys/pkg-cache/ /usr/local/share/pkg-cache/
|
|
COPY ./src/mod_whp_symlink/mod_whp_symlink.c /src/mod_whp_symlink.c
|
|
RUN /usr/local/sbin/pkg-cache-repos.sh rpm && \
|
|
dnf update -y && \
|
|
dnf install -y httpd-devel gcc redhat-rpm-config && \
|
|
/usr/local/sbin/pkg-cache-repos.sh restore && \
|
|
cd /src && apxs -Wc,-Wall -Wc,-Werror -c mod_whp_symlink.c && \
|
|
rpm -q --qf '%{VERSION}-%{RELEASE}' httpd-devel > /src/built-against
|
|
|
|
FROM ${BASE_IMAGE}
|
|
|
|
# OPTIONAL internal package cache, e.g. --build-arg PKG_CACHE=https://192.168.1.40
|
|
# (CT130 pkg-cache, https only). Unset = upstream repositories. Release RPMs are
|
|
# GPG-verified against keys/pkg-cache/ either way. Repo files
|
|
# are restored at the end of every RUN, so no layer keeps the cache address.
|
|
# See scripts/pkg-cache-repos.sh.
|
|
ARG PKG_CACHE=
|
|
COPY ./scripts/pkg-cache-repos.sh /usr/local/sbin/pkg-cache-repos.sh
|
|
COPY ./keys/pkg-cache/ /usr/local/share/pkg-cache/
|
|
|
|
# Install Apache and minimal dependencies (no PHP at all)
|
|
RUN /usr/local/sbin/pkg-cache-repos.sh rpm && \
|
|
/usr/local/sbin/pkg-cache-repos.sh release-install epel && \
|
|
/usr/local/sbin/pkg-cache-repos.sh rpm && \
|
|
dnf update -y && \
|
|
dnf install -y httpd mod_ssl openssl iproute cronie procps curl && \
|
|
/usr/local/sbin/pkg-cache-repos.sh restore && \
|
|
dnf clean all && \
|
|
rm -rf /var/cache/dnf /usr/share/doc /usr/share/man /usr/share/locale/*
|
|
|
|
# Copy scripts and set permissions
|
|
COPY ./scripts/detect-memory.sh /scripts/detect-memory.sh
|
|
COPY ./scripts/create-apache-mpm-config.sh /scripts/create-apache-mpm-config.sh
|
|
COPY ./scripts/log-rotate.sh /scripts/log-rotate.sh
|
|
COPY ./scripts/entrypoint-shared-httpd.sh /scripts/entrypoint-shared-httpd.sh
|
|
COPY ./scripts/stop-services.sh /scripts/stop-services.sh
|
|
COPY ./scripts/tune-mpm.sh /scripts/tune-mpm.sh
|
|
COPY ./scripts/httpd-h2-md-gate.sh /scripts/httpd-h2-md-gate.sh
|
|
RUN chmod +x /scripts/*
|
|
|
|
# Generate self-signed SSL cert (same as main CAC image)
|
|
RUN openssl req -newkey rsa:2048 -nodes \
|
|
-keyout /etc/pki/tls/private/localhost.key \
|
|
-x509 -days 3650 -subj "/CN=localhost" \
|
|
-out /etc/pki/tls/certs/localhost.crt
|
|
|
|
# Copy Apache configs
|
|
COPY ./configs/remote_ip.conf /etc/httpd/conf.d/
|
|
COPY ./configs/default-index.conf /etc/httpd/conf.d/
|
|
|
|
# mod_whp_symlink: tenant .htaccess Options remap + served-file owner guard
|
|
# (configs/whp-symlink.conf). The build fails if the runtime httpd differs from
|
|
# the httpd-devel it was compiled against, or if the module does not load.
|
|
COPY --from=modbuild /src/.libs/mod_whp_symlink.so /usr/lib64/httpd/modules/mod_whp_symlink.so
|
|
COPY --from=modbuild /src/built-against /usr/lib64/httpd/modules/mod_whp_symlink.built-against
|
|
COPY ./configs/whp-symlink.conf /etc/httpd/conf.d/whp-symlink.conf
|
|
RUN echo 'LoadModule whp_symlink_module modules/mod_whp_symlink.so' > /etc/httpd/conf.modules.d/99-whp-symlink.conf && \
|
|
test "$(rpm -q --qf '%{VERSION}-%{RELEASE}' httpd)" = "$(cat /usr/lib64/httpd/modules/mod_whp_symlink.built-against)" && \
|
|
httpd -t && httpd -M 2>/dev/null | grep -q ' whp_symlink_module '
|
|
|
|
# Create vhosts directory (will be volume-mounted from host)
|
|
RUN mkdir -p /etc/httpd/conf.d/vhosts
|
|
|
|
# Set up cron job for log rotation
|
|
RUN echo "15 */12 * * * root /scripts/log-rotate.sh" >> /etc/crontab
|
|
|
|
# CVE-2026-119618 defense in depth: no HTTP/2 / mod_md in the image, build fails
|
|
# if they come back or the config no longer parses. scripts/httpd-h2-md-gate.sh.
|
|
# Placed after every other package step so nothing later can re-add them.
|
|
RUN /scripts/httpd-h2-md-gate.sh remove && /scripts/httpd-h2-md-gate.sh check
|
|
LABEL org.whp.httpd-h2-md="removed"
|
|
|
|
EXPOSE 80 443
|
|
|
|
HEALTHCHECK --interval=30s --timeout=5s --start-period=60s --retries=3 \
|
|
CMD curl -sfk https://localhost/ping || exit 1
|
|
|
|
ENTRYPOINT [ "/scripts/entrypoint-shared-httpd.sh" ]
|