Bug 1995840

Summary: [cloudinit] Fix home permissions modified by ssh module
Product: Red Hat Enterprise Linux 8 Reporter: Emanuele Giuseppe Esposito <eesposit>
Component: cloud-initAssignee: Emanuele Giuseppe Esposito <eesposit>
Status: CLOSED ERRATA QA Contact: xiachen
Severity: medium Docs Contact:
Priority: medium    
Version: 8.5CC: eesposit, eterrell, huzhao, jgreguske, lmiksik, ribarry, rlandy, xiachen, xiliang, yacao
Target Milestone: betaKeywords: Triaged
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: cloud-init-21.1-7.el8 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 1995843 (view as bug list) Environment:
Last Closed: 2021-11-09 18:48:55 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1995843    

Description Emanuele Giuseppe Esposito 2021-08-19 21:59:12 UTC
Description of problem:

In upstream PR #956 and BZ 1862967, we updated the file and directory permissions for keys not in
the user's home directory. We also unintentionally modified the
owner within the home directory as well to root, but only when the file/folders specified in AuthorizedKeysFile don't exist. This is okay and still allows ssh login, but not ideal for other ssh components. For example, if cloud-init creates the .ssh folder in /home/user/, the owner of .ssh will be root and ssh-keygen won't allow to create ssh keys in that folder.

LP: #1940233

Version-Release number of selected component (if applicable):
cloud-init-21.1-6.el8

How reproducible:
always

Steps to Reproduce:

1. Use standard AuthorizedKeysFile: 
# cat /etc/ssh/sshd_config | grep AuthorizedKeysFile
AuthorizedKeysFile .ssh/authorized_keys
2. Remove ~/.ssh
3. Remove /var/lib/cloud/instance/sem/config_ssh
4. systemctl restart cloud-init ; systemctl restart sshd
5. Try to ssh login through the cloud-init created user, login is fine
6. run ssh-keygen and save the key in /home/<user>/.ssh

Actual results:
ssh-keygen gives Permission denied on the .ssh folder
This is because the owner of .ssh is root.

Expected results:
ssh-keygen creates the keys, and .ssh is owned by the user

Comment 23 xiachen 2021-09-09 03:47:21 UTC
*** Bug 2000664 has been marked as a duplicate of this bug. ***

Comment 25 errata-xmlrpc 2021-11-09 18:48:55 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 (cloud-init 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/RHEA-2021:4294