-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
1,374 additions
and
213 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
dwgd | ||
.vagrant | ||
.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package dwgd | ||
|
||
import ( | ||
"io/fs" | ||
"os" | ||
"os/exec" | ||
) | ||
|
||
// commander abstracts the os and os/exec stdlib packages. | ||
// This is needed to mock in unit tests. | ||
type commander interface { | ||
// os | ||
Chmod(name string, mode fs.FileMode) error | ||
MkdirAll(name string, perm fs.FileMode) error | ||
ReadFile(name string) ([]byte, error) | ||
ReadDir(name string) ([]fs.DirEntry, error) | ||
Remove(name string) error | ||
Symlink(oldname string, newname string) error | ||
// os/exec | ||
LookPath(file string) (string, error) | ||
Run(name string, arg ...string) error | ||
} | ||
|
||
type execCommander struct{} | ||
|
||
func (e *execCommander) Chmod(name string, mode fs.FileMode) error { | ||
return os.Chmod(name, mode) | ||
} | ||
|
||
func (e *execCommander) MkdirAll(path string, perm fs.FileMode) error { | ||
return os.MkdirAll(path, perm) | ||
} | ||
|
||
func (e *execCommander) ReadDir(name string) ([]fs.DirEntry, error) { | ||
return os.ReadDir(name) | ||
} | ||
|
||
func (e *execCommander) ReadFile(name string) ([]byte, error) { | ||
return os.ReadFile(name) | ||
} | ||
|
||
func (e *execCommander) Remove(name string) error { | ||
return os.Remove(name) | ||
} | ||
|
||
func (e *execCommander) Symlink(oldname string, newname string) error { | ||
return os.Symlink(oldname, newname) | ||
} | ||
|
||
func (e *execCommander) LookPath(file string) (string, error) { | ||
return exec.LookPath(file) | ||
} | ||
|
||
func (e *execCommander) Run(name string, arg ...string) error { | ||
cmd := exec.Command(name, arg...) | ||
return cmd.Run() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Development | ||
|
||
This folder contains some utilities that can aid the development of `dwgd`: | ||
- `e2e-tests/` contains tests that check the whole `dwgd` lifecycle by creating | ||
the necessary resources (WireGuard interface and docker network), sending a ping | ||
from the container and finally removing everything. The tests can be run like: | ||
`sudo ./development/e2e-tests/test_ifname_mode.sh` and everything should be `OK`. | ||
- `Vagrantfile` a simple Vagrant box that has everything it's needed to run the | ||
`e2e-tests`. | ||
|
||
## Developing on local machine | ||
|
||
You can develop on your own machine by compiling `dwgd`, creating a WireGuard network and starting `dwgd`: | ||
|
||
```sh | ||
go build ./cmd/dwgd.go | ||
# create server keys | ||
SERVER_PRIVATE_KEY=$(wg genkey) | ||
SERVER_PUBLIC_KEY=$(echo $SERVER_PRIVATE_KEY | wg pubkey) | ||
# create new dwgd0 wireguard interface | ||
sudo ip link add dwgd0 type wireguard | ||
echo $SERVER_PRIVATE_KEY | sudo wg set dwgd0 private-key /dev/fd/0 listen-port 51820 | ||
sudo ip address add 10.0.0.1/24 dev dwgd0 | ||
# bring interface up | ||
sudo ip link set up dev dwgd0 | ||
# generate your container's public key with a specific seed | ||
CLIENT_PUBLIC_KEY=$(./dwgd pubkey -i 10.0.0.2 -s supersecretseed) | ||
sudo wg set dwgd0 peer $CLIENT_PUBLIC_KEY allowed-ips 10.0.0.2/32 | ||
# run dwgd driver | ||
sudo ./dwgd -v & | ||
# create docker network with the previously set server public key and seed | ||
docker network create --driver=dwgd -o dwgd.endpoint=localhost:51820 -o dwgd.seed=supersecretseed -o dwgd.pubkey=$SERVER_PUBLIC_KEY --subnet="10.0.0.0/24" --gateway=10.0.0.1 dwgd-net | ||
# run your container | ||
docker run -it --rm --network=dwgd-net --ip=10.0.0.2 busybox | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# -*- mode: ruby -*- | ||
# vi: set ft=ruby : | ||
|
||
Vagrant.configure("2") do |config| | ||
config.vm.box = "debian/bookworm64" | ||
|
||
config.vm.hostname = "dwgd-box" | ||
|
||
config.vm.provision "shell", inline: <<-SHELL | ||
apt-get update | ||
apt-get install -y docker.io wireguard | ||
usermod -aG docker vagrant | ||
SHELL | ||
end |
Oops, something went wrong.