goharbor/harbor · error · errors.UnauthorizedError

UNAUTHORIZED

UNAUTHORIZED

Error message

security context not found

What it means

Type-guard in ListAllRepositories: the security context is expected to be injected into the request context by auth middleware; when security.FromContext(ctx) returns !ok the request bypassed that middleware or the context was malformed, so the API returns Unauthorized. A sentinel guard for a missing context value, not a user mistake.

Solutions

  1. Ensure the request carries valid authentication (auth middleware must populate the security context)
  2. Retry with proper credentials/token
  3. If running behind a proxy, verify auth headers are forwarded correctly
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at src/server/v2.0/handler/repository.go:75 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of goharbor/harbor@7b2fd08cc5 (2026-08-16). Data as JSON: /api/errors/3414f609296f40d5. Report an issue: GitHub.

Appendix: source

Thrown at src/server/v2.0/handler/repository.go:75

func (r *repositoryAPI) ListAllRepositories(ctx context.Context, params operation.ListAllRepositoriesParams) middleware.Responder {
	// set query
	query, err := r.BuildQuery(ctx, params.Q, params.Sort, params.Page, params.PageSize)
	if err != nil {
		return r.SendError(ctx, err)
	}
	secCtx, ok := security.FromContext(ctx)
	if !ok {
		return r.SendError(ctx, errors.UnauthorizedError(errors.New("security context not found")))
	}

View on GitHub (pinned to 7b2fd08cc5)