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

Cannot replicate multi-region key due to missing permission #22

Closed
1 task done
kstevensonnv opened this issue Aug 29, 2023 · 2 comments · Fixed by #24
Closed
1 task done

Cannot replicate multi-region key due to missing permission #22

kstevensonnv opened this issue Aug 29, 2023 · 2 comments · Fixed by #24

Comments

@kstevensonnv
Copy link

kstevensonnv commented Aug 29, 2023

Description

When creating a multi-region key, the 'key_administrators' IAM policy does not provide the 'kms:ReplicateKey' permission and replication fails with an access denied error.

The comment above the IAM policy for 'key_administrators' points to AWS KMS docs - Default key policy (key administrators) and states:

AWS KMS adds the following permissions to the default key administrators statement when you create special-purpose keys.

kms:ReplicateKey
    The kms:ReplicateKey permission allows key administrators to create a replica of a multi-Region primary key in a     different AWS Region. This permission is included in the key policy only when you create a multi-Region primary or     replica key.

kms:UpdatePrimaryRegion
    The kms:UpdatePrimaryRegion permission allows key administrators to change a multi-Region replica key to a     multi-Region primary key. This permission is included in the key policy only when you create a multi-Region     primary or replica key.

This doesn't happen when creating it via Terraform.
Both permissions should be added to the policy.

  • ✋ I have searched the open/closed issues and my issue is not listed.

Versions

  • Module version [Required]: 1.5.0

  • Terraform version: 1.5.5

  • Provider version(s):

.
├── provider[registry.terraform.io/hashicorp/helm] ~> 2.10.1
├── provider[registry.terraform.io/hashicorp/kubernetes] ~> 2.23.0
├── provider[registry.terraform.io/hashicorp/random] ~> 3.5.1
├── provider[registry.terraform.io/hashicorp/aws] ~> 5.12.0
├── module.cluster_secrets_kms_primary
│ └── provider[registry.terraform.io/hashicorp/aws] >= 3.72.0
└── module.cluster_secrets_kms_replica
└── provider[registry.terraform.io/hashicorp/aws] >= 3.72.0

Reproduction Code [Required]

Steps to reproduce the behavior:

provider "aws" {
  region   = "eu-west-1"
  profile  = "profile"
}

provider "aws" {
  alias    = "replica"
  region   = "eu-west-2"
  profile  = "profile"
}

data "aws_caller_identity" "current" {}

module "kms_primary" {
  source  = "terraform-aws-modules/kms/aws"

  description             = "Primary"
  key_usage               = "ENCRYPT_DECRYPT"
  deletion_window_in_days = 7
  enable_key_rotation     = true

  multi_region = true

  enable_default_policy = false
  key_administrators    = [data.aws_caller_identity.current.arn]
  key_users             = [data.aws_caller_identity.current.arn]
}

module "kms_replica" {
  source  = "terraform-aws-modules/kms/aws"

  providers = {
    aws = aws.replica
  }

  description             = "Replica"
  key_usage               = "ENCRYPT_DECRYPT"
  deletion_window_in_days = 7
  enable_key_rotation     = false

  create_replica  = true
  primary_key_arn = module.kms_primary.key_arn

  enable_default_policy = false
  key_administrators    = [data.aws_caller_identity.current.arn]
  key_users             = [data.aws_caller_identity.current.arn]
}

Expected behavior

The key is replicated in another region.

Actual behavior

Access denied error:

Error: creating KMS Replica Key: AccessDeniedException: User: arn:aws:sts::account:assumed-role/role/session_id is not authorized to perform: kms:ReplicateKey on resource: arn:aws:kms:region:account:key/mrk-key because no resource-based policy allows the kms:ReplicateKey action
status code: 400, request id: id

@antonbabenko
Copy link
Member

This issue has been resolved in version 2.0.1 🎉

@github-actions
Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants