Skip to content

fix(compute/serve): provide default override_host to Viceroy via temporary manifest and support IPv6 hostnames - #1940

Open
Tyagiquamar wants to merge 4 commits into
fastly:mainfrom
Tyagiquamar:fix/1435-override-host-manifest-test
Open

Tyagiquamar wants to merge 4 commits into
fastly:mainfrom
Tyagiquamar:fix/1435-override-host-manifest-test

Conversation

@Tyagiquamar

@Tyagiquamar Tyagiquamar commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Change summary

Fixes #1435. When fastly compute serve runs, if local server backends are missing override_host and use a hostname URL:

  1. Writes the modified manifest with override_host to a temporary file passed to Viceroy (-C), keeping the user's project fastly.toml untouched on disk, and cleans up the temporary file on exit via defer os.Remove. If no backends require default override_host, the original manifest path is used without creating a temporary file.
  2. Uses u.Hostname() instead of splitting on : so IPv6 addresses (such as http://[::1]:8080) are correctly recognized by net.ParseIP() and skipped as IP backends rather than incorrectly treated as hostnames.
  3. Adds comprehensive regression tests in serve_internal_test.go covering temporary manifest generation, non-mutation of user files, cleanup, and backend URL variants (hostname with/without port, IPv4, IPv6, existing override_host).

All Submissions:

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?

New Feature Submissions:

  • Does your submission pass tests?

Changes to Core Features:

  • Have you written new tests for your core changes, as applicable?
  • Have you successfully run tests with your changes locally?

User Impact

Running fastly compute serve no longer permanently modifies the user's fastly.toml file when default override_host values are applied for Viceroy. IPv6 backend URLs like http://[::1]:8080 are 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.

@Tyagiquamar
Tyagiquamar requested a review from a team as a code owner October 19, 2026 02:54
@rcaril

rcaril commented Oct 22, 2026

Copy link
Copy Markdown
Member

Hi @Tyagiquamar - please use our PR template:

### Change summary

 <!--
Briefly describe the changes introduced in this pull request. Include context or
reasoning behind the changes, even if they seem minor. If relevant, link to any
related discussions (e.g. Slack threads, tickets, documents).
-->

All Submissions:

* [ ] Have you followed the guidelines in our Contributing document?
* [ ] Have you checked to ensure there aren't other open [Pull Requests](https://github.com/fastly/cli/pulls) for the same update/change?

<!-- You can erase any parts of this template not applicable to your Pull Request. -->

### New Feature Submissions:

* [ ] Does your submission pass tests?

### Changes to Core Features:

* [ ] Have you written new tests for your core changes, as applicable?
* [ ] Have you successfully run tests with your changes locally?

### User Impact

<!-- What is the user impact of this change? -->

### Are there any considerations that need to be addressed for release?

<!-- Any breaking changes, etc -->

@Tyagiquamar

Copy link
Copy Markdown
Contributor Author

Done — the PR description now follows the template. I also merged current main into the branch to clear the CHANGELOG.md conflict (both bug-fix entries kept). go build ./... and go test ./pkg/commands/compute/... pass on the merged branch.

@philippschulte philippschulte left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Comment thread pkg/commands/compute/serve.go Outdated
if !updated {
return nil
}
return c.Globals.Manifest.File.Write(manifestPath)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Comment thread pkg/commands/compute/serve.go Outdated
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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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 WhiteAbeLincoln left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I agree with @philippschulte, we probably want to write the new config to a temporary file as was suggested in #1435.

@Tyagiquamar Tyagiquamar changed the title test(compute/serve): persist default override_host for Viceroy fix(compute/serve): provide default override_host to Viceroy via temporary manifest and support IPv6 hostnames Nov 5, 2026
@Tyagiquamar

Copy link
Copy Markdown
Contributor Author

Thanks for the reviews and feedback @philippschulte and @WhiteAbeLincoln!

I have updated the implementation to address both items:

  1. Temporary Manifest for Viceroy: Instead of mutating the user's fastly.toml, compute serve now writes the modified manifest containing the default override_host to a temporary file passed to Viceroy via -C, with cleanup scheduled on exit (defer cleanup() calling os.Remove). If no backends require an override_host default, the original manifest is used directly without creating any temporary files.
  2. IPv6 Hostname Handling: Replaced manual : splitting with u.Hostname() before calling net.ParseIP(), properly stripping brackets and ports so IPv6 URLs like http://[::1]:8080 and http://[::1] are recognized as IP addresses and skipped as intended.
  3. Regression Tests: Added TestSetBackendsWithDefaultOverrideHostIfMissing_TemporaryManifest (verifying temporary manifest creation, user manifest preservation, and cleanup) and TestSetBackendsWithDefaultOverrideHostIfMissing_BackendMatrix covering IPv4, IPv6 ([::1] and full address), hostname with/without port, and pre-existing override_host.

All tests pass cleanly.

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.

setBackendsWithDefaultOverrideHostIfMissing doesn't actually do anything

5 participants