Skip to content

Commit a91e733

Browse files
committed
imp: switching from Alpine to Debian
1 parent fc768ff commit a91e733

File tree

9 files changed

+231
-2970
lines changed

9 files changed

+231
-2970
lines changed

.hadolint.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
ignored:
2-
- DL3003
3-
- DL3007
4-
- DL3018
2+
- DL3008
53
trustedRegistries:
64
- docker.io
75
- "*.gcr.io"

Dockerfile

Lines changed: 79 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
1-
FROM alpine:latest AS build-privoxy
1+
FROM debian:stable-slim AS build-privoxy
22

33
ARG PRIVOXY_VERSION=4.0.0
44
ARG PRIVOXY_SRC_SHA1SUM=d302cb0bf23536e67a1b5505d01486a335d9c4c0
55
ARG PRIVOXY_CONFIG_OPTIONS="--disable-toggle --disable-editor --disable-force --with-openssl --with-brotli"
6-
ARG PRIVOXY_BUILD_EXTRA="openssl-dev brotli-dev"
6+
ARG PRIVOXY_BUILD_EXTRA="libssl-dev libbrotli-dev"
77

8-
SHELL ["/bin/ash", "-eo", "pipefail", "-c"]
8+
SHELL ["/bin/bash", "-eo", "pipefail", "-c"]
99

1010
WORKDIR /build
1111

1212
RUN set -eux; \
13-
apk add --no-cache --virtual build-tools \
14-
gcc \
13+
apt-get update && apt-get install -y --no-install-recommends \
14+
build-essential \
1515
autoconf \
16-
make \
17-
git; \
18-
apk add --no-cache --virtual build-deps \
19-
libc-dev \
20-
zlib-dev \
21-
pcre2-dev \
22-
$PRIVOXY_BUILD_EXTRA;
23-
16+
ca-certificates \
17+
git \
18+
curl \
19+
libc6-dev \
20+
zlib1g-dev \
21+
libpcre2-dev \
22+
$PRIVOXY_BUILD_EXTRA; \
23+
apt-get clean; \
24+
rm -rf /var/lib/apt/lists/*;
25+
26+
# hadolint ignore=DL3003
2427
RUN set -eux; \
25-
wget -qO privoxy-src.tar.gz https://sourceforge.net/projects/ijbswa/files/Sources/${PRIVOXY_VERSION}%20%28stable%29/privoxy-${PRIVOXY_VERSION}-stable-src.tar.gz/download; \
28+
curl -L -o privoxy-src.tar.gz https://sourceforge.net/projects/ijbswa/files/Sources/${PRIVOXY_VERSION}%20%28stable%29/privoxy-${PRIVOXY_VERSION}-stable-src.tar.gz/download; \
2629
echo "${PRIVOXY_SRC_SHA1SUM} privoxy-src.tar.gz" | sha1sum -c; \
2730
tar -zxvf privoxy-src.tar.gz; \
2831
cd privoxy-${PRIVOXY_VERSION}-stable; \
@@ -34,34 +37,23 @@ RUN set -eux; \
3437
privoxy --version;
3538

3639

37-
FROM alpine:latest AS build-adblock2privoxy
40+
FROM haskell:slim AS build-adblock2privoxy
3841

3942
ARG ADBLOCK2PRIVOXY_RESOLVER=lts-21.25
4043

41-
SHELL ["/bin/ash", "-eo", "pipefail", "-c"]
44+
SHELL ["/bin/bash", "-eo", "pipefail", "-c"]
4245

4346
WORKDIR /build
4447

4548
RUN set -eux; \
46-
apk add --no-cache --virtual build-tools \
47-
gcc \
48-
g++ \
49-
make \
50-
curl \
51-
gmp \
49+
apt-get update && apt-get install -y --no-install-recommends \
5250
git \
53-
ghc \
54-
cabal \
55-
stack; \
56-
apk add --no-cache --virtual build-deps \
57-
musl-dev \
58-
zlib-dev \
59-
gmp-dev \
60-
ncurses-libs \
61-
ncurses-dev \
62-
xz;
63-
#curl -sSL https://get.haskellstack.org/ | sh;
51+
zlib1g-dev \
52+
libncurses-dev; \
53+
apt-get clean; \
54+
rm -rf /var/lib/apt/lists/*;
6455

56+
# hadolint ignore=DL3003
6557
RUN set -eux; \
6658
git clone https://github.com/essandess/adblock2privoxy.git . --depth=1; \
6759
export STACK_ROOT=/usr/local/etc/.stack; \
@@ -72,11 +64,19 @@ RUN set -eux; \
7264
adblock2privoxy --version;
7365

7466

75-
FROM alpine:latest AS runtime
67+
FROM debian:stable-slim AS runtime
7668

7769
ARG SYSTEM_EXTRA_PKGS="brotli net-tools"
7870

79-
SHELL ["/bin/ash", "-eo", "pipefail", "-c"]
71+
SHELL ["/bin/bash", "-eo", "pipefail", "-c"]
72+
73+
ENV PRIVOXY_PORT=8118 \
74+
ADBLOCK_URLS="" \
75+
ADBLOCK_NGINX_ENABLED=true \
76+
ADBLOCK_CSS_DOMAIN="172.17.0.2" \
77+
NGINX_SERVER_NAME="172.17.0.2" \
78+
NGINX_PORT=80 \
79+
NGINX_PORT_SSL=443
8080

8181
# Create Privoxy User
8282
RUN set -ex; \
@@ -94,19 +94,24 @@ RUN set -ex; \
9494

9595
# Add system tools
9696
RUN set -eux; \
97-
apk add --no-cache --virtual runtime-deps \
97+
apt-get update && apt-get install -y --no-install-recommends \
9898
python3 \
99-
pcre2 \
99+
pcre2-utils \
100100
openssl \
101101
nginx \
102-
gmp \
103-
ncurses \
104-
$SYSTEM_EXTRA_PKGS;
102+
libgmp-dev \
103+
libncurses-dev \
104+
ca-certificates \
105+
gettext-base \
106+
$SYSTEM_EXTRA_PKGS; \
107+
apt-get clean; \
108+
rm -rf /var/lib/apt/lists/*;
105109

106110
# Docker Entry Point
107111
COPY docker-entrypoint.sh /usr/local/sbin/
108-
RUN sed -i 's/\r$//' /usr/local/sbin/docker-entrypoint.sh && \
109-
chmod +x /usr/local/sbin/docker-entrypoint.sh;
112+
RUN set -ex; \
113+
sed -i 's/\r$//' /usr/local/sbin/docker-entrypoint.sh; \
114+
chmod +x /usr/local/sbin/docker-entrypoint.sh;
110115

111116
# Privman
112117
COPY data/rules/ /usr/local/etc/privoxy/privman-rules/
@@ -120,19 +125,46 @@ RUN set -ex; \
120125

121126
# Privoxy
122127
COPY --from=build-privoxy /usr/local /usr/local
123-
COPY data/config /usr/local/etc/privoxy/
124-
# hadolint ignore=SC1003
128+
# hadolint ignore=SC1003,SC2016
125129
RUN set -ex; \
126-
#mv /usr/local/etc/privoxy/config /usr/local/etc/privoxy/config.orig; \
127130
mkdir -p /var/log/privoxy /usr/local/etc/privoxy/CA /usr/local/etc/privoxy/certs /usr/local/etc/privoxy/privman-rules; \
128131
chown -R privoxy:privoxy /var/log/privoxy /usr/local/etc/privoxy; \
132+
chmod +x /usr/local/sbin/privoxy; \
133+
cp -a /usr/local/etc/privoxy /opt/privoxy-default; \
134+
# Change the default config
135+
cp /usr/local/etc/privoxy/config /usr/local/etc/privoxy/config.orig; \
129136
sed -i '/^+set-image-blocker{pattern}/a +https-inspection \\' /usr/local/etc/privoxy/match-all.action; \
130-
cp -a /usr/local/etc/privoxy /opt/privoxy-default;
137+
sed -i \
138+
-e 's/^confdir .+/confdir \/usr\/local\/etc\/privoxy/' \
139+
-e 's/^templdir .+/templdir \/usr\/local\/etc\/privoxy\/templates/' \
140+
-e '/^actionsfile user.action/a actionsfile privman-rules\/user.action\nactionsfile ab2p.system.action\nactionsfile ab2p.action' \
141+
-e '/^filterfile user.filter/a filterfile privman-rules\/user.filter\nfilterfile ab2p.system.filter\nfilterfile ab2p.filter' \
142+
-e 's/^#debug 1.+/debug 1/' \
143+
-e 's/^#debug 512.+/debug 512/' \
144+
-e 's/^#debug 1024.+/debug 1024/' \
145+
-e 's/^#debug 8192.+/debug 8192/' \
146+
-e 's/^listen-address .+/listen-address 0.0.0.0:${PRIVOXY_PORT}/' \
147+
-e 's/^enforce-blocks .+/#enforce-blocks 0/' \
148+
-e 's/^buffer-limit .+/buffer-limit 25600/' \
149+
-e 's/^keep-alive-timeout .+/keep-alive-timeout 120/' \
150+
-e 's/^tolerate-pipelining .+/tolerate-pipelining 0/' \
151+
-e 's/^socket-timeout .+/socket-timeout 30/' \
152+
-e 's/^#max-client-connections .+/max-client-connections 256/' \
153+
-e 's/^#listen-backlog .+/listen-backlog 128/' \
154+
-e 's/^#ca-directory .+/ca-directory \/usr\/local\/etc\/privoxy\/CA/' \
155+
-e 's/^#ca-cert-file .+/ca-cert-file privoxy-ca-bundle.crt/' \
156+
-e 's/^#ca-key-file .+/ca-key-file cakey.pem/' \
157+
-e 's/^#certificate-directory .+/certificate-directory \/usr\/local\/etc\/privoxy\/certs/' \
158+
-e 's/^#trusted-cas-file .+/trusted-cas-file trustedCAs.pem/' \
159+
-e '$a\receive-buffer-size 32768' \
160+
-e '$a\cipher-list ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256' \
161+
/usr/local/etc/privoxy/config; \
162+
chmod +x /usr/local/sbin/privoxy;
131163

132164
# adblock2privoxy
133165
COPY --from=build-adblock2privoxy /usr/local/bin/adblock2privoxy /usr/local/bin/adblock2privoxy
134166
COPY --from=build-adblock2privoxy /build/adblock2privoxy/templates /opt/local/share/adblock2privoxy/templates
135-
COPY data/nginx.conf /etc/nginx/nginx.conf
167+
COPY templates/nginx.conf.template /etc/nginx/nginx.conf.template
136168
RUN set -ex; \
137169
mkdir -p /usr/local/etc/adblock2privoxy/css; \
138170
echo "# Dummy file" | tee -a /usr/local/etc/privoxy/ab2p.system.action /usr/local/etc/privoxy/ab2p.action /usr/local/etc/privoxy/ab2p.system.filter /usr/local/etc/privoxy/ab2p.filter; \
@@ -146,15 +178,9 @@ RUN set -ex; \
146178
privoxy --version; \
147179
adblock2privoxy --version;
148180

149-
# Common
150-
ENV ADBLOCK_URLS=""
151-
ENV ADBLOCK_CSS_DOMAIN="172.17.0.2:8119"
152-
153181
ENTRYPOINT ["/usr/local/sbin/docker-entrypoint.sh"]
154182

155183
VOLUME /usr/local/etc/privoxy
156-
EXPOSE 8118/tcp
157-
EXPOSE 8119/tcp
158184

159185
USER privoxy
160186

README.md

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
## :page_with_curl: About
44

5-
Alpine docker with [privoxy](https://www.privoxy.org) enabled and configured to work with HTTPS.
5+
Image with [privoxy](https://www.privoxy.org) enabled and configured to work with HTTPS.
66

77
It also includes '[adblock2privoxy](https://github.com/essandess/adblock2privoxy)' to translate adblock rules to privoxy with CSS hidden elements & blackhole.
8+
This means that this image also includes an nginx server so that the advanced CSS rules work correctly.
89

910
**The default configuration is intended for personal use only (ex. raspberry)**
1011

@@ -14,13 +15,26 @@ This image downloads the 'trustedCAs' file from curl.se and also generates the c
1415

1516
Privoxy Status Page: https://config.privoxy.org/show-status
1617

18+
### Default Ports
19+
20+
| PORT | Description | Required |
21+
|----------------|-------------|-------------|
22+
| 8118 | Privoxy | [x] |
23+
| 80 | Nginx | [] |
24+
| 443 | Nginx SSL | [] |
25+
1726

1827
### Env. Variables
1928

2029
| Name | Description | Default |
2130
|----------------|-------------|-------------|
31+
| PRIVOXY_PORT | The Privoxy port | 8118 |
2232
| ADBLOCK_URLS | String of urls separated by spaces | "" |
23-
| ADBLOCK_CSS_DOMAIN | A domain/IP that points to the container (IP:PORT) | 172.17.0.2:8119 |
33+
| ADBLOCK_CSS_DOMAIN | A domain/IP that points to the container (IP:PORT) | 172.17.0.2 |
34+
| ADBLOCK_NGINX_ENABLED | The server to use to get the css files | true |
35+
| NGINX_SERVER_NAME | The server name for verification process (must coincide with ADBLOCK_CSS_DOMAIN name part) | 172.17.0.2 |
36+
| NGINX_PORT | The HTTP port | 80 |
37+
| NGINX_PORT_SSL | The HTTPS port | 443 |
2438

2539
- Can get urls from: https://easylist.to/
2640

@@ -38,11 +52,13 @@ services:
3852
container_name: privoxy
3953
ports:
4054
- 8118:8118
41-
- 8119:8119
55+
- 80:80
56+
- 443:443
4257
environment:
4358
TZ: Europe/Madrid
4459
ADBLOCK_URLS: https://easylist.to/easylist/easylist.txt
45-
ADBLOCK_CSS_DOMAIN: privoxy.local:8119
60+
ADBLOCK_CSS_DOMAIN: privoxy.local
61+
NGINX_SERVER_NAME: privoxy.local
4662
volumes:
4763
- privoxy-ca:/usr/local/etc/privoxy/CA
4864
restart: unless-stopped
@@ -77,6 +93,7 @@ docker cp privoxy:/usr/local/etc/privoxy/CA/privoxy-ca-bundle.crt .
7793
- `max-client-connections` > Increased to 256
7894
- `listen-backlog` > Set to 128
7995
- `receive-buffer-size` > Increased to 32768 bytes
96+
- `tolerate-pipelining` > Disabled
8097

8198
## :bookmark: Points of Interest
8299

bin/privman.py

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
#!/usr/bin/python
1+
#!/usr/bin/python3
22
# Copyright Alexandre Díaz <dev@redneboa.es>
33
# Privoxy Manager
44

55
import os
6+
import re
67
import argparse
78
import subprocess
89
import urllib.request
@@ -35,7 +36,7 @@ def update_trusted_ca(forced=False):
3536
print_log("Trusted CA", "Nothing to do. The file already exists.")
3637

3738

38-
def generate_crt_bundle(subj, forced=False):
39+
def generate_crt_bundle(subj, subj_nginx, forced=False):
3940
ca_bundle_file = os.path.join(BASEDIR_CA, "privoxy-ca-bundle.crt")
4041
ca_key_file = os.path.join(BASEDIR_CA, "cakey.pem")
4142
if not os.path.isfile(ca_bundle_file) or forced:
@@ -50,10 +51,41 @@ def generate_crt_bundle(subj, forced=False):
5051
'-addext "subjectKeyIdentifier=hash"'
5152
)
5253
print_log("CRT Bundle", f"Generated successfully in '{ca_bundle_file}'")
54+
generate_nginx_certs(subj_nginx, ca_bundle_file, ca_key_file)
5355
else:
5456
print_log("CRT Bundle", "Nothing to do. The file already exists.")
5557

5658

59+
def generate_nginx_certs(subj, ca_bundle_file, ca_key_file):
60+
nginx_priv_key_file = os.path.join(BASEDIR_CA, "nginx.pem")
61+
nginx_priv_csr_file = os.path.join(BASEDIR_CA, "nginx.csr")
62+
nginx_cert_file = os.path.join(BASEDIR_CA, "nginx.crt")
63+
nginx_cert_conf_file = os.path.join(BASEDIR_CA, "nginx.cnf")
64+
nginx_sn = os.environ.get("NGINX_SERVER_NAME", "")
65+
f_subj = f"{subj}/CN={nginx_sn}"
66+
re_ipv4 = r"\d{1,3}\.\d{1,3}\.\d{1,3}.\d{1,3}"
67+
with open(nginx_cert_conf_file, "w") as file:
68+
if re.match(re_ipv4, nginx_sn):
69+
file.write(f"subjectAltName=IP:{nginx_sn}")
70+
else:
71+
file.write(f"subjectAltName=DNS:{nginx_sn}")
72+
os.system(
73+
"openssl req -newkey rsa:2048 -nodes "
74+
f"-keyout {nginx_priv_key_file} "
75+
f"-out {nginx_priv_csr_file} "
76+
f'-subj "{f_subj}" '
77+
)
78+
os.system(
79+
"openssl x509 -req "
80+
f"-in {nginx_priv_csr_file} "
81+
f"-CA {ca_bundle_file} "
82+
f"-CAkey {ca_key_file} "
83+
f"-CAcreateserial -out {nginx_cert_file} -days 365 -sha256 "
84+
f"-extfile {nginx_cert_conf_file}"
85+
)
86+
print_log("NGINX Certs", f"Generated successfully in '{nginx_cert_file}'")
87+
88+
5789
def init_adblock_filters():
5890
subprocess.run(
5991
[
@@ -255,6 +287,13 @@ def remove_blocklist(urls):
255287
help="Generate the .crt bundle",
256288
default="/C=ES/ST=Madrid/L=Madrid/O=DockerPrivoxy Security/OU=PROXY Department/CN=privoxy.proxy",
257289
)
290+
parser.add_argument(
291+
"--nginx-subj",
292+
type=str,
293+
nargs=1,
294+
help="SUBJ parameters for nginx certificate",
295+
default="/C=ES/ST=Madrid/L=Madrid/O=DockerPrivoxy NGinx/OU=PROXY Department",
296+
)
258297
parser.add_argument(
259298
"--update-adblock-filters",
260299
help="Update Adblock Filters",
@@ -303,12 +342,14 @@ def remove_blocklist(urls):
303342

304343
if args.init:
305344
update_trusted_ca()
306-
generate_crt_bundle(args.crt_bundle_subj)
345+
generate_crt_bundle(args.crt_bundle_subj, args.nginx_subj)
307346
init_adblock_filters()
308347
if args.update_trusted_ca:
309348
need_restart = update_trusted_ca(forced=True)
310349
if args.regenerate_crt_bundle:
311-
need_restart = generate_crt_bundle(args.crt_bundle_subj, forced=True)
350+
need_restart = generate_crt_bundle(
351+
args.crt_bundle_subj, args.nginx_subj, forced=True
352+
)
312353
if args.update_adblock_filters:
313354
need_restart = update_adblock_filters()
314355
if args.add_whitelist:

0 commit comments

Comments
 (0)