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

Fail the release manager pipeline and create security vulnerability issues or move them to TODO state if already present #1151

Merged
Show file tree
Hide file tree
Changes from 139 commits
Commits
Show all changes
165 commits
Select commit Hold shift + click to select a range
a157206
EDPC-2338 Log message and create security vulnerability issue.
Jul 23, 2024
9abf6d1
EDPC-2338 Log message and create security vulnerability issue.
Jul 23, 2024
8ccaf83
EDPC-2338 Log message and create security vulnerability issue.
Jul 23, 2024
29338e2
EDPC-2338 Log message and create security vulnerability issue.
Jul 23, 2024
d33fb22
EDPC-2338 Log message and create security vulnerability issue.
Jul 23, 2024
fea1bde
EDPC-2338 Log message and create security vulnerability issue.
Jul 23, 2024
225ea1c
EDPC-2338 Log message and create security vulnerability issue.
Jul 23, 2024
e5febf7
EDPC-2338 Log message and create security vulnerability issue.
Jul 23, 2024
67a3deb
EDPC-2338 Log message and create security vulnerability issue.
Jul 23, 2024
1c09b55
EDPC-2338 Log message and create security vulnerability issue.
Jul 23, 2024
c769471
EDPC-2338 Log message and create security vulnerability issue.
Jul 24, 2024
a7c6004
EDPC-2338 Log message and create security vulnerability issue.
Jul 24, 2024
7ae1a25
EDPC-2338 Log message and create security vulnerability issue.
Jul 24, 2024
20a54e4
EDPC-2338 Log message and create security vulnerability issue.
Jul 24, 2024
84f0d7d
EDPC-2338 Log message and create security vulnerability issue.
Jul 24, 2024
7d3a1f7
EDPC-2338 Add max transition limiter.
Jul 24, 2024
4c712b3
EDPC-2338 Add max transition limiter.
Jul 24, 2024
1675da5
EDPC-2338 Add max transition limiter.
Jul 24, 2024
bf21b2f
EDPC-2338 Add max transition limiter.
Jul 24, 2024
631c508
EDPC-2338 Remove logs.
Jul 24, 2024
13a2e82
EDPC-2338 Transition the first issue found.
Jul 24, 2024
f2b4a73
EDPC-2338 Fix method call.
Jul 24, 2024
fdc31b1
EDPC-2338 Remove logger.
Jul 24, 2024
680c24a
Log aqua json.
Jul 29, 2024
a6b2963
EDPC-2334 Fail pipeline in case of remote critical with solution vuln…
Jul 31, 2024
b050678
EDPC-2334 Fail pipeline in case of remote critical with solution vuln…
Jul 31, 2024
058fb71
EDPC-2334 Fail pipeline in case of remote critical with solution vuln…
Jul 31, 2024
41102d0
EDPC-2334 Fail pipeline in case of remote critical with solution vuln…
Jul 31, 2024
bbe2780
EDPC-2334 Fail pipeline in case of remote critical with solution vuln…
Jul 31, 2024
22a154d
EDPC-2334 Test pipeline failure.
Aug 1, 2024
81a2832
EDPC-2334 Test pipeline failure.
Aug 1, 2024
ec0806a
EDPC-2334 Test pipeline failure.
Aug 3, 2024
4a56e8b
EDPC-2334 Test pipeline failure.
Aug 3, 2024
0e25e4c
EDPC-2334 Test pipeline failure.
Aug 3, 2024
3111d55
EDPC-2334 Test pipeline failure.
Aug 3, 2024
bb9ae40
EDPC-2334 Test pipeline failure.
Aug 3, 2024
4becefc
EDPC-2334 Test pipeline failure.
Aug 3, 2024
6978417
EDPC-2334 Test pipeline failure.
Aug 3, 2024
2cfdee9
EDPC-2334 Test pipeline failure.
Aug 3, 2024
3c5cb1b
EDPC-2334 Test pipeline failure.
Aug 3, 2024
603036a
EDPC-2334 Test pipeline failure.
Aug 3, 2024
8663fae
EDPC-2334 Test pipeline failure.
Aug 3, 2024
bd377e9
EDPC-2334 Test pipeline failure.
Aug 3, 2024
ca4004e
EDPC-2334 Test pipeline failure.
Aug 3, 2024
bfef8c4
EDPC-2334 Test pipeline failure.
Aug 3, 2024
e5b8353
EDPC-2334 Test pipeline failure.
Aug 3, 2024
b4497de
EDPC-2334 Test pipeline failure.
Aug 3, 2024
1e0b4e1
EDPC-2334 Test pipeline failure.
Aug 3, 2024
6fa64a3
EDPC-2334 Test pipeline failure.
Aug 5, 2024
b9875c2
EDPC-2334 Test pipeline failure.
Aug 5, 2024
f215e3a
EDPC-2334 Test pipeline failure.
Aug 5, 2024
6cb3e0b
EDPC-2334 Test pipeline failure.
Aug 5, 2024
0f4a06f
EDPC-2334 Test pipeline failure.
Aug 5, 2024
eadea9b
EDPC-2334 Test pipeline failure.
Aug 5, 2024
980c931
EDPC-2334 Test Bitbucket code insight report.
Aug 5, 2024
78e262b
EDPC-2334 Test Bitbucket code insight report.
Aug 6, 2024
10506d0
EDPC-2334 Removed unused code.
Aug 6, 2024
cea5bba
EDPC-2334 Removed unused code.
Aug 6, 2024
2c82f84
EDPC-2334 Removed unused code.
Aug 7, 2024
684c691
EDPC-2334 Fix Bitbucket blocking message.
Aug 7, 2024
40b2a80
EDPC-2334 Send conde insight report.
Aug 8, 2024
dc3f37a
EDPC-2334 Send code insight report.
Aug 8, 2024
8f209b5
EDPC-2334 Send code insight report.
Aug 8, 2024
3d1b504
EDPC-2334 Send code insight report.
Aug 8, 2024
a0cb052
EDPC-2333 Small fixes.
Aug 8, 2024
080ac96
Merge branch 'refs/heads/master_ods' into test-aqua
Aug 8, 2024
b3e369d
EDPC-2333 Small fixes.
Aug 8, 2024
837a49c
EDPC-2333 Small fixes.
Aug 8, 2024
87a8122
EDPC-2333 Small fixes.
Aug 8, 2024
0fdd183
EDPC-2333 Small fixes.
Aug 8, 2024
b7ee1a9
EDPC-2333 Small fixes.
Aug 8, 2024
76d6088
EDPC-2333 Small fixes.
Aug 8, 2024
a9c7ebe
EDPC-2333 Small fixes.
Aug 8, 2024
6e56020
Update changelog.
Aug 8, 2024
ae73366
Update changelog.
Aug 8, 2024
061858c
Fix PR comments.
Aug 12, 2024
081fa62
Remove log.
Aug 12, 2024
7dc4047
Fix test.
Aug 12, 2024
876524a
Fix adoc rendering.
Aug 12, 2024
8f882d6
Fix adoc rendering.
Aug 12, 2024
f6b0951
Merge branch 'refs/heads/test-aqua' into feature/EDPC-2338_fail_rm_an…
Aug 12, 2024
5acd4c5
Update security issue name.
Aug 13, 2024
7cf0999
Remove "set pipeline unstable".
Aug 13, 2024
aa1dc2a
Merge branch 'refs/heads/test-aqua' into feature/EDPC-2338_fail_rm_an…
Aug 13, 2024
cc032aa
Update actionable vulnerabilities message.
Aug 13, 2024
a4f0a6a
Update actionable vulnerabilities message.
Aug 13, 2024
3a865cc
Update security vulnerabilities issue.
Aug 13, 2024
93843a4
Update security vulnerabilities issue.
Aug 13, 2024
f4e5bf4
Update security vulnerabilities issue.
Aug 13, 2024
f687a3a
Update security vulnerability issue creation.
Aug 16, 2024
33b2506
Update security vulnerability issue creation.
Aug 16, 2024
876cfd2
Update security vulnerability issue creation.
Aug 16, 2024
91b5f7f
Merge branch 'refs/heads/master_ods' into feature/EDPC-2338_fail_rm_a…
Aug 27, 2024
832a1a9
Update security vulnerability issue creation.
Aug 27, 2024
25da6a9
Fix components field in API.
Aug 27, 2024
597a672
Update issue description.
Aug 27, 2024
5cc08f2
Update issue description.
Aug 27, 2024
f99e0fa
Update issue description.
Aug 27, 2024
a587059
Fix pipeline failure for Deploy to D.
Aug 27, 2024
043d205
Update aqua log and jira message.
Aug 27, 2024
654f026
Update aqua log and jira message.
Aug 27, 2024
bb1cb4b
Update aqua log and jira message.
Aug 28, 2024
f8592b2
Update issue transitioning.
Aug 28, 2024
5292082
Update issue transitioning.
Aug 28, 2024
6db1543
Remove log.
Aug 28, 2024
66dcd0f
Fix codenarc violations.
Aug 28, 2024
343fafb
Update tests and add changelog entry.
Aug 28, 2024
5d4b5fc
Add report link to jenkins log.
Aug 28, 2024
1a5c227
Debug.
Aug 28, 2024
203cdcd
Debug.
Aug 28, 2024
4c88b82
Set priority High for security vulnerability issue.
Aug 29, 2024
4f13cb9
Set priority High for security vulnerability issue.
Aug 29, 2024
d8f6808
Update tests.
Aug 29, 2024
7caf7ec
Update jira message.
Aug 29, 2024
0693e26
Update jira message.
Aug 29, 2024
33ba171
Update jira message.
Aug 29, 2024
8606b33
Fix codenarc violations.
Aug 29, 2024
9209088
Debug.
Aug 30, 2024
adc3a55
Debug.
Aug 30, 2024
b5d6e7f
Add PRs to log message.
Sep 3, 2024
5b0bb45
Add PRs to log message.
Sep 3, 2024
8775de0
Add PRs to log message.
Sep 3, 2024
c01c8a2
Add PRs to log message.
Sep 3, 2024
d9f2595
Debug.
Sep 3, 2024
f5a73a6
Debug.
Sep 3, 2024
ca4fbab
Debug.
Sep 3, 2024
702a49c
Fix tests.
Sep 3, 2024
2dda45f
Fix tests.
Sep 3, 2024
b12a050
Fix codenarc level 2 violations.
Sep 4, 2024
25715b0
Fix PR comments.
Sep 4, 2024
ff4f37b
Fix PR comments.
Sep 4, 2024
3bd9e49
Fix PR comments.
Sep 4, 2024
d8568c2
Fix PR comments.
Sep 4, 2024
f10ce33
Fix message comments.
Sep 12, 2024
db4c7a3
Fix message comments.
Sep 12, 2024
a5544ef
Fix message comments.
Sep 12, 2024
35f98fb
Fix message comments.
Sep 12, 2024
4588cb3
Fix codenarc violation.
Sep 13, 2024
1a4e350
Update git branch obsolete error message.
Sep 13, 2024
4734867
EDPC-2542 Fix jira use case instantiation.
Sep 16, 2024
3ff549e
EDPC-2542 Fix jira use case instantiation.
Sep 16, 2024
1ad8903
EDPC-2542 Fix jira use case instantiation.
Sep 16, 2024
6c7c78e
EDPC-2542 Fix jira use case instantiation.
Sep 16, 2024
5b6a499
EDPC-2542 Fix jira use case instantiation.
Sep 16, 2024
a300169
EDPC-2542 Fix jira use case instantiation.
Sep 16, 2024
7b74ae7
EDPC-2542 Fix jira use case instantiation.
Sep 16, 2024
8e09efb
EDPC-2542 Fix jira use case instantiation.
Sep 16, 2024
9294fb7
EDPC-2542 Fix jira use case instantiation.
Sep 16, 2024
af568ca
EDPC-2542 Fix jira use case instantiation.
Sep 16, 2024
dd200fe
EDPC-2542 Fix jira use case instantiation.
Sep 16, 2024
cc160d7
EDPC-2542 Revert.
Sep 16, 2024
2fc2755
EDPC-2542 Fix jira status update.
Sep 17, 2024
f3e5b0c
EDPC-2542 Fix jira status update.
Sep 17, 2024
c3d03f8
EDPC-2542 Revert.
Sep 17, 2024
1c46a82
EDPC-2338 Fix PR comments.
Sep 17, 2024
2feec56
EDPC-2338 Fix PR comments.
Sep 17, 2024
0b273d1
EDPC-2338 Fix PR comments.
Sep 17, 2024
48db7b0
EDPC-2338 Fix PR comments.
Sep 17, 2024
538edf5
EDPC-2542 Fix release status issue update.
Sep 18, 2024
a192b92
EDPC-2542 Fix release status issue update.
Sep 18, 2024
1d27d0a
EDPC-2542 Fix release status issue update.
Sep 18, 2024
02ff6c9
EDPC-2542 Fix PR comments.
Sep 19, 2024
d39e45c
EDPC-2542 Fix PR comments.
Sep 19, 2024
e2ce6f8
EDPC-2542 Fix PR comments.
Sep 19, 2024
ff78bb2
EDPC-2542 Fix PR comments.
Sep 19, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased
* Fail builds when aqua scan detects remotely exploitable security vulnerabilities with solutions ([#1147](https://github.com/opendevstack/ods-jenkins-shared-library/pull/1147))
* Fail the release manager pipeline and create security vulnerability issues or move them to TODO state if already present ([#1151](https://github.com/opendevstack/ods-jenkins-shared-library/pull/1151))

### Added
* In the release manager pipeline, use the default integration branch for component ([#1144](https://github.com/opendevstack/ods-jenkins-shared-library/pull/1144))
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ codenarc {
toolVersion = '1.6'
configFile = file('codenarc.groovy')
maxPriority1Violations = 0
maxPriority2Violations = 1
maxPriority2Violations = 0
maxPriority3Violations = 300
reportFormat = 'html'
}
Expand Down
80 changes: 76 additions & 4 deletions src/org/ods/component/ScanWithAquaStage.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ class ScanWithAquaStage extends Stage {
errorMessages += "<li>Error executing Aqua CLI</li>"
}
List actionableVulnerabilities = null
String nexusReportLink = null
// If report exists
if ([AquaService.AQUA_SUCCESS, AquaService.AQUA_POLICIES_ERROR].contains(returnCode)) {
try {
Expand All @@ -121,7 +122,8 @@ class ScanWithAquaStage extends Stage {
vulnerabilities.malware ?: 0]

URI reportUriNexus = archiveReportInNexus(reportFile, nexusRepository)
createBitbucketCodeInsightReport(url, nexusRepository ? reportUriNexus.toString() : null,
nexusReportLink = nexusRepository ? reportUriNexus.toString() : null
createBitbucketCodeInsightReport(url, nexusReportLink,
registry, imageRef, errorCodes.sum() as int, errorMessages, actionableVulnerabilities)
archiveReportInJenkins(!context.triggeredByOrchestrationPipeline, reportFile)
} catch (err) {
valituguran marked this conversation as resolved.
Show resolved Hide resolved
valituguran marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -135,16 +137,86 @@ class ScanWithAquaStage extends Stage {
notifyAquaProblem(alertEmails, errorMessages)

if (actionableVulnerabilities?.size() > 0) { // We need to mark the pipeline and delete the image
context.addArtifactURI('aquaCriticalVulnerability', 'true')
addAquaVulnerabilityObjectsToContext(actionableVulnerabilities, nexusReportLink)
String response = openShift.deleteImage(context.getComponentId() + ":" + context.getShortGitCommit())
logger.debug("Delete image response: " + response)
throw new AquaRemoteCriticalVulnerabilityWithSolutionException("Vulnerabilities found: " +
actionableVulnerabilities)
throw new AquaRemoteCriticalVulnerabilityWithSolutionException(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Who catches this exception? What is its purpose? You don't need an exception if it's just to log the message. Let's discuss it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to decide what we log and when.

buildActionableMessageForAquaVulnerabilities(actionableVulnerabilities: actionableVulnerabilities,
nexusReportLink: nexusReportLink, gitUrl: context.getGitUrl(), gitBranch: context.getGitBranch(),
gitCommit: context.getGitCommit(), repoName: context.getRepoName()))
}

return
}

private void addAquaVulnerabilityObjectsToContext(List actionableVulnerabilities, String nexusReportLink) {
context.addArtifactURI('aquaCriticalVulnerability', actionableVulnerabilities)
context.addArtifactURI('jiraComponentId', context.getComponentId())
context.addArtifactURI('gitUrl', context.getGitUrl())
context.addArtifactURI('gitBranch', context.getGitBranch())
context.addArtifactURI('repoName', context.getRepoName())
context.addArtifactURI('nexusReportLink', nexusReportLink)
}

private String buildActionableMessageForAquaVulnerabilities(Map args) {
StringBuilder message = new StringBuilder();
message.append("We detected remotely exploitable critical vulnerabilities in ${args.gitUrl} " +
"in branch \"${args.gitBranch}\". Due to their high severity, we must stop the delivery " +
"process until all vulnerabilities have been addressed. ")

message.append("\n\nThe following vulnerabilities were found:\n");
def count= 1;
for (def vulnerability : args.actionableVulnerabilities) {
message.append("\n${count}. Vulnerability name: " + (vulnerability as Map).name as String)
message.append("\n${count}.1. Description: " + (vulnerability as Map).description as String)
message.append("\n${count}.2. Solution: " + (vulnerability as Map).solution as String)
message.append("\n")
count++
}
def openPRs = getOpenPRsForCommit(args.gitCommit as String, args.repoName as String)
if (openPRs.size() > 0) {
message.append("\nThis commit exists in the following open pull requests: ")
def cnt = 1
for (def pr : openPRs) {
message.append("\n${cnt}. Pull request: " + (pr as Map).title as String)
message.append("\n${cnt}.1. Link: " + (pr as Map).link as String)
message.append("\n")
cnt++
}
}
if (args.nexusReportLink != null) {
message.append("\nYou can find the complete security scan report here: ${args.nexusReportLink}.\n")
}
return message.toString()
}

private List getOpenPRsForCommit(String gitCommit, String repoName) {
def apiResponse = bitbucket.getPullRequestsForCommit(repoName, gitCommit)
def prs = []
try {
def js = steps.readJSON(text: apiResponse) as Map
prs = js['values']
if (prs == null) {
throw new RuntimeException('Field "values" of JSON response must not be empty!')
}
} catch (Exception ex) {
logger.warn "Could not understand API response. Error was: ${ex}"
return []
}
def response = []
for (def i = 0; i < (prs as List).size(); i++) {
Map pr = (prs as List)[i] as Map
if (!(pr.open as Boolean)) { // We only consider Open PRs
continue
}
response.add([
title: pr.title,
link: (((pr.links as Map).self as List)[0] as Map).href
])
}
response
}

private String getImageRef() {
// take the image ref of the image that is being build in the image build stage
Map<String, String> buildInfo =
Expand Down
150 changes: 143 additions & 7 deletions src/org/ods/orchestration/BuildStage.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ class BuildStage extends Stage {

public static final String JIRA_CUSTOM_PART = 'Follow the link below'

private static final String VULNERABILITY_NAME_PLACEHOLDER = "<CVE>"

private static final String SECURITY_VULNERABILITY_ISSUE_SUMMARY = "Remotely exploitable security " +
"vulnerability with solution detected by Aqua with name " + VULNERABILITY_NAME_PLACEHOLDER

private static final String SECURITY_VULNERABILITY_ISSUE_PRIORITY = "Highest"

private static final String JIRA_COMPONENT_TECHNOLOGY_PREFIX = 'Technology-'

public final String STAGE_NAME = 'Build'

BuildStage(def script, Project project, List<Set<Map>> repos, String startMROStageName) {
Expand Down Expand Up @@ -103,17 +112,140 @@ class BuildStage extends Stage {
logMessage += buildTailorMessage(failedReposCommaSeparated, LOG_CUSTOM_PART)
jiraMessage += buildTailorMessage(failedReposCommaSeparated, JIRA_CUSTOM_PART)
}

def aquaCriticalVulnerabilityRepos = filterReposWithAquaCriticalVulnerability(repos)
if (aquaCriticalVulnerabilityRepos?.size() > 0) {
def securityVulnerabilityIssueKeys = createSecurityVulnerabilityIssues(aquaCriticalVulnerabilityRepos)
String aquaMessage = buildAquaSecurityVulnerabilityMessage(securityVulnerabilityIssueKeys)
logMessage += aquaMessage
jiraMessage += aquaMessage
}

util.failBuild(logMessage)
// If we are not in Developer Preview or we have a Tailor failure raise an exception
if (!project.isWorkInProgress || tailorFailedRepos?.size() > 0) {
// If we are not in Developer Preview or we have a Tailor failure or a Aqua remotely exploitable
// vulnerability with solution found then raise an exception
if (!project.isWorkInProgress || tailorFailedRepos?.size() > 0
|| aquaCriticalVulnerabilityRepos?.size() > 0) {
throw new IllegalStateException(jiraMessage)
}
}
def aquaCriticalVulnerabilityRepos = filterReposWithAquaCriticalVulnerability(repos)
if (aquaCriticalVulnerabilityRepos?.size() > 0) {
String aquaFiledMessage = "Aqua critical vulnerability with solution detected"
util.failBuild(aquaFiledMessage)
throw new IllegalStateException(aquaFiledMessage)
}

List createSecurityVulnerabilityIssues(List aquaCriticalVulnerabilityRepos) {
valituguran marked this conversation as resolved.
Show resolved Hide resolved
def securityVulnerabilityIssueKeys = [];
try {
for (def repo : aquaCriticalVulnerabilityRepos) {
def jiraComponentId = getJiraComponentId(repo)
for (def vulnerability : repo.data.openshift.aquaCriticalVulnerability) {
def vulerabilityMap = vulnerability as Map
def issueKey = createOrUpdateSecurityVulnerabilityIssue(
vulerabilityMap.name,
jiraComponentId,
buildSecurityVulnerabilityIssueDescription(
vulerabilityMap,
repo.data.openshift.gitUrl,
repo.data.openshift.gitBranch,
repo.data.openshift.repoName,
repo.data.openshift.nexusReportLink))
securityVulnerabilityIssueKeys.add(issueKey)
}
}
} catch (JiraNotPresentException e) {
project.logger.warn(e.getMessage())
return []
}
return securityVulnerabilityIssueKeys
}

String createOrUpdateSecurityVulnerabilityIssue(String vulnerabilityName, String jiraComponentId,
String description) {
if (!project.jiraUseCase || !project.jiraUseCase.jira) {
throw new JiraNotPresentException("JiraUseCase not present, cannot create security vulnerability issue.")
}

def issueSummary = SECURITY_VULNERABILITY_ISSUE_SUMMARY.replace(VULNERABILITY_NAME_PLACEHOLDER,
vulnerabilityName)

def fixVersion = null
if (project.isVersioningEnabled) {
fixVersion = project.getVersionName()
}
def fullJiraComponentName = JIRA_COMPONENT_TECHNOLOGY_PREFIX + jiraComponentId

List securityVulnerabilityIssues = project?.jiraUseCase?.jira?.loadJiraSecurityVulnerabilityIssues(issueSummary,
fixVersion, fullJiraComponentName, project.jiraProjectKey)
if (securityVulnerabilityIssues?.size() >= 1) { // Transition the issue to "TO DO" state
transitionIssueToToDo(securityVulnerabilityIssues.get(0).id)
return (securityVulnerabilityIssues.get(0) as Map)?.key
} else { // Create the issue
return (createIssueTypeSecurityVulnerability(fixVersion, fullJiraComponentName,
SECURITY_VULNERABILITY_ISSUE_PRIORITY, projectKey: project.jiraProjectKey, summary: issueSummary,
description: description)
as Map)?.key
}
}

Map createIssueTypeSecurityVulnerability(Map args, String fixVersion = null, String component = null,
String priority = null) {
return project?.jiraUseCase?.jira?.createIssue(fixVersion, component, priority, summary: args.summary,
type: "Security Vulnerability", projectKey: args.projectKey, description: args.description)
}


void transitionIssueToToDo(String issueId) {
int maxAttemps = 10;
while (maxAttemps-- > 0) {
def possibleTransitions = project?.jiraUseCase?.jira?.getTransitions(issueId)
valituguran marked this conversation as resolved.
Show resolved Hide resolved
Map possibleTransitionsByName = possibleTransitions
.collectEntries { t -> [t.name.toString().toLowerCase(), t] }
if (possibleTransitionsByName.containsKey("confirm dor")) { // Issue is already in TO DO state
valituguran marked this conversation as resolved.
Show resolved Hide resolved
return
} else if (possibleTransitionsByName.containsKey("implement")) { // We need to transiton the issue
project?.jiraUseCase?.jira?.doTransition(issueId, possibleTransitionsByName.get("implement"))
continue
valituguran marked this conversation as resolved.
Show resolved Hide resolved
} else if (possibleTransitionsByName.containsKey("confirm dod")) { // We need to transiton the issue
project?.jiraUseCase?.jira?.doTransition(issueId, possibleTransitionsByName.get("confirm dod"))
continue
} else if (possibleTransitionsByName.containsKey("reopen")) { // We need just one transiton
project?.jiraUseCase?.jira?.doTransition(issueId, possibleTransitionsByName.get("reopen"))
return
} else {
throw new IllegalStateException("Unexpected issue transition states " +
"found: ${possibleTransitionsByName.keySet()}")
}
}
throw new IllegalStateException("The issue could not be transitioned to TODO state.")
valituguran marked this conversation as resolved.
Show resolved Hide resolved
}

String buildSecurityVulnerabilityIssueDescription(Map vulnerability, String gitUrl, String gitBranch,
String repoName, String nexusReportLink) {
StringBuilder message = new StringBuilder()
message.append("\nAqua security scan detected the remotely exploitable critical " +
"vulnerability with name *${vulnerability.name as String}* in repository *[${repoName}|${gitUrl}]* " +
"in branch *${gitBranch}*." )
message.append("\n\n*Description:* " + vulnerability.description as String)
message.append("\n\n*Solution:* " + vulnerability.solution as String)

if (nexusReportLink != null) {
message.append("\n\nYou can find the complete security scan report *[here|${nexusReportLink}]*.")
}

return message.toString()
}

String buildAquaSecurityVulnerabilityMessage(List securityVulnerabilityIssueKeys) {
if (securityVulnerabilityIssueKeys?.size() == 0) { // No issue created as Jira is not connected
return "\n\nRemotely exploitable critical vulnerabilities were detected (see above). " +
"Due to their high severity, we must stop the delivery process until all vulnerabilities " +
"have been addressed.\n"
} else if (securityVulnerabilityIssueKeys?.size() == 1) {
return "\n\nA remotely exploitable critical vulnerability was detected and documented in " +
"the following Jira issue: ${securityVulnerabilityIssueKeys[0]}. Due to their high " +
"severity, we must stop the delivery process until all vulnerabilities have been addressed.\n"
} else {
return "\n\nRemotely exploitable critical vulnerabilities were detected and documented in " +
"the following Jira issues: ${securityVulnerabilityIssueKeys.join(", ")}. Due to their high " +
"severity, we must stop the delivery process until all vulnerabilities have been addressed.\n"
}
}

Expand Down Expand Up @@ -153,6 +285,10 @@ class BuildStage extends Stage {
return repos?.flatten()?.findAll { it -> it.data?.openshift?.aquaCriticalVulnerability }
}

String getJiraComponentId(def repo) {
return repo.data?.openshift?.jiraComponentId
}

String buildReposCommaSeparatedString(def tailorFailedRepos) {
def reposCommaSeparatedString = tailorFailedRepos
.collect { it -> "\"" + it.id + "\"" }
Expand Down
8 changes: 8 additions & 0 deletions src/org/ods/orchestration/JiraNotPresentException.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.ods.orchestration

class JiraNotPresentException extends Exception {

JiraNotPresentException(String message) {
super(message)
}
}
Loading