Skip to content

Commit 5b57c28

Browse files
authored
Fix vulnerability scanner not working in the GitHub actions CI and make it less strict (#772)
* Make vulnerability scanner accept new image versions when they have an equal amount of vulnerabilities as the old version * Check origin/master instead of master when getting allowed images, so we don't crash in the CI
1 parent 5a4e6a9 commit 5b57c28

File tree

1 file changed

+7
-11
lines changed
  • tests/tck-build-logic/src/main/java/org/graalvm/internal/tck

1 file changed

+7
-11
lines changed

tests/tck-build-logic/src/main/java/org/graalvm/internal/tck/GrypeTask.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
package org.graalvm.internal.tck;
22

3-
import com.fasterxml.jackson.annotation.JsonInclude;
43
import com.fasterxml.jackson.core.JsonFactory;
54
import com.fasterxml.jackson.core.JsonParser;
6-
import com.fasterxml.jackson.core.type.TypeReference;
75
import com.fasterxml.jackson.databind.ObjectMapper;
8-
import com.fasterxml.jackson.databind.SerializationFeature;
9-
import org.graalvm.internal.tck.model.MetadataIndexEntry;
106
import org.graalvm.internal.tck.model.grype.GrypeEntry;
117
import org.gradle.api.DefaultTask;
128
import org.gradle.api.tasks.TaskAction;
@@ -61,8 +57,8 @@ public boolean isVulnerableImage() {
6157
return vulnerabilities.critical() > 0 || vulnerabilities.high() > 0;
6258
}
6359

64-
public boolean isLessVulnerable(DockerImage other) {
65-
return this.vulnerabilities.critical() < other.vulnerabilities().critical() && this.vulnerabilities.high() < other.vulnerabilities().high();
60+
public boolean isNotMoreVulnerable(DockerImage other) {
61+
return this.vulnerabilities.critical() <= other.vulnerabilities().critical() && this.vulnerabilities.high() <= other.vulnerabilities().high();
6662
}
6763

6864
public void printVulnerabilityStatus() {
@@ -95,7 +91,7 @@ private void scanAllImages() {
9591

9692
/**
9793
* Scans images that have been changed between org.graalvm.internal.tck.GrypeTask#baseCommit and org.graalvm.internal.tck.GrypeTask#newCommit.
98-
* If changed images are less vulnerable than previously allowed images, they won't be reported as vulnerable
94+
* If changed images are not more vulnerable than previously allowed images, they won't be reported as vulnerable
9995
*/
10096
private void scanChangedImages() throws IOException, URISyntaxException {
10197
Set<DockerImage> imagesToCheck = getChangedImages().stream().map(this::makeDockerImage).collect(Collectors.toSet());
@@ -113,13 +109,13 @@ private void scanChangedImages() throws IOException, URISyntaxException {
113109
.filter(allowedImage -> DockerUtils.getImageName(allowedImage).equalsIgnoreCase(image.getImageName()))
114110
.findFirst();
115111

116-
// check if a new image is less vulnerable than the existing one
112+
// check if a new image is not more vulnerable than the existing one
117113
if (existingAllowedImage.isPresent()) {
118114
DockerImage imageToCompare = makeDockerImage(existingAllowedImage.get());
119115
imageToCompare.printVulnerabilityStatus();
120116

121-
if (image.isLessVulnerable(imageToCompare)) {
122-
System.out.println("Accepting: " + image.image() + " because it has less vulnerabilities than existing: " + imageToCompare.image());
117+
if (image.isNotMoreVulnerable(imageToCompare)) {
118+
System.out.println("Accepting: " + image.image() + " because it does not have more vulnerabilities than existing: " + imageToCompare.image());
123119
acceptedImages++;
124120
}
125121
}
@@ -229,7 +225,7 @@ private Set<String> getAllowedImagesFromMaster() throws URISyntaxException, IOEx
229225
ByteArrayOutputStream baos = new ByteArrayOutputStream();
230226
getExecOperations().exec(spec -> {
231227
spec.setStandardOutput(baos);
232-
spec.commandLine("git", "show", "master:tests/tck-build-logic/src/main/resources" + file);
228+
spec.commandLine("git", "show", "origin/master:tests/tck-build-logic/src/main/resources" + file);
233229
});
234230

235231
allowedImages.add(baos.toString());

0 commit comments

Comments
 (0)