Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always try to reinitialize Crypto.Random when forking minion process #55635

Merged
merged 1 commit into from
Jan 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions salt/minion.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from salt.utils.zeromq import zmq, ZMQDefaultLoop, install_zmq, ZMQ_VERSION_INFO
import salt.transport.client
import salt.defaults.exitcodes
import salt.utils.crypt

from salt.utils.ctx import RequestContext

Expand Down Expand Up @@ -1531,6 +1532,7 @@ def _handle_decoded_payload(self, data):
name='ProcessPayload',
args=(instance, self.opts, data, self.connected)
)
process._after_fork_methods.append((salt.utils.crypt.reinit_crypto, [], {}))
else:
process = threading.Thread(
target=self._target,
Expand Down
22 changes: 22 additions & 0 deletions tests/unit/test_minion.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import tornado
import tornado.testing
from salt.ext.six.moves import range
import salt.utils.crypt
import salt.utils.process


class MinionTestCase(TestCase, AdaptedConfigurationTestCaseMixin):
Expand Down Expand Up @@ -339,6 +341,26 @@ def compile_pillar(self):
finally:
minion.destroy()

@patch('salt.utils.process.default_signals')
def test_reinit_crypto_on_fork(self, def_mock):
'''
Ensure salt.utils.crypt.reinit_crypto() is executed when forking for new job
'''
mock_opts = self.get_config('minion', from_scratch=True)
mock_opts["multiprocessing"] = True

io_loop = tornado.ioloop.IOLoop()
io_loop.make_current()
minion = salt.minion.Minion(mock_opts, io_loop=io_loop)

job_data = {"jid": "test-jid", "fun": "test.ping"}

def mock_start(self):
assert len([x for x in self._after_fork_methods if x[0] == salt.utils.crypt.reinit_crypto]) == 1 # pylint: disable=comparison-with-callable

with patch.object(salt.utils.process.SignalHandlingProcess, 'start', mock_start):
io_loop.run_sync(lambda: minion._handle_decoded_payload(job_data))


class MinionAsyncTestCase(TestCase, AdaptedConfigurationTestCaseMixin, tornado.testing.AsyncTestCase):

Expand Down