mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 19:11:53 +07:00
[PR #6105] [MERGED] feat(amneziawg): add native AmneziaWG protocol support #6082
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#6082
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 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+)
6117561feat(amneziawg): add native AmneziaWG protocol backend474e594feat(amneziawg): add frontend support and fix a Go->Zod generator gape4ba75cfeat(amneziawg): complete frontend parity for the Inbounds list page9f1ed38docs(install): note that AmneziaWG kernel module install is still manual88f10e0feat(amneziawg): add a button to randomize obfuscation parameters06d7c65feat(install): auto-install the AmneziaWG DKMS module + amneziawg-toolsaddda09fix(amneziawg): resolve all 3 real CI failures (typecheck/lint/codegen)cdf0f0afeat(amneziawg): Phase 2a — IPv6 support + NDP proxye10c421fix(amneziawg): fill in IPv6 fields missed by the Phase 2a commitecfc0cafeat(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-goruns 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:
Jc/Jmin/Jmax/S1-S4), magic headers (H1-H4), and signature packets (I1-I5);HeaderProtectionKey(base64 32-byte, shared server↔client),ContentPaddingAddition, the handshake-timing randomization ranges (RekeyAfterTime/RekeyTimeout/RejectAfterTime/KeepaliveTimeout/MaxHandshakeAttempts), and theRandomTrailers/DisableCookiesswitches;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-quickpackage. Clients must run a 3.1-capable Amnezia app to use the 3.1-only fields (HeaderProtectionKey,ContentPaddingAddition, the timing/RandomTrailers/DisableCookiesfields); 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 toawg-quick/awgagainst a DKMS-built kernel module (this fork's original design, and the one every earlier update in this PR body describes), the panel now embedsamneziawg-godirectly 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-toolsline 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/Updatesections 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:I2-I5,HeaderProtectionKey,ContentPaddingAddition, the five timing-randomization ranges, and theRandomTrailers/DisableCookiesbooleans (emitted asKey = on, verified against the real tools' config parser).>= 30sabove the rekey window by construction;RandomTrailers/DisableCookieson). Empty fields are omitted from the rendered config, so blanking one disables just that feature.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.awg-quickif an admin applies it directly), the Go client config behindvpn://links, and both frontend emitters — pinned by order-sensitive tests plus a schema-parity test tying the hand-written Zod schema to the generatedServerSettingskey set.S3/S4/I1labels.install.shupdated for the 3.1 parameters, the version/kernel requirements, and a sample client.confthat 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.20260812was built from source and the panel's actual generated configs (server + client, including the fully randomized generator output and theI1-I5+ booleans set) were run through the genuine parser:awg-quick stripaccepts the full server config, andawg setconfaccepts 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/latestweb 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 gRPCAlterInboundreports success but doesn't actually work, confirmed against a real running instance, not just reasoned about: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.Update, not justAttach): 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.Clientgained 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/24with 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
Areas affected
How was this tested?
deploy/test/smoke-noninteractive.sh) passes locally after the version-resolution fix.go build ./...,go vet ./...,golangci-lint run ./...,go test ./..., andmake raceall pass locally on this branch (rebased onto current upstreammain).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 realxray-corebinary),internal/xray(hot-diff TPROXY/SOCKS5 restart-forcing),internal/sub(client-config emission), andinternal/web/service(Xray config injection for the AmneziaWG relay, cross-inbound AllowedIPs validation, Attach/Update address handling, settings normalization, port-conflict checks).npm run lint,npm run typecheck,npm run build, and the fullvitestsuite 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
go build ./...and the test suite pass locally.npm run lint,npm run typecheck, andnpm run buildpass.docs/content/docs/en/config/amneziawg.mdxand listed AmneziaWG in the protocol table onconfig/inbounds.mdx.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.