Skip to content
Snippets Groups Projects

Add worker for marking pending compliance external controls as failed

What does this MR do and why?

  1. This MR is forked from !180010 (merged) and should only be merged once we merge that MR.
  2. This MR creates a worker to mark compliance external controls as failed if they are in a pending state since more than 30 minutes.
  3. The worker is invoked after 30 minutes of sending the current project payload to the user's external control endpoint.
  4. We would create an API in this issue that will allow user's to mark the pending external controls as fail or pass.
  5. However, if the user doesn't provide the status within 30 minutes then the above worker would mark it as fail and also create an audit event reflecting the same.

References

Please include cross links to any resources that are relevant to this MR. This will give reviewers and future readers helpful context to give an efficient review of the changes introduced.

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.

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

image

How to set up and validate locally

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

  1. Ensure you have ultimate license.
  2. For verification you need to create a compliance framework.
  3. You would also need to create at least one compliance requirement for this framework using the GraphQL API.
  4. You would also need to create at least one external control for the above compliance requirement. We do not support GraphQL API for this so you can use rails console for now.
cr = ComplianceManagement::ComplianceFramework::ComplianceRequirement.last
cr.compliance_requirements_controls.create!(control_type: 'external', name: "external_control", namespace_id: cr.namespace_id, external_url: "https://huzaifaiftikhar.requestcatcher.com", secret_token: "SECRET")
  1. Since this service is not exposed via an API or UI, we would need to use rails console for validation.
project = Project.find(20) # or any other existing project ID

framework = ComplianceManagement::Framework.last

cr = framework.compliance_requirements.last

control = cr.compliance_requirements_controls.last

ComplianceManagement::ComplianceFramework::ComplianceRequirements::TriggerExternalControlService.new(project, control).execute
  1. Check that the status of ProjectControlComplianceStatus is marked as pending.
ComplianceManagement::ComplianceFramework::ProjectControlComplianceStatus.for_project_and_control(project.id, control.id)
  1. After 30 mins again check the the status and now it should be marked as fail.
  2. For testing we can reduce the delay time by applying the below patch
Diff
diff --git a/ee/app/services/compliance_management/compliance_framework/compliance_requirements/trigger_external_control_service.rb b/ee/app/services/compliance_management/compliance_framework/compliance_requirements/trigger_external_control_service.rb
index 23cbca83fdd9..b2910e334066 100644
--- a/ee/app/services/compliance_management/compliance_framework/compliance_requirements/trigger_external_control_service.rb
+++ b/ee/app/services/compliance_management/compliance_framework/compliance_requirements/trigger_external_control_service.rb
@@ -69,7 +69,7 @@ def handle_response(response)
           if response.success?
             audit_success(response.code)

-            ComplianceManagement::TimeoutPendingExternalControlsWorker.perform_in(31.minutes,
+            ComplianceManagement::TimeoutPendingExternalControlsWorker.perform_in(1.minute,
               { 'control_id' => control.id, 'project_id' => project.id })

             ServiceResponse.success(payload: { control: control })
diff --git a/ee/app/workers/compliance_management/timeout_pending_external_controls_worker.rb b/ee/app/workers/compliance_management/timeout_pending_external_controls_worker.rb
index 97e06dbdb574..8d0d6844b9b6 100644
--- a/ee/app/workers/compliance_management/timeout_pending_external_controls_worker.rb
+++ b/ee/app/workers/compliance_management/timeout_pending_external_controls_worker.rb
@@ -21,7 +21,7 @@ def perform(args = {})
                                             .for_project_and_control(project_id, control_id).last

       unless project_control_compliance_status&.pending? &&
-          project_control_compliance_status.updated_at < 30.minutes.ago
+          project_control_compliance_status.updated_at < 50.seconds.ago
         return
       end

Closes #513423 (closed)

Edited by Huzaifa Iftikhar

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
Please register or sign in to reply
Loading