Skip to content

Commit

Permalink
util: set group:user on extracted tar members
Browse files Browse the repository at this point in the history
Set the gid:uid on the tar file members as we extract them from
the build archive, so they are owned by a real user in both the
container and on the host.

Signed-off-by: Eric Fahlgren <[email protected]>
  • Loading branch information
efahl authored and aparcar committed Oct 8, 2024
1 parent f9f8618 commit 54b8cfe
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions asu/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import json
import logging
import struct
from os import getuid, getgid
from pathlib import Path
from re import match
from tarfile import TarFile
Expand Down Expand Up @@ -119,7 +120,7 @@ def get_request_hash(build_request: BuildRequest) -> str:
Creates a reproducible hash of the request by sorting the arguments
Args:
req (dict): dict contianing request information
req (dict): dict containing request information
Returns:
str: hash of `req`
Expand Down Expand Up @@ -185,7 +186,7 @@ def verify_usign(sig_file: Path, msg_file: Path, pub_key: str) -> bool:
pub_key (str): public key to use for verification
Returns:
bool: Sucessfull verification
bool: Successful verification
Todo:
Currently ignores keynum and pkalg
Expand Down Expand Up @@ -270,10 +271,13 @@ def run_cmd(
host_tar.write(data)
host_tar.flush()

tar_file = TarFile(host_tar.name)
tar_file.extractall(copy[1])

host_tar.close()
with TarFile(host_tar.name) as tar_file:
for member in tar_file:
# Fix the owner of the copied files, change to "us".
member.uid = getuid()
member.gid = getgid()
member.mode = 0o755 if member.isdir() else 0o644
tar_file.extractall(copy[1])
logging.debug(f"Closed {host_tar}")

return returncode, stdout, stderr
Expand Down

0 comments on commit 54b8cfe

Please sign in to comment.