Last active
April 27, 2016 01:02
-
-
Save lrvick/1f10da6b46f9142100728eef46e93f79 to your computer and use it in GitHub Desktop.
Hack to bypass Nginx proxy in a ElasticBeanstalk deployment for UDP applications such as rsyslog
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Place in .ebextensions/00-bypass-nginx-proxy.config at the root of your appkication repository. | |
files: | |
"/tmp/setup_iptables.sh": | |
mode: "000755" | |
content: | | |
#!/bin/sh | |
# remove rules added by us (marked by the "added_by_ebextension" comment), if any | |
iptables-save | grep -v added_by_ebextension | iptables-restore | |
# get IP address of the docker container | |
ip=$(docker inspect `cat /etc/elasticbeanstalk/.aws_beanstalk.staging-container-id` | jq -r .[0].NetworkSettings.IPAddress) | |
port=$(docker inspect `cat /etc/elasticbeanstalk/.aws_beanstalk.staging-container-id` | jq -r .[0].Config.ExposedPorts | jq -r to_entries[0].key | sed 's/\/tcp//') | |
# add our rule with the "added_by_ebextension" as a special marker | |
iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 514 -j DNAT --to ${ip}:${port} -m comment --comment added_by_ebextension | |
iptables -A PREROUTING -t nat -i eth0 -p udp --dport 514 -j DNAT --to ${ip}:${port} -m comment --comment added_by_ebextension | |
# following are optional since the FORWARD chain is ACCEPT by default | |
# iptables -A FORWARD -p tcp -m conntrack --ctstate RELATED,ESTABLISHED -d ${ip} -j ACCEPT -m comment --comment added_by_ebextension | |
# iptables -A FORWARD -p tcp -d ${ip} --dport 80 -j ACCEPT -m comment --comment added_by_ebextension | |
# save in case of reboot | |
service iptables save | |
container_commands: | |
00setup-iptables: | |
command: "/tmp/setup_iptables.sh" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment