[PR #6272] [MERGED] feat(pia): add PIA login-and-add WireGuard outbounds #6208

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

📋 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)

  • c837bc8 feat(pia): add login-and-add WireGuard outbounds (#2)
  • 9b17759 fix(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_ENCRYPTION setting (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 /addKey after 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_ENCRYPTION is on. PIA’s token is the same class of long-lived panel secret; it now uses that codec with AAD settings/pia_token so ciphertext cannot be swapped with a node-token blob. Default off keeps plaintext JSON, matching Nord. WireGuard secretKey in the Xray template stays plaintext, same as Nord/WARP.

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Documentation
  • Tests only
  • Build / CI / tooling
  • Other

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?

UI (manual): Xray → Outbounds → More → PIA

  1. Sign in with a PIA username and password. The password field clears; the account hint is shown, not the token.
  2. Pick a country (and optional region), pick a server, Add outbound. A pia-<region>-<server> WireGuard outbound appears in the list and in the “Added servers” table. The modal stays open.
  3. Add a second, different hostname. Both outbounds remain.
  4. Select a hostname that is already added: Add outbound is disabled and the {reset} hint is shown.
  5. Reset on a row keeps the same tag and replaces the WireGuard keys in place.
  6. Logout clears the stored token only; existing pia-* outbounds stay. Delete unused ones from the Outbounds tab so routing cleanup still runs.
  7. With NODE_TOKEN_ENCRYPTION=off (default): the pia setting JSON still contains the raw token.
  8. With NODE_TOKEN_ENCRYPTION=required (and a key): after login the pia setting token is enc: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/:action

action body result
reg username, password { username, accountHint } — token never returned
data — same account view, or empty when logged out
countries — signed server-list country codes
servers countryCode regions + WireGuard servers
addKey hostname tag, hostname, secretKey, address, publicKey, endpoint
del — clears the stored token only

Automated (local):

  • go test ./internal/pia/ ./internal/crypto/nodetoken/ ./internal/web/service/integration/ ./internal/xray/
  • Protocol coverage in internal/pia: auth, RSA signature on the server list, /addKey TLS + JSON fixtures
  • Panel coverage in internal/web/service/integration: login hides the token from data; ModeOff plaintext; ModeRequired enc:v1 at rest; AddKey decrypts; leftover ciphertext is rejected when encryption is off; plaintext migrates on the next read after encryption is enabled; AAD settings/pia_token does not decrypt as nodes/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.tsx
  • golangci-lint run ./internal/pia/... ./internal/crypto/nodetoken/... ./internal/web/service/integration/... ./internal/xray/

CI should still run the full make verify gate.

Screenshots / recordings

image image image image

For duplicated outbounds:
image

Breaking changes

None for existing installs. Additive only: POST /panel/api/xray/pia/:action and a pia settings key. No schema migration. Logout does not delete outbounds.

NODE_TOKEN_ENCRYPTION is unchanged as an env var. When it is off (default), PIA storage matches Nord (plaintext JSON). When it is migration/required, only the PIA API token in that setting is encrypted; WireGuard keys in the Xray template are not.

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.
  • 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/6272 **Author:** [@Masterain98](https://github.com/Masterain98) **Created:** 8/20/2026 **Status:** ✅ Merged **Merged:** 8/22/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `pr/pia-wireguard-outbounds` --- ### 📝 Commits (2) - [`c837bc8`](https://github.com/MHSanaei/3x-ui/commit/c837bc8bfcb2846c2f092352930e18ed04f3b4c2) feat(pia): add login-and-add WireGuard outbounds (#2) - [`9b17759`](https://github.com/MHSanaei/3x-ui/commit/9b1775949bc0615f4ffff1a18fdff63906bcae4e) fix(pia): keep PIA outbounds identifiable after the editor strips hostname ### 📊 Changes **73 files changed** (+4095 additions, -31 deletions) <details> <summary>View changed files</summary> 📝 `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_ </details> ### 📄 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_ENCRYPTION` setting (`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 `/addKey` after 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_ENCRYPTION` is on. PIA’s token is the same class of long-lived panel secret; it now uses that codec with AAD `settings/pia_token` so ciphertext cannot be swapped with a node-token blob. Default `off` keeps plaintext JSON, matching Nord. WireGuard `secretKey` in the Xray template stays plaintext, same as Nord/WARP. ## Type of change - [ ] Bug fix - [x] New feature - [ ] Refactoring (no behavior change) - [x] Documentation - [ ] Tests only - [ ] Build / CI / tooling - [ ] Other ## Areas affected - [x] Frontend (UI / panel pages) - [x] Backend (API endpoints, login, settings) - [x] 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? **UI (manual):** Xray → Outbounds → More → PIA 1. Sign in with a PIA username and password. The password field clears; the account hint is shown, not the token. 2. Pick a country (and optional region), pick a server, **Add outbound**. A `pia-<region>-<server>` WireGuard outbound appears in the list and in the “Added servers” table. The modal stays open. 3. Add a second, different hostname. Both outbounds remain. 4. Select a hostname that is already added: **Add outbound** is disabled and the `{reset}` hint is shown. 5. **Reset** on a row keeps the same tag and replaces the WireGuard keys in place. 6. **Logout** clears the stored token only; existing `pia-*` outbounds stay. Delete unused ones from the Outbounds tab so routing cleanup still runs. 7. With `NODE_TOKEN_ENCRYPTION=off` (default): the `pia` setting JSON still contains the raw token. 8. With `NODE_TOKEN_ENCRYPTION=required` (and a key): after login the `pia` setting token is `enc: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/:action` | action | body | result | | --- | --- | --- | | `reg` | `username`, `password` | `{ username, accountHint }` — token never returned | | `data` | — | same account view, or empty when logged out | | `countries` | — | signed server-list country codes | | `servers` | `countryCode` | regions + WireGuard servers | | `addKey` | `hostname` | tag, hostname, secretKey, address, publicKey, endpoint | | `del` | — | clears the stored token only | **Automated (local):** - `go test ./internal/pia/ ./internal/crypto/nodetoken/ ./internal/web/service/integration/ ./internal/xray/` - Protocol coverage in `internal/pia`: auth, RSA signature on the server list, `/addKey` TLS + JSON fixtures - Panel coverage in `internal/web/service/integration`: login hides the token from `data`; ModeOff plaintext; ModeRequired `enc:v1` at rest; AddKey decrypts; leftover ciphertext is rejected when encryption is off; plaintext migrates on the next read after encryption is enabled; AAD `settings/pia_token` does not decrypt as `nodes/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.tsx` - `golangci-lint run ./internal/pia/... ./internal/crypto/nodetoken/... ./internal/web/service/integration/... ./internal/xray/` CI should still run the full `make verify` gate. ## Screenshots / recordings <img width="807" height="374" alt="image" src="https://github.com/user-attachments/assets/d6d89c6a-3f67-448c-893f-3ce565199a93" /> <img width="809" height="390" alt="image" src="https://github.com/user-attachments/assets/7d050d02-31ba-4158-a488-7c9eee4631c8" /> <img width="836" height="764" alt="image" src="https://github.com/user-attachments/assets/287c05fd-551c-48e0-a998-d7de2b2015ce" /> <img width="1914" height="735" alt="image" src="https://github.com/user-attachments/assets/c0a8fa8f-b19d-40af-8710-a5c5cf9f0c26" /> For duplicated outbounds: <img width="757" height="549" alt="image" src="https://github.com/user-attachments/assets/fb784d44-319a-4c22-a25e-05fda1906e40" /> ## Breaking changes None for existing installs. Additive only: `POST /panel/api/xray/pia/:action` and a `pia` settings key. No schema migration. Logout does not delete outbounds. `NODE_TOKEN_ENCRYPTION` is unchanged as an env var. When it is `off` (default), PIA storage matches Nord (plaintext JSON). When it is `migration`/`required`, only the PIA API token in that setting is encrypted; WireGuard keys in the Xray template are not. ## 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. - [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:07:06 +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#6208
No description provided.