Skip to content

Commit f7dd84e

Browse files
committed
Initial commit
0 parents  commit f7dd84e

11 files changed

+1715
-0
lines changed

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Brent Johnson
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
## EWVM
2+
3+
Quickly create ephemeral Wireguard-enabled VMs on DigitalOcean for various testing purposes. Not a formal project I intend to maintain, and I don't recommend you use this, but maybe you'll find what's being done here interesting.
4+
5+
<img src="https://github.com/brentjo/ewvm/assets/6415223/928dd21a-d582-446d-9d23-57b254abb34f" height="400">
6+
7+
**Example use cases**
8+
9+
- A temporary VPN to have an IP address to proxy traffic through. Maybe you don’t need a VPN running 24/7 racking up a bill, but occasionally do need a second IP address for testing or debugging purposes, and this tooling enables you to quickly spin a VPN up temporarily. This was the original purpose of this tooling.
10+
- `ewvm up` to bring a Wireguard-enabled machine up. Prints out a QR code to easily connect from your phone via the Wireguard mobile app, and a `wg-quick` command to connect from the machine running the tooling.
11+
- A public HTTP receiver to easily test webhooks and similar
12+
- `ewvm log` to listen on a port and print out received TCP traffic, or provide the `--tunnel` flag to additionally spawn a Cloudflare Tunnel so that you can receive traffic with a domain name / TLS-enabled endpoint.
13+
- A throwaway-VM to run potentially untrusted code on and discard, for those one-off scripts and tools with risky origins that you are not comfortable running on your personal machine.
14+
- `ewvm ssh` to interactively SSH into the VM and do whatever you’d like
15+
- As a caveat: you may only want to use it for this purpose if you have no other resources on your DigitalOcean account. I’m unfamiliar with how ‘isolated by default’ new VMs are — for example I see it noted that all VMs created in the same region will be members of the same private VPC network by default and have connectivity to each other, so depending on how/what services you have running on existing machines, that may be problematic.
16+
17+
### Installation
18+
19+
Download and install Go if you do not already have it: https://go.dev/doc/install
20+
21+
```
22+
git clone https://github.com/brentjo/ewvm && cd ewvm && go build
23+
```
24+
25+
`./ewvm` to run the binary out of the project's directory, or copy the binary to wherever you'd like in your `$PATH` for global use in your terminal.
26+
27+
### Uninstallation
28+
29+
Run the command: `ewvm uninstall`
30+
31+
This will destroy all VMs, SSH keys, config directories, and keychain entries associated with this tooling. Notably, it does not revoke the DigitalOcean API key you provided for the tooling, so be sure to revoke it if it's no longer needed.
32+
33+
To manually clean up:
34+
- Delete the `$HOME/.ewvm` directory. This is where all config files and logs are stored.
35+
- Delete the keychain entries: `EWVM: DigitalOcean API token`, `EWVM: Private SSH key`, `EWVM: Public SSH key`
36+
- Delete the SSH key on your DigitalOcean account named `ephemeral-wg-key`
37+
- https://cloud.digitalocean.com/account/security
38+
- Delete any VMs on your DigitalOcean account with the tag `ewvm-temporary-machine`
39+
- https://cloud.digitalocean.com/droplets
40+
- Revoke the API key you provided for this tooling
41+
- https://cloud.digitalocean.com/account/api/tokens

args.go

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package main
2+
3+
// Helper methods used in argument parsing
4+
5+
import (
6+
"net"
7+
"regexp"
8+
)
9+
10+
func validRegion(r string) bool {
11+
match, err := regexp.MatchString("^[a-zA-Z]{3}[0-9]?$", r)
12+
return err == nil && match
13+
}
14+
15+
func validServerIP(ip string) bool {
16+
netIP := net.ParseIP(ip)
17+
if netIP == nil {
18+
return false
19+
}
20+
21+
ip4 := netIP.To4()
22+
if ip4 == nil {
23+
return false
24+
}
25+
26+
lastOctal := int(ip4[3])
27+
28+
return netIP.IsPrivate() && lastOctal < 255
29+
}
30+
31+
func validDNS(dnsServer string) bool {
32+
netIP := net.ParseIP(dnsServer)
33+
if netIP == nil {
34+
return false
35+
}
36+
netIP.DefaultMask()
37+
38+
return netIP.To4() != nil
39+
}
40+
41+
func clientIP(serverIP string) string {
42+
ip := net.ParseIP(serverIP).To4()
43+
ip[3]++
44+
return ip.String()
45+
}
46+
47+
func validPort(port int) bool {
48+
return port >= 1 && port <= 65535
49+
}

args_test.go

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
package main
2+
3+
import "testing"
4+
5+
func TestValidRegion(t *testing.T) {
6+
if !validRegion("sfo3") {
7+
t.Errorf("Expected a valid region")
8+
}
9+
10+
if !validRegion("sfo") {
11+
t.Errorf("Expected a valid region")
12+
}
13+
14+
if validRegion("notdatacentercode") {
15+
t.Errorf("Expected an invalid region")
16+
}
17+
18+
if validRegion("before\nsfo3") {
19+
t.Errorf("Expected an invalid region")
20+
}
21+
22+
if validRegion("sf") {
23+
t.Errorf("Expected an invalid region")
24+
}
25+
26+
if validRegion("sf3") {
27+
t.Errorf("Expected an invalid region")
28+
}
29+
}
30+
31+
func TestValidServerIP(t *testing.T) {
32+
if !validServerIP("10.0.8.1") {
33+
t.Errorf("Expected a valid server IP")
34+
}
35+
36+
if validServerIP("10.0.8.256") {
37+
t.Errorf("Expected an invalid server IP")
38+
}
39+
40+
if validServerIP("8.8.8.8") {
41+
t.Errorf("Expected an public IP to be considered invalid")
42+
}
43+
44+
if validServerIP("2001:0db8:85a3:0000:0000:8a2e:0370:7334") {
45+
t.Errorf("Expected an invalid server IP")
46+
}
47+
48+
if validServerIP("texthere") {
49+
t.Errorf("Expected an invalid server IP")
50+
}
51+
52+
if validServerIP("0") {
53+
t.Errorf("Expected an invalid server IP")
54+
}
55+
}
56+
57+
func TestValidDNS(t *testing.T) {
58+
59+
if !validDNS("8.8.8.8") {
60+
t.Errorf("Expected a valid DNS address")
61+
}
62+
63+
if validDNS("2001:0db8:85a3:0000:0000:8a2e:0370:7334") {
64+
t.Errorf("Expected an invalid DNS address")
65+
}
66+
67+
if validDNS("texthere") {
68+
t.Errorf("Expected an invalid DNS address")
69+
}
70+
71+
if validDNS("0") {
72+
t.Errorf("Expected an invalid DNS address")
73+
}
74+
}
75+
76+
func TestClientIP(t *testing.T) {
77+
if clientIP("10.0.8.1") != "10.0.8.2" {
78+
t.Errorf("Expected client IP to be next address of server")
79+
}
80+
}
81+
82+
func TestValidPort(t *testing.T) {
83+
if !validPort(3000) {
84+
t.Errorf("Expected a valid port")
85+
}
86+
87+
if validPort(0) {
88+
t.Errorf("Expected an invalid DNS address")
89+
}
90+
if validPort(-1) {
91+
t.Errorf("Expected an invalid DNS address")
92+
}
93+
if validPort(65536) {
94+
t.Errorf("Expected an invalid DNS address")
95+
}
96+
}

go.mod

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module github.com/brentjo/ewvm
2+
3+
go 1.19
4+
5+
require (
6+
github.com/digitalocean/godo v1.109.0
7+
golang.org/x/crypto v0.19.0
8+
golang.org/x/term v0.17.0
9+
)
10+
11+
require (
12+
github.com/golang/protobuf v1.5.3 // indirect
13+
github.com/google/go-querystring v1.1.0 // indirect
14+
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
15+
github.com/hashicorp/go-retryablehttp v0.7.5 // indirect
16+
golang.org/x/oauth2 v0.17.0 // indirect
17+
golang.org/x/sys v0.17.0 // indirect
18+
golang.org/x/time v0.5.0 // indirect
19+
google.golang.org/appengine v1.6.8 // indirect
20+
google.golang.org/protobuf v1.32.0 // indirect
21+
)

go.sum

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
2+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3+
github.com/digitalocean/godo v1.107.0 h1:P72IbmGFQvKOvyjVLyT59bmHxilA4E5hWi40rF4zNQc=
4+
github.com/digitalocean/godo v1.107.0/go.mod h1:R6EmmWI8CT1+fCtjWY9UCB+L5uufuZH13wk3YhxycCs=
5+
github.com/digitalocean/godo v1.109.0 h1:4W97RJLJSUQ3veRZDNbp1Ol3Rbn6Lmt9bKGvfqYI5SU=
6+
github.com/digitalocean/godo v1.109.0/go.mod h1:R6EmmWI8CT1+fCtjWY9UCB+L5uufuZH13wk3YhxycCs=
7+
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
8+
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
9+
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
10+
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
11+
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
12+
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
13+
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
14+
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
15+
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
16+
github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ=
17+
github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48=
18+
github.com/hashicorp/go-hclog v0.9.2 h1:CG6TE5H9/JXsFWJCfoIVpKFIkFe6ysEuHirp4DxCsHI=
19+
github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ=
20+
github.com/hashicorp/go-retryablehttp v0.7.5 h1:bJj+Pj19UZMIweq/iie+1u5YCdGrnxCT9yvm0e+Nd5M=
21+
github.com/hashicorp/go-retryablehttp v0.7.5/go.mod h1:Jy/gPYAdjqffZ/yFGCFV2doI5wjtH1ewM9u8iYVjtX8=
22+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
23+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
24+
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
25+
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
26+
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
27+
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
28+
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
29+
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
30+
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
31+
golang.org/x/crypto v0.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo=
32+
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
33+
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
34+
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
35+
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
36+
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
37+
golang.org/x/oauth2 v0.15.0 h1:s8pnnxNVzjWyrvYdFUQq5llS1PX2zhPXmccZv99h7uQ=
38+
golang.org/x/oauth2 v0.15.0/go.mod h1:q48ptWNTY5XWf+JNten23lcvHpLJ0ZSxF5ttTHKVCAM=
39+
golang.org/x/oauth2 v0.17.0 h1:6m3ZPmLEFdVxKKWnKq4VqZ60gutO35zm+zrAHVmHyDQ=
40+
golang.org/x/oauth2 v0.17.0/go.mod h1:OzPDGQiuQMguemayvdylqddI7qcD9lnSDb+1FiwQ5HA=
41+
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
42+
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
43+
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
44+
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
45+
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
46+
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
47+
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
48+
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
49+
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
50+
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
51+
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
52+
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
53+
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
54+
golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4=
55+
golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0=
56+
golang.org/x/term v0.17.0 h1:mkTF7LCd6WGJNL3K1Ad7kwxNfYAW6a8a8QqtMblp/4U=
57+
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
58+
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
59+
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
60+
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
61+
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
62+
golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk=
63+
golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
64+
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
65+
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
66+
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
67+
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
68+
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
69+
google.golang.org/appengine v1.6.8 h1:IhEN5q69dyKagZPYMSdIjS2HqprW324FRQZJcGqPAsM=
70+
google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJffLiz/Ds=
71+
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
72+
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
73+
google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
74+
google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
75+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

0 commit comments

Comments
 (0)