Skip to content

Commit f5526d4

Browse files
clean the username format before using as SKYPILOT_USER (#2290)
* Patch cleaned username. * Update sky/backends/backend_utils.py Co-authored-by: Zongheng Yang <[email protected]> * Update sky/backends/backend_utils.py Co-authored-by: Zongheng Yang <[email protected]> --------- Co-authored-by: Zongheng Yang <[email protected]>
1 parent fc516ce commit f5526d4

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

sky/backends/backend_utils.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,8 @@ def write_cluster_config(
910910
# If the current code is run by controller, propagate the real
911911
# calling user which should've been passed in as the
912912
# SKYPILOT_USER env var (see spot-controller.yaml.j2).
913-
'user': os.environ.get('SKYPILOT_USER', getpass.getuser()),
913+
'user': get_cleaned_username(os.environ.get(
914+
'SKYPILOT_USER', '')),
914915

915916
# AWS only:
916917
# Temporary measure, as deleting per-cluster SGs is too slow.
@@ -1323,8 +1324,8 @@ def generate_cluster_name():
13231324
return f'sky-{uuid.uuid4().hex[:4]}-{get_cleaned_username()}'
13241325

13251326

1326-
def get_cleaned_username() -> str:
1327-
"""Cleans the current username to be used as part of a cluster name.
1327+
def get_cleaned_username(username: str = '') -> str:
1328+
"""Cleans the username to be used as part of a cluster name.
13281329
13291330
Clean up includes:
13301331
1. Making all characters lowercase
@@ -1338,7 +1339,7 @@ def get_cleaned_username() -> str:
13381339
A cleaned username that will pass the regex in
13391340
check_cluster_name_is_valid().
13401341
"""
1341-
username = getpass.getuser()
1342+
username = username or getpass.getuser()
13421343
username = username.lower()
13431344
username = re.sub(r'[^a-z0-9-]', '', username)
13441345
username = re.sub(r'^[0-9-]+', '', username)

0 commit comments

Comments
 (0)