Help us learn about your current experience with the documentation. Take the survey.

审计事件模式和示例

审计事件模式

审计事件在响应体中具有可预测的模式。

字段 描述 备注 仅流式传输字段
author_id 触发事件的用户 ID dotted-circle
author_name 触发事件的可读作者名称 当作者不再存在时很有用 check-circle
created_at 事件触发的时间戳 dotted-circle
details 包含额外元数据的 JSON 对象 没有定义的模式,但通常包含事件的额外信息 dotted-circle
entity_id 审计事件实体的 ID dotted-circle
entity_path 可审计事件影响的实体的完整路径 check-circle
entity_type 实体类型的字符串表示 可接受的值包括 UserGroupKey。此列表不完整 dotted-circle
event_type 审计事件类型的字符串表示 check-circle
id 审计事件的唯一标识符 如需要可用于去重 dotted-circle
ip_address 用于触发事件的主机的 IP 地址 check-circle
target_details 关于目标的额外详细信息 check-circle
target_id 审计事件目标的 ID check-circle
target_type 目标类型的字符串表示 check-circle

审计事件 JSON 模式

{
  "properties": {
    "id": {
      "type": "string"
    },
    "author_id": {
      "type": "integer"
    },
    "author_name": {
      "type": "string"
    },
    "details": {},
    "ip_address": {
      "type": "string"
    },
    "entity_id": {
      "type": "integer"
    },
    "entity_path": {
      "type": "string"
    },
    "entity_type": {
      "type": "string"
    },
    "event_type": {
      "type": "string"
    },
    "target_id": {
      "type": "integer"
    },
    "target_type": {
      "type": "string"
    },
    "target_details": {
      "type": "string"
    },
  },
  "type": "object"
}

标头

标头格式如下:

POST /logs HTTP/1.1
Host: <DESTINATION_HOST>
Content-Type: application/x-www-form-urlencoded
X-Gitlab-Event-Streaming-Token: <DESTINATION_TOKEN>
X-Gitlab-Audit-Event-Type: repository_git_operation

示例:Git 操作的审计事件流式传输

当认证用户推送、拉取或克隆项目的远程 Git 仓库时,可以发送流式审计事件:

  • 使用 SSH
  • 使用 HTTP 或 HTTPS。
  • 在 GitLab UI 中使用下载 download )。

未登录用户的审计事件不会被捕获。例如,下载公共项目时。

示例:使用部署密钥的 Git over SSH 事件的审计事件负载

获取:

{
  "id": "1",
  "author_id": -3,
  "entity_id": 29,
  "entity_type": "Project",
  "details": {
    "author_name": "deploy-key-name",
    "author_class": "DeployKey",
    "target_id": 29,
    "target_type": "Project",
    "target_details": "example-project",
    "custom_message": {
      "protocol": "ssh",
      "action": "git-upload-pack"
    },
    "ip_address": "127.0.0.1",
    "entity_path": "example-group/example-project"
  },
  "ip_address": "127.0.0.1",
  "author_name": "deploy-key-name",
  "entity_path": "example-group/example-project",
  "target_details": "example-project",
  "created_at": "2022-07-26T05:43:53.662Z",
  "target_type": "Project",
  "target_id": 29,
  "event_type": "repository_git_operation"
}