Athena database query-result encryption settings need review

Check the output location and encryption key for Athena database-creation queries.

Description

On aws_athena_database, encryption_configuration applies to the result files from creating or dropping the database. Source data in S3, Glue metadata and the results of later queries each need separate protection.

Potential impact

S3 encrypts new objects by default, but the selected key may fall short of your policy. Broad read permissions can still expose result files.

Remediation

Check the result location and its S3 and KMS permissions. For a customer managed key, select SSE_KMS and supply its ARN. To enforce the same settings on later queries, override client settings in their workgroup. Review the plan before changing encryption because Terraform can replace the database resource.

Examples

Separate encryption configuration omitted

hcl
resource "aws_athena_database" "analytics_db" {
  name   = "database_name"
  bucket = aws_s3_bucket.hoge.bucket
}

Result encryption key selected

hcl
resource "aws_athena_database" "analytics_db" {
  name   = "database_name"
  bucket = aws_s3_bucket.hoge.bucket

  encryption_configuration {
    encryption_option = "SSE_KMS"
    kms_key           = aws_kms_key.example.arn
  }
}

The second example specifies kms_key for results in the referenced S3 bucket. A workgroup configured to override client settings takes precedence. Existing files keep their encryption.

References