More Info:
AWS SQS queues should use KMS CMK customer-managed keys instead of AWS managed-keys in order to benefit from a more granular control over the queues data encryption/decryption process.Risk Level
HighAddress
SecurityCompliance Standards
- APRA CPS 234 (Australia)
- AWS Well Architected Framework
- BSI C5 (Germany)
- Brazil LGPD
- CCPA / CPRA (California)
- CIS Critical Security Controls v8
- CMMC 2.0
- CSA Cloud Controls Matrix v4
- DPDPA
- Digital Operational Resilience Act (EU)
- ISO/IEC 27017
- ISO/IEC 27018
- ISO/IEC 27701
- KSA PDPL
- MAS Technology Risk Management (Singapore)
- MITRE ATT&CK (Cloud)
- NIS2 Directive
- NIST SP 800-171
- NYDFS 23 NYCRR 500
- PCI
- SWIFT Customer Security Controls Framework
- Sarbanes-Oxley IT General Controls
- UK NCSC Cyber Assessment Framework
Triage and Remediation
- Remediation
Remediation
Using Console
Using Console
Here are the step-by-step instructions to remediate this issue:
- Sign in to the AWS Management Console and open the Amazon SQS console at https://console.aws.amazon.com/sqs/.
- In the navigation pane, choose “Queues”.
- In the list of queues, choose the name of the queue that you want to encrypt.
- In the details pane, choose the “Edit” button next to “Queue Attributes”.
- In the “Encryption section”, choose “Enable” for “Server-side encryption”.
- For “Customer master key (CMK)”, choose “Use a KMS master key” to use a customer-managed CMK.
- Click on “Save”.
Using CLI
Using CLI
To remediate this misconfiguration, you need to enforce the use of Customer Managed Key (CMK) for encryption in AWS SQS. Here are the step-by-step instructions using AWS CLI:Step 1: Install and Configure AWS CLI
Before you begin, make sure you have AWS CLI installed on your machine. If not, you can download it from the official AWS CLI website. After installation, configure it with your AWS credentials.Step 2: Identify the SQS Queue
Identify the Amazon SQS queue that is not using a Customer Managed Key (CMK) for server-side encryption. You can list all your SQS queues using the following command:Step 3: Create a CMK
Create a Customer Managed Key (CMK) using AWS Key Management Service (KMS). To create a CMK, use the following command:Take note of the KeyId in the output as you will need it in the next step.Step 4: Enable Server-Side Encryption
Enable server-side encryption with the CMK for the identified SQS queue. Use the following command:Replace This should return the KeyId of the CMK you set for the queue. If it matches the KeyId of the CMK you created, then you have successfully remediated the misconfiguration.
<your_queue_url> with your SQS queue URL and <your_cmk_key_id> with the KeyId of the CMK you created.After running the command, your SQS queue should now be using a CMK for server-side encryption. You can verify this by using the get-queue-attributes command:Using Python
Using Python
To remediate this issue, you’ll need to create a Customer Master Key (CMK) in AWS Key Management Service (KMS) and then use this key to encrypt your SQS queue. Here is how you can do it using Python and AWS SDK Boto3:
-
First, install the necessary Python library, Boto3, if you haven’t already. You can do this using pip:
-
Import the boto3 library in your Python script:
-
Create a new CMK. To do this, you need to initialize the AWS KMS client and then call the
create_keyfunction: -
Now, with the CMK created, you need to use this key to encrypt your SQS queue. First, initialize the SQS client:
-
Then, use the
set_queue_attributesfunction to set the KMSMasterKeyId attribute to the ID of the CMK you created:Replace ‘URL_OF_YOUR_QUEUE’ with the URL of your SQS queue. - Now your SQS queue is encrypted with the CMK.
Using Terraform
Using Terraform
YOUR_QUEUE_NAMEwith the SQS queue name.YOUR_CMK_KEY_ID_OR_ARNwith the ID or ARN of a customer-managed KMS key in the same region as the queue.
kms:GenerateDataKey, kms:Decrypt) on the CMK.Verification: terraform plan should show an update to the aws_sqs_queue resource adding or changing kms_master_key_id from null/an AWS-managed key to the specified CMK.
