Enable user-level management of index credentials via uv (& keyring)#9920
Enable user-level management of index credentials via uv (& keyring)#9920stoney95 wants to merge 32 commits intoastral-sh:mainfrom
Conversation
|
It would be nice to add a |
|
@bschoenmaeckers, I think adding One part is implementing an The other part is providing a |
|
@stoney95 Thx for starting integration of kering-rs into uv! How to use credentials already defined in credential store? |
|
@zanieb, clippy is configured to not allow the usage of |
|
I was super curious whether it would be difficult to interact with keyring-rs directly, so I quickly implemented alternative Credential constructor (tests are necessary!), but it works with locally configured auth.toml and hand-crafted secret in keychain already.. I like what you tried to achieve, but I think it would be good to implement the configuration to be similar to poetry, so users don't have to think and be surprised. Have a look here: https://github.com/astral-sh/uv/compare/main...lejmr:uv:simple-poetry-like-version?expand=1 |
|
@lejmr, thanks for your suggestion. To clarify, I see two suggestions made from your end.
Do you agree with this summary? Personal opinion
|
|
Hey @stoney95 sorry I missed your ping! Reviewing this is on my queue but I'm working through that holiday backlog still. Regarding
We use |
|
@stoney95, let me write my grains of salt..
Add/Rm etc is bad naming to me because what really happens is upsert, so add is confusing.
Regards 2), I think your implementation is just more complicated than what is necessary. I took shortcut by implementing
|
|
@lejmr, thanks for explaining your suggestion in more details :) NamingI would opt for Keyring crate / Complicated implementationI am using If I understand your suggestion correctly we could modify So, we could make |
|
Keyring) if we modify ::from_url, so it loads username from auth.toml for the given URL, we don't need the from_keyring at all because the secret is loaded by middleware, https://github.com/stoney95/uv/blob/main/crates/uv-auth/src/middleware.rs#L203 - which is already existing code, so we won't create any duplicity. |
|
How will this interact with the index url in the uv-receipt.toml file created when installing tools with Context: We frequently rotate Artifactory tokens on clients, where we also update the token on the various tools that use them (poetry, pip, npm etc). Currently, uv is a bit of a pain to update due to these uv-receipt.toml files for each tool installed. This PR will help a lot with robustly updating credentials for uv, but I hope that this will work for tools installed with uv as well. |
|
@lejmr, I moved the logic for loading the username to @nbaju1, I can't answer if this will work for tools as well. I assume that managing tools will also rely on the middleware. So, it should work, but I think the others in this thread are better suited to answer this question. |
|
@zanieb, could you give this PR a review? :) |
|
@charliermarsh, can you take a look at this PR? Or is there anything that's still missing to give it a review? |
|
We're still figuring out how credential management fits into our larger user story. Projects like this involve a significant amount of design work on our end, which usually happens before a pull request is opened. In this case, the pull request will need to wait until we do that work so we can make sure it's aligned with our designs. It's nice to have this for inspiration, but it's a big deal to add a whole new interface to uv like this and we need to approach solutions carefully and holistically as we will be responsible for maintaining it in perpetuity. |
|
Thanks for sharing your - and the uv-team's - perspective, @zanieb. Did you discuss the topic internally already and can you share what you are currently considering? In case I can support the design phase in some way or another, please let me know. |
Merging this PR will improve performance by 7.29%
Performance Changes
Comparing |
Summary
Currently reading credentials from
keyringis only supported when a username is provided in the URL of the index. This prohibits to define indexes - in pyproject.toml - that are shared within a team. See these two issues for further details:In general this PR provides two things:
Setting credentials for an index via CLI
With this MR you can run
uv index credentials add --name <name-of-the-index> [--username <username>]This will ask for the password of the user. A keyring entry will be made with the url of the index, the username and the password. The username and the index will be appended to "<uv_cache_dir>/auth.toml". "auth.toml" has the following structure
Using credentials
When reading the credentials in
uv_distribution_types::index::Index.credentialsit's now additionally checked if credentials have been configured via "<uv_cache_dir>/auth.toml" andkeyring. The current implementation of reading the credentials from the environment variablesUV_INDEX_XXXhas priority overkeyringauthentication.Test Plan
I have added unit tests to the newly defined
uv_auth::keyring_configwhich takes care of loading, storing and modifying the auth configuration.I also want to add a test for
uv_auth::credentials::Credentials.from_keyring. But am currently struggling with mocking keyring and config file.I manually tested the new command
uv index credentials add --name <name-of-the-index>as I could not find examples for testing commands.Further remarks
I am a noobie in this context
=> I am curious about your opinion and suggestions for improvements
Not completely ready
The current version of the PR is a draft. Especially in regards of error handling and logging. Also testing can be improved.
I open this PR to discuss the direction in which the implementation is heading. As I am new to rust & uv I would also like to receive your guideance upfront 🙂