Agent: Add timeouts to utils/linux/users.py

This commit is contained in:
Shreya Malviya 2022-04-01 17:09:50 +05:30
parent 2e389cc87e
commit 885a871be8
1 changed files with 8 additions and 3 deletions

View File

@ -3,6 +3,7 @@ import logging
import shlex
import subprocess
from common.common_consts.timeouts import SHORT_REQUEST_TIMEOUT
from infection_monkey.utils.auto_new_user import AutoNewUser
logger = logging.getLogger(__name__)
@ -43,7 +44,9 @@ class AutoNewLinuxUser(AutoNewUser):
logger.debug(
"Trying to add {} with commands {}".format(self.username, str(commands_to_add_user))
)
_ = subprocess.check_output(commands_to_add_user, stderr=subprocess.STDOUT)
_ = subprocess.check_output(
commands_to_add_user, stderr=subprocess.STDOUT, timeout=SHORT_REQUEST_TIMEOUT
)
def __enter__(self):
return self # No initialization/logging on needed in Linux
@ -52,7 +55,7 @@ class AutoNewLinuxUser(AutoNewUser):
command_as_new_user = shlex.split(
"sudo -u {username} {command}".format(username=self.username, command=command)
)
return subprocess.call(command_as_new_user)
return subprocess.call(command_as_new_user, timeout=SHORT_REQUEST_TIMEOUT)
def __exit__(self, _exc_type, value, traceback):
# delete the user.
@ -62,4 +65,6 @@ class AutoNewLinuxUser(AutoNewUser):
self.username, str(commands_to_delete_user)
)
)
_ = subprocess.check_output(commands_to_delete_user, stderr=subprocess.STDOUT)
_ = subprocess.check_output(
commands_to_delete_user, stderr=subprocess.STDOUT, timeout=SHORT_REQUEST_TIMEOUT
)