Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Project-scoped API tokens] aren't available to maintainers #6262

Closed
webknjaz opened this issue Jul 25, 2019 · 4 comments · Fixed by #6301
Closed

[Project-scoped API tokens] aren't available to maintainers #6262

webknjaz opened this issue Jul 25, 2019 · 4 comments · Fixed by #6301
Assignees
Labels
bug 🐛 tokens Issues relating to API tokens

Comments

@webknjaz
Copy link
Member

Describe the bug

When I use a "bot" account with "Maintainer" level access to projects, there are no projects to select from in the form for the token creation.

Expected behavior

Since this "bot" can upload dists using user/password auth, it should also have similar privileges set when using tokens.

To Reproduce

Go to https://pypi.org/manage/account/token and try selecting a project where you have only "Maintainer"-level access, not "Owner".

My Platform

N/A

Additional context

N/A

@brainwane brainwane added the requires triaging maintainers need to do initial inspection of issue label Jul 25, 2019
@brainwane brainwane added this to the OTF Security work milestone Jul 25, 2019
@brainwane brainwane added bug 🐛 raised in user testing and removed requires triaging maintainers need to do initial inspection of issue labels Jul 26, 2019
@brainwane
Copy link
Contributor

Yup, I can confirm this. If I am logged in as a user who has maintainer-level collaborator status on a project, that project does not appear in the Scope dropdown list at manage/account/token/.

This is a bug IMO and we should fix it before further publicizing the feature (per rollout tracked in #5661).

Thanks for finding and reporting this bug @webknjaz! 🏆

@woodruffw
Copy link
Member

Hmm, yeah, this is probably just a matter of how/which projects we iterate over for the user.

I'll check this out, thanks @webknjaz!

@webknjaz
Copy link
Member Author

just a matter of how/which projects we iterate over

That's my guess too.

@di di added the tokens Issues relating to API tokens label Jul 29, 2019
@woodruffw
Copy link
Member

Yeah, here's the root-cause: We use the user_projects helper in manage/views.py, which returns projects based on just ownership:

def user_projects(request):
    """ Return all the projects for which the user is a sole owner """
    projects_owned = (
        request.db.query(Project.id)
        .join(Role.project)
        .filter(Role.role_name == "Owner", Role.user == request.user)
        .subquery()
    )

    with_sole_owner = (
        request.db.query(Role.project_id)
        .join(projects_owned)
        .filter(Role.role_name == "Owner")
        .group_by(Role.project_id)
        .having(func.count(Role.project_id) == 1)
        .subquery()
    )

    return {
        "projects_owned": (
            request.db.query(Project)
            .join(projects_owned, Project.id == projects_owned.c.id)
            .order_by(Project.name)
            .all()
        ),
        "projects_sole_owned": (
            request.db.query(Project).join(with_sole_owner).order_by(Project.name).all()
        ),
    }

We could either amend that helper to include a sub-dict for maintainer roles as well, or add a new helper just for macaroons that returns just project names for those two roles.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 tokens Issues relating to API tokens
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants