Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

Credstash grant #266

Open
wants to merge 3 commits into
base: master
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
21 changes: 5 additions & 16 deletions modules/credstash-grant-reader/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,10 @@ variable "reader_policy_arn" {
type = string
}

variable "context_keys" {
default = []
description = "list of keys to be zipped with the context_values to set an 'encryption context' for additional granularity that clients are required to provide to read encrypted values. Eg. for env=dev svc=db, this would be [env, svc]. All readers get this context map."
type = list(string)
}

variable "context_values" {
default = []
description = "list of values to be zipped with the context_keys to set an 'encryption context' for additional granularity that clients are required to provide to read encrypted values. Eg. for env=dev svc=db, this would be [dev, db]. All readers get this context map."
type = list(string)
variable "context" {
default = {}
description = "Context for additional granularity that clients are required to provide to read encrypted values."
type = map(string)
}

resource "aws_iam_role_policy_attachment" "credstash-reader-policy-attachment" {
Expand All @@ -48,11 +42,6 @@ resource "aws_kms_grant" "credstash-reader" {
grantee_principal = var.role_arns[count.index]
key_id = var.kms_key_arn
operations = ["Decrypt"]

constraints {
encryption_context_equals = {
element(var.context_keys, count.index) = element(var.context_values, count.index)
}
}
constraints { encryption_context_equals = var.context }
}

21 changes: 5 additions & 16 deletions modules/credstash-grant-writer/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,10 @@ variable "writer_policy_arn" {
type = string
}

variable "context_keys" {
default = []
description = "list of keys to be zipped with the context_values to set an 'encryption context' for additional granularity that clients are required to provide to read encrypted values. Eg. for env=dev svc=db, this would be [env, svc]. All writers get this context map."
type = list(string)
}

variable "context_values" {
default = []
description = "list of values to be zipped with the context_keys to set an 'encryption context' for additional granularity that clients are required to provide to read encrypted values. Eg. for env=dev svc=db, this would be [dev, db]. All writers get this context map."
type = list(string)
variable "context" {
default = {}
description = "Context for additional granularity that clients are required to provide to write values to encrypt."
type = map(string)
}

resource "aws_iam_role_policy_attachment" "credstash-writer-policy-attachment" {
Expand All @@ -48,11 +42,6 @@ resource "aws_kms_grant" "credstash-writer" {
grantee_principal = var.role_arns[count.index]
key_id = var.kms_key_arn
operations = ["GenerateDataKey"]

constraints {
encryption_context_equals = {
element(var.context_keys, count.index) = element(var.context_values, count.index)
}
}
constraints { encryption_context_equals = var.context }
}

3 changes: 3 additions & 0 deletions modules/credstash-grant/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ See [this RFC](https://docs.google.com/document/d/15nEcV7fxskDgYrXoNMl6RYIo10PCi
and [this ticket](https://github.com/hashicorp/terraform/issues/386) for more
details on that.

## Deprecated

With `aws_kms_grant` resource introduced, and in the case that host running the module does not have AWSCLI, this module is deprecated. Please use `credstash-grant-reader`, `credstash-grant-writer`.