Skip to content

Commit b80d475

Browse files
committed
Fix local sources of git repositories
This is I2cbf1f539880d512aa223c3ef3a4b19ee18854ac extended to fix the case when a git repository is used with a git repo. This is probably a rarer use case but, still, we use it in CI for in-review changes testing. Change-Id: I77b0dcd2e9dfd8ea8390a471b80c8954b67ef91b (cherry picked from commit b888f68)
1 parent 6cf2912 commit b80d475

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

kolla/image/build.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,15 @@ def process_source(self, image, source):
367367

368368
dest_archive = os.path.join(image.path, source['name'] + '-archive')
369369

370+
# NOTE(mgoddard): Change ownership of files to root:root. This
371+
# avoids an issue introduced by the fix for git CVE-2022-24765,
372+
# which breaks PBR when the source checkout is not owned by the
373+
# user installing it. LP#1969096
374+
def reset_userinfo(tarinfo):
375+
tarinfo.uid = tarinfo.gid = 0
376+
tarinfo.uname = tarinfo.gname = "root"
377+
return tarinfo
378+
370379
if source.get('type') == 'url':
371380
self.logger.debug("Getting archive from %s", source['source'])
372381
try:
@@ -411,15 +420,6 @@ def process_source(self, image, source):
411420
image.status = Status.ERROR
412421
return
413422

414-
# NOTE(mgoddard): Change ownership of files to root:root. This
415-
# avoids an issue introduced by the fix for git CVE-2022-24765,
416-
# which breaks PBR when the source checkout is not owned by the
417-
# user installing it. LP#1969096
418-
def reset_userinfo(tarinfo):
419-
tarinfo.uid = tarinfo.gid = 0
420-
tarinfo.uname = tarinfo.gname = "root"
421-
return tarinfo
422-
423423
with tarfile.open(dest_archive, 'w') as tar:
424424
tar.add(clone_dir, arcname=os.path.basename(clone_dir),
425425
filter=reset_userinfo)
@@ -430,7 +430,8 @@ def reset_userinfo(tarinfo):
430430
if os.path.isdir(source['source']):
431431
with tarfile.open(dest_archive, 'w') as tar:
432432
tar.add(source['source'],
433-
arcname=os.path.basename(source['source']))
433+
arcname=os.path.basename(source['source']),
434+
filter=reset_userinfo)
434435
else:
435436
shutil.copyfile(source['source'], dest_archive)
436437

0 commit comments

Comments
 (0)