Skip to content

fix: reload uidManager with chrootuid/chrootgid from config#1752

Merged
praiskup merged 1 commit into
rpm-software-management:mainfrom
praiskup:praiskup-issue-1731-chrootuid-fix
May 14, 2026
Merged

fix: reload uidManager with chrootuid/chrootgid from config#1752
praiskup merged 1 commit into
rpm-software-management:mainfrom
praiskup:praiskup-issue-1731-chrootuid-fix

Conversation

@praiskup

Copy link
Copy Markdown
Member

The uidManager was initialized before config was loaded, so it always used the calling user's UID/GID for privilege dropping. When config specifies a different chrootuid/chrootgid, the uidManager needs to be reloaded with those values — otherwise operations run under the wrong identity, leading to permission errors in the chroot.

Move uidManager initialization after command_parse() (which doesn't need to drop privileges) and reload it with chrootuid/chrootgid from config_opts right after config is loaded (loaded with dropped privileges).

Fixes: #1731

Assisted-By: Claude Code (claude-opus-4-6)

@praiskup

Copy link
Copy Markdown
Member Author

/packit test

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request ensures that the uidManager is reloaded with the chrootuid and chrootgid specified in the configuration, rather than always using the calling user's identity. This involves moving the UID manager initialization and adding a new reload_uidmanager function. Review feedback pointed out that the new function and its variables should follow the project's snake_case naming convention and that the docstring should adhere to the Google style guide.

Comment thread mock/py/mockbuild/uid.py Outdated
Comment on lines +45 to +49
def reload_uidmanager(uidmanager, config_opts):
"""Re-create UidManager with chrootuid/chrootgid from config."""
unprivuid = config_opts["chrootuid"]
unprivgid = config_opts.get("chrootgid", uidmanager.unprivGid)
return UidManager(unprivuid, unprivgid)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The function name reload_uidmanager and its internal variables unprivuid/unprivgid do not adhere to the project's naming conventions. Additionally, the docstring should follow the Google style for consistency with the rest of the project.

  • Naming: Use snake_case for functions and variables (e.g., reload_uid_manager, unpriv_uid).
  • Docstrings: Include Args and Returns sections as per Google style.
def reload_uid_manager(uid_manager, config_opts):
    """Re-create UidManager with chrootuid/chrootgid from config.

    Args:
        uid_manager (UidManager): The current UID manager instance.
        config_opts (dict): Configuration options containing chrootuid and optionally chrootgid.

    Returns:
        UidManager: A new UidManager instance initialized with the configured IDs.
    """
    unpriv_uid = config_opts["chrootuid"]
    unpriv_gid = config_opts.get("chrootgid", uid_manager.unprivGid)
    return UidManager(unpriv_uid, unpriv_gid)
References
  1. Functions should use lowercase with underscores (snake_case). (link)
  2. Variables should use lowercase with underscores (snake_case). (link)
  3. Use Google style docstrings for all docstrings. (link)

Comment thread mock/py/mock.py
Comment thread mock/py/mock.py Outdated
The uidManager was initialized before config was loaded, so it always
used the calling user's UID/GID for privilege dropping.  When config
specifies a different chrootuid/chrootgid, the uidManager needs to be
reloaded with those values — otherwise operations run under the wrong
identity, leading to permission errors in the chroot.

Move uidManager initialization after command_parse() (which doesn't need
to drop privileges) and reload it with chrootuid/chrootgid from
config_opts right after config is loaded (loaded with dropped
privileges).

Fixes: rpm-software-management#1731

Assisted-By: Claude Code (claude-opus-4-6)
@praiskup praiskup force-pushed the praiskup-issue-1731-chrootuid-fix branch from 9000530 to c1b5471 Compare May 12, 2026 19:17

@xsuchy xsuchy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@praiskup praiskup merged commit b50cda1 into rpm-software-management:main May 14, 2026
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

config_opts['chrootuid'] with --isolation=simple stopped working

2 participants