33AKS Network Diagnostics Script
44Comprehensive read-only analysis of AKS cluster network configuration
55Author: Azure Networking Diagnostics Generator
6- Version: 1.1.2
6+ Version: 1.2.0
77"""
88
99import argparse
@@ -190,16 +190,16 @@ def check_prerequisites(self):
190190 subprocess .run (
191191 ["az" , "--version" ], capture_output = True , check = True , timeout = AZURE_CLI_TIMEOUT , shell = IS_WINDOWS
192192 )
193- except (subprocess .CalledProcessError , FileNotFoundError ):
194- raise FileNotFoundError ("Azure CLI is not installed or not in PATH" )
193+ except (subprocess .CalledProcessError , FileNotFoundError ) as exc :
194+ raise FileNotFoundError ("Azure CLI is not installed or not in PATH" ) from exc
195195
196196 # Check if logged in
197197 try :
198198 subprocess .run (
199199 ["az" , "account" , "show" ], capture_output = True , check = True , timeout = AZURE_CLI_TIMEOUT , shell = IS_WINDOWS
200200 )
201- except subprocess .CalledProcessError :
202- raise PermissionError ("Not logged in to Azure. Run 'az login' first." )
201+ except subprocess .CalledProcessError as exc :
202+ raise PermissionError ("Not logged in to Azure. Run 'az login' first." ) from exc
203203
204204 # Set subscription if provided
205205 if self .subscription :
@@ -212,8 +212,8 @@ def check_prerequisites(self):
212212 shell = IS_WINDOWS ,
213213 )
214214 self .logger .info (f"Using Azure subscription: { self .subscription } " )
215- except subprocess .CalledProcessError :
216- raise ValueError (f"Failed to set subscription: { self .subscription } " )
215+ except subprocess .CalledProcessError as exc :
216+ raise ValueError (f"Failed to set subscription: { self .subscription } " ) from exc
217217 else :
218218 # Get current subscription
219219 current_sub = self .azure_cli_executor .execute (
@@ -233,20 +233,20 @@ def fetch_cluster_information(self):
233233
234234 def analyze_vnet_configuration (self ):
235235 """Analyze VNet configuration using ClusterDataCollector"""
236- collector = ClusterDataCollector (self .azure_cli_executor , self .logger )
237- self .vnets_analysis = collector .collect_vnet_info (self .agent_pools )
236+ self . cluster_data_collector = ClusterDataCollector (self .azure_cli_executor , self .logger )
237+ self .vnets_analysis = self . cluster_data_collector .collect_vnet_info (self .agent_pools )
238238
239239 def analyze_outbound_connectivity (self ):
240240 """Analyze outbound connectivity configuration using OutboundConnectivityAnalyzer"""
241- analyzer = OutboundConnectivityAnalyzer (
241+ self . outbound_analyzer = OutboundConnectivityAnalyzer (
242242 cluster_info = self .cluster_info ,
243243 agent_pools = self .agent_pools ,
244244 azure_cli = self .azure_cli_executor ,
245245 logger = self .logger ,
246246 )
247247
248- self .outbound_analysis = analyzer .analyze (show_details = self .show_details )
249- self .outbound_ips = analyzer .get_outbound_ips ()
248+ self .outbound_analysis = self . outbound_analyzer .analyze (show_details = self .show_details )
249+ self .outbound_ips = self . outbound_analyzer .get_outbound_ips ()
250250
251251 def _analyze_node_subnet_udrs (self ):
252252 """Analyze User Defined Routes on node subnets using RouteTableAnalyzer"""
@@ -260,8 +260,6 @@ def analyze_vmss_configuration(self):
260260
261261 def analyze_nsg_configuration (self ):
262262 """Analyze Network Security Group configuration for AKS nodes using modular NSGAnalyzer"""
263- self .logger .info ("Analyzing NSG configuration..." )
264-
265263 try :
266264 # Create NSG analyzer instance with the new modular component
267265 nsg_analyzer = NSGAnalyzer (
@@ -346,8 +344,8 @@ def _get_current_client_ip(self):
346344 import urllib .error
347345 import urllib .request
348346
349- response = urllib .request .urlopen ("https://api.ipify.org" , timeout = 5 )
350- return response .read ().decode ("utf-8" ).strip ()
347+ with urllib .request .urlopen ("https://api.ipify.org" , timeout = 5 ) as response :
348+ return response .read ().decode ("utf-8" ).strip ()
351349 except Exception :
352350 return None
353351
@@ -360,10 +358,10 @@ def check_api_connectivity(self):
360358
361359 def analyze_misconfigurations (self ):
362360 """Analyze potential misconfigurations and failures using MisconfigurationAnalyzer"""
363- analyzer = MisconfigurationAnalyzer (self .azure_cli_executor , self .logger )
361+ self . misconfiguration_analyzer = MisconfigurationAnalyzer (self .azure_cli_executor , self .logger )
364362
365363 # Run analysis and get findings
366- findings , cluster_stopped = analyzer .analyze (
364+ findings , cluster_stopped = self . misconfiguration_analyzer .analyze (
367365 cluster_info = self .cluster_info ,
368366 outbound_analysis = self .outbound_analysis ,
369367 outbound_ips = self .outbound_ips ,
@@ -372,6 +370,7 @@ def analyze_misconfigurations(self):
372370 nsg_analysis = self .nsg_analysis ,
373371 api_probe_results = self .api_probe_results ,
374372 vmss_analysis = self .vmss_analysis ,
373+ outbound_analyzer = self .outbound_analyzer ,
375374 )
376375
377376 # Store results
@@ -409,6 +408,27 @@ def generate_report(self):
409408 if self .json_report :
410409 report_gen .save_json_report (self .json_report , file_permissions = DEFAULT_FILE_PERMISSIONS )
411410
411+ def collect_permission_findings (self ):
412+ """Collect permission-related findings from all analyzers"""
413+ # Collect from cluster data collector
414+ if hasattr (self , "cluster_data_collector" ) and hasattr (self .cluster_data_collector , "findings" ):
415+ for finding in self .cluster_data_collector .findings :
416+ self .findings .append (finding .to_dict () if hasattr (finding , "to_dict" ) else finding )
417+
418+ # Collect from outbound analyzer
419+ if hasattr (self , "outbound_analyzer" ) and hasattr (self .outbound_analyzer , "findings" ):
420+ for finding in self .outbound_analyzer .findings :
421+ self .findings .append (finding .to_dict () if hasattr (finding , "to_dict" ) else finding )
422+
423+ # Collect from misconfiguration analyzer
424+ if hasattr (self , "misconfiguration_analyzer" ) and hasattr (self .misconfiguration_analyzer , "findings" ):
425+ for finding in self .misconfiguration_analyzer .findings :
426+ self .findings .append (finding .to_dict () if hasattr (finding , "to_dict" ) else finding )
427+
428+ # NSG and DNS analyzer findings are already collected in their respective methods
429+ # Note: Permission findings are created by analyzers with specific context,
430+ # so we don't need to duplicate them from azure_cli.permission_errors
431+
412432 def run (self ):
413433 """Main execution method"""
414434 self .parse_arguments ()
@@ -426,6 +446,7 @@ def run(self):
426446 self .analyze_api_server_access ()
427447 self .check_api_connectivity ()
428448 self .analyze_misconfigurations ()
449+ self .collect_permission_findings () # Collect all permission findings before reporting
429450 self .generate_report ()
430451
431452
0 commit comments