From de232262d503da01f5f1aa974d985555fe51008a Mon Sep 17 00:00:00 2001 From: Daniel Neilson <53624638+ddneilson@users.noreply.github.com> Date: Mon, 18 Mar 2024 09:26:03 -0500 Subject: [PATCH] fix: improve error messaging for Windows logon (#219) Summary: The current code structure for logging on and loading the user profile blurs the line between password-related logon failures, and agent-user permission-related logon failures. Solution: Break-up the code that's in a single try-catch to split it into multiple try-catches. Signed-off-by: Daniel Neilson <53624638+ddneilson@users.noreply.github.com> --- .../windows/win_credentials_resolver.py | 43 +++++++++++++------ 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/src/deadline_worker_agent/windows/win_credentials_resolver.py b/src/deadline_worker_agent/windows/win_credentials_resolver.py index 64579275..e71cfef8 100644 --- a/src/deadline_worker_agent/windows/win_credentials_resolver.py +++ b/src/deadline_worker_agent/windows/win_credentials_resolver.py @@ -219,21 +219,36 @@ def get_windows_session_user(self, user: str, passwordArn: str) -> WindowsSessio Password=password, Domain=None, ) - # https://timgolden.me.uk/pywin32-docs/win32profile__LoadUserProfile_meth.html - user_profile = LoadUserProfile( - logon_token, - { - "UserName": user, - "Flags": PI_NOUI, - "ProfilePath": None, - }, - ) - windows_session_user = WindowsSessionUser( - user=user, - logon_token=cHANDLE(int(logon_token)), - ) except OSError as e: - logger.error(f'Error logging on as "{user}": {e}') + logger.error( + f'Error logging on as "{user}", please check that your password within {passwordArn} is correct: {e}' + ) + else: + try: + # https://timgolden.me.uk/pywin32-docs/win32profile__LoadUserProfile_meth.html + user_profile = LoadUserProfile( + logon_token, + { + "UserName": user, + "Flags": PI_NOUI, + "ProfilePath": None, + }, + ) + except OSError as e: + logger.error( + ( + f'Error loading profile for "{user}": {e}\n' + "Please ensure that the Worker Agent is running as a user that is an Administrator, and has user rights to both backup and restore files and directories." + ) + ) + else: + try: + windows_session_user = WindowsSessionUser( + user=user, + logon_token=cHANDLE(int(logon_token)), + ) + except OSError as e: + logger.error(f'Error logging on as "{user}": {e}') else: try: # OpenJD will test the ultimate validity of the credentials when creating a WindowsSessionUser