Skip to content

Commit 02b4cb5

Browse files
committed
wip: almost onto Grants now
1 parent da25719 commit 02b4cb5

File tree

6 files changed

+152
-6
lines changed

6 files changed

+152
-6
lines changed

docs/reference/specifications/PSP-1 - Capability Model and Grammar.mdx

Lines changed: 148 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,18 @@ Capability evaluation depends on small, versioned rulebooks ("registries"):
8989
- Resource Schemes: normalization and subset comparators per scheme.
9090
- Channel Lattices: partial order used by channel_geq.
9191
- Builtins: the available operations (opcodes), their types, and tightening rules.
92+
- PSP-4 MAY also define domain verb/resource registries (e.g., energy verbs; asset:/bacnet:/ocpp: schemes) and TAP-referenced trust registries (e.g., notary key lists, DKIM selector archives, origin key policies). CEPs do not consume these artifacts directly; if used, their outputs appear as environment facts and are asserted in Programs (e.g., via ctx_eq).
9293

9394
A registry ID is a content-addressed identifier (e.g., a CID/multihash) for a specific, immutable entry or snapshot in one of these registries.
9495

9596
### Definitions
9697

97-
Channel lattice and channel_lattice_id
98+
Channel `lattice` and `channel_lattice_id`:
9899

99100
- A channel lattice defines a partial order over channel profiles (e.g., mtls:v1 ≥ tls_exporter:v1 ≥ dpop:v1 ≥ bearer:v1). It is the rulebook used by the builtin channel_geq(channel, floor).
100101
- channel_lattice_id is the content-addressed ID of the specific lattice used to interpret "≥". It is required whenever a Program uses channel_geq.
101102

102-
Builtins and builtins_id
103+
Builtins and `builtins_id`:
103104

104105
- The builtins registry defines each opcode's semantics, types, and attenuation tightening rules (e.g., within_time, ttl_ok, in_pairset, channel_geq, ctx_eq, presenter_is).
105106
- builtins_id is the content-addressed ID of the exact builtin set the Program uses.
@@ -108,7 +109,7 @@ Resource schemes:
108109

109110
- Each resource scheme (vault:, net:, k8s:, …) has a registry entry that defines normalization and a decidable subset comparator. In PSP-1, comparators are selected by scheme name; no per-scheme ID is pinned.
110111

111-
Verbs
112+
Verbs:
112113

113114
- Verbs are namespaced strings (e.g., secret:read). Evaluation treats them as strings for equality. TAP may govern allowlists; PSP-1 does not require pinning a verbs set.
114115

@@ -196,23 +197,26 @@ At verification, the CEP supplies an environment of facts. Builtins may referenc
196197
- enforcer: Str — DID/identifier of the enforcing CEP (audience).
197198
- channel: Str — profile representing the live session's binding.
198199
- ctx: `Map<Str, Term>` - runtime context (e.g., `{"ns":"prod","pod":"runner-42"}`).
199-
- Optional environment facts (TAPgated)
200+
- Optional environment facts (TAP-gated)
200201
- lease_status - opaque assurance/freshness input for lease checks (no I/O in the builtin).
202+
- TAP MAY require additional environment facts (e.g., provenance labels, jurisdiction tags, or digest references) and define how they are obtained and verified. PSP-1 does not enumerate these; Programs assert them via equality (e.g., ctx_eq).
201203
- Missing facts (normative)
202204
- If a builtin present in the Program requires an environment fact that is missing, evaluation MUST fail closed.
203205

204-
#### Bultins and registries
206+
#### Builtins and registries
205207

206208
- Each builtin op_id, its type signature, and its tightening rule are defined in the Builtins registry (PSP-4). The exact set in use is pinned by builtins_id in the Grant.
207209
- Channel comparisons (e.g., channel_geq) consult a pinned channel_lattice_id when present.
208210
- Resource subset checks in declaration-aware builtins (e.g., in_pairset) consult the scheme comparator selected by the resource's scheme name.
209211
- If a builtin, lattice, or comparator required by the Program is unknown or unavailable, evaluation MUST fail closed.
212+
- Programs may constrain the live session's profile using `channel_geq(channel, "…")` as defined by the pinned channel lattice. Programs may also assert runtime or provenance context via equality over environment facts (e.g., ctx_eq("k","v")). How those environment facts are obtained or validated — including the presentation binding to a live session - is outside the CPL/0 language and governed by TAP and PSP-2.
210213

211214
#### Typing, totality and failure modes
212215

213216
- Builtins MUST validate argument types at evaluation time. Ill-typed invocations MUST fail closed.
214217
- Strings MUST be considered in NFC for comparison purposes; Bytes are compared as exact octets.
215218
- Evaluation MUST be performed under CEP-enforced limits (CPU/steps/memory). Exceeding limits MUST result in deny.
219+
- The `now: Int` fact is CEP-provided and subject to TAP time-discipline; PSP-1 is agnostic to the time source.
216220

217221
#### Relationship with Biscuit Datalog (Informative)
218222

@@ -225,9 +229,147 @@ At verification, the CEP supplies an environment of facts. Builtins may referenc
225229

226230
### Declarations
227231

232+
Declarations are finite, canonical datasets that a Grant carries alongside the Program. Programs consult Declarations via builtins under pure, bounded evaluation (no network I/O). Declarations exist to express scope allowlists compactly and to make attenuation (subset) checks mechanical and fast.
233+
234+
- Declarations MUST be finite, deterministically canonicalized (normalize, sort, deduplicate), and content-addressed (e.g., with a content identifier).
235+
- Declarations referenced by a Program MUST be bundled in the Grant so CEPs can evaluate without external fetches.
236+
- A CEP MUST deny if a Program references an unknown declaration kind or if a required scheme comparator is unavailable.
237+
238+
#### PairSet
239+
240+
- Definition: PairSet is a finite set of (action: Str, resource: Str) pairs.
241+
- Purpose: express an allowlist of "what actions on which resources" a capability can authorize.
242+
- Canonicalization:
243+
- Normalize each resource string per its scheme's registry entry (PSP-4).
244+
- Sort pairs lexicographically (e.g., by action, then by normalized resource bytes).
245+
- Deduplicate exact duplicates.
246+
- Content-address the canonical bytes to get a stable identifier (CID).
247+
- Portability: PairSets are bundled in the Grant payload (PSP-3 binds bytes) so a CEP can evaluate without network I/O.
248+
249+
Use PairSet when the allowlist is irregular (different actions per resource) and a simple factorization would be incorrect.
250+
251+
#### ActionSet
252+
253+
ActionSet is a finite set of actions. It factorizes "what" independently of "where."
254+
255+
- Canonicalization:
256+
- Actions MUST be normalized as strings, sorted deterministically, and deduplicated.
257+
- The canonical bytes MUST be content-addressed; the content address identifies the ActionSet.
258+
- Program use
259+
- in_actionset(action, Actions#CID) evaluates to true if and only if action ∈ ActionSet(CID).
260+
- Attenuation
261+
- For a derived Grant, the child ActionSet MUST be a subset of the parent ActionSet.
262+
263+
#### ResourceSet
264+
265+
ResourceSet is a finite set of resources (scheme-qualified strings) with scheme-defined subset semantics.
266+
267+
- Canonicalization
268+
- Each resource MUST be normalized per its scheme's registry entry.
269+
- The set MUST be sorted deterministically and deduplicated.
270+
- The canonical bytes MUST be content-addressed; the content address identifies the ResourceSet.
271+
- Program use
272+
- in_resourceset(resource, Resources#CID) evaluates to true if and only if there exists r_sel ∈ ResourceSet(CID) with resource ⊆ r_sel under the scheme's registered subset comparator.
273+
- Attenuation
274+
- For a derived Grant, the child ResourceSet MUST be a subset of the parent ResourceSet (under set inclusion, using the same normalization and comparator).
275+
276+
Use ActionSet * ResourceSet when the policy is truly a cross-product ("any action in A over any resource in R"). Use PairSet when the matrix is irregular.
277+
278+
#### Program Use
279+
280+
- Declarations are data sources invoked via builtins; Programs combine these with other literals (within_time, ttl_ok, channel_geq, ctx_eq, presenter_is).
281+
- Actions appear as strings; resources are scheme-qualified strings; subset relations are defined per scheme in the registry (no unbounded regex/globs; selectors MUST be finite or safely bounded with a decidable comparator).
282+
- Unknown declaration kinds, schemes, or comparators MUST cause deny.
283+
284+
#### Attenuation over Declarations
285+
286+
- Delegation MUST NOT broaden Declarations.
287+
- PairSet_child ⊆ PairSet_parent.
288+
- ActionSet_child ⊆ ActionSet_parent.
289+
- ResourceSet_child ⊆ ResourceSet_parent.
290+
- CEPs MUST verify subset relations hop-by-hop along the delegation chain using the same normalization and comparators; failures or unknowns MUST cause deny.
291+
292+
#### Profiles
293+
294+
- This specification standardizes exactly three Declaration kinds: PairSet, ActionSet, ResourceSet. Profiles MAY further constrain their usage (e.g., disallow ResourceSet for certain verbs) or prescribe default comparators per scheme. A CEP MUST deny if a Program references a declaration kind not supported by the active profile or if a required comparator is not available.
295+
228296
### Program Canonical Format (PCF) & Digest
229297

230-
### Verbs & Resources
298+
Programs MUST be normalized to a canonical tree and deterministically encoded before deriving identity. Canonicalization ensures portable, stable program identifiers across implementations and platforms. The canonical bytes and multihash parameters are specified by PSP-3; this section defines the abstract normalization rules (PCF).
299+
300+
#### Purpose
301+
302+
- PCF yields a unique representation for a Program so syntactic permutations or duplicate literals do not change identity.
303+
- Canonicalization applies to the abstract Program (Checks, Queries, Literals and their arguments), independent of transport/envelope.
304+
305+
#### Normalization rules
306+
307+
- Literals within a Query MUST be sorted by a total order over:
308+
- literal kind (e.g., Builtin before Atom if Atoms are present),
309+
- operator/predicate identifier (text in NFC, bytewise),
310+
- arguments tuple under canonical term order.
311+
- Duplicate Literals within a Query MUST be removed.
312+
- Queries within a Check MUST be sorted lexicographically by their canonical literal lists and duplicates removed.
313+
- Checks within a Program MUST be sorted lexicographically by their canonical query lists and duplicates removed.
314+
315+
#### Canonical term order
316+
317+
- Strings MUST be NFC-normalized and compared/encoded as exact bytes.
318+
- Integers MUST be arbitrary-precision, with no float encodings.
319+
- Bytes MUST be exact octets, ordered lexicographically.
320+
- Booleans MUST use canonical forms, with false < true for ordering.
321+
- Environment and declaration references (e.g., "action", "resource", "Pairs#CID") MUST be encoded deterministically and consistently wherever they appear.
322+
323+
#### Prohibited/non-canonical forms
324+
325+
- Floating-point numbers MUST NOT appear in Programs.
326+
- Indefinite-length encodings and non-normalized strings MUST NOT appear in canonical bytes (see PSP-3 for encoding constraints).
327+
- Any literal or term introducing non-determinism or network I/O MUST NOT be part of a Program.
328+
329+
#### Deterministic encoding and identity
330+
331+
- program_bytes = ENCODE(PCF(Program)) as specified by PSP-3.
332+
- program_id = multihash(program_bytes) as specified by PSP-3.
333+
- A Grant carrying program_bytes and program_id MUST be rejected if recomputation does not match.
334+
335+
#### Failure handling
336+
337+
- Canonicalization MUST fail, and verification MUST deny, if a Program contains an unknown operator, ill-typed arguments under a builtin's signature, non-normalized strings, prohibited numbers, or otherwise cannot be normalized.
338+
- Unknown builtins, schemes, or comparators referenced by the Program MUST cause deny during evaluation; if their presence prevents deterministic term encodings, identity derivation MUST fail.
339+
340+
#### Stability and tests
341+
342+
- Canonicalization is part of the trusted computing base. Implementations SHOULD cross-test that semantically identical Programs (after literal reordering, duplicate removal, and string normalization) yield identical program_bytes and program_id across platforms and versions.
343+
344+
#### Informative guidance
345+
346+
Keep operator identifiers stable and registry-pinned to avoid PCF instability from renaming.
347+
When referencing Declarations by content address (e.g., “Pairs#CID”), ensure the reference syntax and encoding are deterministic and consistent.
348+
349+
### Verbs & Resources (Reader Guidance)
350+
351+
Verbs are namespaced strings (e.g., “secret:read”, “deploy:to_env”, “energy:curtail”). They appear as the action fact and as elements inside Declarations (PairSet/ActionSet). Verb semantics MUST be documented in a registry with versioned definitions. Registry entries SHOULD declare expected resource scheme(s) and any required constraints (e.g., time window, channel profile, mediated surface references). A CEP MUST deny if a required constraint is not asserted by the Program. TAP MAY whitelist verbs per domain; unknown verbs default to non‑permitted unless TAP specifies otherwise.
352+
353+
Resources are scheme‑qualified identifiers (URI‑like) that denote targets (e.g., “vault:secret://org/team/key”, “k8s://ns/prod”, “asset:building‑12:rtu‑3”, “api:https://vendor.com/path”). They appear as the resource fact and as elements inside Declarations (PairSet/ResourceSet). Each resource scheme MUST have a registry entry defining normalization and a decidable subset comparator. Grants SHOULD use specific resources. If a scheme permits selectors, their use MUST be finite or safely bounded with a defined subset proof. Unknown schemes or unavailable comparators MUST cause deny. TAP MAY restrict acceptable schemes or forms per domain and verb.
354+
355+
Delegation subset: For derived Grants, resource.child MUST be a subset of resource.parent under the scheme’s comparator; for Declarations, child sets MUST be subsets of parent sets.
356+
357+
Programs consult finite allowlists via Declarations and evaluate constraints using builtins. Verb and scheme registries define documentation and comparators; unknowns fail closed.
358+
359+
---
360+
361+
## Grants
362+
363+
## Presentations
364+
365+
## Delegation && Attenuation
366+
367+
## Verification Algorithm
368+
369+
## Security Considerations
370+
371+
372+
231373

232374

233375

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# PSP-4 - Registries
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# PSP-5 - Attestations
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# PSP-6 - TAP and RAM

docs/reference/specifications/PSP-6 - TAP.mdx

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# PSP-7 - CEP and Bridge Adapter Profiles

0 commit comments

Comments
 (0)