feat: WireGuard (server + client + peers + QR) + shared UI components
WireGuard --------- * Migration 0013: wireguard_interfaces (server|client mode, key envelope- encrypted) + wireguard_peers (per-server roster). Drop old empty 0005-Schema (Option-A peer_type, kein Iface-FK), neuer Aufbau mit zwei Tabellen + FK. * internal/services/secrets: Box mit AES-256-GCM, Master-Key in /var/lib/edgeguard/.master_key (lazy-create, 0600). Sealed/Open für PrivateKey + PSK. * internal/services/wireguard: KeyGen (Curve25519 mit clamping), PublicFromPrivate (für Import), InterfacesRepo, PeersRepo, Importer (parst /etc/wireguard/*.conf, server vs. client heuristisch nach ListenPort + Peer-Anzahl). * internal/wireguard: Renderer schreibt /etc/edgeguard/wireguard/<iface>.conf (0600), restartet wg-quick@<iface> via sudo (sudoers im postinst erweitert). Idempotent — re-render nur wenn content geändert. * internal/handlers/wireguard.go: REST CRUD für interfaces+peers, /generate-keypair, /peers/:id/config (text/plain wg-quick conf), /peers/:id/qr (PNG via go-qrcode). Auto-reload nach Mutation. * edgeguard-ctl wg-import [--path /etc/wireguard]: liest existierende conf-Files in die DB. Idempotent (überspringt vorhandene Iface-Namen). Shared UI components (proxy-lb-waf design pattern) -------------------------------------------------- * PageHeader: icon + title + subtitle + extras row, einheitlich oben auf jeder Page. * ActionButtons: Edit + Delete combo mit Popconfirm + Tooltip. * StatusDot: AntD Badge pattern statt "Yes/No" — schneller scanbar in dichten Tabellen. * DataTable: pageSizeOptions [20,50,100,200] + extraActions-Alias + optional renderMobileCard für Card-Liste auf < md Breakpoint. * enterprise.css: .page-header* + .datatable-toolbar Klassen. Frontend WireGuard ------------------ * /vpn/wireguard mit zwei Tabs (Server / Client) im neuen Pattern. * Server-Tab: Modal mit Generate-Keypair-Toggle, Peer-Roster im Drawer per Server. Pro Peer: QR-Code-Modal + .conf-Download. * Client-Tab: Upstream-Card im Modal, full-tunnel-Default (0.0.0.0/0,::/0), Keepalive 25. * i18n DE/EN für wg.* Block + common.* Erweiterung. Misc ---- * Sidebar: WireGuard unter Security-Sektion. * Nav-i18n: "Firewall (v2)" → "Firewall". * Version 1.0.8 → 1.0.11. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
65
internal/models/wireguard.go
Normal file
65
internal/models/wireguard.go
Normal file
@@ -0,0 +1,65 @@
|
||||
package models
|
||||
|
||||
import "time"
|
||||
|
||||
// WireguardInterface is the local end of a WireGuard tunnel — server
|
||||
// (we listen for peers) or client (we dial out to a fixed peer).
|
||||
// PrivateKey + PeerPSK never appear in JSON; they are handled inside
|
||||
// the handler as encrypted blobs (sealed via internal/services/secrets).
|
||||
type WireguardInterface struct {
|
||||
ID int64 `gorm:"primaryKey" json:"id"`
|
||||
Name string `gorm:"column:name;uniqueIndex" json:"name"`
|
||||
Mode string `gorm:"column:mode" json:"mode"` // server|client
|
||||
AddressCIDR string `gorm:"column:address_cidr" json:"address_cidr"`
|
||||
ListenPort *int `gorm:"column:listen_port" json:"listen_port,omitempty"`
|
||||
PublicKey string `gorm:"column:public_key" json:"public_key"`
|
||||
PeerEndpoint *string `gorm:"column:peer_endpoint" json:"peer_endpoint,omitempty"`
|
||||
PeerPublicKey *string `gorm:"column:peer_public_key" json:"peer_public_key,omitempty"`
|
||||
AllowedIPs *string `gorm:"column:allowed_ips" json:"allowed_ips,omitempty"`
|
||||
PersistentKeepalive *int `gorm:"column:persistent_keepalive" json:"persistent_keepalive,omitempty"`
|
||||
MTU *int `gorm:"column:mtu" json:"mtu,omitempty"`
|
||||
Role string `gorm:"column:role" json:"role"`
|
||||
Active bool `gorm:"column:active" json:"active"`
|
||||
Description *string `gorm:"column:description" json:"description,omitempty"`
|
||||
CreatedAt time.Time `gorm:"column:created_at" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at"`
|
||||
|
||||
// PrivateKeyEnc / PeerPSKEnc are loaded from the DB as raw bytes
|
||||
// — handler never serialises them. JSON tag uses '-' so they
|
||||
// don't leak into responses if a developer accidentally returns
|
||||
// the model directly.
|
||||
PrivateKeyEnc []byte `gorm:"column:private_key_enc" json:"-"`
|
||||
PeerPSKEnc []byte `gorm:"column:peer_psk_enc" json:"-"`
|
||||
}
|
||||
|
||||
func (WireguardInterface) TableName() string { return "wireguard_interfaces" }
|
||||
|
||||
// WireguardPeer is a single roster entry on a server-mode interface.
|
||||
// PrivateKey + PSK are encrypted at-rest and never returned in list
|
||||
// payloads — only via the explicit /config download endpoint, and
|
||||
// only once we generated the keypair server-side (nullable).
|
||||
type WireguardPeer struct {
|
||||
ID int64 `gorm:"primaryKey" json:"id"`
|
||||
InterfaceID int64 `gorm:"column:interface_id" json:"interface_id"`
|
||||
Name string `gorm:"column:name" json:"name"`
|
||||
PublicKey string `gorm:"column:public_key" json:"public_key"`
|
||||
AllowedIPs string `gorm:"column:allowed_ips" json:"allowed_ips"`
|
||||
Keepalive *int `gorm:"column:keepalive" json:"keepalive,omitempty"`
|
||||
LastHandshake *time.Time `gorm:"column:last_handshake" json:"last_handshake,omitempty"`
|
||||
TransferRX int64 `gorm:"column:transfer_rx" json:"transfer_rx"`
|
||||
TransferTX int64 `gorm:"column:transfer_tx" json:"transfer_tx"`
|
||||
Enabled bool `gorm:"column:enabled" json:"enabled"`
|
||||
Description *string `gorm:"column:description" json:"description,omitempty"`
|
||||
CreatedAt time.Time `gorm:"column:created_at" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at"`
|
||||
|
||||
PrivateKeyEnc []byte `gorm:"column:private_key_enc" json:"-"`
|
||||
PSKEnc []byte `gorm:"column:psk_enc" json:"-"`
|
||||
|
||||
// HasPrivateKey is a derived flag for the UI: "is the QR-code
|
||||
// download going to work for this peer, or is this a roster row
|
||||
// where the operator only pasted a pubkey?"
|
||||
HasPrivateKey bool `gorm:"-" json:"has_private_key"`
|
||||
}
|
||||
|
||||
func (WireguardPeer) TableName() string { return "wireguard_peers" }
|
||||
Reference in New Issue
Block a user