{"record":{"id":"fa2d026e54a1134a","repo":"hyperledger/fabric","slug":"policy-s-must-be-defined-for-channel-s-befor","errorCode":null,"errorMessage":"policy '%s' must be defined for channel '%s' before chaincode operations can be attempted","messagePattern":"policy '(.+?)' must be defined for channel '(.+?)' before chaincode operations can be attempted","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/chaincode/lifecycle/lifecycle.go","lineNumber":382,"sourceCode":"\t}\n\n\treturn approvals, nil\n}\n\n// DefaultEndorsementPolicyAsBytes returns a marshalled version\n// of the default chaincode endorsement policy in the supplied channel\nfunc (ef *ExternalFunctions) DefaultEndorsementPolicyAsBytes(channelID string) ([]byte, error) {\n\tchannelConfig := ef.Resources.ChannelConfigSource.GetStableChannelConfig(channelID)\n\tif channelConfig == nil {\n\t\treturn nil, errors.Errorf(\"could not get channel config for channel '%s'\", channelID)\n\t}\n\n\t// see if the channel defines a default\n\tif _, ok := channelConfig.PolicyManager().GetPolicy(DefaultEndorsementPolicyRef); ok {\n\t\treturn DefaultEndorsementPolicyBytes, nil\n\t}\n\n\treturn nil, errors.Errorf(\n\t\t\"policy '%s' must be defined for channel '%s' before chaincode operations can be attempted\",\n\t\tDefaultEndorsementPolicyRef,\n\t\tchannelID,\n\t)\n}\n\n// SetChaincodeDefinitionDefaults fills any empty fields in the\n// supplied ChaincodeDefinition with the supplied channel's defaults\nfunc (ef *ExternalFunctions) SetChaincodeDefinitionDefaults(chname string, cd *ChaincodeDefinition) error {\n\tif cd.EndorsementInfo.EndorsementPlugin == \"\" {\n\t\t// TODO:\n\t\t// 1) rename to \"default\" or \"builtin\"\n\t\t// 2) retrieve from channel config\n\t\tcd.EndorsementInfo.EndorsementPlugin = \"escc\"\n\t}\n\n\tif cd.ValidationInfo.ValidationPlugin == \"\" {\n\t\t// TODO:","sourceCodeStart":364,"sourceCodeEnd":400,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/chaincode/lifecycle/lifecycle.go#L364-L400","documentation":"The channel exists, but its config does not define a policy named by DefaultEndorsementPolicyRef (default endorsement policy /channel/config style ref). Lifecycle refuses to fabricate a policy and requires the channel to explicitly define it before chaincode operations proceed.","triggerScenarios":"Approving or committing a chaincode definition on a channel whose config lacks the '/Channel/Application/<DefaultEndorsementPolicyRef>' policy while no explicit endorsement policy is supplied in the definition.","commonSituations":"Channels created from old genesis templates that predate the default endorsement policy; custom channel profiles missing the application policy; operators assuming an implicit default policy exists.","solutions":["Define the required default policy in the channel config (update the channel config to include the application-level endorsement policy)","Supply an explicit endorsement policy in the chaincode definition so the default is not needed","Regenerate the channel genesis from a current configtx profile that includes the default policy"],"exampleFix":"// before (relying on missing channel default)\ndefinition := &lifecycle.ChaincodeDefinition{Sequence: 1}\n// after (explicit policy)\ndefinition := &lifecycle.ChaincodeDefinition{Sequence: 1, EndorsementPolicy: policyBytesFromApplicationPolicy(\"MAJORITY Endorsement\")}","handlingStrategy":"validation","validationCode":"// Pre-check that the channel defines the default endorsement policy\ncc := ccSource.GetStableChannelConfig(ch)\nif cc == nil { return fmt.Errorf(\"no channel config for %q\", ch) }\nif _, ok := cc.PolicyManager().GetPolicy(lifecycle.DefaultEndorsementPolicyRef); !ok {\n    return fmt.Errorf(\"channel %q must define policy %s\", ch, lifecycle.DefaultEndorsementPolicyRef)\n}","typeGuard":null,"tryCatchPattern":"bytes, err := ef.DefaultEndorsementPolicyAsBytes(ch)\nif err != nil {\n    if strings.Contains(err.Error(), \"must be defined for channel\") {\n        // fall back to supplying an explicit endorsement policy\n    }\n    return err\n}","preventionTips":["Use current configtx profiles that include the default application endorsement policy","Audit channel configs after channel creation for required policies","Supply explicit endorsement policies in definitions to avoid dependence on channel defaults"],"tags":["fabric","endorsement-policy","channel-config"],"backgroundTag":"policy-not-defined","analyzedSha":"2736b63f8fd5932511d56fe68b7039d15977f7f6","analyzedAt":"2026-09-04T08:52:36.465Z","contentChangedAt":"2026-09-04T08:52:36.465Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}