feat(deploy,gateway): add dual-edition deployment/migration/rollback and TUN route reconciliation

- Add standalone edition (`Dockerfile.standalone`, `docker-compose.standalone.yml`) alongside sandbox edition and publish both in `.github/workflows/release.yml`.
- Implement `scripts/deploy-lib.sh`, `install.sh`, `update.sh`, and `scripts/artex-sandbox-firewall.sh --cleanup` with edition detection, legacy standalone -> sandbox migration (symlink-safe workspace permissions), automatic snapshots with pinned `artex-rollback/*` images + PG dump, auto/manual cross-edition rollback, and post-rollback upstream unpinning.
- Update `ensureWritableDir` in `internal/sandbox/manager.go` to safely migrate nested root-owned workspace files without following symlinks.
- Expose `deploy_edition` in `/api/update/check` and update `UpdateCard` UI/i18n warnings for sandbox vs standalone in-app update/rollback.
- Reconcile `artex-gateway` TUN policy routing (`priority 218`, `raw PREROUTING`, `nat POSTROUTING`, `DOCKER-USER`) every 15s to self-heal after host network rule flushes or bridge changes.
- Add unit and shell tests (`scripts/deploy_test.sh`, `cmd/artex-gateway/tun_linux_test.go`, `internal/sandbox/sandbox_test.go`, `server/update_test.go`) and update `README.md` / `.env.example`.
This commit is contained in:
ji ruo committed 2026-12-02 13:31:05 +08:00
1 parent d786de90af
commit 07309e4530
23 files changed
+2107 -144

No files matched your search

+23 -7
View File
@@ -1401,15 +1401,31 @@ func ensureWritableDir(dir, userSpec string) error {
if err := os.MkdirAll(dir, 0o777); err != nil {
return err
}
// Best-effort chmod + chown so non-root uid inside sandbox can write even
// when artex runs as root in its own container.
_ = os.Chmod(dir, 0o777)
uid, gid := -1, -1
if os.Geteuid() == 0 && userSpec != "" {
uid, gid := parseUIDGID(userSpec)
if uid >= 0 {
_ = os.Chown(dir, uid, gid)
}
uid, gid = parseUIDGID(userSpec)
}
// Best-effort chmod + chown on dir AND pre-existing non-symlink entries so
// workspaces migrated from root-owned standalone deployments remain writable
// by the non-root sandbox user without ever following symlinks.
_ = filepath.WalkDir(dir, func(p string, d os.DirEntry, walkErr error) error {
if walkErr != nil {
return nil
}
if d.Type()&os.ModeSymlink != 0 {
return nil
}
if d.IsDir() {
_ = os.Chmod(p, 0o777)
} else if info, err := d.Info(); err == nil {
// Preserve execute bits while ensuring non-root sandbox user can write.
_ = os.Chmod(p, info.Mode().Perm()|0o666)
}
if uid >= 0 {
_ = os.Lchown(p, uid, gid)
}
return nil
})
return nil
}
+45
View File
@@ -179,3 +179,48 @@ func TestConfigFromEnvAllowNetRaw(t *testing.T) {
t.Fatalf("AllowNetRaw should respect ARTEX_SANDBOX_ALLOW_NET_RAW=false")
}
}
func TestEnsureWritableDirMigratesNestedFilesWithoutFollowingSymlinks(t *testing.T) {
tmp := t.TempDir()
outside := filepath.Join(tmp, "outside-secret.txt")
if err := os.WriteFile(outside, []byte("secret"), 0o400); err != nil {
t.Fatal(err)
}
ws := filepath.Join(tmp, "tasks", "99")
nestedDir := filepath.Join(ws, "findings")
nestedFile := filepath.Join(nestedDir, "note.txt")
if err := os.MkdirAll(nestedDir, 0o755); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(nestedFile, []byte("migrated"), 0o444); err != nil {
t.Fatal(err)
}
if err := os.Chmod(nestedDir, 0o555); err != nil {
t.Fatal(err)
}
t.Cleanup(func() { _ = os.Chmod(nestedDir, 0o755) })
if err := os.Symlink(outside, filepath.Join(ws, "escape-link")); err != nil {
t.Fatal(err)
}
if err := ensureWritableDir(ws, "1000:1000"); err != nil {
t.Fatalf("ensureWritableDir: %v", err)
}
fi, err := os.Stat(nestedFile)
if err != nil {
t.Fatalf("stat nestedFile: %v", err)
}
if fi.Mode().Perm()&0o222 != 0o222 {
t.Fatalf("nested migrated file should be writable, got mode=%o", fi.Mode().Perm())
}
outInfo, err := os.Stat(outside)
if err != nil {
t.Fatalf("stat outside: %v", err)
}
if outInfo.Mode().Perm() != 0o400 {
t.Fatalf("symlink target outside workspace must stay 0400, got %o", outInfo.Mode().Perm())
}
}