github.com/khulnasoft-lab/defsec@v1.0.5-0.20230827010352-5e9f46893d95/rules/cloud/policies/aws/sam/no_state_machine_policy_wildcards.go (about)

     1  package sam
     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 CheckNoStateMachinePolicyWildcards = rules.Register(
    12  	scan.Rule{
    13  		AVDID:       "AVD-AWS-0120",
    14  		Provider:    providers.AWSProvider,
    15  		Service:     "sam",
    16  		ShortCode:   "no-state-machine-policy-wildcards",
    17  		Summary:     "State machine policies should avoid use of wildcards and instead apply the principle of least privilege",
    18  		Impact:      "Overly permissive policies may grant access to sensitive resources",
    19  		Resolution:  "Specify the exact permissions required, and to which resources they should apply instead of using wildcards.",
    20  		Explanation: `You should use the principle of least privilege when defining your IAM policies. This means you should specify each exact permission required without using wildcards, as this could cause the granting of access to certain undesired actions, resources and principals.`,
    21  		Links: []string{
    22  			"https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-statemachine.html#sam-statemachine-policies",
    23  		},
    24  		CloudFormation: &scan.EngineMetadata{
    25  			GoodExamples:        cloudFormationNoStateMachinePolicyWildcardsGoodExamples,
    26  			BadExamples:         cloudFormationNoStateMachinePolicyWildcardsBadExamples,
    27  			Links:               cloudFormationNoStateMachinePolicyWildcardsLinks,
    28  			RemediationMarkdown: cloudFormationNoStateMachinePolicyWildcardsRemediationMarkdown,
    29  		},
    30  		Severity: severity.High,
    31  	},
    32  	func(s *state.State) (results scan.Results) {
    33  
    34  		for _, stateMachine := range s.AWS.SAM.StateMachines {
    35  			if stateMachine.Metadata.IsUnmanaged() {
    36  				continue
    37  			}
    38  
    39  			for _, document := range stateMachine.Policies {
    40  				policy := document.Document.Parsed
    41  				statements, _ := policy.Statements()
    42  				for _, statement := range statements {
    43  					results = checkStatement(document.Document, statement, results)
    44  				}
    45  			}
    46  		}
    47  		return
    48  	},
    49  )