--- /dev/null
+#!/bin/sh
+
+# Get list of nefarious IP addresses from www.friedersdorff.com/.banned
+
+BANNED_HOSTS=$(curl -s https://www.friedersdorff.com/.banned |
+ grep -o -E '([[:digit:]]{1,3}\.){3}[[:digit:]]{1,3}/[[:digit:]]{1,2}')
+ALLOWED_HOSTS=$(cat /etc/glocker/allowed_hosts)
+
+ipset create glocker-tmp hash:net --hashsize 64
+for host in $(echo $BANNED_HOSTS); do
+ ipset add glocker-tmp $host
+done
+
+ipset create -exist glocker hash:net --hashsize 64
+ipset swap glocker-tmp glocker
+ipset destroy glocker-tmp
+echo "IPSet: glocker updated"
+
+# Use local list of explicitly allowed IP addresses from the local machine
+ipset create glocker-tmp hash:net --hashsize 64
+for host in $(echo $ALLOWED_HOSTS); do
+ ip=$(nslookup $host | tail -n2 | head -n1 | sed 's/Address: //')
+ ipset add glocker-tmp $host
+done
+
+ipset create -exist glocker-except hash:net --hashsize 64
+ipset swap glocker-tmp glocker-except
+ipset destroy glocker-tmp
+echo "IPSet: glocker-except updated"
--- /dev/null
+glocker chain:
+ iptables.chain_present:
+ - name: glocker
+ - table: filter
+
+accept glocker-except:
+ iptables.insert:
+ - table: filter
+ - chain: glocker
+ - jump: ACCEPT
+ - match-set: glocker-except dst
+ - position: 1
+
+allow uid 40000-50000:
+ iptables.insert:
+ - table: filter
+ - chain: glocker
+ - jump: ACCEPT
+ - match: owner
+ - uid-owner: 40000-50000
+ - position: 2
+
+reject glocker:
+ iptables.insert:
+ - table: filter
+ - chain: glocker
+ - jump: REJECT
+ - reject-with: icmp-port-unreachable
+ - match-set: glocker dst
+ - position: 3
+
+jump to glocker:
+ iptables.insert:
+ - table: filter
+ - chain: OUTPUT
+ - jump: glocker
+ - position: 1
+
+glocker cron job:
+ file.managed:
+ - name: /etc/cron.hourly/glocker
+ - source: salt://glocker/files/cronjob
+ - user: root
+ - group: root
+ - mode: 750
+
+ensure allowed_hosts file exists:
+ file.touch:
+ - name: /etc/glocker/allowed_hosts
+ - makedirs: True