feat: added check logic and metadata

This commit is contained in:
HugoPBrito committed 2024-12-16 11:31:29 +00:00
1 parent 856b6d782b
commit 5ecf2e9b33
4 files changed
+79

No files matched your search

@@ -0,0 +1,30 @@
{
"Provider": "github",
"CheckID": "repository_enforces_status_checks",
"CheckTitle": "Check if repository enforces status checks to pass",
"CheckType": [],
"ServiceName": "repository",
"SubServiceName": "",
"ResourceIdTemplate": "",
"Severity": "high",
"ResourceType": "Other",
"Description": "Ensure that the repository enforces status checks to pass before merging code into the main branch.",
"Risk": "Merging code without requiring all checks to pass increases the risk of introducing bugs, vulnerabilities, or unstable changes into the codebase. This can compromise the quality, security, and functionality of the application.",
"RelatedUrl": "https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/managing-protected-branches/about-protected-branches#require-status-checks-before-merging",
"Remediation": {
"Code": {
"CLI": "",
"NativeIaC": "",
"Other": "",
"Terraform": ""
},
"Recommendation": {
"Text": "Require all predefined status checks to pass successfully before allowing code changes to be merged. This ensures that all quality, stability, and security conditions are met, reducing the likelihood of errors or vulnerabilities being introduced into the project.",
"Url": "https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/managing-protected-branches/managing-a-branch-protection-rule"
}
},
"Categories": [],
"DependsOn": [],
"RelatedTo": [],
"Notes": ""
}
@@ -0,0 +1,44 @@
from typing import List
from prowler.lib.check.models import Check, Check_Report_Github
from prowler.providers.github.services.repository.repository_client import (
repository_client,
)
class repository_enforces_status_checks(Check):
"""Check if a repository enforces status checks.
This class verifies whether each repository enforces status checks.
"""
def execute(self) -> List[Check_Report_Github]:
"""Execute the Github Repository
Iterates over all repositories and checks if they enforce status checks.
Returns:
List[Check_Report_Github]: A list of reports for each repository.
"""
findings = []
for repo in repository_client.repositories.values():
report = Check_Report_Github(self.metadata())
report.resource_id = repo.id
report.resource_name = repo.name
report.status = "FAIL"
report.status_extended = (
f"Repository {repo.name} does not enforce status checks."
)
if (
repo.default_branch_protection
and repo.default_branch_protection.enforce_status_checks
):
report.status = "PASS"
report.status_extended = (
f"Repository {repo.name} does enforce status checks."
)
findings.append(report)
return findings
@@ -49,6 +49,9 @@ class Repository(GithubService):
)
allow_force_pushes = protection.allow_force_pushes
branch_deletion = protection.allow_deletions
status_checks = (
protection.required_status_checks.strict
)
branch_protection = Protection(
require_pull_request=require_pr,
@@ -56,6 +59,7 @@ class Repository(GithubService):
linear_history=required_linear_history,
allow_force_push=allow_force_pushes,
allow_branch_deletion=branch_deletion,
enforce_status_checks=status_checks,
)
except Exception as e:
@@ -88,6 +92,7 @@ class Protection(BaseModel):
linear_history: bool = False
allow_force_push: bool = True
allow_branch_deletion: bool = True
enforce_status_checks: bool = False
class Repo(BaseModel):