审计日志(Audit Log)
自 Gitea 1.28 起,审计日志已进入开源版,Gitea Enterprise 在其基础上构建。开源版审计日志提供的内容(审计事件模型、[audit] 配置项以及所记录的操作)在企业版中的行为完全一致。本页只介绍企业版新增或不同的部分,共有部分请参阅开源版的审计日志文档。
与开源版的差异
Section titled “与开源版的差异”| 开源版 | Gitea Enterprise | |
|---|---|---|
[audit].RECORD_OUTPUT 默认值 |
disabled |
database,开箱即记录 |
[audit].RETENTION_DAYS 默认值 |
30 |
0,永久保留 |
| 记录的操作 | 开源版操作 | 开源版操作,加上下文列出的操作 |
用户、组织和仓库的审计页面、按 action、来源(origin)和操作者筛选,以及管理页面的 JSONL 导出,开源版中同样提供。Gitea Enterprise 额外提供管理 API、CSV 导出,以及 API 的关键字和时间范围筛选。
RECORD_OUTPUT、RETENTION_DAYS 和 RECORD_PUSH_PULL_FILE_NAMES 在 app.ini 的 [audit] 段中配置。RECORD_PUSH_PULL_FILE_NAMES(默认 false)会额外记录每次 push 和 pull 涉及的文件名,每次 push 和 pull 会多执行一条 git 命令,每条记录最多增大几 KB。
清理由 delete_old_audit_events 定时任务每天执行一次。仅当 RETENTION_DAYS 大于 0 时才会注册该任务,因此升级本身不会删除任何历史记录。
| 页面 | 谁可以查看 | 内容 |
|---|---|---|
站点管理 > 审计日志(/-/admin/audit-logs) |
站点管理员 | 所有记录 |
/user/settings/audit-logs |
当前登录用户 | 属于其账号范围的记录 |
/org/{org}/settings/audit-logs |
组织所有者 | 属于该组织范围的记录 |
/{owner}/{repo}/settings/audit-logs |
仓库管理员 | 属于该仓库范围的记录 |
范围页面不会显示其他实体的记录。管理 API 位于 /api/v1/admin/audit-logs 和 /api/v1/admin/audit-logs/export。
操作筛选接受完整的 action(如 repository:label:create),也接受 action 的前缀(如 repository:label 或 repository),并选中其下所有 action。管理 API 支持按 operator_id、action、q、start_unix 和 end_unix 筛选。
| 字段 | 含义 |
|---|---|
action |
发生了什么,例如 repository:archive。 |
operation_type |
已废弃,请使用 action,其值与 action 相同。 |
operator_id / operator_name |
操作者。未认证的请求记为 anonymous,命令行记为 (gitea-cli),认证源同步记为 (gitea-auth-source)。 |
scope_type / scope_id / scope_name |
记录所属的实体:system、user、organization 或 repository。 |
origin |
操作进入 Gitea 的途径:ui、api、cli 或 system(定时任务、git 钩子、内部 API)。 |
ip_address |
客户端地址(操作通过请求发起时)。 |
仅企业版记录的操作
Section titled “仅企业版记录的操作”以下操作仅由企业版记录,其余操作与开源版共有。
accesstoken:approveaccesstoken:disableaccesstoken:enableaccesstoken:expiry:changeaccesstoken:leak:revokeaccesstoken:rejectaccesstoken:revokeagent:command:denyagent:createagent:deliveryplan:approveagent:deliveryplan:cancelagent:deliveryplan:markdoneagent:deliveryplan:pauseagent:deliveryplan:resumeagent:deliveryplan:submitagent:deliverystep:retryagent:task:createagent:updateissue:comment:updateissue:lockissue:status:closeissue:status:reopenissue:unlockissue:updateorganization:accesstoken:approval:autograntorganization:branch:protection:addorganization:branch:protection:removeorganization:branch:protection:updateorganization:label:createorganization:label:deleteorganization:label:updateorganization:member:addorganization:member:updateorganization:oauth2application:grantorganization:settings:updatepackage:createpackage:deletepackage:downloadpackage:uploadpr:review:submitpr:reviewrequest:addpr:reviewrequest:removepr:targetbranch:updatepr:wip:addpr:wip:removeproject:closeproject:reopenrepository:archive:downloadrepository:avatar:removerepository:avatar:updaterepository:branch:checkoutrepository:branch:deleterepository:branch:mergerepository:file:downloadrepository:git:clonerepository:git:pullrepository:git:pushrepository:git:ref:createrepository:git:ref:deleterepository:label:createrepository:label:deleterepository:label:updaterepository:milestone:createrepository:milestone:deleterepository:milestone:updaterepository:mirror:push:updaterepository:pushprotection:blockrepository:pushprotection:bypassrepository:pushprotection:reportrepository:pushrule:exemptrepository:pushrule:updaterepository:reference:updaterepository:release:createrepository:release:deleterepository:release:updaterepository:security:scanrepository:securityscan:branch:updaterepository:securityscan:cleanuprepository:securityscan:disablerepository:securityscan:enablerepository:settings:updatesystem:announcement:updatesystem:license:activatesystem:license:removesystem:license:updatesystem:maintenance:runsystem:package:cleanupsystem:repository:adoptsystem:settings:auth:updatesystem:settings:cache:updatesystem:settings:mailer:updatesystem:settings:session:updatesystem:settings:storage:updatesystem:settings:updatesystem:webhook:default:addsystem:webhook:default:removesystem:webhook:default:updateuser:authentication:failuser:authentication:logoutuser:authentication:successuser:update
导出审计日志
Section titled “导出审计日志”站点管理员可以在 站点管理 > 审计日志 或通过 GET /admin/audit-logs/export 导出符合当前筛选条件的记录:
- CSV(默认):便于电子表格查看的表格。网页下载的文件带 UTF-8 BOM,以便 Microsoft Excel 正确打开;API 响应不带 BOM。
- JSONL(
?format=jsonl):每行一个 JSON 对象,结构与开源版审计事件一致,适合日志采集器。
从 Gitea Enterprise 27 升级
Section titled “从 Gitea Enterprise 27 升级”- 记录从
ee_audit_log表迁移到开源版的audit_event表。转换以迁移的形式分批执行,升级中断后可继续,不会遗漏任何记录。旧表会保留(仅按RETENTION_DAYS清理),确认结果后可自行删除。 - 升级前写入的记录来源为
unknown,因为此前不区分 UI 和 API。 - 管理审计 API 和导出中的
operation_type现在取action的值(例如user:authentication:success,而不是user:sign_in),请读取action。旧名称仍可作为筛选条件,并以legacy_operation_type保存在记录的元数据中。 - 关闭和重新打开项目现在记为
project:close和project:reopen,此前为project:update。 - 升级后仍会继续记录,除非将
RECORD_OUTPUT设为disabled。