terraform.aws.security.missing-athena-workgroup-encryption.missing-athena-workgroup-encryption

profile photo of semgrepsemgrep
Author
unknown
Download Count*

The AWS Athena Workgroup is unencrypted. Encryption protects query results in your workgroup. To enable, add: encryption_configuration { encryption_option = "SSE_KMS" kms_key_arn = aws_kms_key.example.arn } within result_configuration { } in your resource block, where encryption_option is your chosen encryption method and kms_key_arn is your KMS key ARN.

Run Locally

Run in CI

Defintion

rules:
  - id: missing-athena-workgroup-encryption
    patterns:
      - pattern: resource "aws_athena_workgroup" $ANYTHING {...}
      - pattern-not-inside: |
          resource "aws_athena_workgroup" $ANYTHING {
            ...
            encryption_configuration {...}
            ...
          }
    message: 'The AWS Athena Workgroup is unencrypted. Encryption protects query
      results in your workgroup. To enable, add: `encryption_configuration {
      encryption_option = "SSE_KMS" kms_key_arn =  aws_kms_key.example.arn }`
      within `result_configuration { }` in your resource block,  where
      `encryption_option` is your chosen encryption method and `kms_key_arn`  is
      your KMS key ARN.'
    languages:
      - hcl
    severity: WARNING
    metadata:
      technology:
        - aws
        - terraform
      category: security
      owasp:
        - A03:2017 - Sensitive Data Exposure
      cwe:
        - "CWE-320: CWE CATEGORY: Key Management Errors"
      references:
        - https://owasp.org/Top10/A02_2021-Cryptographic_Failures
      subcategory:
        - audit
      likelihood: LOW
      impact: LOW
      confidence: LOW
      license: Commons Clause License Condition v1.0[LGPL-2.1-only]
      vulnerability_class:
        - Cryptographic Issues

Examples

missing-athena-workgroup-encryption.tf

# ruleid: missing-athena-workgroup-encryption
resource "aws_athena_workgroup" "fail" {
  name = "wg-non-encrypted"

  configuration {
    enforce_workgroup_configuration    = true
    publish_cloudwatch_metrics_enabled = true

    result_configuration {
      output_location = "s3://mys3bucket"
    }
  }
}

# ok: missing-athena-workgroup-encryption
resource "aws_athena_workgroup" "pass" {
  name = "wg-encrypted"

  configuration {
    enforce_workgroup_configuration    = true
    publish_cloudwatch_metrics_enabled = true

    result_configuration {
      output_location = "s3://mys3bucket"
      encryption_configuration {
        encryption_option = "SSE_KMS"
        kms_key_arn       = "mykmsarn"
      }
    }
  }
}