Skip to content

Messages and Policy

A node receives signed requests, decides about each from verified facts, runs a handler, and returns a signed reply.

Handle a route

@node.handler("/task/run")
def run(m):
    # m: id, sender, payload, facts
    return {"done": m["payload"]["name"]}

A handler can be called again for the same message after a crash. Make it idempotent, using m["id"].

Send a request

message = sender.message(recipient_aid, "/task/run", {"name": "x"}, credential=bundle)
reply = recipient.request(message)           # or POST /v1/input and GET /v1/output/{id}
event = sender.open_reply(reply, recipient_aid)
print(event.ked["a"]["decision"], event.ked["a"].get("result"))

What is checked

  1. The message is addressed to this node, and the credential is bound to the signature.
  2. The time is within max_skew_seconds (120).
  3. The signature satisfies the sender's current key state, as confirmed by witnesses and watchers.
  4. The message was not processed before with other signatures. An exact repetition returns the first reply.
  5. The credential verifies up to a trusted root.
  6. The policy allows it.
  7. A handler exists.

Any failure gives DENY with the reasons. Missing information never leads to ALLOW.

Policy

{
  "version": "1",
  "trusted_roots": ["self"],
  "max_chain_depth": 4,
  "max_skew_seconds": 120,
  "rules": [
    {"id": "run", "effect": "allow", "routes": ["/task/*"], "roles": ["operator", "admin"]},
    {"id": "big", "effect": "deny", "routes": ["/task/*"], "conditions": [{"path": "payload.cost", "op": "gt", "value": 100}]}
  ]
}
Field of a rule Meaning
routes Patterns. * matches any characters
roles, schemas Restrict to the presented credential
conditions All must hold

Operators are eq, ne, lt, le, gt, ge, in, contains and exists. Paths refer to sender, route, payload, dt, identity.sn, identity.event, identity.delegator, credential.said, credential.issuer, credential.schema, credential.role, credential.attributes and chain_depth.

  • A matching deny rule overrides every allow rule.
  • A deny condition whose value is missing, or not comparable, counts as fulfilled. The rule fails closed.
  • Without a matching allow rule, the message is denied.