Skip to content
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

Add policy pack - Enforce Encryption for AWS Athena Workgroups. Closes #874 #875

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
102 changes: 102 additions & 0 deletions policy_packs/aws/athena/enforce_encryption_for_workgroups/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
---
categories: ["data protection", "storage"]
primary_category: "data protection"
---

# Enforce AWS Athena Workgroups Have Encryption Enabled

Ensuring that AWS Athena workgroups have encryption enabled for query results stored in Amazon S3 is crucial for protecting sensitive data and complying with security best practices. This policy pack enforces encryption settings on Athena workgroups to safeguard data at rest.

This [policy pack](https://turbot.com/guardrails/docs/concepts/policy-packs) helps you configure the following settings for Athena workgroups:

- Enforce that query results stored in Amazon S3 are encrypted.
- Approve or enforce encryption configurations for Athena workgroups.

**[Review policy settings →](https://hub.guardrails.turbot.com/policy-packs/aws_athena_enforce_encryption_for_workgroups/settings)**

## Getting Started

### Requirements

- [Terraform](https://developer.hashicorp.com/terraform/downloads)
- The following Guardrails mod must be installed:
- [@turbot/aws-athena](https://hub.guardrails.turbot.com/mods/aws/mods/aws-athena)

### Credentials

To create a policy pack through Terraform:

- Ensure you have `Turbot/Admin` permissions (or higher) in Guardrails.
- [Create access keys](https://turbot.com/guardrails/docs/guides/iam/access-keys#generate-a-new-guardrails-api-access-key) in Guardrails.

Set your credentials:

```sh
export TURBOT_WORKSPACE="myworkspace.acme.com"
export TURBOT_ACCESS_KEY="acce6ac5-access-key-here"
export TURBOT_SECRET_KEY="a8af61ec-secret-key-here"
```

Please see [Turbot Guardrails Provider authentication](https://registry.terraform.io/providers/turbot/turbot/latest/docs#authentication) for additional authentication methods.

## Usage

## Install Policy Pack

> [!NOTE]
> By default, installed policy packs are not attached to any resources.
>
> Policy packs must be attached to resources in order for their policy settings to take effect.

Clone:

```sh
git clone https://github.com/turbot/guardrails-samples.git
cd guardrails-samples/policy_packs/aws/athena/enforce_encryption_for_workgroups
```

Run the Terraform to create the policy pack in your workspace:

```sh
terraform init
terraform plan
```

Then apply the changes:

```sh
terraform apply
```

### Apply Policy Pack

Log into your Guardrails workspace and [attach the policy pack to a resource](https://turbot.com/guardrails/docs/guides/policy-packs#attach-a-policy-pack-to-a-resource).

If this policy pack is attached to a Guardrails folder, its policies will be applied to all accounts and resources in that folder. The policy pack can also be attached to multiple resources.

For more information, please see [Policy Packs](https://turbot.com/guardrails/docs/concepts/policy-packs).

### Enable Enforcement

> [!TIP]
> You can also update the policy settings in this policy pack directly in the Guardrails console.
>
> Please note your Terraform state file will then become out of sync and the policy settings should then only be managed in the console.

By default, the policies are set to `Check` in the pack's policy settings. To enable automated enforcements, you can switch these policies settings by adding a comment to the `Check` setting and removing the comment from one of the listed enforcement options:

```hcl
resource "turbot_policy_setting" "aws_athena_workgroup_approved" {
resource = turbot_policy_pack.main.id
type = "tmod:@turbot/aws-athena#/policy/types/workgroupApproved"
# value = "Check: Approved"
value = "Enforce: Delete unapproved if new"
}
```

Then re-apply the changes:

```sh
terraform plan
terraform apply
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
resource "turbot_policy_pack" "main" {
title = "Enforce Encryption for AWS Athena Workgroups"
description = "Ensures that AWS Athena workgroups have encryption enabled for query results stored in Amazon S3."
akas = ["aws_athena_enforce_encryption_for_workgroups"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# AWS > Athena > Workgroup > Approved
resource "turbot_policy_setting" "aws_athena_workgroup_approved" {
resource = turbot_policy_pack.main.id
type = "tmod:@turbot/aws-athena#/policy/types/workgroupApproved"
value = "Check: Approved"
# value = "Enforce: Delete unapproved if new"
}

# AWS > Athena > Workgroup > Approved > Custom
resource "turbot_policy_setting" "aws_athena_workgroup_approved_custom" {
resource = turbot_policy_pack.main.id
type = "tmod:@turbot/aws-athena#/policy/types/workgroupApprovedCustom"
template_input = <<-EOT
{
workgroup {
resultEncryptionConfig: get(path: "Configuration.ResultConfiguration.EncryptionConfiguration.EncryptionOption")
workspaceMinimumEncryption: get(path: "Configuration.EnableMinimumEncryptionConfiguration")
}
}
EOT
template = <<-EOT

{%- set data = {
"title": "Encryption enabled",
"result": "Not approved",
"message": "No encryption options for this workgroup"
} -%}

{%- if $.workspace.workspaceMinimumEncryption -%}
{%- set data = {
"title": "Encryption enabled",
"result": "Approved",
"message": "Minimum encryption option set for workspace"
} -%}

{%- elif $.workspace.resultEncryptionConfig -%}
{%- set data = {
"title": "Encryption enabled",
"result": "Approved",
"message": "Result configuration set to: " + $.workspace.resultEncryptionConfig
} -%}

{%- endif -%}
{{ data | json }}
EOT
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
terraform {
required_providers {
turbot = {
source = "turbot/turbot"
version = ">= 1.11.0"
}
}
}

provider "turbot" {
}