Skip to content

Commit d99141c

Browse files
author
gitlayzer
committed
feat: add tunnel basic auth
1 parent 6abbde4 commit d99141c

28 files changed

Lines changed: 1136 additions & 88 deletions

.dockerignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.git
2+
.github
3+
.DS_Store
4+
5+
sealtun
6+
dist
7+
tmp
8+
*.tmp
9+
10+
docs
11+
homepage
12+
packages
13+
14+
coverage.out
15+
*.test
16+

.github/workflows/ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ jobs:
3131
- name: Run tests
3232
run: go test ./...
3333

34+
- name: Run vet
35+
run: go vet ./...
36+
37+
- name: Check npm package builder syntax
38+
run: node --check scripts/build-npm-packages.mjs
39+
3440
goreleaser-snapshot:
3541
runs-on: ubuntu-latest
3642
needs: test

.github/workflows/release.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ jobs:
3131
go-version: '1.25.10'
3232
cache: true
3333

34+
- name: Run tests
35+
run: go test ./...
36+
37+
- name: Run vet
38+
run: go vet ./...
39+
40+
- name: Check npm package builder syntax
41+
run: node --check scripts/build-npm-packages.mjs
42+
3443
- name: Run GoReleaser
3544
uses: goreleaser/goreleaser-action@v6
3645
with:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
/sealtun
44
/sealtun.exe
55
/packages/
6+
/homepage/
67

78
# Generated copyright application artifacts
89
/docs/copyright/

Makefile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,17 @@ BINARY_NAME=sealtun
1010

1111
# Get version from git (Pure Git Hash mode)
1212
VERSION ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo "dev")
13-
NPM_VERSION ?= $(shell (git describe --tags --abbrev=0 2>/dev/null || echo v0.0.0) | sed 's/^v//')
13+
NPM_LATEST_RELEASE_TAG ?= $(shell git describe --tags --abbrev=0 2>/dev/null || echo v0.0.0)
14+
NPM_VERSION ?= $(shell echo $(NPM_LATEST_RELEASE_TAG) | sed 's/^v//')
1415
NPM_RELEASE_TAG ?= v$(NPM_VERSION)
1516
NPM_GITHUB_REPO ?= gitlayzer/sealtun
1617
NPM_PACKAGE_NAME ?= sealtun
1718
NPM_BINARY_PACKAGE_SCOPE ?= @gitlayzer
1819
NPM_PACKAGES_DIR ?= packages
1920
NPM_DIST_TAG ?= latest
20-
NPM_PUBLISH_FLAGS ?=
21+
NPM_PUBLISH_FLAGS ?= --access public
22+
NPM_DRY_RUN_VERSION ?= 0.0.0-dry-run.$(shell date +%Y%m%d%H%M%S)
23+
NPM_DRY_RUN_RELEASE_TAG ?= $(NPM_LATEST_RELEASE_TAG)
2124

2225
# Build flags
2326
LDFLAGS=-ldflags "-s -w -X github.com/labring/sealtun/pkg/version.Version=$(VERSION)"
@@ -77,6 +80,8 @@ npm-publish: npm-packages
7780
(cd "$(NPM_PACKAGES_DIR)" && $(NPM) publish --tag "$(NPM_DIST_TAG)" $(NPM_PUBLISH_FLAGS))
7881

7982
## npm-publish-dry-run: verify the npm publish payload without publishing
83+
npm-publish-dry-run: NPM_VERSION := $(NPM_DRY_RUN_VERSION)
84+
npm-publish-dry-run: NPM_RELEASE_TAG := $(NPM_DRY_RUN_RELEASE_TAG)
8085
npm-publish-dry-run: NPM_PUBLISH_FLAGS += --dry-run
8186
npm-publish-dry-run: npm-publish
8287

README.md

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ make build
7575
./sealtun --version
7676
```
7777

78-
`make build` 默认会把当前 Git short hash 注入到本地二进制的 version 中,用于确认本地二进制和已 push 的代码提交一致。正式 tag 发布时,GitHub Actions 会用 tag 版本构建 GitHub Release 产物和容器镜像
78+
`make build` 默认会把当前 Git short hash 注入到本地二进制的 version 中,用于确认本地二进制和已 push 的代码提交一致。未打 tag 的本地构建会使用 `latest` 远端隧道镜像;正式 tag 发布时,GitHub Actions 会用 tag 版本构建 GitHub Release 产物和同版本容器镜像
7979

8080
## 🚢 发版流程
8181

@@ -94,6 +94,15 @@ git push origin vX.Y.Z
9494

9595
推送 `v*` tag 后,GitHub Actions 会触发 GoReleaser 生成多平台二进制和 GitHub Release;Docker workflow 会同步构建并发布 `ghcr.io/gitlayzer/sealtun` 镜像。发版后建议重新执行 `make build && ./sealtun --version`,确认本地二进制显示的 Git hash 与已 push 的提交一致。
9696

97+
GitHub Release 产物构建完成后,再发布 npm 包:
98+
99+
```bash
100+
NPM_VERSION=X.Y.Z NPM_RELEASE_TAG=vX.Y.Z make npm-publish-dry-run
101+
NPM_VERSION=X.Y.Z NPM_RELEASE_TAG=vX.Y.Z make npm-publish
102+
```
103+
104+
`make npm-publish` 会先从对应 GitHub Release 下载 GoReleaser 生成的二进制资产,生成本地 `packages/` 目录,然后先发布各平台可选依赖包,最后发布主包。`packages/` 是发包中间产物,已被 `.gitignore` 忽略,不提交到远端。
105+
97106
## 🚀 快速上手
98107

99108
### 1. 登录到 Sealos
@@ -134,6 +143,18 @@ sealtun expose 3000
134143

135144
```
136145

146+
为公网业务流量启用 Basic Auth:
147+
```bash
148+
# 推荐:从环境变量读取密码,避免进入 shell history
149+
export SEALTUN_BASIC_AUTH_PASSWORD='change-me'
150+
sealtun expose 3000 --basic-auth-user admin --basic-auth-password-env SEALTUN_BASIC_AUTH_PASSWORD
151+
152+
# 也支持一次性写法
153+
sealtun expose 3000 --basic-auth admin:change-me
154+
```
155+
156+
Basic Auth 由 Sealtun server 代理层校验,不依赖 Ingress annotation;它只保护公网业务路径,不会拦截 `/_sealtun/ws` 隧道控制通道、健康检查或受内部 Bearer secret 保护的 metrics。
157+
137158
Sealtun 会自动执行以下操作:
138159
1. 在你的 Sealos Namespace 中启动一个隧道代理 Pod。
139160
2. 配置 Ingress 路由规则。
@@ -212,6 +233,8 @@ tunnels:
212233
localPort: 3000
213234
protocol: https
214235
domain: app.example.com
236+
basicAuth:
237+
credential: admin:change-me
215238
waitDomain: false
216239
readyTimeout: 90s
217240
domainTimeout: 5m
@@ -226,6 +249,20 @@ sealtun apply -f sealtun.yaml --dry-run
226249
sealtun apply -f sealtun.yaml
227250
```
228251

252+
也可以使用展开的明文写法:
253+
```yaml
254+
basicAuth:
255+
username: admin
256+
password: change-me
257+
```
258+
259+
或从环境变量读取密码:
260+
```yaml
261+
basicAuth:
262+
username: admin
263+
passwordEnv: SEALTUN_BASIC_AUTH_PASSWORD
264+
```
265+
229266
`name` 会作为稳定 tunnel ID 使用,因此重复执行 `apply` 会更新同一个 `sealtun-<name>` 资源。自定义域名仍然遵循 CNAME 先验证再绑定的规则;新隧道如果 CNAME 未就绪,`apply` 会先保留 Sealos 官方域名并输出后续 `domain set` 指令;已有隧道则会拒绝未验证的自定义域名变更,避免误清理或覆盖正在使用的域名配置。
230267

231268
## 🛠️ 架构详情

README_EN.md

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[中文版本](./README.md)
44

5-
Sealtun is a powerful, elegant CLI tool that provides a `cloudflared` tunnel-like experience entirely built on **Sealos Cloud** and **Kubernetes**.
5+
Sealtun is a powerful, elegant CLI tool that provides a `cloudflared` tunnel-like experience entirely built on **Sealos Cloud** and **Kubernetes**.
66

77
It connects your local development machine straight to the internet by dynamically provisioning Kubernetes resources (Deployments, Services, Ingresses) and tunneling the traffic securely via bidirectional multiplexed WebSocket streams (`yamux`).
88

@@ -75,7 +75,7 @@ make build
7575
./sealtun --version
7676
```
7777

78-
`make build` injects the current Git short hash into the local binary version by default, which makes it easy to verify that the local binary matches the pushed commit. Tagged releases are built by GitHub Actions using the tag version for GitHub Release assets and container images.
78+
`make build` injects the current Git short hash into the local binary version by default, which makes it easy to verify that the local binary matches the pushed commit. Untagged local builds use the `latest` remote tunnel image; tagged releases are built by GitHub Actions using the tag version for GitHub Release assets and matching container images.
7979

8080
## Release Process
8181

@@ -94,6 +94,15 @@ git push origin vX.Y.Z
9494

9595
Pushing a `v*` tag triggers GitHub Actions: GoReleaser builds multi-platform binaries and creates the GitHub Release, while the Docker workflow builds and publishes the matching `ghcr.io/gitlayzer/sealtun` image. After release, run `make build && ./sealtun --version` again to confirm that the local binary reports the Git hash that was pushed.
9696

97+
After GitHub Release assets finish building, publish the npm packages:
98+
99+
```bash
100+
NPM_VERSION=X.Y.Z NPM_RELEASE_TAG=vX.Y.Z make npm-publish-dry-run
101+
NPM_VERSION=X.Y.Z NPM_RELEASE_TAG=vX.Y.Z make npm-publish
102+
```
103+
104+
`make npm-publish` downloads the GoReleaser binary assets from the matching GitHub Release, generates the local `packages/` directory, publishes each platform optional dependency first, and then publishes the main package. `packages/` is a publish-time artifact and is ignored by `.gitignore`, so it is not committed.
105+
97106
## Quick Start
98107

99108
### 1. Login to Sealos
@@ -134,6 +143,18 @@ sealtun expose 3000
134143

135144
```
136145

146+
Enable Basic Auth for public application traffic:
147+
```bash
148+
# Recommended: read the password from the environment to avoid shell history
149+
export SEALTUN_BASIC_AUTH_PASSWORD='change-me'
150+
sealtun expose 3000 --basic-auth-user admin --basic-auth-password-env SEALTUN_BASIC_AUTH_PASSWORD
151+
152+
# One-shot form is also supported
153+
sealtun expose 3000 --basic-auth admin:change-me
154+
```
155+
156+
Basic Auth is enforced by the Sealtun server proxy layer, not by Ingress annotations. It protects only public application paths and does not block the `/_sealtun/ws` tunnel control channel, health checks, or metrics protected by the internal Bearer secret.
157+
137158
Sealtun will:
138159
1. Spin up a tunnel proxy Pod in your Sealos namespace.
139160
2. Establish the Ingress routes.
@@ -212,6 +233,8 @@ tunnels:
212233
localPort: 3000
213234
protocol: https
214235
domain: app.example.com
236+
basicAuth:
237+
credential: admin:change-me
215238
waitDomain: false
216239
readyTimeout: 90s
217240
domainTimeout: 5m
@@ -226,6 +249,20 @@ sealtun apply -f sealtun.yaml --dry-run
226249
sealtun apply -f sealtun.yaml
227250
```
228251

252+
You can also use the expanded inline form:
253+
```yaml
254+
basicAuth:
255+
username: admin
256+
password: change-me
257+
```
258+
259+
If you prefer not to store the password in the config file, use `passwordEnv`:
260+
```yaml
261+
basicAuth:
262+
username: admin
263+
passwordEnv: SEALTUN_BASIC_AUTH_PASSWORD
264+
```
265+
229266
`name` is used as the stable tunnel ID, so repeated `apply` runs update the same `sealtun-<name>` resources. Custom domains still require verified CNAME ownership before attachment; for a new tunnel, `apply` keeps the Sealos-managed host and prints the follow-up `domain set` command when DNS is not ready. For an existing tunnel, `apply` rejects unverified custom-domain changes so it does not accidentally clear or overwrite a working domain configuration.
230267

231268
## Architecture Details

0 commit comments

Comments
 (0)