Hi all!
I am trying to create a rule that alerts if for the past 30 days, a unique combination of user/country is seen for the first time. This is what I came up with so far:
events:
$selection.metadata.vendor_name = "Okta"
$selection.metadata.event_type = "USER_LOGIN"
$selection.security_result.detection_fields["legacyEventType"] = "core.user_auth.login_success"
$userid = $selection.target.user.userid
$country = $selection.principal.ip_geo_artifact.location.country_or_region
match:
$userid, $country over 1d
outcome:
$first_seen_today = max(metrics.auth_attempts_success(
period:1h, window:today, metric:first_seen, agg:max,
target.user.userid:$userid))
$first_seen_monthly = max(metrics.auth_attempts_success(
period:1d, window:30d, metric:first_seen, agg:max,
target.user.userid:$userid))
The problem begins when I add "principal.ip_geo_artifact.location.country_or_region:$country" to $first_seen_today and $first_seen_monthly - it returns results that don't make sense.
I would appreciate if someone can explain to me what am I missing here, and how to build the rule correctly. Thank you in advance.



