@@ -314,9 +314,7 @@ cs_sensor_policy_version() {
314314 sensor_update_policy=$(
315315 curl_command -G " https://$( cs_cloud) /policy/combined/sensor-update/v2" \
316316 --data-urlencode " filter=platform_name:\" Linux\" +name.raw:\" $cs_policy_name \" "
317- )
318-
319- handle_curl_error $?
317+ ) || handle_curl_error $?
320318
321319 if echo " $sensor_update_policy " | grep " authorization failed" ; then
322320 die " Access denied: Please make sure that your Falcon API credentials allow access to sensor update policies (scope Sensor update policies [read])"
@@ -388,9 +386,7 @@ cs_sensor_download() {
388386 existing_installers=$(
389387 curl_command -G " https://$( cs_cloud) /sensors/combined/installers/v3?sort=version|desc" \
390388 --data-urlencode " filter=os:\" $cs_os_name \" $cs_os_version_filter$cs_api_version_filter$cs_os_arch_filter "
391- )
392-
393- handle_curl_error $?
389+ ) || handle_curl_error $?
394390
395391 if echo " $existing_installers " | grep " authorization failed" ; then
396392 die " Access denied: Please make sure that your Falcon API credentials allow sensor download (scope Sensor Download [read])"
@@ -415,9 +411,7 @@ cs_sensor_download() {
415411
416412 installer=" ${destination_dir} /falcon-sensor.${file_type} "
417413
418- curl_command " https://$( cs_cloud) /sensors/entities/download-installer/v3?id=$sha " -o " ${installer} "
419-
420- handle_curl_error $?
414+ curl_command " https://$( cs_cloud) /sensors/entities/download-installer/v3?id=$sha " -o " ${installer} " || handle_curl_error $?
421415
422416 verify_sha256 " $installer " " $sha "
423417
@@ -502,19 +496,20 @@ os_install_package() {
502496}
503497
504498aws_ssm_parameter () {
505- local param_name=" $1 "
499+ local param_name=" $1 " imds_err
506500
507501 hmac_sha256 () {
508502 key=" $1 "
509503 data=" $2 "
510504 echo -n " $data " | openssl dgst -sha256 -mac HMAC -macopt " $key " | sed ' s/^.* //'
511505 }
512506
513- token=$( curl -X PUT " http://169.254.169.254/latest/api/token" -H " X-aws-ec2-metadata-token-ttl-seconds: 21600" )
507+ imds_err=" Failed to query the EC2 instance metadata service. Reading an SSM parameter needs IMDSv2 access from this host."
508+ token=$( curl -X PUT " http://169.254.169.254/latest/api/token" -H " X-aws-ec2-metadata-token-ttl-seconds: 21600" ) || die " $imds_err (curl exit $? )"
514509 api_endpoint=" AmazonSSM.GetParameters"
515- iam_role=" $( printf ' header = "X-aws-ec2-metadata-token: %s"\n' " $token " | curl -s -K- http://169.254.169.254/latest/meta-data/iam/security-credentials/) "
510+ iam_role=" $( printf ' header = "X-aws-ec2-metadata-token: %s"\n' " $token " | curl -s -K- http://169.254.169.254/latest/meta-data/iam/security-credentials/) " || die " $imds_err (curl exit $? ) "
516511 aws_my_region=" $( printf ' header = "X-aws-ec2-metadata-token: %s"\n' " $token " | curl -s -K- http://169.254.169.254/latest/meta-data/placement/availability-zone | sed s/.$//) "
517- _security_credentials=" $( printf ' header = "X-aws-ec2-metadata-token: %s"\n' " $token " | curl -s -K- http://169.254.169.254/latest/meta-data/iam/security-credentials/" $iam_role " ) "
512+ _security_credentials=" $( printf ' header = "X-aws-ec2-metadata-token: %s"\n' " $token " | curl -s -K- http://169.254.169.254/latest/meta-data/iam/security-credentials/" $iam_role " ) " || die " $imds_err (curl exit $? ) "
518513 access_key_id=" $( echo " $_security_credentials " | grep AccessKeyId | sed -e ' s/ "AccessKeyId" : "//' -e ' s/",$//' ) "
519514 access_key_secret=" $( echo " $_security_credentials " | grep SecretAccessKey | sed -e ' s/ "SecretAccessKey" : "//' -e ' s/",$//' ) "
520515 security_token=" $( echo " $_security_credentials " | grep Token | sed -e ' s/ "Token" : "//' -e ' s/",$//' ) "
562557 } | curl -s " https://ssm.$aws_my_region .amazonaws.com/" \
563558 -x " $proxy " -K- \
564559 -d " $request_data "
565- )
566- handle_curl_error $?
560+ ) || handle_curl_error $?
567561 if ! echo " $response " | grep -q ' ^.*"InvalidParameters":\[\].*$' ||
568562 ! echo " $response " | grep -q ' ^.*' " ${param_name} " ' .*$' ; then
569563 # The response body holds the decrypted parameter value, so report only
@@ -725,7 +719,8 @@ check_aws_instance() {
725719 aws_instance=true
726720 # Check if EC2 instance identity document is accessible
727721 else
728- curl_output=" $( curl -s --connect-timeout 5 http://169.254.169.254/latest/dynamic/instance-identity/) "
722+ # A probe failure means this is not an EC2 instance, so keep going.
723+ curl_output=" $( curl -s --connect-timeout 5 http://169.254.169.254/latest/dynamic/instance-identity/ || true) "
729724 if [ -n " $curl_output " ] && ! echo " $curl_output " | grep --silent -i ' not.*found' ; then
730725 aws_instance=true
731726 fi
@@ -790,9 +785,7 @@ get_oauth_token() {
790785 else
791786 auth_payload=" client_id=$cs_falcon_client_id &client_secret=$cs_falcon_client_secret "
792787
793- token_result=$( echo " $auth_payload " | oauth_token_request " $( cs_cloud) " " ${response_headers} " )
794-
795- handle_curl_error $?
788+ token_result=$( echo " $auth_payload " | oauth_token_request " $( cs_cloud) " " ${response_headers} " ) || handle_curl_error $?
796789
797790 token=$( echo " $token_result " | json_value " access_token" | sed ' s/ *$//g' | sed ' s/^ *//g' )
798791 if [ -z " $token " ]; then
@@ -807,8 +800,7 @@ get_oauth_token() {
807800 # Separate file: --dump-header truncates, and region_hint below
808801 # still needs the original response.
809802 retry_headers=$( mktemp)
810- token_result=$( echo " $auth_payload " | oauth_token_request " $retry_host " " $retry_headers " )
811- handle_curl_error $?
803+ token_result=$( echo " $auth_payload " | oauth_token_request " $retry_host " " $retry_headers " ) || handle_curl_error $?
812804 rm -f " $retry_headers "
813805 token=$( echo " $token_result " | json_value " access_token" | sed ' s/ *$//g' | sed ' s/^ *//g' )
814806 fi
@@ -842,8 +834,7 @@ get_oauth_token() {
842834get_provisioning_token () {
843835 local check_settings is_required token_value
844836 # First, let's check if installation tokens are required
845- check_settings=$( curl_command " https://$( cs_cloud) /installation-tokens/entities/customer-settings/v1" )
846- handle_curl_error $?
837+ check_settings=$( curl_command " https://$( cs_cloud) /installation-tokens/entities/customer-settings/v1" ) || handle_curl_error $?
847838
848839 if echo " $check_settings " | grep " authorization failed" > /dev/null; then
849840 # For now we just return. We can error out once more people get a chance to update their API keys
@@ -875,9 +866,7 @@ get_falcon_cid() {
875866 if [ -n " $FALCON_CID " ]; then
876867 echo " $FALCON_CID "
877868 else
878- cs_target_cid=$( curl_command " https://$( cs_cloud) /sensors/queries/installers/ccid/v1" )
879-
880- handle_curl_error $?
869+ cs_target_cid=$( curl_command " https://$( cs_cloud) /sensors/queries/installers/ccid/v1" ) || handle_curl_error $?
881870
882871 if [ -z " $cs_target_cid " ]; then
883872 die " Unable to obtain CrowdStrike Falcon CID. Response was $cs_target_cid "
0 commit comments