github.com/khulnasoft-lab/defsec@v1.0.5-0.20230827010352-5e9f46893d95/rules/cloud/policies/aws/ecr/enforce_immutable_repository.go (about) 1 package ecr 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 CheckEnforceImmutableRepository = rules.Register( 12 scan.Rule{ 13 AVDID: "AVD-AWS-0031", 14 Provider: providers.AWSProvider, 15 Service: "ecr", 16 ShortCode: "enforce-immutable-repository", 17 Summary: "ECR images tags shouldn't be mutable.", 18 Impact: "Image tags could be overwritten with compromised images", 19 Resolution: "Only use immutable images in ECR", 20 Explanation: `ECR images should be set to IMMUTABLE to prevent code injection through image mutation. 21 22 This can be done by setting <code>image_tab_mutability</code> to <code>IMMUTABLE</code>`, 23 Links: []string{ 24 "https://sysdig.com/blog/toctou-tag-mutability/", 25 }, 26 Terraform: &scan.EngineMetadata{ 27 GoodExamples: terraformEnforceImmutableRepositoryGoodExamples, 28 BadExamples: terraformEnforceImmutableRepositoryBadExamples, 29 Links: terraformEnforceImmutableRepositoryLinks, 30 RemediationMarkdown: terraformEnforceImmutableRepositoryRemediationMarkdown, 31 }, 32 CloudFormation: &scan.EngineMetadata{ 33 GoodExamples: cloudFormationEnforceImmutableRepositoryGoodExamples, 34 BadExamples: cloudFormationEnforceImmutableRepositoryBadExamples, 35 Links: cloudFormationEnforceImmutableRepositoryLinks, 36 RemediationMarkdown: cloudFormationEnforceImmutableRepositoryRemediationMarkdown, 37 }, 38 Severity: severity.High, 39 }, 40 func(s *state.State) (results scan.Results) { 41 for _, repo := range s.AWS.ECR.Repositories { 42 if repo.ImageTagsImmutable.IsFalse() { 43 results.Add( 44 "Repository tags are mutable.", 45 repo.ImageTagsImmutable, 46 ) 47 } else { 48 results.AddPassed(&repo) 49 } 50 } 51 return 52 }, 53 )