From 69c90d663eaa40f0a09fb7f7f12ddbc611d31bfb Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Tue, 17 Nov 2026 12:10:01 -0800 Subject: [PATCH 1/4] devops(docker): scan the image for secrets with Trivy --- .github/workflows/test_docker.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/test_docker.yml b/.github/workflows/test_docker.yml index b6f601177..348328ae5 100644 --- a/.github/workflows/test_docker.yml +++ b/.github/workflows/test_docker.yml @@ -39,6 +39,16 @@ jobs: - name: Build Docker image run: | bash utils/docker/build.sh --${{ matrix.arch }} ${{ matrix.flavor }} playwright-java:localbuild-${{ matrix.flavor }} + # The scan looks at the content of the files, in all layers of the image. + - name: Scan the image for secrets + uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0 + with: + image-ref: playwright-java:localbuild-${{ matrix.flavor }} + scanners: secret + version: v0.76.2 + exit-code: '1' + # The secret scan needs no vulnerability database. + cache: 'false' - name: Start container run: | CONTAINER_ID=$(docker run \ From 2bac1b4699da7f82ed6e94ed1258197252f14f0f Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Tue, 17 Nov 2026 13:15:13 -0800 Subject: [PATCH 2/4] chore(docker): use the default Trivy version of the action --- .github/workflows/test_docker.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/test_docker.yml b/.github/workflows/test_docker.yml index 348328ae5..cf625af4e 100644 --- a/.github/workflows/test_docker.yml +++ b/.github/workflows/test_docker.yml @@ -45,7 +45,6 @@ jobs: with: image-ref: playwright-java:localbuild-${{ matrix.flavor }} scanners: secret - version: v0.76.2 exit-code: '1' # The secret scan needs no vulnerability database. cache: 'false' From bb9954cfac2575330fd1e9d6ce92492ad875fc65 Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Tue, 17 Nov 2026 13:28:06 -0800 Subject: [PATCH 3/4] devops(docker): check the image layers for caches and leftovers --- .github/workflows/test_docker.yml | 7 +- utils/docker/build.sh | 2 + utils/docker/check_layers.js | 153 ++++++++++++++++++++++++++++++ utils/docker/test_check_layers.sh | 75 +++++++++++++++ 4 files changed, 236 insertions(+), 1 deletion(-) create mode 100755 utils/docker/check_layers.js create mode 100755 utils/docker/test_check_layers.sh diff --git a/.github/workflows/test_docker.yml b/.github/workflows/test_docker.yml index cf625af4e..8897832ab 100644 --- a/.github/workflows/test_docker.yml +++ b/.github/workflows/test_docker.yml @@ -4,6 +4,7 @@ on: paths: - '.github/workflows/test_docker.yml' - '**/Dockerfile*' + - 'utils/docker/**' branches: - main - release-* @@ -11,6 +12,7 @@ on: paths: - .github/workflows/test_docker.yml - '**/Dockerfile*' + - 'utils/docker/**' - scripts/DRIVER_VERSION - scripts/NODE_VERSION - '**/pom.xml' @@ -39,7 +41,8 @@ jobs: - name: Build Docker image run: | bash utils/docker/build.sh --${{ matrix.arch }} ${{ matrix.flavor }} playwright-java:localbuild-${{ matrix.flavor }} - # The scan looks at the content of the files, in all layers of the image. + # check_layers.js looks at the paths of the files, for caches and other leftovers. + # This scan looks at the content of the files, in all layers, and finds secrets. - name: Scan the image for secrets uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0 with: @@ -48,6 +51,8 @@ jobs: exit-code: '1' # The secret scan needs no vulnerability database. cache: 'false' + - name: Test check_layers.js + run: bash utils/docker/test_check_layers.sh - name: Start container run: | CONTAINER_ID=$(docker run \ diff --git a/utils/docker/build.sh b/utils/docker/build.sh index 2494eade8..addeb2eb0 100755 --- a/utils/docker/build.sh +++ b/utils/docker/build.sh @@ -82,6 +82,8 @@ for ((attempt = 1; attempt <= MAX_ATTEMPTS; attempt++)); do --build-arg ACR_CACHE_PREFIX="${ACR_CACHE_PREFIX}" \ --build-arg UBUNTU_MIRROR_PREFIX="${UBUNTU_MIRROR_PREFIX}" \ -t "$3" -f "Dockerfile.$2" .; then + # A failure of this check is not transient, so it does not retry the build. + node ./check_layers.js "$3" exit 0 fi if (( attempt < MAX_ATTEMPTS )); then diff --git a/utils/docker/check_layers.js b/utils/docker/check_layers.js new file mode 100755 index 000000000..612ff90aa --- /dev/null +++ b/utils/docker/check_layers.js @@ -0,0 +1,153 @@ +#!/usr/bin/env node +/** + * Copyright (c) Microsoft Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * The same file is in microsoft/playwright, microsoft/playwright-python, + * microsoft/playwright-java and microsoft/playwright-mcp, in utils/docker/. + * Keep the copies the same. + */ + +const fs = require('fs'); +const os = require('os'); +const path = require('path'); +const { execFileSync, spawnSync } = require('child_process'); + +const SCRIPT_NAME = path.basename(__filename); + +// A file that a later layer deletes is still in the layer that created it. It makes +// the image larger, and everyone who pulls the image can read it there. So the check +// reads every layer, not the file system of the final image. +// +// This check looks only at the paths of the files. It does not look for secrets: +// the Trivy scan in the Docker tests does that, by content. +// +// Each pattern is matched against the path of a file in a layer, for example +// "root/.npm/_logs/2026-01-01-debug-0.log". +const FORBIDDEN = [ + // npm: the cache and the debug logs. + /(^|\/)\.npm\//, + /(^|\/)_cacache\//, + /(^|\/)_logs\/.*-debug-\d+\.log$/, + // Node.js: the compile cache that npm turns on. It is in the temporary directory. + /(^|\/)node-compile-cache\//, + // yarn. + /(^|\/)\.yarn\//, + // Maven: the local repository. + /(^|\/)\.m2\//, + // The cache directory of a user: pip, virtualenv, yarn and other tools write here. + /(^|\/)\.cache\//, + // Source control. + /(^|\/)\.git\//, +]; + +function usage() { + return `usage: ${SCRIPT_NAME} [--list-files] playwright:localbuild-noble + +Check that no layer of the docker image contains files that a build step +must not leave behind, such as a package manager cache or a .git directory. + + --list-files also print every file that the layers of our Dockerfile add. + Layers of the base image are not listed. +`; +} + +const args = process.argv.slice(2); +if (!args.length || args.includes('--help') || args.includes('-h')) { + console.log(usage()); + process.exit(args.length ? 0 : 1); +} +const listFiles = args.includes('--list-files'); +const images = args.filter(arg => arg !== '--list-files'); +if (images.length !== 1 || images[0].startsWith('-')) { + console.error(usage()); + process.exit(1); +} +const image = images[0]; + +const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'check-layers-')); +process.on('exit', () => fs.rmSync(tmpDir, { recursive: true, force: true })); + +console.log(`Checking the layers of ${image} for caches and other files that must not be in the image...`); +// Unpack the image without a copy of the archive on disk. With pipefail, a +// failure of "docker save" fails the command too. +const saved = spawnSync('bash', ['-o', 'pipefail', '-c', 'docker save "$0" | tar -x -C "$1"', image, tmpDir], { stdio: 'inherit' }); +if (saved.status !== 0) { + console.error(`ERROR: cannot save and unpack ${image}`); + process.exit(1); +} + +let failed = false; +const layers = readLayers(tmpDir); +if (!layers.length) { + console.error(`ERROR: found no layers in ${image}`); + process.exit(1); +} +layers.forEach((layer, index) => { + const files = listLayerFiles(path.join(tmpDir, layer.file)); + if (listFiles && layer.ours) { + console.log(`\n=== layer ${index + 1}: ${layer.step}`); + console.log(`=== ${files.length} file(s). A ".wh." name marks a file that the layer deletes.`); + console.log(files.join('\n')); + } + const matches = files.filter(file => FORBIDDEN.some(re => re.test(file))); + if (!matches.length) + return; + failed = true; + console.log(`\nERROR: layer ${index + 1} contains ${matches.length} forbidden file(s).`); + console.log(` step: ${layer.step}`); + for (const file of matches.slice(0, 20)) + console.log(` ${file}`); +}); + +if (failed) { + console.error('\nThese files stay in the image even when a later layer deletes them.'); + console.error('Do not create them, or delete them in the RUN step that creates them.'); + process.exit(1); +} +console.log(`\nChecked ${layers.length} layer(s), found no forbidden files.`); + +/** + * Returns the layers of an unpacked "docker save" archive, bottom layer first. + * @returns {{ file: string, ours: boolean, step: string }[]} + */ +function readLayers(dir) { + const manifest = JSON.parse(fs.readFileSync(path.join(dir, 'manifest.json'), 'utf8'))[0]; + const config = JSON.parse(fs.readFileSync(path.join(dir, manifest.Config), 'utf8')); + // The history also has the steps that make no layer, such as ENV and ARG. + const steps = (config.history || []).filter(step => !step.empty_layer); + return manifest.Layers.map((file, i) => { + const step = steps[i] || {}; + // BuildKit puts the build arguments in front of a RUN command. Remove them. + const command = (step.created_by || '?').replace(/^RUN \|\d+ .*? \/bin\/sh -c /, 'RUN ').replace(/\s+/g, ' '); + return { + file, + // BuildKit marks the steps of the Dockerfile that it runs. The base image has no mark. + ours: (step.comment || '').includes('buildkit.dockerfile'), + step: command.length > 100 ? command.slice(0, 100) + '...' : command, + }; + }); +} + +/** + * Returns the paths of the files in a layer. tar reads both plain and compressed layers. + */ +function listLayerFiles(layerFile) { + const output = execFileSync('tar', ['-tf', layerFile], { encoding: 'utf8', maxBuffer: 1024 * 1024 * 1024 }); + return output.split('\n') + // Paths in a layer can start with "./". + .map(line => line.replace(/^\.\//, '')) + // Skip directory entries: an empty directory is not a problem. + .filter(line => line && !line.endsWith('/')); +} diff --git a/utils/docker/test_check_layers.sh b/utils/docker/test_check_layers.sh new file mode 100755 index 000000000..a9c38423d --- /dev/null +++ b/utils/docker/test_check_layers.sh @@ -0,0 +1,75 @@ +#!/usr/bin/env bash +set -e +set +x + +if [[ ($1 == '--help') || ($1 == '-h') ]]; then + echo "usage: $(basename $0)" + echo + echo "Test check_layers.js with two small images that this script builds." + echo + exit 0 +fi + +# The images that we publish are clean, so a build never sees check_layers.js fail. +# This test gives it an image with forbidden files, to know that it still finds them. + +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd -P)" +TMP_DIR="$(mktemp -d)" + +function cleanup() { + rm -rf "${TMP_DIR}" + docker rmi -f playwright:check-layers-bad playwright:check-layers-good > /dev/null 2>&1 || true +} +trap cleanup EXIT + +cd "${TMP_DIR}" +echo "placeholder" > file + +# 1. Forbidden files in a lower layer must fail the check. +FORBIDDEN_FILES=( + root/.npm/_cacache/index-v5/aa/bb/cc + root/.npm/_logs/2026-01-01T00_00_00_000Z-debug-0.log + tmp/node-compile-cache/v26.0.0-x64/aabbcc + root/.yarn/berry/cache/a.zip + root/.m2/repository/com/example/a/1.0/a-1.0.jar + root/.cache/pip/http-v2/a/b/c + home/pwuser/.cache/virtualenv/a + src/.git/config +) +echo "FROM scratch" > Dockerfile.bad +for FORBIDDEN_FILE in "${FORBIDDEN_FILES[@]}"; do + echo "COPY file /${FORBIDDEN_FILE}" >> Dockerfile.bad +done +echo "COPY file /readme" >> Dockerfile.bad +docker build -q -t playwright:check-layers-bad -f Dockerfile.bad . > /dev/null +if node "${SCRIPT_DIR}/check_layers.js" playwright:check-layers-bad > output.txt 2>&1; then + cat output.txt + echo "FAILED: check_layers.js passed for an image with forbidden files in its layers" + exit 1 +fi +# The check must fail because it found the files, not because it crashed. +for FORBIDDEN_FILE in "${FORBIDDEN_FILES[@]}"; do + if ! grep -q -x -F " ${FORBIDDEN_FILE}" output.txt; then + cat output.txt + echo "FAILED: check_layers.js did not report ${FORBIDDEN_FILE}" + exit 1 + fi +done + +# 2. An image with no forbidden files must pass the check. Files that can hold +# a secret, such as .npmrc, pass too: the Trivy scan looks for secrets. +cat > Dockerfile.good <<'DOCKERFILE' +FROM scratch +COPY file /usr/local/lib/node_modules/npm/.npmrc +COPY file /etc/ssl/certs/ca.pem +COPY file /var/cache/fontconfig/aabbcc.cache-9 +COPY file /readme +DOCKERFILE +docker build -q -t playwright:check-layers-good -f Dockerfile.good . > /dev/null +if ! node "${SCRIPT_DIR}/check_layers.js" playwright:check-layers-good > output.txt 2>&1; then + cat output.txt + echo "FAILED: check_layers.js failed for an image with no forbidden files" + exit 1 +fi + +echo "PASSED: check_layers.js finds forbidden files and accepts a clean image" From 8c15c969f84639eb780264205a3cbd4e6cfaeb67 Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Tue, 17 Nov 2026 13:32:47 -0800 Subject: [PATCH 4/4] chore(docker): remove check_layers.js, keep the Trivy scan --- .github/workflows/test_docker.yml | 7 +- utils/docker/build.sh | 2 - utils/docker/check_layers.js | 153 ------------------------------ utils/docker/test_check_layers.sh | 75 --------------- 4 files changed, 1 insertion(+), 236 deletions(-) delete mode 100755 utils/docker/check_layers.js delete mode 100755 utils/docker/test_check_layers.sh diff --git a/.github/workflows/test_docker.yml b/.github/workflows/test_docker.yml index 8897832ab..cf625af4e 100644 --- a/.github/workflows/test_docker.yml +++ b/.github/workflows/test_docker.yml @@ -4,7 +4,6 @@ on: paths: - '.github/workflows/test_docker.yml' - '**/Dockerfile*' - - 'utils/docker/**' branches: - main - release-* @@ -12,7 +11,6 @@ on: paths: - .github/workflows/test_docker.yml - '**/Dockerfile*' - - 'utils/docker/**' - scripts/DRIVER_VERSION - scripts/NODE_VERSION - '**/pom.xml' @@ -41,8 +39,7 @@ jobs: - name: Build Docker image run: | bash utils/docker/build.sh --${{ matrix.arch }} ${{ matrix.flavor }} playwright-java:localbuild-${{ matrix.flavor }} - # check_layers.js looks at the paths of the files, for caches and other leftovers. - # This scan looks at the content of the files, in all layers, and finds secrets. + # The scan looks at the content of the files, in all layers of the image. - name: Scan the image for secrets uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0 with: @@ -51,8 +48,6 @@ jobs: exit-code: '1' # The secret scan needs no vulnerability database. cache: 'false' - - name: Test check_layers.js - run: bash utils/docker/test_check_layers.sh - name: Start container run: | CONTAINER_ID=$(docker run \ diff --git a/utils/docker/build.sh b/utils/docker/build.sh index addeb2eb0..2494eade8 100755 --- a/utils/docker/build.sh +++ b/utils/docker/build.sh @@ -82,8 +82,6 @@ for ((attempt = 1; attempt <= MAX_ATTEMPTS; attempt++)); do --build-arg ACR_CACHE_PREFIX="${ACR_CACHE_PREFIX}" \ --build-arg UBUNTU_MIRROR_PREFIX="${UBUNTU_MIRROR_PREFIX}" \ -t "$3" -f "Dockerfile.$2" .; then - # A failure of this check is not transient, so it does not retry the build. - node ./check_layers.js "$3" exit 0 fi if (( attempt < MAX_ATTEMPTS )); then diff --git a/utils/docker/check_layers.js b/utils/docker/check_layers.js deleted file mode 100755 index 612ff90aa..000000000 --- a/utils/docker/check_layers.js +++ /dev/null @@ -1,153 +0,0 @@ -#!/usr/bin/env node -/** - * Copyright (c) Microsoft Corporation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * The same file is in microsoft/playwright, microsoft/playwright-python, - * microsoft/playwright-java and microsoft/playwright-mcp, in utils/docker/. - * Keep the copies the same. - */ - -const fs = require('fs'); -const os = require('os'); -const path = require('path'); -const { execFileSync, spawnSync } = require('child_process'); - -const SCRIPT_NAME = path.basename(__filename); - -// A file that a later layer deletes is still in the layer that created it. It makes -// the image larger, and everyone who pulls the image can read it there. So the check -// reads every layer, not the file system of the final image. -// -// This check looks only at the paths of the files. It does not look for secrets: -// the Trivy scan in the Docker tests does that, by content. -// -// Each pattern is matched against the path of a file in a layer, for example -// "root/.npm/_logs/2026-01-01-debug-0.log". -const FORBIDDEN = [ - // npm: the cache and the debug logs. - /(^|\/)\.npm\//, - /(^|\/)_cacache\//, - /(^|\/)_logs\/.*-debug-\d+\.log$/, - // Node.js: the compile cache that npm turns on. It is in the temporary directory. - /(^|\/)node-compile-cache\//, - // yarn. - /(^|\/)\.yarn\//, - // Maven: the local repository. - /(^|\/)\.m2\//, - // The cache directory of a user: pip, virtualenv, yarn and other tools write here. - /(^|\/)\.cache\//, - // Source control. - /(^|\/)\.git\//, -]; - -function usage() { - return `usage: ${SCRIPT_NAME} [--list-files] playwright:localbuild-noble - -Check that no layer of the docker image contains files that a build step -must not leave behind, such as a package manager cache or a .git directory. - - --list-files also print every file that the layers of our Dockerfile add. - Layers of the base image are not listed. -`; -} - -const args = process.argv.slice(2); -if (!args.length || args.includes('--help') || args.includes('-h')) { - console.log(usage()); - process.exit(args.length ? 0 : 1); -} -const listFiles = args.includes('--list-files'); -const images = args.filter(arg => arg !== '--list-files'); -if (images.length !== 1 || images[0].startsWith('-')) { - console.error(usage()); - process.exit(1); -} -const image = images[0]; - -const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'check-layers-')); -process.on('exit', () => fs.rmSync(tmpDir, { recursive: true, force: true })); - -console.log(`Checking the layers of ${image} for caches and other files that must not be in the image...`); -// Unpack the image without a copy of the archive on disk. With pipefail, a -// failure of "docker save" fails the command too. -const saved = spawnSync('bash', ['-o', 'pipefail', '-c', 'docker save "$0" | tar -x -C "$1"', image, tmpDir], { stdio: 'inherit' }); -if (saved.status !== 0) { - console.error(`ERROR: cannot save and unpack ${image}`); - process.exit(1); -} - -let failed = false; -const layers = readLayers(tmpDir); -if (!layers.length) { - console.error(`ERROR: found no layers in ${image}`); - process.exit(1); -} -layers.forEach((layer, index) => { - const files = listLayerFiles(path.join(tmpDir, layer.file)); - if (listFiles && layer.ours) { - console.log(`\n=== layer ${index + 1}: ${layer.step}`); - console.log(`=== ${files.length} file(s). A ".wh." name marks a file that the layer deletes.`); - console.log(files.join('\n')); - } - const matches = files.filter(file => FORBIDDEN.some(re => re.test(file))); - if (!matches.length) - return; - failed = true; - console.log(`\nERROR: layer ${index + 1} contains ${matches.length} forbidden file(s).`); - console.log(` step: ${layer.step}`); - for (const file of matches.slice(0, 20)) - console.log(` ${file}`); -}); - -if (failed) { - console.error('\nThese files stay in the image even when a later layer deletes them.'); - console.error('Do not create them, or delete them in the RUN step that creates them.'); - process.exit(1); -} -console.log(`\nChecked ${layers.length} layer(s), found no forbidden files.`); - -/** - * Returns the layers of an unpacked "docker save" archive, bottom layer first. - * @returns {{ file: string, ours: boolean, step: string }[]} - */ -function readLayers(dir) { - const manifest = JSON.parse(fs.readFileSync(path.join(dir, 'manifest.json'), 'utf8'))[0]; - const config = JSON.parse(fs.readFileSync(path.join(dir, manifest.Config), 'utf8')); - // The history also has the steps that make no layer, such as ENV and ARG. - const steps = (config.history || []).filter(step => !step.empty_layer); - return manifest.Layers.map((file, i) => { - const step = steps[i] || {}; - // BuildKit puts the build arguments in front of a RUN command. Remove them. - const command = (step.created_by || '?').replace(/^RUN \|\d+ .*? \/bin\/sh -c /, 'RUN ').replace(/\s+/g, ' '); - return { - file, - // BuildKit marks the steps of the Dockerfile that it runs. The base image has no mark. - ours: (step.comment || '').includes('buildkit.dockerfile'), - step: command.length > 100 ? command.slice(0, 100) + '...' : command, - }; - }); -} - -/** - * Returns the paths of the files in a layer. tar reads both plain and compressed layers. - */ -function listLayerFiles(layerFile) { - const output = execFileSync('tar', ['-tf', layerFile], { encoding: 'utf8', maxBuffer: 1024 * 1024 * 1024 }); - return output.split('\n') - // Paths in a layer can start with "./". - .map(line => line.replace(/^\.\//, '')) - // Skip directory entries: an empty directory is not a problem. - .filter(line => line && !line.endsWith('/')); -} diff --git a/utils/docker/test_check_layers.sh b/utils/docker/test_check_layers.sh deleted file mode 100755 index a9c38423d..000000000 --- a/utils/docker/test_check_layers.sh +++ /dev/null @@ -1,75 +0,0 @@ -#!/usr/bin/env bash -set -e -set +x - -if [[ ($1 == '--help') || ($1 == '-h') ]]; then - echo "usage: $(basename $0)" - echo - echo "Test check_layers.js with two small images that this script builds." - echo - exit 0 -fi - -# The images that we publish are clean, so a build never sees check_layers.js fail. -# This test gives it an image with forbidden files, to know that it still finds them. - -SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd -P)" -TMP_DIR="$(mktemp -d)" - -function cleanup() { - rm -rf "${TMP_DIR}" - docker rmi -f playwright:check-layers-bad playwright:check-layers-good > /dev/null 2>&1 || true -} -trap cleanup EXIT - -cd "${TMP_DIR}" -echo "placeholder" > file - -# 1. Forbidden files in a lower layer must fail the check. -FORBIDDEN_FILES=( - root/.npm/_cacache/index-v5/aa/bb/cc - root/.npm/_logs/2026-01-01T00_00_00_000Z-debug-0.log - tmp/node-compile-cache/v26.0.0-x64/aabbcc - root/.yarn/berry/cache/a.zip - root/.m2/repository/com/example/a/1.0/a-1.0.jar - root/.cache/pip/http-v2/a/b/c - home/pwuser/.cache/virtualenv/a - src/.git/config -) -echo "FROM scratch" > Dockerfile.bad -for FORBIDDEN_FILE in "${FORBIDDEN_FILES[@]}"; do - echo "COPY file /${FORBIDDEN_FILE}" >> Dockerfile.bad -done -echo "COPY file /readme" >> Dockerfile.bad -docker build -q -t playwright:check-layers-bad -f Dockerfile.bad . > /dev/null -if node "${SCRIPT_DIR}/check_layers.js" playwright:check-layers-bad > output.txt 2>&1; then - cat output.txt - echo "FAILED: check_layers.js passed for an image with forbidden files in its layers" - exit 1 -fi -# The check must fail because it found the files, not because it crashed. -for FORBIDDEN_FILE in "${FORBIDDEN_FILES[@]}"; do - if ! grep -q -x -F " ${FORBIDDEN_FILE}" output.txt; then - cat output.txt - echo "FAILED: check_layers.js did not report ${FORBIDDEN_FILE}" - exit 1 - fi -done - -# 2. An image with no forbidden files must pass the check. Files that can hold -# a secret, such as .npmrc, pass too: the Trivy scan looks for secrets. -cat > Dockerfile.good <<'DOCKERFILE' -FROM scratch -COPY file /usr/local/lib/node_modules/npm/.npmrc -COPY file /etc/ssl/certs/ca.pem -COPY file /var/cache/fontconfig/aabbcc.cache-9 -COPY file /readme -DOCKERFILE -docker build -q -t playwright:check-layers-good -f Dockerfile.good . > /dev/null -if ! node "${SCRIPT_DIR}/check_layers.js" playwright:check-layers-good > output.txt 2>&1; then - cat output.txt - echo "FAILED: check_layers.js failed for an image with no forbidden files" - exit 1 -fi - -echo "PASSED: check_layers.js finds forbidden files and accepts a clean image"