Skip to content

Commit dcd7d5a

Browse files
dmitshurgopherbot
authored andcommitted
cmd/buildlet: find iptables on newer systems, via PATH
iptables may be installed as /usr/sbin/iptables or as /sbin/iptables, depending on the distribution and its age. Prefer to look for it via the PATH environment variable. Also prefer explicitly picking iptables-legacy when available, since on newer systems "iptables" may default to the newer nftables syntax. Also block port 80 while here, and update dashboard test data. Fixes golang/go#51444. Change-Id: I7b0b622502cb88d7c576c1b18a80a9636467d4ea Reviewed-on: https://go-review.googlesource.com/c/build/+/418792 Reviewed-by: Heschi Kreinick <[email protected]> Auto-Submit: Dmitri Shuralyov <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Dmitri Shuralyov <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]>
1 parent 530f97d commit dcd7d5a

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

cmd/buildlet/buildlet.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2010,13 +2010,23 @@ func disableOutboundNetwork() {
20102010
}
20112011

20122012
func disableOutboundNetworkLinux() {
2013-
const iptables = "/sbin/iptables"
2013+
iptables, err := exec.LookPath("iptables-legacy")
2014+
if err != nil {
2015+
// Some older distributions, such as Debian Stretch, don't yet have nftables,
2016+
// so "iptables" gets us the legacy version whose rules syntax is used below.
2017+
iptables, err = exec.LookPath("iptables")
2018+
if err != nil {
2019+
log.Println("disableOutboundNetworkLinux failed to find iptables:", err)
2020+
return
2021+
}
2022+
}
20142023
const vcsTestGolangOrgIPOnVM = "35.184.38.56" // vcs-test.golang.org, on previous VM
20152024
runOrLog(exec.Command(iptables, "-I", "OUTPUT", "1", "-m", "state", "--state", "NEW", "-d", vcsTestGolangOrgIPOnVM, "-p", "tcp", "-j", "ACCEPT"))
20162025
const vcsTestGolangOrgIP = "34.110.184.62" // vcs-test.golang.org, on GKE
20172026
runOrLog(exec.Command(iptables, "-I", "OUTPUT", "1", "-m", "state", "--state", "NEW", "-d", vcsTestGolangOrgIP, "-p", "tcp", "-j", "ACCEPT"))
20182027
runOrLog(exec.Command(iptables, "-I", "OUTPUT", "2", "-m", "state", "--state", "NEW", "-d", "10.0.0.0/8", "-p", "tcp", "-j", "ACCEPT"))
20192028
runOrLog(exec.Command(iptables, "-I", "OUTPUT", "3", "-m", "state", "--state", "NEW", "-p", "tcp", "--dport", "443", "-j", "REJECT", "--reject-with", "icmp-host-prohibited"))
2029+
runOrLog(exec.Command(iptables, "-I", "OUTPUT", "3", "-m", "state", "--state", "NEW", "-p", "tcp", "--dport", "80", "-j", "REJECT", "--reject-with", "icmp-host-prohibited"))
20202030
runOrLog(exec.Command(iptables, "-I", "OUTPUT", "3", "-m", "state", "--state", "NEW", "-p", "tcp", "--dport", "22", "-j", "REJECT", "--reject-with", "icmp-host-prohibited"))
20212031
}
20222032

dashboard/builders_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func TestTrybots(t *testing.T) {
125125
},
126126
{
127127
repo: "go",
128-
branch: "release-branch.go1.17",
128+
branch: "release-branch.go1.18",
129129
want: []string{
130130
"freebsd-amd64-12_3",
131131
"js-wasm",
@@ -163,7 +163,7 @@ func TestTrybots(t *testing.T) {
163163
},
164164
{
165165
repo: "go",
166-
branch: "release-branch.go1.16",
166+
branch: "release-branch.go1.17",
167167
want: []string{
168168
"freebsd-amd64-12_3",
169169
"js-wasm",
@@ -173,6 +173,7 @@ func TestTrybots(t *testing.T) {
173173
"linux-amd64-race",
174174
"linux-arm-aws",
175175
"linux-arm64-aws",
176+
"openbsd-amd64-70",
176177
"windows-386-2008",
177178
"windows-386-2012",
178179
"windows-amd64-2016",

0 commit comments

Comments
 (0)