Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate SBOM then use trivy to check vulnerabilities #1570

Merged
merged 2 commits into from
Jan 9, 2024
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
72 changes: 72 additions & 0 deletions .jenkins/weekly.jenkins
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/************************************************************************************

Weekly Build :
Checks for vulnerability

*************************************************************************************/
pipeline {
agent any
tools {
maven 'apache-maven-latest'
jdk 'temurin-jdk11-latest'
}
options {
timeout (time: 30, unit: 'MINUTES')
buildDiscarder(logRotator(numToKeepStr: '3'))
disableConcurrentBuilds()
durabilityHint('PERFORMANCE_OPTIMIZED')
}
triggers {
// every night between Saturday and Sunday
cron 'H H * * 6'
}
environment {
PATH = "${env.HOME}/bin:${env.PATH}"
}
stages {
stage('Build') {
steps {
// install trivy
sh ''' curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sh -s -- -b ~/bin v0.48.2 '''

// Build (optional)
sh ''' mvn -B com.github.ekryd.sortpom:sortpom-maven-plugin:verify -PallPom '''
// This ssh agent is needed to cache yarn/node to download.eclipse.org when using -PeclipseJenkins
// see : https://github.com/eclipse-leshan/leshan/pull/1484
sshagent ( ['projects-storage.eclipse.org-bot-ssh']) {
sh ''' mvn -B clean install javadoc:javadoc -PeclipseJenkins -DskipTests'''
}

// Generate SBOM for maven
sh ''' mvn org.cyclonedx:cyclonedx-maven-plugin:makeBom '''

// Generate SBOM for yarn with trivy
// Ideally we would like to use a specific integrated tools like : https://github.com/CycloneDX/cyclonedx-node-yarn
// But project is not really active and is searching for contributor : https://github.com/CycloneDX/cyclonedx-node-yarn/issues/12
// OR maybe we should move from Yarn To NPM : https://github.com/eclipse-leshan/leshan/issues/1550#issuecomment-1878802371
sh ''' trivy fs leshan-server-demo/webapp --format cyclonedx --output leshan-server-demo/target/bom-frontend.json --include-dev-deps '''
sh ''' trivy fs leshan-bsserver-demo/webapp --format cyclonedx --output leshan-bsserver-demo/target/bom-frontend.json --include-dev-deps '''

// check for vulnerabilities
// "find" to search file
// xargs to get correct exit code (find always return 0)
sh ''' find . -type f -path '*/target/bom*.json' -print0 | xargs -0 -I {} sh -c 'echo "Scanning "{}""; trivy -q --exit-code 1 sbom "{}"' '''

// check licenses
// TODO add dash-licenses check when cycloneDx will be supported : https://github.com/eclipse/dash-licenses/issues/191
}
}
}
post {
unsuccessful {
mail to: '[email protected]',
subject: "Build ${env.BUILD_TAG} failed!",
body: "Check console output at ${env.BUILD_URL} to view the results."
}
fixed {
mail to: '[email protected]',
subject: "Build ${env.BUILD_TAG} back to normal.",
body: "Check console output at ${env.BUILD_URL} to view the results."
}
}
}
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,11 @@ Contributors:
<artifactId>wagon-maven-plugin</artifactId>
<version>2.0.2</version>
</plugin>
<plugin>
<groupId>org.cyclonedx</groupId>
<artifactId>cyclonedx-maven-plugin</artifactId>
<version>2.7.10</version>
</plugin>
</plugins>
</pluginManagement>

Expand Down