Skip to content

Commit

Permalink
clean the username format before using as SKYPILOT_USER (#2290)
Browse files Browse the repository at this point in the history
* Patch cleaned username.

* Update sky/backends/backend_utils.py

Co-authored-by: Zongheng Yang <zongheng.y@gmail.com>

* Update sky/backends/backend_utils.py

Co-authored-by: Zongheng Yang <zongheng.y@gmail.com>

---------

Co-authored-by: Zongheng Yang <zongheng.y@gmail.com>
  • Loading branch information
saihtaungkham and concretevitamin authored Jul 24, 2023
1 parent fc516ce commit f5526d4
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions sky/backends/backend_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,8 @@ def write_cluster_config(
# If the current code is run by controller, propagate the real
# calling user which should've been passed in as the
# SKYPILOT_USER env var (see spot-controller.yaml.j2).
'user': os.environ.get('SKYPILOT_USER', getpass.getuser()),
'user': get_cleaned_username(os.environ.get(
'SKYPILOT_USER', '')),

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


def get_cleaned_username() -> str:
"""Cleans the current username to be used as part of a cluster name.
def get_cleaned_username(username: str = '') -> str:
"""Cleans the username to be used as part of a cluster name.
Clean up includes:
1. Making all characters lowercase
Expand All @@ -1338,7 +1339,7 @@ def get_cleaned_username() -> str:
A cleaned username that will pass the regex in
check_cluster_name_is_valid().
"""
username = getpass.getuser()
username = username or getpass.getuser()
username = username.lower()
username = re.sub(r'[^a-z0-9-]', '', username)
username = re.sub(r'^[0-9-]+', '', username)
Expand Down

0 comments on commit f5526d4

Please sign in to comment.