From 5ce7aa33ad8c0e53d20df5a5a3f185f9fa71d71c Mon Sep 17 00:00:00 2001 From: MrCloudSec Date: Mon, 18 Nov 2024 13:15:46 -0400 Subject: [PATCH] chore: revision --- poetry.lock | 49 +++++++++++++++- prowler/lib/check/models.py | 1 + prowler/lib/outputs/summary_table.py | 3 + prowler/providers/github/github_provider.py | 58 ++++++++++++++----- .../github/lib/arguments/arguments.py | 2 +- .../providers/github/lib/mutelist/mutelist.py | 2 +- prowler/providers/github/models.py | 4 +- pyproject.toml | 1 + 8 files changed, 101 insertions(+), 19 deletions(-) diff --git a/poetry.lock b/poetry.lock index 3784112da4..f45066e32b 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.8.4 and should not be changed by hand. [[package]] name = "about-time" @@ -4120,6 +4120,25 @@ files = [ {file = "pyflakes-3.2.0.tar.gz", hash = "sha256:1c61603ff154621fb2a9172037d84dca3500def8c8b630657d1701f026f8af3f"}, ] +[[package]] +name = "pygithub" +version = "2.5.0" +description = "Use the full Github API v3" +optional = false +python-versions = ">=3.8" +files = [ + {file = "PyGithub-2.5.0-py3-none-any.whl", hash = "sha256:b0b635999a658ab8e08720bdd3318893ff20e2275f6446fcf35bf3f44f2c0fd2"}, + {file = "pygithub-2.5.0.tar.gz", hash = "sha256:e1613ac508a9be710920d26eb18b1905ebd9926aa49398e88151c1b526aad3cf"}, +] + +[package.dependencies] +Deprecated = "*" +pyjwt = {version = ">=2.4.0", extras = ["crypto"]} +pynacl = ">=1.4.0" +requests = ">=2.14.0" +typing-extensions = ">=4.0.0" +urllib3 = ">=1.26.0" + [[package]] name = "pygments" version = "2.18.0" @@ -4202,6 +4221,32 @@ pyyaml = "*" [package.extras] extra = ["pygments (>=2.12)"] +[[package]] +name = "pynacl" +version = "1.5.0" +description = "Python binding to the Networking and Cryptography (NaCl) library" +optional = false +python-versions = ">=3.6" +files = [ + {file = "PyNaCl-1.5.0-cp36-abi3-macosx_10_10_universal2.whl", hash = "sha256:401002a4aaa07c9414132aaed7f6836ff98f59277a234704ff66878c2ee4a0d1"}, + {file = "PyNaCl-1.5.0-cp36-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_24_aarch64.whl", hash = "sha256:52cb72a79269189d4e0dc537556f4740f7f0a9ec41c1322598799b0bdad4ef92"}, + {file = "PyNaCl-1.5.0-cp36-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a36d4a9dda1f19ce6e03c9a784a2921a4b726b02e1c736600ca9c22029474394"}, + {file = "PyNaCl-1.5.0-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_24_x86_64.whl", hash = "sha256:0c84947a22519e013607c9be43706dd42513f9e6ae5d39d3613ca1e142fba44d"}, + {file = "PyNaCl-1.5.0-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:06b8f6fa7f5de8d5d2f7573fe8c863c051225a27b61e6860fd047b1775807858"}, + {file = "PyNaCl-1.5.0-cp36-abi3-musllinux_1_1_aarch64.whl", hash = "sha256:a422368fc821589c228f4c49438a368831cb5bbc0eab5ebe1d7fac9dded6567b"}, + {file = "PyNaCl-1.5.0-cp36-abi3-musllinux_1_1_x86_64.whl", hash = "sha256:61f642bf2378713e2c2e1de73444a3778e5f0a38be6fee0fe532fe30060282ff"}, + {file = "PyNaCl-1.5.0-cp36-abi3-win32.whl", hash = "sha256:e46dae94e34b085175f8abb3b0aaa7da40767865ac82c928eeb9e57e1ea8a543"}, + {file = "PyNaCl-1.5.0-cp36-abi3-win_amd64.whl", hash = "sha256:20f42270d27e1b6a29f54032090b972d97f0a1b0948cc52392041ef7831fee93"}, + {file = "PyNaCl-1.5.0.tar.gz", hash = "sha256:8ac7448f09ab85811607bdd21ec2464495ac8b7c66d146bf545b0f08fb9220ba"}, +] + +[package.dependencies] +cffi = ">=1.4.1" + +[package.extras] +docs = ["sphinx (>=1.6.5)", "sphinx-rtd-theme"] +tests = ["hypothesis (>=3.27.0)", "pytest (>=3.2.1,!=3.3.0)"] + [[package]] name = "pyparsing" version = "3.2.0" @@ -5852,4 +5897,4 @@ type = ["pytest-mypy"] [metadata] lock-version = "2.0" python-versions = ">=3.9,<3.13" -content-hash = "e7c299d2efe2a668adecafb0111bc2b1974d7f15203da6fe21ebdcfe28f42420" +content-hash = "3a923925186496d5b6cde88d7b2740667f72a6ca3bb2964ab34c6ef9e4fac719" diff --git a/prowler/lib/check/models.py b/prowler/lib/check/models.py index 615fa06cb9..71c6e35487 100644 --- a/prowler/lib/check/models.py +++ b/prowler/lib/check/models.py @@ -508,6 +508,7 @@ def load_check_metadata(metadata_file: str) -> CheckMetadata: class Check_Report_GitHub(Check_Report): """Contains the GitHub Check's finding information.""" + account_name: str resource_name: str resource_id: str diff --git a/prowler/lib/outputs/summary_table.py b/prowler/lib/outputs/summary_table.py index a2090e53ef..60048617c3 100644 --- a/prowler/lib/outputs/summary_table.py +++ b/prowler/lib/outputs/summary_table.py @@ -40,6 +40,9 @@ def display_summary_table( elif provider.type == "kubernetes": entity_type = "Context" audited_entities = provider.identity.context + elif provider.type == "github": + entity_type = "User Name" + audited_entities = provider.identity.account_name # Check if there are findings and that they are not all MANUAL if findings and not all(finding.status == "MANUAL" for finding in findings): diff --git a/prowler/providers/github/github_provider.py b/prowler/providers/github/github_provider.py index d8d3d0d4f5..3b2b0ad143 100644 --- a/prowler/providers/github/github_provider.py +++ b/prowler/providers/github/github_provider.py @@ -4,11 +4,14 @@ from github import Auth, Github from prowler.config.config import ( default_config_file_path, + get_default_mute_file_path, load_and_validate_config_file, ) from prowler.lib.logger import logger +from prowler.lib.mutelist.mutelist import Mutelist from prowler.providers.common.models import Audit_Metadata from prowler.providers.common.provider import Provider +from prowler.providers.github.lib.mutelist.mutelist import GitHubMutelist from prowler.providers.github.models import GithubIdentityInfo, GithubSession @@ -17,6 +20,7 @@ class GithubProvider(Provider): _session: GithubSession _identity: GithubIdentityInfo _audit_config: dict + _mutelist: Mutelist audit_metadata: Audit_Metadata def __init__( @@ -24,8 +28,11 @@ class GithubProvider(Provider): personal_access_token: bool = False, github_app: bool = False, oauth_app: bool = False, - # config_content: dict = None, config_path: str = None, + config_content: dict = None, + fixer_config: dict = {}, + mutelist_path: str = None, + mutelist_content: dict = None, ): """ GitHub Provider constructor @@ -48,14 +55,30 @@ class GithubProvider(Provider): github_app, oauth_app, ) - self._audit_config = {} - # if config_content: - # self._audit_config = config_content - # else: - if not config_path: - config_path = default_config_file_path - self._audit_config = load_and_validate_config_file(self._type, config_path) + # Audit Config + if config_content: + self._audit_config = config_content + else: + if not config_path: + config_path = default_config_file_path + self._audit_config = load_and_validate_config_file(self._type, config_path) + + # Fixer Config + self._fixer_config = fixer_config + + # Mutelist + if mutelist_content: + self._mutelist = GitHubMutelist( + mutelist_content=mutelist_content, + ) + else: + if not mutelist_path: + mutelist_path = get_default_mute_file_path(self.type) + self._mutelist = GitHubMutelist( + mutelist_path=mutelist_path, + ) + Provider.set_global_provider(self) @property def identity(self): @@ -74,9 +97,19 @@ class GithubProvider(Provider): @property def audit_config(self): - """Returns the audit configuration for the GitHub provider.""" return self._audit_config + @property + def fixer_config(self): + return self._fixer_config + + @property + def mutelist(self) -> GitHubMutelist: + """ + mutelist method returns the provider's mutelist. + """ + return self._mutelist + def setup_session( self, personal_access_token: bool, @@ -141,8 +174,5 @@ class GithubProvider(Provider): return identity - def print_credentials(self) -> None: - return super().print_credentials() - - def get_global_provider(self) -> Provider: - return super().get_global_provider() + def print_credentials(self): + print("Using GitHub PAT") diff --git a/prowler/providers/github/lib/arguments/arguments.py b/prowler/providers/github/lib/arguments/arguments.py index 85d99918b9..49b1386746 100644 --- a/prowler/providers/github/lib/arguments/arguments.py +++ b/prowler/providers/github/lib/arguments/arguments.py @@ -10,7 +10,7 @@ def init_parser(self): "--personal-access-token", action="store_true", help="Use Personal Access Token to log in against GitHub", - default=True, + default=False, ) github_auth_modes_group.add_argument( "--oauth-app", diff --git a/prowler/providers/github/lib/mutelist/mutelist.py b/prowler/providers/github/lib/mutelist/mutelist.py index e0b46449c1..31ec3b1b8d 100644 --- a/prowler/providers/github/lib/mutelist/mutelist.py +++ b/prowler/providers/github/lib/mutelist/mutelist.py @@ -9,7 +9,7 @@ class GitHubMutelist(Mutelist): finding: Check_Report_GitHub, ) -> bool: return self.is_muted( - finding.subscription, + finding.account_name, finding.check_metadata.CheckID, finding.location, finding.resource_name, diff --git a/prowler/providers/github/models.py b/prowler/providers/github/models.py index 6c42ec50c0..c6dfa4bd67 100644 --- a/prowler/providers/github/models.py +++ b/prowler/providers/github/models.py @@ -24,6 +24,8 @@ class GithubOutputOptions(ProviderOutputOptions): not hasattr(arguments, "output_filename") or arguments.output_filename is None ): - self.output_filename = f"prowler-output-{identity.context.replace(':', '_').replace('/', '_')}-{output_file_timestamp}" + self.output_filename = ( + f"prowler-output-{identity.account_name}-{output_file_timestamp}" + ) else: self.output_filename = arguments.output_filename diff --git a/pyproject.toml b/pyproject.toml index 4e27cfae3b..23e1e57b4e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -65,6 +65,7 @@ pandas = "2.2.3" presidio-analyzer = "2.2.355" py-ocsf-models = "0.2.0" pydantic = "1.10.18" +pygithub = "2.5.0" python = ">=3.9,<3.13" python-dateutil = "^2.9.0.post0" pytz = "2024.2"