(t *testing.T, sb integration.Sandbox)
| 1194 | } |
| 1195 | |
| 1196 | func testBuildPolicyConfigFlags(t *testing.T, sb integration.Sandbox) { |
| 1197 | skipNoCompatBuildKit(t, sb, ">= 0.26.0-0", "policy input requires BuildKit v0.26.0+") |
| 1198 | |
| 1199 | dockerfile := []byte("FROM busybox:latest\nRUN echo policy-flags\n") |
| 1200 | defaultPolicy := []byte(` |
| 1201 | package docker |
| 1202 | |
| 1203 | default allow = false |
| 1204 | |
| 1205 | allow if input.env.args["DEFAULT_OK"] == "1" |
| 1206 | |
| 1207 | decision := {"allow": allow} |
| 1208 | `) |
| 1209 | extraPolicy := []byte(` |
| 1210 | package docker |
| 1211 | |
| 1212 | default allow = false |
| 1213 | |
| 1214 | allow if input.env.labels["com.example.extra"] == "1" |
| 1215 | |
| 1216 | decision := {"allow": allow} |
| 1217 | `) |
| 1218 | denyPolicy := []byte(` |
| 1219 | package docker |
| 1220 | |
| 1221 | default allow = false |
| 1222 | |
| 1223 | decision := {"allow": allow} |
| 1224 | `) |
| 1225 | |
| 1226 | t.Run("additional-policy-requires-default", func(t *testing.T) { |
| 1227 | dir := tmpdir( |
| 1228 | t, |
| 1229 | fstest.CreateFile("Dockerfile", dockerfile, 0600), |
| 1230 | fstest.CreateFile("Dockerfile.rego", defaultPolicy, 0600), |
| 1231 | fstest.CreateFile("extra.rego", extraPolicy, 0600), |
| 1232 | ) |
| 1233 | extraPath := filepath.Join(dir, "extra.rego") |
| 1234 | |
| 1235 | cmd := buildxCmd(sb, withDir(dir), withArgs( |
| 1236 | "build", |
| 1237 | "--progress=plain", |
| 1238 | "--policy", "filename="+extraPath, |
| 1239 | "--build-arg", "DEFAULT_OK=1", |
| 1240 | "--label", "com.example.extra=1", |
| 1241 | "--output=type=cacheonly", |
| 1242 | dir, |
| 1243 | )) |
| 1244 | out, err := cmd.CombinedOutput() |
| 1245 | require.NoError(t, err, string(out)) |
| 1246 | |
| 1247 | cmd = buildxCmd(sb, withDir(dir), withArgs( |
| 1248 | "build", |
| 1249 | "--progress=plain", |
| 1250 | "--policy", "filename="+extraPath, |
| 1251 | "--label", "com.example.extra=1", |
| 1252 | "--output=type=cacheonly", |
| 1253 | dir, |
nothing calls this directly
no test coverage detected
searching dependent graphs…