hyperledger/fabric · error
identity index out of range, requested %v, but identities le
Error message
identity index out of range, requested %v, but identities length is %d
What it means
Thrown by the policy compiler in common/cauthdsl when a *cb.SignaturePolicy_SignedBy rule references an identity index that is negative or beyond the number of identities declared in the SignaturePolicyEnvelope. The compiler protects the subsequent identities[t.SignedBy] lookup from an out-of-range panic.
Source
Thrown at common/cauthdsl/cauthdsl.go:63
for _, policy := range policies {
copy(_used, used)
if policy(signedData, _used) {
verified++
copy(used, _used)
}
}
if verified >= t.NOutOf.N {
cauthdslLogger.Debugf("%p gate %d evaluation succeeds", signedData, grepKey)
} else {
cauthdslLogger.Debugf("%p gate %d evaluation fails", signedData, grepKey)
}
return verified >= t.NOutOf.N
}, nil
case *cb.SignaturePolicy_SignedBy:
if t.SignedBy < 0 || t.SignedBy >= int32(len(identities)) {
return nil, fmt.Errorf("identity index out of range, requested %v, but identities length is %d", t.SignedBy, len(identities))
}
signedByID := identities[t.SignedBy]
return func(signedData []msp.Identity, used []bool) bool {
cauthdslLogger.Debugf("%p signed by %d principal evaluation starts (used %v)", signedData, t.SignedBy, used)
for i, sd := range signedData {
if used[i] {
cauthdslLogger.Debugf("%p skipping identity %d because it has already been used", signedData, i)
continue
}
if cauthdslLogger.IsEnabledFor(zapcore.DebugLevel) {
// Unlike most places, this is a huge print statement, and worth checking log level before create garbage
cauthdslLogger.Debugf("%p processing identity %d - %v", signedData, i, sd.GetIdentifier())
}
err := sd.SatisfiesPrincipal(signedByID)
if err != nil {
cauthdslLogger.Debugf("%p identity %d does not satisfy principal: %s", signedData, i, err)
continue
}View on GitHub (pinned to 2736b63f8f)
Solutions
- Ensure every SignedBy index in the rule tree is within [0, len(Identities)-1] of the same envelope
- Regenerate the policy from source (e.g. configtxgen / policygen tooling) instead of hand-editing serialized bytes
- Log len(sigPolicy.Identities) and walk the rule tree before calling compile to find the offending index
Example fix
// before
env.Rule = &cb.SignaturePolicy{Type: &cb.SignaturePolicy_SignedBy{SignedBy: 3}} // only 2 identities
// after
env.Identities = append(env.Identities, mspPrincipalForPeerOrg3)
env.Rule = &cb.SignaturePolicy{Type: &cb.SignaturePolicy_SignedBy{SignedBy: 2}} // index now valid Defensive patterns
Strategy: validation
Validate before calling
func validateSignedByIndexes(rule *cb.SignaturePolicy, ids []*msp.MSPPrincipal) error {
switch t := rule.GetType().(type) {
case *cb.SignaturePolicy_SignedBy:
if t.SignedBy < 0 || int(t.SignedBy) >= len(ids) {
return fmt.Errorf("SignedBy %d out of range for %d identities", t.SignedBy, len(ids))
}
case *cb.SignaturePolicy_NOutOf_:
for _, r := range t.NOutOf.Rules {
if err := validateSignedByIndexes(r, ids); err != nil {
return err
}
}
}
return nil
} Type guard
func signedByInRange(rule *cb.SignaturePolicy, n int) bool {
sb, ok := rule.GetType().(*cb.SignaturePolicy_SignedBy)
return ok && sb.SignedBy >= 0 && int(sb.SignedBy) < n
} Prevention
- Always build rules and the Identities list together from one source of truth
- Walk the full nested rule tree, not just the top level, when validating indexes
- Round-trip marshal/unmarshal the envelope and re-validate before persisting
When it happens
Trigger: Calling compile (directly or via provider.NewPolicy / EnvelopeBasedPolicyProvider.NewPolicy) with a SignaturePolicyEnvelope whose Rule contains SignedBy: N where N < 0 or N >= len(sigPolicy.Identities), e.g. after editing policy protobufs by hand or deserializing a truncated/corrupt policy.
Common situations: Hand-crafted or tool-generated channel application policies referencing principal indexes that were never added to the Identities list; policies serialized by newer tooling than the reader; byte-level corruption during storage or endorsement.
Related errors
- Unknown type: %T:%v
- policy with reference '%s' on channel '%s' is not convertibl
- invalid signature policy: %s
- Empty policy element
- Error unmarshalling to SignaturePolicy: %s
AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04).
Data as JSON: /api/errors/e8193e89e4fe1e4e.
Report an issue: GitHub.