Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shadow_utils: make shadow --root work by fake permissive mode #1313

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion mock/py/mockbuild/shadow_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"""

import grp
import os
import pwd
from mockbuild.file_util import mkdirIfAbsent
from mockbuild.util import do_with_status


Expand All @@ -13,16 +15,35 @@ class ShadowUtils:
"""
def __init__(self, root):
self.root = root
self._selinux_workaround_applied = False

def _selinux_workaround(self):
"""
Work-around for:
https://github.com/shadow-maint/shadow/issues/940
https://github.com/SELinuxProject/selinux/issues/419
"""
if self._selinux_workaround_applied:
return

path = self.root.make_chroot_path("/sys/fs/selinux")
mkdirIfAbsent(path)
file = os.path.join(path, "enforce")
with open(file, "w", encoding="utf-8") as fd:
fd.write("0")
self._selinux_workaround_applied = True

def _execute_command(self, command, can_fail=False):
self._selinux_workaround()

with self.root.uid_manager.elevated_privileges():
# Ordinarily we do not want to depend on shadow-utils in the buildroot, but
# configuring certain options (such as FreeIPA-provided subids) can make it
# impossible to create users in the buildroot using host shadow-utils so we
# provide this workaround.
# Tracking upstream bug https://github.com/shadow-maint/shadow/issues/897
if self.root.config['use_host_shadow_utils']:
do_with_status(command + ['--prefix', self.root.make_chroot_path()], raiseExc=not can_fail)
do_with_status(command + ['--root', self.root.make_chroot_path()], raiseExc=not can_fail)
else:
self.root.doChroot(command, raiseExc=not can_fail)

Expand Down
Loading