Skip to content

Commit c0b26d0

Browse files
authored
Merge pull request #1084 from GitGuardian/severine/handle-tar-gz-in-docker-images
fix: let tarfile auto-detect archive type
2 parents d68cb5c + 440d59f commit c0b26d0

File tree

5 files changed

+13
-2
lines changed

5 files changed

+13
-2
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### Fixed
2+
3+
- Fixed error when scanning `.tar.gz` compressed files inside docker layers.

ggshield/verticals/secret/docker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ def get_layer_scannables(
241241
Extracts Scannable to be scanned for given layer.
242242
"""
243243
layer_filename = layer_info.filename
244-
layer_archive = tarfile.TarFile(
244+
layer_archive = tarfile.open(
245245
name=self.archive_path / layer_filename,
246246
fileobj=self.tar_file.extractfile(layer_filename),
247247
)

tests/unit/conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,7 @@ def is_macos():
592592
DOCKER__INCOMPLETE_MANIFEST_EXAMPLE_PATH = (
593593
DATA_PATH / "docker-incomplete-manifest-example.tar.xz"
594594
)
595+
DOCKER_EXAMPLE_TAR_GZ_LAYER_PATH = DATA_PATH / "docker-tar-gz-layer.tar.xz"
595596

596597
# Format is { layer_id: { path: content }}
597598
DOCKER_EXAMPLE_LAYER_FILES = {
2.01 KB
Binary file not shown.

tests/unit/verticals/secret/test_scan_docker.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
DOCKER__INCOMPLETE_MANIFEST_EXAMPLE_PATH,
2121
DOCKER_EXAMPLE_LAYER_FILES,
2222
DOCKER_EXAMPLE_PATH,
23+
DOCKER_EXAMPLE_TAR_GZ_LAYER_PATH,
2324
)
2425

2526

@@ -83,7 +84,13 @@ def test_get_config(self, members, match):
8384
DockerImage(Path("dummy"), tarfile)
8485

8586
@pytest.mark.parametrize(
86-
"image_path", [DOCKER_EXAMPLE_PATH, DOCKER__INCOMPLETE_MANIFEST_EXAMPLE_PATH]
87+
"image_path",
88+
[
89+
DOCKER_EXAMPLE_PATH,
90+
DOCKER__INCOMPLETE_MANIFEST_EXAMPLE_PATH,
91+
# 1 of the layers contains a tar.gz file -> extraction should work
92+
DOCKER_EXAMPLE_TAR_GZ_LAYER_PATH,
93+
],
8794
)
8895
def test_docker_archive(self, image_path: Path):
8996
with DockerImage.open(image_path) as image:

0 commit comments

Comments
 (0)