Note: This bug is displayed in read-only format because
the product is no longer active in Red Hat Bugzilla.
RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
DescriptionAchilleas Koutsou
2022-03-28 16:49:43 UTC
Description of problem:
When creating a user with a public ssh key through kickstart, the final restorecon call has no effect, possibly because it's run against the mounted sysroot (Current RHEL 8.6 HEAD: https://github.com/rhinstaller/anaconda/blob/858d941ad2d299b4db44ee1ad99e2e2005c690e5/pyanaconda/core/users.py#L528)
This usually has no effect other than a warning in the syslog
> WARNING org.fedoraproject.Anaconda.Modules.Users:INFO:program:Warning no default label for /mnt/sysroot/home/achilleas/.ssh
However, in some cases, if the home or .ssh directory doesn't have the correct label on creation, the lack of a successful restorecon can cause issues.
How reproducible:
Always
Steps to Reproduce:
1. Create a kickstart file with a user configuration and an sshkey:
> user --name admin --password $6$GRmb7S0p8vsYmXzH$o0E020S.9JQGaHkszoog4ha4AQVs3sk8q0DvLjSMxoxHBKnB2FBXGQ/OkwZQfW/76ktHd0NX5nls2LPxPuUdl. --iscrypted --groups wheel --homedir /home/admin/
> sshkey --username admin ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIL0AMjiKC8UTxZWLhCxtSZLfKPumUVdHUehCsOXiae/P admin@test
2. Serve or embed the kickstart file in the iso
3. Boot the iso and modify the kernel cmdline parameters with 'inst.ks=<kickstart file location>'
4. Start and complete the installation
5. Check the syslog for the warning message
Actual results:
> WARNING org.fedoraproject.Anaconda.Modules.Users:INFO:program:Warning no default label for /mnt/sysroot/home/achilleas/.ssh
appears in the log
If the home directory is not labelled properly on creation, the home and .ssh directories have the following selinux contexts:
> unconfined_u:object_r:default_t:s0
Expected results:
The warning should not appear in the log (the restorecon should be successful).
The home directory and .ssh directories should have the following selinux contexts:
For home directory:
> unconfined_u:object_r:user_home_dir_t:s0
and for .ssh
> system_u:object_r:ssh_home_t:s0
Additional info:
In all my tests I was using installer ISOs built using osbuild/imagebuilder that install using a tarball and include the liveimg directive in the kickstart file. I don't know if this is relevant, but I didn't include it in the steps above.
In RHEL 8.6, there is a bug in useradd of the shadow-utils package that fails to label the home directory with the proper selinux contexts if the home directory has a trailing slash (as in the example above).
This isn't an Anaconda bug, but it's an example of how the restorecon failure can cause side-effects. After installation, the system is inaccessible through SSH, because sshd can't read the authorized_keys file for the user with the mislabelled home directory.
So, this is in set_user_ssh_key() and create_user() on rhel-8, or set_user_ssh_key() and _reown_homedir() on master. We do util.execWithRedirect("restorecon", ["-r", <something>]), which is wrong.
Looks like it was originally added with 911f99f834eb31cc2fbbcb23c2cb40d05a68c610 and the other place with 5e238e89882171e66c43be1bdc16d5a9183f585b in response to bug 1087736. Apparently nobody ever noticed that this does not work, or that it stopped working somewhere along the way. We just refactored it a few times since then...
It looks like these things run when creating users, which is after payload installation, so simply adding the sysroot parameter to the calls should be enough.
Comment 4Achilleas Koutsou
2022-04-04 08:37:29 UTC
A note about RHEL 9.0:
The bug in Anaconda also exists in RHEL 9.0, the restorecon run uses the full path and not a chroot so the call has no effect. However, the way it doesn't cause the issue I saw because useradd labels the home directory correctly.
There may be other scenarios where the failure to relabel does cause problems though.
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.
For information on the advisory (anaconda bug fix and enhancement update), and where to find the updated
files, follow the link below.
If the solution does not work for you, open a new bug report.
https://access.redhat.com/errata/RHBA-2022:7462