审计事件格式和示例

审计事件模式#

History
    • 极狐 GitLab 15.3 中引入了审计事件流模式的文档。

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

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

审计事件 JSON 模式#

json
1{ 2 "properties": { 3 "id": { 4 "type": "string" 5 }, 6 "author_id": { 7 "type": "integer" 8 }, 9 "author_name": { 10 "type": "string" 11 }, 12 "details": {}, 13 "ip_address": { 14 "type": "string" 15 }, 16 "entity_id": { 17 "type": "integer" 18 }, 19 "entity_path": { 20 "type": "string" 21 }, 22 "entity_type": { 23 "type": "string" 24 }, 25 "event_type": { 26 "type": "string" 27 }, 28 "target_id": { 29 "type": "integer" 30 }, 31 "target_type": { 32 "type": "string" 33 }, 34 "target_details": { 35 "type": "string" 36 }, 37 }, 38 "type": "object" 39}

标头#

History
    • X-Gitlab-Audit-Event-Type 在极狐 GitLab 15.0 中引入。

标头格式如下:

plaintext
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 仓库时,可以发送流式审计事件:

  1. 使用 SSH
  2. 使用 HTTP 或 HTTPS。
  3. 使用极狐 GitLab UI 中的 下载 ()。

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

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

Fetch:

json
1{ 2 "id": "1", 3 "author_id": -3, 4 "entity_id": 29, 5 "entity_type": "Project", 6 "details": { 7 "author_name": "deploy-key-name", 8 "author_class": "DeployKey", 9 "target_id": 29, 10 "target_type": "Project", 11 "target_details": "example-project", 12 "custom_message": { 13 "protocol": "ssh", 14 "action": "git-upload-pack" 15 }, 16 "ip_address": "127.0.0.1", 17 "entity_path": "example-group/example-project" 18 }, 19 "ip_address": "127.0.0.1", 20 "author_name": "deploy-key-name", 21 "entity_path": "example-group/example-project", 22 "target_details": "example-project", 23 "created_at": "2022-07-26T05:43:53.662Z", 24 "target_type": "Project", 25 "target_id": 29, 26 "event_type": "repository_git_operation" 27}