From 4aa2d719c7b2c3910b95071e33c988ac18183ee6 Mon Sep 17 00:00:00 2001 From: Jacopo Date: Thu, 12 Aug 2021 21:31:56 +0200 Subject: [PATCH] security groups now auto-delete themselves? ignore those errors --- ctfoood/spawner.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/ctfoood/spawner.py b/ctfoood/spawner.py index 5bc17ff..dd73ffc 100644 --- a/ctfoood/spawner.py +++ b/ctfoood/spawner.py @@ -398,8 +398,15 @@ def delete_ooo_vm(vm:VM, raise_exceptions=False) -> Tuple[int,str]: if vm.security_group_id: all_output += "[*] Deleting the EC2 Security Group\n" - sg = ec2.SecurityGroup(vm.security_group_id) - sg.delete() + try: + sg = ec2.SecurityGroup(vm.security_group_id) + sg.delete() + except ec2.meta.client.exceptions.ClientError as error: # ec2 doesn't have other exception types? + assert error.operation_name == "DeleteSecurityGroup" + if error.response['Error']['Code'] == 'InvalidGroup.NotFound': + all_output += "[-] The security group was auto-deleted? Ignoring.\n" + else: + raise # Ignore anyway? vm.security_group_id = "" vm.save()