Deploys Tailscale as WireGuard-based zero-trust mesh VPN with identity-aware ACLs, exit nodes, and P2P connections. Covers Linux, Docker, Kubernetes installs.
npx claudepluginhub killvxk/cybersecurity-skills-zhThis skill uses the workspace's default tool permissions.
Tailscale 是一种基于 WireGuard 构建的零信任网状 VPN,无需传统 VPN 服务器或复杂网络配置,即可在设备之间创建加密的点对点连接。Tailscale 网络(tailnet)中的每个连接都使用 WireGuard 的 Noise 协议框架和 Curve25519 密钥交换进行端到端加密。Tailscale 通过身份提供商认证每个连接请求、执行细粒度访问控制列表(ACL),以及支持出口节点(exit node)、子网路由器、MagicDNS 和 Tailscale SSH 等功能来实现零信任网络。对于偏好自托管基础设施的组织,Headscale 提供了 Tailscale 控制服务器的开源实现。
Deploys and configures Tailscale as a WireGuard-based zero trust mesh VPN with identity-aware access controls, ACLs, exit nodes, and Headscale for secure peer-to-peer connectivity.
Deploys and configures Tailscale as WireGuard-based zero-trust mesh VPN with identity-aware ACLs, exit nodes, and Headscale for secure P2P connectivity.
Manages Tailscale mesh VPN networks via CLI and API: check status/peers, ping devices, list tailnet devices, send files, expose services with serve/funnel, create auth keys.
Share bugs, ideas, or general feedback.
Tailscale 是一种基于 WireGuard 构建的零信任网状 VPN,无需传统 VPN 服务器或复杂网络配置,即可在设备之间创建加密的点对点连接。Tailscale 网络(tailnet)中的每个连接都使用 WireGuard 的 Noise 协议框架和 Curve25519 密钥交换进行端到端加密。Tailscale 通过身份提供商认证每个连接请求、执行细粒度访问控制列表(ACL),以及支持出口节点(exit node)、子网路由器、MagicDNS 和 Tailscale SSH 等功能来实现零信任网络。对于偏好自托管基础设施的组织,Headscale 提供了 Tailscale 控制服务器的开源实现。
Tailscale 协调服务器
(或自托管 Headscale)
|
密钥分发
& NAT 穿透
|
+-----------------+-----------------+
| | |
+----+----+ +----+----+ +----+----+
| 节点 A |<---->| 节点 B |<---->| 节点 C |
| (Linux) | | (macOS) | |(Windows)|
+---------+ +---------+ +---------+
WireGuard WireGuard WireGuard
加密 P2P 隧道 加密 P2P 隧道 加密 P2P 隧道
每个节点与其他所有节点直接连接。
仅在直连 P2P 失败时使用 DERP 中继服务器。
# 添加 Tailscale 仓库并安装
curl -fsSL https://tailscale.com/install.sh | sh
# 启动 Tailscale 并进行认证
sudo tailscale up
# 检查连接状态
tailscale status
# 查看分配的 IP 地址
tailscale ip -4
tailscale ip -6
# Windows:从 https://tailscale.com/download/windows 下载
# macOS:通过 Homebrew 安装
brew install --cask tailscale
# 或从 https://tailscale.com/download/mac 下载
# 用于 Tailscale sidecar 的 docker-compose.yml
version: '3.8'
services:
tailscale:
image: tailscale/tailscale:latest
container_name: tailscale
hostname: my-service
environment:
- TS_AUTHKEY=tskey-auth-xxxxx # 预认证密钥
- TS_STATE_DIR=/var/lib/tailscale
- TS_EXTRA_ARGS=--advertise-tags=tag:container
volumes:
- tailscale-state:/var/lib/tailscale
- /dev/net/tun:/dev/net/tun
cap_add:
- net_admin
- sys_module
restart: unless-stopped
volumes:
tailscale-state:
# Tailscale Kubernetes Operator
apiVersion: v1
kind: Secret
metadata:
name: tailscale-auth
namespace: tailscale
type: Opaque
stringData:
TS_AUTHKEY: "tskey-auth-xxxxx"
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: tailscale
namespace: tailscale
spec:
selector:
matchLabels:
app: tailscale
template:
metadata:
labels:
app: tailscale
spec:
containers:
- name: tailscale
image: tailscale/tailscale:latest
env:
- name: TS_AUTHKEY
valueFrom:
secretKeyRef:
name: tailscale-auth
key: TS_AUTHKEY
- name: TS_KUBE_SECRET
value: tailscale-state
- name: TS_USERSPACE
value: "true"
securityContext:
capabilities:
add: ["NET_ADMIN"]
Tailscale ACL 使用声明式 JSON 格式定义 tailnet 内谁可以访问什么。默认策略为拒绝所有,从设计上实现零信任。
{
"acls": [
// 工程团队可以访问开发服务器
{
"action": "accept",
"src": ["group:engineering"],
"dst": ["tag:dev-server:*"]
},
// SRE 团队可以访问生产基础设施
{
"action": "accept",
"src": ["group:sre"],
"dst": ["tag:production:22,443,8080"]
},
// 数据库访问仅限后端服务
{
"action": "accept",
"src": ["tag:backend"],
"dst": ["tag:database:5432,3306,27017"]
},
// 所有员工可以访问内部工具
{
"action": "accept",
"src": ["group:employees"],
"dst": ["tag:internal-tools:443"]
}
],
"groups": {
"group:engineering": ["user@company.com", "dev@company.com"],
"group:sre": ["sre@company.com", "oncall@company.com"],
"group:employees": ["autogroup:members"]
},
"tagOwners": {
"tag:dev-server": ["group:engineering"],
"tag:production": ["group:sre"],
"tag:backend": ["group:sre"],
"tag:database": ["group:sre"],
"tag:internal-tools": ["group:sre"],
"tag:container": ["group:sre"]
},
"ssh": [
{
"action": "check",
"src": ["group:sre"],
"dst": ["tag:production"],
"users": ["root", "admin"]
},
{
"action": "accept",
"src": ["group:engineering"],
"dst": ["tag:dev-server"],
"users": ["autogroup:nonroot"]
}
],
"nodeAttrs": [
{
"target": ["autogroup:members"],
"attr": ["funnel:deny"]
}
]
}
# 在出口节点机器上
sudo tailscale up --advertise-exit-node
# 在客户端机器上使用出口节点
sudo tailscale up --exit-node=<exit-node-ip>
# 验证出口节点路由
curl ifconfig.me # 应显示出口节点的公网 IP
# 通过 Tailscale 发布本地子网
sudo tailscale up --advertise-routes=10.0.0.0/24,192.168.1.0/24
# 在 Linux 上启用 IP 转发
echo 'net.ipv4.ip_forward = 1' | sudo tee -a /etc/sysctl.conf
echo 'net.ipv6.conf.all.forwarding = 1' | sudo tee -a /etc/sysctl.conf
sudo sysctl -p
# 在客户端上接受路由
sudo tailscale up --accept-routes
Tailscale SSH 以基于身份的访问取代传统 SSH 密钥管理。
# 在服务器上启用 Tailscale SSH
sudo tailscale up --ssh
# 使用 Tailscale SSH 连接(无需 SSH 密钥)
ssh user@hostname # 通过 Tailscale 身份认证
# 会话录制(审计日志)
# 在 ACL 策略中配置:
# "ssh": [{"action": "check", "src": [...], "dst": [...], "users": [...]}]
# "check" 操作要求重新认证并录制会话
# MagicDNS 在新 tailnet 中默认启用
# 通过主机名而非 IP 访问设备
ping my-server # 通过 MagicDNS 解析
# 通过管理控制台进行自定义 DNS 配置
# 分割 DNS:将特定域名路由到内部 DNS 服务器
# 全局域名服务器:覆盖默认 DNS 解析
# 安装 Headscale(开源 Tailscale 控制服务器)
wget https://github.com/juanfont/headscale/releases/latest/download/headscale_linux_amd64
chmod +x headscale_linux_amd64
sudo mv headscale_linux_amd64 /usr/local/bin/headscale
# 创建配置
sudo mkdir -p /etc/headscale
sudo headscale generate config > /etc/headscale/config.yaml
# 编辑配置以适应您的环境
# 关键设置:
# server_url: https://headscale.example.com
# listen_addr: 0.0.0.0:8080
# private_key_path: /etc/headscale/private.key
# db_type: sqlite3
# db_path: /var/lib/headscale/db.sqlite
# 启动 Headscale
sudo headscale serve
# 创建用户和预认证密钥
headscale users create myorg
headscale preauthkeys create --user myorg --reusable --expiration 24h
# 将 Tailscale 客户端连接到 Headscale
tailscale up --login-server https://headscale.example.com
# 在管理控制台设置密钥到期(默认:180 天)
# 定期强制重新认证
# 为服务器禁用密钥到期(改用认证密钥)
sudo tailscale up --authkey=tskey-auth-xxxxx
# 用于自动部署的预认证密钥
# 为 CI/CD 创建临时单次使用密钥
{
"nodeAttrs": [
{
"target": ["autogroup:members"],
"attr": [
"mullvad:deny",
"funnel:deny"
]
}
],
"autoApprovers": {
"routes": {
"10.0.0.0/24": ["group:sre"],
"192.168.0.0/16": ["group:sre"]
},
"exitNode": ["group:sre"]
}
}
# 使用签名密钥初始化网络锁
tailscale lock init
# 添加受信任签名密钥
tailscale lock add nodekey:xxxxx
# 所有新节点加入前需要签名
# 防止未授权节点加入 tailnet
# 查看网络状态
tailscale status --json | jq '.Peer | to_entries[] | {name: .value.HostName, online: .value.Online, os: .value.OS}'
# 检查连接质量
tailscale ping <peer-ip>
# 查看网络拓扑图
tailscale netcheck
# 审计日志在 Tailscale 管理控制台中可查
# 通过 Webhook 或 API 集成 SIEM
# Tailscale 作为服务间通信的 sidecar
# 每个服务获得一个 Tailscale 身份
# ACL 执行服务间访问策略
# 示例:API 服务只能访问数据库服务
# ACL:tag:api -> tag:database:5432
# 在 CI/CD 中使用临时认证密钥
export TS_AUTHKEY=tskey-auth-xxxxx-ephemeral
tailscale up --authkey=$TS_AUTHKEY --hostname=ci-runner-$CI_JOB_ID
# 在构建/部署过程中访问内部资源
# 容器停止时节点自动移除