Skip to content

Conversation

nathanhammond
Copy link

@nathanhammond nathanhammond commented Sep 24, 2025

Problem

list_owners calls self.get:

pub fn list_owners(&mut self, krate: &str) -> Result<Vec<User>> {
let body = self.get(&format!("/crates/{}/owners", krate))?;
Ok(serde_json::from_str::<Users>(&body)?.users)
}

Which, surprisingly, is configured to send Auth::Authorized:

fn get(&mut self, path: &str) -> Result<String> {
self.handle.get(true)?;
self.req(path, None, Auth::Authorized)
}

But the endpoint does not require auth:
https://crates.io/api/v1/crates/serde/owners

Important note: list_owners is the only one that actually calls .get.

Part of #16007

@rustbot rustbot added A-interacts-with-crates.io Area: interaction with registries S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 24, 2025
@rustbot
Copy link
Collaborator

rustbot commented Sep 24, 2025

r? @epage

rustbot has assigned @epage.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution!

Can we add a test for cargo owner --list demonstrating the problematic behavior? The test should pass in a standalone commit.

The second commit will contain both the fix and the test change diff, which the diff shows the behavior change.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR isn't priority for me; I just noticed the issue while reading the code. Determining how to add a test for a presently untested code path is well beyond the investment I have in this getting fixed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is understandable. Just call that out that this PR doesn't fix #16007 because of #16008 (comment)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let (mut registry, _) = super::registry(
gctx,
&source_ids,
opts.token.as_ref().map(Secret::as_deref),
opts.reg_or_index.as_ref(),
true,
Some(operation),
)?;

This code path super::registry still requires a token. This may need a bit more refactor

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, there is only a single instance in the entire codebase of something delegating to get. add_owners delegates to put which includes the authorization.

get is private, and list_owners is the only thing that calls it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code path I shown above unconditionally called before hitting get even for cargo owner --list. Granted, this PR standalone is good enough for fixing the issue in the crates-io crate.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just saw the token_required bit and how the read is being conflated with the owners add/remove operation.

I've caught up to you now. It's only the "back half" of the fix, and assumes that we don't throw a TokenMissing when we create the registry.

Thanks for your patience. ❤️ (Sorry, not an expert in this codebase, but you already knew that. 😜)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am fine merging this as-is. Let me edit the title a bit to reflect that.

@weihanglo weihanglo changed the title Make get requests Unauthorized fix(crates-io): list owner request unauthorized Sep 24, 2025
@weihanglo weihanglo added this pull request to the merge queue Sep 24, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Sep 24, 2025
Copy link
Contributor

@epage epage left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #16007

@rustbot rustbot added S-waiting-on-author Status: The marked PR is awaiting some action (such as code changes) from the PR author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 24, 2025
@epage
Copy link
Contributor

epage commented Sep 24, 2025

Part of #16007

What would be left after this PR for that issue?

@epage
Copy link
Contributor

epage commented Sep 24, 2025

Ah, my answer is in #16007 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-interacts-with-crates.io Area: interaction with registries S-waiting-on-author Status: The marked PR is awaiting some action (such as code changes) from the PR author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants