anon-iclr-submission/benchname-bug-localization huggingface dataset:
Repository: deepfence/threatmapper
Issue: PagerDuty integration does not take into account all of the integrations to match the user-provided integration key

**Describe the bug**
When entering a new integration key for PagerDuty integration, the current workflow matches it against a list of integrations fetched from PagerDuty's services API endpoint to verify if the integration_key is valid. But it matches the integration_key against only the first integration of each service to validate it.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to 'Integrations' tab
2. Click on 'Configure Integration' inside 'PagerDuty' block
3. Enter multiple integration keys from a PagerDuty service with more than 1 integrations.
4. Only 1 of them will be accepted and the others will throw an error 'Looks like integration key provided is not valid'

**Expected behavior**
Any Integration Key from any service should be accepted for PagerDuty integration

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Components/Services affected**

- [ ] UI/Frontend
- [x] API/Backend
- [ ] Agent
- [ ] Deployment/YAMLs
- [ ] CI/CD Integration
- [ ] Other (specify)

**Additional context**
Add any other context about the problem here.


Changed files:
deepfence_backend/api/user_api.py

diff --git a/deepfence_backend/api/user_api.py b/deepfence_backend/api/user_api.py
index 86507e2e3..81ba4b94e 100644
--- a/deepfence_backend/api/user_api.py
+++ b/deepfence_backend/api/user_api.py
@@ -1617,15 +1617,18 @@ class IntegrationView(MethodView):
             if response.status_code != 200:
                 raise InvalidUsage("Looks like no user own this Authentication token provided")
             else:
+                service_key_found = False
                 for data in response.json()["services"]:
                     if data["integrations"]:
                         for integrations in data["integrations"]:
                             if integrations.get("integration_key", ""):
                                 integration_key = integrations.get("integration_key", "")
-                                break
-                    if integration_key == service_key:
+                                if integration_key == service_key:
+                                    service_key_found = True
+                                    break
+                    if service_key_found:
                         break
-                if not integration_key or integration_key != service_key:
+                if not integration_key or not service_key_found:
                     raise InvalidUsage("Looks like integration key provided is not valid")
         except Exception as e:
             raise InvalidUsage(e)
Repository: deepfence/threatmapper
Issue: Vulnerability scan shows failure when started by Read Only user

**Describe the bug**
When a read only user starts a vulnerability scan on the console, it shows `Failed` status on the side panel.

**To Reproduce**
Steps to reproduce the behavior:
1. Login as a read only user.
2. Go to topology tab and select an Agent to show the side panel.
3. Click on 'Vulnerability Scan' on the side panel
4. Click on 'Start Scan' to start a vulnerability scan
5. Scan fails to start, but the side panel starts showing `Failed` status for 'Vulnerability Scan'

**Expected behavior**
'Vulnerability Scan' status should remain as it is before the scan is started by a read only user, since a read only user is not authorized to start a vulnerability scan.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Components/Services affected**

- [ ] UI/Frontend
- [x] API/Backend
- [ ] Agent
- [ ] Deployment/YAMLs
- [ ] CI/CD Integration
- [ ] Other (specify)

**Additional context**
An additional row is created in the Vulnerability Scans table. This should also not persist since the read only user is not authorized to perform the scan.


Changed files:
deepfence_backend/api/vulnerability_api.py

diff --git a/deepfence_backend/api/vulnerability_api.py b/deepfence_backend/api/vulnerability_api.py
index 180b3e4e9..34c95c28f 100644
--- a/deepfence_backend/api/vulnerability_api.py
+++ b/deepfence_backend/api/vulnerability_api.py
@@ -1069,6 +1069,7 @@ def vulnerability_csv_download():
 
 @vulnerability_api.route("/add-cve-scan-log", methods=["POST"])
 @jwt_required
+@non_read_only_user
 def cve_scan():
     """
     Add a CVE scan document to Elastic search
Repository: deepfence/threatmapper
Issue: Secret Scan: Interrupted scans status remains "In Progress"

- If a secret scan gets interrupted when it is in progress, scan status stays "In Progress" forever
- Scenarios where this can happen: agent container gets deleted / redeployed, secret scan process gets killed, etc.
- The cleanup [job](https://github.com/deepfence/ThreatMapper/blob/master/deepfence_backend/tasks/reaper_tasks.py#L114) doesn't seem to be working

Changed files:
deepfence_backend/utils/esconn.py

diff --git a/deepfence_backend/utils/esconn.py b/deepfence_backend/utils/esconn.py
index 3df588f48..911270653 100644
--- a/deepfence_backend/utils/esconn.py
+++ b/deepfence_backend/utils/esconn.py
@@ -7,7 +7,7 @@ from elasticsearch import Elasticsearch
 from elasticsearch.client.indices import IndicesClient
 
 from utils.constants import CVE_SCAN_LOGS_INDEX, ES_TERMS_AGGR_SIZE, \\
-    TIME_UNIT_MAPPING
+    TIME_UNIT_MAPPING, SECRET_SCAN_LOGS_INDEX
 from utils.common import (
     sort_expression,
     get_rounding_time_unit,
@@ -1063,7 +1063,7 @@ class ESConn:
             },
             "size": 0
         }
-        res = EL_CLIENT.search(index=CVE_SCAN_LOGS_INDEX, body=aggs_query)
+        res = EL_CLIENT.search(index=SECRET_SCAN_LOGS_INDEX, body=aggs_query)
         response = {}
         if "aggregations" not in res:
             return response
@@ -1076,17 +1076,17 @@ class ESConn:
                 if node_aggr["action"]["buckets"]:
                     recent_action = max(node_aggr["action"]["buckets"],
                                         key=lambda x: x["action_max_timestamp"]["value"])
-                    cve_scan_message = ""
-                    cve_scan_messages = recent_action["scan_message"]["buckets"]
-                    if cve_scan_messages:
-                        cve_scan_message = cve_scan_messages[-1]["key"]
+                    secret_scan_message = ""
+                    secret_scan_messages = recent_action["scan_message"]["buckets"]
+                    if secret_scan_messages:
+                        secret_scan_message = secret_scan_messages[-1]["key"]
                     scan_id = ""
                     scan_id_buckets = recent_action["scan_id"]["buckets"]
                     if scan_id_buckets:
                         scan_id = scan_id_buckets[-1]["key"]
                     response[host_aggr["key"]][node_aggr["key"]] = {
                         "action": recent_action["key"], "timestamp": recent_action["action_max_timestamp"]["value"],
-                        "scan_message": cve_scan_message, "scan_id": scan_id, "node_type": node_type}
+                        "scan_message": secret_scan_message, "scan_id": scan_id, "node_type": node_type}
         return response
 
     @staticmethod