Allow to use wireproxy as endpoint (#74)

This is useful for running wireguard endpoints in unprivileged
containers.
This commit is contained in:
Jonah Brüchert 2023-07-15 21:39:24 +02:00 committed by GitHub
parent aa207764b2
commit 31e6afd75d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 16 deletions

View file

@ -174,5 +174,17 @@ ListenPort = 5080
Target = service-three.servicenet:80 Target = service-three.servicenet:80
``` ```
Wireproxy can also allow peers to connect to it:
```
[Interface]
ListenPort = 5400
...
[Peer]
PublicKey = YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY=
AllowedIPs = 10.254.254.100/32
# Note there is no Endpoint defined here.
```
# Stargazers over time # Stargazers over time
[![Stargazers over time](https://starchart.cc/octeep/wireproxy.svg)](https://starchart.cc/octeep/wireproxy) [![Stargazers over time](https://starchart.cc/octeep/wireproxy.svg)](https://starchart.cc/octeep/wireproxy)

View file

@ -15,7 +15,7 @@ import (
type PeerConfig struct { type PeerConfig struct {
PublicKey string PublicKey string
PreSharedKey string PreSharedKey string
Endpoint string Endpoint *string
KeepAlive int KeepAlive int
AllowedIPs []netip.Prefix AllowedIPs []netip.Prefix
} }
@ -27,6 +27,7 @@ type DeviceConfig struct {
Peers []PeerConfig Peers []PeerConfig
DNS []netip.Addr DNS []netip.Addr
MTU int MTU int
ListenPort *int
} }
type TCPClientTunnelConfig struct { type TCPClientTunnelConfig struct {
@ -229,6 +230,14 @@ func ParseInterface(cfg *ini.File, device *DeviceConfig) error {
device.MTU = value device.MTU = value
} }
if sectionKey, err := section.GetKey("ListenPort"); err == nil {
value, err := sectionKey.Int()
if err != nil {
return err
}
device.ListenPort = &value
}
return nil return nil
} }
@ -259,15 +268,14 @@ func ParsePeers(cfg *ini.File, peers *[]PeerConfig) error {
peer.PreSharedKey = value peer.PreSharedKey = value
} }
decoded, err = parseString(section, "Endpoint") if sectionKey, err := section.GetKey("Endpoint"); err == nil {
value := sectionKey.String()
decoded, err = resolveIPPAndPort(strings.ToLower(value))
if err != nil { if err != nil {
return err return err
} }
decoded, err = resolveIPPAndPort(decoded) peer.Endpoint = &decoded
if err != nil {
return err
} }
peer.Endpoint = decoded
if sectionKey, err := section.GetKey("PersistentKeepalive"); err == nil { if sectionKey, err := section.GetKey("PersistentKeepalive"); err == nil {
value, err := sectionKey.Int() value, err := sectionKey.Int()

View file

@ -26,15 +26,21 @@ func createIPCRequest(conf *DeviceConfig) (*DeviceSetting, error) {
request.WriteString(fmt.Sprintf("private_key=%s\n", conf.SecretKey)) request.WriteString(fmt.Sprintf("private_key=%s\n", conf.SecretKey))
if conf.ListenPort != nil {
request.WriteString(fmt.Sprintf("listen_port=%d\n", *conf.ListenPort))
}
for _, peer := range conf.Peers { for _, peer := range conf.Peers {
request.WriteString(fmt.Sprintf(heredoc.Doc(` request.WriteString(fmt.Sprintf(heredoc.Doc(`
public_key=%s public_key=%s
endpoint=%s
persistent_keepalive_interval=%d persistent_keepalive_interval=%d
preshared_key=%s preshared_key=%s
`), `),
peer.PublicKey, peer.Endpoint, peer.KeepAlive, peer.PreSharedKey, peer.PublicKey, peer.KeepAlive, peer.PreSharedKey,
)) ))
if peer.Endpoint != nil {
request.WriteString(fmt.Sprintf("endpoint=%s\n", *peer.Endpoint))
}
if len(peer.AllowedIPs) > 0 { if len(peer.AllowedIPs) > 0 {
for _, ip := range peer.AllowedIPs { for _, ip := range peer.AllowedIPs {