functions-framework-go icon indicating copy to clipboard operation
functions-framework-go copied to clipboard

allow firewall dialog shows under development and testing in macOS

Open picaoao opened this issue 4 years ago • 9 comments

When starting a function for integration testing, the OS always shows a dialog box to confirm we allow opening the firewall.

image

Is there any way of not having this show ? It disables any chance of scripting and automating integration tests.

It seems that if the localhost:port as the address for the http.ListenAndServe, we no longer get the dialog. https://github.com/GoogleCloudPlatform/functions-framework-go/blob/7ae80f37956ac3a83ee676c63cc4a7a3f753f476/funcframework/framework.go#L106

picaoao avatar Dec 15 '20 16:12 picaoao

I think this is a generic warning that can be disabled in settings. I don't think it's specific to this library.

Maybe send a PR if there's a change that doesn't break anything?

grant avatar Dec 15 '20 18:12 grant

Can't really do it unless I disable the firewall completely. The binary keeps changing location (build) when I run tests.

Seems the same issue as in https://github.com/golang/appengine/pull/25 ? Could we do something like that ?

picaoao avatar Dec 17 '20 14:12 picaoao

Thanks for linking that issue @picaoao, something similar might work. Above is a PR.

grant avatar Dec 17 '20 20:12 grant

@grant any problems in going forward with the merge ?

picaoao avatar Jan 08 '21 00:01 picaoao

@grant any problems in going forward with the merge ?

I need to talk to @grayside and figure out a solution that is appropriate for Go per a comment in the PR. Maybe adding an environment variable.

Comments on the pr at welcome. Pardon the delay.

grant avatar Jan 08 '21 02:01 grant

Comment from @picaoao in https://github.com/GoogleCloudPlatform/functions-framework-go/pull/63#issuecomment-762907726

I think an optional env would be fine. What do you think ?

Hopefully we don't need to introduce an env var to fix this, but as @grayside said in the PR comments, that PR's approach was incorrect.

I'm not familiar enough with Go to suggest a solution for this, maybe propose/prototype a solution and look at the standard solution used by other libraries? Feel free to talk about this here and send a PR after some thought. I can help get the PR through.

grant avatar Jan 19 '21 16:01 grant

Note that as a workaround, you can call http.ListenAndServe directly. You don't have to use Start (you can see the function body is very minimal).

tbpg avatar Jan 19 '21 17:01 tbpg

@tbpg Not sure how something outside this package could call that directly; the handler is private to this package. It's totally possible I'm missing something :)

Another solution that compliments the existing example might be to have a separate environment variable for host, with the default set to "" so it binds to all addresses if its not provided. It does end up changing the method signature on Start() to include an address, so would likely require a minor version bump.

	port := "8080"
	host := ""

	if envPort := os.Getenv("PORT"); envPort != "" {
		port = envPort
	}

	if envHost := os.Getenv("HOST"); envHost != "" {
		host = envHost
	}

	if err := funcframework.Start(host, port); err != nil {
		log.Fatalf("funcframework.Start: %v\n", err)
	}

Other minor tweaks might include passing in the entire listen address but I think this approach would be ergonomic, and not force any particular address binding. This way any configuration / development setup / etc could rely on the developers preference (dotenv style, viper, etc)

trevoro avatar Jan 30 '21 22:01 trevoro

What I meant was directly replace your call to funcframework.Start with http.ListenAndServe.

tbpg avatar Feb 01 '21 14:02 tbpg