@@ -62,7 +62,8 @@ func TestClientGatewayIntegration(t *testing.T) {
6262 ), integration .WithMirroredImages (integration .OfficialImages ("busybox:latest" )))
6363
6464 integration .Run (t , integration .TestFuncs (
65- testClientGatewayContainerSecurityMode ,
65+ testClientGatewayContainerSecurityModeCaps ,
66+ testClientGatewayContainerSecurityModeValidation ,
6667 ), integration .WithMirroredImages (integration .OfficialImages ("busybox:latest" )),
6768 integration .WithMatrix ("secmode" , map [string ]interface {}{
6869 "sandbox" : securitySandbox ,
@@ -71,7 +72,8 @@ func TestClientGatewayIntegration(t *testing.T) {
7172 )
7273
7374 integration .Run (t , integration .TestFuncs (
74- testClientGatewayContainerHostNetworking ,
75+ testClientGatewayContainerHostNetworkingAccess ,
76+ testClientGatewayContainerHostNetworkingValidation ,
7577 ),
7678 integration .WithMirroredImages (integration .OfficialImages ("busybox:latest" )),
7779 integration .WithMatrix ("netmode" , map [string ]interface {}{
@@ -1836,9 +1838,17 @@ func testClientGatewayExecFileActionError(t *testing.T, sb integration.Sandbox)
18361838 checkAllReleasable (t , c , sb , true )
18371839}
18381840
1839- // testClientGatewayContainerSecurityMode ensures that the correct security mode
1841+ // testClientGatewayContainerSecurityModeCaps ensures that the correct security mode
18401842// is propagated to the gateway container
1841- func testClientGatewayContainerSecurityMode (t * testing.T , sb integration.Sandbox ) {
1843+ func testClientGatewayContainerSecurityModeCaps (t * testing.T , sb integration.Sandbox ) {
1844+ testClientGatewayContainerSecurityMode (t , sb , false )
1845+ }
1846+
1847+ func testClientGatewayContainerSecurityModeValidation (t * testing.T , sb integration.Sandbox ) {
1848+ testClientGatewayContainerSecurityMode (t , sb , true )
1849+ }
1850+
1851+ func testClientGatewayContainerSecurityMode (t * testing.T , sb integration.Sandbox , expectFail bool ) {
18421852 integration .CheckFeatureCompat (t , sb , integration .FeatureSecurityMode )
18431853 requiresLinux (t )
18441854
@@ -1865,6 +1875,9 @@ func testClientGatewayContainerSecurityMode(t *testing.T, sb integration.Sandbox
18651875 require .EqualValues (t , 0xa80425fb , caps )
18661876 }
18671877 allowedEntitlements = []entitlements.Entitlement {}
1878+ if expectFail {
1879+ return
1880+ }
18681881 } else {
18691882 assertCaps = func (caps uint64 ) {
18701883 /*
@@ -1881,6 +1894,9 @@ func testClientGatewayContainerSecurityMode(t *testing.T, sb integration.Sandbox
18811894 }
18821895 mode = llb .SecurityModeInsecure
18831896 allowedEntitlements = []entitlements.Entitlement {entitlements .EntitlementSecurityInsecure }
1897+ if expectFail {
1898+ allowedEntitlements = []entitlements.Entitlement {}
1899+ }
18841900 }
18851901
18861902 b := func (ctx context.Context , c client.Client ) (* client.Result , error ) {
@@ -1930,6 +1946,12 @@ func testClientGatewayContainerSecurityMode(t *testing.T, sb integration.Sandbox
19301946 t .Logf ("Stdout: %q" , stdout .String ())
19311947 t .Logf ("Stderr: %q" , stderr .String ())
19321948
1949+ if expectFail {
1950+ require .Error (t , err )
1951+ require .Contains (t , err .Error (), "security.insecure is not allowed" )
1952+ return nil , err
1953+ }
1954+
19331955 require .NoError (t , err )
19341956
19351957 capsValue , err := strconv .ParseUint (strings .TrimSpace (stdout .String ()), 16 , 64 )
@@ -1944,7 +1966,13 @@ func testClientGatewayContainerSecurityMode(t *testing.T, sb integration.Sandbox
19441966 AllowedEntitlements : allowedEntitlements ,
19451967 }
19461968 _ , err = c .Build (ctx , solveOpts , product , b , nil )
1947- require .NoError (t , err )
1969+
1970+ if expectFail {
1971+ require .Error (t , err )
1972+ require .Contains (t , err .Error (), "security.insecure is not allowed" )
1973+ } else {
1974+ require .NoError (t , err )
1975+ }
19481976
19491977 checkAllReleasable (t , c , sb , true )
19501978}
@@ -2020,7 +2048,15 @@ func testClientGatewayContainerExtraHosts(t *testing.T, sb integration.Sandbox)
20202048 checkAllReleasable (t , c , sb , true )
20212049}
20222050
2023- func testClientGatewayContainerHostNetworking (t * testing.T , sb integration.Sandbox ) {
2051+ func testClientGatewayContainerHostNetworkingAccess (t * testing.T , sb integration.Sandbox ) {
2052+ testClientGatewayContainerHostNetworking (t , sb , false )
2053+ }
2054+
2055+ func testClientGatewayContainerHostNetworkingValidation (t * testing.T , sb integration.Sandbox ) {
2056+ testClientGatewayContainerHostNetworking (t , sb , true )
2057+ }
2058+
2059+ func testClientGatewayContainerHostNetworking (t * testing.T , sb integration.Sandbox , expectFail bool ) {
20242060 if os .Getenv ("BUILDKIT_RUN_NETWORK_INTEGRATION_TESTS" ) == "" {
20252061 t .SkipNow ()
20262062 }
@@ -2041,6 +2077,9 @@ func testClientGatewayContainerHostNetworking(t *testing.T, sb integration.Sandb
20412077 if sb .Value ("netmode" ) == hostNetwork {
20422078 netMode = pb .NetMode_HOST
20432079 allowedEntitlements = []entitlements.Entitlement {entitlements .EntitlementNetworkHost }
2080+ if expectFail {
2081+ allowedEntitlements = []entitlements.Entitlement {}
2082+ }
20442083 }
20452084 c , err := New (sb .Context (), sb .Address ())
20462085 require .NoError (t , err )
@@ -2099,7 +2138,12 @@ func testClientGatewayContainerHostNetworking(t *testing.T, sb integration.Sandb
20992138 t .Logf ("Stderr: %q" , stderr .String ())
21002139
21012140 if netMode == pb .NetMode_HOST {
2102- require .NoError (t , err )
2141+ if expectFail {
2142+ require .Error (t , err )
2143+ require .Contains (t , err .Error (), "network.host is not allowed" )
2144+ } else {
2145+ require .NoError (t , err )
2146+ }
21032147 } else {
21042148 require .Error (t , err )
21052149 }
0 commit comments