Commit bca17322 authored by Ruben ten Hove's avatar Ruben ten Hove
Browse files

allow custom files + add longer timeout

parent d18e8a1a
Loading
Loading
Loading
Loading
+12 −9
Original line number Diff line number Diff line
---
variables:
  KUBE_BENCH_VERSION: main  # Or use for example v0.6.7 from the available tags on https://github.com/aquasecurity/kube-bench/tags
  KUBE_BENCH_MANIFEST: kube-bench/job.yaml
  KUBE_BENCH_MANIFEST_JUNIT: kube-bench/job-junit.yaml

.kube-context:
  image: registry.gitlab.com/gitlab-org/cluster-integration/cluster-applications:latest
@@ -13,19 +15,20 @@ k8s:kube-bench:
  extends: .kube-context
  script:
    - |
      if ! test -f kube-bench/job.yaml; then
        apk add --no-cache yq
      if ! test -f ${KUBE_BENCH_MANIFEST}; then
        mkdir -p kube-bench
        wget -O kube-bench/job.yaml https://raw.githubusercontent.com/aquasecurity/kube-bench/${KUBE_BENCH_VERSION}/job.yaml
        yq eval '.spec.template.spec.containers[0].args = ["--junit"]' kube-bench/job.yaml > kube-bench/job-junit.yaml
        yq eval -i '.metadata.name = "kube-bench-junit"' kube-bench/job-junit.yaml
        wget -O ${KUBE_BENCH_MANIFEST} https://raw.githubusercontent.com/aquasecurity/kube-bench/${KUBE_BENCH_VERSION}/job.yaml
      fi
    - kubectl delete -f kube-bench/job-junit.yaml -f kube-bench/job.yaml --ignore-not-found=true
    - kubectl apply -f kube-bench/job-junit.yaml -f kube-bench/job.yaml
    - kubectl wait -f kube-bench/job-junit.yaml -f kube-bench/job.yaml --for=condition=complete=true
    - apk add --no-cache yq
    - yq eval '.spec.template.spec.containers[0].args += ["--junit"]' ${KUBE_BENCH_MANIFEST} > ${KUBE_BENCH_MANIFEST_JUNIT}
    - yq eval -i '.metadata.name = "kube-bench-junit"' ${KUBE_BENCH_MANIFEST_JUNIT}
    - kubectl delete -f ${KUBE_BENCH_MANIFEST_JUNIT} -f ${KUBE_BENCH_MANIFEST} --ignore-not-found=true
    - kubectl apply -f ${KUBE_BENCH_MANIFEST_JUNIT} -f ${KUBE_BENCH_MANIFEST}
    - kubectl wait -f ${KUBE_BENCH_MANIFEST_JUNIT} -f ${KUBE_BENCH_MANIFEST} --for=condition=complete=true --timeout=5m
    - kubectl logs -f jobs/kube-bench-junit > kube-bench/kube-bench-junit.xml
    - kubectl logs -f jobs/kube-bench
    - if [ -z ${KUBE_BENCH_KEEP_JOB} ]; then kubectl delete -f kube-bench/job.yaml -f kube-bench/job-junit.yaml; fi
  after_script:
    - if [ -z ${KUBE_BENCH_KEEP_JOB} ]; then kubectl delete -f ${KUBE_BENCH_MANIFEST} -f ${KUBE_BENCH_MANIFEST_JUNIT}; fi
  artifacts:
    reports:
      junit: kube-bench/kube-bench-junit.xml