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

feat(x/authz): Disable authz grant message grant #20687

Merged
merged 18 commits into from
Jun 25, 2024

Conversation

sontrinh16
Copy link
Member

@sontrinh16 sontrinh16 commented Jun 17, 2024

Description

Closes: #19737


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title, you can find examples of the prefixes below:
  • confirmed ! in the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • updated the relevant documentation or specification, including comments for documenting Go code
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

Please see Pull Request Reviewer section in the contributing guide for more information on how to review a pull request.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

Summary by CodeRabbit

  • New Features

    • Introduced a restriction preventing users from granting MsgGrant authorization, ensuring users cannot accidentally authorize their entire account to another account.
  • Documentation

    • Updated README.md to reflect the new restriction on MsgGrant authorization.
  • Tests

    • Added a new test case to validate the restriction on MsgGrant authorization, ensuring it triggers the appropriate error.

@sontrinh16 sontrinh16 requested a review from a team as a code owner June 17, 2024 08:32
Copy link
Contributor

coderabbitai bot commented Jun 17, 2024

Walkthrough

The recent changes to the x/authz module introduce a restriction that prevents users from granting authorization (MsgGrant) to another account to avoid accidental authorization of their entire account. This involves updates across multiple files, including the addition of a new test case and documentation of this restriction in the README and CHANGELOG files.

Changes

File Summary
x/authz/keeper/... Added a check in msg_server.go to disallow authorization of authz.MsgGrant messages and included a new test case in msg_server_test.go to validate this restriction.
x/authz/CHANGELOG.md Documented the new feature that prevents authorization of MsgGrant to other accounts.
x/authz/keeper_test.go Added authz.RegisterMsgServer to register a message server with the authzKeeper.
x/authz/README.md Updated to mention the new restriction on granting authz.MsgGrant to prevent users from inadvertently granting their entire account to another account.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Interface
    participant AuthzKeeper
    User->>Interface: Create MsgGrant
    Interface->>AuthzKeeper: Validate MsgGrant
    AuthzKeeper-->>Interface: "authz msgGrant is not allowed"
    Interface-->>User: Error: authz msgGrant is not allowed
Loading

Assessment against linked issues

Objective Addressed Explanation
Disable authz grant of MsgGrant to avoid account access (19737)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

This comment has been minimized.

@sontrinh16 sontrinh16 changed the title Feature(x/authz): Disable authz grant message grant feat(x/authz): Disable authz grant message grant Jun 17, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9ab7d39 and 9efe4c3.

Files selected for processing (3)
  • x/authz/keeper/keeper_test.go (1 hunks)
  • x/authz/keeper/msg_server.go (1 hunks)
  • x/authz/keeper/msg_server_test.go (1 hunks)
Additional context used
Path-based instructions (3)
x/authz/keeper/msg_server.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

x/authz/keeper/msg_server_test.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

x/authz/keeper/keeper_test.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

Additional comments not posted (3)
x/authz/keeper/msg_server.go (1)

46-47: The implementation correctly blocks the authorization of authz.MsgGrant messages as intended by the PR. This change aligns with the PR's goal to prevent accidental full account access grants.

x/authz/keeper/msg_server_test.go (1)

203-214: The added test case "invalid grant with msg grant" correctly validates the new behavior in msg_server.go by expecting an error when trying to grant an authz.MsgGrant. This ensures that the new logic is effectively preventing the specific unwanted authorization scenario.

x/authz/keeper/keeper_test.go (1)

83-83: The registration of the message server with authzKeeper in the test setup is crucial for integration tests to simulate the actual environment accurately. This setup is essential for testing the new changes thoroughly.

Copy link
Member

@julienrbrt julienrbrt left a comment

Choose a reason for hiding this comment

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

We should add a note about this in the x/authz/README.md and x/authz/CHANGELOG.md.

@@ -43,6 +43,9 @@ func (k Keeper) Grant(ctx context.Context, msg *authz.MsgGrant) (*authz.MsgGrant
if err := k.MsgRouterService.CanInvoke(ctx, t); err != nil {
return nil, sdkerrors.ErrInvalidType.Wrapf("%s doesn't exist", t)
}
if t == sdk.MsgTypeURL(&authz.MsgGrant{}) {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe let's add a comment on why it is done here (msg server) and not in the keeper?
My guess is you did it like this so that modules can still create a grant of grants if needed, and this only break the user flow and not module code. If so I would precise that so it doesn't get refactored away in the futurre.

Copy link
Member Author

Choose a reason for hiding this comment

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

gotcha

Copy link
Member Author

Choose a reason for hiding this comment

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

added the docs

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9efe4c3 and 6f08979.

Files selected for processing (2)
  • x/authz/CHANGELOG.md (1 hunks)
  • x/authz/keeper/msg_server.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • x/authz/keeper/msg_server.go
Additional context used
Path-based instructions (1)
x/authz/CHANGELOG.md (1)

Pattern **/*.md: "Assess the documentation for misspellings, grammatical errors, missing documentation and correctness"

LanguageTool
x/authz/CHANGELOG.md

[uncategorized] ~32-~32: Possible missing article found. (AI_HYDRA_LEO_MISSING_A)
Context: ... MsgGrant to other accounts. Preventing user from accidentally authorizing their ent...

Markdownlint
x/authz/CHANGELOG.md

38-38: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation


39-39: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation


40-40: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation

@@ -29,6 +29,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

* [#18737](https://github.com/cosmos/cosmos-sdk/pull/18737) Added a limit of 200 grants pruned per `BeginBlock` and the `PruneExpiredGrants` message that prunes 75 expired grants on every run.
* [#20161](https://github.com/cosmos/cosmos-sdk/pull/20161) Added `RevokeAll` method to revoke all grants at once.
* [#20687](https://github.com/cosmos/cosmos-sdk/pull/20687) Prevent user to grant authz MsgGrant to other accounts. Preventing user from accidentally authorizing their entire account to a different account.
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider revising the entry for clarity and grammatical correctness.

- * [#20687](https://github.com/cosmos/cosmos-sdk/pull/20687) Prevent user to grant authz MsgGrant to other accounts. Preventing user from accidentally authorizing their entire account to a different account.
+ * [#20687](https://github.com/cosmos/cosmos-sdk/pull/20687) Prevent users from granting authz MsgGrant to other accounts to avoid accidentally authorizing their entire account to a different user.
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
* [#20687](https://github.com/cosmos/cosmos-sdk/pull/20687) Prevent user to grant authz MsgGrant to other accounts. Preventing user from accidentally authorizing their entire account to a different account.
* [#20687](https://github.com/cosmos/cosmos-sdk/pull/20687) Prevent users from granting authz MsgGrant to other accounts to avoid accidentally authorizing their entire account to a different user.
Tools
LanguageTool

[uncategorized] ~32-~32: Possible missing article found. (AI_HYDRA_LEO_MISSING_A)
Context: ... MsgGrant to other accounts. Preventing user from accidentally authorizing their ent...


Fix indentation for list items to maintain consistency with the rest of the document.

-    * `NewMsgExec`, `NewMsgGrant` and `NewMsgRevoke` now takes strings as arguments instead of `sdk.AccAddress`.
-    * `ExportGenesis` also returns an error.
-    * `IterateGrants` returns an error, its handler function also returns an error.
+  * `NewMsgExec`, `NewMsgGrant` and `NewMsgRevoke` now takes strings as arguments instead of `sdk.AccAddress`.
+  * `ExportGenesis` also returns an error.
+  * `IterateGrants` returns an error, its handler function also returns an error.

Committable suggestion was skipped due to low confidence.

Tools
LanguageTool

[uncategorized] ~32-~32: Possible missing article found. (AI_HYDRA_LEO_MISSING_A)
Context: ... MsgGrant to other accounts. Preventing user from accidentally authorizing their ent...

Copy link
Member

@julienrbrt julienrbrt left a comment

Choose a reason for hiding this comment

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

utACK

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6f08979 and 005a971.

Files selected for processing (1)
  • x/authz/README.md (1 hunks)
Additional context used
Path-based instructions (1)
x/authz/README.md (1)

Pattern **/*.md: "Assess the documentation for misspellings, grammatical errors, missing documentation and correctness"

LanguageTool
x/authz/README.md

[style] ~41-~41: This phrase is redundant. Consider using “outside”. (OUTSIDE_OF)
Context: ...defined for any Msg service method even outside of the module where the Msg method is defi...


[uncategorized] ~51-~51: Possible missing article found. (AI_HYDRA_LEO_MISSING_THE)
Context: ... Cosmos SDK x/authz module comes with following authorization types: #### GenericAutho...


[uncategorized] ~71-~71: ‘Amount of’ should usually only be used with uncountable or mass nouns. Consider using “number” if this is not the case. (AMOUNTOF_TO_NUMBEROF)
Context: ...SpendLimit that specifies the maximum amount of tokens the grantee can spend. The `S...


[uncategorized] ~87-~87: ‘Amount of’ should usually only be used with uncountable or mass nouns. Consider using “number” if this is not the case. (AMOUNTOF_TO_NUMBEROF)
Context: ...ens` that keeps track of a limit to the amount of tokens that can be delegated/undeleg...


[style] ~98-~98: Consider a shorter alternative to avoid wordiness. (IN_ORDER_TO_PREMIUM)
Context: ...ng/types/authz.go#L15-L35 ``` ### Gas In order to prevent DoS attacks, granting `StakeAut...


[uncategorized] ~99-~99: Do not mix variants of the same word (‘authorize’ and ‘authorise’) within a single text. (EN_WORD_COHERENCY)
Context: ...gas. StakeAuthorization allows you to authorize another account to delegate, undelegate...


[grammar] ~99-~99: After the number ‘10’, use a plural noun. Did you mean “gases”, “gasses”? (CD_NNU)
Context: ...iterates over these lists and charge 10 gas for each validator in both of the lists...


[uncategorized] ~101-~101: Use a comma before ‘and’ if it connects two independent clauses (unless they are closely connected and short). (COMMA_COMPOUND_SENTENCE)
Context: ...e of particular msgType) from the list and we are charging 20 gas per iteration. ...


[grammar] ~101-~101: After the number ‘20’, use a plural noun. Did you mean “gases”, “gasses”? (CD_NNU)
Context: ...`) from the list and we are charging 20 gas per iteration. ## State ### Grant Gr...


[uncategorized] ~107-~107: A comma may be missing after the conjunctive/linking adverb ‘Hence’. (SENT_START_CONJUNCTIVE_LINKING_ADVERB_COMMA)
Context: ... and Authorization type (its type URL). Hence we only allow one grant for the (grante...


[typographical] ~139-~139: It appears that a comma is missing. (DURING_THAT_TIME_COMMA)
Context: ...cated in the key. ## Messages In this section we describe the processing of messages ...


[uncategorized] ~146-~146: Possible missing article found. (AI_HYDRA_LEO_MISSING_A)
Context: ...return an error. This is for preventing user from accidentally authorizing their ent...


[uncategorized] ~155-~155: Possible missing comma found. (AI_HYDRA_LEO_MISSING_COMMA)
Context: ...l be created if no expiration time is provided since expiration is optional). * prov...

Markdownlint
x/authz/README.md

15-15: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation


16-16: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation


17-17: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation


19-19: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation


20-20: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation


22-22: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation


23-23: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation


24-24: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation


25-25: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation


26-26: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation


29-29: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation


30-30: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation


31-31: Expected: 2; Actual: 4 (MD007, ul-indent)
Unordered list indentation

Additional comments not posted (1)
x/authz/README.md (1)

146-147: Clarify the new restriction on MsgGrant in the documentation

The documentation states that an authorization grant for authz MsgGrant is not allowed, which is a critical security feature. It's crucial to ensure that this information is clear and unambiguous to prevent misuse.

Tools
LanguageTool

[uncategorized] ~146-~146: Possible missing article found. (AI_HYDRA_LEO_MISSING_A)
Context: ...return an error. This is for preventing user from accidentally authorizing their ent...

@sontrinh16 sontrinh16 enabled auto-merge June 25, 2024 08:46
@sontrinh16 sontrinh16 added this pull request to the merge queue Jun 25, 2024
Merged via the queue into main with commit 7f329c6 Jun 25, 2024
67 checks passed
@sontrinh16 sontrinh16 deleted the disable_grant_authz_grant_msg branch June 25, 2024 09: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.

[Feature]: disable authz grant message grant
3 participants