CompositeContentGuard should return a 401 authentication challenge when a sub-guard requires authentication
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 45/100
- Issue 类型
- 功能
- 描述清晰度
- 基本清楚
- 活跃度
- 活跃
- 技术栈
- python
- 领域
- api, authentication, backend
调研方向
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.
由索引模型根据 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:
- Authorization denied — the request has an identity, but that identity is not allowed.
403 Forbiddenis correct. - Authentication missing — the request carried no identity at all. The correct HTTP response is 401 Unauthorized with a
WWW-Authenticatechallenge, 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
- Introduce (or adopt) a distinct exception that a content guard can raise to mean "authentication required" rather than "forbidden" — e.g. an
AuthenticationErrorseparate fromPermissionError. - 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 genericPermissionError. (Authorization denials still collapse toPermissionError→ 403.) - In the content handler's
_permit(), translate the authentication-required error intoHTTPUnauthorized(401) with aWWW-Authenticatechallenge 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:
The patch:
- Catches a new
AuthenticationErrorinCompositeContentGuard.permit(), remembers the first one, and re-raises it after the loop if no guard passed. - Catches
AuthenticationErrorinhandler._permit()and raisesHTTPUnauthorizedwithWWW-Authenticate: Basic realm="packages.redhat.com". - Updates
auth_cached()to treatHTTPUnauthorizedlikeHTTPForbiddenand 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.
- 主要语言
- Python
- 星标
- 619
- 派生
- 176
- 平均合并
- 16 小时 49 分钟
- 30 天内合并 PR
- 126
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
pulp/pulpcore 的其他 Issue
-
Content cache ignores the query string, so one path serves the response cached for another query未关闭
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
Issue
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
Feature
难度 2/5 1-3 小时 新手友好度 62/100
维护者通常 1 天内回复
-
Issue Triage-Needed
难度 3/5 1-2 天 新手友好度 68/100
维护者通常 1 天内回复
-
Issue
难度 4/5 3-5 天 新手友好度 42/100
维护者通常 1 天内回复
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 86/100
-
Validate finite output clamping limits in StepPredictor.prepare_clamping_params to prevent silent NaN/Inf propagation可能已有人在做 @muskan-creates352 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 84/100
mllam/neural-lam#848 ·
维护者通常 2 天内回复
-
infra
难度 1/5 1 小时以内 新手友好度 88/100
fab-geocommuns/RNB-coeur#1166 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
deepspeedai/DeepSpeed#8951 ·
维护者通常 2 天内回复