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

Support Docker mode #63

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Support Docker mode #63

wants to merge 2 commits into from

Conversation

chadell
Copy link
Collaborator

@chadell chadell commented Apr 18, 2020

Initial proposal to verify the approach to the docker mode.

Use it:
$ go run main.go run --docker nginx

Hints:

@@ -53,26 +57,65 @@ func init() {
runCmd.Flags().BoolVarP(&params.debug, "debug", "d", false, "Print debugging information to the standard error")
runCmd.Flags().IntVarP(&params.reportingInterval, "interval", "i", 1, "Interval, in seconds, between stats updates")
runCmd.Flags().BoolVarP(&params.assumeyes, "assume-yes", "y", false, "Force execution without asking for confirmation")
runCmd.Flags().BoolVarP(&params.docker, "docker", "", false, "Running against a docker image. " +
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re-using things like the "host" to inject the image name is a bit hacky. But that is a minor thing

@@ -53,26 +57,65 @@ func init() {
runCmd.Flags().BoolVarP(&params.debug, "debug", "d", false, "Print debugging information to the standard error")
runCmd.Flags().IntVarP(&params.reportingInterval, "interval", "i", 1, "Interval, in seconds, between stats updates")
runCmd.Flags().BoolVarP(&params.assumeyes, "assume-yes", "y", false, "Force execution without asking for confirmation")
runCmd.Flags().BoolVarP(&params.docker, "docker", "", false, "Running against a docker image. " +
"Use the image reference instead of the <host>, and a custom mapped port if the first exposed one is not ok (optional")
}

func validateRequiredArgs(params *tcpgoonParams, args []string) error {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we must redo how we are validating parms. Relying on a max/min num of required params looks ugly: we should just check which parm is required and which are not in each execution mode. If execution modes parameters differ a lot in the end, maybe we should recover your idea of using different commands

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, the execution mode is the first question to answer

}

params.targetip = addrs[0].String()
fmt.Fprintln(debugging.DebugOut, "TCPGOON target: Hostname(", params.target, "), IP (", params.targetip, ")")
if params.docker {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this massive if/else is... :) . That smells to two different validation functions depending on the "mode", but again, we should rethink the parms in general

Port int
}

func lookForAvailableLocalPort() (availablePort int){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

up to you, but i would try the same the docker is exposing, and if that fails, require the user to be the one that chooses one

return availablePort
}

func DownloadAndRun(image string, port int) (targetinfo IPandPort, containerID string) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i guess this requires refactor / better encapsulation... long and with too much statements inside if/elses. I would also not panic in this function, but return an error and make the caller to manage the errors accordingly

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, do not take this PR as ready to review. The point here is, having a first working version, understand if this docker mode should be part of the regular command or have a custom one.

fmt.Println("Internal Docker port binding:", mapperProto, mappedPort)
}

// hack https://stackoverflow.com/questions/47395973/issue-while-using-docker-api-for-go-cannot-import-nat
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to nat / expose the port in the host 0.0.0.0? Maybe we can target the container IP if an internal subnet/bridge network is being used

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changing the network defaults is another option, but I considered this simpler

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants