Skip to content

Commit 2ffb769

Browse files
authored
Merge pull request #23 from threefoldtech/reinegrate-wg-in-zosbase
Reinegrate wg in zosbase
2 parents 1d8f2ec + 50edc09 commit 2ffb769

File tree

18 files changed

+726
-50
lines changed

18 files changed

+726
-50
lines changed

docs/internals/network-light/readme.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,52 @@ What happens now is:
8080
- VMs inside a single space can communicate directly over their bridge.
8181
- Different networks resource can (and well) have conflicting IP and ranges but with no issue since each network is completely isolated from the other ones.
8282

83+
## Private Networks
84+
85+
To reach vms on local nodes using wireguard you need to:
86+
87+
- Deploy a networkwith valid pairs so you can be able to connect to the vm from your machine and add a container to this network.
88+
For example:
89+
90+
```go
91+
WGPrivateKey: wgKey,
92+
WGListenPort: 3011,
93+
Peers: []zos.Peer{
94+
{
95+
Subnet: gridtypes.MustParseIPNet("10.1.2.0/24"),
96+
WGPublicKey: "4KTvZS2KPWYfMr+GbiUUly0ANVg8jBC7xP9Bl79Z8zM=",
97+
98+
AllowedIPs: []gridtypes.IPNet{
99+
gridtypes.MustParseIPNet("10.1.2.0/24"),
100+
gridtypes.MustParseIPNet("100.64.1.2/32"),
101+
102+
```
103+
104+
> **Note:** make sure to use valid two wg key pairs for the container and your local machine.
105+
106+
- After the deployment the network can be accessed through wg with the following config.
107+
108+
```conf
109+
[Interface]
110+
Address = 100.64.1.2/32
111+
PrivateKey = <your private key>
112+
113+
[Peer]
114+
PublicKey = cYvKjMRBLj3o3e4lxWOK6bbSyHWtgLNHkEBxIv7Olm4=
115+
AllowedIPs = 10.1.1.0/24, 100.64.1.1/32
116+
PersistentKeepalive = 25
117+
Endpoint = 192.168.123.32:3011
118+
```
119+
120+
- Bring wireguard interface up `wg-quick up <config file>`
121+
- Test the connection `wg`
122+
![image](https://github.com/user-attachments/assets/ca0d37e2-d586-4e0f-ae98-2d70188492bd)
123+
124+
- Then you should be able to ping/access the container `ping 10.1.1.2`
125+
![image](https://github.com/user-attachments/assets/d625a573-3d07-4980-afc0-4570acd7a21f)
126+
127+
- Then you should be able to ping to the container `ping 10.1.1.2`
128+
83129
### Full Picture
84130
85131
![full](png/full.png)

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ require (
104104
github.com/gtank/ristretto255 v0.1.2 // indirect
105105
github.com/hanwen/go-fuse/v2 v2.3.0 // indirect
106106
github.com/hashicorp/errwrap v1.1.0 // indirect
107-
github.com/hashicorp/go-multierror v1.1.1 // indirect
107+
github.com/hashicorp/go-multierror v1.1.1
108108
github.com/hashicorp/go-retryablehttp v0.7.7
109109
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
110110
github.com/holiman/uint256 v1.2.3 // indirect

pkg/gridtypes/zos/network_light.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,28 @@ type NetworkLight struct {
2929
// if no mycelium configuration is provided, vms can't
3030
// get mycelium IPs.
3131
Mycelium Mycelium `json:"mycelium,omitempty"`
32+
33+
// wg config
34+
// IP range of the network, must be an IPv4 /16
35+
// for example a 10.1.0.0/16
36+
NetworkIPRange gridtypes.IPNet `json:"ip_range"`
37+
38+
// The private wg key of this node (this peer) which is installing this
39+
// network workload right now.
40+
// This has to be filled in by the user (and not generated for example)
41+
// because other peers need to be installed as well (with this peer public key)
42+
// hence it's easier to configure everything one time at the user side and then
43+
// apply everything on all nodes at once
44+
WGPrivateKey string `json:"wireguard_private_key"`
45+
46+
// WGListenPort is the wireguard listen port on this node. this has
47+
// to be filled in by the user for same reason as private key (other nodes need to know about it)
48+
// To find a free port you have to ask the node first by a call over RMB about which ports are possible
49+
// to use.
50+
WGListenPort uint16 `json:"wireguard_listen_port"`
51+
52+
// Peers is a list of other peers in this network
53+
Peers []Peer `json:"peers"`
3254
}
3355

3456
// Valid checks if the network resource is valid.

pkg/netlight/bootstrap/bootstrap_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func TestAddrSet(t *testing.T) {
5656
mustParseAddr("192.168.0.10/24"),
5757
})
5858
assert.Equal(t, 3, s.Len())
59-
assert.Equal(t, []netlink.Addr{
59+
assert.ElementsMatch(t, []netlink.Addr{
6060
mustParseAddr("192.168.0.1/24"),
6161
mustParseAddr("192.168.1.1/24"),
6262
mustParseAddr("192.168.0.10/24"),

0 commit comments

Comments
 (0)