Skip to content

Commit ed9b2e2

Browse files
authored
feat(install): Add --no-gpg-check flag and interactive GPG verification override (#2998)
* Add --no-gpg-check flag and GPG verification override prompt * Display GPG verification failure details to user regardless of override choice * Fix script early exit on GPG verification failure by handling set -e * Add security warning for --no-gpg-check flag usage * Remove redundant warning
1 parent 41326e3 commit ed9b2e2

File tree

1 file changed

+74
-10
lines changed

1 file changed

+74
-10
lines changed

scripts/install/install_unix.sh

Lines changed: 74 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ INDENT_WIDTH=' '
5151
indent=""
5252
non_interactive=false
5353
error_mode=false
54+
skip_gpg_check=false
5455

5556
# package_out_file_path is the full path to the downloaded package (e.g. "/tmp/observiq-otel-collector_linux_amd64.deb")
5657
package_out_file_path="unknown"
@@ -279,8 +280,22 @@ Usage:
279280
280281
This parameter will have the script check access to Bindplane based on the provided '--endpoint'
281282
283+
$(fg_yellow '--no-gpg-check')
284+
Skips GPG signature verification of the package. When using this flag, the
285+
package signature will not be verified. This should only be used in trusted
286+
or offline environments where the package authenticity has been verified
287+
through other means.
288+
289+
This option is incompatible with '--gpg-tar-file' and will cause the script
290+
to exit with an error if both are specified.
291+
282292
$(fg_yellow '-q, --quiet')
283-
Use quiet (non-interactive) mode to run the script in headless environments
293+
Use quiet (non-interactive) mode to run the script in headless environments.
294+
295+
Note: If a GPG signature verification failure occurs during installation and
296+
'--no-gpg-check' was not specified, the script will exit immediately without
297+
prompting the user to continue. For interactive handling of verification
298+
failures, do not use the '--quiet' flag.
284299
285300
EOF
286301
)
@@ -614,6 +629,12 @@ root_check()
614629
# Test non-interactive mode compatibility
615630
interactive_check()
616631
{
632+
# Incompatible with --no-gpg-check and --gpg-tar-file
633+
if [ "$skip_gpg_check" = "true" ] && [ -n "$gpg_tar_path" ]; then
634+
failed
635+
error_exit "$LINENO" "--no-gpg-check is incompatible with '--gpg-tar-file'. These options cannot be used together."
636+
fi
637+
617638
# Incompatible with proxies unless both username and password are passed
618639
if [ "$non_interactive" = "true" ] && [ -n "$proxy_password" ]
619640
then
@@ -790,7 +811,7 @@ install_package()
790811
dpkg -s "observiq-otel-collector" > /dev/null 2>&1 && dpkg --purge "observiq-otel-collector" > /dev/null 2>&1
791812
fi
792813

793-
# Verify the package signature and display detailed error information on failure
814+
# Verify the package signature, with optional user override on failure
794815
# Capture GPG verification output to display failure details
795816
# Temporarily disable set -e to allow capture of failing command output
796817
set +e
@@ -803,14 +824,48 @@ install_package()
803824
fi
804825

805826
if [ $gpg_verify_exit_code -ne 0 ]; then
806-
increase_indent
807-
printf "\\n${indent}The package signature could not be verified. This may indicate:\n"
808-
printf "${indent} - The GPG keys are not properly installed or accessible\n"
809-
printf "${indent} - The package has been tampered with\n"
810-
printf "${indent} - The signing key has expired or been revoked\n"
811-
printf "${indent} - Network issues prevented GPG key retrieval\n"
812-
error_exit "$LINENO" "Failed to verify package"
813-
decrease_indent
827+
if [ "$non_interactive" = "true" ]; then
828+
# In quiet mode, fail immediately on GPG verification failure
829+
if [ -n "$gpg_verify_output" ]; then
830+
increase_indent
831+
printf "%s\n" "$gpg_verify_output"
832+
decrease_indent
833+
fi
834+
error_exit "$LINENO" "Failed to verify package signature. Use '--no-gpg-check' to skip verification."
835+
else
836+
# In interactive mode, show verification output, prompt the user, and explain failure
837+
if [ -n "$gpg_verify_output" ]; then
838+
increase_indent
839+
printf "%s\n" "$gpg_verify_output"
840+
decrease_indent
841+
fi
842+
843+
increase_indent
844+
printf "\\n${indent}The package signature could not be verified. This may indicate:\n"
845+
printf "${indent} - The GPG keys are not properly installed or accessible\n"
846+
printf "${indent} - The package has been tampered with\n"
847+
printf "${indent} - The signing key has expired or been revoked\n"
848+
printf "${indent} - Network issues prevented GPG key retrieval\n"
849+
printf "\\n${indent}$(fg_yellow 'Continuing without signature verification is NOT RECOMMENDED unless you have independently verified the package authenticity.')\\n\\n"
850+
decrease_indent
851+
852+
command printf "${indent}Do you wish to continue installation without GPG verification? "
853+
prompt "n"
854+
read -r gpg_override_input
855+
printf "\\n"
856+
857+
if [ "$gpg_override_input" != "y" ] && [ "$gpg_override_input" != "Y" ]; then
858+
if [ -n "$gpg_verify_output" ]; then
859+
increase_indent
860+
error "Verification failed due to:"
861+
printf "%s\n" "$gpg_verify_output"
862+
decrease_indent
863+
fi
864+
error_exit "$LINENO" "Installation aborted due to GPG verification failure."
865+
fi
866+
867+
warn "Continuing installation without GPG verification. Ensure package authenticity has been verified through other means."
868+
fi
814869
fi
815870
unpack_package || error_exit "$LINENO" "Failed to extract package"
816871
succeeded
@@ -858,6 +913,13 @@ install_package()
858913
}
859914

860915
verify_package() {
916+
# If GPG check is skipped, return success immediately
917+
if [ "$skip_gpg_check" = "true" ]; then
918+
warn "GPG signature verification is being bypassed with the '--no-gpg-check' flag."
919+
warn "This disables a critical security check and should only be used if your organization policies permit it."
920+
return 0
921+
fi
922+
861923
[ -d "$TMP_DIR/gpg" ] && rm -rf "$TMP_DIR/gpg"
862924
mkdir -p "$TMP_DIR/gpg"
863925

@@ -1195,6 +1257,8 @@ main()
11951257
check_bp_url="true" ; shift 1 ;;
11961258
-b|--base-url)
11971259
base_url=$2 ; shift 2 ;;
1260+
--no-gpg-check)
1261+
skip_gpg_check="true" ; shift 1 ;;
11981262
-r|--uninstall)
11991263
uninstall
12001264
exit 0

0 commit comments

Comments
 (0)