-
Notifications
You must be signed in to change notification settings - Fork 428
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
Authz redesign: CLI implementation #1079
Conversation
Codecov Report
@@ Coverage Diff @@
## main #1079 +/- ##
==========================================
- Coverage 60.33% 59.79% -0.55%
==========================================
Files 54 54
Lines 7211 7273 +62
==========================================
- Hits 4351 4349 -2
- Misses 2549 2612 +63
- Partials 311 312 +1
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great start. The CLI will be hard to come with a good UX. I have added some notes to help. My gut feeling is that more concrete parameter may be better to guide the user than overloading max-calls and amount for the different cases. But other opinions are welcome, too.
x/wasm/client/cli/tx.go
Outdated
|
||
var filter types.ContractAuthzFilterX | ||
switch len(msgs) { | ||
case 0: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am a bit worried that this becomes the default without giving notice to people. What do you think about an extra parameter that must be set for this option? Something like: --allow-all-messages-wildcard
x/wasm/client/cli/tx.go
Outdated
return fmt.Errorf("max funds: %s", err) | ||
} | ||
limit = types.NewMaxFundsLimit(maxFunds) | ||
case maxCalls != 0: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This option does not allow any token transfers. It would be nice if we can be explicit in the cli like --max-calls=1 --no-token-transfer
. WDYT?
case maxFundsStr != "": | ||
maxFunds, err := sdk.ParseCoinsNormalized(maxFundsStr) | ||
if err != nil { | ||
return fmt.Errorf("max funds: %s", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
filter = types.NewAllowAllMessagesFilter() | ||
default: | ||
filter = types.NewAcceptedMessageKeysFilter(msgs...) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The third option is to set the concrete json message(s) (byte equal).
} | ||
|
||
var authorization authz.Authorization | ||
switch args[1] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 this works
tests/e2e/setup.go
Outdated
coordinator *ibctesting.Coordinator | ||
providerChain *ibctesting.TestChain | ||
consumerChain *ibctesting.TestChain | ||
// coordinator *ibctesting.Coordinator |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I have removed this file on a local branch already. These changes will cause merge conflicts for you when I push.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good progress. I added some notes to unblock you. I will do a deeper review tomorrow.
x/wasm/client/cli/tx.go
Outdated
@@ -379,9 +385,9 @@ func parseExecuteArgs(contractAddr string, execMsg string, sender sdk.AccAddress | |||
|
|||
func GrantAuthorizationCmd() *cobra.Command { | |||
cmd := &cobra.Command{ | |||
Use: "grant [grantee] [contract_addr_bech32] --allow-msgs [msg1,msg2,...]", | |||
Use: "grant [grantee] [authorization_type=\"execution\"|\"migration\"] [contract_addr_bech32] --allow-raw-msgs `[msg1,msg2,...]` --allow-msg-keys [key1,key2,...]", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make authorization_type
message type. It it the wasmd tx message that can be executed
The '
in "`[msg1,msg2,...]`" were confusing. it is not a json array content but a list of strings
How about adding --allow-all-messages
here to have the filters complete? I think some full examples in the Long description would be very useful. The filter + limits model needs to be explained a bit for people to configure this.
x/wasm/client/cli/tx.go
Outdated
if err != nil { | ||
return err | ||
} | ||
|
||
once, err := cmd.Flags().GetBool(flagRunOnce) | ||
rawMsgsStr, err := cmd.Flags().GetString(flagAllowedRawMsgs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be GetStringSlice
as well.
x/wasm/client/cli/tx.go
Outdated
cmd.Flags().StringSlice(flagAllowedMsgs, []string{}, "Allowed msgs") | ||
cmd.Flags().Bool(flagRunOnce, false, "Allow to execute only once") | ||
cmd.Flags().StringSlice(flagAllowedMsgKeys, []string{}, "Allowed msg keys") | ||
cmd.Flags().String(flagAllowedRawMsgs, "", "Allowed raw msgs") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above, this should be a StringSlice
} | ||
|
||
var filter types.ContractAuthzFilterX | ||
switch { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Filters are mutual exclusive within one grant. Better fail fast if more than one is set.
@Mergifyio rebase |
❌ Base branch update has failedGit reported the following error:
err-code: FB22C |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work! I added some nits and personal preferences. But nothing blocking!
|
||
var limit types.ContractAuthzLimitX | ||
switch { | ||
case maxFundsStr != "" && maxCalls != 0 && !noTokenTransfer: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good check
x/wasm/client/cli/tx.go
Outdated
return fmt.Errorf("max funds: %s", err) | ||
} | ||
limit = types.NewCombinedLimit(maxCalls, maxFunds...) | ||
case maxFundsStr != "" && !noTokenTransfer: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: To be on the safe side, I would be very explicit: case maxFundsStr != "" && maxCalls == 0 && !noTokenTransfer:
x/wasm/client/cli/tx.go
Outdated
return fmt.Errorf("max funds: %s", err) | ||
} | ||
limit = types.NewMaxFundsLimit(maxFunds...) | ||
case maxCalls != 0 && noTokenTransfer: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to be on the safe side: maxCalls != 0 && noTokenTransfer && maxFundsStr == ""
x/wasm/client/cli/tx.go
Outdated
case maxCalls != 0 && noTokenTransfer: | ||
limit = types.NewMaxCallsLimit(maxCalls) | ||
default: | ||
limit = types.UndefinedLimit{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can fail fast here already
limit = types.UndefinedLimit{} | |
limit = errors.New("invalid limit setup") |
x/wasm/client/cli/tx.go
Outdated
|
||
var filter types.ContractAuthzFilterX | ||
switch { | ||
case allowAllMsgs && len(msgKeys) > 0 || allowAllMsgs && len(rawMsgs) > 0 || len(msgKeys) > 0 && len(rawMsgs) > 0: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 you cover all 3 cases here. I am a bit more used to read len(x) != 0
instead but all correct
x/wasm/client/cli/tx.go
Outdated
var filter types.ContractAuthzFilterX | ||
switch { | ||
case allowAllMsgs && len(msgKeys) > 0 || allowAllMsgs && len(rawMsgs) > 0 || len(msgKeys) > 0 && len(rawMsgs) > 0: | ||
return fmt.Errorf("cannot set more than one filter within one grant") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit
return fmt.Errorf("cannot set more than one filter within one grant") | |
return errors.New("cannot set more than one filter within one grant") |
x/wasm/client/cli/tx.go
Outdated
} | ||
filter = types.NewAcceptedMessagesFilter(msgs...) | ||
default: | ||
filter = &types.UndefinedFilter{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: as above, just return an error here
x/wasm/client/cli/tx.go
Outdated
Long: fmt.Sprintf(`Grant authorization to an address. | ||
Examples: | ||
$ %s tx grant <grantee_addr> execution <contract_addr> --allow-all-messages --maxCalls 1 --no-token-transfer --expiration 1667979596 | ||
`, version.AppName), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to have some more concrete examples for the limits and filters? I think you can cover all in 3 examples
73c401b
to
0164d85
Compare
* Add contract authz proto * Implement contract autorization * Register contract authz * Add contract-authz tests * Consume gas for contract authz * Add contract authz cli * Update cli usage * Model spike * Add max funds limit * Redesign authz model * Start e2e test * Full e2e test * Add cli implementation for signle grant case * Restore file to avoid merge conflicts * Test filter and limits * Add allow-al-messages flag * Add cli implementation for signle grant case * Add allow-al-messages flag * Implement comments fixes * Test accept * Fix description * No linter warning * Fix flags and add example command * Fix lint error * Fix limits cli * Add cli implementation for signle grant case * Add allow-al-messages flag * Implement comments fixes * Fix flags and add example command * Fix lint error * Fix limits cli * Add cli implementation for signle grant case * Add allow-al-messages flag * Implement comments fixes * Fix flags and add example command * Fix lint error * Fix limits cli * Fix comments Co-authored-by: Giancarlos Salas <me@giansalex.dev> Co-authored-by: Alex Peters <alpe@users.noreply.github.com>
* Add contract authz proto * Implement contract autorization * Register contract authz * Add contract-authz tests * Consume gas for contract authz * Add contract authz cli * Update cli usage * Model spike * Add max funds limit * Redesign authz model * Start e2e test * Full e2e test * Add cli implementation for signle grant case * Restore file to avoid merge conflicts * Test filter and limits * Add allow-al-messages flag * Add cli implementation for signle grant case * Add allow-al-messages flag * Implement comments fixes * Test accept * Fix description * No linter warning * Fix flags and add example command * Fix lint error * Fix limits cli * Add cli implementation for signle grant case * Add allow-al-messages flag * Implement comments fixes * Fix flags and add example command * Fix lint error * Fix limits cli * Add cli implementation for signle grant case * Add allow-al-messages flag * Implement comments fixes * Fix flags and add example command * Fix lint error * Fix limits cli * Fix comments Co-authored-by: Giancarlos Salas <me@giansalex.dev> Co-authored-by: Alex Peters <alpe@users.noreply.github.com>
* Add contract authz proto * Implement contract autorization * Register contract authz * Add contract-authz tests * Consume gas for contract authz * Add contract authz cli * Update cli usage * Model spike * Add max funds limit * Redesign authz model * Start e2e test * Full e2e test * Add cli implementation for signle grant case * Restore file to avoid merge conflicts * Test filter and limits * Add allow-al-messages flag * Add cli implementation for signle grant case * Add allow-al-messages flag * Implement comments fixes * Test accept * Fix description * No linter warning * Fix flags and add example command * Fix lint error * Fix limits cli * Add cli implementation for signle grant case * Add allow-al-messages flag * Implement comments fixes * Fix flags and add example command * Fix lint error * Fix limits cli * Add cli implementation for signle grant case * Add allow-al-messages flag * Implement comments fixes * Fix flags and add example command * Fix lint error * Fix limits cli * Fix comments Co-authored-by: Giancarlos Salas <me@giansalex.dev> Co-authored-by: Alex Peters <alpe@users.noreply.github.com>
Follow up on #1077