Repository navigation
Expand file tree
/
Copy pathopenapi.yaml
More file actions
1877 lines (1814 loc) · 75.1 KB
/
Copy pathopenapi.yaml
File metadata and controls
1877 lines (1814 loc) · 75.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
openapi: 3.0.3
info:
title: WGPanel API
description: |
WGPanel manages WireGuard nodes and peer ("account") provisioning behind a
separate Telegram sales bot. This panel deliberately has **no concept of
payments, pricing, or plans** — the bot owns all of that and talks to this
API using a scoped, HMAC-signed API key. Admin/operator users manage the
same resources through the same endpoints using a JWT session instead.
## Authentication
Every endpoint under `/api/v1/*` (except `POST /api/v1/auth/login`,
`POST /api/v1/auth/refresh`, and `POST /api/v1/nodes/join`) requires
**one** of:
- **Admin session** — `Authorization: Bearer <access_token>` from
`POST /api/v1/auth/login`. Access tokens are short-lived (15 minutes);
exchange the refresh token via `POST /api/v1/auth/refresh` before it
expires. Admin sessions are additionally subject to role checks
(`support` < `operator` < `super_admin`) documented per-operation below.
- **Bot/reseller API key** — three headers together:
`X-API-Key` (the key ID), `X-Timestamp` (unix seconds), and
`X-Signature` (hex HMAC-SHA256). The signed payload is exactly:
```
{METHOD}\n{URL_PATH}\n{TIMESTAMP}\n{RAW_BODY}
```
`METHOD` is the uppercase HTTP verb, `URL_PATH` is the request path
with no query string, `TIMESTAMP` is the literal `X-Timestamp` header
value (not re-serialized), and `RAW_BODY` is the exact request body
bytes (empty string for bodyless requests). Compute the HMAC with the
API key's secret (returned **once**, at creation or rotation time) and
hex-encode it. Requests outside a ±5 minute timestamp window are
rejected regardless of signature validity. API keys carry their own
`permissions` (a subset of `read`/`create`/`update`/`suspend`/`delete`)
and `node_groups` scoping (empty = unrestricted).
These two mechanisms are mutually exclusive per request — the server
checks for a non-empty `Authorization` header first and, if absent, falls
back to the three `X-*` headers.
## Error format
Every error response, from every endpoint, uses exactly this envelope:
```json
{ "error": { "code": "account_not_found", "message": "no account with that id" } }
```
`code` is a stable machine-readable string (see the shared
`ErrorEnvelope` schema and per-operation `4xx`/`5xx` responses below);
`message` is a human-readable string that MAY change wording over time —
integrate against `code`, not `message`.
## Two listeners
This spec documents two distinct HTTP servers this backend runs:
1. **Main API** (`HTTP_PORT`, default `8080`) — everything under
`/api/v1/*`, `/healthz`, and `/internal/*`. This is what admins, the
Telegram bot, and `POST /api/v1/nodes/join` (install-node.sh) talk to.
2. **Node agent listener** (`NODE_AGENT_PORT`, default `48443`) — `/agent/register`
and `/agent/heartbeat` only, served over mTLS by this project's internal
CA. `/agent/register` needs no client certificate (the one-time join
token IS the credential); `/agent/heartbeat` requires a client
certificate issued by a prior `/agent/register` call. OpenAPI 3.0 has
no first-class way to express "TLS client certificate required"
as a security scheme, so this requirement is called out in each
operation's description instead — it is enforced at the TLS layer,
before the handler ever runs.
version: "1.0.0"
contact:
name: WGPanel
servers:
- url: /
description: >-
Main API host. All paths below are absolute (e.g. /api/v1/nodes,
/healthz, /internal/admins), matching the real Go net/http mux exactly -
there is no shared path prefix across every route.
- url: https://node-agent.internal:48443
description: >-
Node agent mTLS listener (NODE_AGENT_PORT). Separate TLS listener, separate
trust root (this project's internal CA) - not reachable through the main
API's port or through Caddy's public reverse proxy. Only the /agent/*
operations below use this server (see their per-operation `servers`
override).
tags:
- name: Auth
description: Admin login/session management.
- name: Nodes
description: WireGuard server (node) directory and lifecycle.
- name: Accounts
description: WireGuard peer provisioning and lifecycle.
- name: Subscription
description: >-
Unauthenticated capability-URL surface for client apps: the per-account
subscription token in the path is the credential. Serves the account's
current config with steering-based node selection.
- name: API Keys
description: Bot/reseller credentials for the HMAC-signed integration surface. super_admin only.
- name: Admin Users
description: Panel operator accounts and roles. super_admin only.
- name: Audit Log
description: Append-only record of every mutating action. super_admin only.
- name: Settings
description: Panel-wide configuration and defaults. Readable by any admin, editable by super_admin only.
- name: Backup
description: >-
Whole-panel backup & restore as a single JSON file. super_admin only, both
directions audit-logged. The file contains every panel secret except
deploy/.env - treat it like the database itself.
- name: Health
description: Liveness/readiness probes.
- name: Node Agent
description: >-
Endpoints served on the separate mTLS listener (NODE_AGENT_PORT), called by
cmd/agent running on each WireGuard node - never called by the admin panel
or the Telegram bot directly.
paths:
/healthz:
get:
tags: [Health]
summary: Public liveness probe
security: []
responses:
"200":
description: Process is up (does not check DB/Redis - see /internal/healthz for that).
content:
application/json:
schema:
type: object
properties:
status: { type: string, example: ok }
/internal/healthz:
get:
tags: [Health]
summary: Readiness probe (DB + Redis reachability)
description: >-
Gated by `X-Internal-Token` (must equal the `INTERNAL_API_TOKEN` env var),
not by admin/API-key auth. Not reachable from the public internet in the
reference deployment (Caddy doesn't proxy `/internal/*`; Docker publishes
the API port on `127.0.0.1` only) - but the token is the actual security
boundary, since sibling containers on the same network can still reach it.
security:
- InternalToken: []
responses:
"200":
description: Database and Redis are both reachable.
content:
application/json:
schema:
type: object
properties:
status: { type: string, example: ok }
"503":
description: Database or Redis unreachable.
content:
application/json:
schema: { $ref: "#/components/schemas/ErrorEnvelope" }
/internal/admins:
post:
tags: [Admin Users]
summary: Create the first super_admin (CLI bootstrap only)
description: >-
Used by the `wgpanel create-admin` CLI command during installation, not
by the frontend. Gated by `X-Internal-Token`. Unlike
`POST /api/v1/admins`, this endpoint defaults role to `super_admin` and
does not validate the role against an allow-list - it exists purely to
create the very first operator before any admin session exists.
security:
- InternalToken: []
requestBody:
required: true
content:
application/json:
schema:
type: object
required: [username, password]
properties:
username: { type: string }
password: { type: string }
role: { type: string, default: super_admin }
responses:
"201":
description: Admin created.
content:
application/json:
schema: { $ref: "#/components/schemas/AdminCreateResponse" }
"400": { $ref: "#/components/responses/BadRequest" }
"409":
description: Username already taken.
content:
application/json:
schema: { $ref: "#/components/schemas/ErrorEnvelope" }
"500": { $ref: "#/components/responses/InternalError" }
/internal/nodes/bootstrap-self:
post:
tags: [Nodes]
summary: Create a node and generate its join token in one call (install.sh only)
description: >-
Used by `install.sh` to self-register the panel's own server as its
first WireGuard node (docs/STORY-09-multi-node-accounts.md), combining
`POST /api/v1/nodes` + `POST /api/v1/nodes/{id}/join-token` into one
install-time convenience call. Gated by `X-Internal-Token`, same trust
tier as `/internal/admins`. The resulting node behaves identically to
one created through the admin panel - this is not a distinct node type.
security:
- InternalToken: []
requestBody:
required: true
content:
application/json:
schema: { $ref: "#/components/schemas/CreateNodeRequest" }
responses:
"201":
description: Node created and a join token generated for it.
content:
application/json:
schema:
type: object
properties:
node_id: { type: string, format: uuid }
token: { type: string }
expires_at: { type: string, format: date-time }
"400": { $ref: "#/components/responses/BadRequest" }
"409":
description: A node with this name already exists.
content:
application/json:
schema: { $ref: "#/components/schemas/ErrorEnvelope" }
"500": { $ref: "#/components/responses/InternalError" }
/api/v1/auth/login:
post:
tags: [Auth]
summary: Log in with username/password
security: []
requestBody:
required: true
content:
application/json:
schema:
type: object
required: [username, password]
properties:
username: { type: string }
password: { type: string, format: password }
responses:
"200":
description: Authenticated.
content:
application/json:
schema:
type: object
properties:
access_token: { type: string, description: "JWT, 15 minute TTL" }
refresh_token: { type: string, description: "Redis-backed, 7 day TTL" }
expires_in_seconds: { type: integer, example: 900 }
"400": { $ref: "#/components/responses/BadRequest" }
"401":
description: Invalid username or password (same response for both cases, to avoid leaking which one was wrong).
content:
application/json:
schema: { $ref: "#/components/schemas/ErrorEnvelope" }
"500": { $ref: "#/components/responses/InternalError" }
/api/v1/auth/refresh:
post:
tags: [Auth]
summary: Exchange a refresh token for a new access token
description: >-
Does NOT rotate the refresh token - the same refresh token remains valid
and reusable until its own 7-day TTL expires. A rotating-refresh-token
design was deliberately deferred (see docs/STORY-06).
security: []
requestBody:
required: true
content:
application/json:
schema:
type: object
required: [refresh_token]
properties:
refresh_token: { type: string }
responses:
"200":
description: New access token issued.
content:
application/json:
schema:
type: object
properties:
access_token: { type: string }
expires_in_seconds: { type: integer, example: 900 }
"400": { $ref: "#/components/responses/BadRequest" }
"401":
description: Refresh token is invalid, expired, or its admin no longer exists.
content:
application/json:
schema: { $ref: "#/components/schemas/ErrorEnvelope" }
"500": { $ref: "#/components/responses/InternalError" }
/api/v1/nodes/join:
post:
tags: [Nodes]
summary: Redeem a join token for a plain node record (used by install-node.sh)
description: >-
Unauthenticated by admin/API-key standards - the one-time join token
itself is the credential. Distinct from `/agent/register` on the mTLS
listener: this returns a plain `Node` JSON object, not a signed
certificate. install-node.sh calls this to confirm the token is valid
before handing off to cmd/agent, which then calls `/agent/register`
for its actual mTLS identity.
security: []
requestBody:
required: true
content:
application/json:
schema:
type: object
required: [token]
properties:
token: { type: string }
responses:
"200":
description: Token redeemed; node's registration is now marked complete.
content:
application/json:
schema: { $ref: "#/components/schemas/Node" }
"400": { $ref: "#/components/responses/BadRequest" }
"401":
description: Join token is invalid, expired, or already used.
content:
application/json:
schema: { $ref: "#/components/schemas/ErrorEnvelope" }
"500": { $ref: "#/components/responses/InternalError" }
/api/v1/nodes:
post:
tags: [Nodes]
summary: Register a new node
description: Requires an admin session with role >= `operator`.
security:
- BearerAuth: []
requestBody:
required: true
content:
application/json:
schema: { $ref: "#/components/schemas/CreateNodeRequest" }
responses:
"201":
description: Node created (status starts as `pending` until a real agent registers against it).
content:
application/json:
schema: { $ref: "#/components/schemas/Node" }
"400": { $ref: "#/components/responses/BadRequest" }
"401": { $ref: "#/components/responses/Unauthorized" }
"403": { $ref: "#/components/responses/Forbidden" }
"409":
description: A node with this name already exists.
content:
application/json:
schema: { $ref: "#/components/schemas/ErrorEnvelope" }
"500": { $ref: "#/components/responses/InternalError" }
get:
tags: [Nodes]
summary: List nodes
description: >-
Admin session (any role) or API key with `read` permission. API-key
callers only see nodes in their key's `node_groups` (empty node_groups
on the key = unrestricted, sees all).
security:
- BearerAuth: []
- ApiKeyAuth: []
responses:
"200":
description: OK
content:
application/json:
schema:
type: object
properties:
nodes:
type: array
items: { $ref: "#/components/schemas/Node" }
"401": { $ref: "#/components/responses/Unauthorized" }
"500": { $ref: "#/components/responses/InternalError" }
/api/v1/nodes/{id}:
parameters:
- name: id
in: path
required: true
schema: { type: string, format: uuid }
get:
tags: [Nodes]
summary: Get a node by id
description: 404 if the node exists but is outside an API-key caller's node_groups scope (not 403 - avoids confirming the node's existence to a caller who shouldn't see it).
security:
- BearerAuth: []
- ApiKeyAuth: []
responses:
"200":
description: OK
content:
application/json:
schema: { $ref: "#/components/schemas/Node" }
"401": { $ref: "#/components/responses/Unauthorized" }
"404": { $ref: "#/components/responses/NotFound" }
"500": { $ref: "#/components/responses/InternalError" }
patch:
tags: [Nodes]
summary: Update mutable node fields
description: >-
Admin session with role >= `operator`. All fields optional; only provided
fields change. `wg_subnet` is deliberately not editable (peers may already
be allocated from it). `region: ""` explicitly clears the steering label.
security:
- BearerAuth: []
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
name: { type: string }
node_group: { type: string }
region: { type: string }
public_endpoint: { type: string }
capacity_max_peers: { type: integer, minimum: 1 }
responses:
"200":
description: Updated node.
content:
application/json:
schema: { $ref: "#/components/schemas/Node" }
"400": { $ref: "#/components/responses/BadRequest" }
"401": { $ref: "#/components/responses/Unauthorized" }
"403": { $ref: "#/components/responses/Forbidden" }
"404": { $ref: "#/components/responses/NotFound" }
"409":
description: "`node_name_taken`"
content:
application/json:
schema: { $ref: "#/components/schemas/ErrorEnvelope" }
"500": { $ref: "#/components/responses/InternalError" }
/api/v1/nodes/{id}/join-token:
post:
tags: [Nodes]
summary: Generate a one-time join token for a node
description: >-
Requires an admin session with role = `super_admin` (the highest-privilege
node-management action, since a join token lets any holder register as
that node's trusted agent). TTL is `NODE_AGENT_JOIN_TOKEN_TTL_MIN`
(default 30 minutes).
parameters:
- name: id
in: path
required: true
schema: { type: string, format: uuid }
security:
- BearerAuth: []
responses:
"201":
description: Token generated.
content:
application/json:
schema:
type: object
properties:
token: { type: string }
expires_at: { type: string, format: date-time, nullable: true }
unlimited: { type: boolean }
panel_addr:
type: string
nullable: true
description: >-
The exact host:port to give install-node.sh as the control-plane
address: the panel domain (falling back to the Host this request
was made on, for IP-only deployments) + NODE_AGENT_PORT. This is
NOT the panel's web/HTTPS port.
example: panel.example.com:48443
"401": { $ref: "#/components/responses/Unauthorized" }
"403": { $ref: "#/components/responses/Forbidden" }
"404": { $ref: "#/components/responses/NotFound" }
"500": { $ref: "#/components/responses/InternalError" }
/api/v1/accounts:
post:
tags: [Accounts]
summary: Create a WireGuard peer account
description: >-
Admin session (role >= `operator` - `support` is read-only everywhere)
or API key with `create` permission. Generates a real WireGuard keypair
server-side and gives the account a peer on every currently eligible
node (status `registered`/`online`, node_group-restricted for a scoped
API key) - not just one. Pass an explicit `node_id` to pin the account
to a single node instead of the default fan-out. A node added to the
fleet later automatically gets this account backfilled a peer too, the
first time that node completes registration. See
docs/STORY-09-multi-node-accounts.md for the full design.
security:
- BearerAuth: []
- ApiKeyAuth: []
requestBody:
required: true
content:
application/json:
schema: { $ref: "#/components/schemas/CreateAccountRequest" }
responses:
"201":
description: Account created.
content:
application/json:
schema: { $ref: "#/components/schemas/Account" }
"400": { $ref: "#/components/responses/BadRequest" }
"401": { $ref: "#/components/responses/Unauthorized" }
"403":
description: >-
Forbidden - either a `support`-role admin session, or an API key
without `create` permission, or (`node_group_not_allowed`) an
explicit `node_id` outside the API key's `node_groups` scope.
content:
application/json:
schema: { $ref: "#/components/schemas/ErrorEnvelope" }
"404": { $ref: "#/components/responses/NotFound" }
"409":
description: "`node_not_registered` (an explicit `node_id` hasn't completed agent registration), `node_capacity_exceeded` (that one pinned node has no room), or `no_available_node` (no eligible node had room - the default fan-out only fails entirely when literally zero nodes could be provisioned; a single full node is skipped, not fatal), or `external_ref_taken`."
content:
application/json:
schema: { $ref: "#/components/schemas/ErrorEnvelope" }
"500": { $ref: "#/components/responses/InternalError" }
get:
tags: [Accounts]
summary: List accounts
description: >-
Admin session (any role) or API key with `read` permission. API-key
callers only ever see accounts under their own key's namespace
(`owner_key_namespace`) - admins see every account. `limit` defaults to
50, capped at 200.
security:
- BearerAuth: []
- ApiKeyAuth: []
parameters:
- name: limit
in: query
schema: { type: integer, default: 50, maximum: 200, minimum: 1 }
responses:
"200":
description: OK
content:
application/json:
schema:
type: object
properties:
accounts:
type: array
items: { $ref: "#/components/schemas/Account" }
"401": { $ref: "#/components/responses/Unauthorized" }
"500": { $ref: "#/components/responses/InternalError" }
/api/v1/accounts/{id}:
parameters:
- name: id
in: path
required: true
schema: { type: string, format: uuid }
get:
tags: [Accounts]
summary: Get an account by id
security:
- BearerAuth: []
- ApiKeyAuth: []
responses:
"200":
description: OK
content:
application/json:
schema: { $ref: "#/components/schemas/Account" }
"401": { $ref: "#/components/responses/Unauthorized" }
"404": { $ref: "#/components/responses/NotFound" }
"500": { $ref: "#/components/responses/InternalError" }
patch:
tags: [Accounts]
summary: Update mutable account fields
description: Admin session (role >= `operator`) or API key with `update` permission. All fields optional; only provided fields change.
security:
- BearerAuth: []
- ApiKeyAuth: []
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
label: { type: string }
data_quota_gb: { type: number, nullable: true }
expiry_at: { type: string, format: date-time, nullable: true }
device_limit: { type: integer, nullable: true }
bandwidth_limit_mbps:
type: integer
nullable: true
description: 0 removes the limit (unshaped); omitted = unchanged; 1-100000 sets the rate in Mbps.
device_limit_hard_enforce:
type: boolean
description: Toggle auto-suspend on device-limit breach (PRD-account-management.md §6.4).
responses:
"200":
description: Updated account.
content:
application/json:
schema: { $ref: "#/components/schemas/Account" }
"400": { $ref: "#/components/responses/BadRequest" }
"401": { $ref: "#/components/responses/Unauthorized" }
"403": { $ref: "#/components/responses/Forbidden" }
"404": { $ref: "#/components/responses/NotFound" }
"500": { $ref: "#/components/responses/InternalError" }
delete:
tags: [Accounts]
summary: Soft-delete an account
description: >-
Admin session (role >= `operator`) or API key with `delete` permission.
Returns the soft-deleted account record (status becomes `deleted`), not
an empty 204 - the assigned IP is released after a grace period
(`ip_release_at`), not immediately, to avoid immediate reuse collisions.
security:
- BearerAuth: []
- ApiKeyAuth: []
responses:
"200":
description: Account soft-deleted.
content:
application/json:
schema: { $ref: "#/components/schemas/Account" }
"401": { $ref: "#/components/responses/Unauthorized" }
"403": { $ref: "#/components/responses/Forbidden" }
"404": { $ref: "#/components/responses/NotFound" }
"500": { $ref: "#/components/responses/InternalError" }
/api/v1/accounts/{id}/suspend:
post:
tags: [Accounts]
summary: Suspend an account
description: Admin session (role >= `operator`) or API key with `suspend` permission.
parameters:
- name: id
in: path
required: true
schema: { type: string, format: uuid }
security:
- BearerAuth: []
- ApiKeyAuth: []
requestBody:
required: false
content:
application/json:
schema:
type: object
properties:
reason:
type: string
enum: [manual, abuse_flag]
default: manual
description: Any other value is silently coerced to "manual".
responses:
"200":
description: Account suspended.
content:
application/json:
schema: { $ref: "#/components/schemas/Account" }
"401": { $ref: "#/components/responses/Unauthorized" }
"403": { $ref: "#/components/responses/Forbidden" }
"404": { $ref: "#/components/responses/NotFound" }
"500": { $ref: "#/components/responses/InternalError" }
/api/v1/accounts/{id}/enable:
post:
tags: [Accounts]
summary: Re-enable a suspended account
description: Admin session (role >= `operator`) or API key with `suspend` permission (enable shares the suspend permission, not a separate one).
parameters:
- name: id
in: path
required: true
schema: { type: string, format: uuid }
security:
- BearerAuth: []
- ApiKeyAuth: []
responses:
"200":
description: Account enabled.
content:
application/json:
schema: { $ref: "#/components/schemas/Account" }
"401": { $ref: "#/components/responses/Unauthorized" }
"403": { $ref: "#/components/responses/Forbidden" }
"404": { $ref: "#/components/responses/NotFound" }
"500": { $ref: "#/components/responses/InternalError" }
/api/v1/accounts/{id}/renew:
post:
tags: [Accounts]
summary: Extend an account's quota and/or expiry
description: Admin session (role >= `operator`) or API key with `update` permission.
parameters:
- name: id
in: path
required: true
schema: { type: string, format: uuid }
security:
- BearerAuth: []
- ApiKeyAuth: []
requestBody:
required: false
content:
application/json:
schema:
type: object
properties:
add_quota_gb:
type: number
nullable: true
description: Added on top of the existing quota (not a replacement).
extend_days:
type: integer
nullable: true
description: Extends from the current expiry_at (or from now, if the account has none/has already expired).
responses:
"200":
description: Account renewed.
content:
application/json:
schema: { $ref: "#/components/schemas/Account" }
"400": { $ref: "#/components/responses/BadRequest" }
"401": { $ref: "#/components/responses/Unauthorized" }
"403": { $ref: "#/components/responses/Forbidden" }
"404": { $ref: "#/components/responses/NotFound" }
"500": { $ref: "#/components/responses/InternalError" }
/api/v1/accounts/{id}/config:
get:
tags: [Accounts]
summary: Fetch the account's wg-quick configuration file for one of its node peers
description: >-
Returns `text/plain`, not JSON - a ready-to-import wg-quick config
including the account's real (decrypted) private key. An account can
have a peer on several nodes (see the `Account.peers` field) - `node_id`
picks which one. If omitted and the account has exactly one peer, that
peer is used by default; if it has more than one, this 400s with the
list of valid node ids instead of guessing. Admin session (any role)
or API key with `read` permission.
parameters:
- name: id
in: path
required: true
schema: { type: string, format: uuid }
- name: node_id
in: query
required: false
schema: { type: string, format: uuid }
description: Required if the account has peers on more than one node; optional (defaults to the only peer) otherwise.
security:
- BearerAuth: []
- ApiKeyAuth: []
responses:
"200":
description: wg-quick config text.
content:
text/plain:
schema:
type: string
example: |
[Interface]
PrivateKey = <account private key>
Address = 10.66.0.4/32
[Peer]
PublicKey = <node public key>
Endpoint = vpn1.example.com:51820
AllowedIPs = 0.0.0.0/0
PersistentKeepalive = 25
"400":
description: "`node_id_required` - the account has peers on multiple nodes and `node_id` was omitted; the message lists the valid ids."
content:
application/json:
schema: { $ref: "#/components/schemas/ErrorEnvelope" }
"401": { $ref: "#/components/responses/Unauthorized" }
"404":
description: "`account_not_found`, or `node_not_found` if `node_id` doesn't match any of this account's peers."
content:
application/json:
schema: { $ref: "#/components/schemas/ErrorEnvelope" }
"409":
description: "`no_peers` (this account has no node peers yet) or `node_missing_public_key` (the target node has no WireGuard public key recorded yet)."
content:
application/json:
schema: { $ref: "#/components/schemas/ErrorEnvelope" }
"500": { $ref: "#/components/responses/InternalError" }
/api/v1/accounts/{id}/devices:
get:
tags: [Accounts]
summary: List distinct client devices observed for this account
description: >-
Device tracking per PRD-account-management.md §6.4 - a "device" is a
distinct source endpoint (IP:port) reported by node agents from live
WireGuard handshakes. `active` = handshaked within the rolling 5-minute
window, the same definition device-limit enforcement uses. Rows unseen
for 30 days are pruned. Admin session (any role) or API key with `read`
permission.
parameters:
- name: id
in: path
required: true
schema: { type: string, format: uuid }
security:
- BearerAuth: []
- ApiKeyAuth: []
responses:
"200":
description: OK
content:
application/json:
schema:
type: object
properties:
devices:
type: array
items:
type: object
properties:
id: { type: string, format: uuid }
source_endpoint: { type: string, example: "203.0.113.7:51843" }
node_id: { type: string, format: uuid }
node_name: { type: string }
first_seen_at: { type: string, format: date-time }
last_seen_at: { type: string, format: date-time }
active: { type: boolean }
active_devices: { type: integer }
device_limit: { type: integer, nullable: true }
device_limit_exceeded: { type: boolean }
"401": { $ref: "#/components/responses/Unauthorized" }
"404": { $ref: "#/components/responses/NotFound" }
"500": { $ref: "#/components/responses/InternalError" }
/api/v1/accounts/{id}/steer:
get:
tags: [Accounts]
summary: Rank this account's nodes, best connection choice first
description: >-
Smart node steering - scores every node the account has a peer on by
current load (active peers / capacity) and recent average CPU, with
online nodes always ahead of offline ones and `?region=` matches ahead
of the rest. Exactly one entry is `recommended`. This is the same engine
the subscription endpoint uses for its default node choice. Admin
session (any role) or API key with `read` permission.
parameters:
- name: id
in: path
required: true
schema: { type: string, format: uuid }
- name: region
in: query
required: false
schema: { type: string }
description: Prefer nodes whose region label matches (case-insensitive).
security:
- BearerAuth: []
- ApiKeyAuth: []
responses:
"200":
description: Nodes ranked best-first.
content:
application/json:
schema:
type: object
properties:
nodes:
type: array
items:
type: object
properties:
node_id: { type: string, format: uuid }
name: { type: string }
region: { type: string }
public_endpoint: { type: string }
online: { type: boolean }
active_peers: { type: integer }
capacity: { type: integer }
cpu_percent: { type: number, nullable: true, description: Recent average; null when the node has no samples in the window. }
score: { type: number, description: Composite load/CPU score - lower is better. }
region_match: { type: boolean }
recommended: { type: boolean }
"401": { $ref: "#/components/responses/Unauthorized" }
"404": { $ref: "#/components/responses/NotFound" }
"500": { $ref: "#/components/responses/InternalError" }
/api/v1/accounts/{id}/subscription/rotate:
post:
tags: [Accounts]
summary: Rotate the account's subscription URL
description: >-
Replaces the subscription token immediately - the old URL stops working,
the response carries the account with its new `subscription_path`. The
WireGuard keypair is untouched (existing device tunnels keep working;
only the config-fetch URL changes). Admin session (role >= `operator`)
or API key with `update` permission.
parameters:
- name: id
in: path
required: true
schema: { type: string, format: uuid }
security:
- BearerAuth: []
- ApiKeyAuth: []
responses:
"200":
description: Account with the new subscription_path.
content:
application/json:
schema: { $ref: "#/components/schemas/Account" }
"401": { $ref: "#/components/responses/Unauthorized" }
"403": { $ref: "#/components/responses/Forbidden" }
"404": { $ref: "#/components/responses/NotFound" }
"500": { $ref: "#/components/responses/InternalError" }
/api/v1/sub/{token}:
get:
tags: [Subscription]
summary: Fetch the account's current wg-quick config via its subscription URL
description: >-
Unauthenticated by design - the 192-bit random token in the path is the
credential (capability URL), suitable for pasting into client apps that
poll for their latest config. By default the best node is chosen by the
steering engine; `?node_id=` pins one, `?region=` biases the choice.
Suspended/expired accounts get 403 `account_suspended` rather than a
config that would silently fail to handshake. The token never appears
in access logs (redacted by the logging middleware).
parameters:
- name: token
in: path
required: true
schema: { type: string }
- name: node_id
in: query
required: false
schema: { type: string, format: uuid }
- name: region
in: query
required: false
schema: { type: string }
responses:
"200":
description: >-
wg-quick config text (Content-Disposition attachment). Served as
`application/octet-stream` rather than `text/plain` so Android
Chrome keeps the `.conf` extension instead of renaming the
download to `.conf.txt`, which the WireGuard app can't import.
content:
application/octet-stream:
schema: { type: string }
"403":
description: "`account_suspended`"
content:
application/json:
schema: { $ref: "#/components/schemas/ErrorEnvelope" }
"404":
description: Unknown token, or `node_not_found` for an explicit `node_id` the account has no peer on.
content:
application/json:
schema: { $ref: "#/components/schemas/ErrorEnvelope" }
"409":
description: "`no_peers` or `node_missing_public_key`"
content:
application/json:
schema: { $ref: "#/components/schemas/ErrorEnvelope" }
"500": { $ref: "#/components/responses/InternalError" }
/api/v1/sub/{token}/nodes:
get:
tags: [Subscription]
summary: List the nodes available to this subscription, steering-ranked
description: >-
The machine-readable companion to the config endpoint, for client apps
that want to offer a node picker. Same token-as-credential model; each
entry carries a ready-to-fetch `config_path`.
parameters:
- name: token
in: path
required: true