-
Notifications
You must be signed in to change notification settings - Fork 6
Added SNS.1 #307
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nhammadi
wants to merge
1
commit into
hashicorp:main
Choose a base branch
from
nhammadi:SNS.1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Added SNS.1 #307
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# Amazon SQS queues should be encrypted at rest | ||
|
||
| Provider | Category | | ||
| ------------------- | ------------------------- | | ||
| Amazon Web Services | Data Protection | | ||
|
||
## Description | ||
|
||
This control checks whether an Amazon SNS topic is encrypted at rest using keys managed in AWS Key Management Service (AWS KMS). The controls fails if the SNS topic doesn't use a KMS key for server-side encryption (SSE). By default, SNS stores messages and files using disk encryption. To pass this control, you must choose to use a KMS key for encryption instead. This adds an additional layer of security and provides more access control flexibility. | ||
|
||
Encrypting data at rest reduces the risk of data stored on disk being accessed by a user not authenticated to AWS. API permissions are required to decrypt the data before it can be read. We recommend encrypting SNS topics with KMS keys for an added layer of security. | ||
|
||
This rule is covered by the [sns-topic-should-be-encrypted-at-rest](https://github.com/hashicorp/policy-library-FSBP-Policy-Set-for-AWS-Terraform/blob/main/policies/sns-topic-should-be-encrypted-at-rest.sentinel) policy. | ||
|
||
## Policy Results (Pass) | ||
|
||
```bash | ||
trace: | ||
Pass - sns-topic-should-be-encrypted-at-rest.sentinel | ||
|
||
Description: | ||
This policy requires resources of type `aws_sns_topic` to be encrypted at | ||
rest. | ||
|
||
Print messages: | ||
|
||
→ → Overall Result: true | ||
|
||
This result means that all resources have passed the policy check for the policy sns-topic-should-be-encrypted-at-rest. | ||
|
||
✓ Found 0 resource violations | ||
|
||
sns-topic-should-be-encrypted-at-rest.sentinel:52:1 - Rule "main" | ||
Value: | ||
true | ||
``` | ||
|
||
--- | ||
|
||
## Policy Results (Fail) | ||
|
||
```bash | ||
trace: | ||
Fail - sns-topic-should-be-encrypted-at-rest.sentinel | ||
|
||
Description: | ||
This policy requires resources of type `aws_sns_topic` to be encrypted at | ||
rest. | ||
|
||
Print messages: | ||
|
||
→ → Overall Result: false | ||
|
||
This result means that not all resources passed the policy check and the protected behavior is not allowed for the policy sns-topic-should-be-encrypted-at-rest. | ||
|
||
Found 1 resource violations | ||
|
||
→ Module name: root | ||
↳ Resource Address: aws_sns_topic.user_updates | ||
| ✗ failed | ||
| SNS topics should be encrypted at rest. Refer to https://docs.aws.amazon.com/securityhub/latest/userguide/sns-controls.html#sns-1 for more details. | ||
|
||
|
||
sns-topic-should-be-encrypted-at-rest.sentinel:52:1 - Rule "main" | ||
Value: | ||
``` | ||
|
||
--- |
54 changes: 54 additions & 0 deletions
54
policies/sns/sns-topic-should-be-encrypted-at-rest.sentinel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# This policy requires resources of type `aws_sns_topic` to be encrypted at rest. | ||
|
||
# Copyright (c) HashiCorp, Inc. | ||
# SPDX-License-Identifier: BUSL-1.1 | ||
|
||
# Imports | ||
|
||
import "tfplan/v2" as tfplan | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is recommended to use import "tfconfig/v2" mock since if the user is using a customer managed kms key which is being created using terraform |
||
import "tfresources" as tf | ||
import "report" as report | ||
import "collection" as collection | ||
import "collection/maps" as maps | ||
|
||
# Constants | ||
|
||
const = { | ||
"policy_name": "sns-topic-should-be-encrypted-at-rest", | ||
"message": "SNS topics should be encrypted at rest. Refer to https://docs.aws.amazon.com/securityhub/latest/userguide/sns-controls.html#sns-1 for more details.", | ||
"resource_aws_sns_topic": "aws_sns_topic", | ||
} | ||
|
||
# Functions | ||
|
||
get_violations = func(resources) { | ||
return collection.reject(resources, func(res) { | ||
return maps.get(res, "values.kms_master_key_id", null) is not null | ||
}) | ||
} | ||
|
||
# Variables | ||
|
||
aws_sns_topics = tf.plan(tfplan.planned_values.resources).type(const.resource_aws_sns_topic).resources | ||
violations = get_violations(aws_sns_topics) | ||
|
||
summary = { | ||
"policy_name": const.policy_name, | ||
"violations": map violations as _, v { | ||
{ | ||
"address": v.address, | ||
"module_address": v.module_address, | ||
"message": const.message, | ||
} | ||
}, | ||
} | ||
|
||
# Outputs | ||
|
||
print(report.generate_policy_report(summary)) | ||
|
||
# Rules | ||
|
||
main = rule { | ||
violations is empty | ||
} |
26 changes: 26 additions & 0 deletions
26
...s/sns/test/sns-topic-should-be-encrypted-at-rest/failure-encryption-at-rest-undefined.hcl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Copyright (c) HashiCorp, Inc. | ||
# SPDX-License-Identifier: BUSL-1.1 | ||
|
||
mock "tfplan/v2" { | ||
module { | ||
source = "./mocks/failure-encryption-at-rest-undefined/mock-tfplan-v2.sentinel" | ||
} | ||
} | ||
|
||
mock "tfresources" { | ||
module { | ||
source = "../../../../modules/tfresources/tfresources.sentinel" | ||
} | ||
} | ||
|
||
mock "report" { | ||
module { | ||
source = "../../../../modules/mocks/report/report.sentinel" | ||
} | ||
} | ||
|
||
test { | ||
rules = { | ||
main = false | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...d-be-encrypted-at-rest/mocks/failure-encryption-at-rest-undefined/mock-tfplan-v2.sentinel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
terraform_version = "1.7.4" | ||
|
||
planned_values = { | ||
"outputs": {}, | ||
"resources": { | ||
"aws_sns_topic.user_updates": { | ||
"address": "aws_sns_topic.user_updates", | ||
"depends_on": [], | ||
"deposed_key": "", | ||
"index": null, | ||
"mode": "managed", | ||
"module_address": "", | ||
"name": "user_updates", | ||
"provider_name": "registry.terraform.io/hashicorp/aws", | ||
"tainted": false, | ||
"type": "aws_sns_topic", | ||
"values": { | ||
"application_failure_feedback_role_arn": null, | ||
"application_success_feedback_role_arn": null, | ||
"application_success_feedback_sample_rate": null, | ||
"archive_policy": null, | ||
"content_based_deduplication": false, | ||
"delivery_policy": null, | ||
"display_name": null, | ||
"fifo_topic": false, | ||
"firehose_failure_feedback_role_arn": null, | ||
"firehose_success_feedback_role_arn": null, | ||
"firehose_success_feedback_sample_rate": null, | ||
"http_failure_feedback_role_arn": null, | ||
"http_success_feedback_role_arn": null, | ||
"http_success_feedback_sample_rate": null, | ||
"kms_master_key_id": null, | ||
"lambda_failure_feedback_role_arn": null, | ||
"lambda_success_feedback_role_arn": null, | ||
"lambda_success_feedback_sample_rate": null, | ||
"name": "user-updates-topic", | ||
"region": "eu-west-1", | ||
"sqs_failure_feedback_role_arn": null, | ||
"sqs_success_feedback_role_arn": null, | ||
"sqs_success_feedback_sample_rate": null, | ||
"tags": null, | ||
}, | ||
}, | ||
}, | ||
} |
45 changes: 45 additions & 0 deletions
45
...cies/sns/test/sns-topic-should-be-encrypted-at-rest/mocks/success/mock-tfplan-v2.sentinel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
terraform_version = "1.7.4" | ||
|
||
planned_values = { | ||
"outputs": {}, | ||
"resources": { | ||
"aws_sns_topic.user_updates": { | ||
"address": "aws_sns_topic.user_updates", | ||
"depends_on": [], | ||
"deposed_key": "", | ||
"index": null, | ||
"mode": "managed", | ||
"module_address": "", | ||
"name": "user_updates", | ||
"provider_name": "registry.terraform.io/hashicorp/aws", | ||
"tainted": false, | ||
"type": "aws_sns_topic", | ||
"values": { | ||
"application_failure_feedback_role_arn": null, | ||
"application_success_feedback_role_arn": null, | ||
"application_success_feedback_sample_rate": null, | ||
"archive_policy": null, | ||
"content_based_deduplication": false, | ||
"delivery_policy": null, | ||
"display_name": null, | ||
"fifo_topic": false, | ||
"firehose_failure_feedback_role_arn": null, | ||
"firehose_success_feedback_role_arn": null, | ||
"firehose_success_feedback_sample_rate": null, | ||
"http_failure_feedback_role_arn": null, | ||
"http_success_feedback_role_arn": null, | ||
"http_success_feedback_sample_rate": null, | ||
"kms_master_key_id": "alias/aws/sns", | ||
"lambda_failure_feedback_role_arn": null, | ||
"lambda_success_feedback_role_arn": null, | ||
"lambda_success_feedback_sample_rate": null, | ||
"name": "user-updates-topic", | ||
"region": "eu-west-1", | ||
"sqs_failure_feedback_role_arn": null, | ||
"sqs_success_feedback_role_arn": null, | ||
"sqs_success_feedback_sample_rate": null, | ||
"tags": null, | ||
}, | ||
}, | ||
}, | ||
} |
26 changes: 26 additions & 0 deletions
26
policies/sns/test/sns-topic-should-be-encrypted-at-rest/success.hcl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Copyright (c) HashiCorp, Inc. | ||
# SPDX-License-Identifier: BUSL-1.1 | ||
|
||
mock "tfplan/v2" { | ||
module { | ||
source = "./mocks/success/mock-tfplan-v2.sentinel" | ||
} | ||
} | ||
|
||
mock "tfresources" { | ||
module { | ||
source = "../../../../modules/tfresources/tfresources.sentinel" | ||
} | ||
} | ||
|
||
mock "report" { | ||
module { | ||
source = "../../../../modules/mocks/report/report.sentinel" | ||
} | ||
} | ||
|
||
test { | ||
rules = { | ||
main = true | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.