tailscale/tailscale · error

creating token request: %w

Error message

creating token request: %w

What it means

In getAWS, constructing the PUT request for an IMDSv2 token failed at http.NewRequestWithContext — a URL-parsing failure of ci.endpoint+"/latest/api/token", not a network error. Nothing has been sent yet; the endpoint string is effectively invalid.

Source

Thrown at util/cloudinfo/cloudinfo.go:120

	}

	body, err := io.ReadAll(resp.Body)
	if err != nil {
		return nil, fmt.Errorf("reading response body for %q: %w", path, err)
	}

	return strings.Split(strings.TrimSpace(string(body)), "\n"), nil
}

// getAWS returns all public IPv4 and IPv6 addresses present in the AWS instance metadata.
func (ci *CloudInfo) getAWS(ctx context.Context) ([]netip.Addr, error) {
	ctx, cancel := context.WithTimeout(ctx, maxCloudInfoWait)
	defer cancel()

	// Get a token so we can query the metadata service.
	req, err := http.NewRequestWithContext(ctx, "PUT", ci.endpoint+"/latest/api/token", nil)
	if err != nil {
		return nil, fmt.Errorf("creating token request: %w", err)
	}
	req.Header.Set("X-Aws-Ec2-Metadata-Token-Ttl-Seconds", "10")

	resp, err := ci.client.Do(req)
	if err != nil {
		return nil, fmt.Errorf("making token request to metadata service: %w", err)
	}
	body, err := io.ReadAll(resp.Body)
	resp.Body.Close()
	if err != nil {
		return nil, fmt.Errorf("reading token response body: %w", err)
	}
	token := string(body)

	server := resp.Header.Get("Server")
	if server != "EC2ws" {
		return nil, fmt.Errorf("unexpected server header: %q", server)
	}

View on GitHub (pinned to 6e0912f979)

Solutions

  1. Fix the metadata endpoint configuration to a valid absolute URL
  2. Reject this as a permanent config error; retrying cannot help since no request was made
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at util/cloudinfo/cloudinfo.go:120 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of tailscale/tailscale@6e0912f979 (2026-08-18). Data as JSON: /api/errors/284b474ae0d5228f. Report an issue: GitHub.