Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
154 changes: 43 additions & 111 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# SPDX-License-Identifier: Apache-2.0

name: "CI"
on:
on:
push:
schedule:
- cron: "15 2 * * *" # Nightly-Build at 2:15 AM UTC
Expand Down Expand Up @@ -492,75 +492,6 @@ jobs:

# ---- Build Stage | Matrix Parsers ----

parsers:
name: "Build | Parsers"
needs: sdk
runs-on: ubuntu-latest
strategy:
matrix:
parser:
- test-scan

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Docker Meta
id: docker_meta
uses: docker/metadata-action@v3
with:
images: ${{ env.DOCKER_NAMESPACE }}/parser-${{ matrix.parser }}
tags: |
type=sha
type=semver,pattern={{version}}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
with:
driver: docker

- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}

- name: Set baseImageTag to commit hash
run: |
echo "baseImageTag=sha-$(git rev-parse --short HEAD)" >> $GITHUB_ENV

- name: Download Parser SDK Image
uses: actions/download-artifact@v2
with:
name: parser-sdk-image
path: /tmp

- name: Load Parser SDK Image
run: |
docker load --input /tmp/parser-sdk.tar
docker images | grep sdk

- name: Build and Push
uses: docker/build-push-action@v2
with:
context: ./scanners/${{ matrix.parser }}/parser
file: ./scanners/${{ matrix.parser }}/parser/Dockerfile
build-args: |
namespace=${{ env.DOCKER_NAMESPACE }}
baseImageTag=${{ env.baseImageTag }}
platforms: linux/amd64
push: true
tags: ${{ steps.docker_meta.outputs.tags }}
labels: ${{ steps.docker_meta.outputs.labels }}

- name: Update Docker Hub Description
uses: peter-evans/dockerhub-description@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
repository: ${{ env.DOCKER_NAMESPACE }}/parser-${{ matrix.parser }}
readme-filepath: ./scanners/${{ matrix.parser }}/docs/README.DockerHub-Parser.md

# ---- Build | Scanners ----

# Note we only build images for scanner that don't provider official public container images
Expand All @@ -584,7 +515,6 @@ jobs:
strategy:
matrix:
scanner:
- test-scan
- zap-advanced
steps:
- name: Checkout
Expand Down Expand Up @@ -701,7 +631,6 @@ jobs:
needs:
- operator
- hooks
- parsers
- scanners-custom
runs-on: ubuntu-latest
strategy:
Expand Down Expand Up @@ -769,32 +698,42 @@ jobs:
run: "kubectl create namespace demo-targets"

# ---- Install Test Dependencies ----

- name: "Install Test Dependencies"
run: |
cd tests/integration/
npm ci

# ----- Build Parser SDK Image ----

- name: Build Image
working-directory: ./parser-sdk/nodejs/
run: make docker-build-sdk

# ----- Build Test-Scan ScanType Image ----

- name: Build Images
working-directory: ./scanners/test-scan/
run: make docker-build

- name: Export Docker Images
working-directory: ./scanners/test-scan/
run: make docker-export

- name: Kind import
working-directory: ./scanners/test-scan/
run: make kind-import

- name: Test-scan deploy
working-directory: ./scanners/test-scan/
run: make deploy


# ---- General Testing ----

# This steps should include Integration tests which are not related to a Specific Scanner

# ---- Gerneral Testing | Findings Validation ----

- name: "Parser should fail on invalid Findings"
run: |
helm -n integration-tests install test-scan ./scanners/test-scan/ \
--set="scanner.image.repository=docker.io/${{ env.DOCKER_NAMESPACE }}/scanner-test-scan" \
--set="parser.image.repository=docker.io/${{ env.DOCKER_NAMESPACE }}/parser-test-scan" \
--set="parser.image.tag=sha-$(git rev-parse --short HEAD)" \
--set="scanner.image.tag=sha-$(git rev-parse --short HEAD)" \
--set="parser.env[0].name=CRASH_ON_FAILED_VALIDATION" \
--set-string="parser.env[0].value=true" \
--set="parser.env[1].name=PRODUCE_INVALID_FINDINGS" \
--set-string="parser.env[1].value=true"
cd tests/integration/
npx jest --ci --color generic/findings-validation.test.js
helm -n integration-tests uninstall test-scan

# ---- General Testing | ReadAndWrite Hook ----

Expand All @@ -814,36 +753,22 @@ jobs:
--set="hook.image.tag=sha-$(git rev-parse --short HEAD)" \
--set="attribute.name=severity" \
--set="attribute.value=high"
helm -n integration-tests install test-scan ./scanners/test-scan/ \
--set="scanner.image.repository=docker.io/${{ env.DOCKER_NAMESPACE }}/scanner-test-scan" \
--set="parser.image.repository=docker.io/${{ env.DOCKER_NAMESPACE }}/parser-test-scan" \
--set="parser.image.tag=sha-$(git rev-parse --short HEAD)" \
--set="scanner.image.tag=sha-$(git rev-parse --short HEAD)" \
--set="parser.env[0].name=CRASH_ON_FAILED_VALIDATION" \
--set-string="parser.env[0].value=true"
cd tests/integration/
npx jest --ci --color generic/read-write-hook.test.js
helm -n integration-tests uninstall test-scan update-category update-severity
helm -n integration-tests uninstall update-category update-severity

# ---- Gerneral Testing | ReadOnly Hook ----

- name: "Hooks (ReadOnly) Integration Tests"
run: |
helm -n integration-tests install test-scan ./scanners/test-scan/ \
--set="scanner.image.repository=docker.io/${{ env.DOCKER_NAMESPACE }}/scanner-test-scan" \
--set="parser.image.repository=docker.io/${{ env.DOCKER_NAMESPACE }}/parser-test-scan" \
--set="parser.image.tag=sha-$(git rev-parse --short HEAD)" \
--set="scanner.image.tag=sha-$(git rev-parse --short HEAD)" \
--set="parser.env[0].name=CRASH_ON_FAILED_VALIDATION" \
--set-string="parser.env[0].value=true"
helm -n integration-tests install http-webhook ./demo-targets/http-webhook
helm -n integration-tests install ro-hook ./hooks/generic-webhook/ \
--set="hook.image.repository=docker.io/${{ env.DOCKER_NAMESPACE }}/hook-generic-webhook" \
--set="webhookUrl=http://http-webhook/hallo-welt" \
--set="hook.image.tag=sha-$(git rev-parse --short HEAD)"
cd tests/integration/
npx jest --ci --color generic/read-only-hook.test.js
helm -n integration-tests uninstall test-scan http-webhook ro-hook
helm -n integration-tests uninstall http-webhook ro-hook

# ---- Install Demo Apps for Specific Tests ----

Expand Down Expand Up @@ -875,13 +800,6 @@ jobs:

- name: "Notification Hook Tests"
run: |
helm -n integration-tests install test-scan ./scanners/test-scan/ \
--set="scanner.image.repository=docker.io/${{ env.DOCKER_NAMESPACE }}/scanner-test-scan" \
--set="parser.image.repository=docker.io/${{ env.DOCKER_NAMESPACE }}/parser-test-scan" \
--set="parser.image.tag=sha-$(git rev-parse --short HEAD)" \
--set="scanner.image.tag=sha-$(git rev-parse --short HEAD)" \
--set="parser.env[0].name=CRASH_ON_FAILED_VALIDATION" \
--set-string="parser.env[0].value=true"
helm -n integration-tests install http-webhook ./demo-targets/http-webhook --wait

helm -n integration-tests install notification-hook ./hooks/notification --values tests/integration/hooks/__testFiles__/notification-values.yaml \
Expand All @@ -890,7 +808,7 @@ jobs:

cd tests/integration/
npx jest --ci --color ./hooks/notification.test.js
helm -n integration-tests uninstall test-scan http-webhook notification-hook
helm -n integration-tests uninstall http-webhook notification-hook

# ---- Zap Extended Integration Tests ----

Expand Down Expand Up @@ -936,6 +854,20 @@ jobs:
echo "Operator Startup Logs"
kubectl -n securecodebox-system logs deployment/securecodebox-controller-manager

- name: Test-scan integration-tests
working-directory: ./scanners/test-scan/
run: |
helm -n integration-tests upgrade --install test-scan . \
--set="scanner.image.repository=docker.io/${{ env.DOCKER_NAMESPACE }}/scanner-test-scan" \
--set="parser.image.repository=docker.io/${{ env.DOCKER_NAMESPACE }}/parser-test-scan" \
--set="parser.image.tag=sha-$(git rev-parse --short HEAD)" \
--set="scanner.image.tag=sha-$(git rev-parse --short HEAD)" \
--set="parser.env[0].name=CRASH_ON_FAILED_VALIDATION" \
--set-string="parser.env[0].value=true" \
--set="parser.env[1].name=PRODUCE_INVALID_FINDINGS" \
--set-string="parser.env[1].value=true"
make integration-tests

# ---- Clean UP ----

- name: "Delete kind cluster"
Expand Down
4 changes: 1 addition & 3 deletions scanners/test-scan/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ deploy-with-scanner:
--set="parser.image.tag=$(IMG_TAG)" \
--set="scanner.image.tag=$(IMG_TAG)" \
--set="parser.env[0].name=CRASH_ON_FAILED_VALIDATION" \
--set-string="parser.env[0].value=true" \
--set="parser.env[1].name=PRODUCE_INVALID_FINDINGS" \
--set-string="parser.env[1].value=true"
--set-string="parser.env[0].value=true"

integration-tests:
@echo ".: 🩺 Starting integration test in kind namespace 'integration-tests'."
Expand Down