forked from toniblyx/aws-security-toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ast.sh
executable file
·78 lines (68 loc) · 2.19 KB
/
ast.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/bash
# vgrenu@zoph.io
# https://zoph.me
################ Project #######################
PROJECT="aws-security-toolbox"
DESCRIPTION="Docker image for SecOps folks"
################################################
################ Config ########################
PROFILE_NAME="default"
CONTAINER_IMAGE="aws-security-toolbox:latest"
GREEN='\033[0;32m'
NC='\033[0m' # No Color
################################################
help() {
echo "$PROJECT"
echo "$DESCRIPTION"
echo ""
echo " build - build the container image based on Dockerfile (update tools)"
echo " pull - pull the container image from Docker hub"
echo " login - log-in to the container image using interactive mode"
echo " exec [command] - exec your command using aws-vault remotly"
echo " stop - stop the current running SecOps Container"
}
build() {
docker build -t $PROJECT .
echo "--> Container: $CONTAINER_IMAGE built successfully"
}
pull() {
docker pull zoph/$PROJECT
echo "--> Container: zoph/$CONTAINER_IMAGE pulled successfully"
docker tag zoph/$CONTAINER_IMAGE zoph/$PROJECT:$PROJECT
}
login() {
docker run -it -v ${HOME}/.aws:/root/.aws:ro --mount src="/tmp",target=/tmp,type=bind $CONTAINER_IMAGE /bin/bash
}
exec() {
unset AWS_VAULT
export $(aws-vault exec $PROFILE_NAME --assume-role-ttl=1h -- env | grep ^AWS | xargs)
# For troubleshooting, uncomment below :)
# echo $AWS_ACCESS_KEY_ID
# echo $AWS_SECRET_ACCESS_KEY
# echo $AWS_SESSION_TOKEN
# echo $AWS_SECURITY_TOKEN
printf "==> Running: ${GREEN}$@${NC} (aws-vault profile: $PROFILE_NAME)\n"
docker run -it \
-e AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID \
-e AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY \
-e AWS_SESSION_TOKEN=$AWS_SESSION_TOKEN \
-e AWS_SECURITY_TOKEN=$AWS_SECURITY_TOKEN \
$CONTAINER_IMAGE "$@"
}
stop() {
docker stop `docker ps -q --filter ancestor=$CONTAINER_IMAGE`
echo "--> Container: $CONTAINER_IMAGE stopped successfully"
}
if [[ "$1" == "build"* ]]; then
build
elif [[ "$1" == "pull"* ]]; then
pull
elif [[ "$1" == "login"* ]]; then
login
elif [[ "$1" == "exec"* ]]; then
exec $2 $3 $4 $5 $6 $7 $8
elif [[ "$1" == "stop"* ]]; then
stop
else
help
fi