@@ -2184,6 +2184,48 @@ RUN if echo > /dev/tcp/8.8.8.8/53; then echo "Has network access!"; exit 1; fi
21842184 })
21852185 })
21862186
2187+ t .Run ("DoesntBlockLoopback" , func (t * testing.T ) {
2188+ contextDir := setupTestContext (t )
2189+ writeContainerfile (contextDir , fmt .Sprintf (`
2190+ FROM %s
2191+
2192+ # Try to connect to the UDP port 9 (the discard port).
2193+ # UDP avoids the "Connection refused" that we would get with TCP because nothing is listening.
2194+ RUN echo > /dev/udp/127.0.0.1/9
2195+ ` , baseImage ))
2196+
2197+ runTest := func (t * testing.T , user string ) {
2198+ SetupGomega (t )
2199+
2200+ outputRef := "localhost/test-hermetic-loopback:" + GenerateUniqueTag (t )
2201+
2202+ buildParams := BuildParams {
2203+ Context : contextDir ,
2204+ OutputRef : outputRef ,
2205+ Push : false ,
2206+ Hermetic : true ,
2207+ }
2208+
2209+ var opts []ContainerOption
2210+ if user == "root" {
2211+ opts = append (opts , WithUser ("root" ), maybeMountContainerStorage (rootStoragePath , "root" ))
2212+ }
2213+
2214+ container := setupBuildContainerWithCleanup (t , buildParams , nil , opts ... )
2215+
2216+ _ , _ , err := runBuildWithOutput (container , buildParams )
2217+ Expect (err ).ToNot (HaveOccurred ())
2218+ }
2219+
2220+ t .Run ("AsNonRoot" , func (t * testing.T ) {
2221+ runTest (t , "taskuser" )
2222+ })
2223+
2224+ t .Run ("AsRoot" , func (t * testing.T ) {
2225+ runTest (t , "root" )
2226+ })
2227+ })
2228+
21872229 t .Run ("PrePullImages" , func (t * testing.T ) {
21882230 SetupGomega (t )
21892231
0 commit comments