argoproj/argo-workflows · error

failed to decode bearer token's JWT payload: %w

Error message

failed to decode bearer token's JWT payload: %w

What it means

ClaimSetWithBearerToken splits the service-account bearer token into its three JWT dot-delimited parts and base64-decodes the payload; this wraps a base64 decode failure of that payload. It fires when the token used for SSO/service-account authentication is not a properly encoded JWT (corrupted or hand-crafted payload), so claims cannot be extracted by ClaimSetFor.

Source

Thrown at server/auth/serviceaccount/claims.go:52

func ClaimSetWithBearerToken(restConfig *rest.Config) (*types.Claims, error) {
	bearerToken := restConfig.BearerToken
	if bearerToken == "" {
		// should only ever be used for service accounts
		data, err := os.ReadFile(restConfig.BearerTokenFile)
		if err != nil {
			return nil, fmt.Errorf("failed to read bearer token file: %w", err)
		}
		bearerToken = string(data)
	}

	parts := strings.SplitN(bearerToken, ".", 3)
	if len(parts) != 3 {
		return nil, fmt.Errorf("expected bearer token to be a JWT and therefore have 3 dot-delimited parts")
	}
	payload := parts[1]
	data, err := base64.RawStdEncoding.DecodeString(payload)
	if err != nil {
		return nil, fmt.Errorf("failed to decode bearer token's JWT payload: %w", err)
	}

	claims := &types.Claims{}
	err = json.Unmarshal(data, &claims)
	if err != nil {
		return nil, fmt.Errorf("failed to unmarshal bearer token's JWT payload: %w", err)
	}

	// attempt to derive SA name and namespace from Subject
	// "system:serviceaccount:argo:jenkins" -> "argo", "jenkins"
	// note that the SA name can have a colon in it, although the rest cannot
	parts = strings.SplitN(claims.Subject, ":", 4)
	if len(parts) < 4 {
		return claims, nil
	}
	claims.ServiceAccountNamespace = parts[2]
	claims.ServiceAccountName = parts[3]

View on GitHub (pinned to 35bff19146)

Solutions

  1. Check the token is copied fully without truncation or URL-unsafe mutations
  2. Re-mount or regenerate the service account token
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at server/auth/serviceaccount/claims.go:52 when the library encounters an invalid state.

Common situations: See trigger scenarios.

Understand the failure class


AI-assisted analysis of argoproj/argo-workflows@35bff19146 (2026-09-03). Data as JSON: /api/errors/dd8229913892b69c. Report an issue: GitHub.