Skip to content

Commit 535b809

Browse files
authored
Merge pull request #214 from stackhpc/upstream/yoga-2023-04-10
Synchronise yoga with upstream
2 parents 7ee6f2f + feb5d46 commit 535b809

File tree

3 files changed

+74
-1
lines changed

3 files changed

+74
-1
lines changed

docker/base/curlrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
--fail
33
--location
44
--retry 5
5+
--retry-all-errors
56
--silent
67
--show-error
78
--write-out "curl (%{url_effective}): response: %{http_code}, time: %{time_total}, size: %{size_download}\n"

kolla/image/build.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ def update_buildargs(self):
502502
def builder(self, image):
503503

504504
def _test_malicious_tarball(archive, path):
505-
tar_file = tarfile.open(archive, 'r|gz')
505+
tar_file = tarfile.open(archive, 'r|*')
506506
for n in tar_file.getnames():
507507
if not os.path.abspath(os.path.join(path, n)).startswith(path):
508508
tar_file.close()

kolla/tests/test_build.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,9 +305,81 @@ def test_process_source(self, mock_get, mock_client,
305305
else:
306306
self.assertIsNotNone(get_result)
307307

308+
@mock.patch.dict(os.environ, clear=True)
309+
@mock.patch('docker.APIClient')
310+
def test_local_directory(self, mock_client):
311+
tmpdir = tempfile.mkdtemp()
312+
file_name = 'test.txt'
313+
file_path = os.path.join(tmpdir, file_name)
314+
saved_umask = os.umask(0o077)
315+
316+
try:
317+
with open(file_path, 'w') as f:
318+
f.write('Hello')
319+
320+
self.dc = mock_client
321+
self.image.plugins = [{
322+
'name': 'fake-image-base-plugin-test',
323+
'type': 'local',
324+
'enabled': True,
325+
'source': tmpdir}
326+
]
327+
push_queue = mock.Mock()
328+
builder = build.BuildTask(self.conf, self.image, push_queue)
329+
builder.run()
330+
self.assertTrue(builder.success)
331+
332+
except IOError:
333+
print('IOError')
334+
else:
335+
os.remove(file_path)
336+
finally:
337+
os.umask(saved_umask)
338+
os.rmdir(tmpdir)
339+
308340
@mock.patch.dict(os.environ, clear=True)
309341
@mock.patch('docker.APIClient')
310342
def test_malicious_tar(self, mock_client):
343+
tmpdir = tempfile.mkdtemp()
344+
file_name = 'test.txt'
345+
archive_name = 'my_archive.tar'
346+
file_path = os.path.join(tmpdir, file_name)
347+
archive_path = os.path.join(tmpdir, archive_name)
348+
# Ensure the file is read/write by the creator only
349+
saved_umask = os.umask(0o077)
350+
351+
try:
352+
with open(file_path, 'w') as f:
353+
f.write('Hello')
354+
355+
with tarfile.open(archive_path, 'w') as tar:
356+
tar.add(file_path, arcname='../test.txt')
357+
358+
self.dc = mock_client
359+
self.image.plugins = [{
360+
'name': 'fake-image-base-plugin-test',
361+
'type': 'local',
362+
'enabled': True,
363+
'source': archive_path}
364+
]
365+
366+
push_queue = mock.Mock()
367+
builder = build.BuildTask(self.conf, self.image, push_queue)
368+
builder.run()
369+
self.assertFalse(builder.success)
370+
371+
except IOError:
372+
print('IOError')
373+
else:
374+
os.remove(file_path)
375+
os.remove(archive_path)
376+
finally:
377+
os.umask(saved_umask)
378+
os.rmdir(tmpdir)
379+
380+
@mock.patch.dict(os.environ, clear=True)
381+
@mock.patch('docker.APIClient')
382+
def test_malicious_tar_gz(self, mock_client):
311383
tmpdir = tempfile.mkdtemp()
312384
file_name = 'test.txt'
313385
archive_name = 'my_archive.tar.gz'

0 commit comments

Comments
 (0)