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

[ISSUE-897] Add ANONYMOUS Permission #917

Merged
merged 10 commits into from
Apr 23, 2024

Conversation

seonWKim
Copy link
Contributor

@seonWKim seonWKim commented Feb 6, 2024

Motivation

If there is no sensitive information in a repository, users may want to make the repo public and allow access without an access token. ANONYMOUS could be added as a new permission in addition to OWNER, MEMBMER and GUEST.

Modification

  • Add ProjectRole#ANONYMOUS
  • Modify UI
image image

Result

  • Users will be able to add ANONYMOUS role to their project

Links

#897

@ikhoon ikhoon added this to the 0.65.0 milestone Feb 13, 2024
@minwoox
Copy link
Member

minwoox commented Feb 22, 2024

I wonder how we can allow anonymous users to access public repositories(without passing access token) with the Authorizer's token checking logic.

Let's create an anonymous user and set the user if the token is anoymous in the authorizer.

@seonWKim
Copy link
Contributor Author

seonWKim commented Mar 1, 2024

Let's create an anonymous user and set the user if the token is anoymouse in the authorizer.

@minwoox, please check if I've understood correctly 😄

  • Add an anonymous user in com.linecorp.centraldogma.server.metadata.User
  • Users will be able to add tokens with App Id of "anonymous". The Authorizer will set Anonymous user when token's App Id is "anonymous"

@minwoox
Copy link
Member

minwoox commented Mar 2, 2024

Users will be able to add tokens with App Id of "anonymous".

Does "Users" mean the clients or the repository owners?

The repository owners do not have to add the tokens. All they have to do is adding the read permission to the anonymous role. Here is the flow:

Please let me know if you have any further questions. 😉

/**
* Holds a default application token.
*/
public class ApplicationToken {
Copy link
Contributor Author

@seonWKim seonWKim Mar 2, 2024

Choose a reason for hiding this comment

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

@minwoox, thank you so much for the detailed explanation. It helped me a lot 👍

It seems like com.linecorp.centraldogma.client.armeria.AbstractCentralDogmaBuilder sets com.linecorp.centraldogma.internal.CsrfToken#ANONYMOUS as accessToken by default(when no other accessToken is specified). So the question is, should we use CsrfToken#ANONYMOUS when checking anonymous token, or should we create a new ApplicationToken#ANONYMOUS?

Copy link
Member

Choose a reason for hiding this comment

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

It's simply a string, so it doesn't matter what we use.
Let's remove this class and use CsrfToken#ANONYMOUS.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added a commit that uses CsrfToken#ANONYMOUS and remove ApplicationToken

Copy link

codecov bot commented Mar 4, 2024

Codecov Report

Attention: Patch coverage is 65.38462% with 9 lines in your changes are missing coverage. Please review.

❗ No coverage uploaded for pull request base (main@9ecb84d). Click here to learn what that means.
Report is 15 commits behind head on main.

❗ Current head 57d39a7 differs from pull request most recent head bb55dca. Consider uploading reports for the commit bb55dca to get more accurate results

Files Patch % Lines
.../centraldogma/server/metadata/MetadataService.java 42.85% 2 Missing and 2 partials ⚠️
...ntraldogma/server/metadata/PerRolePermissions.java 55.55% 2 Missing and 2 partials ⚠️
...om/linecorp/centraldogma/server/metadata/User.java 80.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #917   +/-   ##
=======================================
  Coverage        ?   66.80%           
  Complexity      ?     3522           
=======================================
  Files           ?      370           
  Lines           ?    14494           
  Branches        ?     1557           
=======================================
  Hits            ?     9683           
  Misses          ?     3931           
  Partials        ?      880           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@minwoox minwoox left a comment

Choose a reason for hiding this comment

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

Looks great! Thanks! 👍 👍 👍

throw new UnsupportedOperationException(
"Can't give a permission to guest for internal repository: " + repoName);
"Can't give a permission to guest or anonymous for internal repository: " + repoName);
}
}

Copy link
Member

Choose a reason for hiding this comment

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

Could you also check if the anonymous permission has the write permission? If so, we should raise an exception.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've fixed to throw exception when trying to grant WRITE permission to anonymous user

Copy link
Contributor

@jrhee17 jrhee17 left a comment

Choose a reason for hiding this comment

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

Changes look reasonable to me 👍 Thanks @seonwoo960000 !

nit; we may need to update

later if not now

Copy link
Member

@trustin trustin left a comment

Choose a reason for hiding this comment

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

Excellent work, @seonwoo960000! 🙇

Copy link
Contributor

@ikhoon ikhoon left a comment

Choose a reason for hiding this comment

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

Thanks, @seonwoo960000! 🙇‍♂️🙇‍♂️ This would be a go-to feature for many users.

@minwoox minwoox merged commit 1fd531a into line:main Apr 23, 2024
9 checks passed
@minwoox
Copy link
Member

minwoox commented Apr 23, 2024

@seonwoo960000 👍 👍 👍

@seonWKim seonWKim deleted the feature/897-add-anonymous-permission branch April 23, 2024 08:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants