1. 概述
作为代码管理平台,gitlab 虽然私有化部署,但仍不能保证私有仓库中的代码不被泄露到外部。于是对gitlab下载审计就变得尤为重要。
2. 架构流程

- 使用 
filebeat收集 gitlab 的日志,传送到redis. - 程序从 
redis中读取 日志数据,经过分析,过滤,最后将数据存入到mysql中 
效果展示:
MariaDB [gitlab_log]> SELECT username,resource,count(*) AS "访问次数" FROM gitlab_log_info GROUP BY resource,username;+-----------+--------------------+--------------+| username | resource | 访问次数 |+-----------+--------------------+--------------+| root | /root/ziweiapp.git | 4 || yanglibin | /root/ziweiapp.git | 2 || yanglibin | /test/zznode.git | 2 |+-----------+--------------------+--------------+
3. gitlab 日志处理说明
先使用
filebeat初步过滤include_lines: [‘GET’,’200’,’”action”:”archive”‘,’”action”:”git_upload_pack”‘]
只保留 get 操作的日志。
exclude_lines: [‘metrics’,’”username”:null’,’”path”:”/api/graphql”‘]
去掉gitlab日志中的监控日志。当用户进行
git clone或点击 下载时,我们将其识别为一次代码下载。
git_upload_pack : git clone 操作
archive                :   用户进行打包下载
4. 附:
4.1. filebeat
- filebeat 配置文件: 
filebeat.yml```yaml filebeat.inputs: 
- type: log
paths:
- /srv/gitlab/logs/gitlab-rails/production_json.log include_lines: [‘GET’,’200’,’”action”:”archive”‘,’”action”:”git_upload_pack”‘] exclude_lines: [‘metrics’,’”username”:null’,’”path”:”/api/graphql”‘]
 
 
output.redis: hosts: [“10.2.21.39:6379”] key: “filebeat” db: 0 timeout: 5 ```
- filebeat 启动:  
filebeat -c ./filebeat.yml -e4.2. 实现代码
gitlabLog.zip5. 参考文章
 
