Gitlab

Gitlab

Tweak

禁止某些 IP 访问某些内容

应用场景:Gitlab 系统部署在公司服务器,能够通过内网(192.168.0.0/16)或公网访问。出于安全考虑,要求配置为以下模式:通过公网访问时,不能访问所有项目“代码”,但能够使用项目的“Issues”、“Wiki”等功能。

考虑通过 Gitlab 集成的 nginx 做权限控制:

docker exec -it gitlab_image_id bash

/etc/gitlab/gitlab.rb

# 去掉 nginx['custom_gitlab_server_config'] 这行注释并设置以下内容:
nginx['custom_gitlab_server_config'] = "include /etc/gitlab/custom_gitlab_server.conf;"

/etc/gitlab/custom_gitlab_server.conf

location ~ ^(/api/)|(\.git|(/(raw|tree|blob|commits?)/.*))$ {
        proxy_cache off;
        proxy_pass  http://gitlab-workhorse;
        allow 192.168.0.0/16;
        allow 127.0.0.0/8;
        deny all;
}

这里使用的 nginx location 配置项里正则匹配 Gitlab 里的以下 URL:

  • /api/*
  • */raw|tree|blob|commit(s)/*
  • */*.git

重启 docker 生效。

另外,还需要在 Gitlab 系统设置里禁用 Git 的 ssh 协议,只允许通过 http 访问。


Last update: 2018-05-07 03:07:46 UTC