#!/usr/bin/env bash # usage: agent-run.sh MODE 'command' MODE: envonly = default bridge with proxy variables set (proxy is a request, not a rule); off = default bridge, no proxy; on = internal network, proxy only MODE=$1; CMD=$2 read CAN INT < "$(dirname "$0")/.ips" HOSTS="--add-host canary.example.test:$CAN --add-host internal.example.test:$INT" case $MODE in off) docker run --rm $HOSTS egress-agent sh -c "$CMD" ;; on) docker run --rm --network agentnet --read-only --cap-drop ALL --user 10001:10001 \ -e http_proxy=http://squid:3128 -e https_proxy=http://squid:3128 egress-agent sh -c "$CMD" ;; envonly) SQ=$(docker inspect -f '{{.NetworkSettings.Networks.bridge.IPAddress}}' squid) docker run --rm $HOSTS -e http_proxy=http://$SQ:3128 -e https_proxy=http://$SQ:3128 egress-agent sh -c "$CMD" ;; esac