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

Set more reasonable default port for storage nodes #521

Merged
merged 2 commits into from
Aug 15, 2017
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
20 changes: 20 additions & 0 deletions commands/tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package commands

import (
"fmt"
"strconv"

"github.com/spf13/cobra"

Expand Down Expand Up @@ -42,6 +43,25 @@ func init() {
// tunnelFn ...
func tunnelFn(ccmd *cobra.Command, args []string) {

if tunnelCmdFlags.port != "" {
port, err := strconv.Atoi(tunnelCmdFlags.port)
if err != nil {
fmt.Printf(`
Please specify a number for a port to listen on. You specified '%s'.

`, tunnelCmdFlags.port)
return
}

if port < 1024 {
fmt.Printf(`
Please specify a number above 1023 as a port to listen on. You specified '%d'.

`, port)
return
}
}

env, _ := models.FindEnvByID(config.EnvID())
args, location, name := helpers.Endpoint(env, args, 2)

Expand Down
12 changes: 11 additions & 1 deletion util/display/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ func UnexpectedPrivilage() {
--------------------------------------------------------------------------------
+ ERROR:
+ Nanobox is designed to run as a standard user (non root)
+ Please run all nanobox commands as a non privilage user
+ Please run all nanobox commands as a non privileged user
--------------------------------------------------------------------------------

`))
Expand All @@ -327,6 +327,16 @@ the '-p' flag. (eg. 'nanobox tunnel data.db -p 5444')
`, port))
}

func PortPrivileged(port string) {
os.Stderr.WriteString(fmt.Sprintf(`
--------------------------------------------------------------------------------
PRIVILEGED PORT
Port '%s' is a privileged port. Please specify a port greater than 1023 with
the '-p' flag. (eg. 'nanobox tunnel data.db -p 5444')
--------------------------------------------------------------------------------
`, port))
}

func ConsoleNodeNotFound() {
os.Stderr.WriteString(fmt.Sprintf(`
--------------------------------------------------------------------------------
Expand Down
11 changes: 10 additions & 1 deletion util/nanoagent/tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ func Tunnel(key, location, port, name string) error {
}
defer conn.Close()

if port == "22" {
port = "2022"
}

// setup a tcp listener
serv, err := net.Listen("tcp4", fmt.Sprintf(":%s", port))
if err != nil {
Expand All @@ -38,7 +42,12 @@ func Tunnel(key, location, port, name string) error {
if strings.Contains(err.Error(), "address already in use") || err == syscall.EADDRINUSE {
display.PortInUse(port)
err2.Code = "USER"
err2.Suggest = fmt.Sprintf("It appears your local port (%s) is in use. Please specify a different port.", port)
err2.Suggest = fmt.Sprintf("It appears your local port (%s) is in use. Please specify a different port with '-p'.", port)
}
if strings.Contains(err.Error(), "bind: permission denied") || err == syscall.EACCES {
display.PortPrivileged(port)
err2.Code = "USER"
err2.Suggest = fmt.Sprintf("It appears you don't have permission to use port '%s'. Please specify a different port with '-p'.", port)
}

return util.ErrorAppend(err2, "failed to setup tcp listener")
Expand Down