Control: Lambda permissions should restrict service permission by source account or source arn
Description
Ensure that Lambda permissions restricts service permission by source account or source arn.
Usage
Run the control in your terminal:
powerpipe control run terraform_aws_compliance.control.lambda_permission_restricted_service_permission
Snapshot and share results via Turbot Pipes:
powerpipe loginpowerpipe control run terraform_aws_compliance.control.lambda_permission_restricted_service_permission --share
SQL
This control uses a named query:
select address as resource, split_part((attributes_std ->> 'principal'), '.', 2), case when not (split_part((attributes_std ->> 'principal'), '.', 2) = 'amazonaws' and split_part((attributes_std ->> 'principal'), '.', 3)= 'com') then 'info' when split_part((attributes_std ->> 'principal'), '.', 2) = 'amazonaws' and split_part((attributes_std ->> 'principal'), '.', 3)= 'com' and ((attributes_std -> 'source_arn') is not null or (attributes_std -> 'source_account') is not null ) then 'ok' else 'alarm' end as status, split_part(address, '.', 2) || case when not (split_part((attributes_std ->> 'principal'), '.', 2) = 'amazonaws' and split_part((attributes_std ->> 'principal'), '.', 3) = 'com') then ' principal not set as service' when split_part((attributes_std ->> 'principal'), '.', 2) = 'amazonaws' and split_part((attributes_std ->> 'principal'), '.', 3)= 'com' and ((attributes_std -> 'source_arn') is not null or (attributes_std -> 'source_account') is not null ) then ' permissions to AWS services restricted by SourceArn or SourceAccount' else ' permissions to AWS services not restricted by SourceArn or SourceAccount' end || '.' as reason , path || ':' || start_linefrom terraform_resourcewhere type = 'aws_lambda_permission';