github.com/khulnasoft-lab/defsec@v1.0.5-0.20230827010352-5e9f46893d95/rules/cloud/policies/aws/lambda/restrict_source_arn.go (about) 1 package lambda 2 3 import ( 4 "github.com/khulnasoft-lab/defsec/internal/rules" 5 "github.com/khulnasoft-lab/defsec/pkg/providers" 6 "github.com/khulnasoft-lab/defsec/pkg/scan" 7 "github.com/khulnasoft-lab/defsec/pkg/severity" 8 "github.com/khulnasoft-lab/defsec/pkg/state" 9 ) 10 11 var CheckRestrictSourceArn = rules.Register( 12 scan.Rule{ 13 AVDID: "AVD-AWS-0067", 14 Provider: providers.AWSProvider, 15 Service: "lambda", 16 ShortCode: "restrict-source-arn", 17 Summary: "Ensure that lambda function permission has a source arn specified", 18 Impact: "Not providing the source ARN allows any resource from principal, even from other accounts", 19 Resolution: "Always provide a source arn for Lambda permissions", 20 Explanation: `When the principal is an AWS service, the ARN of the specific resource within that service to grant permission to. 21 22 Without this, any resource from principal will be granted permission – even if that resource is from another account. 23 24 For S3, this should be the ARN of the S3 Bucket. For CloudWatch Events, this should be the ARN of the CloudWatch Events Rule. For API Gateway, this should be the ARN of the API`, 25 Links: []string{ 26 "https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-permission.html", 27 }, 28 Terraform: &scan.EngineMetadata{ 29 GoodExamples: terraformRestrictSourceArnGoodExamples, 30 BadExamples: terraformRestrictSourceArnBadExamples, 31 Links: terraformRestrictSourceArnLinks, 32 RemediationMarkdown: terraformRestrictSourceArnRemediationMarkdown, 33 }, 34 CloudFormation: &scan.EngineMetadata{ 35 GoodExamples: cloudFormationRestrictSourceArnGoodExamples, 36 BadExamples: cloudFormationRestrictSourceArnBadExamples, 37 Links: cloudFormationRestrictSourceArnLinks, 38 RemediationMarkdown: cloudFormationRestrictSourceArnRemediationMarkdown, 39 }, 40 Severity: severity.Critical, 41 }, 42 func(s *state.State) (results scan.Results) { 43 for _, function := range s.AWS.Lambda.Functions { 44 for _, permission := range function.Permissions { 45 if !permission.Principal.EndsWith(".amazonaws.com") { 46 continue 47 } 48 if permission.SourceARN.IsEmpty() { 49 results.Add( 50 "Lambda permission lacks source ARN for *.amazonaws.com principal.", 51 permission.SourceARN, 52 ) 53 } else { 54 results.AddPassed(&function) 55 } 56 } 57 } 58 return 59 }, 60 )