Skip to content

Commit

Permalink
image-tools: T6154: installer prompts to confirm a non-default passwd
Browse files Browse the repository at this point in the history
  • Loading branch information
jestabro committed Apr 17, 2024
1 parent 6825873 commit f43edbd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
5 changes: 4 additions & 1 deletion python/vyos/utils/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def print_error(str='', end='\n'):
sys.stderr.flush()

def ask_input(question, default='', numeric_only=False, valid_responses=[],
no_echo=False):
no_echo=False, non_empty=False):
from getpass import getpass
question_out = question
if default:
Expand All @@ -48,6 +48,9 @@ def ask_input(question, default='', numeric_only=False, valid_responses=[],
if valid_responses and response not in valid_responses:
print("Invalid value, try again.")
continue
if non_empty and not response:
print("Non-empty value required; try again.")
continue
break
return response

Expand Down
14 changes: 11 additions & 3 deletions src/op_mode/image_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@
MSG_INPUT_CONFIG_CHOOSE: str = 'Which file would you like as boot config?'
MSG_INPUT_IMAGE_NAME: str = 'What would you like to name this image?'
MSG_INPUT_IMAGE_DEFAULT: str = 'Would you like to set the new image as the default one for boot?'
MSG_INPUT_PASSWORD: str = 'Please enter a password for the "vyos" user'
MSG_INPUT_PASSWORD: str = 'Please enter a password for the "vyos" user:'
MSG_INPUT_PASSWORD_CONFIRM: str = 'Please confirm password for the "vyos" user:'
MSG_INPUT_ROOT_SIZE_ALL: str = 'Would you like to use all the free space on the drive?'
MSG_INPUT_ROOT_SIZE_SET: str = 'Please specify the size (in GB) of the root partition (min is 1.5 GB)?'
MSG_INPUT_CONSOLE_TYPE: str = 'What console should be used by default? (K: KVM, S: Serial, U: USB-Serial)?'
Expand All @@ -74,6 +75,7 @@
MSG_WARN_ROOT_SIZE_TOOSMALL: str = 'The size is too small. Try again'
MSG_WARN_IMAGE_NAME_WRONG: str = 'The suggested name is unsupported!\n'\
'It must be between 1 and 64 characters long and contains only the next characters: .+-_ a-z A-Z 0-9'
MSG_WARN_PASSWORD_CONFIRM: str = 'The entered values did not match. Try again'
CONST_MIN_DISK_SIZE: int = 2147483648 # 2 GB
CONST_MIN_ROOT_SIZE: int = 1610612736 # 1.5 GB
# a reserved space: 2MB for header, 1 MB for BIOS partition, 256 MB for EFI
Expand Down Expand Up @@ -695,8 +697,14 @@ def install_image() -> None:
print(MSG_WARN_IMAGE_NAME_WRONG)

# ask for password
user_password: str = ask_input(MSG_INPUT_PASSWORD, default='vyos',
no_echo=True)
while True:
user_password: str = ask_input(MSG_INPUT_PASSWORD, no_echo=True,
non_empty=True)
confirm: str = ask_input(MSG_INPUT_PASSWORD_CONFIRM, no_echo=True,
non_empty=True)
if user_password == confirm:
break
print(MSG_WARN_PASSWORD_CONFIRM)

Check failure

Code scanning / CodeQL

Clear-text logging of sensitive information High

This expression logs
sensitive data (password)
as clear text.

# ask for default console
console_type: str = ask_input(MSG_INPUT_CONSOLE_TYPE,
Expand Down

0 comments on commit f43edbd

Please sign in to comment.