def run_sync(args: Args, config: Config, *, resources: Path) -> None:
if os.getuid() == 0:
- os.setgroups(os.getgrouplist(INVOKING_USER.name(), INVOKING_USER.gid))
+ os.setgroups(INVOKING_USER.extra_groups())
os.setgid(INVOKING_USER.gid)
os.setuid(INVOKING_USER.uid)
import os
import pwd
import tempfile
+from collections.abc import Sequence
from pathlib import Path
from mkosi.log import die
def init(cls) -> None:
name = cls.name()
home = cls.home()
- logging.debug(f"Running as user '{name}' ({cls.uid}:{cls.gid}) with home {home}.")
+ extra_groups = cls.extra_groups()
+ logging.debug(
+ f"Running as user '{name}' ({cls.uid}:{cls.gid}) with home {home} "
+ f"and extra groups {extra_groups}."
+ )
@classmethod
def is_running_user(cls) -> bool:
def home(cls) -> Path:
return Path(f"~{cls.name()}").expanduser()
+ @classmethod
+ @functools.lru_cache(maxsize=1)
+ def extra_groups(cls) -> Sequence[int]:
+ return os.getgrouplist(cls.name(), cls.gid)
+
@classmethod
def is_regular_user(cls) -> bool:
return cls.uid >= 1000