Skip to content

Commit 7fb3ecb

Browse files
Marcin Juszkiewiczmarkgoddard
authored andcommitted
Fix image builds with sources using a type=git
A recent change to git [1] introduced a new behaviour to work around a CVE [2] that disallows any git operations in directories not owned by the current user. This may seem unrelated to installation, but it plays havoc with PBR, which calls out to git to get to get revision history. So if you are "pip install"-ing from a source tree you don't own, the PBR git calls in that tree now fail and the install blows up. When using type=source, kolla clones the repository, then creates a tarball from it, which is ADDed to the image. The ownership of the files in the tarball is preserved, which in this case will be the user running kolla-build. Since the Docker build runs as root, we hit the PBR issue. Our solution is to make sure that any tarball we generate from git sources have all files owned by root:root so that the root user is able to use git commands when building container images. [1] git/git@8959555 [2] https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2022-24765. Closes-Bug: #1969096 Related-Bug: #1968877 Co-Authored-By: Mark Goddard <[email protected]> Change-Id: I2cbf1f539880d512aa223c3ef3a4b19ee18854ac (cherry picked from commit c4fda7b)
1 parent 3567973 commit 7fb3ecb

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

kolla/image/build.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,8 +431,18 @@ def process_source(self, image, source):
431431
image.status = Status.ERROR
432432
return
433433

434+
# NOTE(mgoddard): Change ownership of files to root:root. This
435+
# avoids an issue introduced by the fix for git CVE-2022-24765,
436+
# which breaks PBR when the source checkout is not owned by the
437+
# user installing it. LP#1969096
438+
def reset_userinfo(tarinfo):
439+
tarinfo.uid = tarinfo.gid = 0
440+
tarinfo.uname = tarinfo.gname = "root"
441+
return tarinfo
442+
434443
with tarfile.open(dest_archive, 'w') as tar:
435-
tar.add(clone_dir, arcname=os.path.basename(clone_dir))
444+
tar.add(clone_dir, arcname=os.path.basename(clone_dir),
445+
filter=reset_userinfo)
436446

437447
elif source.get('type') == 'local':
438448
self.logger.debug("Getting local archive from %s",
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
fixes:
3+
- |
4+
Fixes an issue building images that use a source with a ``type`` of
5+
``git``, when using a git that includes the fix for `CVE-2022-24765
6+
<https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2022-24765>`__ (2.35.2
7+
or later). By default, this includes the ``gnocchi-base`` image, but may
8+
include other images with a non-default configuration. `LP#837710
9+
<https://review.opendev.org/c/openstack/kolla/+/837710>`__

0 commit comments

Comments
 (0)