diff --git a/.github/workflows/gobuild.yml b/.github/workflows/gobuild.yml index e224d6a0d..70926a51d 100644 --- a/.github/workflows/gobuild.yml +++ b/.github/workflows/gobuild.yml @@ -2,6 +2,8 @@ name: build on: push: pull_request: + schedule: + - cron: 0 23 * * * jobs: validate: runs-on: ubuntu-latest @@ -10,10 +12,15 @@ jobs: GOPATH: /home/runner/work/terrascan GOBIN: /home/runner/work/terrascan/bin GO_VERSION: 1.16 + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID_TEST }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY_TEST }} + AWS_REGION: ${{ secrets.AWS_REGION_TEST }} + AZURE_AUTH_TEST_SECRET: ${{ secrets.AZURE_AUTH_TEST_KEY }} + GOOGLE_APPLICATION_CREDENTIALS_TEST_SECRET: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS_TEST_KEY }} steps: - name: Checkout Terrascan uses: actions/checkout@v2 - + - name: Setup Go uses: actions/setup-go@v1 with: @@ -37,6 +44,10 @@ jobs: - name: Run e2e tests run: make e2e-tests + - name: Run e2e vulnerability tests + if: ${{ github.event_name == 'push'|| github.event_name == 'schedule' }} + run: make e2e-vulnerability-tests + - name: Upload coverage to Codecov uses: codecov/codecov-action@v1 diff --git a/Makefile b/Makefile index d521e9aaf..29ff99b17 100644 --- a/Makefile +++ b/Makefile @@ -31,6 +31,7 @@ help: @echo "unit-tests\n\texecute unit tests" @echo "e2e-tests\n\texecute e2e tests" @echo "e2e-admission-control-tests\n\texecute e2e admission control tests" + @echo "e2e-vulnerability-tests\n\texecute e2e vulnerability tests" @echo "validate\n\trun all validations" # build terrascan binary @@ -95,6 +96,10 @@ e2e-tests: build e2e-admission-control-tests: build ./scripts/e2e-admission-control.sh +# run e2e vulnerability tests +e2e-vulnerability-tests: build + ./scripts/e2e-vulnerability.sh + # install kind install-kind: ./scripts/install-kind.sh diff --git a/scripts/e2e-vulnerability.sh b/scripts/e2e-vulnerability.sh new file mode 100755 index 000000000..2dc3343d6 --- /dev/null +++ b/scripts/e2e-vulnerability.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +set -o errexit +set -o nounset +set -o pipefail + +export TERRASCAN_BIN_PATH=${PWD}/bin/terrascan + +go test -p 1 -v ./test/e2e/vulnerability/... \ No newline at end of file diff --git a/scripts/run-e2e.sh b/scripts/run-e2e.sh index fba71c5d1..2fe55e8fa 100755 --- a/scripts/run-e2e.sh +++ b/scripts/run-e2e.sh @@ -6,4 +6,4 @@ set -o pipefail export TERRASCAN_BIN_PATH=${PWD}/bin/terrascan -go test -p 1 -v ./test/... \ No newline at end of file +go test -p 1 -v $(go list ./test/e2e/... | grep -v /vulnerability) \ No newline at end of file diff --git a/test/e2e/test_data/iac/resource_for_vulnerability_scan/aws_ecr_registry_used_in_resource/main.tf b/test/e2e/test_data/iac/resource_for_vulnerability_scan/aws_ecr_registry_used_in_resource/main.tf new file mode 100644 index 000000000..391ab7f7e --- /dev/null +++ b/test/e2e/test_data/iac/resource_for_vulnerability_scan/aws_ecr_registry_used_in_resource/main.tf @@ -0,0 +1,37 @@ +resource "aws_ecs_task_definition" "demo-ecs-task-definition" { + family = "ecs-task-definition-demo" + network_mode = "awsvpc" + requires_compatibilities = ["FARGATE"] + memory = "1024" + cpu = "512" + execution_role_arn = "arn:aws:iam::123456789012:role/ecsTaskExecutionRole" + container_definitions = <=", expectedCount)) +}