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

x/authz specs #8499

Merged
merged 21 commits into from
Feb 11, 2021
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions x/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ parent:
Here are some production-grade modules that can be used in Cosmos SDK applications, along with their respective documentation:

- [Auth](auth/spec/README.md) - Authentication of accounts and transactions for Cosmos SDK application.
- [Authz](authz/spec/README.md) - Allows accounts to grant authorizations to perform actions on behalf of that account to other accounts.
aleem1314 marked this conversation as resolved.
Show resolved Hide resolved
- [Bank](bank/spec/README.md) - Token transfer functionalities.
- [Capability](capability/spec/README.md) - Object capability implementation.
- [Crisis](crisis/spec/README.md) - Halting the blockchain under certain circumstances (e.g. if an invariant is broken).
Expand Down
37 changes: 37 additions & 0 deletions x/authz/spec/01_concepts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<!--
order: 1
-->

# Concepts

## Authorization
Any concrete type of authorization defined in the `x/authz` module must fulfill `Authorization` interface outlined below. Authorizations determine exactly what privileges are granted. They are extensible and can be defined for any Msg service method even outside of the module where the Msg method is defined. Authorizations use the new `ServiceMsg` type from [ADR 031](docs/architecture/adr-31-msg-service.md).
amaury1093 marked this conversation as resolved.
Show resolved Hide resolved


+++ https://github.com/cosmos/cosmos-sdk/blob/master/x/authz/types/authorizations.go#L15-L24
aleem1314 marked this conversation as resolved.
Show resolved Hide resolved


## Built-in Authorizations

Cosmos-SDK `x/authz` module comes with following authorization types

### SendAuthorization

`SendAuthorization` implements `Authorization` interface for the `MsgSend` ServiceMsg, that takes a `SpendLimit` and updates it down to zero.
aleem1314 marked this conversation as resolved.
Show resolved Hide resolved

+++ https://github.com/cosmos/cosmos-sdk/blob/master/proto/cosmos/authz/v1beta1/authz.proto#L12-L19

+++ https://github.com/cosmos/cosmos-sdk/blob/master/x/authz/types/send_authorization.go#L23-L45

- `spent_limit` keeps track of how many coins left in the authorization.


### GenericAuthorization

`GenericAuthorization` implements the `Authorization` interface, that gives unrestricted permission to execute the provided ServiceMsg on behalf of granter's account.

+++ https://github.com/cosmos/cosmos-sdk/blob/master/proto/cosmos/authz/v1beta1/authz.proto#L21-L30

+++ https://github.com/cosmos/cosmos-sdk/blob/master/x/authz/types/generic_authorization.go#L20-L28

- `method_name` holds ServiceMsg type.
14 changes: 14 additions & 0 deletions x/authz/spec/02_state.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!--
order: 2
-->

# State

## AuthorizationGrant

Authorizations are identified by combining granter address (the address bytes of the granter), grantee address (the address bytes of the grantee) and ServiceMsg type.
aleem1314 marked this conversation as resolved.
Show resolved Hide resolved

- AuthorizationGrant: `0x01 | granter_address_bytes | grantee_address_bytes | msgType_bytes-> ProtocolBuffer(AuthorizationGrant)`
aleem1314 marked this conversation as resolved.
Show resolved Hide resolved


+++ https://github.com/cosmos/cosmos-sdk/blob/master/proto/cosmos/authz/v1beta1/authz.proto#L32-L37
42 changes: 42 additions & 0 deletions x/authz/spec/03_messages.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<!--
order: 3
-->

# Messages

In this section we describe the processing of messages for the authz module.

## MsgGrantAuthorization
aleem1314 marked this conversation as resolved.
Show resolved Hide resolved

An authorization-grant is created using the `MsgGrantAuthorization` message.

+++ https://github.com/cosmos/cosmos-sdk/blob/master/proto/cosmos/authz/v1beta1/tx.proto#L27-L35

This message is expected to fail if:

- both granter & grantee have same address.
- provided `Expiration` time less than current unix timestamp.
- provided `Authorization` is not implemented.

## MsgRevokeAuthorization

An allowed authorization can be removed with `MsgRevokeAuthorization` message.

+++ https://github.com/cosmos/cosmos-sdk/blob/master/proto/cosmos/authz/v1beta1/tx.proto#L53-L59

This message is expected to fail if:

- both granter & grantee have same address.
- provided `MethodName` is empty.

## MsgExecAuthorizedRequest

When a grantee wants to execute transaction on behalf of a granter, it must send MsgExecAuthorizedRequest.

+++ https://github.com/cosmos/cosmos-sdk/blob/master/proto/cosmos/authz/v1beta1/tx.proto#L42-L48

This message is expected to fail if:

- authorization not implemented for the provided msg.
- grantee don't have permission to run transaction.
- if granted authorization is expired.
29 changes: 29 additions & 0 deletions x/authz/spec/04_events.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!--
order: 4
-->

# Events

The authz module emits the following events:

## Keeper

### GrantAuthorization

| Type | Attribute Key | Attribute Value |
|----------------------|-------------------|--------------------|
| grant-authorization | module | authz |
| grant-authorization | grant-type | {msgType} |
| grant-authorization | granter | |
| grant-authorization | grantee | |
aleem1314 marked this conversation as resolved.
Show resolved Hide resolved


### RevokeAuthorization

| Type | Attribute Key | Attribute Value |
|----------------------|-------------------|--------------------|
| revoke-authorization | module | authz |
| revoke-authorization | grant-type | {msgType} |
| revoke-authorization | granter | |
| revoke-authorization | grantee | |
aleem1314 marked this conversation as resolved.
Show resolved Hide resolved

26 changes: 26 additions & 0 deletions x/authz/spec/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!--
order: 0
title: Authz Overview
parent:
title: "authz"
-->

# `authz`

## Contents

## Abstract
`x/authz` is an implementation of a Cosmos SDK module, per [ADR 30](docs/architecture/adr-030-authz-module.md), that allows
aleem1314 marked this conversation as resolved.
Show resolved Hide resolved
granting arbitrary privileges from one account (the granter) to another account (the grantee).Authorizations must be granted for a particular Msg service methods one by one using an implementation of `Authorization` interface.
aleem1314 marked this conversation as resolved.
Show resolved Hide resolved

1. **[Concept](01_concepts.md)**
- [Authorization](01_concepts.md#Authorization)
- [Built-in Authorizations](01_concepts.md#Built-in-Authorization)
2. **[State](02_state.md)**
3. **[Messages](03_messages.md)**
- [MsgGrantAuthorization](03_messages.md#MsgGrantAuthorization)
- [MsgRevokeAuthorization](03_messages.md#MsgRevokeAuthorization)
- [MsgExecAuthorized](03_messages.md#MsgExecAuthorized)
4. **[Events](04_events.md)**
- [Keeper](04_events.md#Keeper)