-
Notifications
You must be signed in to change notification settings - Fork 251
shadow_utils: make shadow --root work by fake permissive mode #1313
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
Draft
praiskup
wants to merge
1
commit into
rpm-software-management:main
Choose a base branch
from
praiskup:praiskup-shadow-utils-root
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,9 @@ | |
| """ | ||
|
|
||
| import grp | ||
| import os | ||
| import pwd | ||
| from mockbuild.file_util import mkdirIfAbsent | ||
| from mockbuild.util import do_with_status | ||
|
|
||
|
|
||
|
|
@@ -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) | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ... but we'll have to continue using |
||
| else: | ||
| self.root.doChroot(command, raiseExc=not can_fail) | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the fix from shadow-maint/shadow#1258 gets released, we no longer need the
_selinux_workaround().