VPS に Tailscale を入れた。これで名実ともにすべてのポートを閉ざすことが可能になった。
まず tag を Access Control で作っておく:
"tagOwners": {
"tag:ci": ["autogroup:admin"],
"tag:server": ["autogroup:admin"],
}
- 上記は admin(Owner Role の保持者)がタグをアサインできる、というだけの意味
- このあと VPS に server、CI ランナーに ci をアタッチする
Access Control で通信の設定もしておく:
"grants": [
{"src": ["autogroup:admin"], "dst": ["tag:server"], "ip": ["*"]},
{"src": ["tag:ci"], "dst": ["tag:server"], "ip": ["*"]},
],
"ssh": [
{
"action": "accept",
"src": ["autogroup:admin"],
"dst": ["tag:server"],
"users": ["root", "ansible"],
},
{
"action": "accept",
"src": ["tag:ci"],
"dst": ["tag:server"],
"users": ["root", "ansible"],
},
],
- 開発機 -> サーバ, CI -> サーバ 方向の通信だけ許可する
Ansible の設定する:
roles:
- role: artis3n.tailscale
vars:
verbose: true
tailscale_authkey: "{{ taliscale_key }}"
tailscale_tags:
- server
tailscale_oauth_preauthorized: true
tailscale_oauth_ephemeral: true
tailscale_args: "--ssh"
- OAuth Client を作って Client Secret を
tailscale_authkeyに指定 - OAuth Client のスコープは
device:coreの read/write、auth_keysの read/writedevice:coreは タグを device にアタッチするために必要auth_keysは OAuth Client が auth token を device 向けに生成するために必要- 上記の操作をどの device に対して許可するのかタグで指定する
- このとき
tags:server,tags:ciみたいにタグを複数選択できるが、AND 条件なので注意
GitHub Actions で Tailscale を使うのは簡単:
- name: Tailscale
uses: tailscale/github-action@v3
with:
oauth-client-id: ${{ secrets.TS_OAUTH_CLIENT_ID }}
oauth-secret: ${{ secrets.TS_OAUTH_SECRET }}
tags: tag:ci
use-cache: 'true'
- name: SSH to VPS
uses: appleboy/ssh-action@v1
with:
host: ${{ secrets.TS_HOST }}
username: ${{ secrets.VPS_USER }}
key: ${{ secrets.VPS_SSH_KEY }}
- これも同様に tag:ci を指定して OAuth Client を作っておく。
TS_HOSTは100.x.y.zとかになる。
Tailscale は tailscale serve http://localhost:8000 すると https でローカルホストの内容を公開することもできる。リバース SSH トンネルみたいなかんじ