Skip to content

Commit 8f6a715

Browse files
committed
Add actors for OpenSSL conf and IBMCA
* The openssl-ibmca needs to be reconfigured manually after the upgrade. Report it to the user if the package is installed. * The openssl configuration file (/etc/pki/tls/openssl.cnf) is not 100% compatible between major verions of RHEL due to different versions of OpenSSL. Also the configuration is supposed to be done via system wide crypto policies instead, so it's expected to not modify this file anymore. If the content of the file has been modified, report to user what will happen during the upgrade and what they should do after it. * If the openssl config file is modified (rpm -Vf <file>) and *.rpmnew file exists, back up the file with .leappsave suffix and replace it by the *.rpmsave one.
1 parent a4d294e commit 8f6a715

File tree

6 files changed

+222
-0
lines changed

6 files changed

+222
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from leapp.actors import Actor
2+
from leapp.libraries.actor import checkopensslconf
3+
from leapp.models import InstalledRedHatSignedRPM, Report, TrackedSourceFilesInfo
4+
from leapp.tags import ChecksPhaseTag, IPUWorkflowTag
5+
6+
7+
class CheckOpenSSLConf(Actor):
8+
"""
9+
Check whether the openssl configuration and openssl-IBMCA.
10+
11+
See the report messages for more details. The summary is that since RHEL 8
12+
it's expected to configure OpenSSL via crypto policies. Also, OpenSSL has
13+
different versions between major versions of RHEL:
14+
* RHEL 7: 1.0,
15+
* RHEL 8: 1.1,
16+
* RHEL 9: 3.0
17+
So OpenSSL configuration from older system does not have to be 100%
18+
compatible with the new system. In some cases, the old configuration could
19+
make the system inaccessible remotely. So new approach is to ensure the
20+
upgraded system will use always new default /etc/pki/tls/openssl.cnf
21+
configuration file (the original one will be backed up if modified by user).
22+
23+
Similar for OpenSSL-IBMCA, when it's expected to configure it again on
24+
each newer system.
25+
"""
26+
27+
name = 'check_openssl_conf'
28+
consumes = (InstalledRedHatSignedRPM, TrackedSourceFilesInfo)
29+
produces = (Report,)
30+
tags = (IPUWorkflowTag, ChecksPhaseTag)
31+
32+
def process(self):
33+
checkopensslconf.process()
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
from leapp import reporting
2+
from leapp.libraries.common.config import architecture, version
3+
from leapp.libraries.common.rpms import has_package
4+
from leapp.libraries.stdlib import api
5+
from leapp.models import InstalledRedHatSignedRPM, TrackedSourceFilesInfo
6+
7+
DEFAULT_OPENSSL_CONF = '/etc/pki/tls/openssl.cnf'
8+
9+
10+
def check_ibmca():
11+
if not architecture.matches_architecture(architecture.ARCH_S390X):
12+
# not needed check really, but keeping it to make it clear
13+
return
14+
if not has_package(InstalledRedHatSignedRPM, 'openssl-ibmca'):
15+
return
16+
# TODO(pstodulk): check with @ksrot whether this is relevant for IPU 8 -> 9 also
17+
# (orig msg was for IPU 7 -> 8 only); engine vs provider?
18+
# https://www.ibm.com/docs/en/linux-on-z?topic=openssl-using-ibmca-provider
19+
summary = (
20+
'The presence of openssl-ibmca package suggests that the system may be configured'
21+
' to use the IBMCA OpenSSL engine.'
22+
' Due to major changes in OpenSSL and libica between RHEL {old} and RHEL {new} it is not'
23+
' possible to migrate OpenSSL configuration files automatically. Therefore,'
24+
' it is necessary to enable IBMCA engine in the OpenSSL config file manually'
25+
' after the system upgrade.'
26+
.format(
27+
old=version.get_source_major_version(),
28+
new=version.get_target_major_version()
29+
)
30+
)
31+
32+
hint = (
33+
'Configure the IBMCA engine manually after the upgrade.'
34+
' Please, be aware that it is not recommended to configure the system default'
35+
' /etc/pki/tls/openssl.cnf. Instead, it is recommended to configure a copy of'
36+
' that file and used this copy only for particular applications that are supposed'
37+
' to utilize the IBMCA engine. The location of the OpenSSL configuration file'
38+
' can be specified using the OPENSSL_CONF environment variable.'
39+
)
40+
# TODO(pstodulk): is there a doc?
41+
# TODO(pstodulk): encryption, security groups?
42+
43+
reporting.create_report([
44+
reporting.Title('Detected possible use of IBMCA in OpenSSL'),
45+
reporting.Summary(summary),
46+
reporting.Remediation(hint=hint),
47+
reporting.Severity(reporting.Severity.MEDIUM),
48+
reporting.Groups([
49+
reporting.Groups.POST,
50+
reporting.Groups.SECURITY,
51+
reporting.Groups.SERVICES
52+
]),
53+
])
54+
55+
56+
def _is_openssl_modified():
57+
tracked_files = next(api.consume(TrackedSourceFilesInfo), None)
58+
if not tracked_files:
59+
# unexpected at all, skipping testing, but keeping the log just in case
60+
api.current_logger.warning('The TrackedSourceFilesInfo message is missing! Skipping check of openssl config.')
61+
return False
62+
for finfo in tracked_files.files:
63+
if finfo.path == DEFAULT_OPENSSL_CONF:
64+
return finfo.is_modified
65+
return False
66+
67+
68+
def check_default_openssl():
69+
if not _is_openssl_modified():
70+
return
71+
# TODO(pstodulk): total TODO. sync with dbelyakov
72+
summary = (
73+
''
74+
)
75+
hint = (
76+
'Review the changes after the upgrade and configure the system as needed'
77+
' via crypto policies.'
78+
)
79+
reporting.create_report([
80+
reporting.Title('The /etc/pki/tls/openssl.cnf file will be replaced by the target RHEL default.'),
81+
reporting.Summary(summary),
82+
reporting.Remediation(hint=hint),
83+
reporting.Severity(reporting.Severity.MEDIUM),
84+
reporting.Groups([reporting.Groups.POST, reporting.Groups.SECURITY]),
85+
])
86+
87+
88+
def process():
89+
check_ibmca()
90+
check_default_openssl()
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import pytest
2+
3+
from leapp import reporting
4+
from leapp.libraries.actor import checkopensslconf
5+
from leapp.libraries.common.config import architecture
6+
from leapp.libraries.common.testutils import create_report_mocked, CurrentActorMocked, logger_mocked
7+
from leapp.libraries.stdlib import api
8+
from leapp.models import InstalledRedHatSignedRPM, TrackedSourceFilesInfo
9+
10+
11+
# TODO(pstodulk)
12+
@pytest.mark.parametrize('arch,msgs,ibmca,openssl', (
13+
(architecture.ARCH_S390X, [], False, False),
14+
))
15+
def test_ibmca(monkeypatch, arch, msgs):
16+
monkeypatch.setattr(reporting, "create_report", create_report_mocked())
17+
monkeypatch.setattr(api, 'current_actor', CurrentActorMocked(arch=arch, msgs=msgs))
18+
pass
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from leapp.actors import Actor
2+
from leapp.libraries.actor import migrateopensslconf
3+
from leapp.tags import ApplicationsPhaseTag, IPUWorkflowTag
4+
5+
6+
class MigrateOpenSslConf(Actor):
7+
"""
8+
Enforce the target default configuration file to be used.
9+
10+
If the /etc/pki/tls/openssl.cnf has been modified and openssl.cnf.rpmnew
11+
file is created, backup the original one and replace it by the new default.
12+
13+
tl;dr:
14+
if the file is modified; then
15+
mv /etc/pki/tls/openssl.cnf{,rpmsave_leapp}
16+
mv /etc/pki/tls/openssl.cnf{.rpmnew,}
17+
fi
18+
"""
19+
20+
name = 'migrate_openssl_conf'
21+
consumes = ()
22+
produces = ()
23+
tags = (IPUWorkflowTag, ApplicationsPhaseTag)
24+
25+
def process(self):
26+
migrateopensslconf.process()
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import os
2+
3+
from leapp.libraries.stdlib import api, CalledProcessError, run
4+
5+
DEFAULT_OPENSSL_CONF = '/etc/pki/tls/openssl.cnf'
6+
OPENSSL_CONF_RPMNEW = '{}.rpmnew'.format(DEFAULT_OPENSSL_CONF)
7+
OPENSSL_CONF_BACKUP = '{}.leappsave'.format(DEFAULT_OPENSSL_CONF)
8+
9+
10+
def _is_openssl_modified():
11+
"""
12+
Return True if modified in any way
13+
"""
14+
# NOTE(pstodulk): this is different from the approach in scansourcefiles,
15+
# where we are interested about modified content. In this case, if the
16+
# file is modified in any way, let's do something about that..
17+
try:
18+
run(['rpm', '-Vf', DEFAULT_OPENSSL_CONF])
19+
except CalledProcessError:
20+
return True
21+
return False
22+
23+
24+
def _safe_mv_file(src, dst):
25+
"""
26+
Move the file from src to dst. Return True on success, otherwise False.
27+
"""
28+
try:
29+
run(['mv', src, dst])
30+
except CalledProcessError:
31+
return False
32+
return True
33+
34+
35+
def process():
36+
if not _is_openssl_modified():
37+
return
38+
if not os.path.exists(OPENSSL_CONF_RPMNEW):
39+
api.current_logger().debug('The {} file is modified, but *.rpmsave not found. Cannot do anything.')
40+
return
41+
if not _safe_mv_file(DEFAULT_OPENSSL_CONF, OPENSSL_CONF_BACKUP):
42+
# NOTE(pstodulk): One of reasons could be the file is missing, however
43+
# that's not expected to happen at all. If the file is missing before
44+
# the upgrade, it will be installed by new openssl* package
45+
api.current_logger().error(
46+
'Could not back up the {} file. Skipping other actions.'
47+
.format(DEFAULT_OPENSSL_CONF)
48+
)
49+
return
50+
if not _safe_mv_file(OPENSSL_CONF_RPMNEW, DEFAULT_OPENSSL_CONF):
51+
# unexpected, it's double seatbelt
52+
api.current_logger().error('Cannot apply the new openssl configuration file! Restore it from the backup.')
53+
if not _safe_mv_file(OPENSSL_CONF_BACKUP, DEFAULT_OPENSSL_CONF):
54+
api.current_logger().error('Cannot restore the openssl configuration file!')

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
# '8' (etc..) -> files supposed to be scanned when particular major version of OS is used
1010
TRACKED_FILES = {
1111
'common': [
12+
'/etc/pki/tls/openssl.cnf',
1213
],
1314
'8': [
1415
],

0 commit comments

Comments
 (0)