sagemaker-ssh-helper icon indicating copy to clipboard operation
sagemaker-ssh-helper copied to clipboard

sm-ssh-ide script failure on grep during init-ssm

Open hidemire opened this issue 1 year ago • 1 comments

Hello, firstly, thank you for the wonderful library!

We encountered a problem when initializing ssm in the case when the ExecutionRole is not available for the user-profile, but only for the domain.

The sm-ssh-ide script, fails due to the use of grep within a pipeline combined with set -o pipefail. The grep command can exit with code 1 if "ExecutionRole" is not found, triggering the pipefail behavior and causing the script to terminate.

Steps to Reproduce:

  1. Run the script in an environment where "ExecutionRole" is not present in the user_profile_json.
  2. Observe that the script fails due to grep exiting with code 1.

Suggested Solution:

  1. Temporarily disable pipefail and re-enable after the condition is processed.
set +o pipefail
# execution_role extraction
set -o pipefail
  1. Add || true;
execution_role=$(echo "$user_profile_json" | {grep "ExecutionRole" || true;} \
      | sed -e 's/^.*"ExecutionRole": \"\([^"]*\)\".*$/\1/')
# ...
execution_role=$(echo "$domain_json" | {grep "ExecutionRole" || true;} \
        | sed -e 's/^.*"ExecutionRole": \"\([^"]*\)\".*$/\1/')

hidemire avatar Jun 06 '24 15:06 hidemire

Hi, @hidemire , thank you for pointing to this bug and to the solutions! I've applied the second solution to the main branch and it will appear in the next release.

ivan-khvostishkov avatar Jul 25 '24 10:07 ivan-khvostishkov

Released in v2.2.1

ivan-khvostishkov avatar Nov 28 '24 19:11 ivan-khvostishkov