Skip to content

Commit 3f99b93

Browse files
committed
Merge branch 'release/4.0.0'
2 parents 6da6e67 + 597f67d commit 3f99b93

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1404
-654
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
/*.iml
44
/.idea/
55
.mvn/**
6+
**/trivyReport.json
Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,19 @@
1-
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip
2-
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
wrapperVersion=3.3.2
18+
distributionType=only-script
19+
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip

CHANGELOG.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88

99
## [Unreleased]
1010

11-
## [3.1.0](https://github.com/cloudogu/ces-build-lib/releases/tag/3.0.0) - 2024-11-25
11+
## [4.0.0](https://github.com/cloudogu/ces-build-lib/releases/tag/4.0.0) - 2025-01-07
12+
### Added
13+
- Add Trivy class for scanning container images with Trivy
14+
- Combines the functionality of the findVulnerabilitiesWithTrivy function and the Trivy class of the dogu-build-lib
15+
16+
### Deprecated
17+
- findVulnerabilitiesWithTrivy function is deprecated now. Please use the new Trivy class.
18+
19+
### Changed
20+
- [#140] Update Maven-Build-Dependencies
21+
- JUnit 5
22+
- Groovy 2.5
23+
- Maven 3.9.9
24+
- Compiler-Target: Java 11
25+
26+
## [3.1.0](https://github.com/cloudogu/ces-build-lib/releases/tag/3.1.0) - 2024-11-25
1227
### Added
1328
- [#137] function to determine PreRelease Branch
1429

Jenkinsfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ node('docker') {
1111

1212
def cesBuildLib = libraryFromLocalRepo().com.cloudogu.ces.cesbuildlib
1313

14-
def mvn = cesBuildLib.MavenWrapperInDocker.new(this, 'adoptopenjdk/openjdk11:jdk-11.0.10_9-alpine')
14+
def mvn = cesBuildLib.MavenWrapperInDocker.new(this, 'eclipse-temurin:11.0.25_9-jdk-alpine')
1515
mvn.useLocalRepoFromJenkins = true
1616
def git = cesBuildLib.Git.new(this)
1717

@@ -40,7 +40,7 @@ node('docker') {
4040
}
4141

4242
stage('Unit Test') {
43-
mvn 'test -Dmaven.test.failure.ignore=true'
43+
mvn 'test'
4444
// Archive Unit and integration test results, if any
4545
junit allowEmptyResults: true, testResults: '**/target/failsafe-reports/TEST-*.xml,**/target/surefire-reports/TEST-*.xml'
4646
}
@@ -70,4 +70,4 @@ def libraryFromLocalRepo() {
7070
// Checks out to workspace local folder named like the identifier.
7171
// We have to pass an identifier with version (which is ignored). Otherwise the build fails.
7272
library(identifier: 'ces-build-lib@snapshot', retriever: legacySCM(scm))
73-
}
73+
}

README.md

Lines changed: 177 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ Jenkins Pipeline Shared library, that contains additional features for Git, Mave
6868
- [Markdown](#markdown)
6969
- [DockerLint (Deprecated)](#dockerlint-deprecated)
7070
- [ShellCheck](#shellcheck)
71+
- [Trivy](#trivy)
7172
- [Steps](#steps)
7273
- [mailIfStatusChanged](#mailifstatuschanged)
7374
- [isPullRequest](#ispullrequest)
@@ -1240,6 +1241,179 @@ shellCheck(fileList) // fileList="a.sh b.sh" execute shellcheck on a custom list
12401241

12411242
See [shellCheck](vars/shellCheck.groovy)
12421243

1244+
# Trivy
1245+
1246+
Scan container images for vulnerabilities with Trivy.
1247+
1248+
## Create a Trivy object
1249+
1250+
```groovy
1251+
Trivy trivy = new Trivy(this)
1252+
// With specific Trivy version
1253+
Trivy trivy = new Trivy(this, "0.57.1")
1254+
// With specific Trivy image
1255+
Trivy trivy = new Trivy(this, "0.57.1", "images.mycompany.test/trivy")
1256+
// With explicit Docker registry
1257+
Docker docker = new Docker(this)
1258+
docker.withRegistry("https://my.registry.invalid", myRegistryCredentialsID)
1259+
Trivy trivy = new Trivy(this, "0.57.1", "aquasec/trivy", docker)
1260+
```
1261+
1262+
## Scan image with Trivy
1263+
1264+
Scan an image with Trivy by calling the `scanImage` function.
1265+
1266+
```groovy
1267+
Trivy trivy = new Trivy(this)
1268+
boolean imageIsSafe = trivy.scanImage("ubuntu:24.04")
1269+
if (!imageIsSafe){
1270+
echo "This image has vulnerabilities!"
1271+
}
1272+
```
1273+
1274+
### Set the severity level for the scan
1275+
1276+
You can set the severity levels of the vulnerabilities Trivy should scan for as a parameter of the scan method:
1277+
1278+
```groovy
1279+
Trivy trivy = new Trivy(this)
1280+
trivy.scanImage("ubuntu:24.04", TrivySeverityLevel.ALL)
1281+
trivy.scanImage("ubuntu:24.04", "CRITICAL,LOW")
1282+
```
1283+
1284+
For the available pre-defined severity levels see [TrivySeverityLevel.groovy](src/com/cloudogu/ces/cesbuildlib/TrivySeverityLevel.groovy)
1285+
1286+
### Set the pipeline strategy
1287+
1288+
To define how the Jenkins pipeline should behave if vulnerabilities are found, you can set certain strategies:
1289+
- TrivyScanStrategy.IGNORE: Ignore the vulnerabilities and continue
1290+
- TrivyScanStrategy.UNSTABLE: Mark the job as "unstable" and continue
1291+
- TrivyScanStrategy.FAIL: Mark the job as failed
1292+
1293+
```groovy
1294+
Trivy trivy = new Trivy(this)
1295+
trivy.scanImage("ubuntu:24.04", TrivySeverityLevel.ALL, TrivyScanStrategy.UNSTABLE)
1296+
```
1297+
1298+
### Set additional Trivy flags
1299+
1300+
To set additional Trivy command flags, use the `additionalFlags` parameter:
1301+
1302+
```groovy
1303+
Trivy trivy = new Trivy(this)
1304+
trivy.scanImage("ubuntu:24.04", TrivySeverityLevel.ALL, TrivyScanStrategy.UNSTABLE, "--db-repository public.ecr.aws/aquasecurity/trivy-db")
1305+
```
1306+
1307+
Note that the flags `--db-repository public.ecr.aws/aquasecurity/trivy-db --java-db-repository public.ecr.aws/aquasecurity/trivy-java-db`
1308+
are set by default to avoid rate limiting of Trivy database downloads. If you set `additionalFlags` by yourself, you are overwriting
1309+
these default flags and have to make sure to include them in your set of additional flags, if needed.
1310+
1311+
### Set the Trivy report file name
1312+
1313+
If you want to run multiple image scans in one pipeline, you can set distinct file names for the report files:
1314+
1315+
```groovy
1316+
Trivy trivy = new Trivy(this)
1317+
trivy.scanImage("ubuntu:20.04", TrivySeverityLevel.ALL, TrivyScanStrategy.UNSTABLE, "", "trivy/ubuntu20.json")
1318+
trivy.scanImage("ubuntu:24.04", TrivySeverityLevel.ALL, TrivyScanStrategy.UNSTABLE, "", "trivy/ubuntu24.json")
1319+
// Save report by using the same file name (last parameter)
1320+
trivy.saveFormattedTrivyReport(TrivyScanFormat.HTML, "UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL", "ubuntu20.04report", "trivy/ubuntu20.json")
1321+
```
1322+
1323+
## Save Trivy report in another file format
1324+
1325+
After calling the `scanImage` function you can save the scan report as JSON, HTML or table files.
1326+
1327+
```groovy
1328+
Trivy trivy = new Trivy(this)
1329+
trivy.scanImage("ubuntu:24.04")
1330+
trivy.saveFormattedTrivyReport(TrivyScanFormat.TABLE)
1331+
trivy.saveFormattedTrivyReport(TrivyScanFormat.JSON)
1332+
trivy.saveFormattedTrivyReport(TrivyScanFormat.HTML)
1333+
```
1334+
1335+
You may filter the output to show only specific severity levels (default: `"UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL"`):
1336+
1337+
```groovy
1338+
Trivy trivy = new Trivy(this)
1339+
trivy.scanImage("ubuntu:24.04")
1340+
trivy.saveFormattedTrivyReport(TrivyScanFormat.TABLE, "CRITICAL")
1341+
trivy.saveFormattedTrivyReport(TrivyScanFormat.JSON, "UNKNOWN,LOW,MEDIUM")
1342+
```
1343+
1344+
You may also use any other supported [Trivy format](https://trivy.dev/v0.57/docs/references/configuration/cli/trivy_convert/) or a custom template from a file in your workspace.
1345+
1346+
```groovy
1347+
Trivy trivy = new Trivy(this)
1348+
trivy.scanImage("ubuntu:24.04")
1349+
trivy.saveFormattedTrivyReport("cosign-vuln", "UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL", "ubuntu24.04cosign.txt")
1350+
trivy.saveFormattedTrivyReport("template --template @myTemplateFile.xyz", "UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL", "ubuntu24.04myTemplate.txt")
1351+
```
1352+
1353+
## Scan Dogu image with Trivy
1354+
1355+
This section describes how to get a Dogu image from the testing CES instance and scan it with Trivy.
1356+
1357+
### Get Dogu image from CES instance
1358+
1359+
Make sure to have a `build` stage in your Dogu test pipeline which builds the Dogu image, e.g. via
1360+
the `ecoSystem.build("/dogu")` command.
1361+
After the build stage you will be able to copy the Dogu image to your local Jenkins worker via
1362+
the `ecoSystem.copyDoguImageToJenkinsWorker("/dogu")` command.
1363+
1364+
### Scan Dogu image
1365+
1366+
The `scanDogu()` function lets you scan a Dogu image without typing its full name. The method reads the image name
1367+
and version from the dogu.json inside the directory you point it to via its first argument.
1368+
The default directory is the current directory.
1369+
1370+
```groovy
1371+
// Preparation
1372+
ecoSystem.copyDoguImageToJenkinsWorker("/dogu")
1373+
Trivy trivy = new Trivy(this)
1374+
1375+
// Scan the Dogu image
1376+
trivy.scanDogu()
1377+
// Explicitly set directory that contains the dogu code (dogu.json)
1378+
trivy.scanDogu("subfolder/test1/jenkins")
1379+
// Set scan options just like in the scanImage method
1380+
trivy.scanDogu(".", TrivySeverityLevel.ALL, TrivyScanStrategy.UNSTABLE, "", "trivy/mydogu.json")
1381+
trivy.saveFormattedTrivyReport(TrivyScanFormat.TABLE)
1382+
trivy.saveFormattedTrivyReport(TrivyScanFormat.JSON)
1383+
trivy.saveFormattedTrivyReport(TrivyScanFormat.HTML)
1384+
```
1385+
1386+
## Ignore / allowlist
1387+
1388+
If you want to ignore / allow certain vulnerabilities, please use a `.trivyignore` file.
1389+
1390+
Provide the file in your repo `/` directory where you run your job, e.g.:
1391+
1392+
```shell
1393+
.gitignore
1394+
Jenkinsfile
1395+
.trivyignore
1396+
```
1397+
1398+
[Offical documentation](https://trivy.dev/v0.57/docs/configuration/filtering/#by-finding-ids)
1399+
```ignorelang
1400+
# Accept the risk
1401+
CVE-2018-14618
1402+
1403+
# Accept the risk until 2023-01-01
1404+
CVE-2019-14697 exp:2023-01-01
1405+
1406+
# No impact in our settings
1407+
CVE-2019-1543
1408+
1409+
# Ignore misconfigurations
1410+
AVD-DS-0002
1411+
1412+
# Ignore secrets
1413+
generic-unwanted-rule
1414+
aws-account-id
1415+
```
1416+
12431417
# Steps
12441418

12451419
## mailIfStatusChanged
@@ -1293,7 +1467,9 @@ For example, if running on `http(s)://server:port/jenkins`, `server` is returned
12931467

12941468
Returns true if the build is successful, i.e. not failed or unstable (yet).
12951469

1296-
## findVulnerabilitiesWithTrivy
1470+
## findVulnerabilitiesWithTrivy (Deprecated)
1471+
1472+
This function is deprecated. Use [Trivy](#trivy) functionality instead.
12971473

12981474
Returns a list of vulnerabilities or an empty list if there are no vulnerabilities for the given severity.
12991475

@@ -1330,36 +1506,7 @@ node {
13301506
}
13311507
```
13321508

1333-
### Ignore / allowlist
1334-
1335-
If you want to ignore / allow certain vulnerabilities please use a .trivyignore file
1336-
Provide the file in your repo / directory where you run your job
1337-
e.g.:
1338-
```shell
1339-
.gitignore
1340-
Jenkinsfile
1341-
.trivyignore
1342-
```
1343-
1344-
[Offical documentation](https://aquasecurity.github.io/trivy/v0.41/docs/configuration/filtering/#by-finding-ids)
1345-
```ignorelang
1346-
# Accept the risk
1347-
CVE-2018-14618
13481509

1349-
# Accept the risk until 2023-01-01
1350-
CVE-2019-14697 exp:2023-01-01
1351-
1352-
# No impact in our settings
1353-
CVE-2019-1543
1354-
1355-
# Ignore misconfigurations
1356-
AVD-DS-0002
1357-
1358-
# Ignore secrets
1359-
generic-unwanted-rule
1360-
aws-account-id
1361-
1362-
```
13631510

13641511
If there are vulnerabilities the output looks as follows.
13651512

docs/development/development_en.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,13 @@ Run
2121
```
2222

2323
Then right-click tests in IntelliJ and run.
24+
25+
# Update Maven Version
26+
27+
Use this line to update the mvnw command with your desired version:
28+
29+
```bash
30+
./mvnw -N wrapper:wrapper -Dmaven=3.9.9
31+
```
32+
33+
This will change the mvnw-File and the mvnw.cmd-File.

0 commit comments

Comments
 (0)