35
35
MAX_RETRY = 5
36
36
SECURITY_HUB_THROTTLE_PERIOD = 0.2
37
37
BOTO3_CONFIG = Config (retries = {"max_attempts" : 10 , "mode" : "standard" })
38
+ AWS_DEFAULT_SBP_VERSION = "1.0.0"
39
+ AWS_DEFAULT_CIS_VERSION = "1.2.0"
38
40
39
41
try :
40
42
MANAGEMENT_ACCOUNT_SESSION = boto3 .Session ()
@@ -276,7 +278,14 @@ def enable_account_securityhub(account_id: str, regions: list, configuration_rol
276
278
277
279
278
280
def configure_delegated_admin_securityhub (
279
- accounts : list , regions : list , delegated_admin_account_id : str , configuration_role_name : str , region_linking_mode : str , home_region : str
281
+ accounts : list ,
282
+ regions : list ,
283
+ delegated_admin_account_id : str ,
284
+ configuration_role_name : str ,
285
+ region_linking_mode : str ,
286
+ home_region : str ,
287
+ aws_partition : str ,
288
+ standards_user_input : dict ,
280
289
) -> None :
281
290
"""Configure delegated admin security hub.
282
291
@@ -287,13 +296,46 @@ def configure_delegated_admin_securityhub(
287
296
configuration_role_name: Configuration Role Name
288
297
region_linking_mode: Region Linking Mode
289
298
home_region: Home Region
299
+ aws_partition: AWS Partition
300
+ standards_user_input: Dictionary of standards
290
301
"""
291
302
process_organization_admin_account (delegated_admin_account_id , regions )
292
- delegated_admin_session = common .assume_role (configuration_role_name , "sra-enable-security-hub" , delegated_admin_account_id )
303
+ delegated_admin_session : boto3 . Session = common .assume_role (configuration_role_name , "sra-enable-security-hub" , delegated_admin_account_id )
293
304
294
305
for region in regions :
295
306
securityhub_delegated_admin_region_client : SecurityHubClient = delegated_admin_session .client ("securityhub" , region , config = BOTO3_CONFIG )
296
- update_organization_configuration_response = securityhub_delegated_admin_region_client .update_organization_configuration (AutoEnable = True )
307
+
308
+ standard_dict = get_standard_dictionary (
309
+ delegated_admin_account_id ,
310
+ region ,
311
+ aws_partition ,
312
+ AWS_DEFAULT_SBP_VERSION ,
313
+ AWS_DEFAULT_CIS_VERSION ,
314
+ standards_user_input ["PCIVersion" ],
315
+ standards_user_input ["NISTVersion" ],
316
+ )
317
+
318
+ for i in range (10 ):
319
+ standards_subscriptions = get_enabled_standards (securityhub_delegated_admin_region_client )
320
+ if (
321
+ all_standards_in_status (standards_subscriptions , "READY" , securityhub_delegated_admin_region_client )
322
+ and len (standards_subscriptions ) != 0
323
+ ):
324
+ break
325
+ LOGGER .info (f"Waiting 20 seconds before checking if delegated admin default standards are in READY status. { i } of 10" )
326
+ sleep (20 )
327
+
328
+ # Manually disable Security Hub default standards in Admin Account
329
+ batch_disable_standards_response = securityhub_delegated_admin_region_client .batch_disable_standards (
330
+ StandardsSubscriptionArns = [standard_dict ["sbp" ]["subscription_arn" ], standard_dict ["cis" ]["subscription_arn" ]]
331
+ )
332
+ api_call_details = {"API_Call" : "securityhub:BatchDisableStandards" , "API_Response" : batch_disable_standards_response }
333
+ LOGGER .info (api_call_details )
334
+ LOGGER .info (f"SecurityHub default standards disabled in { region } " )
335
+
336
+ update_organization_configuration_response = securityhub_delegated_admin_region_client .update_organization_configuration (
337
+ AutoEnable = True , AutoEnableStandards = "NONE"
338
+ )
297
339
api_call_details = {"API_Call" : "securityhub:UpdateOrganizationConfiguration" , "API_Response" : update_organization_configuration_response }
298
340
LOGGER .info (api_call_details )
299
341
LOGGER .info (f"SecurityHub organization configuration updated in { region } " )
0 commit comments