{"record":{"id":"96d8dc3ab05e4260","repo":"goharbor/harbor","slug":"no-credential-data-provided","errorCode":null,"errorMessage":"no credential data provided","messagePattern":"no credential data provided","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/pkg/p2p/preheat/provider/auth/handler.go","lineNumber":50,"sourceCode":"\tMode() string\n}\n\n// BaseHandler provides some basic functions like validation.\ntype BaseHandler struct{}\n\n// Mode implements @Handler.Mode\nfunc (b *BaseHandler) Mode() string {\n\treturn \"BASE\"\n}\n\n// Authorize implements @Handler.Authorize\nfunc (b *BaseHandler) Authorize(req *http.Request, cred *Credential) error {\n\tif req == nil {\n\t\treturn errors.New(\"nil request cannot be authorized\")\n\t}\n\n\tif cred == nil || cred.Data == nil {\n\t\treturn errors.New(\"no credential data provided\")\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":32,"sourceCodeEnd":55,"githubUrl":"https://github.com/goharbor/harbor/blob/7b2fd08cc568955cca339afeefab27372840d936/src/pkg/p2p/preheat/provider/auth/handler.go#L32-L55","documentation":"BaseHandler.Authorize (shared by all auth handlers in the P2P preheat provider package) rejects the call when the *http.Request is nil, or when the *Credential is nil / has a nil Data map. It is the first gate every mode-specific handler (BASIC, OAUTH, CUSTOM) runs before checking its own fields, so a nil credential masquerades as whichever mode error the outer handler would add — here, plain 'no credential data provided'.","triggerScenarios":"Calling provider.Client methods with a nil Credential (instance with no auth configured but code path still calling Authorize); passing a Credential whose Data map was never populated (auth_info absent on the instance); constructing handlers directly in Go code with a nil request.","commonSituations":"Instances registered without any auth_info at all (empty map or omitted) while the client still routes through an auth handler; edge cases in provider drivers that build credentials from empty instance metadata; unit tests instantiating handlers without fixtures.","solutions":["Ensure the preheat instance carries a non-empty auth_info appropriate for its auth_mode (BASIC: username/password pair; OAUTH: token key; CUSTOM: header key/value).","If no auth is required, set auth_mode \"NONE\" so the none-handler skips data entirely.","In Go code, guard before calling: if req == nil || cred == nil || len(cred.Data) == 0 { return errors.New(\"credential data required\") }."],"exampleFix":"// Go: before\nclient.Authorize(req, nil)\n// after\nif cred == nil || len(cred.Data) == 0 {\n    return errors.New(\"credential data required\")\n}\nclient.Authorize(req, cred)","handlingStrategy":"type-guard","validationCode":"// Go: guard before calling Authorize\nif req == nil || cred == nil || len(cred.Data) == 0 {\n    return errors.New(\"credential data required\")\n}","typeGuard":"// Go\nfunc hasAuthData(req *http.Request, cred *auth.Credential) bool {\n    return req != nil && cred != nil && cred.Data != nil && len(cred.Data) > 0\n}","tryCatchPattern":"This is a programming-contract error, not a runtime condition to retry: fix the caller to pass a non-nil request and a credential with data (or switch the instance to NONE auth), then re-run.","preventionTips":["Never construct provider clients with nil credentials; derive them from instance metadata with defaults.","Default auth_mode to NONE when instances are registered without auth_info.","Unit-test handler wiring with empty-instance fixtures."],"tags":["p2p-preheat","auth","credentials","nil-guard","harbor"],"backgroundTag":null,"analyzedSha":"7b2fd08cc568955cca339afeefab27372840d936","analyzedAt":"2026-08-16T00:00:10.961Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}