Skip to content

Instantly share code, notes, and snippets.

@akoenig
Created March 4, 2018 07:43
Show Gist options
  • Save akoenig/789627651bb9bc82b97c2fcc2df91c30 to your computer and use it in GitHub Desktop.
Save akoenig/789627651bb9bc82b97c2fcc2df91c30 to your computer and use it in GitHub Desktop.
#!/usr/bin/env sh
#
# iptables configuration
#
# The following allows in- and outbound traffic
# within a certain `CIDR` (default: `192.168.0.0/24`),
# but blocks all other network traffic.
#
ACCEPT_CIDR=${ALLOWED_CIDR:-192.168.0.0/24}
iptables -A INPUT -s $ACCEPT_CIDR -j ACCEPT
iptables -A INPUT -j DROP
iptables -A OUTPUT -d $ACCEPT_CIDR -j ACCEPT
iptables -A OUTPUT -j DROP
#
# After configuring `iptables` as root, execute
# the passed command as the non-privileged `app` user.
#
sudo -u app sh -c "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment