kubernetes/kops · error

invalid google cloud storage path: %q

Error message

invalid google cloud storage path: %q

What it means

VFSContext.buildGCSPath wraps a raw string into a GSPath VFS object. It rejects any string that url.Parse fails on, returning "invalid google cloud storage path". This is a client-side validation error: the path never leaves the process.

Source

Thrown at util/pkg/vfs/context.go:497

	if c.memfsContext == nil {
		// We only initialize this in unit tests etc
		return nil, fmt.Errorf("memfs context not initialized")
	}
	fspath := NewMemFSPath(c.memfsContext, location)
	return fspath, nil
}

func (c *VFSContext) ResetMemfsContext(clusterReadable bool) {
	c.memfsContext = NewMemFSContext()
	if clusterReadable {
		c.memfsContext.MarkClusterReadable()
	}
}

func (c *VFSContext) buildGCSPath(p string) (*GSPath, error) {
	u, err := url.Parse(p)
	if err != nil {
		return nil, fmt.Errorf("invalid google cloud storage path: %q", p)
	}

	if u.Scheme != "gs" {
		return nil, fmt.Errorf("invalid google cloud storage path: %q", p)
	}

	bucket := strings.TrimSuffix(u.Host, "/")
	if bucket == "" {
		return nil, fmt.Errorf("invalid google cloud storage path: %q", p)
	}

	gcsPath := NewGSPath(c, bucket, u.Path)
	return gcsPath, nil
}

// getGCSClient returns the google cloud storage client, caching it for future calls
func (c *VFSContext) getGCSClient(ctx context.Context) (*storage.Client, error) {
	c.mutex.Lock()

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Percent-encode or remove special characters (%, spaces, control chars) in the path before passing it to BuildVfsPath
  2. Print the exact path %q at the call site and run it through url.Parse in isolation to see the underlying parse error
  3. Ensure the state store URL is configured as a proper gs://<bucket>/<prefix> string, not assembled from raw user input
  4. Trim whitespace/newlines from configuration values before building the path

Example fix

// before
vfsPath, err := context.BuildVfsPath("gs://bucket/state/" + rawPrefix) // rawPrefix = "my%2zzstate"
// after
prefix := url.PathEscape(strings.TrimSpace(rawPrefix))
vfsPath, err := context.BuildVfsPath("gs://bucket/state/" + prefix)
Defensive patterns

Strategy: validation

Validate before calling

if _, err := url.Parse(stateStore); err != nil { return fmt.Errorf("state store %q is not a valid URL: %v", stateStore, err) }

Type guard

func isParsableURL(p string) bool { _, err := url.Parse(p); return err == nil }

Try / catch

if _, err := context.BuildVfsPath(p); err != nil { if strings.Contains(err.Error(), "invalid google cloud storage path") { /* reject config, show user the offending path */ } return err }

Prevention

When it happens

Trigger: Calling VFSContext.BuildVfsPath with a gs:// path that is so malformed url.Parse returns an error (e.g. invalid percent-encoding like "gs://bucket/%zz", control characters in the URL).

Common situations: Cluster state-store flags built by string concatenation from untrusted config values; secrets or passwords interpolated into the state store URL that break URL escaping (a literal % followed by non-hex characters); copy-pasted URLs containing stray characters.

Related errors


AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05). Data as JSON: /api/errors/ced508094d7b4d0f. Report an issue: GitHub.