Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow a custom name, not just auto-generated #130

Merged
merged 3 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
[![Documentation](https://godoc.org/github.com/inlets/inletsctl?status.svg)](http://godoc.org/github.com/inlets/inletsctl)
![Downloads](https://img.shields.io/github/downloads/inlets/inletsctl/total) <a href="https://actuated.dev/"><img alt="Arm CI sponsored by Actuated" src="https://docs.actuated.dev/images/actuated-badge.png" width="120px"></img></a>


inletsctl automates the task of creating an exit-server (tunnel server) on public cloud infrastructure.
The `create` command provisions a cheap cloud VM with a public IP and pre-installs inlets Pro for you. You'll then get a connection string that you can use with the inlets client.
The `create` command provisions a cheap cloud VM with a public IP and pre-installs inlets for you. You'll then get a connection string that you can use with the inlets client.

**Conceptual diagram**

Expand All @@ -16,7 +15,7 @@ The `create` command provisions a cheap cloud VM with a public IP and pre-instal

Use-cases:

* Setup L4 TCP and HTTPS tunnels for your local services using [inlets Pro](https://inlets.dev/) with `inletsctl create`
* Setup L4 TCP and HTTPS tunnels for your local services using [inlets-pro](https://inlets.dev/) with `inletsctl create`
* Create tunnels for use with Kubernetes clusters, create the tunnel and use it whenever you need it
* Port-forward services your local Kubernetes cluster using `inletsctl kfwd`

Expand Down Expand Up @@ -47,7 +46,6 @@ In the demo we:

[![asciicast](https://asciinema.org/a/q8vqJ0Fwug47T62biscp7cJ5O.svg)](https://asciinema.org/a/q8vqJ0Fwug47T62biscp7cJ5O)


inletsctl is the quickest and easiest way to automate tunnels, whilst retaining complete control of your tunnel and data.

## Features
Expand Down Expand Up @@ -114,5 +112,4 @@ type Provisioner interface {

inletsctl is distributed under the MIT license. inlets-pro, which inletsctl uses is licensed under the [inlets-pro End User License Agreement (EULA)](https://github.com/inlets/inlets-pro/blob/master/EULA.md).

A valid inlets license or Gumroad subscription is required to create tunnel servers with inletsctl.

[A valid static inlets license or a Gumroad subscription](https://store.openfaas.com/) is required to create tunnel servers with inletsctl.
55 changes: 31 additions & 24 deletions cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/spf13/cobra"
)

const inletsProDefaultVersion = "0.9.25"
const inletsProDefaultVersion = "0.9.28"
const inletsProControlPort = 8123

func init() {
Expand Down Expand Up @@ -49,15 +49,13 @@ func init() {
createCmd.Flags().String("endpoint", "ovh-eu", "API endpoint (ovh), default: ovh-eu")
createCmd.Flags().String("consumer-key", "", "The Consumer Key for using the OVH API")

createCmd.Flags().Bool("tcp", true, `Provision an exit-server with inlets running as a TCP server`)
createCmd.Flags().Bool("tcp", false, `Provision an exit-server with inlets running as a TCP server`)
createCmd.Flags().String("aws-key-name", "", "The name of an existing SSH key on AWS to be used to access the EC2 instance for maintenance (optional)")

createCmd.Flags().StringArray("letsencrypt-domain", []string{}, `Domains you want to get a Let's Encrypt certificate for`)
createCmd.Flags().String("letsencrypt-issuer", "prod", `The issuer endpoint to use with Let's Encrypt - \"prod\" or \"staging\"`)
createCmd.Flags().String("letsencrypt-issuer", "prod", `The issuer endpoint to use with Let's Encrypt - "prod" or "staging"`)
createCmd.Flags().String("letsencrypt-email", "", `The email to register with Let's Encrypt for renewal notices (required)`)

createCmd.Flags().Bool("pro", true, `Provision an exit-server with inlets Pro (Deprecated)`)
_ = createCmd.Flags().MarkHidden("pro")
createCmd.Flags().DurationP("poll", "n", time.Second*2, "poll every N seconds, use a higher value if you encounter rate-limiting")

createCmd.Flags().String("inlets-version", inletsProDefaultVersion, `Binary release version for inlets`)
Expand All @@ -71,19 +69,25 @@ var createCmd = &cobra.Command{
with inlets preloaded as a systemd service. The estimated cost of each
VM along with what OS version and spec will be used is explained in the
project docs.`,
Example: ` # Create a TCP tunnel server
inletsctl create \
--provider [digitalocean|equinix-metal|ec2|scaleway|civo|gce|azure|linode|hetzner] \
--access-token-file $HOME/access-token \
--region lon1

Example: `
# Create a HTTPS tunnel server, terminating TLS with a certificate
# from Let's Encrypt
# from Let's Encrypt called "tunnel-richardcase" so your team mates
# don't delete your VM unintentionally.
inletsctl create \
tunnel-richardcase \
--letsencrypt-domain inlets.example.com \
--letsencrypt-email [email protected]

# Create a HTTPS tunnel server with multiple domains
# Create a TCP tunnel server with a VM name of ssh-tunnel
inletsctl create \
ssh-tunnel \
--tcp \
--provider [digitalocean|equinix-metal|ec2|scaleway|civo|gce|azure|linode|hetzner] \
--access-token-file $HOME/access-token \
--region lon1

# Create a HTTPS tunnel server with multiple domains and an auto-generated
# VM name
inletsctl create \
--letsencrypt-domain tunnel1.example.com \
--letsencrypt-domain tunnel2.example.com \
Expand All @@ -99,6 +103,12 @@ const EquinixMetalProvider = "equinix-metal"

func runCreate(cmd *cobra.Command, _ []string) error {

// Get name from the Args, if not provided, generate a random name
name := strings.Replace(names.GetRandomName(10), "_", "-", -1)
if len(cmd.Flags().Args()) > 0 {
name = cmd.Flags().Args()[0]
}

inletsProVersion, err := cmd.Flags().GetString("inlets-version")
if err != nil {
return err
Expand All @@ -108,12 +118,7 @@ func runCreate(cmd *cobra.Command, _ []string) error {
inletsProVersion = inletsProDefaultVersion
}

tcp := true

if cmd.Flags().Changed("pro") {
fmt.Printf("WARN: --pro is deprecated, use --tcp instead.")
tcp, _ = cmd.Flags().GetBool("pro")
}
tcp := false
if cmd.Flags().Changed("tcp") {
tcp, _ = cmd.Flags().GetBool("tcp")
}
Expand All @@ -138,7 +143,7 @@ func runCreate(cmd *cobra.Command, _ []string) error {
serverMode = "L7 HTTPS"
}

fmt.Printf("inletsctl version: %v\nTunnel server: %s\tProvider: %s\tVersion: %s\n",
fmt.Printf("inletsctl version: %v\nTunnel server: %s\tProvider: %s\tinlets-pro version: %s\n",
getVersion(),
serverMode, provider, inletsProVersion)

Expand Down Expand Up @@ -291,6 +296,10 @@ func runCreate(cmd *cobra.Command, _ []string) error {
letsencryptEmail, _ := cmd.Flags().GetString("letsencrypt-email")
letsencryptIssuer, _ := cmd.Flags().GetString("letsencrypt-issuer")

if len(letsencryptDomains) == 0 && !tcp {
return fmt.Errorf("either --letsencrypt-domain (for a HTTPS tunnel) or --tcp (for a TCP tunnel) must be set")
}

if len(letsencryptDomains) > 0 {
if len(letsencryptEmail) == 0 {
return fmt.Errorf("--letsencrypt-email is required when --letsencrypt-domain is given")
Expand All @@ -301,8 +310,6 @@ func runCreate(cmd *cobra.Command, _ []string) error {
tcp = false
}

name := strings.Replace(names.GetRandomName(10), "_", "-", -1)

var userData string
if len(letsencryptDomains) > 0 {
userData = MakeHTTPSUserdata(inletsToken,
Expand Down Expand Up @@ -341,9 +348,9 @@ func runCreate(cmd *cobra.Command, _ []string) error {
}

if provider == "gce" {
fmt.Printf("Requesting host: %s in %s, from %s\n", name, zone, provider)
fmt.Printf("Provisioning exit-server: %s in %s [%s]\n", name, zone, provider)
} else {
fmt.Printf("Requesting host: %s in %s, from %s\n", name, region, provider)
fmt.Printf("Provisioning exit-server: %s in %s [%s]\n", name, region, provider)
}

hostRes, err := provisioner.Provision(*hostReq)
Expand Down
Loading