1. Resources
  2. Detection sources
  3. security_policy_service_account_branch_deletion_bypass

security_policy_service_account_branch_deletion_bypass: A service account deleted a policy-protected branch through a policy exception

Recorded when a service account listed as an exception in a merge request approval policy deletes a protected branch that the policy would otherwise keep from being deleted.

Log source
GitLab audit events
Detection value
Supporting
Volume
Low (estimate)
Last updated
Log
GitLab audit events (GitLab audit events, on by default)
Service
GitLab audit events
Operation
security_policy_service_account_branch_deletion_bypass
Detects
1 attack (1 rule)
MITRE ATT&CK
1 technique in 1 tactic
Threat groups
33 groups that MITRE ATT&CK records using these techniques
Fields the rules read
event_type

When it is written

GitLab writes the event (GitLab 18.9 and later, Ultimate) when a merge request approval policy blocks changes to protected branches (block_branch_modification, which stops a protected branch being deleted or unprotected) and a service account in the policy's bypass_settings deletes such a branch anyway. GitLab's documentation says service accounts and access tokens listed as exceptions can bypass branch protections enforced by these policies, for automation such as pipelines and mirroring.

GitLab documents the event type but not its fields. In the GitLab source the scope is the security policy project and the target the policy; the details give the project or group whose branch was deleted (details.container_type, details.container_id), the policy, the service account's user ID and branch_deletion as the action, and the message is "Protected branch deletion for '' has been bypassed by a service_account with ID: ". The deleted branch's name is not in the record. An access token exception writes security_policy_access_token_branch_deletion_bypass instead.

How to turn it on

GitLab audit events records security_policy_service_account_branch_deletion_bypass calls to GitLab audit events without any setup. Vendor documentation

Audit events need GitLab Premium or Ultimate; on Free only successful sign-ins are kept (the user's authentication log). On a paid tier GitLab writes most event types to its database without any setup and keeps them indefinitely. Each event type in GitLab's list says whether it is saved to the database: the ones that are not exist only in a streaming destination. The list also gives each type's scope: a type whose only scope is User or Instance is not among a group's or a project's audit events, and is read in the instance's audit events or an instance stream (GitLab Self-Managed and Dedicated).

  • Where to read them: a group's events need the Owner role, a project's the Maintainer role (with the Developer role a user sees only the events of their own actions, and a user with the Auditor access level sees all of them), and instance events (GitLab Self-Managed and Dedicated) an administrator, in the UI or with the audit events API. Both filter only by author and date range, at most 30 days per query, and cannot search inside the event details.
  • Collecting them (Ultimate): audit event streaming sends every event as JSON to a destination: an HTTP endpoint (a SIEM collector), Google Cloud Logging or Amazon S3. A top-level group stream (GitLab.com too) covers the group, its subgroups and projects; an instance stream (Self-Managed and Dedicated) covers the whole instance, including instance-scope events. An HTTP destination sends each event with the content type application/x-www-form-urlencoded by default: set it to application/json. Each request carries the destination's verification token in X-Gitlab-Event-Streaming-Token and the event type in X-Gitlab-Audit-Event-Type (except with batched delivery, a GitLab.com feature flag that sends a JSON array of events).
  • Delivery: GitLab can send one event more than once; deduplicate on id. A failed delivery is not retried, and after 25 failures in a row GitLab pauses the destination for five minutes and drops the events of that pause without telling you: watch for gaps on the receiving side. A dropped event of a type saved to the database can still be read in GitLab; a streaming-only type is gone. GitLab states no delivery delay.
  • Filters: a destination can be limited to some event types or to one subgroup or project. A filtered destination silently stops receiving everything else, so the filter changes themselves are worth an alert.
  • Time: the API returns UTC (or the instance's configured time zone), CSV exports UTC, and the UI the viewer's local time.
List a group's audit events since a date (Owner token, read only)
curl --header "PRIVATE-TOKEN: <token>" "https://gitlab.example.com/api/v4/groups/<group-id>/audit_events?created_after=<YYYY-MM-DDTHH:MM:SSZ>"
Based on vendor documentation.
List a top-level group's HTTP streaming destinations and their filters (read-only GraphQL query)
curl --request POST --header "Authorization: Bearer <token>" --header "Content-Type: application/json" --data '{"query":"{ group(fullPath: \"<group-path>\") { externalAuditEventDestinations { nodes { name destinationUrl eventTypeFilters namespaceFilter { namespace { fullName } } } } } }"}' "https://gitlab.example.com/api/graphql"
Based on vendor documentation.
List the instance's HTTP streaming destinations and their filters (administrator, read-only GraphQL query)
curl --request POST --header "Authorization: Bearer <token>" --header "Content-Type: application/json" --data '{"query":"{ instanceExternalAuditEventDestinations { nodes { name destinationUrl eventTypeFilters } } }"}' "https://gitlab.example.com/api/graphql"
Based on vendor documentation.

Fields

The operation’s own fields first, then the fields every GitLab audit events record has. Field names are the JSON paths of the record as the vendor documents it.

FieldWhat it holds
details.container_typeWhat owns the protected branch, Project or Group in the GitLab source.
details.container_idID of that project or group.
details.service_account_idUser ID of the service account that deleted the branch.
details.bypass_typeservice_account for this type, in the GitLab source.
details.actionbranch_deletion in the GitLab source.
details.security_policy_nameName of the policy whose exception allowed it (details.security_policy_id is its ID).
details.custom_messageThe message GitLab writes, "Protected branch deletion for '' has been bypassed by a service_account with ID: ".
Fields every GitLab audit events record has (14)
FieldWhat it holds
idUnique identifier of the audit event. GitLab can stream an event more than once; use it to deduplicate.
created_atWhen the event was triggered, an ISO 8601 timestamp.
event_typeRead by 1 ruleThe audit event type, the operation this page is about. Streamed events always carry it.
author_idUser ID of the account that triggered the event. Negative values mark authors that are not a user (-3 for a deploy key in GitLab's example; -1 for an unauthenticated or token author in the GitLab source).
author_nameName of the author, kept even when the account no longer exists.
entity_typeThe scope the event belongs to: User, Group, Project or Gitlab::Audit::InstanceScope for instance events (GitLab says the list is not exhaustive).
entity_idID of that scope (the user, group or project).
entity_pathFull path of the scope (corp-example/platform), gitlab_instance for instance events.
target_typeThe kind of object the action was taken on, as GitLab's class name (Group, Key, Ci::Runner...).
target_idID of that object.
target_detailsA readable name for the target, chosen per event type (a name, a path, a key).
ip_addressAddress of the host the action came from, as GitLab saw it.
detailsA JSON object with more about the event. GitLab gives it no schema; it usually repeats the author, target, scope and address and adds the event's own keys, including custom_message, the sentence the audit events page shows (listed on each page).
details.author_classWhat kind of author acted: User for a person, or a GitLab class for other actors (a deploy key, a runner token, a service account acting for a person).

Values to know

details.container_type

ValueMeaningSignal
ProjectA project's protected branch was deletedThe project's path is in the message.Worth knowing
GroupA branch protected at group level was deleted in a project of the groupWorth knowing

Volume and noise

Low: deleting a protected branch is unusual even for automation. A deletion by a service account that normally only pushes or mirrors, or of a project's default or release branch, is the record to read first.

Keeping it manageable

  • Identify the service account in details.service_account_id and confirm that deleting branches is part of its job.
  • Check the project in details.container_id for which protected branch disappeared; the record does not name it.
  • Keep the service account exceptions of each policy short and reviewed.

Sample event

A GitLab audit events record in the vendor’s format, with made-up values.

{
  "id": "48213",
  "author_id": 913,
  "author_name": "release-mirror-bot",
  "entity_id": 412,
  "entity_path": "corp-example/security-policies",
  "entity_type": "Project",
  "target_id": 2207,
  "target_type": "Security::Policy",
  "target_details": "Require security approval",
  "ip_address": "203.0.113.24",
  "created_at": "2026-11-18T09:30:12.415Z",
  "details": {
    "author_name": "release-mirror-bot",
    "author_class": "User",
    "target_id": 2207,
    "target_type": "Security::Policy",
    "target_details": "Require security approval",
    "custom_message": "Protected branch deletion for project 'corp-example/payments-api' has been bypassed by a service_account with ID: 913",
    "ip_address": "203.0.113.24",
    "entity_path": "corp-example/security-policies",
    "container_id": 311,
    "container_type": "Project",
    "security_policy_name": "Require security approval",
    "security_policy_id": 2207,
    "bypass_type": "service_account",
    "service_account_id": 913,
    "action": "branch_deletion"
  },
  "event_type": "security_policy_service_account_branch_deletion_bypass"
}

Attacks this event reveals

Detection rules that read this event:

References