grpc/grpc-go · error

"name" is not present

Error message

"name" is not present

What it means

Raised by translatePolicy right after JSON decode succeeds: the top-level "name" field of the gRPC authorization policy is mandatory and must be non-empty. The policy name is used as a prefix for every generated RBAC policy key, so an empty name would collide and is rejected before translation proceeds.

Source

Thrown at authz/rbac_translator.go:370

		return v3rbacpb.RBAC_AuditLoggingOptions_ON_DENY
	default:
		return v3rbacpb.RBAC_AuditLoggingOptions_NONE
	}
}

// translatePolicy translates SDK authorization policy in JSON format to two
// Envoy RBAC polices (deny followed by allow policy) or only one Envoy RBAC
// allow policy. Also returns the overall policy name. If the input policy
// cannot be parsed or is invalid, an error will be returned.
func translatePolicy(policyStr string) ([]*v3rbacpb.RBAC, string, error) {
	policy := &authorizationPolicy{}
	d := json.NewDecoder(bytes.NewReader([]byte(policyStr)))
	d.DisallowUnknownFields()
	if err := d.Decode(policy); err != nil {
		return nil, "", fmt.Errorf("failed to unmarshal policy: %v", err)
	}
	if policy.Name == "" {
		return nil, "", fmt.Errorf(`"name" is not present`)
	}
	if len(policy.AllowRules) == 0 {
		return nil, "", fmt.Errorf(`"allow_rules" is not present`)
	}
	allowLogger, denyLogger, err := policy.AuditLoggingOptions.toProtos()
	if err != nil {
		return nil, "", err
	}
	rbacs := make([]*v3rbacpb.RBAC, 0, 2)
	if len(policy.DenyRules) > 0 {
		denyPolicies, err := parseRules(policy.DenyRules, policy.Name)
		if err != nil {
			return nil, "", fmt.Errorf(`"deny_rules" %v`, err)
		}
		denyRBAC := &v3rbacpb.RBAC{
			Action:              v3rbacpb.RBAC_DENY,
			Policies:            denyPolicies,
			AuditLoggingOptions: denyLogger,

View on GitHub (pinned to 03255a9237)

Solutions

  1. Add a top-level "name" field with a unique, non-empty identifier for the policy.
  2. Ensure the name is unique across all policies loaded by the same interceptor set.
  3. Validate the policy JSON has a non-empty "name" in a pre-deploy lint.
  4. Generate policies from the SDK's documented example as a base template.

Example fix

// before:
{ "allow_rules": [ ... ] }   // no top-level name

// after:
{ "name": "payments-svc-policy", "allow_rules": [ ... ] }
Defensive patterns

Strategy: validation

Validate before calling

func validatePolicyName(policyStr string) error {
    var p struct {
        Name string `json:"name"`
    }
    if err := json.Unmarshal([]byte(policyStr), &p); err != nil { return err }
    if strings.TrimSpace(p.Name) == "" {
        return fmt.Errorf(`"name" is not present`) // mirrors SDK message
    }
    return nil
}

Prevention

When it happens

Trigger: The policy JSON decodes cleanly but the "name" field is missing or empty string. translatePolicy checks `policy.Name == ""` and returns this exact message (no index, since name is a top-level scalar).

Common situations: Forgetting the name field entirely; setting name to "" intentionally; building the policy from a template whose name placeholder wasn't substituted; assuming name is optional.

Related errors


AI-assisted analysis of grpc/grpc-go@03255a9237 (2026-08-07). Data as JSON: /api/errors/c53e6924ca61b84d. Report an issue: GitHub.