| 1 |
# This will generate a squid container image which can be used either over http on port 3128 |
| 2 |
# or over https over port 3129. No MITM/reencryption/... is done. |
| 3 |
# |
| 4 |
# The resulting container image needs to be run with -p 3128:3128 -p 3129:3129 |
| 5 |
# |
| 6 |
# If you use the default image, the root CA used to sign the certificate used by squid |
| 7 |
# is located in the image in /etc/pki/squid/rootCA.crt |
| 8 |
# |
| 9 |
# You can override the certificates used by the image by running it with -v ./pki/:/etc/pki/squid:z |
| 10 |
# These certificates can be generated by the generate-certs.sh script. |
| 11 |
# |
| 12 |
# Once the container is running, the https proxy can be tested with |
| 13 |
# https_proxy=https://localhost:3129 curl --proxy-cacert ./pki/rootCA.crt -L https://gandi.net |
| 14 |
# |
| 15 |
# The generated TLS certificate is currently only valid for 192.168.122.1, you'll need to modify |
| 16 |
# generate-certs.sh if you want to use it on a different host |
| 17 |
# |
| 18 |
# https Traffic in the VM can be blocked by running this in a VM: |
| 19 |
# sudo firewall-cmd --direct --add-rule ipv4 filter OUTPUT 0 -p tcp -m tcp --dport=443 -j REJECT |
| 20 |
# sudo firewall-cmd --direct --add-rule ipv4 filter OUTPUT 1 -j ACCEPT |
| 21 |
# |
| 22 |
# To allow traffic on port 3128/3129 from the VM to the host, run this on the host: |
| 23 |
# sudo firewall-cmd --zone=libvirt --add-port=3128/tcp |
| 24 |
# sudo firewall-cmd --zone=libvirt --add-port=3129/tcp |
| 25 |
# |
| 26 |
# After this, running this command in a VM hangs: |
| 27 |
# curl -L -I https://gandi.net |
| 28 |
# and this command succeds: |
| 29 |
# https_proxy=https://192.168.122.1:3129 curl --proxy-cacert ./rootCA.crt -L https://gandi.net |
| 30 |
# (commonName must be set to 192.168.122.1 before running generate-certs.sh and building the container image) |
| 31 |
|
| 32 |
# Intermediate build image to generate the CA and certificate used for https |
| 33 |
FROM quay.io/centos/centos:stream8 AS gencerts |
| 34 |
MAINTAINER CRC <[email protected]> |
| 35 |
|
| 36 |
RUN yum -y install openssl |
| 37 |
|
| 38 |
WORKDIR /root |
| 39 |
COPY generate-certs.sh . |
| 40 |
RUN bash ./generate-certs.sh |
| 41 |
|
| 42 |
|
| 43 |
# Final squid container |
| 44 |
FROM quay.io/centos/centos:stream8 |
| 45 |
|
| 46 |
MAINTAINER CRC <[email protected]> |
| 47 |
|
| 48 |
RUN yum -y install squid && \ |
| 49 |
yum clean all |
| 50 |
RUN systemctl enable squid.service |
| 51 |
|
| 52 |
# Workaround for https://github.com/moby/moby/issues/31243 |
| 53 |
RUN usermod -a -G tty squid |
| 54 |
|
| 55 |
# Allow localnet to access proxy and enable access to squid over https |
| 56 |
RUN sed -i "s/^#\+\(.*[acl|allow] localnet\)/\1/" /etc/squid/squid.conf && \ |
| 57 |
sed -i "s!http_port 3128!http_port 3128\nhttps_port 3129 tls-cert=/etc/pki/squid/squid.pem!" /etc/squid/squid.conf |
| 58 |
|
| 59 |
COPY --from=gencerts /root/pki/squid.pem /etc/pki/squid/ |
| 60 |
COPY --from=gencerts /root/pki/rootCA.crt /etc/pki/squid/ |
| 61 |
|
| 62 |
EXPOSE 3128/tcp |
| 63 |
EXPOSE 3129/tcp |
| 64 |
|
| 65 |
CMD [ "/sbin/init" ] |