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

gok vm: add custom ports #78

Closed
Tracked by #18209
andig opened this issue Jan 26, 2025 · 6 comments · Fixed by #79
Closed
Tracked by #18209

gok vm: add custom ports #78

andig opened this issue Jan 26, 2025 · 6 comments · Fixed by #79

Comments

@andig
Copy link
Contributor

andig commented Jan 26, 2025

We're using port 80 for the host application and 8080 for gokrazy:

"Hostname": "evcc",
"Update": {
    "HTTPPort": "8080",
    "HTTPPassword": "HjJv6aBX51G4wT8EueCc"
},

Here the host application occupies 8080 and gokrazy is not available via qemu. It would be nice if gok vm (automatically?) allowed mapping additional ports for this purpose. Maybe by overriding to appending to netdev:

-netdev user,id=net0,hostfwd=tcp::8080-:80,hostfwd=tcp::8022-:22
@andig
Copy link
Contributor Author

andig commented Jan 26, 2025

I'll try a PR for this

@andig andig mentioned this issue Jan 26, 2025
@andig
Copy link
Contributor Author

andig commented Jan 26, 2025

PR works:

GOOS=linux gok -i mac vm run --ports 8088:8080
❯ curl -v http://localhost:8088
* Host localhost:8088 was resolved.
* IPv6: ::1
* IPv4: 127.0.0.1
*   Trying [::1]:8088...
* connect to ::1 port 8088 from ::1 port 51961 failed: Connection refused
*   Trying 127.0.0.1:8088...
* Connected to localhost (127.0.0.1) port 8088
> GET / HTTP/1.1
> Host: localhost:8088
> User-Agent: curl/8.7.1
> Accept: */*
> 
* Request completely sent off
< HTTP/1.1 401 Unauthorized
< Content-Type: text/plain; charset=utf-8
< Www-Authenticate: Basic realm="gokrazy"
< X-Content-Type-Options: nosniff
< Date: Sun, 26 Jan 2025 14:46:28 GMT
< Content-Length: 34
< 
no Basic Authorization header set
* Connection #0 to host localhost left intact

It does however produce very odd results if run with evcc-io/evcc#18209:

❯ curl -v http://localhost:8088
* Host localhost:8088 was resolved.
* IPv6: ::1
* IPv4: 127.0.0.1
*   Trying [::1]:8088...
* connect to ::1 port 8088 from ::1 port 53039 failed: Connection refused
*   Trying 127.0.0.1:8088...
* Connected to localhost (127.0.0.1) port 8088
> GET / HTTP/1.1
> Host: localhost:8088
> User-Agent: curl/8.7.1
> Accept: */*
> 
* Request completely sent off
< HTTP/1.1 302 Found
< Content-Type: text/html; charset=utf-8
< Location: https://localhost:8088:8080/
< Date: Sun, 26 Jan 2025 14:49:55 GMT
< Content-Length: 51
< 
<a href="https://localhost:8088:8080/">Found</a>.

I have no idea where the broken redirect comes from?

@andig
Copy link
Contributor Author

andig commented Jan 27, 2025

I'm still lost where this super weird port 8088:8080 https redirect issue comes from. It works fine with a simple example and only shows in the evcc case. Since evcc listens on 8080:80 it's out of the way and it doesn't listen to 8080 itself.

@andig
Copy link
Contributor Author

andig commented Jan 27, 2025

Oh, I see. Simple case:

http://gokrazy:ru6j9eEvXO823f7n7jYO@mac:8080/

evcc:

 https://gokrazy:HjJv6aBX51G4wT8EueCc@evcc:8080/

Not sure what triggers this though, looking at https://github.com/gokrazy/tools/blob/main/internal/packer/packer.go#L1650-L1659 atm.

@andig
Copy link
Contributor Author

andig commented Jan 27, 2025

@stapelberg I can see this happens here in packer.go:

	fmt.Printf("!! cfg.Update %+v\n", cfg.Update)
	update, err := cfg.Update.WithFallbackToHostSpecific(cfg.Hostname)
	fmt.Printf("!! update %+v\n", update)

which results in HTTPS port being set:

!! cfg.Update &{Hostname: UseTLS: NoPassword:false HTTPPort:8080 HTTPSPort: HTTPPassword:HjJv6aBX51G4wT8EueCc CertPEM: KeyPEM:}
!! update &{Hostname: UseTLS: NoPassword:false HTTPPort:8080 HTTPSPort:8080 HTTPPassword:HjJv6aBX51G4wT8EueCc CertPEM: KeyPEM:}

I dunno yet how that triggers the fancy redirect, but maybe this is enough for you to take a quick look? It seems the HTTPS choice is a bit arbitrary and has side effects.

@andig
Copy link
Contributor Author

andig commented Jan 27, 2025

Found it. There was 4 year old ~/Library/Application\ Support/gokrazy/hosts/evcc directory lying around on my harddrive which apparently is not instance-centric.

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 a pull request may close this issue.

1 participant