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.
Bug 2072426 - restorecon fails to apply to user ssh directory after creating key
Summary: restorecon fails to apply to user ssh directory after creating key
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 9
Classification: Red Hat
Component: anaconda
Version: 9.0
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: rc
: ---
Assignee: Vladimír Slávik
QA Contact: Release Test Team
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2022-04-06 09:39 UTC by Jiri Konecny
Modified: 2022-11-15 10:29 UTC (History)
8 users (show)

Fixed In Version: anaconda-34.25.1.3-1.el9
Doc Type: If docs needed, set a value
Doc Text:
Clone Of: 2069305
Environment:
Last Closed: 2022-11-15 09:58:14 UTC
Type: Bug
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Issue Tracker RHELPLAN-118030 0 None None None 2022-04-06 09:54:30 UTC
Red Hat Issue Tracker RTT-4449 0 None None None 2022-05-06 18:43:37 UTC
Red Hat Issue Tracker RTT-4450 0 None Closed Differences Update-info RedHat Subscriptions Page and OS 2022-06-27 12:11:47 UTC
Red Hat Product Errata RHBA-2022:7977 0 None None None 2022-11-15 09:58:32 UTC

Description Jiri Konecny 2022-04-06 09:39:32 UTC
+++ This bug was initially created as a clone of Bug #2069305 +++

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.

--- Additional comment from Jiri Konecny on 2022-03-29 18:39:39 UTC ---

We should make sure that we are running restorecon always in the chroot.

--- Additional comment from Vladimír Slávik on 2022-03-30 10:03:24 UTC ---

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.

--- Additional comment from Vladimír Slávik on 2022-03-30 13:43:08 UTC ---

Upstream PR: https://github.com/rhinstaller/anaconda/pull/3993

--- Additional comment from Achilleas Koutsou on 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.

Comment 2 Vladimír Slávik 2022-05-17 19:27:39 UTC
https://github.com/rhinstaller/anaconda/pull/4110

Comment 6 Jan Stodola 2022-05-27 14:26:08 UTC
Checked that anaconda-34.25.1.3-1.el9 is in nightly compose RHEL-9.1.0-20220527.0

Moving to VERIFIED

Comment 8 errata-xmlrpc 2022-11-15 09:58:14 UTC
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:7977


Note You need to log in before you can comment on or make changes to this bug.