configure_system_https can report wrong error on fail

Bug #1995633 reported by Al Bailey
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
StarlingX
Fix Released
Low
Marcelo de Castro Loebens

Bug Description

Brief Description
-----------------
I have only seen this error once. The purpose of this bug is to show where the problem is, and explain the fix.

I setup a STD system (only controller-0) and then ran the following:

 system modify --https_enabled true

Remote error: FileNotFoundError [Errno 2] No such file or directory: '/etc/ssl/private/self-signed-server-cert.pem'
['Traceback (most recent call last):\n', ' File "/usr/lib/python3/dist-packages/sysinv/openstack/common/rpc/amqp.py", line 435, in _process_data\n rval = self.proxy.dispatch(ctxt, version, method, namespace,\n', ' File "/usr/lib/python3/dist-packages/sysinv/openstack/common/rpc/dispatcher.py", line 172, in dispatch\n result = getattr(proxyobj, method)(ctxt, **kwargs)\n', ' File "/usr/lib/python3/dist-packages/sysinv/conductor/manager.py", line 7734, in configure_system_https\n self._config_selfsigned_certificate(context)\n', ' File "/usr/lib/python3/dist-packages/sysinv/conductor/manager.py", line 13251, in _config_selfsigned_certificate\n with open(certificate_file) as pemfile:\n', "FileNotFoundError: [Errno 2] No such file or directory: '/etc/ssl/private/self-signed-server-cert.pem'\n"].

I was able to run the command a short time later without issue.

The code is located here and I will explain the problem
https://github.com/starlingx/config/blob/master/sysinv/sysinv/sysinv/sysinv/conductor/manager.py#L13241

Here is the snippet
        try:
            with open(os.devnull, "w") as fnull:
                openssl_cmd = "openssl req -new -x509 -sha256 \
                        -keyout {file} -out {file} -days 365 -nodes \
                        -config <(echo \"{config}\"); sync" \
                        .format(file=certificate_file, config=csr_config)
                subprocess.check_call(openssl_cmd, # pylint: disable=not-callable
                                      stdout=fnull, stderr=fnull,
                                      shell=True, executable='/usr/bin/bash')
        except subprocess.CalledProcessError as e:
            LOG.exception(e)
            msg = "Fail to generate self-signed certificate to enable https."
            raise exception.SysinvException(_(msg))
        with open(certificate_file) as pemfile:
            pem_contents = pemfile.read()

subprocess.check_call is invoking a command which is two commands.
the openssl command is failing, but the 'sync' command called afterward is passing.
This means that the check_call is reporting 'success' and not reporting "Fail to generate self-signed certificate to enable https."
However the file was not actually created, so the following 'open' fails with the FileNotFound

In my opinion, we should call the sync on its own, if the first openssl call succeeds

Severity
--------
Minor

Steps to Reproduce
------------------
setup STD controller-0 (bootstrap, unlock)
source /etc/platform/openrc
system modify --https_enabled true

Expected Behavior
------------------
It should have reported success

HTTPS enabled with a self-signed certificate.
This should be changed to a CA-signed certificate with 'system certificate-install'.

Actual Behavior
----------------
It reported a weird file not found error.

Reproducibility
---------------
Seen Once

System Configuration
--------------------
STD

Branch/Pull Time/Commit
-----------------------
Nov 3, 2022

Last Pass
---------
Never saw this problem before

Timestamp/Logs
--------------
Remote error: FileNotFoundError [Errno 2] No such file or directory: '/etc/ssl/private/self-signed-server-cert.pem'
['Traceback (most recent call last):\n', ' File "/usr/lib/python3/dist-packages/sysinv/openstack/common/rpc/amqp.py", line 435, in _process_data\n rval = self.proxy.dispatch(ctxt, version, method, namespace,\n', ' File "/usr/lib/python3/dist-packages/sysinv/openstack/common/rpc/dispatcher.py", line 172, in dispatch\n result = getattr(proxyobj, method)(ctxt, **kwargs)\n', ' File "/usr/lib/python3/dist-packages/sysinv/conductor/manager.py", line 7734, in configure_system_https\n self._config_selfsigned_certificate(context)\n', ' File "/usr/lib/python3/dist-packages/sysinv/conductor/manager.py", line 13251, in _config_selfsigned_certificate\n with open(certificate_file) as pemfile:\n', "FileNotFoundError: [Errno 2] No such file or directory: '/etc/ssl/private/self-signed-server-cert.pem'\n"].

Test Activity
-------------
Developer Testing

Workaround
----------
Run the command a second time.

Ghada Khalil (gkhalil)
Changed in starlingx:
status: New → Triaged
importance: Undecided → Low
tags: added: stx.security
Changed in starlingx:
status: Triaged → In Progress
assignee: nobody → Marcelo de Castro Loebens (mdecastr)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to config (master)

Reviewed: https://review.opendev.org/c/starlingx/config/+/864434
Committed: https://opendev.org/starlingx/config/commit/313f2769554f5e83072fe6e766b09e35521608d4
Submitter: "Zuul (22348)"
Branch: master

commit 313f2769554f5e83072fe6e766b09e35521608d4
Author: Marcelo de Castro Loebens <email address hidden>
Date: Mon Nov 14 13:28:30 2022 -0400

    Avoid masking err while creating self-signed cert

    Modified shell command to avoid succeeding in case of an error in
    the creation of self-signed certificate for HTTPS, which leads into
    a posterior failure to open the certificate and gives no precise way
    for debugging.

    Test Plan:
    PASS: Enable https for the first time in the system. The command
          should exhibit the system info with https_enabled set to "True",
          plus a message "HTTPS enabled with a self-signed certificate.
          This should be changed to a CA-signed certificate with 'system
          certificate-install'.".

    Closes-Bug: 1995633

    Signed-off-by: Marcelo de Castro Loebens <email address hidden>
    Change-Id: Id54e9187b65c710814c6a8abdbc026c412c89865

Changed in starlingx:
status: In Progress → Fix Released
Ghada Khalil (gkhalil)
tags: added: stx.8.0
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.