-
Notifications
You must be signed in to change notification settings - Fork 587
[New Rule] Kubernetes Unusual Decision by User Agent #4829
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Rule: New - GuidelinesThese 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
|
for anomalies in the username and response annotations, this rule helps identify | ||
potential unauthorized access or misconfigurations in the Kubernetes environment. | ||
""" | ||
index = ["logs-kubernetes.audit_logs-*"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did we intentionally exclude from
rule object?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is a good question. I copy pasted the template from the other k8s rules. I just did a check in the kubernetes repository, and the from
field is nowhere present.

@imays11 do you happen to know why this is not set? Is this related to timestamps in the audit log file system?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default value (if not specified) for it is now-6m
afaik
timestamp_override = "event.ingested" | ||
type = "new_terms" | ||
query = ''' | ||
event.dataset:"kubernetes.audit_logs" and kubernetes.audit.stage:"ResponseComplete" and user_agent.original:* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont know if it's applicable but may want to ensure user_agent is not ""
instead as *
will include these.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to filter out cases where the user_agent.original field does not exist, as this will break the logic based on the new_terms
value; generally speaking, the user_agent.original is supplied; having an empty string there is (as far as I know based on my research) suspicious, as that is not common by default system behavior.

The empty user_agent.original example above is based on reconnaissance activity from a network scanner.
timestamp_override = "event.ingested" | ||
type = "new_terms" | ||
query = ''' | ||
event.dataset:"kubernetes.audit_logs" and kubernetes.audit.stage:"ResponseComplete" and user_agent.original:* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why we are filtering for the user_agent.original
field and not "kubernetes.audit.annotations.authorization_k8s_io/decision", "kubernetes.audit.user.username"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because these two fields are always present, I figured it does not require filtering, while the user agent string can be empty in certain cases.
Do you have any logs we can view in the shared stack? |
rules/integrations/kubernetes/execution_unusual_request_response_by_user_agent.toml
Outdated
Show resolved
Hide resolved
rules/integrations/kubernetes/execution_unusual_request_response_by_user_agent.toml
Outdated
Show resolved
Hide resolved
…se_by_user_agent.toml
…se_by_user_agent.toml
Summary
This rule detects unusual request responses in Kubernetes audit logs through the use of the "new_terms" rule type. In production environments, default API requests are typically made by system components or trusted users, which are expected to have a consistent user agent and allowed response annotations. By monitoring for anomalies in the username and response annotations, this rule helps identify potential unauthorized access or misconfigurations in the Kubernetes environment.
Telemetry
User agents, usernames, and decisions are typically consistent in production environments, as all API requests should be allowed. This rule leverages the new_terms rule type to find requests that deviate from this pattern.
If this rule were to be noisy, I can exclude certain service account behavior + commonly hit API endpoints.