@@ -62,7 +62,8 @@ func TestClientGatewayIntegration(t *testing.T) {
62
62
), integration .WithMirroredImages (integration .OfficialImages ("busybox:latest" )))
63
63
64
64
integration .Run (t , integration .TestFuncs (
65
- testClientGatewayContainerSecurityMode ,
65
+ testClientGatewayContainerSecurityModeCaps ,
66
+ testClientGatewayContainerSecurityModeValidation ,
66
67
), integration .WithMirroredImages (integration .OfficialImages ("busybox:latest" )),
67
68
integration .WithMatrix ("secmode" , map [string ]interface {}{
68
69
"sandbox" : securitySandbox ,
@@ -71,7 +72,8 @@ func TestClientGatewayIntegration(t *testing.T) {
71
72
)
72
73
73
74
integration .Run (t , integration .TestFuncs (
74
- testClientGatewayContainerHostNetworking ,
75
+ testClientGatewayContainerHostNetworkingAccess ,
76
+ testClientGatewayContainerHostNetworkingValidation ,
75
77
),
76
78
integration .WithMirroredImages (integration .OfficialImages ("busybox:latest" )),
77
79
integration .WithMatrix ("netmode" , map [string ]interface {}{
@@ -1836,9 +1838,17 @@ func testClientGatewayExecFileActionError(t *testing.T, sb integration.Sandbox)
1836
1838
checkAllReleasable (t , c , sb , true )
1837
1839
}
1838
1840
1839
- // testClientGatewayContainerSecurityMode ensures that the correct security mode
1841
+ // testClientGatewayContainerSecurityModeCaps ensures that the correct security mode
1840
1842
// 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 ) {
1842
1852
integration .CheckFeatureCompat (t , sb , integration .FeatureSecurityMode )
1843
1853
requiresLinux (t )
1844
1854
@@ -1865,6 +1875,9 @@ func testClientGatewayContainerSecurityMode(t *testing.T, sb integration.Sandbox
1865
1875
require .EqualValues (t , 0xa80425fb , caps )
1866
1876
}
1867
1877
allowedEntitlements = []entitlements.Entitlement {}
1878
+ if expectFail {
1879
+ return
1880
+ }
1868
1881
} else {
1869
1882
assertCaps = func (caps uint64 ) {
1870
1883
/*
@@ -1881,6 +1894,9 @@ func testClientGatewayContainerSecurityMode(t *testing.T, sb integration.Sandbox
1881
1894
}
1882
1895
mode = llb .SecurityModeInsecure
1883
1896
allowedEntitlements = []entitlements.Entitlement {entitlements .EntitlementSecurityInsecure }
1897
+ if expectFail {
1898
+ allowedEntitlements = []entitlements.Entitlement {}
1899
+ }
1884
1900
}
1885
1901
1886
1902
b := func (ctx context.Context , c client.Client ) (* client.Result , error ) {
@@ -1930,6 +1946,12 @@ func testClientGatewayContainerSecurityMode(t *testing.T, sb integration.Sandbox
1930
1946
t .Logf ("Stdout: %q" , stdout .String ())
1931
1947
t .Logf ("Stderr: %q" , stderr .String ())
1932
1948
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
+
1933
1955
require .NoError (t , err )
1934
1956
1935
1957
capsValue , err := strconv .ParseUint (strings .TrimSpace (stdout .String ()), 16 , 64 )
@@ -1944,7 +1966,13 @@ func testClientGatewayContainerSecurityMode(t *testing.T, sb integration.Sandbox
1944
1966
AllowedEntitlements : allowedEntitlements ,
1945
1967
}
1946
1968
_ , 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
+ }
1948
1976
1949
1977
checkAllReleasable (t , c , sb , true )
1950
1978
}
@@ -2020,7 +2048,15 @@ func testClientGatewayContainerExtraHosts(t *testing.T, sb integration.Sandbox)
2020
2048
checkAllReleasable (t , c , sb , true )
2021
2049
}
2022
2050
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 ) {
2024
2060
if os .Getenv ("BUILDKIT_RUN_NETWORK_INTEGRATION_TESTS" ) == "" {
2025
2061
t .SkipNow ()
2026
2062
}
@@ -2041,6 +2077,9 @@ func testClientGatewayContainerHostNetworking(t *testing.T, sb integration.Sandb
2041
2077
if sb .Value ("netmode" ) == hostNetwork {
2042
2078
netMode = pb .NetMode_HOST
2043
2079
allowedEntitlements = []entitlements.Entitlement {entitlements .EntitlementNetworkHost }
2080
+ if expectFail {
2081
+ allowedEntitlements = []entitlements.Entitlement {}
2082
+ }
2044
2083
}
2045
2084
c , err := New (sb .Context (), sb .Address ())
2046
2085
require .NoError (t , err )
@@ -2099,7 +2138,12 @@ func testClientGatewayContainerHostNetworking(t *testing.T, sb integration.Sandb
2099
2138
t .Logf ("Stderr: %q" , stderr .String ())
2100
2139
2101
2140
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
+ }
2103
2147
} else {
2104
2148
require .Error (t , err )
2105
2149
}
0 commit comments