You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+45-65Lines changed: 45 additions & 65 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,17 +5,15 @@ could-could is yet another authorization library built atop [JsonLogic](https://
5
5
## Features
6
6
7
7
- Generates the set of policies ahead of time for predictable performance
8
-
- Allows for defining policies across `environments` (e.g. `development`, `production-use1`, etc) as well as `actions` (e.g. `create`, `kitty:PetKitty`, etc) on a given resource type. Policies will be merged with an `or` so any one matching policy is sufficient
9
8
- Provides for both `allow` and `deny` constraints. `deny` constraints will always take precedence
10
9
- Allows for a context to be provided when evaluating the policy, allowing for more complex conditional logic
11
-
- Uses a portable [JSONSchema](./schemas/resource-policy-2022-04.schema.json) for validating the shape of the policies
10
+
- Uses a portable [JSONSchema](./schemas/resource-policy-2023-02.schema.json) for validating the shape of the policies
12
11
- Can extend JsonLogic with custom functions if needed (not recommended as you will need to implement the same functions in each consumer of the policy)
13
12
14
13
## Terms
15
14
16
-
-`resourceType`: an identifier for a type of resource to validate (e.g. `BlogPost`, `com.kitties.Kitty`)
17
-
-`environment`: an arbitrary identifier for an operating context, allowing for different constraints in `test`, non-production (e.g. `alpha`, `preview`), or different regions of `production` (e.g. `production-use1`)
18
-
-`action`: an identifier of what kind of action is being requested (e.g. `create`, `kittes:PetKitty`). Actions can be specified as a single action, an array of actions, or `*` which will match any action.
15
+
-`action`: an identifier of what kind of action(s) are being requested (e.g. `create`, `kitties:PetKitty`)
16
+
- Actions can be specified as a single action, an array of actions, or `*` which will match any action.
19
17
-`effect`: what the result should be if the `constraint` is true
20
18
-`constraint`: the rules that will be evaluated to determine if an action can occur
21
19
-`context`: the extra data that can be provided to make decisions, such as a principal (e.g. user/service object) or the resource in question
@@ -24,72 +22,54 @@ could-could is yet another authorization library built atop [JsonLogic](https://
24
22
25
23
You will need a few pieces of information up front when creating a collection of policies:
26
24
27
-
1. a resource type naming convention
28
25
1. a list of actions that are permitted for each resource type. All other actions will evaluate to `false`
29
-
1. what environments you plan to use across all resource types, such as `development`, `test`, `beta`, `production`
26
+
- TIP: use a namespacing scheme such as `documents:deleteDocument` to group actions by domain
30
27
1. what information will be available in the context when evaluating an action
31
28
32
29
```jsonc
33
30
// example policy stored somewhere that can be consumed at runtime
if (!resolver.can({ action: 'kitty:pet' }, { kitty, subject })) {
108
88
thrownewNotAuthorizedError()
109
89
}
110
90
}
@@ -122,4 +102,4 @@ The package is broken into three major areas: the validator, the parser, and the
122
102
123
103
* the validator checks that the provided resource policy matches the schema, has listed all potential actions defined in the constraints, and has an evaluatable set of constraints
124
104
* the parser does the heavy lifting of turning a resource policy into a compiled Map of action => JsonLogic
125
-
* the resolver accepts a policyStore and handles the runtime evaluation logic based on the provided action, resource type, and context
105
+
* the resolver accepts a policyStore and handles the runtime evaluation logic based on the provided action and context
0 commit comments