> For the complete documentation index, see [llms.txt](https://cortex-docs.paloaltonetworks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cortex-docs.paloaltonetworks.com/posture-rules/cloud-saas-active-directory-posture-rules/cortex-posture-query-based-rules/detection-rules-by-name/aws-cloudtrail-s3-bucket-encrypted-with-customer-managed-key-cmk-that-is-scheduled-for-deletion.md). Agents can also search and read this documentation through its [MCP server](https://cortex-docs.paloaltonetworks.com/~gitbook/mcp).

# AWS CloudTrail S3 bucket encrypted with Customer Managed Key (CMK) that is scheduled for deletion

### Synopsis

| Field               | Value                                                                                             |
| ------------------- | ------------------------------------------------------------------------------------------------- |
| Rule Type           | Detection                                                                                         |
| Finding Type        | AWS CloudTrail S3 bucket encrypted with Customer Managed Key (CMK) that is scheduled for deletion |
| Finding ID          | 60000853                                                                                          |
| Generates a Finding | This detection rule also generates a finding                                                      |
| Severity            | Medium                                                                                            |
| Category            | CONFIGURATION                                                                                     |
| Cloud Providers     | AWS                                                                                               |
| Platform Module     | CSPM                                                                                              |
| Asset Types         | S3\_BUCKET                                                                                        |
| ATT\&CK Tactic      | TA0040 (TA0040)                                                                                   |
| ATT\&CK Technique   | T1486 (T1486)                                                                                     |

### Description

AWS CloudTrail S3 buckets encrypted with Customer Managed Keys (CMKs) scheduled for deletion pose a significant security risk. The deletion of these CMKs prevents decryption of CloudTrail logs, hindering security monitoring and incident response.

CloudTrail logs, stored in S3 buckets and encrypted using CMKs, record crucial account activity. Deleting the CMK renders these logs inaccessible, effectively concealing malicious actions such as data exfiltration or lateral movement. An attacker could leverage this misconfiguration to evade detection and maintain persistence.

Compromised CloudTrail logs due to CMK deletion leave organizations blind to security incidents. Maintaining the integrity and accessibility of CloudTrail logs is crucial for effective threat detection and incident response. Data breaches, compromised credentials, and ransomware attacks could go undetected, leading to significant financial and reputational damage.

To mitigate this risk, implement robust CMK lifecycle management. Regularly review scheduled CMK deletions, ensuring that they are intentional and necessary. Establish a process for securely rotating CMKs and consider using AWS KMS key rotation capabilities. Implement logging and alerting for CMK deletion attempts to provide timely notification of suspicious activity.

### Remediation

**Manual steps:**

S3 Bucket - This issue arises when a Customer Managed Key (CMK) used to encrypt CloudTrail logs stored in an S3 bucket is scheduled for deletion. This poses a significant security risk as it could hinder the ability to decrypt CloudTrail logs, potentially masking malicious activities:

1. **Identify the Affected S3 Bucket:** Log in to the AWS Console and navigate to the 'S3' service. Locate the S3 bucket mentioned in the alert.
2. **Access Bucket Properties:** Click on the identified S3 bucket and select the 'Properties' tab.
3. **Locate the KMS Key:** Under the 'Default encryption' section, click on the KMS key link displayed in the 'Encryption key ARN' field.
4. **Navigate to KMS:** This action will redirect you to the Key Management Service (KMS) console.
5. **Cancel Key Deletion:** Click on the 'Key actions' dropdown and select 'Cancel key deletion'.
6. **Enable the Key:** Click on 'Enable' to reactivate the KMS key.

**Note:** Carefully review and test these steps before implementation. Canceling key deletion and enabling the key may impact other services or applications that rely on the KMS key. Ensure you understand the potential consequences before proceeding.

**CLI code:**

S3 Bucket - This command cancels the scheduled deletion of the KMS key used to encrypt the CloudTrail S3 bucket. This prevents the key from being deleted, ensuring that CloudTrail logs can continue to be decrypted:

```bash
aws kms cancel-key-deletion --key-id ${entity} --region ${entity}
```

**Terraform code:**

S3 Bucket - This Terraform snippet identifies the S3 bucket used by CloudTrail and the KMS key that is scheduled for deletion. It then updates the S3 bucket encryption configuration to use a new KMS key or an existing one, if provided. Finally, it updates the CloudTrail configuration to use the new KMS key and creates a new S3 bucket policy for the CloudTrail logs bucket:

```hcl
# Get the ARN of the KMS key that is scheduled for deletion
kms_key_arn = data.aws_kms_key.kms_key_for_cloudtrail.arn
# Get the name of the S3 bucket used by CloudTrail
s3_bucket_name = aws_cloudtrail.cloudtrail.s3_bucket_name
# Get the ARN of the S3 bucket used by CloudTrail
s3_bucket_arn = aws_s3_bucket.cloudtrail_logs_bucket.arn
# Get the current KMS key ARN used by the S3 bucket
current_kms_key_arn = data.aws_s3_bucket_server_side_encryption_configuration.cloudtrail_logs_bucket_encryption.rule.0.apply_server_side_encryption_by_default.kms_master_key_id
# Find a suitable existing KMS key or create a new one
data "aws_kms_key" "kms_key_for_cloudtrail" {
  key_id = "<kms_key_arn>"
}
# Create a new KMS key if the existing one is scheduled for deletion
resource "aws_kms_key" "new_kms_key_for_cloudtrail" {
  description             = "KMS key for CloudTrail logs"
  deletion_window_in_days = 7
  enable_key_rotation     = true
}
# Update the S3 bucket encryption configuration to use the new KMS key
resource "aws_s3_bucket_server_side_encryption_configuration" "cloudtrail_logs_bucket_encryption" {
  bucket = s3_bucket_name
  rule {
    apply_server_side_encryption_by_default {
      kms_master_key_id = var.use_existing_kms_key ? current_kms_key_arn : aws_kms_key.new_kms_key_for_cloudtrail.arn
      sse_algorithm     = "aws:kms"
    }
  }
}
# Update the CloudTrail configuration to use the new KMS key
resource "aws_cloudtrail" "cloudtrail" {
  # ... other configuration ...
  kms_key_id = var.use_existing_kms_key ? current_kms_key_arn : aws_kms_key.new_kms_key_for_cloudtrail.arn
}
# Create a new S3 bucket policy for the CloudTrail logs bucket
data "aws_iam_policy_document" "cloudtrail_logs_bucket_policy" {
  statement {
    sid    = "AWSCloudTrailAclCheck"
    effect = "Allow"
    principals {
      type        = "Service"
      identifiers = ["cloudtrail.amazonaws.com"]
    }
    actions   = ["s3:GetBucketAcl"]
    resources = [s3_bucket_arn]
    condition {
      test     = "StringEquals"
      variable = "aws:SourceArn"
      values   = ["arn:${entity}:cloudtrail:${entity}:${entity}:trail/${entity}"]
    }
  }
  statement {
    sid    = "AWSCloudTrailWrite"
    effect = "Allow"
    principals {
      type        = "Service"
      identifiers = ["cloudtrail.amazonaws.com"]
    }
    actions   = ["s3:PutObject"]
    resources = ["<s3_bucket_arn>/${entity}/AWSLogs/${entity}/*"]
    condition {
      test     = "StringEquals"
      variable = "s3:x-amz-acl"
      values   = ["bucket-owner-full-control"]
    }
    condition {
      test     = "StringEquals"
      variable = "aws:SourceArn"
      values   = ["arn:${entity}:cloudtrail:${entity}:${entity}:trail/${entity}"]
    }
  }
}
resource "aws_s3_bucket_policy" "cloudtrail_logs_bucket_policy" {
  bucket = s3_bucket_name
  policy = data.aws_iam_policy_document.cloudtrail_logs_bucket_policy.json
}
resource "aws_s3_bucket" "cloudtrail_logs_bucket" {
  bucket        = s3_bucket_name
  force_destroy = true
}
data "aws_caller_identity" "current" {}
data "aws_partition" "current" {}
data "aws_region" "current" {}
variable "use_existing_kms_key" {
  type = bool
  default = false
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://cortex-docs.paloaltonetworks.com/posture-rules/cloud-saas-active-directory-posture-rules/cortex-posture-query-based-rules/detection-rules-by-name/aws-cloudtrail-s3-bucket-encrypted-with-customer-managed-key-cmk-that-is-scheduled-for-deletion.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
