簡體   English   中英

安全地提供一線bash安裝腳本

[英]Securely provide a one-liner bash install script

我喜歡提供單行的bash安裝腳本,看起來像這樣:

curl https://gist.githubusercontent.com/.../raw/install.sh | bash

甚至

curl http://tinyurl.com/installmything | bash

但這對於不信任我的人來說顯然是巨大的安全風險。

有什么方便,簡單的方法可以:

  1. 讓用戶在腳本運行之前對其進行查看,
  2. 仍然只需要一個復制粘貼操作
  3. 不太累嗎

例如,我可以像這樣提供單線:

wget https://gist.githubusercontent.com/.../installthing.sh ; cat installthing.sh ; read -p "Type YES to continue: " X && [ $X = "YES" ] && bash installthing.sh

那沒有繁瑣的要求。 還有更好的方法嗎?

有兩種類型的人不信任您:

  1. 誰知道bash:這些人仍然會下載您的腳本並查看其內容。 他們知道什么curl ... | bash curl ... | bash會執行,他們不會執行該命令。

  2. 誰不了解bash:即使向這些人展示源代碼,他們也將無法做任何事情。 他們將無法決定該代碼是否存在安全風險。

因此,我認為不需要在執行之前讓用戶查看腳本的內容。 但是,如果仍然需要,則可以例如運行腳本,但在執行真實代碼之前詢問用戶。 就像是:

#!/bin/bash

read -p "Do you wish to see the content of this script before execution?" -n 1 -r
echo

if [[ $REPLY =~ ^[Yy]$ ]]
then
  tail -n +20 "$0"

  echo
  read -p "Continue? " -n 1 -r
  echo

  if [[ $REPLY =~ ^[Nn]$ ]]
  then
    exit
  fi
fi

echo "INSTALL"

這樣,您可以繼續使用:

curl https://gist.githubusercontent.com/.../raw/install.sh | bash

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM