Skip to content

Commit b3efd66

Browse files
author
Taniya Mathur
committed
Fix permission boundary validation and cleanup logic
- Add missing PermissionsBoundary to Discovery Lambda functions - Make permission boundary validation failure cause deployment to fail - Remove redundant cleanup from install_service - Cleanup handled by uninstall_service and CodePipeline
1 parent f08a7a7 commit b3efd66

File tree

3 files changed

+4
-64
lines changed

3 files changed

+4
-64
lines changed

patterns/pattern-1/template.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,7 @@ Resources:
714714
- id: W92
715715
reason: "Function does not require concurrent execution limits as it is designed to scale based on demand"
716716
Properties:
717+
PermissionsBoundary: !If [HasPermissionsBoundary, !Ref PermissionsBoundaryArn, !Ref AWS::NoValue]
717718
CodeUri: src/bda_discovery_function/
718719
Handler: index.handler
719720
Runtime: python3.12

scripts/sdlc/idp-cli/src/idp_cli/service/install_service.py

Lines changed: 1 addition & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -136,66 +136,6 @@ def publish(self):
136136
return False
137137

138138

139-
def cleanup_failed_stack(self, stack_name):
140-
"""
141-
Clean up failed stack if it exists in ROLLBACK_COMPLETE state.
142-
143-
Args:
144-
stack_name: Name of the stack to clean up
145-
146-
Returns:
147-
bool: True if cleanup successful or not needed, False if cleanup failed
148-
"""
149-
try:
150-
# Check stack status
151-
cmd = [
152-
'aws', 'cloudformation', 'describe-stacks',
153-
'--region', self.region,
154-
'--stack-name', stack_name,
155-
'--query', 'Stacks[0].StackStatus',
156-
'--output', 'text'
157-
]
158-
159-
process = subprocess.run(
160-
cmd,
161-
check=True,
162-
text=True,
163-
stdout=subprocess.PIPE,
164-
stderr=subprocess.PIPE
165-
)
166-
167-
stack_status = process.stdout.strip()
168-
169-
if stack_status in ['ROLLBACK_COMPLETE', 'CREATE_FAILED', 'DELETE_FAILED']:
170-
logger.info(f"Cleaning up failed stack {stack_name} (status: {stack_status})")
171-
172-
delete_cmd = [
173-
'aws', 'cloudformation', 'delete-stack',
174-
'--region', self.region,
175-
'--stack-name', stack_name
176-
]
177-
178-
subprocess.run(delete_cmd, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
179-
180-
# Wait for deletion to complete
181-
wait_cmd = [
182-
'aws', 'cloudformation', 'wait', 'stack-delete-complete',
183-
'--region', self.region,
184-
'--stack-name', stack_name
185-
]
186-
187-
subprocess.run(wait_cmd, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
188-
logger.info(f"Successfully cleaned up failed stack {stack_name}")
189-
190-
return True
191-
192-
except subprocess.CalledProcessError:
193-
# Stack doesn't exist - no cleanup needed
194-
return True
195-
except Exception as e:
196-
logger.error(f"Failed to cleanup stack {stack_name}: {e}")
197-
return False
198-
199139
def deploy_service_role(self):
200140
"""
201141
Deploy the CloudFormation service role stack.
@@ -487,6 +427,7 @@ def install(self, admin_email: str, idp_pattern: str):
487427
logger.info("Step 4: Validating permission boundary on all IAM roles...")
488428
if not self.validate_permission_boundary(self.stack_name, permission_boundary_arn):
489429
logger.error("Permission boundary validation failed!")
430+
logger.error("Deployment failed due to security policy violations.")
490431
return False
491432

492433
logger.info("Deployment and validation completed successfully!")
@@ -501,10 +442,6 @@ def install(self, admin_email: str, idp_pattern: str):
501442
logger.debug(f"Command stdout: {e.stdout}")
502443
if e.stderr:
503444
logger.debug(f"Command stderr: {e.stderr}")
504-
505-
# Cleanup failed deployment for next attempt
506-
logger.info("Cleaning up failed deployment for next attempt...")
507-
self.cleanup_failed_stack(self.stack_name)
508445
return False
509446
except Exception as e:
510447
logger.error(f"Unexpected error during stack deployment: {e}")

template.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5744,6 +5744,7 @@ Resources:
57445744
# checkov:skip=CKV_AWS_117: "Function does not require VPC access as it only interacts with AWS services via APIs"
57455745
# checkov:skip=CKV_AWS_173: "Environment variables do not contain sensitive data - only configuration values like feature flags and non-sensitive settings"
57465746
Properties:
5747+
PermissionsBoundary: !If [HasPermissionsBoundary, !Ref PermissionsBoundaryArn, !Ref AWS::NoValue]
57475748
Handler: index.handler
57485749
Runtime: python3.12
57495750
CodeUri: ./src/lambda/discovery_upload_resolver
@@ -5907,6 +5908,7 @@ Resources:
59075908
# checkov:skip=CKV_AWS_115: "Function does not require reserved concurrency as it scales based on demand"
59085909
# checkov:skip=CKV_AWS_173: "Environment variables do not contain sensitive data - only configuration values like feature flags and non-sensitive settings"
59095910
Properties:
5911+
PermissionsBoundary: !If [HasPermissionsBoundary, !Ref PermissionsBoundaryArn, !Ref AWS::NoValue]
59105912
Handler: index.handler
59115913
Runtime: python3.12
59125914
CodeUri: ./src/lambda/discovery_processor

0 commit comments

Comments
 (0)