Triage and Remediation
- Remediation
Remediation
Using Console
Using Console
The control name you quoted — “AWS KMS Customer Master Keys For EFS Encryption” — applies to Amazon EFS, not API Gateway. You cannot fix that specific finding in API Gateway; it’s about how your EFS file systems are encrypted.Below are the concise steps to remediate this in the AWS Console by ensuring EFS uses a customer-managed KMS key (CMK) instead of the default AWS-managed key.
If what you actually need is encryption/KMS configuration for API Gateway assets (e.g., logs in CloudWatch, KMS for custom domain certs, etc.), specify the exact security finding or resource type and I’ll list the steps for that separately.
Important: You cannot change the KMS key of an existing EFS file system. You must create a new, encrypted file system with a CMK and migrate data.
1. Create a Customer-Managed KMS Key
- In the AWS Console, go to Key Management Service (KMS).
- In the left pane, choose Customer managed keys.
- Click Create key.
- Key type: Symmetric → Next.
- Set Alias (e.g.,
alias/efs-cmk-prod) and optional description → Next. - Choose key administrators and key users (IAM roles/users that EFS and your apps use).
- Review and click Finish.
arn:aws:kms:region:account-id:key/key-id).2. Create a New EFS File System Using the CMK
- In the AWS Console, go to EFS.
- Click Create file system.
- In the General settings page:
- Set Name.
- Under Encryption, ensure Enable encryption of data at rest is ON.
- For KMS key, select Choose from your AWS KMS keys and pick your new CMK (e.g.,
alias/efs-cmk-prod).
- Configure VPC, availability zones, and mount targets as required.
- Complete the wizard by clicking Create.
3. Migrate Data From Old EFS (If Applicable)
If you already had an unencrypted or AWS-managed-key EFS file system:- Mount both:
- Old EFS file system.
- New CMK-encrypted EFS file system.
- Use a copy/sync tool from an EC2 instance (or container) that has both file systems mounted:
- Basic example:
- Basic example:
- Update all applications / services / mount targets to point to the new EFS file system.
- After verification, delete the old EFS file system in the EFS console.
4. (Optional) Restrict the CMK for EFS Use
In KMS → Customer managed keys:- Select your CMK.
- Go to the Key policy tab.
- Ensure that:
- EFS service (and your IAM roles/users) have
kms:Encrypt,kms:Decrypt,kms:GenerateDataKey, etc. - Access is limited to the required principals only.
- EFS service (and your IAM roles/users) have
- Save policy.
If what you actually need is encryption/KMS configuration for API Gateway assets (e.g., logs in CloudWatch, KMS for custom domain certs, etc.), specify the exact security finding or resource type and I’ll list the steps for that separately.
Using CLI
Using CLI
AWS API Gateway does not use EFS or KMS directly; EFS is typically attached to Lambda functions that API Gateway invokes. The KMS misconfiguration is on the EFS file system itself, not on API Gateway.To remediate “AWS KMS Customer Master Keys For EFS Encryption” with AWS CLI, you must:
Capture the KeyId or ARN from the output, e.g.:Optionally give it an alias:You can then use
Find the file system currently used by the Lambda(s) behind your API Gateway. Note its Check its encryption configuration:If it’s encrypted with the default AWS-managed key (or incorrectly configured CMK), you must create a new EFS; encryption settings cannot be changed in place.
Capture the new Wait until the mount targets are
Validate data integrity as required.
For each function, inspect its file system configs:If it references Repeat for all affected functions.API Gateway itself does not need changes; it continues to invoke the same Lambda functions.
Edit This completes remediation: EFS used (indirectly by API Gateway via Lambda) is now encrypted with a customer-managed KMS CMK, configured via AWS CLI.
- create/use a customer-managed KMS key,
- create a new EFS encrypted with that CMK,
- migrate data,
- update any Lambda functions (invoked by API Gateway) to mount the new EFS.
1. Create a customer-managed KMS CMK (if you don’t already have one)
alias/efs-cmk in EFS commands.2. Identify the existing EFS file system to replace
List EFS file systems:FileSystemId, e.g.:3. Create a new EFS encrypted with the CMK
FileSystemId, e.g. fs-0abcdef1234567890.Create mount targets in the same subnets/security groups used by the original EFS:available:4. Copy data from old EFS to the new EFS
From an EC2 instance in the same VPC (or another host that can mount both EFS file systems):- Install the EFS mount helper if needed.
- Mount both file systems:
- Copy data:
5. Update Lambda functions (invoked by API Gateway) to use the new EFS
List Lambda functions that might be using the old EFS:fs-0123456789abcdef0, update it to the new file system id using the existing (or new) access point that points to the new EFS:6. Decommission the old EFS
After confirming all functions work correctly and all data is migrated:- Unmount from any instances.
- Delete the old EFS:
7. (Optional) Lock down KMS key policy
Ensure the CMK’s key policy follows least privilege:key-policy.json to restrict access, then:Using Python
Using Python
In AWS, EFS encryption with KMS CMK is unrelated to API Gateway. EFS is a filesystem used by EC2/Lambda, not by API Gateway directly.Assuming the misconfiguration is:
To create a new CMK:If you’re using an existing CMK alias:Make sure the CMK key policy allows the EFS service and your IAM principals to use it for
You also need mount targets for subnets:Repeat
“EFS is not encrypted with a customer-managed KMS key (CMK)”Below are step‑by‑step Python (boto3) instructions to:
- Create or reuse a KMS CMK
- Create a new encrypted EFS with that CMK
- (Optional but common) Move data from an unencrypted EFS to the new encrypted one
1. Prerequisites
2. Create (or identify) a KMS Customer Managed Key (CMK)
If you already have a CMK you want to use, skip to step 3.To create a new CMK:
Encrypt, Decrypt, GenerateDataKey*, etc.3. Create a new encrypted EFS using the CMK
EFS encryption at rest can only be enabled at file system creation time; you cannot turn it on later for an existing unencrypted file system.create_mount_target for each AZ where you need access.4. (Optional) Migrate data from an existing unencrypted EFS
If you already have an unencrypted EFS (old_fs_id) you must copy data to the new encrypted one. This is done via EC2 or a container, not directly via API:High-level steps:- Create/mount both file systems on an EC2 instance.
- Mount unencrypted EFS to
/mnt/old_efs - Mount new encrypted EFS to
/mnt/new_efs
- Mount unencrypted EFS to
- Copy data:
- Update your applications (or Lambda functions) to mount/use the new encrypted EFS.
- After verifying, delete the old file system:
5. Clarifying the “API Gateway” part
API Gateway itself doesn’t use EFS or KMS CMKs for its core operation. Common KMS-related controls for API Gateway are typically about:- Encrypting CloudWatch log groups with a CMK
- Encrypting API cache data (for REST APIs) with a CMK
Using Terraform
Using Terraform
encrypted from false to true or changing kms_key_id on an existing aws_efs_file_system forces replacement of the file system, which deletes data unless you migrate it beforehand.Verification: terraform plan should show aws_efs_file_system.this with encrypted = true and kms_key_id set to the ARN of aws_kms_key.efs_cmk, with either a create (new filesystem) or a -/+ replacement if you are modifying an existing one.
