Repository navigation
fix(compute/serve): provide default override_host to Viceroy via temporary manifest and support IPv6 hostnames - #1940
Conversation
|
Hi @Tyagiquamar - please use our PR template: |
|
Done — the PR description now follows the template. I also merged current |
philippschulte
left a comment
There was a problem hiding this comment.
Thanks for your contribution and for working on this fix! We appreciate you taking the time to address this issue and add regression test coverage.
I've left a couple of comments regarding some potential edge cases and the handling of the manifest file.
| if !updated { | ||
| return nil | ||
| } | ||
| return c.Globals.Manifest.File.Write(manifestPath) |
There was a problem hiding this comment.
This writes the default override_host directly into the user's original fastly.toml, meaning simply running fastly compute serve permanently changes their configuration.
In #1435, the proposed approach was to write the modified manifest to a temporary file, pass that file to Viceroy, and clean it up afterward. Please see #1435 (comment).
Could we use a temporary manifest instead? That would fix the Viceroy issue without introducing unexpected changes to the user's project files.
| for k, backend := range c.Globals.Manifest.File.LocalServer.Backends { | ||
| if backend.OverrideHost == "" { | ||
| if u, err := url.Parse(backend.URL); err == nil { | ||
| segs := strings.Split(u.Host, ":") // avoid parsing IP with port |
There was a problem hiding this comment.
The current hostname extraction works for IPv4 addresses but fails for IPv6 URLs such as http://[::1]:8080.
Splitting u.Host on : produces "[" as the first element, so net.ParseIP() returns nil. This incorrectly treats the IPv6 address as a hostname and assigns an override_host, even though IP addresses are supposed to be skipped.
Although this logic existed previously, the new persistence behavior makes the issue affect Viceroy.
Could we use u.Hostname() instead? It correctly removes ports and IPv6 brackets, allowing net.ParseIP() to handle both IPv4 and IPv6 addresses. It would also be useful to add regression tests covering both.
WhiteAbeLincoln
left a comment
There was a problem hiding this comment.
I agree with @philippschulte, we probably want to write the new config to a temporary file as was suggested in #1435.
|
Thanks for the reviews and feedback @philippschulte and @WhiteAbeLincoln! I have updated the implementation to address both items:
All tests pass cleanly. |
Change summary
Fixes #1435. When
fastly compute serveruns, if local server backends are missingoverride_hostand use a hostname URL:override_hostto a temporary file passed to Viceroy (-C), keeping the user's projectfastly.tomluntouched on disk, and cleans up the temporary file on exit viadefer os.Remove. If no backends require defaultoverride_host, the original manifest path is used without creating a temporary file.u.Hostname()instead of splitting on:so IPv6 addresses (such ashttp://[::1]:8080) are correctly recognized bynet.ParseIP()and skipped as IP backends rather than incorrectly treated as hostnames.serve_internal_test.gocovering temporary manifest generation, non-mutation of user files, cleanup, and backend URL variants (hostname with/without port, IPv4, IPv6, existingoverride_host).All Submissions:
New Feature Submissions:
Changes to Core Features:
User Impact
Running
fastly compute serveno longer permanently modifies the user'sfastly.tomlfile when defaultoverride_hostvalues are applied for Viceroy. IPv6 backend URLs likehttp://[::1]:8080are now correctly recognized as IP addresses without bracket extraction errors.Are there any considerations that need to be addressed for release?
None: no breaking changes or flags introduced.