3.0.1 • Published 2 months ago

@restorecommerce/acs-client v3.0.1

Weekly downloads
94
License
MIT
Repository
github
Last release
2 months ago

acs-client

VersionBuild StatusDependenciesCoverage Status

Features:

  • A generic client for the access-control-srv.
  • It uses grpc-client to access the exposed API via its gRPC interface.
  • It constructs the request object expected by access-control-srv when requesting access to a particular resource with a specific action on it.
  • It supports access requests for both methods isAllowed and whatIsAllowed exposed by access-control-srv.
  • It provides an optional caching mechanism for the two operations based on a redis store.
  • It evaluates the condition for whatIsAllowed requests.
  • It returns the decision made by the ACS.

Configuration

The access-control-srv URN configurations needs to be set using authorization configuration to acs-client from access requesting microservice. The URN for the role scoping entity for Organization/ business units must be set using the configuration property authorization.urns.orgScope.

orgScope: 'urn:\<organization\>:acs:model:<Entity_Name>

ex: orgScope: urn:restorecommerce:acs:model:organization.Organization

The caching configurations for redis can be set using authorization:cache configuration.

For testing and debugging the access control checking can be dsiabled as a whole via the enabled flag. This will supress the access control checking via the ACS and always permit any request. If the ACS checks should be performed (and thus logged) but not enforced, the enforce flag can be set to false which is useful for debugging the ruleset.

It is also possible to configure authorization:unauthenticated_user as subject with identifiter and token in the configuration, if the subject is empty then the token from this configuration will be used.

API

The client exposes the following API:

accessRequest

It turns an API request as can be found in typical Web frameworks like express, koa etc. into a proper ACS request. Depending on Operation respective api's isAllowed and whatIsAllowed are invoked from access-control-srv. Requests are performed providing Request message as input and response is Response message type. For the read operations it extends the filter provided in the ReadRequst of the input message to enforce the applicapble poilicies. The response is DecisionResponse or policy set reverse query PolicySetRQResponse depending on the requeste operation isAllowed() or whatIsAllowed() respectively.

Request

FieldTypeLabelDescription
subjectio.restorecommerce.user.SubjectrequiredSubject user details (ID, token, role-associations and hierarchical scopes)
resourceResource [ ]requiredcontains resource name, resource instance and optional resource properties
actionEnumrequiredaction to be performed on the resource (CREATE, READ, MODIFY, DELETE or ALL)
ctxACSClientContextrequiredcontext containing subject and context resources for ACS
opeationOperationrequiredoperation to perform either isAllowed or whatIsAllowed
databasestringoptionaldatabase used, currently 'arangoDB' and 'postgres' are supported
useCachebooleanoptionaldefaults to true, if set to false then ACS cache is not used and ACS request is made to access-control-srv

Response

FieldTypeLabelDescription
DecisionResponseDecisionResponseoptionalAccess decision; possible values are PERMIT, DENY or INDETERMINATE
PolicySetRQResponsePolicySetRQResponse [ ]optionalList of applicable policy sets along with obligations if any

Resource

FieldTypeLabelDescription
resourcestringrequriedresource entity or operation name
idstringoptionalinstance identifier of the resource
propertystring optionallist of fields for accessing or modifying resource

ACSClientContext

FieldTypeLabelDescription
subjectio.restorecommerce.user.SubjectrequiredSubject user details (ID, token, role-associations and hierarchical scopes)
resourcesCtxResource [ ]optionalcontext resources

CtxResource | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | | id | string | required | resource identifier | | meta | io.restorecommerce.meta.Meta | required | meta object containing owner information | | key | any | optional | optional resource properties |

Operation | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | | operation | string | required | operation to perform isAllowed or whatIsAllowed |

DecisionResponse

FieldTypeLabelDescription
decisionio.restorecommerce.access_control.DecisionrequiredAccess decision; possible values are PERMIT, DENY or INDETERMINATE
obligationObligation [ ]optionallist of obligations
operation_statusio.restorecommerce.status.OperationStatusrequiredoperation status code and message

Obligation

FieldTypeLabelDescription
resourcestringrequiredresource name
propertystring requiredlist of resource properties

PolicySetRQResponse

FieldTypeLabelDescription
policy_sets (https://github.com/restorecommerce/access-control-srv#whatisallowed)requiredList of applicable policy sets
obligationObligation [ ]optionallist of obligations

isAllowed

This API exposes the isAllowed api of access-control-srv and retruns the response as Decision. Requests are performed providing io.restorecommerce.access_control.Request message as input and response is io.restorecommerce.access_control.Response message.

whatIsAllowed

This API exposes the whatIsAllowed api of access-control-srv and retruns policy sets list containing list of applicable policies and rules. Requests are performed providing io.restorecommerce.access_control.Request message as input and response is io.restorecommerce.access_control.ReverseQuery message.

Caching

This client supports caching for isAllowed and whatIsAllowed access request operations if authorization:cache options are set. The time to live for redis key can be set using authorization:cache:ttl configuration. The hash key for caching the request is generated using MD5 hash algorithm. For whatIsAllowed operations Request Object is used to generate the hash key and for isAllowed operations io.restorecommerce.access_control.Target Object is used since the resource data changes. Each of the ACS request is associated with an ID of subject, this subject ID is included in the hash key as prefix to keep track of mapping between ACS requests and cached data. The cache can be invalidated by invoking flushCache api with subject ID as prefix parameter.

Development

Tests

For a simple example on how to use this client with a access-control-srv check the test cases.

  • Run tests
npm run test

Usage

  • Install dependencies
npm install
  • Build
# compile the code
npm run build
3.0.1

2 months ago

3.0.0

3 months ago

2.0.4

4 months ago

2.0.3

4 months ago

2.0.2

4 months ago

2.0.1

5 months ago

2.0.0

6 months ago

1.6.9

7 months ago

1.6.11

6 months ago

1.6.10

6 months ago

1.6.8

8 months ago

1.6.7

8 months ago

1.6.6

8 months ago

1.6.4

8 months ago

1.6.5

8 months ago

1.6.3

8 months ago

1.6.2

8 months ago

1.6.1

8 months ago

1.6.0

8 months ago

1.5.1

8 months ago

1.5.0

8 months ago

1.4.15

9 months ago

1.4.14

9 months ago

1.4.13

10 months ago

1.4.12

10 months ago

1.4.11

10 months ago

1.4.10

10 months ago

1.4.9

11 months ago

1.4.8

11 months ago

1.4.7

11 months ago

1.4.6

11 months ago

1.4.5

12 months ago

1.4.3

1 year ago

1.2.0

1 year ago

1.2.2

1 year ago

1.2.1

1 year ago

1.1.9

1 year ago

1.1.8

1 year ago

1.1.12

1 year ago

1.1.11

1 year ago

1.1.10

1 year ago

1.1.16

1 year ago

1.1.15

1 year ago

1.1.14

1 year ago

1.1.13

1 year ago

1.1.19

1 year ago

1.1.18

1 year ago

1.1.17

1 year ago

1.1.20

1 year ago

1.4.2

1 year ago

1.4.1

1 year ago

1.4.0

1 year ago

1.3.2

1 year ago

1.3.1

1 year ago

1.3.0

1 year ago

1.1.7

1 year ago

1.1.1

2 years ago

1.1.6

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.0

2 years ago

1.0.2

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.6.32

3 years ago

0.6.34

3 years ago

0.6.33

3 years ago

0.6.36

2 years ago

0.6.35

2 years ago

0.6.37

2 years ago

0.6.31

3 years ago

0.6.30

3 years ago

0.6.29

3 years ago

0.6.23

3 years ago

0.6.22

3 years ago

0.6.28

3 years ago

0.6.25

3 years ago

0.6.24

3 years ago

0.6.27

3 years ago

0.6.26

3 years ago

0.6.21

3 years ago

0.6.20

3 years ago

0.6.18

3 years ago

0.6.17

3 years ago

0.6.19

3 years ago

0.6.16

3 years ago

0.6.15

3 years ago

0.6.9

3 years ago

0.6.10

3 years ago

0.6.12

3 years ago

0.6.11

3 years ago

0.6.14

3 years ago

0.6.13

3 years ago

0.6.7

3 years ago

0.6.6

3 years ago

0.6.8

3 years ago

0.5.3

3 years ago

0.5.0

3 years ago

0.5.2

3 years ago

0.5.1

3 years ago

0.4.19

3 years ago

0.6.3

3 years ago

0.6.2

3 years ago

0.6.5

3 years ago

0.6.4

3 years ago

0.6.1

3 years ago

0.4.18

3 years ago

0.4.17

3 years ago

0.4.15

3 years ago

0.4.16

3 years ago

0.4.13

3 years ago

0.4.14

3 years ago

0.4.12

3 years ago

0.4.10

3 years ago

0.4.11

3 years ago

0.4.9

3 years ago

0.4.8

3 years ago

0.4.7

3 years ago

0.4.5

3 years ago

0.4.3

3 years ago

0.3.12

3 years ago

0.3.10

3 years ago

0.3.9

3 years ago

0.3.8

3 years ago

0.3.5

4 years ago

0.3.4

4 years ago

0.3.0

4 years ago

0.3.1

4 years ago

0.2.24

4 years ago

0.2.23

4 years ago

0.2.22

4 years ago

0.2.21

4 years ago

0.2.20

4 years ago

0.2.19

4 years ago

0.2.18

4 years ago

0.2.18-alpha.4

4 years ago

0.2.18-alpha.3

4 years ago

0.2.18-alpha.2

4 years ago

0.2.18-alpha.1

4 years ago

0.2.17

4 years ago

0.2.16

4 years ago

0.2.15

4 years ago

0.2.14

4 years ago

0.2.13

4 years ago

0.2.12

4 years ago

0.2.11

4 years ago

0.2.10

4 years ago

0.2.9

4 years ago

0.2.8

4 years ago

0.2.7

4 years ago

0.2.6

4 years ago

0.2.5

4 years ago

0.2.4

4 years ago

0.2.3

4 years ago

0.2.2

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.10

5 years ago

0.1.9

5 years ago

0.1.8

5 years ago

0.1.7

5 years ago

0.1.6

5 years ago

0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.5

5 years ago

0.0.6

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago