perms

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 23, 2017 License: Apache-2.0 Imports: 1 Imported by: 0

README

ChainOrchestra-SDK

Chaincode permissions module

Permissions module general design
Intended use

The rationale for this library is to have a very lightweight module, consistent accross all chaincode applications, that doesn't re-implement the cryptographic services already in place with Hyperledger. It just checks rights and permissions granted to already enrolled users.

As of Hyperledger v0.6, it uses the position member services attribute with a bitmask to set prioritized permissions.

The perms.go library must be included by all chaincode applications that need to implement some level of resource sharing. The module defines a set of roles that are granted to blockchain users, according to which the chaincode will let the user perform certain actions.

Example implementation

A banking application defines 3 positions: Bank Clerk, Cashier and Accountant. The Accountant is granted both BankClerk and Cashier rights.

const BankClerk			uint64 = 0x0000000000100000
const Cashier			uint64 = 0x0000000000200000
const Accountant		uint64 = 0x0000000000300000

System administrators and power users have cross-functional rights that include those defined above.

const SystemAdmin		uint64 = 0xffffffffffff000f
const PowerUser			uint64 = 0x0000000000ff0000
perms.go library usage
  • Importing the library from user chaincode.
import (
	"github.com/hyperledger/fabric/core/chaincode/shim"
	"chainorchestra.com/perms"
)
  • Using the shim.ChaincodeStubInterface to get permissions mask.
permissions, err := perms.CheckPermissions(stub)
  • Checking the permissions mask for a specific grant.
if (0 == permissions & perms.BankClerk) {
	return nil, errors.New("Need Bank Clerk rights to open or close account")
}

Documentation

Index

Constants

View Source
const Accountant uint64 = 0x0000000000300000
View Source
const BankClerk uint64 = 0x0000000000100000
View Source
const Cashier uint64 = 0x0000000000200000
View Source
const DeskClerk uint64 = 0x0000000000010000
View Source
const PowerUser uint64 = 0x0000000000ff0000
View Source
const SecurityGuard uint64 = 0x0000000000020000
View Source
const SoftwareEngineer uint64 = 0xffffffffffffffff
View Source
const SystemAdmin uint64 = 0xffffffffffff000f
View Source
const SystemOperator uint64 = 0x0000000000000001

Variables

This section is empty.

Functions

func CheckPermissions

func CheckPermissions(stub shim.ChaincodeStubInterface) (uint64, error)

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL