Skip to content
Snippets Groups Projects

Add security bot comment for policy violations in MRs

What does this MR do and why?

This MR adds security bot comments for policy violations in MRs.

This change introduces an automatic comments on the MRs where security policy violations are detected. It adds guidance for the user on what to do next with regards to the needed approvals.

The comments are created by security bot. We may switch to a dedicated security policy bot from #394958 (closed), but for the moment, we plan to test this feature with the security bot.

This feature is added behind a feature flag.

Screenshots or screen recordings

With violations:

CleanShot_2023-06-06_at_19.01.36_2x

Resolved violations:

CleanShot_2023-06-06_at_19.05.47_2x

Recording:

lightweight_bot_comment

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

  1. Enable the feature flags in the rails console:

    Feature.enable(:security_policy_approval_notification)
  2. Add secret detection template into .gitlab-ci.yml:

    include:
      - template: Jobs/Secret-Detection.gitlab-ci.yml
    test-job:
      script:
      - echo "Test Job..."
  3. Create a new project with a security policy. Example:

    type: scan_result_policy
    name: Secrets
    description: ''
    enabled: true
    rules:
      - type: scan_finding
        branches: []
        scanners:
          - secret_detection
        vulnerabilities_allowed: 0
        severity_levels:
          - critical
          - high
          - medium
          - low
          - unknown
          - info
        vulnerability_states:
          - new_needs_triage
          - new_dismissed
    actions:
      - type: require_approval
        approvals_required: 1
        user_approvers_ids:
          - 4
  4. Introduce a policy violation in an MR - for example, add a secret which would trigger secret detection scanner from a policy.

  5. After the CI has finished, observe an automatic comment being added.

  6. Add a new commit which doesn't fix the violation yet. There shouldn't be any new automatic comment.

  7. Add a new commit, fixing the violation.

  8. The comment should get updated and say that violations have been fixed.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #411656 (closed)

Edited by Martin Čavoj

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
  • Martin Čavoj added 899 commits

    added 899 commits

    Compare with previous version

  • Martin Čavoj changed title from Add security policy bot comment for policy violations in MRs to Add security bot comment for policy violations in MRs

    changed title from Add security policy bot comment for policy violations in MRs to Add security bot comment for policy violations in MRs

  • Martin Čavoj changed the description

    changed the description

  • Martin Čavoj added 1 commit

    added 1 commit

    • 5016c40e - Add security bot comment for policy violations in MRs

    Compare with previous version

  • Martin Čavoj added 1 commit

    added 1 commit

    • 7e0335c4 - Add security bot comment for policy violations in MRs

    Compare with previous version

  • Martin Čavoj requested review from @Andysoiron

    requested review from @Andysoiron

  • Martin Čavoj changed the description

    changed the description

  • Martin Čavoj added 1 commit

    added 1 commit

    • d81482e9 - Add security bot comment for policy violations in MRs

    Compare with previous version

  • Andy Schoenen resolved all threads

    resolved all threads

  • Andy Schoenen
  • Andy Schoenen
  • Andy Schoenen
  • Andy Schoenen removed review request for @Andysoiron

    removed review request for @Andysoiron

  • Martin Čavoj changed the description

    changed the description

  • Martin Čavoj
  • Martin Čavoj requested review from @rdickenson

    requested review from @rdickenson

  • Martin Čavoj added 1 commit

    added 1 commit

    • d4bc812e - Add security bot comment for policy violations in MRs

    Compare with previous version

  • Martin Čavoj requested review from @Andysoiron

    requested review from @Andysoiron

  • Russell Dickenson approved this merge request

    approved this merge request

  • :wave: @rdickenson, thanks for approving this merge request.

    This is the first time the merge request is approved. To ensure full test coverage, a new pipeline will be started shortly.

    For more info, please refer to the following links:

  • Russell Dickenson unapproved this merge request

    unapproved this merge request

  • Martin Čavoj added 457 commits

    added 457 commits

    Compare with previous version

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