diff options
| author | Michal Nasiadka <mnasiadka@gmail.com> | 2023-03-16 10:04:47 +0000 |
|---|---|---|
| committer | Michal Nasiadka <mnasiadka@gmail.com> | 2023-03-17 09:09:35 +0000 |
| commit | 3d008b7f5ec2a54d004e8e9370f303ef9dc7858b (patch) | |
| tree | 3752fa4bd32b4523f8ca1380b06a63c13f161689 /kolla/tests | |
| parent | 12d431e3994023ce735a2352554a99a5cc9431c9 (diff) | |
| download | kolla-3d008b7f5ec2a54d004e8e9370f303ef9dc7858b.tar.gz kolla-3d008b7f5ec2a54d004e8e9370f303ef9dc7858b.zip | |
Test for unsafe files in tarfile.extractall
In addition to that, mark bifrost unbuildable since it's
failing on EPEL 9 enablement.
Closes-Bug: #1990432
Change-Id: I650fcbc8f773fad8116338f6fb0cf7b4f4f17b33
Diffstat (limited to 'kolla/tests')
| -rw-r--r-- | kolla/tests/test_build.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/kolla/tests/test_build.py b/kolla/tests/test_build.py index a4784ba86..ce7896da5 100644 --- a/kolla/tests/test_build.py +++ b/kolla/tests/test_build.py @@ -14,6 +14,8 @@ import fixtures import os import requests import sys +import tarfile +import tempfile from unittest import mock from kolla.cmd import build as build_cmd @@ -289,6 +291,46 @@ class TasksTest(base.TestCase): else: self.assertIsNotNone(get_result) + @mock.patch.dict(os.environ, clear=True) + @mock.patch('docker.APIClient') + def test_malicious_tar(self, mock_client): + tmpdir = tempfile.mkdtemp() + file_name = 'test.txt' + archive_name = 'my_archive.tar.gz' + file_path = os.path.join(tmpdir, file_name) + archive_path = os.path.join(tmpdir, archive_name) + # Ensure the file is read/write by the creator only + saved_umask = os.umask(0o077) + + try: + with open(file_path, 'w') as f: + f.write('Hello') + + with tarfile.open(archive_path, 'w:gz') as tar: + tar.add(file_path, arcname='../test.txt') + + self.dc = mock_client + self.image.plugins = [{ + 'name': 'fake-image-base-plugin-test', + 'type': 'local', + 'enabled': True, + 'source': archive_path} + ] + + push_queue = mock.Mock() + builder = tasks.BuildTask(self.conf, self.image, push_queue) + builder.run() + self.assertFalse(builder.success) + + except IOError: + print('IOError') + else: + os.remove(file_path) + os.remove(archive_path) + finally: + os.umask(saved_umask) + os.rmdir(tmpdir) + @mock.patch('os.path.exists') @mock.patch('os.utime') @mock.patch('shutil.rmtree') |
