Skip to content

Commit

Permalink
checks(aws): change the wording of AVD-AWS-0015
Browse files Browse the repository at this point in the history
  • Loading branch information
nikpivkin authored and simar7 committed Mar 26, 2024
1 parent 1e43dca commit 4b444db
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 75 deletions.
4 changes: 3 additions & 1 deletion avd_docs/aws/cloudtrail/AVD-AWS-0015/CloudFormation.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

Enable encryption at rest
Use Customer managed key

```yaml---
Resources:
Expand All @@ -15,4 +15,6 @@ Resources:
```

#### Remediation Links
- https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-cloudtrail-trail.html#cfn-cloudtrail-trail-kmskeyid

2 changes: 1 addition & 1 deletion avd_docs/aws/cloudtrail/AVD-AWS-0015/Terraform.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

Enable encryption at rest
Use Customer managed key

```hcl
resource "aws_cloudtrail" "good_example" {
Expand Down
6 changes: 4 additions & 2 deletions avd_docs/aws/cloudtrail/AVD-AWS-0015/docs.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@

Cloudtrail logs should be encrypted at rest to secure the sensitive data. Cloudtrail logs record all activity that occurs in the the account through API calls and would be one of the first places to look when reacting to a breach.
Using Customer managed keys provides comprehensive control over cryptographic keys, enabling management of policies, permissions, and rotation, thus enhancing security and compliance measures for sensitive data and systems.

### Impact
Data can be freely read if compromised
Using AWS managed keys does not allow for fine grained control

<!-- DO NOT CHANGE -->
{{ remediationActions }}

### Links
- https://docs.aws.amazon.com/awscloudtrail/latest/userguide/encrypting-cloudtrail-log-files-with-aws-kms.html

- https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#key-mgmt


51 changes: 0 additions & 51 deletions checks/cloud/aws/cloudtrail/enable_at_rest_encryption.go

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package cloudtrail

var cloudFormationEnableAtRestEncryptionGoodExamples = []string{
var cloudFormationEncryptionCustomerManagedKeyGoodExamples = []string{
`---
Resources:
BadExample:
Expand All @@ -15,7 +15,7 @@ Resources:
`,
}

var cloudFormationEnableAtRestEncryptionBadExamples = []string{
var cloudFormationEncryptionCustomerManagedKeyBadExamples = []string{
`---
Resources:
BadExample:
Expand All @@ -29,6 +29,6 @@ Resources:
`,
}

var cloudFormationEnableAtRestEncryptionLinks = []string{}

var cloudFormationEnableAtRestEncryptionRemediationMarkdown = ``
var cloudFormationEncryptionCustomerManagedKeyLinks = []string{
"https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-cloudtrail-trail.html#cfn-cloudtrail-trail-kmskeyid",
}
52 changes: 52 additions & 0 deletions checks/cloud/aws/cloudtrail/encryption_customer_key.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package cloudtrail

import (
"github.com/aquasecurity/trivy-policies/pkg/rules"
"github.com/aquasecurity/trivy/pkg/iac/providers"
"github.com/aquasecurity/trivy/pkg/iac/scan"
"github.com/aquasecurity/trivy/pkg/iac/severity"
"github.com/aquasecurity/trivy/pkg/iac/state"
)

var EncryptionCustomerManagedKey = rules.Register(
scan.Rule{
AVDID: "AVD-AWS-0015",
Provider: providers.AWSProvider,
Service: "cloudtrail",
ShortCode: "encryption-customer-managed-key",
Summary: "CloudTrail should use Customer managed keys to encrypt the logs",
Impact: "Using AWS managed keys does not allow for fine grained control",
Resolution: "Use Customer managed key",
Explanation: `Using Customer managed keys provides comprehensive control over cryptographic keys, enabling management of policies, permissions, and rotation, thus enhancing security and compliance measures for sensitive data and systems.`,
Links: []string{
"https://docs.aws.amazon.com/awscloudtrail/latest/userguide/encrypting-cloudtrail-log-files-with-aws-kms.html",
"https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#key-mgmt",
},
Terraform: &scan.EngineMetadata{
GoodExamples: terraformEncryptionCustomerManagedKeyGoodExamples,
BadExamples: terraformEncryptionCustomerManagedKeyBadExamples,
Links: terraformEncryptionCustomerManagedKeyLinks,
RemediationMarkdown: ``,
},
CloudFormation: &scan.EngineMetadata{
GoodExamples: cloudFormationEncryptionCustomerManagedKeyGoodExamples,
BadExamples: cloudFormationEncryptionCustomerManagedKeyBadExamples,
Links: cloudFormationEncryptionCustomerManagedKeyLinks,
RemediationMarkdown: ``,
},
Severity: severity.High,
},
func(s *state.State) (results scan.Results) {
for _, trail := range s.AWS.CloudTrail.Trails {
if trail.KMSKeyID.IsEmpty() {
results.Add(
"CloudTrail does not use a customer managed key to encrypt the logs.",
trail.KMSKeyID,
)
} else {
results.AddPassed(&trail)
}
}
return
},
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package cloudtrail

var terraformEnableAtRestEncryptionGoodExamples = []string{
var terraformEncryptionCustomerManagedKeyGoodExamples = []string{
`
resource "aws_cloudtrail" "good_example" {
is_multi_region_trail = true
Expand All @@ -20,7 +20,7 @@ var terraformEnableAtRestEncryptionGoodExamples = []string{
`,
}

var terraformEnableAtRestEncryptionBadExamples = []string{
var terraformEncryptionCustomerManagedKeyBadExamples = []string{
`
resource "aws_cloudtrail" "bad_example" {
is_multi_region_trail = true
Expand All @@ -38,8 +38,6 @@ var terraformEnableAtRestEncryptionBadExamples = []string{
`,
}

var terraformEnableAtRestEncryptionLinks = []string{
var terraformEncryptionCustomerManagedKeyLinks = []string{
`https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudtrail#kms_key_id`,
}

var terraformEnableAtRestEncryptionRemediationMarkdown = ``
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,22 @@ package cloudtrail
import (
"testing"

trivyTypes "github.com/aquasecurity/trivy/pkg/iac/types"

"github.com/aquasecurity/trivy/pkg/iac/state"
"github.com/stretchr/testify/assert"

"github.com/aquasecurity/trivy/pkg/iac/providers/aws/cloudtrail"
"github.com/aquasecurity/trivy/pkg/iac/scan"

"github.com/stretchr/testify/assert"
"github.com/aquasecurity/trivy/pkg/iac/state"
trivyTypes "github.com/aquasecurity/trivy/pkg/iac/types"
)

func TestCheckEnableAtRestEncryption(t *testing.T) {
func TestEncryptionCustomerManagedKey(t *testing.T) {
tests := []struct {
name string
input cloudtrail.CloudTrail
expected bool
}{
{
name: "AWS CloudTrail unencrypted",
name: "AWS CloudTrail without CMK",
input: cloudtrail.CloudTrail{
Trails: []cloudtrail.Trail{
{
Expand All @@ -32,7 +30,7 @@ func TestCheckEnableAtRestEncryption(t *testing.T) {
expected: true,
},
{
name: "AWS CloudTrail encrypted with KMS key",
name: "AWS CloudTrail with CMK",
input: cloudtrail.CloudTrail{
Trails: []cloudtrail.Trail{
{
Expand All @@ -48,10 +46,10 @@ func TestCheckEnableAtRestEncryption(t *testing.T) {
t.Run(test.name, func(t *testing.T) {
var testState state.State
testState.AWS.CloudTrail = test.input
results := CheckEnableAtRestEncryption.Evaluate(&testState)
results := EncryptionCustomerManagedKey.Evaluate(&testState)
var found bool
for _, result := range results {
if result.Status() == scan.StatusFailed && result.Rule().LongID() == CheckEnableAtRestEncryption.LongID() {
if result.Status() == scan.StatusFailed && result.Rule().LongID() == EncryptionCustomerManagedKey.LongID() {
found = true
}
}
Expand Down

0 comments on commit 4b444db

Please sign in to comment.