0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Cline Kanban をコンテナで動かす

0
Posted at

動機

Cline Kanban を Devcontainer 上で動かしたかった。compose.yml に ports セクションを書いてポートフォワーディングするだけかと思いきや、予想外の悪戦苦闘を強いられたのでメモを残しておく。

わたしは Devcontainer を devcontainer-cli から利用しているので、docker compose を直接利用するのと大差ない形になっている。VSCode から Devcontainer を利用する場合はまた別の方法でポートフォワーディングされるので、この問題は起こらないらしい。

問題

Kanban をコンテナで起動し、ホストマシンからアクセスする場合、ホストからのアクセスを受け入れるために kanban --host 0.0.0.0 で起動する必要がある。しかし Kanban は厳格な Host ヘッダーのチェックを行っているため、ホストからは http://0.0.0.0:<port> でアクセスしなければ 403 を返してしまう。 0.0.0.0 は無効なメタアドレスである。

解決策

Nginx をプロキシとして、厳格にリクエストヘッダーを偽装する。以下の点に注意。

  • Host ヘッダーだけでなく、Referer, Origin ヘッダーも偽装する
  • ポート名も含める
  • Kanban は WebSocket を使っているので、この設定もフォワードする

設定例

services:
  app:
    build:
      context: .
      dockerfile: ./Dockerfile
    networks:
      - kanban-net

  proxy:
    image: nginx:alpine
    ports:
      - "3484:8080"
    depends_on:
      - app
    networks:
      - kanban-net
    command: >
      /bin/sh -c "echo 'server {
        listen 8080;
        location / {
          proxy_pass http://app:3484;
          proxy_set_header Host 0.0.0.0:3484;
          proxy_set_header Referer http://0.0.0.0:3484;
          proxy_set_header Origin http://0.0.0.0:3484;
          proxy_set_header X-Real-IP $$remote_addr;
          proxy_set_header X-Forwarded-For $$proxy_add_x_forwarded_for;

          proxy_http_version 1.1;
          proxy_set_header Upgrade $$http_upgrade;
          proxy_set_header Connection \"upgrade\";
        }
      }' > /etc/nginx/conf.d/default.conf && nginx -g \"daemon off;\""

networks:
  kanban-net:

3484 は Kanban のデフォルトポートなので、適宜修正されたい。

注意事項

Kanban は Service Worker を使っているので、Nginx の設定を間違えた場合は Developer Console から Application > Service Worker > Unregister でエラー状態のキャッシュをクリアする必要があるかもしれない。

その他

トラブルシューティング自体は AI にやってもらったが、この記事自体は今日日珍しいことに人間の手で書かれた。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?