【发布时间】:2021-01-13 08:39:06
【问题描述】:
假设我的 iptables 规则在 INPUT 和 OUTPUT 链上默认为 DROP,我必须添加到链中以防止在 GitHub Actions 中运行的脚本无限期停止的最少规则集是多少?
我将(免费)GitHub Actions 用于我的开源应用程序的 CI/CD 基础架构。当我将更改推送到 github.com 时,它会自动在 Microsoft 的云中启动一个 Ubuntu 18.04 linux 服务器,用于签出我的存储库并执行 BASH 脚本来构建我的应用程序。
出于安全原因,在我的构建脚本的早期,我在INPUT 和OUTPUT 链上安装并设置了一些非常严格的iptables 规则,这些规则默认为DROP。我在INPUT 上为127.0.0.1、RELATED/ESTABLISHED 在防火墙上戳了一个洞,并且只允许_apt 用户通过OUTPUT 发送流量。
当我在本地系统的 docker 容器中运行构建脚本时,这非常有用。但是——正如我刚刚了解到的——当它与 GitHub Actions 一起运行时,它会无限期地停止。显然,实例本身需要能够与 GitHub 的服务器进行通信才能完成。而我似乎已经打破了这一点。
所以问题是:我应该在我的 iptables INPUT 和 OUTPUT 链中添加什么 -j ACCEPT 规则,以只允许 GitHub Actions 执行的基本必需品照常进行?
作为参考,这是我的构建脚本中设置防火墙的 sn-p:
##################
# SETUP IPTABLES #
##################
# We setup iptables so that only the apt user (and therefore the apt command)
# can access the internet. We don't want insecure tools like `pip` to download
# unsafe code from the internet.
${SUDO} iptables-save > /tmp/iptables-save.`date "+%Y%m%d_%H%M%S"`
${SUDO} iptables -A INPUT -i lo -j ACCEPT
${SUDO} iptables -A INPUT -s 127.0.0.1/32 -j DROP
${SUDO} iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
${SUDO} iptables -A INPUT -j DROP
${SUDO} iptables -A OUTPUT -s 127.0.0.1/32 -d 127.0.0.1/32 -j ACCEPT
${SUDO} iptables -A OUTPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
${SUDO} iptables -A OUTPUT -m owner --uid-owner 100 -j ACCEPT # apt uid = 100
${SUDO} iptables -A OUTPUT -j DROP
${SUDO} ip6tables-save > /tmp/ip6tables-save.`date "+%Y%m%d_%H%M%S"`
${SUDO} ip6tables -A INPUT -i lo -j ACCEPT
${SUDO} ip6tables -A INPUT -s ::1/128 -j DROP
${SUDO} ip6tables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
${SUDO} ip6tables -A INPUT -j DROP
${SUDO} ip6tables -A OUTPUT -s ::1/128 -d ::1/128 -j ACCEPT
${SUDO} ip6tables -A OUTPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
${SUDO} ip6tables -A OUTPUT -m owner --uid-owner 100 -j ACCEPT
${SUDO} ip6tables -A OUTPUT -j DROP
# attempt to access the internet as root. If it works, exit 1
curl -s 1.1.1.1
if [ $? -eq 0 ]; then
echo "ERROR: iptables isn't blocking internet access to unsafe tools. You may need to run this as root (and you should do it inside a VM)"
exit 1
fi
【问题讨论】:
标签: ubuntu github continuous-integration iptables github-actions