@govuk-pay/cli 0.0.7 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "vulnerability_scan",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "generate_vulnerability_report.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "keywords": [],
10
+ "author": "",
11
+ "license": "MIT",
12
+ "dependencies": {
13
+ "csv-stringify": "^6"
14
+ }
15
+ }
@@ -11,46 +11,77 @@
11
11
 
12
12
  set -euo pipefail
13
13
 
14
-
15
14
  ACCOUNT="staging"
16
15
  ACCOUNT_ID="888564216586"
17
- REPORTS_FOLDER="cli/vulnerability_scan/reports"
16
+ SOURCE_DIR=$(realpath "$(dirname "${BASH_SOURCE[0]}")")
17
+ REPORTS_FOLDER="$SOURCE_DIR/reports"
18
+ ARCHITECTURE_TO_SCAN="linux/amd64"
18
19
 
19
20
  echo "🔍 checking for dependencies..."
20
21
 
21
- declare -a commands=("aws" "jq" "aws-vault" "docker" "docker scout")
22
+ declare -a commands=("aws" "aws-vault" "docker" "docker scout")
22
23
 
23
- for i in "${!commands[@]}"; do
24
- if ! command -v ${commands[i]} &> /dev/null
24
+ for cmd in "${commands[@]}"; do
25
+ # shellcheck disable=SC2086
26
+ if ! command -v $cmd &> /dev/null
25
27
  then
26
- echo "❌ ${commands[i]}"
28
+ echo "❌ $cmd"
27
29
  exit 1
28
30
  else
29
- echo "✅ ${commands[i]}"
31
+ echo "✅ $cmd"
30
32
  fi
31
33
  done
32
34
 
33
35
  # Login to ECR
34
- echo "Logging into staging ECR"
35
- aws-vault exec $ACCOUNT -- aws ecr get-login-password --region eu-west-1 | docker login --username AWS --password-stdin "${ACCOUNT_ID}.dkr.ecr.eu-west-1.amazonaws.com"
36
-
37
- # Get list of govukpay repository URIs (ignore postgres, selenium etc)
38
- REPOSITORIES="$(aws-vault exec $ACCOUNT -- aws ecr describe-repositories --no-paginate | jq -r '.repositories[].repositoryUri' | grep 'govukpay')"
39
- if [[ -z $REPOSITORIES ]]; then
40
- echo "Unable to find ECR repositories"
41
- exit 1
42
- fi
43
-
44
- # For each repository, run scan on the latest image and save to JSON file
45
- for REPO_URI in $REPOSITORIES
46
- do
47
- SHORT_REPO_NAME=$(echo "$REPO_URI"| cut -d'/' -f 3)
48
- LATEST_TAG="$(aws-vault exec $ACCOUNT -- aws ecr describe-images --repository-name "govukpay/$SHORT_REPO_NAME" --query 'sort_by(imageDetails,& imagePushedAt)[-1].imageTags[0]' | tr -d '"')"
49
- echo "Scanning latest image in $SHORT_REPO_NAME with tag $LATEST_TAG."
50
- docker scout cves --format sarif --output "${REPORTS_FOLDER}/${SHORT_REPO_NAME}-${LATEST_TAG}.json" "${REPO_URI}:${LATEST_TAG}"
36
+ echo "Logging into $ACCOUNT ECR"
37
+ aws-vault exec "$ACCOUNT" -- aws ecr get-login-password --region eu-west-1 | docker login --username AWS --password-stdin "${ACCOUNT_ID}.dkr.ecr.eu-west-1.amazonaws.com"
38
+
39
+ IMAGES=""
40
+
41
+ # Get a all ECS clusters
42
+ echo "Getting list of ECS clusters"
43
+ CLUSTERS=$(aws-vault exec "$ACCOUNT" -- aws ecs list-clusters --query clusterArns --output text)
44
+
45
+ for CLUSTER in $CLUSTERS; do
46
+ echo "Checking services in cluster $CLUSTER"
47
+ SERVICES=$(aws-vault exec "$ACCOUNT" -- aws ecs list-services --cluster "$CLUSTER" --query 'serviceArns' --output text | xargs -n1 | sort)
48
+
49
+ for SERVICE in $SERVICES; do
50
+ echo "Checking for container images in service $SERVICE"
51
+ TASK_DEFINITION=$(\
52
+ aws-vault exec "$ACCOUNT" -- \
53
+ aws ecs describe-services --cluster "$CLUSTER" --service "$SERVICE" --query 'services[].taskDefinition' --output text
54
+ )
55
+ CONTAINER_IMAGES=$(aws-vault exec "$ACCOUNT" -- aws ecs describe-task-definition --task-definition "$TASK_DEFINITION" --query 'taskDefinition.containerDefinitions[].image' --output text)
56
+ for CONTAINER_IMAGE in $CONTAINER_IMAGES; do
57
+ IMAGES="$IMAGES $CONTAINER_IMAGE"
58
+ done
59
+ done
51
60
  done
52
61
 
53
- node ./cli/vulnerability_scan/generate_vulnerability_report.js
62
+ for IMAGE in $(xargs -n1 <<<"$IMAGES" | sort | uniq); do
63
+ SHORT_REPO_AND_TAG=$(cut -d'/' -f 3 <<<"$IMAGE")
64
+ SHORT_REPO_NAME=$(cut -f 1 -d ":" <<<"$SHORT_REPO_AND_TAG")
65
+ IMAGE_TAG=$(cut -f 2 -d ":" <<<"$SHORT_REPO_AND_TAG")
66
+
67
+ echo "Scanning image $IMAGE"
68
+ docker scout cves --format sarif --platform "$ARCHITECTURE_TO_SCAN" --output "${REPORTS_FOLDER}/${SHORT_REPO_NAME}-${IMAGE_TAG}.json" "$IMAGE"
69
+ done
70
+
71
+ pushd "$SOURCE_DIR" >>/dev/null 2>&1
72
+
73
+ echo "Installing node dependencies"
74
+ npm install
75
+
76
+ echo
77
+ echo "|============================================================================================"
78
+ echo "| Generating vulnerability report"
79
+ echo "|============================================================================================"
80
+ node "${SOURCE_DIR}/generate_vulnerability_report.js"
81
+ echo "|============================================================================================"
82
+ echo
83
+
84
+ popd >>/dev/null 2>&1
54
85
 
55
86
  # Clean up report JSON files once done
56
87
  echo "Removing JSON report files..."