Merge branch 'feat_scan_image_cve' into 'master'

Feat scan image cve

See merge request gilden/ci/gitlab-ci-templates!3
This commit is contained in:
Fabian Widmann 2021-07-02 07:15:14 +00:00
commit 42ebe004f3
12 changed files with 93 additions and 45 deletions

1
.gitignore vendored
View File

@ -72,3 +72,4 @@ fabric.properties
# Android studio 3.1+ serialized cache file # Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser .idea/caches/build_file_checksums.ser
/.idea/sonarlint/

View File

@ -2,7 +2,9 @@
<module type="JAVA_MODULE" version="4"> <module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true"> <component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output /> <exclude-output />
<content url="file://$MODULE_DIR$" /> <content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.idea/sonarlint" />
</content>
<orderEntry type="inheritedJdk" /> <orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
</component> </component>

View File

@ -1,3 +0,0 @@
A
publish-image.yml,2/e/2eef21b10116aab77b6b014cb5adf007d2d2e128

View File

@ -4,6 +4,9 @@
rules: rules:
- if: $CI_COMMIT_TAG - if: $CI_COMMIT_TAG
variables: variables:
DOCKER_REGISTRY: $CI_REGISTRY
DOCKER_REGISTRY_USER: $CI_REGISTRY_USER
DOCKER_REGISTRY_PASSWORD: $CI_REGISTRY_PASSWORD
MVN_VERSION: "true" MVN_VERSION: "true"
script: script:
- export PARSED_VERSION=$(echo $CI_COMMIT_TAG | sed -r 's/\+/_/g') # Replace + sign since this is not valid in a docker tag - export PARSED_VERSION=$(echo $CI_COMMIT_TAG | sed -r 's/\+/_/g') # Replace + sign since this is not valid in a docker tag
@ -14,8 +17,9 @@
fi fi
- mvn $MAVEN_CLI_OPTS compile jib:build - mvn $MAVEN_CLI_OPTS compile jib:build
"-DskipTests" "-DskipTests"
"-Djib.to.auth.username=$CI_REGISTRY_USER" "-Djib.to.image=$DOCKER_REGISTRY:$PARSED_VERSION"
"-Djib.to.auth.password=$CI_REGISTRY_PASSWORD" "-Djib.to.auth.username=$DOCKER_REGISTRY_USER"
"-Djib.to.auth.password=$DOCKER_REGISTRY_PASSWORD"
.publish-image-kaniko: .publish-image-kaniko:
image: image:

34
container-scan.yml Normal file
View File

@ -0,0 +1,34 @@
.scan-container-jib:
image: $MAVEN_IMAGE
stage: test
variables:
TRIVY_VERSION: 0.18.3
EXITCODE_ON_HIGH: 1
EXITCODE_ON_CRITICAL: 1
before_script:
- curl -L "https://github.com/aquasecurity/trivy/releases/download/v${TRIVY_VERSION}/trivy_${TRIVY_VERSION}_Linux-64bit.tar.gz" --output trivy_${TRIVY_VERSION}_Linux-64bit.tar.gz
- tar zxvf trivy_${TRIVY_VERSION}_Linux-64bit.tar.gz
script:
- mvn $MAVEN_CLI_OPTS compile jib:buildTar -DskipTests
- ./trivy --exit-code $EXITCODE_ON_HIGH --severity HIGH --no-progress --auto-refresh --input target/jib-image.tar
- ./trivy --exit-code $EXITCODE_ON_CRITICAL --severity CRITICAL --no-progress --auto-refresh --input target/jib-image.tar
.scan-container-kaniko:
stage: test
image:
name: gcr.io/kaniko-project/executor:debug
entrypoint: [ "" ]
variables:
TRIVY_VERSION: 0.18.3
PROJECT_DIR: $CI_PROJECT_DIR
DOCKERFILE_LOCATION: $CI_PROJECT_DIR/Dockerfile
CONTEXT_LOCATION: $CI_PROJECT_DIR
EXITCODE_ON_HIGH: 1
EXITCODE_ON_CRITICAL: 1
before_script:
- wget "https://github.com/aquasecurity/trivy/releases/download/v${TRIVY_VERSION}/trivy_${TRIVY_VERSION}_Linux-64bit.tar.gz"
- tar zxvf trivy_${TRIVY_VERSION}_Linux-64bit.tar.gz
script:
- /kaniko/executor --context $CONTEXT_LOCATION --dockerfile $DOCKERFILE_LOCATION --cache-dir cache/image --tarPath image.tar --no-push --destination image
- ./trivy --exit-code $EXITCODE_ON_HIGH --severity HIGH --no-progress --auto-refresh --input image.tar
- ./trivy --exit-code $EXITCODE_ON_CRITICAL --severity CRITICAL --no-progress --auto-refresh --input image.tar

View File

@ -23,7 +23,8 @@ include:
- 'npm-dependencies-template.yml' - 'npm-dependencies-template.yml'
- 'npm-lint-template.yml' - 'npm-lint-template.yml'
- 'npm-test-template.yml' - 'npm-test-template.yml'
- 'publish-image.yml' - 'container-publish.yml'
- 'container-scan.yml'
- 'set-version-template.yml' - 'set-version-template.yml'
- 'sonar-template.yml' - 'sonar-template.yml'

View File

@ -0,0 +1,18 @@
:sourcedir: ../../../
= Container-Publish
Baut mithilfe von jib oder kaniko ein Docker Image und läd das Image in der Docker Registry des Projekts hoch.
Dieser Schritt wird nur ausgeführt, wenn ein Tag gesetzt wird.
.Variables
|===
|Name |Description | Default Value
|MVN_VERSION | Bestimmt, ob die version von MAVEN gesetzt werden soll.
Falls das Projekt aus mehreren Poms besteht, kann `before_script:` benutzt werden. | "true"
|===
.sonar-template
----
include::{sourcedir}/container-publish.yml[]
----

View File

@ -0,0 +1,22 @@
:sourcedir: ../../../
= Container-Scan
Baut ein Image mithilfe von jib oder Kaniko welches im Anschluss gescanned wird. Dieser Schritt wird ausgeführt, wenn ein Tag gesetzt wird. Die Ergebnisse des Scans können genutzt werden den Build failen zu lassen, falls gewünscht (vgl. `EXITCODE_ON_HIGH` und `EXITCODE_ON_CRITICAL`).
.Variables
|===
|Name |Description | Default Value
|TRIVY_VERSION | Version von Trivy die benutzt werden soll.
|EXITCODE_ON_HIGH | Bestimmt den Exit code der ausgegeben werden soll, wenn ein CVE der als HIGH markiert wurde, gefunden werden konnte.
Wenn 0 benutzt wird, läuft die CI weiter.
Benutzte `allow_failure: true` damit die CI weiter läuft aber ein Failure angezeigt wird.
|EXITCODE_ON_CRITICAL | Bestimmt den Exit code der ausgegeben werden soll, wenn ein CVE der als CRITICAL markiert wurde, gefunden werden konnte.
Wenn 0 benutzt wird, läuft die CI weiter.
Benutzte `allow_failure: true` damit die CI weiter läuft aber ein Failure angezeigt wird.
|===
.sonar-template
----
include::{sourcedir}/container-scan.yml[]
----

View File

@ -1,18 +0,0 @@
:sourcedir: ../../../
= Publish-Image-jib
Baut mithilfe von jib ein Docker Image und läd es in der Docker Registry des Projekt hoch.
Dieser Schritt wird nur ausgeführt, wenn ein Tag gesetzt wird.
.Variables
|===
|Name |Description | Default Value
|MVN_VERSION | Bestimmt, ob die version von MAVEN gesetzt werden soll.
Falls das Projekt aus mehreren Poms besteht, kann `bevor_script:` benutzt werden. | "true"
|===
.sonar-template
----
include::{sourcedir}/publish-image.yml[]
----

View File

@ -1,17 +0,0 @@
:sourcedir: ../../../
= sonar-template
Ruft den Sonar Job für das Projekt auf.
Mehr Details zu finden hier: https://gitlab.exxcellent.de/gilden/ci/exxcellent-sonar-tool[Gilde CI/CD: exxcellent-sonar-tool].
.Variables
|===
|Name |Description | Default Value
|SONAR_PROJECT_KEY | Der Sonar-Projekt-Key. | ""
|===
.sonar-template
----
include::{sourcedir}/sonar-template.yml[]
----

View File

@ -36,8 +36,8 @@ include::chapters/generalInformation.adoc[leveloffset=1]
== Misc Templates == Misc Templates
include::chapters/templates/sonar-template.adoc[leveloffset=1] include::chapters/templates/container-publish.adoc[leveloffset=1]
include::chapters/templates/publish-image.adoc[leveloffset=1] include::chapters/templates/container-scan.adoc[leveloffset=1]
== NPM Templates == NPM Templates
@ -51,3 +51,7 @@ include::chapters/templates/npm-test-template.adoc[leveloffset=1]
include::chapters/templates/maven-dependencies-template.adoc[leveloffset=1] include::chapters/templates/maven-dependencies-template.adoc[leveloffset=1]
include::chapters/templates/maven-build-template.adoc[leveloffset=1] include::chapters/templates/maven-build-template.adoc[leveloffset=1]
include::chapters/templates/maven-verify-template.adoc[leveloffset=1] include::chapters/templates/maven-verify-template.adoc[leveloffset=1]
== Tools
Weitere Templates für die Tools der CI Gilde, sind in den jeweiligen Repos zu finden.