1 Star 0 Fork 2

k8s-devops/DevOps-Bash-tools

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
check_aws_no_git_credentials.sh 1.85 KB
一键复制 编辑 原始数据 按行查看 历史
#!/usr/bin/env bash
# shellcheck disable=SC2230
# vim:ts=4:sts=4:sw=4:et
#
# Author: Hari Sekhon
# Date: 2019-10-18 13:57:12 +0100 (Fri, 18 Oct 2019)
#
# https://github.com/harisekhon/bash-tools
#
# License: see accompanying Hari Sekhon LICENSE file
#
# If you're using my code you're welcome to connect with me on LinkedIn and optionally send me feedback
#
# https://www.linkedin.com/in/harisekhon
#
set -euo pipefail
[ -n "${DEBUG:-}" ] && set -x
srcdir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# shellcheck source=lib/utils.sh
. "$srcdir/lib/utils.sh"
section "AWS Git credentials scan"
start_time="$(start_timer)"
location="${1:-.}"
if [ "$location" = . ]; then
:
elif [ -d "$location" ]; then
cd "$location"
else
cd "$(dirname "$location")"
fi
# $(pwd) more reliable than $PWD
echo "checking $(pwd)"
echo
matches="$(git grep -Ei \
-e 'AWS_ACCESS_KEY.*=.*[[:alnum:]]+' \
-e 'AWS_SECRET_KEY.*=.*[[:alnum:]]+' \
-e 'AWS_SECRET_ACCESS_KEY.*=.*[[:alnum:]]+' \
-e 'AWS_SESSION_TOKEN.*=.*[[:alnum:]]+' \
|| :
)"
if [ -f .gitallowed ]; then
# makes not difference, .gitallowed is exempted next anyway
#matches="$(grep -Ev -f .gitallowed <<< "$matches" | grep -Fv -f .gitallowed || :)"
matches="$(grep -Ev -f .gitallowed <<< "$matches" || :)"
fi
matches="$(grep -Ev -e "^${0##*/}:[[:space:]]+-e[[:space:]]+'AWS_" -e '^.bash.d/aws.sh:' -e '^.gitallowed:' <<< "$matches" || :)"
if [ -n "$matches" ]; then
# dangerous, fails silently and suppressed legitimate matches
#grep -v -f "$gitallowed" |
#grep -v -e '\.bash\.d/aws.sh:' \
# -e "${0##*/}:" |
# shellcheck disable=SC2001
sed 's/\(=.....\).*/\1....../' <<< "$matches"
echo
echo "DANGER: potential AWS credentials found in Git!!"
exit 1
fi
time_taken "$start_time"
section2 "OK: no AWS credentials found in Git"
echo
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/k8s-devops/DevOps-Bash-tools.git
git@gitee.com:k8s-devops/DevOps-Bash-tools.git
k8s-devops
DevOps-Bash-tools
DevOps-Bash-tools
master

搜索帮助