elastic / detection-rules

https://www.elastic.co/guide/en/security/current/detection-engine-overview.html
Other
1.92k stars 492 forks source link

[Rule Tuning] Tuning AWS Rules for SAML Provider Updates and Assumed Roles via STS #3898

Closed terrancedejesus closed 1 month ago

terrancedejesus commented 2 months ago

Pull Request

Issue link(s):

Summary - What I changed

Per conversation with @aarju, the following AWS OOTB rules had room for improvement.

For AWS Security Token Service (STS) AssumeRole Usage, we changed this rule from a custom KQL query to New Terms. The new terms values will focus solely on user.id and aws.cloudtrail.flattened.request_parameters.roleArn for uniqueness. It was pointed out that false-positives may occur for environments with third-party IdPs. This remains true for automation workflows as well. New terms should ignore common benign temporary creds retrieved for specific users and roles that are commonly assumed. Additionally, rather than separate AssumeRole and AssumeRoleWithSAML, we added * to account for any assumed role activity. Based on global alert telemetry, we have assumed role activity from various sources (SAML via IdP, web identity, pod identity, etc.) With user.id: * added to the query, this field must exist but only exists for assumed role activity where an IAM user is involved, thus ignoring some automated workflows.

For AWS SAML Activity, this rule originally seemed to capture multiple SAML authentication workflow activity that may or may not have been related to each other, based on the API calls reported in event.action. As a result, AssumeRoleWithSAML will be covered in AWS STS Temporary Credentials via AssumeRole. This rule now only detects when the IAM SAML provider has had metadata modification. We also increased the risk score associated with this as the result of a true-positive could have higher consequences. Note that this update reduces alerts to ~82 within the last 4 months globally.

Additional Information:

How To Test

AWS IAM SAML Provider Updated

Screenshot 2024-07-16 at 10 11 20 AM

AWS STS Temporary Credentials via AssumeRole

This is more difficult to test as it is new terms. Instead, knowing that the user ID is used for New Terms regarding AWS IAM and STS events, we can confidently assume lower alert volume or false-positives. There are ~502 unique user.ids for global telemetry from ~8000 alerts in the last 120 days, therefore, this should reduce these.

Checklist

Contributor checklist

protectionsmachine commented 2 months ago

Rule: New - Guidelines

These guidelines serve as a reminder set of considerations when proposing a new rule.

Documentation and Context

Rule Metadata Checks

New BBR Rules

Testing and Validation

terrancedejesus commented 2 months ago

This seems to be a bug, making this a blocker.

FAILED tests/test_specific_rules.py::TestNewTerms::test_new_terms_fields - AssertionError: aws.cloudtrail.flattened.request_parameters.roleArn not found in ECS, Beats, or non-ecs schemas