rancher/rancher · error

failed to parse jsonpath: %w

Error message

failed to parse jsonpath: %w

What it means

parsePaths is the audit package's shared helper that parses a []string of redaction paths with github.com/rancher/jsonpath. It backs additionalRedactions[].paths parsing; a single malformed expression fails the whole list and the AuditPolicy is rejected.

Source

Thrown at pkg/auth/audit/utils.go:91

	return compiled, nil
}

func matchesAny(s string, regexes []*regexp.Regexp) bool {
	for _, re := range regexes {
		if re.MatchString(s) {
			return true
		}
	}

	return false
}

func parsePaths(paths []string) ([]*jsonpath.JSONPath, error) {
	compiled := make([]*jsonpath.JSONPath, len(paths))
	for i, v := range paths {
		jp, err := jsonpath.Parse(v)
		if err != nil {
			return nil, fmt.Errorf("failed to parse jsonpath: %w", err)
		}
		compiled[i] = jp
	}

	return compiled, nil
}

func pairMatches(v any, f func(string, any) bool) bool {
	switch v := v.(type) {
	case map[string]any:
		for k, v := range v {
			if f(k, v) {
				return true
			}

			if pairMatches(v, f) {
				return true
			}

View on GitHub (pinned to 932558d4e6)

Solutions

  1. Compile-check every path with jsonpath.Parse before applying
  2. Standardize on the brace syntax ({.field.subfield})
  3. Re-apply and confirm the policy loads
Defensive patterns

Strategy: validation

Validate before calling

import jsonpath "github.com/rancher/jsonpath/pkg"

func validatePaths(paths []string) error {
    for _, p := range paths {
        if _, err := jsonpath.Parse(p); err != nil {
            return fmt.Errorf("path %q: %w", p, err)
        }
    }
    return nil
}

Prevention

When it happens

Trigger: Any audit redaction configuration whose paths array contains one malformed JSONPath expression (bare path without braces, unclosed brace, invalid selector).

Common situations: Mixed-style paths where some entries use kubectl-style braces and others are bare; hand-edited CRs.

Understand the failure class

Related errors


AI-assisted analysis of rancher/rancher@932558d4e6 (2026-08-16). Data as JSON: /api/errors/545f1f4f2b5ff969. Report an issue: GitHub.