@intentius/chant-lexicon-cedar 0.44.8 → 0.44.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +58 -0
- package/dist/codegen/package.d.ts.map +1 -1
- package/dist/config.d.ts +25 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/dogwood/cli.d.ts +206 -0
- package/dist/dogwood/cli.d.ts.map +1 -0
- package/dist/dogwood/event-schema.d.ts +161 -0
- package/dist/dogwood/event-schema.d.ts.map +1 -0
- package/dist/dogwood/index.d.ts +33 -0
- package/dist/dogwood/index.d.ts.map +1 -0
- package/dist/dogwood/macros.d.ts +96 -0
- package/dist/dogwood/macros.d.ts.map +1 -0
- package/dist/dogwood/policy.d.ts +120 -0
- package/dist/dogwood/policy.d.ts.map +1 -0
- package/dist/dogwood/scan.d.ts +109 -0
- package/dist/dogwood/scan.d.ts.map +1 -0
- package/dist/dogwood/serialize.d.ts +46 -0
- package/dist/dogwood/serialize.d.ts.map +1 -0
- package/dist/dogwood/temporal.d.ts +259 -0
- package/dist/dogwood/temporal.d.ts.map +1 -0
- package/dist/dogwood/upstream.d.ts +41 -0
- package/dist/dogwood/upstream.d.ts.map +1 -0
- package/dist/dogwood/window.d.ts +73 -0
- package/dist/dogwood/window.d.ts.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/integrity.json +13 -3
- package/dist/lint/audit-catalog.d.ts.map +1 -1
- package/dist/lint/post-synth/dogwood-helpers.d.ts +63 -0
- package/dist/lint/post-synth/dogwood-helpers.d.ts.map +1 -0
- package/dist/lint/post-synth/dwdc010.d.ts +25 -0
- package/dist/lint/post-synth/dwdc010.d.ts.map +1 -0
- package/dist/lint/post-synth/dwdc011.d.ts +19 -0
- package/dist/lint/post-synth/dwdc011.d.ts.map +1 -0
- package/dist/lint/post-synth/dwdc012.d.ts +21 -0
- package/dist/lint/post-synth/dwdc012.d.ts.map +1 -0
- package/dist/lint/post-synth/dwde010.d.ts +32 -0
- package/dist/lint/post-synth/dwde010.d.ts.map +1 -0
- package/dist/lint/post-synth/dwde011.d.ts +33 -0
- package/dist/lint/post-synth/dwde011.d.ts.map +1 -0
- package/dist/lint/post-synth/dwds010.d.ts +24 -0
- package/dist/lint/post-synth/dwds010.d.ts.map +1 -0
- package/dist/lint/post-synth/index.d.ts.map +1 -1
- package/dist/manifest.json +1 -1
- package/dist/okf/index.md +6 -0
- package/dist/okf/rules/DWDC010.md +11 -0
- package/dist/okf/rules/DWDC011.md +11 -0
- package/dist/okf/rules/DWDC012.md +11 -0
- package/dist/okf/rules/DWDE010.md +11 -0
- package/dist/okf/rules/DWDE011.md +11 -0
- package/dist/okf/rules/DWDS010.md +11 -0
- package/dist/policy-text.d.ts +53 -0
- package/dist/policy-text.d.ts.map +1 -0
- package/dist/rules/dogwood-helpers.ts +139 -0
- package/dist/rules/dwdc010.ts +62 -0
- package/dist/rules/dwdc011.ts +61 -0
- package/dist/rules/dwdc012.ts +46 -0
- package/dist/rules/dwde010.ts +130 -0
- package/dist/rules/dwde011.ts +108 -0
- package/dist/rules/dwds010.ts +46 -0
- package/dist/serializer.d.ts +10 -18
- package/dist/serializer.d.ts.map +1 -1
- package/dist/skills/chant-cedar-authoring.md +180 -0
- package/dist/skills/chant-cedar-avp-embedding.md +125 -0
- package/dist/skills/chant-cedar-meta-policy.md +119 -0
- package/package.json +2 -2
- package/src/codegen/package.ts +3 -2
- package/src/config.test.ts +12 -0
- package/src/config.ts +28 -0
- package/src/dogwood/cli.test.ts +392 -0
- package/src/dogwood/cli.ts +545 -0
- package/src/dogwood/event-schema.test.ts +218 -0
- package/src/dogwood/event-schema.ts +318 -0
- package/src/dogwood/index.ts +198 -0
- package/src/dogwood/macros.test.ts +104 -0
- package/src/dogwood/macros.ts +229 -0
- package/src/dogwood/policy.test.ts +94 -0
- package/src/dogwood/policy.ts +141 -0
- package/src/dogwood/scan.ts +287 -0
- package/src/dogwood/serialize.test.ts +331 -0
- package/src/dogwood/serialize.ts +209 -0
- package/src/dogwood/temporal.test.ts +272 -0
- package/src/dogwood/temporal.ts +592 -0
- package/src/dogwood/testdata/custom-kinds.dwschema +17 -0
- package/src/dogwood/testdata/default-macros.dw +23 -0
- package/src/dogwood/testdata/lowered-read-after-login.json +13 -0
- package/src/dogwood/testdata/max-window-raised.dwschema +25 -0
- package/src/dogwood/testdata/pinned.dwschema +31 -0
- package/src/dogwood/testdata/read-after-login.cedarschema +20 -0
- package/src/dogwood/testdata/read-after-login.dw +17 -0
- package/src/dogwood/testdata/temporal-policies.dw +53 -0
- package/src/dogwood/upstream.ts +41 -0
- package/src/dogwood/window.ts +124 -0
- package/src/index.ts +24 -0
- package/src/lint/audit-catalog.ts +56 -0
- package/src/lint/post-synth/dogwood-helpers.ts +139 -0
- package/src/lint/post-synth/dwd-post-synth.test.ts +256 -0
- package/src/lint/post-synth/dwdc010.ts +62 -0
- package/src/lint/post-synth/dwdc011.ts +61 -0
- package/src/lint/post-synth/dwdc012.ts +46 -0
- package/src/lint/post-synth/dwde-post-synth.test.ts +368 -0
- package/src/lint/post-synth/dwde010.ts +130 -0
- package/src/lint/post-synth/dwde011.ts +108 -0
- package/src/lint/post-synth/dwds010.ts +46 -0
- package/src/lint/post-synth/index.ts +12 -0
- package/src/lint/post-synth/post-synth.test.ts +7 -3
- package/src/policy-text.ts +128 -0
- package/src/serializer.ts +71 -109
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
---
|
|
2
|
+
skill: chant-cedar-authoring
|
|
3
|
+
description: Author Cedar authorization policies as typed chant resources — schema to generated classes to .cedar and JSON outputs
|
|
4
|
+
user-invocable: true
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Cedar Policies as Typed Resources
|
|
8
|
+
|
|
9
|
+
## What this lexicon covers
|
|
10
|
+
|
|
11
|
+
Cedar is an authorization policy language. Its toolchain validates and evaluates
|
|
12
|
+
policies; it does not help you write them. There are no functions, no modules,
|
|
13
|
+
no loops, and templates carry exactly two slots (`?principal`, `?resource`), so
|
|
14
|
+
teams managing large policy sets generate `.cedar` text with string templating.
|
|
15
|
+
This lexicon replaces that with typed TypeScript.
|
|
16
|
+
|
|
17
|
+
Two artifacts come out of every build:
|
|
18
|
+
|
|
19
|
+
- `<name>.cedar` — the policy text every Cedar evaluator reads (Amazon Verified
|
|
20
|
+
Permissions, cedar-agent, an embedded `cedar-wasm`).
|
|
21
|
+
- `policies.cedar.json` — the same set in the Cedar JSON policy format, beside
|
|
22
|
+
it. This is also the parse source for import.
|
|
23
|
+
|
|
24
|
+
chant is nowhere in either. An emitted policy set is consumed by any evaluator.
|
|
25
|
+
|
|
26
|
+
## The three steps
|
|
27
|
+
|
|
28
|
+
### 1. Declare a schema
|
|
29
|
+
|
|
30
|
+
The schema is *your* file, not a global upstream — it is the input codegen
|
|
31
|
+
reads. Write it in Cedar's human-readable syntax and point the config at it:
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
// chant.config.ts
|
|
35
|
+
import type { ChantConfig } from "@intentius/chant";
|
|
36
|
+
import "@intentius/chant-lexicon-cedar";
|
|
37
|
+
|
|
38
|
+
export default {
|
|
39
|
+
lexicons: ["cedar"],
|
|
40
|
+
cedar: {
|
|
41
|
+
schema: "authz/app.cedarschema",
|
|
42
|
+
validation: { mode: "strict", requireProjectSchema: true },
|
|
43
|
+
},
|
|
44
|
+
} satisfies ChantConfig;
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Turn `requireProjectSchema` on once the project has its own schema. Without it a
|
|
48
|
+
missing file silently falls back to the bundled default, and the difference
|
|
49
|
+
between "your entity types" and "somebody else's" is invisible.
|
|
50
|
+
|
|
51
|
+
### 2. Run generate
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
npx chant generate --lexicon cedar
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
That produces, per declaration in the schema:
|
|
58
|
+
|
|
59
|
+
| Schema declaration | Generated |
|
|
60
|
+
|---|---|
|
|
61
|
+
| `entity Document in [Folder] = { … }` | `Document` class, `DocumentAttributes` property class, `DocumentUid` template-literal type |
|
|
62
|
+
| `action read appliesTo { … }` | `ReadAction` constant, `ReadContext` property class |
|
|
63
|
+
| — | `Policy` class, `EntityTypeName`, `ActionUid`, `PolicyScope`, `ALL_ACTIONS`, `ALL_ENTITY_TYPES` |
|
|
64
|
+
|
|
65
|
+
`DocumentUid` is `` `App::Document::"${string}"` `` — a typo'd namespace is a
|
|
66
|
+
compile error, not a validation error hours later.
|
|
67
|
+
|
|
68
|
+
### 3. Write policies
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
import { Policy, ReadAction, WriteAction, type UserUid } from "@intentius/chant-lexicon-cedar";
|
|
72
|
+
|
|
73
|
+
const archivist: UserUid = 'App::User::"archivist"';
|
|
74
|
+
|
|
75
|
+
export const ownerRead = new Policy({
|
|
76
|
+
effect: "permit",
|
|
77
|
+
principal: { is: "App::User" },
|
|
78
|
+
action: { in: [ReadAction, WriteAction] },
|
|
79
|
+
resource: { is: "App::Document" },
|
|
80
|
+
when: ["resource.owner == principal"],
|
|
81
|
+
annotations: { doc: "Owners always read their own documents." },
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
export const restrictDelete = new Policy({
|
|
85
|
+
effect: "forbid",
|
|
86
|
+
resource: { is: "App::Document" },
|
|
87
|
+
when: ['resource.classification == "confidential"'],
|
|
88
|
+
unless: [`principal == ${archivist}`],
|
|
89
|
+
});
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Policy props
|
|
93
|
+
|
|
94
|
+
| Prop | Meaning |
|
|
95
|
+
|------|---------|
|
|
96
|
+
| `effect` | `"permit"` or `"forbid"`. Defaults to `permit` |
|
|
97
|
+
| `principal`, `action`, `resource` | Scope constraints. Omit for unconstrained |
|
|
98
|
+
| `when` | Cedar expression strings, one `when { … }` clause each |
|
|
99
|
+
| `unless` | Cedar expression strings, one `unless { … }` clause each |
|
|
100
|
+
| `annotations` | `Record<string, string>`, emitted as `@key("value")` |
|
|
101
|
+
|
|
102
|
+
### Scope forms
|
|
103
|
+
|
|
104
|
+
| Written | Emitted |
|
|
105
|
+
|---|---|
|
|
106
|
+
| `{}` or omitted | `principal` |
|
|
107
|
+
| `{ eq: X }` | `principal == X` |
|
|
108
|
+
| `{ in: X }` | `principal in X` |
|
|
109
|
+
| `{ in: [X, Y] }` | `principal in [X, Y]` |
|
|
110
|
+
| `{ is: "App::User" }` | `principal is App::User` |
|
|
111
|
+
| `{ is: "App::User", in: X }` | `principal is App::User in X` |
|
|
112
|
+
|
|
113
|
+
`when`/`unless` stay strings. Cedar's expression grammar *is* the policy
|
|
114
|
+
language; typing it in TypeScript is a separate problem, and the escape hatch
|
|
115
|
+
would leak either way.
|
|
116
|
+
|
|
117
|
+
## Policy ids
|
|
118
|
+
|
|
119
|
+
The id comes from the export's logical name, kebab-cased: `allowAdminRead`
|
|
120
|
+
becomes `@id("allow-admin-read")`. Set `annotations.id` to pin one explicitly —
|
|
121
|
+
worth doing for a policy whose id something downstream references.
|
|
122
|
+
|
|
123
|
+
## Composites
|
|
124
|
+
|
|
125
|
+
Repeated policy shapes go in a factory, because Cedar has nowhere to put them.
|
|
126
|
+
|
|
127
|
+
```typescript
|
|
128
|
+
import {
|
|
129
|
+
DeleteAction,
|
|
130
|
+
DenyByDefaultSet,
|
|
131
|
+
OwnerCanManage,
|
|
132
|
+
ReadAction,
|
|
133
|
+
WriteAction,
|
|
134
|
+
} from "@intentius/chant-lexicon-cedar";
|
|
135
|
+
|
|
136
|
+
const docOwner = OwnerCanManage({
|
|
137
|
+
entityType: "App::Document",
|
|
138
|
+
actions: [ReadAction, WriteAction],
|
|
139
|
+
principal: "App::User",
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
const guarded = DenyByDefaultSet({
|
|
143
|
+
policies: [docOwner],
|
|
144
|
+
entityType: "App::Document",
|
|
145
|
+
actions: DeleteAction,
|
|
146
|
+
when: ['resource.classification == "confidential"'],
|
|
147
|
+
unless: ['principal == App::User::"archivist"'],
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
export const [confidentialFloor, documentOwnerGrant] = guarded.all;
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
`DenyByDefaultSet` returns the `forbid` floor and its members from one call, so
|
|
154
|
+
deleting the floor deletes the grants with it. A `forbid` beats every `permit`
|
|
155
|
+
in the set unconditionally — it is the only construct that survives a later,
|
|
156
|
+
wider grant.
|
|
157
|
+
|
|
158
|
+
## Checking the result
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
npx chant build # emits both artifacts, runs the CED rules
|
|
162
|
+
npx chant coverage --lexicon cedar # is every schema declaration generated?
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
The MCP tool `cedar:coverage` answers the other question: which schema entity
|
|
166
|
+
types and actions the *policy set* can reach, which are reachable only from a
|
|
167
|
+
`forbid`, and which no policy touches at all. An entity type nothing covers is
|
|
168
|
+
inert under Cedar's default-deny — either the intent or a hole.
|
|
169
|
+
|
|
170
|
+
## Things that will bite
|
|
171
|
+
|
|
172
|
+
- **An empty schema validates everything clean.** `checkParseSchema("")`
|
|
173
|
+
succeeds. Set `requireProjectSchema: true`.
|
|
174
|
+
- **`Group` and `Team`-shaped container entities appear in no `appliesTo`.**
|
|
175
|
+
They exist to be `in`, so no policy — not even `permit (principal, action,
|
|
176
|
+
resource)` — resolves to them. `cedar:coverage` reports that honestly rather
|
|
177
|
+
than rounding it up.
|
|
178
|
+
- **A policy naming an entity type outside the schema still parses.** It
|
|
179
|
+
resolves to an empty request envelope and never fires. `cedar:coverage`
|
|
180
|
+
reports it under `inert`.
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
---
|
|
2
|
+
skill: chant-cedar-avp-embedding
|
|
3
|
+
description: Embed a typed cedar-lexicon policy into an AWS Verified Permissions policy resource instead of a hand-written string
|
|
4
|
+
user-invocable: true
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Cedar Policies Inside Verified Permissions
|
|
8
|
+
|
|
9
|
+
## The seam
|
|
10
|
+
|
|
11
|
+
Amazon Verified Permissions is one deployment vehicle for Cedar, and chant
|
|
12
|
+
already ships it: `AWS::VerifiedPermissions::Policy` in the aws lexicon carries
|
|
13
|
+
its policy text in a `definition.static.statement` field typed `CedarPolicy` —
|
|
14
|
+
which is to say, `string`.
|
|
15
|
+
|
|
16
|
+
That string is the seam. Everything upstream of it — the schema, the entity
|
|
17
|
+
types, the actions, the scope constraints — is what the cedar lexicon owns.
|
|
18
|
+
Everything downstream — the policy store, the CloudFormation `ApplyOp`, the IAM
|
|
19
|
+
around it — is the aws lexicon's, and already works.
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
cedar lexicon aws lexicon
|
|
23
|
+
schema → Policy → .cedar text → VerifiedPermissionsPolicy.definition.static.statement
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
The walk-away test holds on both sides. The emitted `.cedar` file is read by any
|
|
27
|
+
evaluator with no AWS involved; the AVP resource deploys through the same
|
|
28
|
+
CloudFormation path every other AWS resource does.
|
|
29
|
+
|
|
30
|
+
## The typed handoff
|
|
31
|
+
|
|
32
|
+
`avpPolicyDefinition(name, props)` returns exactly the `Definition` property
|
|
33
|
+
`AWS::VerifiedPermissions::Policy` takes, rendered by the same renderer that
|
|
34
|
+
writes the `.cedar` file — so the deployed policy and the reviewed file cannot
|
|
35
|
+
disagree.
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
import { Policy, ReadAction, avpPolicyDefinition } from "@intentius/chant-lexicon-cedar";
|
|
39
|
+
import { VerifiedPermissionsPolicy } from "@intentius/chant-lexicon-aws";
|
|
40
|
+
|
|
41
|
+
const ownerReadProps = {
|
|
42
|
+
effect: "permit",
|
|
43
|
+
principal: { is: "App::User" },
|
|
44
|
+
action: { eq: ReadAction },
|
|
45
|
+
resource: { is: "App::Document" },
|
|
46
|
+
when: ["resource.owner == principal"],
|
|
47
|
+
} as const;
|
|
48
|
+
|
|
49
|
+
/** The evaluator-agnostic artifact: this is what lands in the `.cedar` file. */
|
|
50
|
+
export const ownerRead = new Policy(ownerReadProps);
|
|
51
|
+
|
|
52
|
+
/** The AVP deployment view of the same policy. */
|
|
53
|
+
export const ownerReadAvp = new VerifiedPermissionsPolicy({
|
|
54
|
+
PolicyStoreId: policyStore.ref(),
|
|
55
|
+
Definition: avpPolicyDefinition("ownerRead", ownerReadProps, {
|
|
56
|
+
ownership: { stack: "authz", env: "prod" },
|
|
57
|
+
description: "Owners read their own documents.",
|
|
58
|
+
}),
|
|
59
|
+
});
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Beside it: `avpStatement()` for the bare string, `avpStatementJSON()` for
|
|
63
|
+
evaluators that take the JSON policy format, and `avpPolicySet(entities)` to
|
|
64
|
+
render a whole build's policies at once, keyed by chant entity name.
|
|
65
|
+
|
|
66
|
+
**The cedar lexicon does not depend on the aws lexicon.** The seam is the data
|
|
67
|
+
shape, which is stable CloudFormation. `examples/avp-embedding/` shows the
|
|
68
|
+
pairing with a plain-object stand-in, because the shipped cedar examples build
|
|
69
|
+
against the cedar serializer alone.
|
|
70
|
+
|
|
71
|
+
## The lifecycle surface
|
|
72
|
+
|
|
73
|
+
`describeResources()`, `observeAmbient()` and `exportResources()` read a live
|
|
74
|
+
policy store. Point them at one with `CEDAR_AVP_POLICY_STORE_ID` (or
|
|
75
|
+
`CEDAR_AVP_POLICY_STORE_ID_<ENV>`), or a `policyStoreId` prop on a declared
|
|
76
|
+
policy.
|
|
77
|
+
|
|
78
|
+
The link from a chant entity to a live policy is the Cedar `@id` annotation,
|
|
79
|
+
which is derived from the export name (`ownerRead` → `owner-read`) unless
|
|
80
|
+
`annotations.id` overrides it. Rename an export and the observation follows it;
|
|
81
|
+
rename it *and* pin `annotations.id` and the live policy stays matched.
|
|
82
|
+
|
|
83
|
+
## Rules
|
|
84
|
+
|
|
85
|
+
- **Do not write the statement as prose.** A hand-typed
|
|
86
|
+
`"permit(principal, action, resource);"` in an AVP resource is the exact thing
|
|
87
|
+
this lexicon exists to remove, and the meta-policy wall (see the
|
|
88
|
+
`chant-cedar-meta-policy` skill) fails a bare permit in a prod build.
|
|
89
|
+
- **Do not try to tag an individual policy.** AVP policy *stores* are taggable;
|
|
90
|
+
individual policies are not — `CreatePolicy` has no tag surface and a policy
|
|
91
|
+
has no ARN. chant's per-policy marker therefore rides in the policy
|
|
92
|
+
description, stamped by passing `ownership` to `avpPolicyDefinition` and read
|
|
93
|
+
back by `describeResources`/`exportResources`. Store tags remain the coarse
|
|
94
|
+
channel. The design record, including what the choice costs, is
|
|
95
|
+
`src/avp/OWNERSHIP.md`.
|
|
96
|
+
- **Do not hand-write the description when you want ownership.** Pass
|
|
97
|
+
`ownership` and let the marker be encoded; the description is capped at 150
|
|
98
|
+
characters and the encoder truncates prose rather than the marker, which is
|
|
99
|
+
what keeps a chant-owned policy from silently reading as foreign.
|
|
100
|
+
- **Do not treat an ambient permit as housekeeping.** A permit found in a store
|
|
101
|
+
that no source file declares is a standing grant somebody made outside review.
|
|
102
|
+
It is a security finding. `observeAmbient()` reports the statement and its
|
|
103
|
+
effect and stops short of the verdict — the judgement is yours.
|
|
104
|
+
|
|
105
|
+
## Non-AVP evaluators
|
|
106
|
+
|
|
107
|
+
AVP is not the only target, and the lexicon does not privilege it. The same
|
|
108
|
+
emitted `.cedar` and `policies.cedar.json` feed:
|
|
109
|
+
|
|
110
|
+
- **cedar-agent** — a standalone Cedar decision service; point it at the policy
|
|
111
|
+
file and the entity store.
|
|
112
|
+
- **An embedded `cedar-wasm`** — the package this lexicon already depends on.
|
|
113
|
+
Load the policy text in-process and call `isAuthorized`.
|
|
114
|
+
- **Cloudflare-style embeddings** — the same file, read at the edge.
|
|
115
|
+
|
|
116
|
+
If the deployment target is anything other than AVP, there is no embedding step
|
|
117
|
+
at all. Emit the files and ship them.
|
|
118
|
+
|
|
119
|
+
## Cedar-for-Kubernetes
|
|
120
|
+
|
|
121
|
+
The CNCF push includes Cedar as a Kubernetes authorizer, with policies as CRDs.
|
|
122
|
+
Those kinds belong to the k8s lexicon's CRD sources — the same rule that kept
|
|
123
|
+
`helm.cattle.io` out of the k3s lexicon. What the cedar lexicon does there is
|
|
124
|
+
lint the policy *text* embedded in those kinds, which is the pattern the ARGO
|
|
125
|
+
rules already use.
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
---
|
|
2
|
+
skill: chant-cedar-meta-policy
|
|
3
|
+
description: Organizational policy over Cedar policy sets — the bare-permit wall, forbid conventions, and env-aware severity
|
|
4
|
+
user-invocable: true
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Policy About Policy
|
|
8
|
+
|
|
9
|
+
## The ruling this sits under
|
|
10
|
+
|
|
11
|
+
Cedar is a target, never chant's gate. There is no `cedarGate()` and there will
|
|
12
|
+
not be one: organizational policy in chant is TypeScript post-synth checks, and
|
|
13
|
+
a second policy engine would duplicate the lint engine and break "TypeScript is
|
|
14
|
+
the one language."
|
|
15
|
+
|
|
16
|
+
So the rules below are ordinary `PostSynthCheck`s and lint rules under the `CED`
|
|
17
|
+
prefix. They read the emitted policy set the way any other check reads emitted
|
|
18
|
+
YAML. Cedar's own validator runs beside them, in-process, through
|
|
19
|
+
`@cedar-policy/cedar-wasm` — no CLI on PATH, no Docker.
|
|
20
|
+
|
|
21
|
+
## The bare-permit wall
|
|
22
|
+
|
|
23
|
+
```cedar
|
|
24
|
+
permit (principal, action, resource);
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Every scope position unconstrained, no `when`, no `unless`. It grants every
|
|
28
|
+
principal every action on every resource. It is legal Cedar, it validates
|
|
29
|
+
clean, and it is the single most damaging line a policy set can contain.
|
|
30
|
+
|
|
31
|
+
The rule is **env-aware, not absolute**:
|
|
32
|
+
|
|
33
|
+
| Environment | Verdict |
|
|
34
|
+
|---|---|
|
|
35
|
+
| dev / local | warn — a scratch policy set during development is a normal state |
|
|
36
|
+
| staging | warn, and expect it fixed before promotion |
|
|
37
|
+
| **prod** | **fail the build** |
|
|
38
|
+
|
|
39
|
+
Env-aware because an absolute rule gets suppressed the first time it fires
|
|
40
|
+
during development, and a suppressed rule protects nothing. Failing only where
|
|
41
|
+
the blast radius is real keeps the wall credible.
|
|
42
|
+
|
|
43
|
+
A permit with any of the following is not bare and does not trip the wall:
|
|
44
|
+
|
|
45
|
+
- a constrained scope position (`is`, `in`, `==`) on principal, action, or
|
|
46
|
+
resource, or
|
|
47
|
+
- at least one `when` or `unless` clause.
|
|
48
|
+
|
|
49
|
+
## Schema-absent references
|
|
50
|
+
|
|
51
|
+
A policy naming an entity type or action the schema does not declare fails
|
|
52
|
+
**everywhere** — dev included. There is no environment where that is intended.
|
|
53
|
+
Two distinct failure modes hide behind it:
|
|
54
|
+
|
|
55
|
+
1. **The typo.** `App::Documnt`. With generated classes this is a compile error
|
|
56
|
+
before any check runs, which is the point of the codegen. It survives only in
|
|
57
|
+
hand-written expression strings inside `when`/`unless`.
|
|
58
|
+
2. **The silent no-op.** A scope naming an entity type outside the schema
|
|
59
|
+
*parses*, and `getValidRequestEnvsPolicy` answers "success, nothing" — an
|
|
60
|
+
empty request envelope. The policy is well-formed, deployed, and can never
|
|
61
|
+
fire. `cedar:coverage` reports these under `inert`.
|
|
62
|
+
|
|
63
|
+
## Forbid conventions
|
|
64
|
+
|
|
65
|
+
Cedar is default-deny, so a `forbid` is never about the absence of a grant. It
|
|
66
|
+
is about the presence of a bad one: a forbid beats every permit in the set
|
|
67
|
+
unconditionally, which makes it the only construct that survives a later, wider
|
|
68
|
+
grant somebody adds next quarter.
|
|
69
|
+
|
|
70
|
+
Three conventions follow:
|
|
71
|
+
|
|
72
|
+
**Every forbid carries a guard.** An unguarded `forbid (principal, action,
|
|
73
|
+
resource)` denies everything and no permit can lift it — the policy set
|
|
74
|
+
authorizes nothing. `DenyByDefaultSet` throws on an empty `when` for this
|
|
75
|
+
reason.
|
|
76
|
+
|
|
77
|
+
**A forbid and the permits it governs ship together.** Separated, the forbid
|
|
78
|
+
gets deleted during a refactor and the permits keep working, wider than anyone
|
|
79
|
+
intended. `DenyByDefaultSet({ policies, when })` returns both from one call.
|
|
80
|
+
|
|
81
|
+
**Sensitive resources get an explicit floor, not just an absent permit.**
|
|
82
|
+
"Nobody wrote a permit for it" and "a forbid says no" look identical at
|
|
83
|
+
evaluation time and completely different in review. `cedar:coverage`'s
|
|
84
|
+
`forbidOnly` list is how you find declarations that have a floor; its
|
|
85
|
+
`uncovered` list is how you find the ones relying on absence.
|
|
86
|
+
|
|
87
|
+
## Cross-domain checks
|
|
88
|
+
|
|
89
|
+
This is the thing no Cedar tool can express, because Cedar only ever sees
|
|
90
|
+
policies. In a chant build, policies and the infrastructure they govern are in
|
|
91
|
+
one entity graph, so a post-synth check can span both:
|
|
92
|
+
|
|
93
|
+
- an entity id in a policy references an actual resource declaration
|
|
94
|
+
- every declared bucket is covered by at least one `forbid`
|
|
95
|
+
- no schema action lacks any policy
|
|
96
|
+
|
|
97
|
+
These are ordinary post-synth checks. They are the differentiator, and they only
|
|
98
|
+
work because the policy set and the estate are built together.
|
|
99
|
+
|
|
100
|
+
## Severity, by environment
|
|
101
|
+
|
|
102
|
+
| Finding | dev | staging | prod |
|
|
103
|
+
|---|---|---|---|
|
|
104
|
+
| Bare permit | warn | warn | fail |
|
|
105
|
+
| Entity type or action absent from schema | fail | fail | fail |
|
|
106
|
+
| Unguarded forbid | fail | fail | fail |
|
|
107
|
+
| Policy with an empty request envelope (inert) | warn | warn | fail |
|
|
108
|
+
| Schema action no policy covers | info | warn | warn |
|
|
109
|
+
| Entity type reachable only from a forbid | info | info | info |
|
|
110
|
+
|
|
111
|
+
The last row is deliberately never a failure. A resource nothing grants access
|
|
112
|
+
to is frequently correct.
|
|
113
|
+
|
|
114
|
+
## Where these live
|
|
115
|
+
|
|
116
|
+
Post-synth checks and their catalog entries are **INTENTIUS/chant#1651**'s
|
|
117
|
+
scope. This skill describes the conventions the checks encode; if you are
|
|
118
|
+
writing a check, put it in `src/lint/post-synth/` with a `CED` id and an
|
|
119
|
+
`auditCatalog()` entry, not in a policy file.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intentius/chant-lexicon-cedar",
|
|
3
|
-
"version": "0.44.
|
|
3
|
+
"version": "0.44.9",
|
|
4
4
|
"description": "Cedar lexicon for chant — typed authoring for Cedar authorization policies",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://intentius.io/chant",
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
},
|
|
70
70
|
"peerDependencies": {
|
|
71
71
|
"zod": "^4.3.6",
|
|
72
|
-
"@intentius/chant": "^0.44.
|
|
72
|
+
"@intentius/chant": "^0.44.9",
|
|
73
73
|
"typescript": "^5.9.3"
|
|
74
74
|
}
|
|
75
75
|
}
|
package/src/codegen/package.ts
CHANGED
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
* Cedar lexicon packaging — delegates to core's packagePipeline.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
+
import { cedarPlugin } from "../plugin";
|
|
5
6
|
import { readFileSync } from "fs";
|
|
6
7
|
import { dirname, join } from "path";
|
|
7
8
|
import { fileURLToPath } from "url";
|
|
8
9
|
import {
|
|
10
|
+
collectSkills,
|
|
9
11
|
packagePipeline,
|
|
10
12
|
type PackageOptions,
|
|
11
13
|
type PackageResult,
|
|
@@ -42,8 +44,7 @@ export async function packageLexicon(opts: PackageOptions = {}): Promise<Package
|
|
|
42
44
|
|
|
43
45
|
srcDir: pkgDir,
|
|
44
46
|
|
|
45
|
-
|
|
46
|
-
collectSkills: () => new Map(),
|
|
47
|
+
collectSkills: () => collectSkills(cedarPlugin.skills?.() ?? []),
|
|
47
48
|
|
|
48
49
|
version: pkgJson.version ?? "0.0.0",
|
|
49
50
|
},
|
package/src/config.test.ts
CHANGED
|
@@ -37,6 +37,18 @@ describe("cedar config namespace", () => {
|
|
|
37
37
|
it("leaves everything optional, so an empty namespace is legal", () => {
|
|
38
38
|
expect(cedarConfigSchema.parse({})).toEqual({});
|
|
39
39
|
});
|
|
40
|
+
|
|
41
|
+
it("takes the dogwood binary path (#1659)", () => {
|
|
42
|
+
const parsed = cedarConfigSchema.parse({ dogwood: { binary: "../dogwood/target/release/dogwood" } });
|
|
43
|
+
expect(parsed.dogwood?.binary).toBe("../dogwood/target/release/dogwood");
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("rejects a typo in the dogwood namespace, where a silent skip would follow", () => {
|
|
47
|
+
// A misspelled key here means "no binary found", and "no binary found" is
|
|
48
|
+
// an advisory rather than a failure — exactly the case strictObject exists
|
|
49
|
+
// to catch before it turns into a validation gap nobody notices.
|
|
50
|
+
expect(() => cedarConfigSchema.parse({ dogwood: { path: "/usr/local/bin/dogwood" } })).toThrow();
|
|
51
|
+
});
|
|
40
52
|
});
|
|
41
53
|
|
|
42
54
|
describe("schema resolution", () => {
|
package/src/config.ts
CHANGED
|
@@ -71,6 +71,34 @@ export const cedarConfigSchema = z.strictObject({
|
|
|
71
71
|
requireProjectSchema: z.boolean().optional(),
|
|
72
72
|
})
|
|
73
73
|
.optional(),
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* The dogwood dialect's CLI-gated leg (#1659).
|
|
77
|
+
*
|
|
78
|
+
* `strictObject` again, for the reason the outer one is: a typo here is the
|
|
79
|
+
* difference between "full .dw validation ran" and "DWDE010 said it could
|
|
80
|
+
* not run", and the second is easy to skim past.
|
|
81
|
+
*/
|
|
82
|
+
dogwood: z
|
|
83
|
+
.strictObject({
|
|
84
|
+
/**
|
|
85
|
+
* Path to the `dogwood` binary, absolute or relative to the config file.
|
|
86
|
+
*
|
|
87
|
+
* Optional, and its absence is not an error: DWDE010 warns-and-skips
|
|
88
|
+
* with an issue-linked advisory when no binary is found, which is the
|
|
89
|
+
* epic's explicit exception. Set this when the binary is built somewhere
|
|
90
|
+
* `PATH` does not reach — the on-demand harness shape the epic borrows
|
|
91
|
+
* from forgejo-runtime-e2e.
|
|
92
|
+
*
|
|
93
|
+
* A `chant.config.ts` cannot be read from inside a post-synth check —
|
|
94
|
+
* `check()` is synchronous and evaluating project code is not — so this
|
|
95
|
+
* key is honoured from `chant.config.json` and the `CHANT_DOGWOOD_BINARY`
|
|
96
|
+
* environment variable covers the TypeScript-config case. See
|
|
97
|
+
* `src/dogwood/cli.ts`.
|
|
98
|
+
*/
|
|
99
|
+
binary: z.string().optional(),
|
|
100
|
+
})
|
|
101
|
+
.optional(),
|
|
74
102
|
});
|
|
75
103
|
|
|
76
104
|
export type CedarConfig = z.infer<typeof cedarConfigSchema>;
|