{"id":13825152,"url":"https://github.com/m3dev/gitlab-access-controlled-server","last_synced_at":"2026-01-16T06:35:44.079Z","repository":{"id":142989146,"uuid":"97487420","full_name":"m3dev/gitlab-access-controlled-server","owner":"m3dev","description":"This is a web server for Gitlab pages or Gitlab review apps.","archived":false,"fork":false,"pushed_at":"2018-07-29T07:30:20.000Z","size":9,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-06-08T16:03:26.218Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/m3dev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2017-07-17T14:44:47.000Z","updated_at":"2018-07-29T07:30:21.000Z","dependencies_parsed_at":"2023-04-01T02:49:06.784Z","dependency_job_id":null,"html_url":"https://github.com/m3dev/gitlab-access-controlled-server","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/m3dev/gitlab-access-controlled-server","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m3dev%2Fgitlab-access-controlled-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m3dev%2Fgitlab-access-controlled-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m3dev%2Fgitlab-access-controlled-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m3dev%2Fgitlab-access-controlled-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/m3dev","download_url":"https://codeload.github.com/m3dev/gitlab-access-controlled-server/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m3dev%2Fgitlab-access-controlled-server/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264352662,"owners_count":23594944,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-04T09:01:15.504Z","updated_at":"2026-01-16T06:35:44.039Z","avatar_url":"https://github.com/m3dev.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# Gitlab-access-controlled simple web server\n\nThis is a web server for Gitlab pages or Gitlab review apps.\n\nこれはGitlabのアクセス権限設定に対応して静的コンテンツを提供するサーバーです。  \nGitlab PagesやReview Appにアクセス制御を追加することを目的にしています。\n\n## 構成\n\nこのサーバーは、nginx + [oauth2_proxy](https://github.com/bitly/oauth2_proxy) + 本アプリ の構成で利用します。\n\n```\n     nginx\n       ↓\n  oauth2_proxy  ーoauth2 ー→  Gitlab\n       ↓                 ｜\n     server      ー API ー┘\n```\n\n\nGitlabサーバーのOAuth2機能を使ってoauth2_proxyで認証を行い、\nそこで取得したaccess tokenを本アプリに渡します。  \n本アプリでは受け取ったaccess tokenを使ってGitlab APIへアクセスし、\n対象コンテンツのへアクセス可能かどうかを判定しています。\n\n## コンテンツ\n\nこのサーバーが提供するコンテンツは、実行しているカレントディレクトリのファイルになります。  \n`/srv/nginx/pages`というディレクトリで実行したのであれば、その中にある`/srv/nginx/pages/file.html`に`http://example.com/file.html`でアクセスできます。\n\nアクセス可否の判定をするにあたって表示するコンテンツがどのプロジェクトに属しているかが問題になります。  \nこれは、表示対象ディレクトリにプロジェクトIDを記入した`.gitlab-info.json`というファイルを配置して判断します。  \n\n.gitlab-info.jsonのフォーマットは以下の通りです。\n\n```json\n{\n  \"project_id\": 1,\n  \"requires_access_to_code\": false\n}\n```\n\n`project_id`はGitlabのプロジェクトID(数値)です。`requires_access_to_code`がfalseであれば対象のプロジェクトにアクセス可能であればコンテンツを返答します(実質的にGuest権限以上)。逆にtrueにするとgitリポジトリのファイルにアクセス可能な権限がなければアクセスを拒否します(実質的にReporter権限以上)。\n\n表示対象のURLのパスの直下にこの`.gitlab-info.json`ファイルがなければその上位ディレクトリを順番に探索して最初にみつけたものを使います。  \n例えば`http://example.com/path/to/index.html`にアクセスしたときに、`/srv/nginx/pages/path/to/.gitlab-info.json`にファイルがなければ`/srv/nginx/pages/path/.gitlab-info.json`を、それもなければ`/srv/pages/.gitlab-info.json`を探します。\n\n\n## セットアップ方法\n\n実際に利用するときのセットアップ方法の例として、nginx + oauth2_proxy + 本サーバーの構成をDockerで起動できるようにしています。  \ndocker-compose.yml ファイルの各環境変数を書き換えた上で起動してください。\n\nこのサーバーはGitlab Pages用のサーバーとして、`http://myproj.example.com/myfile.html`にアクセスしたら`$PWD/pages/myproj/myfile.html`の内容を返答します。  \n実際にGitlab PagesのコンテンツをGitlab-CIで生成するときは、以下のようにして`.gitlab-info.json`を作成してください。\n\n```yaml:.gitlab-ci.yml\n# .gitlab-ci.yml\npages:\n  script:\n    # コンテンツ生成\n    - make some contents\n    - mv build public\n    # .gitlab-info.json生成\n    - echo \"{\\\"project_id\\\": $CI_PROJECT_ID, \\\"requires_access_to_code\\\": false}\" \u003e public/.gitlab-info.json\n  artifacts:\n    paths:\n      - public\n```\n\n具体的なnginxやoauth2_proxyの設定方法については、dockerフォルダ下のファイルを参照してください。\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fm3dev%2Fgitlab-access-controlled-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fm3dev%2Fgitlab-access-controlled-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fm3dev%2Fgitlab-access-controlled-server/lists"}