Skip to content

Proposal: auth helpers - #651

Closed
vlad-ivanov-name wants to merge 1 commit into
prefix-dev:mainfrom
vlad-ivanov-name:vlad/auth-helpers
Closed

vlad-ivanov-name wants to merge 1 commit into
prefix-dev:mainfrom
vlad-ivanov-name:vlad/auth-helpers

Conversation

@vlad-ivanov-name

Copy link
Copy Markdown
Contributor

No description provided.

@baszalmstra

Copy link
Copy Markdown
Contributor

@vlad-ivanov-name Thanks for the write-up! I think the general idea of authentication helpers in this way is pretty clever!

This is already a little technical but I'm wondering if this is something we could implement in rattlers AuthenticatedClient. That way not only rip (for python dependencies) would benefit from this but we could also use it for conda packages. Did you think about the technical details already? WDYT?

@ruben-arts ruben-arts left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Great proposal! Left one question, could you clarify that?

Comment on lines +34 to +36
A number of authentication helpers is shipped together with `pixi`. However, the interface between `pixi` and authentication helpers is documented, and it's expected that users may add a helper specific to their usecase.

Authentication helpers are loosely inspired by `GIT_ASKPASS`, and authentication helpers in Docker and Flyte.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you clarify this a little more, is your proposal to ship multiple binaries with together with pixi or are there commands that will be called. Or maybe pixi can install them when needed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Given that pixi is a package manager that can install packages, we could also ship them as conda dependencies of the project perhaps.

@vlad-ivanov-name vlad-ivanov-name Jan 11, 2024 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@ruben-arts yes the intention was to ship multiple binaries. I think this is the simplest way.

@baszalmstra the issue here is that the binary should be available before all the other packages are installed. Is this something already supported?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I could see a future where you might have to update the helpers without updating the version of pixi. Wouldn't that make it easier if we support them as conda packages. The logic for "pre installing" is not really in yet. But we have something in the works for installing python before the pypi solve so it shouldn't be that hard to add.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We could also implement this by having hard coded implementations and "fallback" commands to execute instead of having to ship multiple binaries. Having multiple binaries complicates the distribution of releases.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Im curious what that would look like! Do you mean something along the lines of pixi auth-helper x. If x is built-in it would use that but otherwise it tries to find the executable pixi-auth-helper-x?

Correct

@vlad-ivanov-name vlad-ivanov-name Jan 11, 2024 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Regarding bundling and installation: what are the downsides of bundling and versioning everything together? The way I see it, having helpers as separate packages just creates noise. It's much easier mentally to understand that pixi vX.Y supports auth with provider "N", than to find out specific auth helper version and to check that.

Also, keep in mind that separate versioning means that there's an API version that we will need to consider -- API between helpers and pixi. In future it might create situation where pixi vX.Y is not compatible with auth helper vN.P. Dealing with semver requirements there would introduce additional complexity.

And if providers need to be updated, it's not a big deal -- a new version of pixi can be released, users don't care where exactly the change occurred, so from the point of UX an update is an update anyway.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I have to think about this for a bit.

We could easily encode the API version in a package that the authentication helper would need to depend on. When installing an environment for the auth helper we would simply include the requirement 'pixi-auth-helper-api=1.0'.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Just to clarify - my main goal is to get this in in any way, shape or form with least amount of work. You have authority on the project -- so if you say to change this to your proposed solution, I will -- just let me know :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

To not get stuck on the distribution details before we have an working example. Lets continue with a separate binary that we might merge in or not when we decide what we do with this part.

I think the implementation is not an overnight thing so I guess you could start on the implementation of supporting any (not just private) pypi index to get started.

@vlad-ivanov-name

Copy link
Copy Markdown
Contributor Author

This is already a little technical but I'm wondering if this is something we could implement in rattlers AuthenticatedClient. That way not only rip (for python dependencies) would benefit from this but we could also use it for conda packages. Did you think about the technical details already? WDYT?

Yes I started looking into using AuthenticatedClient. I could see this being used for conda channels as well -- just need to come up with toml syntax

@ruben-arts

Copy link
Copy Markdown
Contributor

I'm curious how we would test this feature in CI. In the tests/ we have a package database builder. But I assume we need something alike for testing this with multiple pypi indices. Did you already have some ideas on that front?

@vlad-ivanov-name

Copy link
Copy Markdown
Contributor Author

I'm curious how we would test this feature in CI. In the tests/ we have a package database builder. But I assume we need something alike for testing this with multiple pypi indices. Did you already have some ideas on that front?

I wonder how difficult it would be to build a small, simple pip registry server (if it can even be small and simple). I'd say for stuff like that I'd write an integration test that spawns a local server (implemented with e. g. axum -- really cool framework) and add snapshot tests with something like insta

@ruben-arts

Copy link
Copy Markdown
Contributor

I'm curious how we would test this feature in CI. In the tests/ we have a package database builder. But I assume we need something alike for testing this with multiple pypi indices. Did you already have some ideas on that front?

I wonder how difficult it would be to build a small, simple pip registry server (if it can even be small and simple). I'd say for stuff like that I'd write an integration test that spawns a local server (implemented with e. g. axum -- really cool framework) and add snapshot tests with something like insta

I think this would be cool, @tdejager you think this could be part of rip?


Upon failure, authentication helpers exit with code other than `0`. Authentication helpers must print a human-readable error message to stderr. `pixi` will relay the message back to the user.

Authentication helpers are never launched in interactive mode. Authentication helpers never receive user input over `stdin`, and can't print any additional information upon success.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why not? For an oauth2 flow one might need to open a url, login and paste a token into the terminal.
This works for example in the AWS CLI https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-sourcing-external.html

@vlad-ivanov-name vlad-ivanov-name Feb 13, 2024 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point. Initially I wanted to avoid situations where actual token is input by user, or username / password — that should be the job of the existing auth mechanisms. Also, non interactive is simple - user interface adds a lot of different complexity levels. But you’re right, there are indeed flows that would require user input. Perhaps a non interactive can be implemented first, and interactive auth can be next iteration? Because I feel like it will need some thoughtful API design

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

As a follow-up: perhaps we can implement non-interactive first and then add interactive support afterwards, but with a catch: I think if we do support interactive auth at some point, pixi should keep control over it, meaning that the flow is expressed as a series of function calls returning predefined types. The variations of flows therefore would be restricted, and pixi would be able to set up the UX of these flows exactly consistent across different auth helpers. This also means no direct connection between e. g. stdin of pixi and stdout of auth helper would be established

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Implementating non-interactive first makes sense. I was just scared of the never in the sentence.
Regarding the interface to interactive auth helpers I would argue to postpone the discussion how it looks like to a later stage. Also worth looking at how other tools do it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Well "never" in this context means something like in RFCs -- "never in this revision of the design". It's just a note to implementors that if they'd like to implement something differently, the spec should be changed too. It's just a file in git repo after all :)


Authentication helper is a program that receives an URL to the package registry as an input and outputs a JSON object containing the credentials. Authentication helpers can utilize different methods for obtaining credentials, but it's expected that they are specific to the package host implementation.

Authentication helper is a runnable binary available in `PATH`. The name of the binary must start with `pixi-auth-` and followed by its unique ID.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why add this restriction now? What if another package or CLI tool already provides the needed functionality to return the username/password JSON? I would recommend to keep this more flexible, which means just allowing specifying a path to any binary / shell.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think it’s a good convention that indicates specific API compatibility. It’s unlikely to clash with anything, and if there’s an existing tool, it’s easy to write a wrapper for it. I would argue that no existing tool provides the interface because the interface doesn’t exist yet.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's a 5 minutes thing to implement something like aws sts assume-role ... | jq '...' which returns the desired {"username": "...", "password": "..."} JSON compared to creating wrapper packages and shipping them to pypi/conda-forge which takes even someone experienced at least a few hours.
My point is that almost any existing tool can be converted to the interface you are proposing with a few lines of code.

@vlad-ivanov-name vlad-ivanov-name Feb 14, 2024 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes. Then you rename your wrapper to “pixi-auth-aws” and you can start using it :) there is no need to ship it as a package with proposed design - enabling users to add helpers as you describe is one of the main points.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants