Skip to content
Snippets Groups Projects

Adherence check - Static Application Security Testing (SAST)

Merged Hitesh Raghuvanshi requested to merge 440722-sast-adherence into master

What does this MR do and why?

This MR adds adherence check whenever a SAST scan runs on the default branch of a repository.

Hows does it do it?

  1. Whenever a SAST scanner runs in a pipeline, it creates a job artifact object.
  2. In the service for creation of job artifacts, we are checking if the file type for the artifact is sast and if the pipeline of the artifact belongs to the default branch of the repository then create the adherence check for the scan.

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

How to set up and validate locally

  1. You need to have a group with Ultimate license, let's say the name of the group is test-group.
  2. Enable the feature flag by running Feature.enable(:enable_adherence_check_for_scanners) in the rails console.
  3. Create a project in the group, I have created a reference project https://gitlab.com/issue-reproduce/hraghuvanshi-group/sast_adherence_test, you can also clone the contents of this project in your test project. I contains all the required file including pipeline configuration.
  4. You should have a ruby file in your project for sast run and sast scanner config in your project's pipeline config.
  5. Once the pipeline for this project completes running, an adherence check for the sast scan will be created which you can check by running Projects::ComplianceStandards::Adherence.where(project_id: <project_id>).last in the rails console.
  6. Scenarios:
    1. Create a merge request for your project and make sure the pipeline completes. On checking
      1. Projects::ComplianceStandards::Adherence.where(project_id: <project_id>).last in rails console, the updated_at time should be same before the pipeline of merge request starts, which means the adherence check should not be created or updated for non-default branches.
      2. Merge the merge request in the default branch and once the pipeline for merge finishes, updated_at time should get updated.
  7. You can also check the refresh adherence checks mutation for refreshing the adherence checks for a group's projects. The mutation is as follows, it will update the time of the last status change of the checks:
mutation runStandardsAdherenceChecks {
  refreshStandardsAdherenceChecks(input: {groupPath: "pipeline_testing"}) {
    adherenceChecksStatus {
      startedAt,
      totalChecks,
      checksCompleted
    }
  }
}

Related to #440722 (closed)

Edited by Hitesh Raghuvanshi

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
11 11 override :track_artifact_uploader
12 12 def track_artifact_uploader(artifact)
13 13 super
14 return unless artifact.file_type == 'metrics'
14 return unless artifact.file_type == 'metrics' || artifact.file_type == 'sast'
15 15
16 track_usage_event(METRICS_REPORT_UPLOAD_EVENT_NAME, job.user_id)
16 if artifact.file_type == 'sast'
  • Hitesh Raghuvanshi added 3477 commits

    added 3477 commits

    Compare with previous version

  • added 1 commit

    • 23aabbc9 - Removed incomplete rspec and refactored

    Compare with previous version

  • Hitesh Raghuvanshi
  • Hitesh Raghuvanshi changed the description

    changed the description

  • Huzaifa Iftikhar
  • Hitesh Raghuvanshi changed milestone to %17.5

    changed milestone to %17.5

  • Hitesh Raghuvanshi added 529 commits

    added 529 commits

    Compare with previous version

  • added 1 commit

    Compare with previous version

  • A deleted user added feature flag label

    added feature flag label

  • Hitesh Raghuvanshi added 474 commits

    added 474 commits

    Compare with previous version

  • added 1 commit

    Compare with previous version

  • Hitesh Raghuvanshi added 217 commits

    added 217 commits

    Compare with previous version

  • added 3 commits

    • 30b7c7a8 - Added test cases
    • 4186e1ed - Added graphql doc
    • 2a821881 - Fixed rubocop offence

    Compare with previous version

  • added 33 commits

    Compare with previous version

  • added 1 commit

    • fb4e04c3 - Adding adherence check for sast scanner run

    Compare with previous version

  • Hitesh Raghuvanshi marked this merge request as ready

    marked this merge request as ready

  • Hitesh Raghuvanshi changed title from Draft: Resolve "Adherence check - Static Application Security Testing (SAST)" to Adherence check - Static Application Security Testing (SAST)

    changed title from Draft: Resolve "Adherence check - Static Application Security Testing (SAST)" to Adherence check - Static Application Security Testing (SAST)

  • Hitesh Raghuvanshi changed the description

    changed the description

  • requested review from @craigmsmith

  • Craig Smith removed review request for @craigmsmith

    removed review request for @craigmsmith

  • Craig Smith requested review from @hyan3

    requested review from @hyan3

  • Hua Yan
  • Hua Yan
  • Hitesh Raghuvanshi added 715 commits

    added 715 commits

    Compare with previous version

  • added 2 commits

    • 0f7b77a2 - Refactored the code around feature flag
    • 8f267671 - Fixed lint issues

    Compare with previous version

  • Hitesh Raghuvanshi added 270 commits

    added 270 commits

    Compare with previous version

  • added 1 commit

    Compare with previous version

  • mentioned in issue #467082

  • mentioned in issue #440721 (closed)

  • mentioned in issue #440720

  • mentioned in issue #440718

  • mentioned in issue #440717

  • mentioned in issue #440715

  • Hua Yan approved this merge request

    approved this merge request

  • added pipelinetier-2 label and removed pipelinetier-1 label

  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Please register or sign in to reply
    Loading