Skip to content

feat: checks for awscc provider resources #7043

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
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: added bedrock agent encryption policy
  • Loading branch information
quixoticmonk committed Mar 6, 2025
commit ec576fb339808a53da9126baa4c6e4ab6e39ec24
25 changes: 25 additions & 0 deletions checkov/terraform/checks/resource/awscc/BedrockAgentEncrypted.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from typing import Any

from checkov.common.models.consts import ANY_VALUE
from checkov.common.models.enums import CheckCategories
from checkov.terraform.checks.resource.base_resource_value_check import (
BaseResourceValueCheck,
)


class BedrockAgentEncrypted(BaseResourceValueCheck):
def __init__(self) -> None:
name = "Ensure Bedrock Agent is encrypted with a CMK"
id = "CKV_AWS_373"
supported_resources = ("awscc_bedrock_agent",)
categories = (CheckCategories.ENCRYPTION,)
super().__init__(name=name, id=id, categories=categories, supported_resources=supported_resources)

def get_inspected_key(self) -> str:
return "customer_encryption_key_arn"

def get_expected_value(self) -> Any:
return ANY_VALUE


check = BedrockAgentEncrypted()
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class BedrockGuardrails(BaseResourceValueCheck):
def __init__(self) -> None:
name = "Ensure AWS Bedrock agent is associated with Bedrock guardrails"
id = "CKV_AWS_383"
supported_resources = ("awscc_bedrockagent_agent",)
supported_resources = ("awscc_bedrock_agent",)
categories = (CheckCategories.AI_AND_ML,)
super().__init__(name=name, id=id, categories=categories, supported_resources=supported_resources)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
resource "awscc_bedrock_agent" "pass" {
agent_name = "pass"
instruction = "You are a helpful assistant that provides information about our company's products."
foundation_model = "anthropic.claude-v2"
customer_encryption_key_arn = awscc_kms_key.example.arn
}

resource "awscc_bedrock_agent" "fail" {
agent_name = "fail"
instruction = "You are a helpful assistant that provides information about our company's products."
foundation_model = "anthropic.claude-v2"


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import os
import unittest

from checkov.runner_filter import RunnerFilter
from checkov.terraform.checks.resource.awscc.BedrockGuardrails import check
from checkov.terraform.runner import Runner


class TestBedrockGuardrails(unittest.TestCase):
def test(self):
runner = Runner()
current_dir = os.path.dirname(os.path.realpath(__file__))

test_files_dir = current_dir + "/example_BedrockAgentEncrypted"
report = runner.run(
root_folder=test_files_dir, runner_filter=RunnerFilter(checks=[check.id])
)
summary = report.get_summary()

passing_resources = {
"awscc_bedrock_agent.pass",
}
failing_resources = {
"awscc_bedrock_agent.fail"
}

passed_check_resources = set([c.resource for c in report.passed_checks])
failed_check_resources = set([c.resource for c in report.failed_checks])

self.assertEqual(summary["passed"], len(passing_resources))
self.assertEqual(summary["failed"], len(failing_resources))
self.assertEqual(summary["skipped"], 0)
self.assertEqual(summary["parsing_errors"], 0)

self.assertEqual(passing_resources, passed_check_resources)
self.assertEqual(failing_resources, failed_check_resources)


if __name__ == "__main__":
unittest.main()
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ def test(self):
summary = report.get_summary()

passing_resources = {
"awscc_bedrockagent_agent.pass",
"awscc_bedrock_agent.pass",
}
failing_resources = {
"awscc_bedrockagent_agent.fail"
"awscc_bedrock_agent.fail"
}

passed_check_resources = set([c.resource for c in report.passed_checks])
Expand Down