<!-- Sanitized reference copy. Original comments removed; OAuth domains generalized.
     Logic is otherwise unchanged and includes known review issues.
     Read README.md and the draft Technical Review Notes before use. -->

<group name="gitlab,json,">
  <rule id="110010" level="3">
    <decoded_as>json</decoded_as>
    <field name="integration.log_type">^audit_json$</field>
    <field name="event_name">^authenticated_with_password$</field>
    <description>GitLab successful password authentication: $(meta.user) from $(meta.remote_ip), correlation $(correlation_id)</description>
    <group>authentication_success,</group>
  </rule>

  <rule id="110011" level="3">
    <decoded_as>json</decoded_as>
    <field name="integration.log_type">^audit_json$</field>
    <field name="event_name">^authenticated_with_oauth$</field>
    <description>GitLab successful OAuth authentication: $(meta.user) from $(meta.remote_ip), correlation $(correlation_id)</description>
    <group>authentication_success,oauth,</group>
  </rule>

  <rule id="110012" level="3">
    <decoded_as>json</decoded_as>
    <field name="integration.log_type">^audit_json$</field>
    <field name="event_name">^authenticated_with_two_factor$</field>
    <description>GitLab successful two-factor authentication: $(meta.user) from $(meta.remote_ip), correlation $(correlation_id)</description>
    <group>authentication_success,mfa,</group>
  </rule>

  <rule id="110013" level="10">
    <decoded_as>json</decoded_as>
    <field name="integration.log_type">^audit_json$</field>
    <field name="event_name">^user_access_locked$</field>
    <description>GitLab account locked - excessive failed login attempts: $(meta.user) from $(meta.remote_ip), correlation $(correlation_id)</description>
    <mitre><id>T1110</id></mitre>
    <group>account_lockout,brute_force,authentication_failed,</group>
  </rule>

  <rule id="110030" level="8">
    <decoded_as>json</decoded_as>
    <field name="integration.log_type">^audit_json$</field>
    <field name="event_name" type="pcre2">(?i)(personal_access_token|ssh_key|password_changed|email_changed|two_factor_(enabled|disabled)|member_(added|removed)|project_created|user_(created|blocked|unblocked))</field>
    <description>GitLab security-sensitive audit event: $(event_name), actor $(meta.user), target $(target_details)</description>
    <group>account_changed,gitlab_audit,</group>
  </rule>

  <rule id="110050" level="12">
    <decoded_as>json</decoded_as>
    <field name="integration.log_type">^production_json$</field>
    <field name="controller">^UserSettings::PersonalAccessTokensController$</field>
    <action type="pcre2">^create$</action>
    <field name="method">^POST$</field>
    <status type="pcre2">^200$</status>
    <description>GitLab personal access token created by $(meta.user) from $(remote_ip), correlation $(correlation_id)</description>
    <group>credential_created,personal_access_token,</group>
  </rule>

  <rule id="110051" level="12">
    <decoded_as>json</decoded_as>
    <field name="integration.log_type">^production_json$</field>
    <field name="controller">^UserSettings::SshKeysController$</field>
    <action type="pcre2">^(create|destroy|revoke)$</action>
    <description>GitLab SSH key changed by $(meta.user) from $(remote_ip): $(action), correlation $(correlation_id)</description>
    <mitre><id>T1098.004</id></mitre>
    <group>account_manipulation,ssh_key,</group>
  </rule>

  <rule id="110052" level="10">
    <decoded_as>json</decoded_as>
    <field name="integration.log_type">^production_json$</field>
    <field name="controller">^Profiles::TwoFactorAuthsController$</field>
    <field name="method" type="pcre2">^(POST|PUT|PATCH|DELETE)$</field>
    <description>GitLab two-factor authentication setting changed by $(meta.user) from $(remote_ip): $(action)</description>
    <mitre><id>T1098</id></mitre>
    <group>account_manipulation,mfa,</group>
  </rule>

  <rule id="110053" level="10">
    <decoded_as>json</decoded_as>
    <field name="integration.log_type">^production_json$</field>
    <field name="controller" type="pcre2">^(Profiles::|UserSettings::).*(Passwords|Emails|Accounts|Profiles|Preferences)</field>
    <field name="method" type="pcre2">^(POST|PUT|PATCH|DELETE)$</field>
    <description>GitLab account/profile security setting changed by $(meta.user) from $(remote_ip): $(controller)#$(action)</description>
    <group>account_manipulation,</group>
  </rule>

  <rule id="110060" level="10">
    <decoded_as>json</decoded_as>
    <field name="integration.log_type">^production_json$</field>
    <field name="controller">^ProjectsController$</field>
    <action type="pcre2">^create$</action>
    <field name="method">^POST$</field>
    <description>GitLab project created by $(meta.user) from $(remote_ip): $(path)</description>
    <group>project_created,resource_creation,</group>
  </rule>

  <rule id="110061" level="12">
    <decoded_as>json</decoded_as>
    <field name="integration.log_type">^production_json$</field>
    <field name="controller" type="pcre2">^Projects::Settings::.*Controller$</field>
    <field name="method" type="pcre2">^(POST|PUT|PATCH|DELETE)$</field>
    <description>GitLab project security/repository setting changed by $(meta.user): $(controller)#$(action), $(path)</description>
    <group>project_configuration,configuration_changed,</group>
  </rule>

  <rule id="110062" level="12">
    <decoded_as>json</decoded_as>
    <field name="integration.log_type">^production_json$</field>
    <field name="controller" type="pcre2">^(Projects|Groups)::.*(Members|Hooks|DeployKeys|AccessTokens|ProtectedBranches|ProtectedTags)Controller$</field>
    <field name="method" type="pcre2">^(POST|PUT|PATCH|DELETE)$</field>
    <description>GitLab membership/access/hook control changed by $(meta.user): $(controller)#$(action), $(path)</description>
    <mitre><id>T1098</id></mitre>
    <group>access_control,configuration_changed,</group>
  </rule>

  <rule id="110063" level="8">
    <decoded_as>json</decoded_as>
    <field name="integration.log_type">^production_json$</field>
    <field name="controller" type="pcre2">^Projects::(Branches|Tags)Controller$</field>
    <action type="pcre2">^(create|destroy)$</action>
    <description>GitLab branch/tag changed by $(meta.user) from $(remote_ip): $(action), $(path)</description>
    <group>repository_changed,</group>
  </rule>

  <rule id="110064" level="5">
    <decoded_as>json</decoded_as>
    <field name="integration.log_type">^production_json$</field>
    <field name="controller">^Repositories::GitHttpController$</field>
    <action type="pcre2">^git_receive_pack$</action>
    <status type="pcre2">^200$</status>
    <description>GitLab Git-over-HTTP push by $(meta.user) from $(remote_ip): $(path)</description>
    <group>git_push,repository_changed,</group>
  </rule>

  <rule id="110065" level="11" frequency="10" timeframe="300" ignore="300">
    <if_matched_sid>110064</if_matched_sid>
    <same_field>meta.user</same_field>
    <description>GitLab unusually frequent Git-over-HTTP pushes by $(meta.user)</description>
    <group>git_push,anomaly,</group>
  </rule>

  <rule id="110066" level="9">
    <decoded_as>json</decoded_as>
    <field name="integration.log_type">^production_json$</field>
    <field name="controller" type="pcre2">^Projects::.*(Exports|Repositories)Controller$</field>
    <action type="pcre2">^(create|download|archive)$</action>
    <description>GitLab repository export/archive activity by $(meta.user) from $(remote_ip): $(path)</description>
    <mitre><id>T1213.003</id></mitre>
    <group>data_access,repository_export,</group>
  </rule>

  <rule id="110067" level="12">
    <decoded_as>json</decoded_as>
    <field name="integration.log_type">^sidekiq$</field>
    <field name="meta.root_caller_id">^ProjectsController#destroy$</field>
    <field name="job_status">^start$</field>
    <description>GitLab project deleted (web UI) by $(meta.user): $(meta.project)</description>
    <mitre><id>T1485</id></mitre>
    <group>project_deleted,resource_deletion,</group>
  </rule>

  <rule id="110068" level="5">
    <decoded_as>json</decoded_as>
    <field name="integration.log_type" type="pcre2">^(production_json|api_json)$</field>
    <field name="meta.project" type="pcre2">-deletion_scheduled-</field>
    <description>GitLab activity on project pending deletion by $(meta.user) from $(remote_ip): $(meta.project)</description>
    <group>pending_deletion_access,data_access,</group>
  </rule>

  <rule id="110069" level="12">
    <decoded_as>json</decoded_as>
    <field name="integration.log_type">^sidekiq$</field>
    <field name="meta.root_caller_id">^GroupsController#destroy$</field>
    <field name="job_status">^start$</field>
    <description>GitLab group deleted (web UI) by $(meta.user): $(meta.project)</description>
    <mitre><id>T1485</id></mitre>
    <group>project_deleted,resource_deletion,</group>
  </rule>

  <rule id="110072" level="10">
    <decoded_as>json</decoded_as>
    <field name="integration.log_type">^api_json$</field>
    <field name="route">^/api/:version/projects$</field>
    <field name="method">^POST$</field>
    <status type="pcre2">^20[0-9]$</status>
    <description>GitLab project created via API by $(meta.user) from $(remote_ip)</description>
    <group>project_created,resource_creation,</group>
  </rule>

  <rule id="110073" level="12">
    <decoded_as>json</decoded_as>
    <field name="integration.log_type">^api_json$</field>
    <field name="route">^/api/:version/projects/:id$</field>
    <field name="method">^DELETE$</field>
    <status type="pcre2">^20[0-9]$</status>
    <description>GitLab project deleted via API by $(meta.user) from $(remote_ip): $(meta.project)</description>
    <mitre><id>T1485</id></mitre>
    <group>project_deleted,resource_deletion,</group>
  </rule>

  <rule id="110074" level="9">
    <decoded_as>json</decoded_as>
    <field name="integration.log_type">^api_json$</field>
    <field name="route">^/api/:version/projects/:id/fork$</field>
    <field name="method">^POST$</field>
    <status type="pcre2">^20[0-9]$</status>
    <description>GitLab project forked via API by $(meta.user) from $(remote_ip): $(meta.project)</description>
    <mitre><id>T1537</id></mitre>
    <group>project_forked,data_access,</group>
  </rule>

  <rule id="110070" level="7">
    <decoded_as>json</decoded_as>
    <field name="integration.log_type">^production_json$</field>
    <field name="path" type="pcre2">^/admin(?:/|$)</field>
    <description>GitLab Admin Area accessed by $(meta.user) from $(remote_ip): $(method) $(path)</description>
    <group>admin_access,</group>
  </rule>

  <rule id="110071" level="12">
    <if_sid>110070</if_sid>
    <field name="method" type="pcre2">^(POST|PUT|PATCH|DELETE)$</field>
    <description>GitLab administrative change by $(meta.user) from $(remote_ip): $(method) $(path)</description>
    <group>admin_action,configuration_changed,</group>
  </rule>
</group>
