Skip to content

Commit

Permalink
Add EC2 provisioner
Browse files Browse the repository at this point in the history
Add a provisioner for deploying exit nodes to AWS EC2

Signed-off-by: Adam Johnson <[email protected]>
  • Loading branch information
adamjohnson01 authored and alexellis committed Jan 5, 2020
1 parent 7ff3ed3 commit 725c13e
Show file tree
Hide file tree
Showing 192 changed files with 144,651 additions and 20 deletions.
72 changes: 67 additions & 5 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 27 additions & 7 deletions cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package cmd

import (
"encoding/base64"
"fmt"
"io/ioutil"
"strconv"
Expand All @@ -21,16 +22,16 @@ import (

func init() {
inletsCmd.AddCommand(createCmd)
createCmd.Flags().StringP("provider", "p", "digitalocean", "The cloud provider - digitalocean, gce, packet, scaleway, or civo")
createCmd.Flags().StringP("provider", "p", "digitalocean", "The cloud provider - digitalocean, gce, ec2, packet, scaleway, or civo")
createCmd.Flags().StringP("region", "r", "lon1", "The region for your cloud provider")
createCmd.Flags().StringP("zone", "z", "us-central1-a", "The zone for the exit node (Google Compute Engine)")

createCmd.Flags().StringP("inlets-token", "t", "", "The inlets auth token for your exit node")
createCmd.Flags().StringP("access-token", "a", "", "The access token for your cloud")
createCmd.Flags().StringP("access-token-file", "f", "", "Read this file for the access token for your cloud")

createCmd.Flags().String("secret-key", "", "The access token for your cloud (Scaleway)")
createCmd.Flags().String("secret-key-file", "", "Read this file for the access token for your cloud (Scaleway)")
createCmd.Flags().String("secret-key", "", "The access token for your cloud (Scaleway, EC2)")
createCmd.Flags().String("secret-key-file", "", "Read this file for the access token for your cloud (Scaleway, EC2)")
createCmd.Flags().String("organisation-id", "", "Organisation ID (Scaleway)")
createCmd.Flags().String("project-id", "", "Project ID (Packet.com, Google Compute Engine)")

Expand Down Expand Up @@ -97,6 +98,8 @@ func runCreate(cmd *cobra.Command, _ []string) error {
region = "fr-par-1"
} else if provider == "packet" {
region = "ams1"
} else if provider == "ec2" {
region = "eu-west-1"
}

var zone string
Expand All @@ -106,17 +109,19 @@ func runCreate(cmd *cobra.Command, _ []string) error {

var secretKey string
var organisationID string
if provider == "scaleway" {
if provider == "scaleway" || provider == "ec2" {

var secretKeyErr error
secretKey, secretKeyErr = getFileOrString(cmd.Flags(), "secret-key-file", "secret-key", true)
if secretKeyErr != nil {
return secretKeyErr
}

organisationID, _ = cmd.Flags().GetString("organisation-id")
if len(organisationID) == 0 {
return fmt.Errorf("--organisation-id cannot be empty")
if provider == "scaleway" {
organisationID, _ = cmd.Flags().GetString("organisation-id")
if len(organisationID) == 0 {
return fmt.Errorf("--organisation-id cannot be empty")
}
}
}

Expand Down Expand Up @@ -218,6 +223,8 @@ func getProvisioner(provider, accessToken, secretKey, organisationID, region str
return provision.NewScalewayProvisioner(accessToken, secretKey, organisationID, region)
} else if provider == "gce" {
return provision.NewGCEProvisioner(accessToken)
} else if provider == "ec2" {
return provision.NewEC2Provisioner(region, accessToken, secretKey)
}
return nil, fmt.Errorf("no provisioner for provider: %s", provider)
}
Expand Down Expand Up @@ -280,6 +287,19 @@ func createHost(provider, name, region, zone, projectID, userData, inletsPort st
"firewall-port": inletsPort,
},
}, nil
} else if provider == "ec2" {
// Ubuntu images can be found here https://cloud-images.ubuntu.com/locator/ec2/
// Name is used in the OS field so the ami can be lookup up in the region specified
return &provision.BasicHost{
Name: name,
OS: "ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-20191114",
Plan: "t3.nano",
Region: region,
UserData: base64.StdEncoding.EncodeToString([]byte(userData)),
Additional: map[string]string{
"inlets-port": inletsPort,
},
}, nil
}

return nil, fmt.Errorf("no provisioner for provider: %q", provider)
Expand Down
19 changes: 11 additions & 8 deletions cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,22 @@ package cmd

import (
"fmt"

"github.com/pkg/errors"
"github.com/spf13/cobra"
)

func init() {
inletsCmd.AddCommand(deleteCmd)
deleteCmd.Flags().StringP("provider", "p", "digitalocean", "The cloud provider - digitalocean, gce, packet, scaleway, or civo")
deleteCmd.Flags().StringP("provider", "p", "digitalocean", "The cloud provider - digitalocean, gce, ec2, packet, scaleway, or civo")

deleteCmd.Flags().StringP("inlets-token", "t", "", "The inlets auth token for your exit node")
deleteCmd.Flags().StringP("access-token", "a", "", "The access token for your cloud")
deleteCmd.Flags().StringP("access-token-file", "f", "", "Read this file for the access token for your cloud")

deleteCmd.Flags().StringP("id", "i", "", "Host ID")

deleteCmd.Flags().String("secret-key", "", "The access token for your cloud (Scaleway)")
deleteCmd.Flags().String("secret-key-file", "", "Read this file for the access token for your cloud (Scaleway)")
deleteCmd.Flags().String("secret-key", "", "The access token for your cloud (Scaleway, EC2)")
deleteCmd.Flags().String("secret-key-file", "", "Read this file for the access token for your cloud (Scaleway, EC2)")
deleteCmd.Flags().String("organisation-id", "", "Organisation ID (Scaleway)")
}

Expand Down Expand Up @@ -56,6 +55,8 @@ func runDelete(cmd *cobra.Command, _ []string) error {

} else if provider == "scaleway" {
region = "fr-par-1"
} else if provider == "ec2" {
region = "eu-west-1"
}

inletsToken, err := cmd.Flags().GetString("inlets-token")
Expand All @@ -78,16 +79,18 @@ func runDelete(cmd *cobra.Command, _ []string) error {

var secretKey string
var organisationID string
if provider == "scaleway" {
if provider == "scaleway" || provider == "ec2" {
var secretKeyErr error
secretKey, secretKeyErr = getFileOrString(cmd.Flags(), "secret-key-file", "secret-key", true)
if secretKeyErr != nil {
return secretKeyErr
}

organisationID, _ = cmd.Flags().GetString("organisation-id")
if len(organisationID) == 0 {
return fmt.Errorf("--organisation-id cannot be empty")
if provider == "scaleway" {
organisationID, _ = cmd.Flags().GetString("organisation-id")
if len(organisationID) == 0 {
return fmt.Errorf("--organisation-id cannot be empty")
}
}
}

Expand Down
Loading

0 comments on commit 725c13e

Please sign in to comment.