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 1777718 - default umask for sshd process is 0077
Summary: default umask for sshd process is 0077
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 8
Classification: Red Hat
Component: shadow-utils
Version: 8.1
Hardware: Unspecified
OS: Unspecified
medium
unspecified
Target Milestone: rc
: 8.0
Assignee: Iker Pedrosa
QA Contact: sssd-qe
URL:
Whiteboard: sync-to-jira
: 1833664 (view as bug list)
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2019-11-28 07:10 UTC by adam winberg
Modified: 2024-10-01 16:24 UTC (History)
9 users (show)

Fixed In Version: shadow-utils-4.6-11.el8
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2020-11-04 01:42:09 UTC
Type: Bug
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Issue Tracker SSSD-2658 0 None None None 2023-12-01 20:06:16 UTC
Red Hat Issue Tracker SSSD-2675 0 None None None 2023-12-01 20:06:06 UTC
Red Hat Product Errata RHBA-2020:4467 0 None None None 2020-11-04 01:42:14 UTC

Description adam winberg 2019-11-28 07:10:09 UTC
Description of problem:
The sshd user process gets a umask of 0077 which is different compared to RHEL7 where the umask is 0022. 


$ ps aux | grep sshd
root        787  0.0  0.0 112920  2828 ?        Ss   Sep11   1:17 /usr/sbin/sshd -D
root     101531  0.0  0.0 192032  4124 ?        Ss   Nov27   0:00 sshd: a001329 [priv]

The main sshd process (787, owned by root) has an umask of 0022. But the spawned user process has an umask of 0077. 

This causes some problems in transitioning from RHEL7 to RHEL8. 

This can be resolved by the user by adding an 'umask' statement in the users .bashrc - but that requires an action from our users which we would like to avoid. 

I can change the sshd umask by changing the 'UMASK' value in /etc/login.defs which by default is 077. But it is 077 in RHEL7 as well, so while this would restore the behaviour of sshd it would change the behaviour of other programs compared to RHEL7. 

So, what is the recommended way to change the umask of sshd and why has it changed from RHEL7 to RHEL8?

Version-Release number of selected component (if applicable):
openssh-8.0p1-3.el8.x86_64

How reproducible:
Always

Steps to Reproduce:
1. make sure your user has no .bashrc
2. ssh <rhel8-box> umask
3.

Actual results:
0077

Expected results:
0022

Additional info:

Comment 1 Jakub Jelen 2019-11-28 09:42:14 UTC
On my recently installed RHEL8 without any significant modifications I see the following:

[root@localhost ~]# ssh tester@localhost umask
tester@localhost's password: 
0002
[root@localhost ~]# ssh root@localhost umask
root@localhost's password: 
0022
[root@localhost ~]# rpm -q openssh
openssh-8.0p1-3.el8.x86_64
[root@localhost ~]# grep root /etc/passwd
root:x:0:0:root:/root:/bin/bash
[root@localhost ~]# grep tester /etc/passwd
tester:x:1000:1000:Tester:/home/tester:/bin/bash

This sounds like there is something in the way changing this for you, but it does not sound like default nor anything inside of openssh. Can you try with fresh RHEL8 without any modifications, whether you can reproduce my observations? Assuming you are using bash and password authentication. If you use something else, please clarify.

Comment 2 adam winberg 2019-11-28 09:48:19 UTC
Do you have a '.bashrc' file for your user? 

I think local users gets one by default, which includes:

# Source global definitions
if [ -f /etc/bashrc ]; then
	. /etc/bashrc
fi


But our users are from AD with NFS mounted home directory, so they have no .bashrc since they've had no need for it. 

So please test again without sourcing /etc/bashrc.

Comment 3 Jakub Jelen 2019-11-28 10:28:58 UTC
You are right. Without the default I can see the same behavior as you. But this umask is not set by sshd, but (most probably) in the pam stack as /etc/pam.d/postlogin contains the pam_umask module and it pulls this value from /etc/login.defs to have for all logins systematic umasks. This was not in RHEL7 so it did not have to be completely systematic in the past.

I will reassign this to authselect, which generates these pam stacks for you and they will hopefully have better idea behind the reasoning why this was introduced. But I think the correct way is to change this system-wide in login.defs. If you want different values for sshd, you can modify sshd pam stack to overwrite the umask to something else.

[root@localhost ~]# rm /home/tester/.bashrc
rm: remove regular file '/home/tester/.bashrc'? y
[root@localhost ~]# ssh tester@localhost umask
tester@localhost's password: 
0077
[root@localhost ~]# grep umask /etc/pam.d/postlogin
#session optional                   pam_umask.so silent
[root@localhost ~]# ssh tester@localhost umask
tester@localhost's password: 
0022

Comment 4 adam winberg 2019-11-28 10:47:49 UTC
ah, thank you - its in the postlogin, then I know what sets it. But yes, would also be interesting to know if there is a reasoning behind this.

Comment 5 Tomas Mraz 2019-11-28 11:11:51 UTC
The use of pam_umask was added for consistency among various login methods.

And the value of UMASK 077 in login.defs was there since ages. However it is true that this value is not convenient and expected. We could change the value to 022 but that would require shadow-utils update.

Comment 6 Tomas Mraz 2019-11-28 11:13:46 UTC
BTW the value of UMASK in login.defs does not have any effect on RHEL-7, so there should not be any problem with changing it to 022 on RHEL-8. It really affects only user logins.

Comment 7 Tomas Mraz 2019-11-28 11:17:06 UTC
Actually I have to take it back - sorry for the confusion - the value has to stay at 077 because this value is used when creating home directories for new users and we want that value to be applied there.

Comment 8 Tomas Mraz 2019-11-28 11:19:34 UTC
So the only solution is to change authselect to add umask=022 on pam_umask cmdline. Whether it has any unwanted consequences I am not sure.

Comment 9 Pavel Březina 2019-11-29 12:58:39 UTC
Here is the bugzilla that requested pam_umask: https://bugzilla.redhat.com/show_bug.cgi?id=1558599

Why is 022 better default then 077?

Comment 10 Tomas Mraz 2019-11-29 13:26:47 UTC
Because 077 is kind-of unexpected umask value as it makes all the files you create unreadable to others. That is usually not what you want to do. On the other hand having the user's home directory with permissions that disallow looking into it to others is actually desirable. It was kind-of unfortunate to re-use the UMASK login.defs value for these two fairly separate purposes. I am sorry for not realizing this when I was consulted about the change that added pam_umask to the default configuration.

In theory we could do something with it else than adding umask=022 to the pam_umask cmdline however it would require simultaneous changes in both shadow-utils and pam. We would have to add a new LOGIN_UMASK value to login.defs and pam_umask could start using it instead of UMASK if it is set. And we could modify the login.defs in shadow-utils to add LOGIN_UMASK with value of 022.

Comment 11 Pavel Březina 2019-12-03 12:57:16 UTC
Or perhaps pam umask could start using different configuration file? Say /etc/security/pam_umask.conf? This way only one component needs to be modified and it does not need to be hardcoded in pam.

Comment 12 Tomas Mraz 2019-12-03 15:01:28 UTC
This has a disadvantage that we could not introduce a setting in /etc/security/pam_umask.conf without risk of breaking existing customers that depend on some non-default umask value set in login.defs.

Comment 13 Pavel Březina 2019-12-04 09:36:17 UTC
Setting pam_umask=022 will break those customers as well (or do I miss something?) and worse, to change that they would have to create custom authselect profile. Configuration option can be set to possible non-default value during install scriptlet.

Comment 14 Tomas Mraz 2019-12-04 15:12:40 UTC
Yes, I was not comparing it to the pam_umask command line setting but to the LOGIN_UMASK in login.defs.

Comment 15 Pavel Březina 2020-01-06 12:35:19 UTC
I'm moving this to pam component as I think pam_umask should read custom configuration option given the fact that UMASK from login.defs serves completely different purpose.

Comment 17 Tomas Mraz 2020-04-03 12:00:01 UTC
The final solution should be to set the UMASK to 022 in login.defs and add support for HOME_MODE and set it to 077. I am reassigning the bug to shadow-utils as that is the component that contains login.defs.

Comment 18 Tomas Mraz 2020-04-03 12:05:17 UTC
And to make it clear - with the change from comment 17 no changes in pam or authselect packages should be needed.

Comment 19 Iker Pedrosa 2020-04-03 13:43:06 UTC
As Tomas has already pointed the fix will include the change in login.defs of UMASK to 022 and HOME_MODE to 0700, as it isn't a masked value. This issue is similar to https://bugzilla.redhat.com/show_bug.cgi?id=1807957 in Fedora.

Comment 21 Tomas Mraz 2020-04-03 13:49:07 UTC
(In reply to Iker Pedrosa from comment #19)
> As Tomas has already pointed the fix will include the change in login.defs
> of UMASK to 022 and HOME_MODE to 0700, as it isn't a masked value. This
> issue is similar to https://bugzilla.redhat.com/show_bug.cgi?id=1807957 in
> Fedora.

Yes, I am sorry for confusing things with mentioning HOME_MODE as if it was an umask value.

Comment 27 Iker Pedrosa 2020-04-14 09:50:34 UTC
* master
    a847899b521b0df0665e442845bcff23407d9ea0 - add new HOME_MODE login.defs(5) option

Comment 30 Iker Pedrosa 2020-05-11 07:37:27 UTC
*** Bug 1833664 has been marked as a duplicate of this bug. ***

Comment 31 Madhuri 2020-08-07 11:49:47 UTC
checked with:

[root@ci-vm-10-0-105-73 ~]# rpm -qa shadow-utils openssh
openssh-8.0p1-5.el8.x86_64
shadow-utils-4.6-10.el8.x86_64

Verification steps:
1) Add local user and change password
[root@ci-vm-10-0-105-73 ~]# useradd madhuri
[root@ci-vm-10-0-105-73 ~]# passwd madhuri
Changing password for user madhuri.
New password: 
BAD PASSWORD: The password fails the dictionary check - it is based on a dictionary word
Retype new password: 
passwd: all authentication tokens updated successfully.

2) remove rm  /home/madhuri/.bashrc 
[root@ci-vm-10-0-105-73 ~]# rm  /home/madhuri/.bashrc 
rm: remove regular file '/home/madhuri/.bashrc'? yes

3) Check authentication and mask

[root@ci-vm-10-0-105-73 ~]# ssh madhuri@localhost umask
madhuri@localhost's password: 
0077

[root@ci-vm-10-0-105-73 ~]# cat  /etc/login.defs | grep UMASK
UMASK           077

Getting 0077, the expected value is 0022,
Thus marking this FailedQA.

Comment 32 Tomas Mraz 2020-08-07 11:58:23 UTC
Yes, apparently the login.defs file as shipped in the package was not changed at all, only the HOME_MODE support was added to the utilities.

Comment 34 Madhuri 2020-08-10 07:43:44 UTC
Verified with:
[root@ci-vm-10-0-96-221 ~]# rpm -qa shadow-utils openssh
openssh-8.0p1-5.el8.x86_64
shadow-utils-4.6-11.el8.x86_64

Verification steps:

1) Add local user and change the password of user
[root@ci-vm-10-0-96-221 ~]# useradd madhuri
[root@ci-vm-10-0-96-221 ~]# passwd madhuri
Changing password for user madhuri.
New password: 
BAD PASSWORD: The password is shorter than 8 characters
Retype new password: 
passwd: all authentication tokens updated successfully.

2) Check the home directory folder permission

[root@ci-vm-10-0-96-221 ~]# ls -l /home
total 0
drwx------. 4 cloud-user cloud-user 90 Aug 10 03:07 cloud-user
drwx------. 2 madhuri    madhuri    62 Aug 10 03:23 madhuri

Home directory permission is 700.

3) Remove  /home/madhuri/.bashrc 

[root@ci-vm-10-0-96-221 ~]# rm  /home/madhuri/.bashrc 
rm: remove regular file '/home/madhuri/.bashrc'? yes

4) Check authentication and mask
[root@ci-vm-10-0-96-221 ~]# ssh madhuri@localhost umask
madhuri@localhost's password: 
0022

5) 
[root@ci-vm-10-0-96-221 ~]#  cat  /etc/login.defs | grep UMASK
# UMASK is also used by useradd(8) and newusers(8) to set the mode for new
UMASK		022
# If HOME_MODE is not set, the value of UMASK is used to create the mode.


From above steps marking this bug verified.

Comment 36 Alexander Bokovoy 2020-10-08 10:14:42 UTC
This change broke default permissions to home directories created with pam_oddjob_mkhomedir.so because UMASK value became less secure.

See https://bugzilla.redhat.com/show_bug.cgi?id=1886362

Comment 37 Alexander Bokovoy 2020-10-08 10:16:39 UTC
Please note that nobody informed oddjob that it needs to start reading HOME_MODE variable instead of UMASK from /etc/login.defs.

Comment 38 Tomas Mraz 2020-10-08 11:13:53 UTC
The main reason is that nobody expected pam_oddjob_mkhomedir to silently ignore its module options and to read /etc/login.defs instead.

Comment 39 Tomas Mraz 2020-10-08 11:14:39 UTC
This is also opportunity to add a testcase of pam_oddjob_mkhomedir to shadow-utils and pam testplans.

Comment 40 Alexander Bokovoy 2020-10-08 11:28:53 UTC
Man page of pam_oddjob_mkhomedir.so explicitly tells that it doesn't support *any* PAM options. It never did, for the lifetime of this project. ;)

Please add a test case. With https://pagure.io/oddjob/pull-request/12 merged, oddjob should support HOME_MODE and UMASK.

Comment 41 Alexander Bokovoy 2020-10-08 11:30:48 UTC
I would also argue that a change like this (semantic change of UMASK usage and introduction of HOME_MODE) is a release change. At least in Fedora, this should have been a system-wide change that would need to be announced in advance.

Comment 42 Iker Pedrosa 2020-10-08 13:55:40 UTC
I take a note to write a system-wide change when something important is changed around login.defs file

Comment 44 errata-xmlrpc 2020-11-04 01:42:09 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 (shadow-utils 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-2020:4467


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