conda / conda-package-streaming

An efficient library to read from new and old format .conda and .tar.bz2 conda packages.
https://conda.github.io/conda-package-streaming/
Other
10 stars 9 forks source link

override TarFile.chown() instead of post-facto restoring owner to 0 #28

Closed dholth closed 2 years ago

dholth commented 2 years ago

conda-package-streaming uses this code from conda to make sure packages extracted as root are owned by root, and not by whatever the tarfile said. Instead, subclass TarFile and override chown() to be a no-op, or, replace each member's uid/gid with os.geteuid() as part of the safety filter. (Overriding Tarfile should be a little faster, since we can avoid chowning at all).

    if sys.platform.startswith("linux") and os.getuid() == 0:
        # When extracting as root, tarfile will by restore ownership
        # of extracted files.  However, we want root to be the owner
        # (our implementation of --no-same-owner).

        # XXX we could only chown collected names from checked_members()
        for root, _, files in os.walk(dest_dir):
            for fn in files:
                p = os.path.join(root, fn)
                os.lchown(p, 0, 0)
dholth commented 2 years ago

Fixed in https://github.com/conda-incubator/conda-package-streaming/commit/bc8e2fd7d9f1ab0a2168ad370b048c7346e88637