Skip to content

Commit 760f364

Browse files
committed
Version 1.0.8
1 parent 7e2ecd8 commit 760f364

File tree

1,897 files changed

+1043
-1343323
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,897 files changed

+1043
-1343323
lines changed

README.md

Lines changed: 185 additions & 68 deletions
Large diffs are not rendered by default.

ash

Lines changed: 85 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,50 @@
33
# SPDX-License-Identifier: Apache-2.0
44
set -e
55
START_TIME=$(date +%s)
6-
VERSION=("1.0.5-e-06Mar2023")
6+
VERSION=("1.0.8-e-25Apr2023")
77
OCI_RUNNER="docker"
88

9+
#
10+
# Version check
11+
#
12+
# Based on the version type, (internal or external),
13+
# attempt to use git ls-remote to obtain the latest tag (version)
14+
# from the appropriate Git repository. If found, check
15+
# it against the script version. If different, suggest the
16+
# user update to the version in the Git repository
17+
# which presumes that the Git repository has a version higher
18+
# than the current script version.
19+
#
20+
version_check() {
21+
_ASHTYPE="${VERSION%-*}" # remove the date portion
22+
_ASHTYPE="${_ASHTYPE#*-}" # remove the version number portion
23+
_GITREPO="git@github.com:aws-samples/automated-security-helper.git"
24+
25+
#
26+
# list the tag values and sort based on "version sort"
27+
# take the "latest/highest" version
28+
#
29+
_REPO_VERSION=$(git ls-remote --tags "${_GITREPO}" 2>/dev/null \
30+
| cut -f2 | cut -f3 -d"/" \
31+
| grep -E "\^\{\}" | sed -E "s/\^\{\}//" \
32+
| grep -v "version1.0"| sort -Vr \
33+
| head -1 )
34+
35+
#
36+
# use VERSION as the script version
37+
#
38+
_SCRIPT_VERSION="${VERSION}"
39+
40+
if [ -n "${_REPO_VERSION}" ]; then # found a version
41+
if [ "${_REPO_VERSION}" != "${_SCRIPT_VERSION}" ]; then
42+
echo "ASH version ${_SCRIPT_VERSION} is different from repository version ${_REPO_VERSION} ... consider upgrading"
43+
else
44+
# the ":" below allows the else/fi clause to remain, even if there is no operation listed
45+
: # echo "repo version is ${_REPO_VERSION}, current version is ${_SCRIPT_VERSION}"
46+
fi
47+
fi
48+
}
49+
950
# Overrides default OCI Runner used by ASH
1051
[ ! -z "$ASH_OCI_RUNNER" ] && OCI_RUNNER="$ASH_OCI_RUNNER"
1152

@@ -23,11 +64,18 @@ print_usage() {
2364
echo -e "\t--force Rebuild the Docker images of the scanning tools, to make sure software is up-to-date."
2465
echo -e "\t-q | --quiet Don't print verbose text about the build process."
2566
echo -e "\t-c | --no-color Don't print colorized output."
67+
echo -e "\t-n | --no-telemetry Opt out of sending telemetry information about the running of ash."
2668
echo -e "\t-q | --quiet Don't print verbose text about the build process"
2769
echo -e "\t-f | --finch Use finch instead of docker to run the containerized tools.\n"
2870
echo -e "For more information please visit https://github.com/aws-samples/automated-security-helper"
2971
}
3072

73+
#
74+
# Attempt to check the current version of ASH against what is found in
75+
# the appropriate Git repository.
76+
#
77+
version_check
78+
3179
# Look for extensions
3280
GIT_EXTENSIONS=("git")
3381
PY_EXTENSIONS=("py" "pyc" "ipynb")
@@ -48,7 +96,6 @@ HIGHEST_RC=0
4896
#
4997
# Initialize options
5098
#
51-
5299
COLOR_OUTPUT="true"
53100
FORCED_EXT="false"
54101

@@ -83,7 +130,7 @@ while (("$#")); do
83130
OCI_RUNNER="finch"
84131
;;
85132
--version | -v)
86-
echo -n "ASH version $VERSION"
133+
echo "ASH version $VERSION"
87134
EXITCODE=0
88135
exit $EXITCODE
89136
;;
@@ -95,7 +142,6 @@ while (("$#")); do
95142
shift
96143
done
97144

98-
99145
if [[ $COLOR_OUTPUT = "true" ]]; then
100146
LPURPLE='\033[1;35m'
101147
LGRAY='\033[0;37m'
@@ -117,9 +163,9 @@ fi
117163

118164
# shellcheck disable=SC2120
119165
# Find all possible extensions in the $SOURCE_DIR directory
120-
map_extensions_anf_files() {
166+
map_extensions_and_files() {
121167
all_files=$(find "${SOURCE_DIR}" \( -path '*/node_modules*' -prune -o -path '*/cdk.out*' -prune \) -o -type f -name '*') # $SOURCE_DIR comes from user input
122-
extenstions_found=()
168+
extensions_found=()
123169
files_found=()
124170

125171
for file in $all_files; do
@@ -129,8 +175,8 @@ map_extensions_anf_files() {
129175
filename="${file##*/}" # extract the base filename plus extension
130176

131177
# add only new extensions, skipping already-found ones.
132-
if [[ ! "${extenstions_found[*]}" =~ ${extension} ]]; then
133-
extenstions_found+=("$extension")
178+
if [[ ! "${extensions_found[*]}" =~ ${extension} ]]; then
179+
extensions_found+=("$extension")
134180
fi
135181

136182
# add only new files, skipping already-found ones.
@@ -145,7 +191,7 @@ search_extension() {
145191
items_to_search=("$@") # passed as parameter to the function
146192
local item_found=0
147193
for item in "${items_to_search[@]}"; do
148-
if [[ "${extenstions_found[*]}" =~ ${item} ]]; then
194+
if [[ "${extensions_found[*]}" =~ ${item} ]]; then
149195
local item_found=1
150196
echo "$item_found"
151197
break
@@ -245,16 +291,30 @@ done
245291

246292
unset IFS
247293

294+
all_files='' # Variable will be populated inside 'map_extensions_and_files' block
295+
248296
validate_input
249-
map_extensions_anf_files
297+
map_extensions_and_files
250298

251299
echo -e "ASH version $VERSION\n"
252300

301+
TOTAL_FILES=$(echo "$all_files" | wc -l)
302+
303+
echo -e "ASH found ${TOTAL_FILES} file(s) in the source directory..."
304+
if [ $TOTAL_FILES -gt 1000 ]; then
305+
echo -e "${RED}Depending on your machine this might take a while...${NC}"
306+
for i in {1..5}
307+
do
308+
echo -n "." && sleep 1
309+
done
310+
echo -e "Starting now!";
311+
fi
312+
253313
#
254314
# set up some variables for use further down
255315
#
256316
typeset -a JOBS JOBS_RC
257-
typeset -i i
317+
typeset -i i j
258318

259319
#
260320
# Collect all the jobs to be run into a list that can be looped through
@@ -298,6 +358,7 @@ i=0
298358
for pid in ${JOBS[@]}; do
299359
echo -e "${CYAN}waiting on ${GREEN}${JOB_NAMES[${i}]}${CYAN} to finish ...${NC}"
300360
WAIT_ERR=0
361+
j=5 # number of times to re-try a failed wait
301362
while wait ${pid} || WAIT_ERR=$?; do
302363
#
303364
# This check allows for the "wait" to fail for some reason, if so
@@ -310,10 +371,21 @@ for pid in ${JOBS[@]}; do
310371
JOBS_RC[${i}]=${WAIT_ERR}
311372
break
312373
else
313-
echo -e "${RED}wait had and error, re-waiting ...${NC}"
374+
j=${j}-1
375+
if [ ${j} -gt 0 ]; then
376+
echo -e "${RED}wait had and error, ${j} retries left, re-waiting ...${NC}"
377+
else
378+
JOBS_RC[${i}]=${WAIT_ERR}
379+
echo -e "${RED}wait had and error, ${j} retries left, skipping wait for ${GREEN}${JOB_NAMES[${i}]}${RED} ...${NC}"
380+
break
381+
fi
314382
fi
315383
done
316-
echo -e "${GREEN}${JOB_NAMES[${i}]}${CYAN} finished with return code ${JOBS_RC[${i}]}${NC}"
384+
if [ ${JOBS_RC[${i}]} -ne 127 ]; then
385+
echo -e "${GREEN}${JOB_NAMES[${i}]}${CYAN} finished with return code ${JOBS_RC[${i}]}${NC}"
386+
else
387+
echo -e "${GREEN}${JOB_NAMES[${i}]}${RED} wait for completion failed${NC}"
388+
fi
317389
i=$i+1
318390
done
319391

@@ -381,10 +453,6 @@ else
381453
echo -e "${GREEN}No extensions were found, nothing to scan at the moment.${NC}"
382454
fi
383455

384-
END_TIME=$(date +%s)
385-
TOTAL_EXECUTION=$((END_TIME-START_TIME))
386-
387-
388456

389457
RCCOLOR=${GREEN}
390458
if [[ $HIGHEST_RC -gt 0 ]]; then

helper_dockerfiles/Dockerfile-cdk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ RUN apt-get update && \
1111
apt-get install -y curl && \
1212
rm -rf /var/lib/apt/lists/*
1313
RUN wget https://bootstrap.pypa.io/get-pip.py && python3 get-pip.py
14+
RUN pip install --no-cache-dir --upgrade pip
1415
RUN npm install -g aws-cdk
1516
RUN python3 -m pip install -U aws-cdk-lib cdk-nag jinja2
1617
WORKDIR /app

quickstart/README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# ASH Quickstart
2+
3+
The purpose of this template is to deploy an AWS Cloud9 Environment with ASH and all the dependencies pre-installed.
4+
5+
This quickstart is designed for **learning purposes only**. The user will be responsible for any patching strategy, network protection and access controls to the instance.
6+
7+
By default, the owner of the AWS Cloud9 Environment will be the user that launched the CloudFormation stackset.
8+
9+
## Pre-requisites
10+
11+
1. An AWS Account and enough permissions to deploy a CloudFormation Stack.
12+
13+
## Installation
14+
15+
1. Download the [template](./c9template.yaml) to your local machine, or clone this repository.
16+
1. Log into your AWS Console
17+
1. Navigate to the AWS CloudFormation console in your region of choice. You can use [this](https://console.aws.amazon.com/cloudformation/home) link.
18+
1. Select `Create stack`
19+
1. In `Specify template` section, select `Upload a template file` option.
20+
1. Use the `Choose file` option to select the template file (`c9template.yaml`) from your local machine and select `Next`.
21+
1. Specify a descriptive `Stack name` (for example `ASH-TestStack`)
22+
1. Select `Next` and accept the default settings on the following screen. Select `Next` again until reaching the last step (`Review ASH-TestStack`).
23+
1. Accept the IAM resource acknowledgement `I acknowledge that AWS CloudFormation might create IAM resources with custom names.` and select Submit to create the Stack.
24+
1. Wait until the Stack is created and status is `CREATE_COMPLETE`.
25+
1. Navigate to the AWS Cloud9 Console. You can use [this](https://console.aws.amazon.com/cloud9control/home) link.
26+
1. Use the `Open` link to access your AWS Cloud9 Environment.
27+
1. You can confirm that ASH is installed properly by running `ash -v` in the terminal. It will take a few minutes for the bootstrap process to complete, wait until you see an empty file with the name `ASH-READY` under `/home/ec2-user/environment`. If you already launched a terminal, refresh the `PATH` environment variable by running `source ~/.bashrc` on your terminal and try again or close the terminal and launch a new one.
28+
29+
30+
## Troubleshooting
31+
32+
If the stack fails to deploy, check the error message in CloudFormation under the `Event` tabs. In general errors are very descriptive about the reasons for the failure. For example:
33+
34+
```
35+
ash-admin already exists in stack arn:aws:cloudformation:us-east-1:123456789012:stack/ASHC9/c0426010-c99c-11ed-85fd-0e5951eaa6e5
36+
```
37+
38+
In this case, another environment with the same name already exists. You will need to delete the old stack or change the Environment name.
39+
40+
## Additional information
41+
42+
- [AWS Cloud9 User Guide](https://docs.aws.amazon.com/cloud9/latest/user-guide/welcome.html)
43+
- [AWS CloudFormation User Guide](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html)
44+
- [AWS CloudFormation Troubleshooting](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/troubleshooting.html)

0 commit comments

Comments
 (0)