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

Issue creating KMS key #134

Closed
applike-ss opened this issue Sep 27, 2022 · 6 comments
Closed

Issue creating KMS key #134

applike-ss opened this issue Sep 27, 2022 · 6 comments
Assignees
Labels
help wanted Extra attention is needed question Further information is requested

Comments

@applike-ss
Copy link
Contributor

applike-ss commented Sep 27, 2022

For testing out tEKS i don't want to use KMS for ebs volume encryption, however the module insists on creating resources and fails.

This is the failing resource:

 # aws_kms_key.this will be created
  + resource "aws_kms_key" "this" {
      + arn                                = (known after apply)
      + bypass_policy_lockout_safety_check = false
      + customer_master_key_spec           = "SYMMETRIC_DEFAULT"
      + description                        = "EKS Secret Encryption Key for my-foo-cluster"
      + enable_key_rotation                = true
      + id                                 = (known after apply)
      + is_enabled                         = true
      + key_id                             = (known after apply)
      + key_usage                          = "ENCRYPT_DECRYPT"
      + multi_region                       = false
      + policy                             = jsonencode(
            {
              + Statement = [
                  + {
                      + Action    = "kms:*"
                      + Effect    = "Allow"
                      + Principal = {
                          + AWS = "arn:aws:iam::123456789012:root"
                        }
                      + Resource  = "*"
                      + Sid       = "Enable IAM User Permissions"
                    },
                  + {
                      + Action    = [
                          + "kms:ReEncrypt*",
                          + "kms:GenerateDataKey*",
                          + "kms:Encrypt",
                          + "kms:DescribeKey",
                          + "kms:Decrypt",
                        ]
                      + Effect    = "Allow"
                      + Principal = {
                          + AWS = "arn:aws:iam::123456789012:role/aws-service-role/autoscaling.amazonaws.com/AWSServiceRoleForAutoScaling"
                        }
                      + Resource  = "*"
                      + Sid       = "Allow service-linked role use of the CMK"
                    },
                  + {
                      + Action    = "kms:CreateGrant"
                      + Condition = {
                          + Bool = {
                              + "kms:GrantIsForAWSResource" = [
                                  + "true",
                                ]
                            }
                        }
                      + Effect    = "Allow"
                      + Principal = {
                          + AWS = "arn:aws:iam::123456789012:role/aws-service-role/autoscaling.amazonaws.com/AWSServiceRoleForAutoScaling"
                        }
                      + Resource  = "*"
                      + Sid       = "Allow attachment of persistent resources"
                    },
                ]
              + Version   = "2012-10-17"
            }
        )
      + tags                               = {
          + "Environment" = "foo"
          + "Owner"       = "me"
          + "Project"     = "teks"
        }
      + tags_all                           = {
          + "Environment" = "foo"
          + "Owner"       = "me"
          + "Project"     = "teks"
        }
    }

And this is the error message i get:

╷
│ Error: error creating KMS Key: MalformedPolicyDocumentException: Policy contains a statement with one or more invalid principals.
│ 
│   with aws_kms_key.this,
│   on main.tf line 1, in resource "aws_kms_key" "this":
│    1: resource "aws_kms_key" "this" {
│ 
╵

The role AWSServiceRoleForAutoScaling does not exist yet.

@ArchiFleKs
Copy link
Member

ArchiFleKs commented Sep 30, 2022

Hi @applike-ss If you are managing a new account only via Terraform I think you should create the serviceRole in another module, with the help of https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_service_linked_role

@ArchiFleKs
Copy link
Member

@applike-ss You should also be able to disable the use of KMS and encryption all together for EBS CSI https://github.com/particuleio/terraform-kubernetes-addons/blob/main/modules/aws/aws-ebs-csi-driver.tf#L26, if not could you raise a bug in the addons module please ?

@applike-ss
Copy link
Contributor Author

Hi @applike-ss If you are managing a new account only via Terraform I think you should create the serviceRole in another module, with the help of https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_service_linked_role

with serviceRole you mean the role i let terragrunt assume? I don't see how that gives any more permissions than my current role - Or what is the point in doing that?

@applike-ss You should also be able to disable the use of KMS and encryption all together for EBS CSI https://github.com/particuleio/terraform-kubernetes-addons/blob/main/modules/aws/aws-ebs-csi-driver.tf#L26, if not could you raise a bug in the addons module please ?

I did disable encryption completely for my testing. However i assume that due to

path = "../../../../../../dependency-blocks/encryption-config.hcl"
it always tries to create a kms key.

@ArchiFleKs
Copy link
Member

Ok so it seems I misunderstood the issue. If you don't want to use kms with ebs-csi-driver you can put use_kms to false in addons-critical but then you need to remove the kms configuration in eks/terragrunt.hcl to not reference the encryption config and remove the encryption-config folder

@ArchiFleKs ArchiFleKs self-assigned this Oct 10, 2022
@ArchiFleKs ArchiFleKs added help wanted Extra attention is needed question Further information is requested labels Oct 10, 2022
@applike-ss
Copy link
Contributor Author

thx, i will try that.

@applike-ss
Copy link
Contributor Author

i removed the encryption config for now and it seems to work nicely this way, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants