Skip to content

Commit 8ffdee9

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 444bdff commit 8ffdee9

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
@@ -388,6 +388,15 @@ def followups(self):
388388
def process_source(self, image, source):
389389
dest_archive = os.path.join(image.path, source['name'] + '-archive')
390390

391+
# NOTE(mgoddard): Change ownership of files to root:root. This
392+
# avoids an issue introduced by the fix for git CVE-2022-24765,
393+
# which breaks PBR when the source checkout is not owned by the
394+
# user installing it. LP#1969096
395+
def reset_userinfo(tarinfo):
396+
tarinfo.uid = tarinfo.gid = 0
397+
tarinfo.uname = tarinfo.gname = "root"
398+
return tarinfo
399+
391400
if source.get('type') == 'url':
392401
self.logger.debug("Getting archive from %s", source['source'])
393402
try:
@@ -432,15 +441,6 @@ def process_source(self, image, source):
432441
image.status = Status.ERROR
433442
return
434443

435-
# NOTE(mgoddard): Change ownership of files to root:root. This
436-
# avoids an issue introduced by the fix for git CVE-2022-24765,
437-
# which breaks PBR when the source checkout is not owned by the
438-
# user installing it. LP#1969096
439-
def reset_userinfo(tarinfo):
440-
tarinfo.uid = tarinfo.gid = 0
441-
tarinfo.uname = tarinfo.gname = "root"
442-
return tarinfo
443-
444444
with tarfile.open(dest_archive, 'w') as tar:
445445
tar.add(clone_dir, arcname=os.path.basename(clone_dir),
446446
filter=reset_userinfo)
@@ -451,7 +451,8 @@ def reset_userinfo(tarinfo):
451451
if os.path.isdir(source['source']):
452452
with tarfile.open(dest_archive, 'w') as tar:
453453
tar.add(source['source'],
454-
arcname=os.path.basename(source['source']))
454+
arcname=os.path.basename(source['source']),
455+
filter=reset_userinfo)
455456
else:
456457
shutil.copyfile(source['source'], dest_archive)
457458

0 commit comments

Comments
 (0)