Skip to content

Refactor authentication mechanisms #7266

@ewdurbin

Description

@ewdurbin

Motivation

Two authenticate issues were reported by @ewjoachim which both came down to our global authentication policy.

Web UI Authentication and 2FA bypass via API Tokens (Macaroons)

API tokens are advertised as only being valid for uploads, however by setting the appropriate header, Authorization: token pypi-....., requests for arbitrary actions could be made with the equivalent of a standard session.

Thus leaked API tokens regardless of scope may have had a much bigger impact than advertised (uploading rogue releases vs deleting releases/projects or modifying user account components)

Initially resolved in: #7184

Web UI 2FA bypass via Basic Auth

Similar to above, constructing and setting the appropriate header, Authorization: Basic <base64>, requests for arbitrary actions could be made with the equivalent of a standard session.

Thus, 2FA bypass was possible if an attacker had the username and password for a user.

Initially resolved in: #7186

Initial Discussion

After report, while verifying and implementing the above fixes @dstufft some longer term solutions to avoid these kinds of issues:

A view deriver that can be applied to the view_config that flags it as accepting specific authentication types:

def api_view(view, info):
    if info.options.get("is_api"):
        @functools.wraps(view)
        def wrapped(context, request):
            # Somehow check the authentication mechanism and reject if not Macaroon or Basic Auth
            return view(context, request)
    else:
        @functools.wraps(view)
        def wrapped(context, request):
            # Same as above, but the inverse
            return view(context, request)
    return wrapped

Another suggestion was running API/upload hosts with specific configurations to enable the appropriate methods.

Ultimately this issue is being opened to discuss alternative approaches and decide on a path forward.

Metadata

Metadata

Assignees

No one assigned

    Labels

    2FAneeds discussiona product management/policy issue maintainers and users should discusssecuritySecurity-related issues and pull requests

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions