cloudflared 設定メモ

# メモ

# Tunnel の設定
1. Zero Trust dashboard にアクセス
    - https://one.dash.cloudflare.com/
2. 左サイドバーで `Networks > Tunnels` 選択 
    - ![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/278058/d309ebe0-fe15-22ec-4a30-4b80e604de1f.png)
3. `Add a tunnel` クリック
    - ![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/278058/55764fc6-cafc-a668-e238-648889ad680d.png)
4. `Cloudflared` 選択
    - ![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/278058/8b909d47-6a54-dadc-6c4f-996713f81bc5.png)
5. Tunnel の名前を入力して `Save tunnel`
    - ![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/278058/889fa2cb-97d1-29f9-3a8b-f072af751e9e.png)
6. Choose your environment で `Docker` 選択
    - ![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/278058/4ab4f729-3abc-a56e-e1c5-3782351da531.png)
    - Docker コマンド: `docker run cloudflare/cloudflared:latest tunnel --no-autoupdate run --token <token>`
7. 今回は VPN 的に使いたいので `Private Networks` を設定する
    - ![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/278058/cd6c3c47-cec8-2827-5506-da6811d6c388.png)

## Authentication の設定
1. Zero Trust dashboard にアクセス
    - https://one.dash.cloudflare.com/
2. 左サイドバーで `Settings` 選択
    - ![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/278058/57dfaa9d-2ec6-c69a-4191-0865ff2677d3.png)
3. `Authentication` 選択
    - ![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/278058/70dee67b-e378-0520-837e-2fbc67366222.png)
4. Autentication の設定を行う
    - `Global session timeout` で timeout 設定
    - `Login methods` でログイン認証の設定
        - ![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/278058/7390c80e-e416-ac48-fa2e-c464138c84af.png)
    - ![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/278058/a51ac2c1-a966-9b63-b442-447417b43cf8.png)
5. 左サイドバーで `Settings` 選択
    - ![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/278058/57dfaa9d-2ec6-c69a-4191-0865ff2677d3.png)
6. `WARP Client` 選択
    - ![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/278058/048601f7-37be-ba09-b486-2a2330b155c4.png)
7. `Device enrollment > Device enrollment permissions` 選択
    - ![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/278058/41d3625b-0b73-e16d-2463-e09186021c6c.png)
8. `Device enrollment rules` で Email 設定して `Save`
    - 該当 Email 以外には PIN が送信されない 
    - ![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/278058/14049032-470b-42ba-2052-30dded415564.png)
9. こうなる
    - ![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/278058/aa2f7fca-3172-0c61-f703-7e89b29ecbc1.png)
 
## Split Tunnel の設定
- https://developers.cloudflare.com/cloudflare-one/connections/connect-devices/warp/configure-warp/route-traffic/split-tunnels//

1. Zero Trust dashboard にアクセス
    - https://one.dash.cloudflare.com/
2. 左サイドバーで `Settings` 選択
    - ![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/278058/57dfaa9d-2ec6-c69a-4191-0865ff2677d3.png)
3. `WARP Client` 選択
    - ![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/278058/048601f7-37be-ba09-b486-2a2330b155c4.png)
4. `Device settings > Profile settings` から `Configure` 選択
    - ![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/278058/79500828-6fd7-a667-70ba-fe66c1116538.png)
5. `Split Tunnels` で `***` 選択
    - ![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/278058/8c78a40a-300f-a31e-f913-9650b42bde96.png)
6. IP アドレス等入力して `Save destination`
    - ![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/278058/b38641c0-0f74-13c3-5e99-93627caee75c.png)
7. こうなる
    - ![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/278058/e65810e6-d016-1b98-1393-2e8e0cf45675.png)


## cloudflared 起動
1. `docker run -d --network=host cloudflare/cloudflared:latest tunnel --no-autoupdate run --token ***`
    - `-d` でデーモン化
    - `--network=host` でホストネットワークに接続
2. Zero Trust dashboard にアクセス
    - https://one.dash.cloudflare.com/
3. 左サイドバーで `Networks > Tunnels` 選択 
    - ![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/278058/d309ebe0-fe15-22ec-4a30-4b80e604de1f.png)
4. `Status` が `HEALTHY` になっていれば OK
    - ![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/278058/0c9dcc65-b8b5-cdd0-3098-e207b7d17316.png)
 
## WARP client 設定
1. `WARP` で検索して Client Install
    - `1.1.1.1: Faster Interner` というアプリ名 
    - ![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/278058/73b60984-7f4d-6f9d-d8b5-1293ba9de89f.png)
2. `Install VPN profile` タップ
    - ![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/278058/8282d8e3-8769-6116-f648-dc4b7027e8ff.png)
3. 右上の `≡` からメニュー展開
    - ![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/278058/0e87f185-e052-57bc-a85f-4199555ebf63.png)
4. `Account` をタップして `Login to Cloudflare Zero Trust` からログイン
    - ![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/278058/ef32fb55-987b-ec69-97ae-99d986992790.png)
5. Team Name は Zero Trust dashboard > Settings > Custom Pages から確認可能
    - ![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/278058/2b249367-7e9f-eb82-41c4-626d6e8ad74b.png)
6. ログイン完了後、`Install VPN profile` 設定
    - ![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/278058/c02e809e-bcb9-64fb-bd39-5ed918847fdc.png)