- Newest
- Most votes
- Most comments
It appears that you're experiencing an issue with KMS (Key Management Service) when deploying new infrastructure using Terraform through GitLab CI/CD. The error suggests that the KMS key used for encrypting EBS volumes is in an incorrect state or inaccessible.
Here are some steps to troubleshoot and potentially resolve the issue:
-
Verify KMS key state: Ensure that the KMS key used for encrypting EBS volumes is in the "Enabled" state. If it was previously disabled or scheduled for deletion, make sure it has been fully re-enabled.
-
Check KMS key permissions: Confirm that the IAM user or role used by Terraform has the necessary permissions to use the KMS key. The required permissions include:
- kms:CreateGrant
- kms:Decrypt
- kms:DescribeKey
- kms:GenerateDataKeyWithoutPlaintext
- kms:ReEncrypt
-
Review KMS key policy: If the instance is being launched by another AWS service (like EC2 Auto Scaling), ensure that the KMS key policy grants access to that service.
-
Verify Terraform configuration: Check your Terraform configuration to ensure it's using the correct KMS key ARN for EBS volume encryption.
-
IAM role permissions: If you're using an IAM role for EC2 instances, make sure it has the necessary permissions to access the KMS key.
-
Clean up Terraform state: If the issue persists, try running
terraform refresh
to update the state, followed byterraform plan
andterraform apply
. This can help resolve any discrepancies between the actual infrastructure and Terraform's state. -
Check AWS CloudTrail: Review CloudTrail logs for any KMS-related errors or access denied events that might provide more insight into the issue.
-
Temporary workaround: As a temporary measure, you could try launching the instance without encryption and then add encryption later, although this is not recommended for production environments.
If the issue continues after trying these steps, you may need to reach out to AWS support for further assistance, especially if you suspect there might be an issue with the KMS service itself.
Sources
Deploying Containers on AWS: A Guide to ECS and EKS | AWS re:Post
Connect your on-premises Kubernetes cluster to AWS APIs using IAM Roles Anywhere | AWS Security Blog
It sounds like the AutoScaling Group (ASG) being used for the cluster isn't able to access a CMK (Customer Managed KMS Key). You'll need to allow the Service Linked Role (SLR) of the ASG in the Key Policy, and then in the ASG account call the create-grant CLI command. After doing both of these, it should work. More info: https://docs.aws.amazon.com/autoscaling/ec2/userguide/key-policy-requirements-EBS-encryption.html#policy-example-cmk-cross-account-access
Relevant content
- asked 6 months ago
- asked 2 years ago
- asked a year ago