Skip to content

Commit c0aa6bb

Browse files
committed
Restore add_permitrootlogin_conf functionality
1 parent 6794bbb commit c0aa6bb

File tree

2 files changed

+49
-19
lines changed

2 files changed

+49
-19
lines changed

repos/system_upgrade/common/actors/opensshpermitrootlogincheck/actor.py

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from leapp import reporting
22
from leapp.actors import Actor
33
from leapp.exceptions import StopActorExecutionError
4-
from leapp.libraries.actor.opensshpermitrootlogincheck import global_value, semantics_changes
4+
from leapp.libraries.actor.opensshpermitrootlogincheck import global_value, semantics_changes, add_permitrootlogin_conf
55
from leapp.libraries.common.config.version import get_source_major_version
66
from leapp.libraries.stdlib import api
77
from leapp.models import OpenSshConfig, Report
@@ -64,25 +64,29 @@ def process7to8(self, config):
6464
# the configuration file was locally modified, it will not get updated by
6565
# RPM and the user might be locked away from the server with new default
6666
if not config.permit_root_login:
67+
add_permitrootlogin_conf()
6768
create_report([
68-
reporting.Title('Possible problems with remote login using root account'),
69-
reporting.Summary(
70-
'OpenSSH configuration file does not explicitly state '
71-
'the option PermitRootLogin in sshd_config file, '
72-
'which will default in RHEL8 to "prohibit-password".'
73-
),
74-
reporting.Severity(reporting.Severity.HIGH),
75-
reporting.Groups(COMMON_REPORT_TAGS),
76-
reporting.Remediation(
77-
hint='If you depend on remote root logins using passwords, consider '
78-
'setting up a different user for remote administration or adding '
79-
'"PermitRootLogin yes" to sshd_config. '
80-
'If this change is ok for you, add explicit '
81-
'"PermitRootLogin prohibit-password" to your sshd_config '
82-
'to ignore this inhibitor'
83-
),
84-
reporting.Groups([reporting.Groups.INHIBITOR])
85-
] + COMMON_RESOURCES)
69+
reporting.Title('SSH configuration automatically modified to permit root login'),
70+
reporting.Summary(
71+
'Your OpenSSH configuration file does not explicitly state '
72+
'the option PermitRootLogin in sshd_config file. '
73+
'Its default is "yes" in RHEL7, but will change in '
74+
'RHEL8 to "prohibit-password", which may affect your ability '
75+
'to log onto this machine after the upgrade. '
76+
'To prevent this from occuring, the PermitRootLogin option '
77+
'has been explicity set to "yes" to preserve the default behaivour '
78+
'after migration. '
79+
'The original configuration file has been backed up to '
80+
'/etc/ssh/sshd_config.leapp_backup'
81+
),
82+
reporting.Severity(reporting.Severity.MEDIUM),
83+
reporting.Groups(COMMON_REPORT_TAGS),
84+
reporting.Remediation(
85+
hint='If you would prefer to configure the root login policy yourself, '
86+
'consider setting the PermitRootLogin option '
87+
'in sshd_config explicitly.'
88+
)
89+
] + resources)
8690
return
8791

8892
# Check if there is at least one PermitRootLogin other than "no"

repos/system_upgrade/common/actors/opensshpermitrootlogincheck/libraries/opensshpermitrootlogincheck.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,29 @@ def semantics_changes(config):
4141
in_match_enabled = True
4242

4343
return config_global_value is None and not in_match_enabled
44+
45+
def add_permitrootlogin_conf():
46+
CONFIG = '/etc/ssh/sshd_config'
47+
CONFIG_BACKUP = '/etc/ssh/sshd_config.leapp_backup'
48+
try:
49+
with open(CONFIG, 'r') as fd:
50+
sshd_config = fd.readlines()
51+
52+
permit_autoconf = [
53+
"# Automatically added by Leapp to preserve RHEL7 default\n",
54+
"# behavior after migration.\n",
55+
"# Placed on top of the file to avoid being included into Match blocks.\n",
56+
"PermitRootLogin yes\n"
57+
"\n",
58+
]
59+
permit_autoconf.extend(sshd_config)
60+
with open(CONFIG, 'w') as fd:
61+
fd.writelines(permit_autoconf)
62+
with open(CONFIG_BACKUP, 'w') as fd:
63+
fd.writelines(sshd_config)
64+
65+
except IOError as err:
66+
if err.errno != errno.ENOENT:
67+
error = 'Failed to open sshd_config: {}'.format(str(err))
68+
api.current_logger().error(error)
69+
return

0 commit comments

Comments
 (0)