diff --git a/projects/vdk-plugins/vdk-kerberos-auth/src/vdk/plugin/kerberos/minikerberos_authenticator.py b/projects/vdk-plugins/vdk-kerberos-auth/src/vdk/plugin/kerberos/minikerberos_authenticator.py index 1b88e981c8..48583337ba 100644 --- a/projects/vdk-plugins/vdk-kerberos-auth/src/vdk/plugin/kerberos/minikerberos_authenticator.py +++ b/projects/vdk-plugins/vdk-kerberos-auth/src/vdk/plugin/kerberos/minikerberos_authenticator.py @@ -75,7 +75,22 @@ def _kinit(self) -> None: async def get_tgt(): await krb_client.get_TGT() - asyncio.run(get_tgt()) + # Create a separate event loop and run minikerberos coroutines in it + # to avoid interfering with other plugins or with data jobs that + # rely on asyncio functionality, as well. The steps of the process + # are as follows: + # 1) Create a new event loop which is different from the default one + # 2) Execute the `get_tgt()` coroutine and wait until it is + # finished. + # 3) After the kerberos TGT is retrieved and the coroutine has + # finished, close the event loop. As it is a single coroutine, + # we don't really need to do anything else. + loop = asyncio.new_event_loop() + try: + loop.run_until_complete(get_tgt()) + finally: + loop.close() + krb_client.ccache.to_file(self._ccache_file) log.info( f"Got Kerberos TGT for {self._kerberos_principal}@{self._kerberos_realm} " diff --git a/projects/vdk-plugins/vdk-kerberos-auth/tests/jobs/test-job/20_async_test.py b/projects/vdk-plugins/vdk-kerberos-auth/tests/jobs/test-job/20_async_test.py new file mode 100644 index 0000000000..587ae3cbac --- /dev/null +++ b/projects/vdk-plugins/vdk-kerberos-auth/tests/jobs/test-job/20_async_test.py @@ -0,0 +1,13 @@ +# Copyright 2021 VMware, Inc. +# SPDX-License-Identifier: Apache-2.0 +import asyncio +import logging + +from vdk.api.job_input import IJobInput + +log = logging.getLogger(__name__) + + +def run(job_input: IJobInput): + log.info("Test Async step") + _ = asyncio.Semaphore(2)