mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 19:11:53 +07:00
[PR #6272] [MERGED] feat(pia): add PIA login-and-add WireGuard outbounds #6208
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#6208
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/6272
Author: @Masterain98
Created: 8/20/2026
Status: ✅ Merged
Merged: 8/22/2026
Merged by: @MHSanaei
Base:
main← Head:pr/pia-wireguard-outbounds📝 Commits (2)
c837bc8feat(pia): add login-and-add WireGuard outbounds (#2)9b17759fix(pia): keep PIA outbounds identifiable after the editor strips hostname📊 Changes
73 files changed (+4095 additions, -31 deletions)
View changed files
📝
CLAUDE.md(+1 -0)📝
docs/architecture.md(+4 -3)📝
docs/content/docs/en/operations/outbounds-routing.mdx(+21 -4)📝
docs/content/docs/en/reference/api/xray-settings.mdx(+11 -3)📝
docs/content/docs/fa/operations/outbounds-routing.mdx(+20 -2)📝
docs/content/docs/ru/operations/outbounds-routing.mdx(+21 -2)📝
docs/content/docs/zh/operations/outbounds-routing.mdx(+16 -2)📝
docs/public/openapi.json(+42 -1)📝
frontend/public/openapi.json(+42 -1)📝
frontend/src/pages/api-docs/endpoints.ts(+38 -1)📝
frontend/src/pages/xray/XrayPage.tsx(+10 -1)📝
frontend/src/pages/xray/outbounds/OutboundsTab.tsx(+8 -0)➕
frontend/src/pages/xray/overrides/PiaModal.css(+53 -0)➕
frontend/src/pages/xray/overrides/PiaModal.tsx(+468 -0)📝
frontend/src/pages/xray/overrides/index.ts(+1 -0)📝
frontend/src/test/outbounds-loopback-index.test.tsx(+2 -0)➕
frontend/src/test/pia-modal.test.tsx(+391 -0)📝
internal/crypto/nodetoken/nodetoken.go(+30 -10)📝
internal/crypto/nodetoken/nodetoken_test.go(+17 -0)➕
internal/pia/auth.go(+84 -0)...and 53 more files
📄 Description
Summary
Add a Private Internet Access (PIA) WireGuard integration on Xray → Outbounds → More → PIA: sign in with a PIA username and password, pick a country/region/server from the signature-verified server list, and append a WireGuard outbound to the Xray template. Operators can add several servers (one outbound per hostname) and Reset a row in place.
The stored PIA API token follows the panel’s existing
NODE_TOKEN_ENCRYPTIONsetting (off/migration/required). The password is never stored.Why
WARP and Nord already have a panel modal that provisions an outbound. PIA did not: operators had to mint a WireGuard peer by hand. The frontend cannot invent that peer — PIA only issues one through per-server
/addKeyafter a username/password login — so the panel needs a protocol client plus a Nord-shaped UI.Node API tokens already encrypt at rest when
NODE_TOKEN_ENCRYPTIONis on. PIA’s token is the same class of long-lived panel secret; it now uses that codec with AADsettings/pia_tokenso ciphertext cannot be swapped with a node-token blob. Defaultoffkeeps plaintext JSON, matching Nord. WireGuardsecretKeyin the Xray template stays plaintext, same as Nord/WARP.Type of change
Areas affected
How was this tested?
UI (manual): Xray → Outbounds → More → PIA
pia-<region>-<server>WireGuard outbound appears in the list and in the “Added servers” table. The modal stays open.{reset}hint is shown.pia-*outbounds stay. Delete unused ones from the Outbounds tab so routing cleanup still runs.NODE_TOKEN_ENCRYPTION=off(default): thepiasetting JSON still contains the raw token.NODE_TOKEN_ENCRYPTION=required(and a key): after login thepiasetting token isenc:v1:…; Add outbound still works. Turning encryption off afterwards makes Add/Reset fail closed until the operator signs in again.API:
POST /panel/api/xray/pia/:actionregusername,password{ username, accountHint }— token never returneddatacountriesserverscountryCodeaddKeyhostnamedelAutomated (local):
go test ./internal/pia/ ./internal/crypto/nodetoken/ ./internal/web/service/integration/ ./internal/xray/internal/pia: auth, RSA signature on the server list,/addKeyTLS + JSON fixturesinternal/web/service/integration: login hides the token fromdata; ModeOff plaintext; ModeRequiredenc:v1at rest; AddKey decrypts; leftover ciphertext is rejected when encryption is off; plaintext migrates on the next read after encryption is enabled; AADsettings/pia_tokendoes not decrypt asnodes/api_token/{id}npx vitest run src/test/pia-modal.test.tsx src/test/i18n-dead-keys.test.ts src/test/outbounds-loopback-index.test.tsxgolangci-lint run ./internal/pia/... ./internal/crypto/nodetoken/... ./internal/web/service/integration/... ./internal/xray/CI should still run the full
make verifygate.Screenshots / recordings
For duplicated outbounds:

Breaking changes
None for existing installs. Additive only:
POST /panel/api/xray/pia/:actionand apiasettings key. No schema migration. Logout does not delete outbounds.NODE_TOKEN_ENCRYPTIONis unchanged as an env var. When it isoff(default), PIA storage matches Nord (plaintext JSON). When it ismigration/required, only the PIA API token in that setting is encrypted; WireGuard keys in the Xray template are not.Checklist
go build ./...and the test suite pass locally.npm run lint,npm run typecheck, andnpm run buildpass.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.