621e8895c9
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
52 lines
2.3 KiB
Markdown
52 lines
2.3 KiB
Markdown
---
|
|
name: wg_peer_remove
|
|
kind: function
|
|
lang: go
|
|
domain: infra
|
|
version: "1.0.0"
|
|
purity: impure
|
|
signature: "func WGPeerRemove(deviceID string, configPath string) (WGPeerRemoveResult, error)"
|
|
description: "Quita peer del hub wg0.conf por device_id, syncconf en caliente, idempotente. Para reconfigurar peer existente (no kill switch)."
|
|
tags: [wireguard, hub, peer, mesh, infra, audit]
|
|
uses_functions: []
|
|
uses_types: []
|
|
returns: []
|
|
returns_optional: false
|
|
error_type: "error_go_core"
|
|
imports: []
|
|
params:
|
|
- name: deviceID
|
|
desc: "Identificador unico del dispositivo. Debe coincidir con el comentario '# DeviceID:<id>' en el bloque [Peer] del config."
|
|
- name: configPath
|
|
desc: "Ruta absoluta al archivo de configuracion WireGuard (ej. /etc/wireguard/wg0.conf). Debe tener permisos de escritura."
|
|
output: "WGPeerRemoveResult con DeviceID, ConfigPath y Status (removed | not-present). not-present cuando el peer no existia — no es error."
|
|
tested: true
|
|
tests:
|
|
- "peer present → status=removed"
|
|
- "peer absent → status=not-present"
|
|
test_file_path: "functions/infra/wg_peer_remove_test.go"
|
|
file_path: "functions/infra/wg_peer_remove.go"
|
|
---
|
|
|
|
## Ejemplo
|
|
|
|
```go
|
|
result, err := infra.WGPeerRemove("device-laptop-alice", "/etc/wireguard/wg0.conf")
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
// result.Status == "removed" o "not-present"
|
|
fmt.Printf("peer %s: %s\n", result.DeviceID, result.Status)
|
|
```
|
|
|
|
## Cuando usarla
|
|
|
|
Cuando necesites dar de baja temporalmente un peer del hub (dispositivo reemplazado, rotar claves, reconfigurar AllowedIPs). No deja rastro permanente — si el dispositivo vuelve a conectarse puedes añadirlo de nuevo. Para kill switch permanente (dispositivo perdido/comprometido) usa `wg_peer_revoke_go_infra`.
|
|
|
|
## Gotchas
|
|
|
|
- Requiere privilegios de root para `wg syncconf`. La funcion escribe el .conf y luego invoca `wg syncconf <iface> <path>`. Si el binario `wg` no esta disponible o el proceso no tiene permisos, el write se revierte automaticamente.
|
|
- El marker `# DeviceID:<id>` debe estar en el bloque [Peer] correcto. Si el comentario esta duplicado solo se elimina el primer bloque encontrado.
|
|
- El nombre de la interfaz se deduce del nombre del archivo (wg0.conf → wg0). Si configPath no sigue esa convencion, syncconf se omite (solo se modifica el archivo).
|
|
- La funcion NO toca la blacklist ni la audit DB — eso es exclusivo de `wg_peer_revoke`.
|