Skip to content

Commit

Permalink
fix: Vulnerability scanning on hibernate/unhibernate api's (#5164)
Browse files Browse the repository at this point in the history
* wip

* check added

* renaming

---------

Co-authored-by: ayushmaheshwari <ayush@devtron.ai>
Co-authored-by: Vikram Singh <vikram@devtron.ai>
Co-authored-by: Shivam-nagar23 <shivam@devtron.ai>
  • Loading branch information
4 people authored Jun 10, 2024
1 parent 2e664d6 commit b3f4f78
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions pkg/deployment/trigger/devtronApps/TriggerService.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,19 +426,21 @@ func (impl *TriggerServiceImpl) ManualCdTrigger(triggerContext bean.TriggerConte
impl.logger.Warnw("unable to migrate deprecated DataSource", "artifactId", artifact.Id)
}
}
vulnerabilityCheckRequest := adapter.GetVulnerabilityCheckRequest(cdPipeline, artifact.ImageDigest)
isVulnerable, err := impl.imageScanService.GetArtifactVulnerabilityStatus(ctx, vulnerabilityCheckRequest)
if err != nil {
impl.logger.Errorw("error in getting Artifact vulnerability status, ManualCdTrigger", "err", err)
return 0, err
}
if isNotHibernateRequest(overrideRequest.DeploymentType) {
vulnerabilityCheckRequest := adapter.GetVulnerabilityCheckRequest(cdPipeline, artifact.ImageDigest)
isVulnerable, err := impl.imageScanService.GetArtifactVulnerabilityStatus(ctx, vulnerabilityCheckRequest)
if err != nil {
impl.logger.Errorw("error in getting Artifact vulnerability status, ManualCdTrigger", "err", err)
return 0, err
}

if isVulnerable == true {
// if image vulnerable, update timeline status and return
if err = impl.cdWorkflowCommonService.MarkCurrentDeploymentFailed(runner, errors.New(pipelineConfig.FOUND_VULNERABILITY), overrideRequest.UserId); err != nil {
impl.logger.Errorw("error while updating current runner status to failed, TriggerDeployment", "wfrId", runner.Id, "err", err)
if isVulnerable == true {
// if image vulnerable, update timeline status and return
if err = impl.cdWorkflowCommonService.MarkCurrentDeploymentFailed(runner, errors.New(pipelineConfig.FOUND_VULNERABILITY), overrideRequest.UserId); err != nil {
impl.logger.Errorw("error while updating current runner status to failed, TriggerDeployment", "wfrId", runner.Id, "err", err)
}
return 0, fmt.Errorf("found vulnerability for image digest %s", artifact.ImageDigest)
}
return 0, fmt.Errorf("found vulnerability for image digest %s", artifact.ImageDigest)
}

// Deploy the release
Expand Down Expand Up @@ -537,6 +539,13 @@ func (impl *TriggerServiceImpl) ManualCdTrigger(triggerContext bean.TriggerConte
return releaseId, err
}

func isNotHibernateRequest(deploymentType models.DeploymentType) bool {
if deploymentType == models.DEPLOYMENTTYPE_STOP || deploymentType == models.DEPLOYMENTTYPE_START {
return false
}
return true
}

// TODO: write a wrapper to handle auto and manual trigger
func (impl *TriggerServiceImpl) TriggerAutomaticDeployment(request bean.TriggerRequest) error {
//in case of manual trigger auth is already applied and for auto triggers there is no need for auth check here
Expand Down

0 comments on commit b3f4f78

Please sign in to comment.