For AI agents: A markdown version of this page is available at https://docs.datadoghq.com/security/code_security/iac_security/iac_rules/terraform-aws-secretsmanager-secret-without-kms.md. A documentation index is available at /llms.txt.
This product is not supported for your selected Datadog site. ().

Metadata

Id: terraform-aws-secretsmanager-secret-without-kms

Provider: AWS

Platform: Terraform

Severity: Medium

Category: Encryption

Learn More

Description

By default, AWS Secrets Manager encrypts secrets using the default AWS-managed key, which may not provide the desired level of control over key rotation, access policies, or auditability. Without explicitly specifying a kms_key_id in your Terraform resource, as shown below, secrets will not use a customer-managed AWS KMS key (CMK) for encryption:

resource "aws_secretsmanager_secret" "example" {
  name = "example"
}

This misconfiguration can increase the exposure of sensitive data and limit your ability to implement strict access controls. To reduce risk, explicitly provide a kms_key_id attribute referencing a CMK:

resource "aws_secretsmanager_secret" "example" {
  name       = "example"
  kms_key_id = "arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab"
}

Compliant Code Examples

resource "aws_secretsmanager_secret" "example" {
  name = "example"
  kms_key_id = "arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab"
}
resource "aws_kms_key" "example" {
  description = "Example KMS key"
}

module "complete" {
  source  = "terraform-aws-modules/secrets-manager/aws"
  version = "5.30.1"

  create_role             = true
  role_name               = "complete-example"
  role_requires_mfa       = true
  role_description        = "My awesome role"
  role_permissions_boundary_arn = "arn:aws:iam::aws:policy/AdministratorAccess"
  custom_role_policy_arns = [
    "arn:aws:iam::aws:policy/AdministratorAccess",
  ]
  role_policy_arns = [
    "arn:aws:iam::aws:policy/AdministratorAccess",
  ]

  tags = {
    Role = "role"
  }
  kms_key_id = aws_kms_key.example.arn
}

Non-Compliant Code Examples

resource "aws_secretsmanager_secret" "example" {
  name = "example"
}