公司抓信息安全,使用gitlab進行代碼管理,要求全部用戶的遠程操做(推送、同步)都記錄下來。html
經過查看Gitlab官方文檔,整理信息以下:git
gitlab 後臺的各類日誌保存位置 /var/log/gitlab/
shell
注意:本日誌只記錄經過http操做的日誌
存放目錄:/var/log/gitlab/gitlab-rails/
json
production_json.log
裏面是Json請求串。windows
{ "method": "GET", "path": "/test_user/test_project.git/info/refs", "format": "*/*", "controller": "Projects::GitHttpController", "action": "info_refs", "status": 200, "duration": 268.22, "view": 0.48, "db": 14.41, "time": "2019-06-27T10:59:56.324Z", "params": [ { "key": "service", "value": "git-receive-pack" }, { "key": "namespace_id", "value": "test_user" }, { "key": "project_id", "value": "test_project.git" } ], "remote_ip": "192.168.XX.XX", "user_id": 3, "username": "test_user", "ua": "git/2.21.0.windows.1", "queue_duration": null, "correlation_id": "b02c02f9-0167-49bf-965f-e4cc86d6751f" }
日誌中有價值的信息:安全
service:git-receive-pack
service:git-upload-pack
project_id:test_project.git
remote_ip:192.168.XX.XX
username:test_user
time:2019-06-27T10:59:56.324Z
(UTC格式,加上8個小時等於北京時間)status:200
(200表示操做成功,其餘表示失敗)action:info_refs
(每次同步、推送操做出現的標誌,須要經過這個字段來來篩選日誌是不是更新或者推送操做)對存在Json嵌套的數據操做,建議看看這篇文章,可以提升工做效率。
Go 如何優雅的獲取嵌套Json數據內容socket
**注意:此日誌只記錄Gitclone協議的操做
日誌目錄:/var/log/gitlab/gitlab-shell
如下日誌就不是Json格式了,須要本身對字符串進行操做處理。gitlab
time="2019-07-02T11:17:48+08:00" level=info msg="executing git command" command="gitaly-receive-pack unix:/var/opt/gitlab/gitaly/gitaly.socket {\"repository\":{\"storage_name\":\"default\",\"relative_path\":\"test_user/test_project.git\",\"git_object_directory\":\"\",\"git_alternate_object_directories\":[],\"gl_repository\":\"project-5\",\"gl_project_path\":\"test_user/test_project\"},\"gl_repository\":\"project-5\",\"gl_project_path\":\"test_user/test_project\",\"gl_id\":\"key-3\",\"gl_username\":\"test_user\",\"git_config_options\":[],\"git_protocol\":null}" pid=23657 user="user with id key-3"
日誌中有價值的信息:post
command:gitaly-receive-pack
command:gitaly-upload-pack
gl_project_path:test_user/test_project
remote_ip:192.168.XX.XX
gl_username:test_user
time:2019-07-02T11:17:48+08:00
(UTC格式,加上8個小時等於北京時間)status:200
(200表示操做成功,其餘表示失敗)action:info_refs
(每次同步、推送操做出現的標誌,須要經過這個字段來來篩選日誌是不是更新或者推送操做)參考文檔:spa
本文首發於 BigYoung小站