Skip to content

Conversation

magnalite
Copy link
Contributor

@magnalite magnalite commented Aug 4, 2021

This PR is the implementation of public authentication! It closes issue #8, see that for more info.

This PR:

  • Adds support for associating an oauth client id with a registry
  • Allows wally login to ask for an api key or present an oauth flow if the registry has an oauth client id
  • Allows storage of authentication tokens on a per registry basis
  • Enables the registry backend to accept oauth tokens as authentication by verifying them against the github api
  • Creates owners.json files in scopes to track ownership and enable ownership by multiple users (although no command to do so exists yet)

@magnalite magnalite marked this pull request as ready for review August 5, 2021 16:59
let response = client
.get("https://api.github.com/user")
.header("accept", "application/json")
.header("user-agent", "wally")
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be UpliftGames/wally? I vaguely remember GitHub requesting that you do that.

Copy link
Contributor Author

@magnalite magnalite Aug 5, 2021

Choose a reason for hiding this comment

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

If I understand the documentation correctly then this is our oauth application name, not our repo name.

&self.github
}

pub fn can_write_package(
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is a little more than can_write_package because it also mutates the index if the user can write. In the future, we might have an API endpoint for the frontend where we might want to just check if the user can write.

Additionally, can_do_x would usually return a bool! This is more like... "let me write to this package"

What's a better name for this method?

Copy link
Contributor Author

@magnalite magnalite Aug 5, 2021

Choose a reason for hiding this comment

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

This is a good point! I've kept the name and changed this to return a bool for "if the user should be allowed to write a package". Ie they can have permission but not be an owner. We therefore then later check to see if they are an owner and if they aren't we add them as we know they have authorization to write. This seems to make far more semantic sense!

Comment on lines 175 to 179
AuthMode::ApiKey(key) => match_api_key(request, key, Self { github: None }),
AuthMode::DoubleApiKey { write, .. } => {
match_api_key(request, write, Self { _dummy: 0 })
match_api_key(request, write, Self { github: None })
}
AuthMode::GithubOAuth => verify_github_token(request).await,
Copy link
Contributor

Choose a reason for hiding this comment

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

Having github: None in all non-GitHub auth cases is a little funny. I think we've got a couple options to make this struct fit our intent a little better.

I think my favorite is to make WriteAccess an enum:

pub enum WriteAccess {
    /// Granted from a global API key; the user can do whatever they want!
    Global,

    /// Granted from a GitHub login; the user has limited scope
    GitHub(GitHubInfo)
}

This makes our matches a little more semantically clear, as a nice bonus.

Copy link
Contributor Author

@magnalite magnalite Aug 5, 2021

Choose a reason for hiding this comment

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

I forget how nice Rust enums are! I've used Global to indicate everyone has this access and ApiKey to indicate if they have access because of an api key. Having Global vs ApiKey doesn't make any functional difference atm but does add a lot of meaning, for example WriteAccess doesn't have a Global as we intentionally don't support that. Doing this has really cleaned up stuff semantically and it's all feeling incredibly clean!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually I've decided to use Public instead of Global. I realised you probably meant global as in "access to all packages" so my usage could be confusing.

@magnalite magnalite requested a review from LPGhatguy August 6, 2021 13:45
@magnalite magnalite linked an issue Aug 9, 2021 that may be closed by this pull request
@magnalite magnalite merged commit b23da10 into main Sep 29, 2021
@magnalite magnalite deleted the public-auth-impl branch September 29, 2021 18:16
@magnalite magnalite added this to the Essential feature complete milestone Jun 13, 2023
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.

Authentication for public registries
2 participants