Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

CompositeContentGuard should return a 401 authentication challenge when a sub-guard requires authentication

Abierto
#8,245 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
45/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
python

Línea de trabajo

Read pulpcore/app/models/publication.py and pulpcore/content/handler.py, then inspect the content guard and handler tests for permission failures and cached authentication. Implement the configurable authentication challenge across composite guards and the handler. Done means missing authentication returns 401 with WWW-Authenticate, authorization denial remains 403, and an allowed sub-guard still permits access.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Issue

Problem

CompositeContentGuard.permit() evaluates its sub-guards with OR semantics: the first guard that passes permits the request, and if all guards fail it raises a single PermissionError. The content app handler translates that PermissionError into an HTTP 403 Forbidden.

This conflates two distinct situations:

  1. Authorization denied — the request has an identity, but that identity is not allowed. 403 Forbidden is correct.
  2. Authentication missing — the request carried no identity at all. The correct HTTP response is 401 Unauthorized with a WWW-Authenticate challenge, so the client knows it should authenticate and retry.

Because CompositeContentGuard only knows about PermissionError, a request that fails purely for lack of authentication still gets a flat 403. A client (e.g. a package manager, or a browser behind basic auth) never receives the WWW-Authenticate challenge and has no signal to supply credentials.

Current behavior

pulpcore/app/models/publication.py — CompositeContentGuard.permit():

for guard in self.guards.all():
    detail_guard = guard.cast()
    try:
        detail_guard.permit(request)
        return  # success on first-pass
    except PermissionError as pe:
        errors.append(...)

# If we get here - FAIL
raise PermissionError(_("Access forbidden. Refusals: {}").format(errors))

pulpcore/content/handler.py — _permit() maps any PermissionError to HTTPForbidden (403). There is no path that produces a 401 with a WWW-Authenticate header.

Proposed behavior

  1. Introduce (or adopt) a distinct exception that a content guard can raise to mean "authentication required" rather than "forbidden" — e.g. an AuthenticationError separate from PermissionError.
  2. In CompositeContentGuard.permit(), track whether any sub-guard raised the authentication-required error. If no guard passes and at least one raised authentication-required, re-raise that authentication error instead of the generic PermissionError. (Authorization denials still collapse to PermissionError → 403.)
  3. In the content handler's _permit(), translate the authentication-required error into HTTPUnauthorized (401) with a WWW-Authenticate challenge header. Also update the cached-auth path so a 401 is handled like a 403 (not cached as a pass).

This preserves the OR semantics: if any guard permits, access is granted; a 401 is only returned when the sole reason for failure is missing authentication.

Reference implementation

pulp-service already carries this as a downstream patch and it works in production for packages.redhat.com:

https://github.com/pulp/pulp-service/blob/main/images/assets/patches/0078-Return-authentication-challenge-for-missing-identity.patch

The patch:

  • Catches a new AuthenticationError in CompositeContentGuard.permit(), remembers the first one, and re-raises it after the loop if no guard passed.
  • Catches AuthenticationError in handler._permit() and raises HTTPUnauthorized with WWW-Authenticate: Basic realm="packages.redhat.com".
  • Updates auth_cached() to treat HTTPUnauthorized like HTTPForbidden and to avoid caching when the guard result is indeterminate.

Upstreaming this would require a general mechanism (the realm / challenge value should be configurable rather than hard-coded), but the core behavior — a composite guard surfacing an authentication challenge instead of a blanket 403 — belongs in pulpcore.

Lenguaje dominante
Python
Estrellas
619
Forks
176
Merge medio
16 h 51 min
PR fusionados (30 d)
117

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de pulp/pulpcore

Todos los issues de pulp/pulpcore

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.