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
- Percent-encode or remove special characters (%, spaces, control chars) in the path before passing it to BuildVfsPath
- Print the exact path %q at the call site and run it through url.Parse in isolation to see the underlying parse error
- Ensure the state store URL is configured as a proper gs://<bucket>/<prefix> string, not assembled from raw user input
- 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
- Percent-encode user-supplied path segments before composing gs:// URLs
- Trim whitespace and control characters from config values
- Fail fast in config loading by validating the state-store URL at startup
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
- error parsing location %q - not a valid URI
- error parsing ConfigStore.Base %q: %v
- clusterName is required
- error parsing locationStore=%q: %w
- parsing etcd backup-store %q: %w
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/ced508094d7b4d0f.
Report an issue: GitHub.