mirror of
https://github.com/prowler-cloud/prowler.git
synced 2026-07-20 02:51:52 +00:00
feat(m365): add first fixer for m365
This commit is contained in:
@@ -290,6 +290,7 @@ def prowler():
|
||||
output_options = M365OutputOptions(
|
||||
args, bulk_checks_metadata, global_provider.identity
|
||||
)
|
||||
global_provider.set_output_options(output_options)
|
||||
elif provider == "nhn":
|
||||
output_options = NHNOutputOptions(
|
||||
args, bulk_checks_metadata, global_provider.identity
|
||||
|
||||
@@ -685,6 +685,20 @@ class M365PowerShell(PowerShellSession):
|
||||
"""
|
||||
return self.execute("Get-TransportConfig | ConvertTo-Json", json_parse=True)
|
||||
|
||||
def set_audit_log_config(self):
|
||||
"""
|
||||
Set Purview Admin Audit Log Settings.
|
||||
|
||||
Sets the audit log configuration settings for Microsoft Purview.
|
||||
|
||||
Args:
|
||||
enabled (bool): Whether to enable or disable the audit log.
|
||||
|
||||
"""
|
||||
return self.execute(
|
||||
"Set-AdminAuditLogConfig -UnifiedAuditLogIngestionEnabled $true"
|
||||
)
|
||||
|
||||
|
||||
# This function is used to install the required M365 PowerShell modules in Docker containers
|
||||
def initialize_m365_powershell_modules():
|
||||
|
||||
@@ -218,6 +218,9 @@ class M365Provider(Provider):
|
||||
# Fixer Config
|
||||
self._fixer_config = fixer_config
|
||||
|
||||
# Output Options
|
||||
self._output_options = None
|
||||
|
||||
# Mutelist
|
||||
if mutelist_content:
|
||||
self._mutelist = M365Mutelist(
|
||||
@@ -1132,3 +1135,10 @@ class M365Provider(Provider):
|
||||
except Exception as error:
|
||||
# Generic exception handling for unexpected errors
|
||||
raise RuntimeError(f"An unexpected error occurred: {str(error)}")
|
||||
|
||||
@property
|
||||
def output_options(self):
|
||||
return self._output_options
|
||||
|
||||
def set_output_options(self, output_options):
|
||||
self._output_options = output_options
|
||||
|
||||
@@ -55,4 +55,4 @@ class M365OutputOptions(ProviderOutputOptions):
|
||||
self.output_filename = arguments.output_filename
|
||||
|
||||
# Add fixer mode to the output options
|
||||
self.fixer = arguments.fixer
|
||||
self.fixer = arguments.fixer if hasattr(arguments, "fixer") else False
|
||||
|
||||
+4
-27
@@ -16,7 +16,6 @@ class PurviewAuditLogSearchEnabledFixer(M365Fixer):
|
||||
"""
|
||||
Initialize Purview audit log search fixer.
|
||||
"""
|
||||
print("Inicializando PurviewAuditLogSearchEnabledFixer")
|
||||
super().__init__(
|
||||
description="Enable Purview audit log search",
|
||||
cost_impact=False,
|
||||
@@ -37,36 +36,14 @@ class PurviewAuditLogSearchEnabledFixer(M365Fixer):
|
||||
bool: True if the operation is successful (audit log search is enabled), False otherwise
|
||||
"""
|
||||
try:
|
||||
print("Iniciando fix de Purview Audit Log")
|
||||
# Show the fixing message
|
||||
super().fix()
|
||||
|
||||
print(f"Estado de purview_client: {purview_client}")
|
||||
print(f"Estado de purview_client.powershell: {purview_client.powershell}")
|
||||
|
||||
# Connect to Exchange Online
|
||||
if purview_client.powershell:
|
||||
print("Conectando a Exchange Online")
|
||||
purview_client.powershell.connect_exchange_online()
|
||||
try:
|
||||
# Execute the command to enable audit log search
|
||||
print("Ejecutando comando pwsh")
|
||||
purview_client.powershell.execute(
|
||||
"Set-AdminAuditLogConfig -UnifiedAuditLogIngestionEnabled $true"
|
||||
)
|
||||
return True
|
||||
finally:
|
||||
# Always close the PowerShell session
|
||||
print("Cerrando sesión de PowerShell")
|
||||
purview_client.powershell.close()
|
||||
else:
|
||||
logger.error("PowerShell session could not be initialized")
|
||||
print("Error al inicializar la sesión de PowerShell")
|
||||
return False
|
||||
|
||||
purview_client.powershell.set_audit_log_config()
|
||||
purview_client.powershell.close()
|
||||
return True
|
||||
except Exception as error:
|
||||
print(f"Error en el fixer: {str(error)}")
|
||||
logger.error(
|
||||
f"{error.__class__.__name__}[{error.__traceback__.tb_lineno}]: {error}"
|
||||
)
|
||||
purview_client.powershell.close()
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user