Skip to content

Instantly share code, notes, and snippets.

@vitalvas
Created October 7, 2020 19:47
Show Gist options
  • Select an option

  • Save vitalvas/ee500f5bf9cf0115577e38a7fed06cc8 to your computer and use it in GitHub Desktop.

Select an option

Save vitalvas/ee500f5bf9cf0115577e38a7fed06cc8 to your computer and use it in GitHub Desktop.
squid docker auth
#!/bin/bash
# Author: <[email protected]> Vitaliy Vasilenko
# run: usermod -a -G docker proxy
# tested on squid 4.10
while read line; do
ip_addr=$(echo "${line}" | awk '{print $1}')
ip_done="0"
for ctx in $(docker ps | awk '$NF!="NAMES" {print $NF}'); do
for addr in $(docker inspect ${ctx} | jq -r '.[].NetworkSettings.Networks[].IPAddress'); do
if [ "${ip_addr}" == "${addr}" ]; then
echo "OK user=docker:${ctx}"
ip_done="1"
fi
done
done
if [ "${ip_done}" == "0" ]; then
echo "ERR"
fi
done
external_acl_type docker_ips ttl=60 negative_ttl=20 children-max=1 grace=90 %SRC /etc/squid/auth_docker.sh
acl DockerAuthIPs external docker_ips
http_access allow DockerAuthIPs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment