Skip to content

Commit 15afe89

Browse files
authored
fix: non-user-friendly error when trying to install the worker agent as domain user (#457)
Signed-off-by: Josh Usiskin <[email protected]>
1 parent 4937200 commit 15afe89

File tree

3 files changed

+68
-2
lines changed

3 files changed

+68
-2
lines changed

src/deadline_worker_agent/installer/__init__.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212

1313

1414
if sys.platform == "win32":
15-
from deadline_worker_agent.installer.win_installer import start_windows_installer
15+
from deadline_worker_agent.installer.win_installer import (
16+
start_windows_installer,
17+
InstallerFailedException,
18+
)
1619

1720

1821
INSTALLER_PATH = {
@@ -100,7 +103,11 @@ def install() -> None:
100103
if args.windows_job_user:
101104
installer_args.update(windows_job_user=args.windows_job_user)
102105

103-
start_windows_installer(**installer_args)
106+
try:
107+
start_windows_installer(**installer_args)
108+
except InstallerFailedException as e:
109+
print(f"ERROR: {e}")
110+
sys.exit(1)
104111
else:
105112
cmd = [
106113
"sudo",

src/deadline_worker_agent/installer/win_installer.py

+25
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,21 @@ def print_banner():
6666
)
6767

6868

69+
def is_domain_user(username: str) -> bool:
70+
# There are two formats for specifying domain users:
71+
#
72+
# 1. User Principal Name (UPN), e.g:
73+
#
74+
# <USERNAME>@<DOMAIN>
75+
#
76+
# 2. Down-Level Logon Name, e.g:
77+
#
78+
# <DOMAIN>\<USERNAME>
79+
#
80+
# See https://learn.microsoft.com/en-us/windows/win32/secauthn/user-name-formats
81+
return "\\" in username or "@" in username
82+
83+
6984
def check_account_existence(account_name: str) -> bool:
7085
"""
7186
Checks if an account exists on the system by attempting to resolve the account's SID.
@@ -846,16 +861,26 @@ def print_helping_info_and_exit():
846861
logging.error(f"Not a valid value for Fleet id: {fleet_id}")
847862
print_helping_info_and_exit()
848863

864+
# Validate that the --user argument is not a domain user. The installer does not currently support this.
865+
if is_domain_user(user_name):
866+
raise InstallerFailedException(
867+
"running worker agent as a domain user is not currently supported. You can "
868+
"have jobs run as a domain user by configuring the queue job run user to specify a "
869+
"domain user account."
870+
)
871+
849872
# Check that user has Administrator privileges
850873
if not shell.IsUserAnAdmin():
851874
logging.error(f"User does not have Administrator privileges: {os.environ['USERNAME']}")
852875
print_helping_info_and_exit()
853876

877+
# Validate that if a windows job user override is specified, that the user exists
854878
if windows_job_user is not None and not check_account_existence(windows_job_user):
855879
raise InstallerFailedException(
856880
f"Account {windows_job_user} provided for argument windows-job-user does not exist. "
857881
"Please create the account before proceeding."
858882
)
883+
# Validate that if a windows job user override is specified, that it is not the same as the worker agent user
859884
elif windows_job_user is not None and users_equal(windows_job_user, user_name):
860885
raise InstallerFailedException(
861886
f"Argument for windows-job-user cannot be the same as the worker agent user: {user_name}. "

test/unit/install/test_windows_installer.py

+34
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,40 @@ def test_start_windows_installer_fails_when_windows_job_user_is_agent_user(
121121
)
122122

123123

124+
# Override the "user" fixture, which feeds into the parsed_kwargs fixture
125+
# with Valid domain username formats. For valid domain user formats, see:
126+
# https://learn.microsoft.com/en-us/windows/win32/secauthn/user-name-formats
127+
@pytest.mark.parametrize(
128+
argnames="user",
129+
argvalues=(
130+
pytest.param("user@domain", id="user principal name"),
131+
pytest.param(r"domain\username", id="down-level logon name"),
132+
),
133+
)
134+
# No job user override
135+
@pytest.mark.parametrize(
136+
argnames="windows_job_user",
137+
argvalues=(None,),
138+
)
139+
def test_start_windows_installer_fails_on_domain_worker_user(
140+
parsed_kwargs: dict,
141+
) -> None:
142+
# GIVEN
143+
with (
144+
patch.object(shell, "IsUserAnAdmin", return_value=True),
145+
pytest.raises(win_installer.InstallerFailedException) as raise_ctx,
146+
):
147+
# WHEN
148+
win_installer.start_windows_installer(**parsed_kwargs)
149+
150+
# THEN
151+
assert str(raise_ctx.value) == (
152+
"running worker agent as a domain user is not currently supported. You can "
153+
"have jobs run as a domain user by configuring the queue job run user to specify a "
154+
"domain user account."
155+
)
156+
157+
124158
class TestCreateLocalQueueUserGroup:
125159
"""Tests for the create_local_queue_user_group function"""
126160

0 commit comments

Comments
 (0)