[PR #6105] [MERGED] feat(amneziawg): add native AmneziaWG protocol support #6082

Closed
opened 2026-11-02 04:06:14 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/6105
Author: @kuzzrus
Created: 7/25/2026
Status: ✅ Merged
Merged: 8/24/2026
Merged by: @MHSanaei

Base: main ← Head: upstream-pr/amneziawg


📝 Commits (10+)

  • 6117561 feat(amneziawg): add native AmneziaWG protocol backend
  • 474e594 feat(amneziawg): add frontend support and fix a Go->Zod generator gap
  • e4ba75c feat(amneziawg): complete frontend parity for the Inbounds list page
  • 9f1ed38 docs(install): note that AmneziaWG kernel module install is still manual
  • 88f10e0 feat(amneziawg): add a button to randomize obfuscation parameters
  • 06d7c65 feat(install): auto-install the AmneziaWG DKMS module + amneziawg-tools
  • addda09 fix(amneziawg): resolve all 3 real CI failures (typecheck/lint/codegen)
  • cdf0f0a feat(amneziawg): Phase 2a — IPv6 support + NDP proxy
  • e10c421 fix(amneziawg): fill in IPv6 fields missed by the Phase 2a commit
  • ecfc0ca feat(amneziawg): Phase 2b — per-client port-forwarding

📊 Changes

146 files changed (+15241 additions, -134 deletions)

View changed files

📝 CLAUDE.md (+8 -1)
📝 docker-compose.yml (+4 -0)
📝 docs/architecture.md (+1 -0)
➕ docs/content/docs/en/config/amneziawg.mdx (+177 -0)
📝 docs/content/docs/en/config/inbounds.mdx (+1 -0)
📝 docs/content/docs/en/config/meta.json (+1 -0)
📝 docs/content/docs/en/reference/api/server.mdx (+8 -1)
📝 docs/content/docs/fa/reference/api/hosts.mdx (+1 -1)
📝 docs/content/docs/ru/reference/api/hosts.mdx (+1 -1)
📝 docs/content/docs/zh/reference/api/hosts.mdx (+1 -1)
📝 docs/public/openapi.json (+342 -1)
📝 frontend/public/openapi.json (+342 -1)
📝 frontend/src/generated/examples.ts (+75 -0)
📝 frontend/src/generated/schemas.ts (+265 -1)
📝 frontend/src/generated/types.ts (+63 -0)
📝 frontend/src/generated/zod.ts (+67 -1)
➕ frontend/src/lib/xray/amneziawg-obfuscation.ts (+125 -0)
📝 frontend/src/lib/xray/inbound-defaults.ts (+44 -1)
📝 frontend/src/lib/xray/inbound-form-adapter.ts (+3 -0)
📝 frontend/src/lib/xray/inbound-link.ts (+195 -1)

...and 80 more files

📄 Description

Summary

Adds native AmneziaWG 3.1 protocol support as a new inbound type — a WireGuard fork with traffic obfuscation, popular for bypassing DPI. amneziawg-go runs embedded in the panel process over a userspace (gVisor) network stack — no kernel module, no DKMS, no host tooling at all. Decapsulated traffic is relayed into a stock Xray SOCKS5 inbound authenticated per peer, so Xray's own stats/sniffing/access-log/routing all work for AmneziaWG clients natively, with no protocol-specific plumbing on that side. See the Update (2026-08-21) section below for why this differs from the kernel-module design this PR originally shipped.

Why

AmneziaWG has no first-class support in 3x-ui today. This adds it as a fully managed protocol with the full AmneziaWG 3.1 obfuscation parameter set:

  • junk-packet and padding params (Jc/Jmin/Jmax/S1-S4), magic headers (H1-H4), and signature packets (I1-I5);
  • the 3.x additions — HeaderProtectionKey (base64 32-byte, shared server↔client), ContentPaddingAddition, the handshake-timing randomization ranges (RekeyAfterTime/RekeyTimeout/RejectAfterTime/KeepaliveTimeout/MaxHandshakeAttempts), and the RandomTrailers/DisableCookies switches;
  • a regenerate button that produces a fully randomized, protocol-valid set per inbound (a static fingerprint defeats the point of obfuscation);

plus native IPv6 with a per-peer source-address alias (distinct outbound identity per peer, no NAT66), per-client port-forwarding, and routing a client's traffic through Xray's own outbound chain via the existing Routing page (every AmneziaWG inbound's relay is already tagged with its own inbound tag, so it's selectable there with no new UI needed for that part).

Host requirements: none beyond what the panel itself already needs — no kernel version floor, no DKMS, no amneziawg-tools/awg-quick package. Clients must run a 3.1-capable Amnezia app to use the 3.1-only fields (HeaderProtectionKey, ContentPaddingAddition, the timing/RandomTrailers/DisableCookies fields); blanking a 3.1-only field renders a config older clients still understand.

Update (2026-08-21) — reworked from a kernel-module (DKMS + awg-quick) sidecar to an embedded, in-process architecture

This supersedes the architecture described in the Update (2026-08-16) section below — that update's own "Go server config (awg-quick)" and "DKMS kernel module + root" mentions describe the design as it stood before this rewrite, not the code in this PR today. Rather than shelling out to awg-quick/awg against a DKMS-built kernel module (this fork's original design, and the one every earlier update in this PR body describes), the panel now embeds amneziawg-go directly and terminates each tunnel over an in-process userspace (gVisor) network stack. A forwarder recovers each connection's real destination and relays it into a stock, unmodified Xray SOCKS5 inbound, authenticated as that peer's own email — so Xray's native per-user stats, access log, sniffing, and Routing-page rules all apply to AmneziaWG traffic for free, the same way they already do for every other protocol, with no AmneziaWG-specific code needed on that side.

Motivation: the DKMS module structurally lagged the protocol (the 3.1 parameter set landed in the userspace amneziawg-go/amneziawg-tools line well before the kernel module + DKMS package caught up), and DKMS itself was this fork's single biggest source of installer fragility (kernel-version compatibility, Secure Boot rejecting the unsigned module outright, and package-repository reachability issues on some VPS providers). Moving the whole thing in-process removes that entire problem class. The real-network throughput tradeoff of a userspace stack vs. a kernel module was measured directly before committing to this (a real, substantial gap on a single saturating stream) and judged acceptable for this protocol's realistic usage pattern (many lower-throughput, latency-bound connections, not sustained bulk transfer) — noted here for reviewers who'd otherwise reasonably ask about it.

Everything else this PR's Why/Update sections describe — the full 3.1 parameter set, IPv6 identity, per-client port-forwarding, install/i18n/docs — is unchanged in scope and behavior; only the underlying mechanism moved.

Update (2026-08-16) — reworked from AWG 2.0 to AmneziaWG 3.1

The protocol surface was moved from the initial AWG 2.0 parameter set to AmneziaWG 3.1, matching the upstream amnezia-vpn tooling (amneziawg-tools v3.1.20260812, amneziawg-go v3.1.20260814). Concretely:

  • New parameters on both the stored inbound settings and every emitter: I2-I5, HeaderProtectionKey, ContentPaddingAddition, the five timing-randomization ranges, and the RandomTrailers/DisableCookies booleans (emitted as Key = on, verified against the real tools' config parser).
  • Generation fills a full-stealth set (header protection + padding + jittered timing windows that bracket WireGuard's own constants, with every reject window >= 30s above the rekey window by construction; RandomTrailers/DisableCookies on). Empty fields are omitted from the rendered config, so blanking one disables just that feature.
  • Validation requires a real base64 32-byte header-protection key, treats the range fields as uint32 lo-hi, cross-checks rekey-vs-reject (including against the WireGuard defaults when one side is blank), rejects control characters (a line-wrapped pasted key otherwise decoded to a valid key but split client configs), and canonicalizes range values on save.
  • All four config emitters agree key-by-key and in order — the rendered client-facing config (consumed by the Amnezia app, or awg-quick if an admin applies it directly), the Go client config behind vpn:// links, and both frontend emitters — pinned by order-sensitive tests plus a schema-parity test tying the hand-written Zod schema to the generated ServerSettings key set.
  • i18n: 19 new keys across all 13 locales; the "2.0" branding dropped from the S3/S4/I1 labels.
  • Docs + install.sh updated for the 3.1 parameters, the version/kernel requirements, and a sample client .conf that matches what the panel actually emits.

Real-tools validation (historical, describes this update's own testing at the time — see the 2026-08-21 update above for the architecture this now runs on): amneziawg-tools v3.1.20260812 was built from source and the panel's actual generated configs (server + client, including the fully randomized generator output and the I1-I5 + booleans set) were run through the genuine parser: awg-quick strip accepts the full server config, and awg setconf accepts every key/value, reaching the netlink stage (the only step gated on the DKMS kernel module + root, which this PR's design no longer uses server-side). Negative tests confirm the parser rejects unknown keys and bad values, so "accepted" is meaningful.

Also in this update: fixed the non-interactive install smoke test — it resolved the release version through the unauthenticated GitHub API (60 req/h per IP), and the two installs it runs could get the second call rate-limited on shared CI/CGNAT IPs, aborting the install. Version resolution now reads the releases/latest web redirect (no API quota), with the API only as a fallback.

Update (2026-08-04)

Since the last review pass, this branch picked up a batch of real bug fixes found while running this feature in production on a separate long-lived deployment. Summarizing here since the change touches several files across a few different concerns:

Hot-apply reliability (internal/xray/hot_diff.go) — two cases where Xray's gRPC AlterInbound reports success but doesn't actually work, confirmed against a real running instance, not just reasoned about:

  • A TPROXY inbound (this PR's own Xray egress bridge) added via gRPC never actually binds a working listener, even though the call succeeds.
  • A password-auth SOCKS5 inbound with named accounts can silently drop an account on a gRPC remove+add, even when the settings JSON on disk is correct.

Both cases now force a full process restart instead of a hot add/swap, mirroring the existing REALITY-inbound special case just above them in the same function.

AllowedIPs correctness across inbounds/protocols (internal/web/service/client_*.go) — a cluster of related bugs, all versions of the same root cause: uniqueness/validity of a tunnel client's address was only ever checked against its own inbound's client list.

  • Two clients on different WireGuard/AmneziaWG inbounds could be handed (or could keep) the exact same address — collision checking is now cross-inbound.
  • Re-attaching a client to a tunnel inbound (after detaching from all of them) could resurrect a stale address instead of allocating a genuinely free one.
  • An address inherited from one inbound could get silently carried over to a different inbound whose configured subnet doesn't actually contain it, producing a peer that can never connect — this is now checked per target inbound, with a fresh allocation as the fallback.
  • The same broadcast issue existed on the far more common plain-edit path (Update, not just Attach): a client attached to both WireGuard and AmneziaWG saving one shared AllowedIPs value could silently overwrite one protocol's address with the other's. Fixed at the root (model.Client gained an optional per-inbound override), and the edit form now shows two separate, correctly-labeled fields when both protocols are attached instead of one ambiguous shared one.

WireGuard gets its own configurable subnet field, mirroring the AmneziaWG inbound's existing one — previously WireGuard always inferred its subnet from existing clients, falling back to a hardcoded 10.0.0.0/24 with no way to override it. Existing inbounds that never set this are unaffected (same inference fallback as before).

Resync trigger fix — editing an AmneziaWG peer in a way that changes whether the inbound now qualifies for the Xray egress bridge (its first peer added, its last peer removed) now correctly flags Xray for a resync. Previously the bridge could silently fail to appear/disappear until a full panel restart.

Small fix: the AmneziaWG client config download button was missing from the subscription page.

All of the above ships with new unit tests (Go: internal/xray, internal/web/service; frontend: two new pure-function test files) and passes the full existing suite on both stacks.

Type of change

  • New feature
  • Bug fix

Areas affected

  • Frontend (UI / panel pages)
  • Backend (API endpoints, login, settings)
  • Xray config generation
  • Subscription (share links / Clash / JSON)
  • Statistics / traffic counters
  • Database / migrations
  • Install / upgrade script
  • Docker image
  • Multi-node (sub-nodes)
  • Telegram bot

How was this tested?

  • Live-tested on a real deployment: inbound created through the panel, real AmneziaWG client connected, handshake completed, traffic counted, IPv6 per-peer identity, per-client port-forwarding, and routing a client through an Xray outbound via the Routing page all verified working end-to-end.
  • The 3.1 rework was validated against amneziawg-tools v3.1.20260812 built from source: the panel's actual generated client configs parse cleanly (every 3.1 key/value accepted, unknown keys and bad values rejected).
  • The non-interactive install smoke test (deploy/test/smoke-noninteractive.sh) passes locally after the version-resolution fix.
  • The hot-apply fixes and the cross-inbound AllowedIPs fixes were each found as real bugs on a running deployment first, then reduced to a fix + regression test — not written speculatively.
  • go build ./..., go vet ./..., golangci-lint run ./..., go test ./..., and make race all pass locally on this branch (rebased onto current upstream main).
  • Backend has dedicated unit tests: internal/amneziawg (obfuscation generation/validation, protocol-shape derivation, version gating), internal/amneziawgnet (embedded device/netstack/forwarder/relay, real handshake + end-to-end SOCKS5-relay tests against a real xray-core binary), internal/xray (hot-diff TPROXY/SOCKS5 restart-forcing), internal/sub (client-config emission), and internal/web/service (Xray config injection for the AmneziaWG relay, cross-inbound AllowedIPs validation, Attach/Update address handling, settings normalization, port-conflict checks).
  • Frontend npm run lint, npm run typecheck, npm run build, and the full vitest suite all pass on this branch.

Screenshots / recordings

None attached — happy to add a screenshot of the inbound/client forms if useful for review.

Breaking changes

None. Adds a new protocol and new (nullable/defaulted) columns; no existing behavior changes.

Checklist

  • I tested the change locally and confirmed the described behavior.
  • I added or updated tests for the new behavior (when applicable).
  • go build ./... and the test suite pass locally.
  • For frontend changes: npm run lint, npm run typecheck, and npm run build pass.
  • I updated the Wiki / README / API docs if user-facing behavior changed. Added docs/content/docs/en/config/amneziawg.mdx and listed AmneziaWG in the protocol table on config/inbounds.mdx.
  • My commits follow the project's existing message style.
  • I have no unrelated changes mixed into this PR.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/6105 **Author:** [@kuzzrus](https://github.com/kuzzrus) **Created:** 7/25/2026 **Status:** ✅ Merged **Merged:** 8/24/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `upstream-pr/amneziawg` --- ### 📝 Commits (10+) - [`6117561`](https://github.com/MHSanaei/3x-ui/commit/6117561b95e764a3aa10b163c7ba3d67de6350af) feat(amneziawg): add native AmneziaWG protocol backend - [`474e594`](https://github.com/MHSanaei/3x-ui/commit/474e594a2cbd3d039d6511e61759c2717daf5dae) feat(amneziawg): add frontend support and fix a Go->Zod generator gap - [`e4ba75c`](https://github.com/MHSanaei/3x-ui/commit/e4ba75c288a3b467508e22e4f9b2948b6fadb829) feat(amneziawg): complete frontend parity for the Inbounds list page - [`9f1ed38`](https://github.com/MHSanaei/3x-ui/commit/9f1ed3830c22c508573ea4bd4ecb2d990fd5e204) docs(install): note that AmneziaWG kernel module install is still manual - [`88f10e0`](https://github.com/MHSanaei/3x-ui/commit/88f10e0dac937fc1725ee4542d15c7aca9536869) feat(amneziawg): add a button to randomize obfuscation parameters - [`06d7c65`](https://github.com/MHSanaei/3x-ui/commit/06d7c653e8d43494f6b8feb1d9089e619c71900d) feat(install): auto-install the AmneziaWG DKMS module + amneziawg-tools - [`addda09`](https://github.com/MHSanaei/3x-ui/commit/addda0946edc25589102e2f556ed5c81b5c72e10) fix(amneziawg): resolve all 3 real CI failures (typecheck/lint/codegen) - [`cdf0f0a`](https://github.com/MHSanaei/3x-ui/commit/cdf0f0a22ef37ddf9b16b8af28125a548a39fae3) feat(amneziawg): Phase 2a — IPv6 support + NDP proxy - [`e10c421`](https://github.com/MHSanaei/3x-ui/commit/e10c42167738787f22b373e645d591bd2cce9c93) fix(amneziawg): fill in IPv6 fields missed by the Phase 2a commit - [`ecfc0ca`](https://github.com/MHSanaei/3x-ui/commit/ecfc0caf231baa8d11cccc230719c076b99e6cb3) feat(amneziawg): Phase 2b — per-client port-forwarding ### 📊 Changes **146 files changed** (+15241 additions, -134 deletions) <details> <summary>View changed files</summary> 📝 `CLAUDE.md` (+8 -1) 📝 `docker-compose.yml` (+4 -0) 📝 `docs/architecture.md` (+1 -0) ➕ `docs/content/docs/en/config/amneziawg.mdx` (+177 -0) 📝 `docs/content/docs/en/config/inbounds.mdx` (+1 -0) 📝 `docs/content/docs/en/config/meta.json` (+1 -0) 📝 `docs/content/docs/en/reference/api/server.mdx` (+8 -1) 📝 `docs/content/docs/fa/reference/api/hosts.mdx` (+1 -1) 📝 `docs/content/docs/ru/reference/api/hosts.mdx` (+1 -1) 📝 `docs/content/docs/zh/reference/api/hosts.mdx` (+1 -1) 📝 `docs/public/openapi.json` (+342 -1) 📝 `frontend/public/openapi.json` (+342 -1) 📝 `frontend/src/generated/examples.ts` (+75 -0) 📝 `frontend/src/generated/schemas.ts` (+265 -1) 📝 `frontend/src/generated/types.ts` (+63 -0) 📝 `frontend/src/generated/zod.ts` (+67 -1) ➕ `frontend/src/lib/xray/amneziawg-obfuscation.ts` (+125 -0) 📝 `frontend/src/lib/xray/inbound-defaults.ts` (+44 -1) 📝 `frontend/src/lib/xray/inbound-form-adapter.ts` (+3 -0) 📝 `frontend/src/lib/xray/inbound-link.ts` (+195 -1) _...and 80 more files_ </details> ### 📄 Description ## Summary Adds native **AmneziaWG 3.1** protocol support as a new inbound type — a WireGuard fork with traffic obfuscation, popular for bypassing DPI. `amneziawg-go` runs embedded in the panel process over a userspace (gVisor) network stack — no kernel module, no DKMS, no host tooling at all. Decapsulated traffic is relayed into a stock Xray SOCKS5 inbound authenticated per peer, so Xray's own stats/sniffing/access-log/routing all work for AmneziaWG clients natively, with no protocol-specific plumbing on that side. See the **Update (2026-08-21)** section below for why this differs from the kernel-module design this PR originally shipped. ## Why AmneziaWG has no first-class support in 3x-ui today. This adds it as a fully managed protocol with the full **AmneziaWG 3.1** obfuscation parameter set: - junk-packet and padding params (`Jc`/`Jmin`/`Jmax`/`S1`-`S4`), magic headers (`H1`-`H4`), and signature packets (`I1`-`I5`); - the 3.x additions — `HeaderProtectionKey` (base64 32-byte, shared server↔client), `ContentPaddingAddition`, the handshake-timing randomization ranges (`RekeyAfterTime`/`RekeyTimeout`/`RejectAfterTime`/`KeepaliveTimeout`/`MaxHandshakeAttempts`), and the `RandomTrailers`/`DisableCookies` switches; - a **regenerate** button that produces a fully randomized, protocol-valid set per inbound (a static fingerprint defeats the point of obfuscation); plus native IPv6 with a per-peer source-address alias (distinct outbound identity per peer, no NAT66), per-client port-forwarding, and routing a client's traffic through Xray's own outbound chain via the existing Routing page (every AmneziaWG inbound's relay is already tagged with its own inbound tag, so it's selectable there with no new UI needed for that part). **Host requirements:** none beyond what the panel itself already needs — no kernel version floor, no DKMS, no `amneziawg-tools`/`awg-quick` package. Clients must run a 3.1-capable Amnezia app to use the 3.1-only fields (`HeaderProtectionKey`, `ContentPaddingAddition`, the timing/`RandomTrailers`/`DisableCookies` fields); blanking a 3.1-only field renders a config older clients still understand. ## Update (2026-08-21) — reworked from a kernel-module (DKMS + awg-quick) sidecar to an embedded, in-process architecture **This supersedes the architecture described in the Update (2026-08-16) section below** — that update's own "Go server config (`awg-quick`)" and "DKMS kernel module + root" mentions describe the design as it stood *before* this rewrite, not the code in this PR today. Rather than shelling out to `awg-quick`/`awg` against a DKMS-built kernel module (this fork's original design, and the one every earlier update in this PR body describes), the panel now embeds [`amneziawg-go`](https://github.com/amnezia-vpn/amneziawg-go) directly and terminates each tunnel over an in-process userspace (gVisor) network stack. A forwarder recovers each connection's real destination and relays it into a stock, unmodified Xray SOCKS5 inbound, authenticated as that peer's own email — so Xray's native per-user stats, access log, sniffing, and Routing-page rules all apply to AmneziaWG traffic for free, the same way they already do for every other protocol, with no AmneziaWG-specific code needed on that side. Motivation: the DKMS module structurally lagged the protocol (the 3.1 parameter set landed in the userspace `amneziawg-go`/`amneziawg-tools` line well before the kernel module + DKMS package caught up), and DKMS itself was this fork's single biggest source of installer fragility (kernel-version compatibility, Secure Boot rejecting the unsigned module outright, and package-repository reachability issues on some VPS providers). Moving the whole thing in-process removes that entire problem class. The real-network throughput tradeoff of a userspace stack vs. a kernel module was measured directly before committing to this (a real, substantial gap on a single saturating stream) and judged acceptable for this protocol's realistic usage pattern (many lower-throughput, latency-bound connections, not sustained bulk transfer) — noted here for reviewers who'd otherwise reasonably ask about it. Everything else this PR's `Why`/`Update` sections describe — the full 3.1 parameter set, IPv6 identity, per-client port-forwarding, install/i18n/docs — is unchanged in scope and behavior; only the underlying mechanism moved. ## Update (2026-08-16) — reworked from AWG 2.0 to AmneziaWG 3.1 The protocol surface was moved from the initial AWG 2.0 parameter set to **AmneziaWG 3.1**, matching the upstream amnezia-vpn tooling (`amneziawg-tools v3.1.20260812`, `amneziawg-go v3.1.20260814`). Concretely: - **New parameters** on both the stored inbound settings and every emitter: `I2`-`I5`, `HeaderProtectionKey`, `ContentPaddingAddition`, the five timing-randomization ranges, and the `RandomTrailers`/`DisableCookies` booleans (emitted as `Key = on`, verified against the real tools' config parser). - **Generation** fills a full-stealth set (header protection + padding + jittered timing windows that bracket WireGuard's own constants, with every reject window `>= 30s` above the rekey window by construction; `RandomTrailers`/`DisableCookies` on). Empty fields are omitted from the rendered config, so blanking one disables just that feature. - **Validation** requires a real base64 32-byte header-protection key, treats the range fields as uint32 `lo-hi`, cross-checks rekey-vs-reject (including against the WireGuard defaults when one side is blank), rejects control characters (a line-wrapped pasted key otherwise decoded to a valid key but split client configs), and canonicalizes range values on save. - **All four config emitters agree** key-by-key and in order — the rendered client-facing config (consumed by the Amnezia app, or `awg-quick` if an admin applies it directly), the Go client config behind `vpn://` links, and both frontend emitters — pinned by order-sensitive tests plus a schema-parity test tying the hand-written Zod schema to the generated `ServerSettings` key set. - **i18n**: 19 new keys across all 13 locales; the "2.0" branding dropped from the `S3`/`S4`/`I1` labels. - **Docs + `install.sh`** updated for the 3.1 parameters, the version/kernel requirements, and a sample client `.conf` that matches what the panel actually emits. **Real-tools validation (historical, describes this update's own testing at the time — see the 2026-08-21 update above for the architecture this now runs on):** amneziawg-tools `v3.1.20260812` was built from source and the panel's actual generated configs (server + client, including the fully randomized generator output and the `I1`-`I5` + booleans set) were run through the genuine parser: `awg-quick strip` accepts the full server config, and `awg setconf` accepts every key/value, reaching the netlink stage (the only step gated on the DKMS kernel module + root, which this PR's design no longer uses server-side). Negative tests confirm the parser rejects unknown keys and bad values, so "accepted" is meaningful. **Also in this update:** fixed the non-interactive install smoke test — it resolved the release version through the unauthenticated GitHub API (60 req/h per IP), and the two installs it runs could get the second call rate-limited on shared CI/CGNAT IPs, aborting the install. Version resolution now reads the `releases/latest` web redirect (no API quota), with the API only as a fallback. ## Update (2026-08-04) Since the last review pass, this branch picked up a batch of real bug fixes found while running this feature in production on a separate long-lived deployment. Summarizing here since the change touches several files across a few different concerns: **Hot-apply reliability (`internal/xray/hot_diff.go`)** — two cases where Xray's gRPC `AlterInbound` reports success but doesn't actually work, confirmed against a real running instance, not just reasoned about: - A TPROXY inbound (this PR's own Xray egress bridge) added via gRPC never actually binds a working listener, even though the call succeeds. - A password-auth SOCKS5 inbound with named accounts can silently drop an account on a gRPC remove+add, even when the settings JSON on disk is correct. Both cases now force a full process restart instead of a hot add/swap, mirroring the existing REALITY-inbound special case just above them in the same function. **AllowedIPs correctness across inbounds/protocols (`internal/web/service/client_*.go`)** — a cluster of related bugs, all versions of the same root cause: uniqueness/validity of a tunnel client's address was only ever checked against its *own* inbound's client list. - Two clients on *different* WireGuard/AmneziaWG inbounds could be handed (or could keep) the exact same address — collision checking is now cross-inbound. - Re-attaching a client to a tunnel inbound (after detaching from all of them) could resurrect a stale address instead of allocating a genuinely free one. - An address inherited from one inbound could get silently carried over to a *different* inbound whose configured subnet doesn't actually contain it, producing a peer that can never connect — this is now checked per target inbound, with a fresh allocation as the fallback. - The same broadcast issue existed on the far more common plain-edit path (`Update`, not just `Attach`): a client attached to both WireGuard and AmneziaWG saving one shared AllowedIPs value could silently overwrite one protocol's address with the other's. Fixed at the root (`model.Client` gained an optional per-inbound override), and the edit form now shows two separate, correctly-labeled fields when both protocols are attached instead of one ambiguous shared one. **WireGuard gets its own configurable subnet field**, mirroring the AmneziaWG inbound's existing one — previously WireGuard always inferred its subnet from existing clients, falling back to a hardcoded `10.0.0.0/24` with no way to override it. Existing inbounds that never set this are unaffected (same inference fallback as before). **Resync trigger fix** — editing an AmneziaWG peer in a way that changes whether the inbound now qualifies for the Xray egress bridge (its first peer added, its last peer removed) now correctly flags Xray for a resync. Previously the bridge could silently fail to appear/disappear until a full panel restart. **Small fix**: the AmneziaWG client config download button was missing from the subscription page. All of the above ships with new unit tests (Go: `internal/xray`, `internal/web/service`; frontend: two new pure-function test files) and passes the full existing suite on both stacks. ## Type of change - [x] New feature - [x] Bug fix ## Areas affected - [x] Frontend (UI / panel pages) - [x] Backend (API endpoints, login, settings) - [x] Xray config generation - [x] Subscription (share links / Clash / JSON) - [x] Statistics / traffic counters - [x] Database / migrations - [x] Install / upgrade script - [ ] Docker image - [ ] Multi-node (sub-nodes) - [ ] Telegram bot ## How was this tested? - Live-tested on a real deployment: inbound created through the panel, real AmneziaWG client connected, handshake completed, traffic counted, IPv6 per-peer identity, per-client port-forwarding, and routing a client through an Xray outbound via the Routing page all verified working end-to-end. - The 3.1 rework was validated against **amneziawg-tools v3.1.20260812 built from source**: the panel's actual generated client configs parse cleanly (every 3.1 key/value accepted, unknown keys and bad values rejected). - The non-interactive install smoke test (`deploy/test/smoke-noninteractive.sh`) passes locally after the version-resolution fix. - The hot-apply fixes and the cross-inbound AllowedIPs fixes were each found as real bugs on a running deployment first, then reduced to a fix + regression test — not written speculatively. - `go build ./...`, `go vet ./...`, `golangci-lint run ./...`, `go test ./...`, and `make race` all pass locally on this branch (rebased onto current upstream `main`). - Backend has dedicated unit tests: `internal/amneziawg` (obfuscation generation/validation, protocol-shape derivation, version gating), `internal/amneziawgnet` (embedded device/netstack/forwarder/relay, real handshake + end-to-end SOCKS5-relay tests against a real `xray-core` binary), `internal/xray` (hot-diff TPROXY/SOCKS5 restart-forcing), `internal/sub` (client-config emission), and `internal/web/service` (Xray config injection for the AmneziaWG relay, cross-inbound AllowedIPs validation, Attach/Update address handling, settings normalization, port-conflict checks). - Frontend `npm run lint`, `npm run typecheck`, `npm run build`, and the full `vitest` suite all pass on this branch. ## Screenshots / recordings _None attached — happy to add a screenshot of the inbound/client forms if useful for review._ ## Breaking changes None. Adds a new protocol and new (nullable/defaulted) columns; no existing behavior changes. ## Checklist - [x] I tested the change locally and confirmed the described behavior. - [x] I added or updated tests for the new behavior (when applicable). - [x] `go build ./...` and the test suite pass locally. - [x] For frontend changes: `npm run lint`, `npm run typecheck`, and `npm run build` pass. - [x] I updated the Wiki / README / API docs if user-facing behavior changed. Added `docs/content/docs/en/config/amneziawg.mdx` and listed AmneziaWG in the protocol table on `config/inbounds.mdx`. - [x] My commits follow the project's existing message style. - [x] I have no unrelated changes mixed into this PR. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:06:14 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#6082
No description provided.