OKHAM.org Documentación EnglishCastellano

OPC · Open Policy Contract

An Open Policy Contract (OPC) expresses a rule that governs a decision. A policy author identifies where the rule applies, the facts needed to evaluate it, and the outcomes the host can act on. Several workflows can refer to the same policy when they need the same decision. Giving the policy its own identifier and version lets a team review a change to the rule separately from changes to those workflows.

Scope and enforcement

The contract brings three things together. Its scope and optional target identify the work it governs. Its condition names an expression and its inputs. Its decision can describe permission to proceed, a refusal, a warning, or constraints on the operation.

The host supplies the actual context, selects an evaluator that understands the expression, and enforces the applicable outcome before proceeding. A structurally valid policy can still refer to a context value the host cannot supply. The workflow that requests the decision and the function that performs the work have their own contracts. See the business contract and the function registry.

Field reference

Read each table within its named object. A required field must be present whenever that object is supplied. Brackets ([]) denote one array entry. Each object in the tables accepts additional properties.

Document

Field JSON type Required Meaning and constraints
policy string Yes OPC version (semantic version). Use three dot-separated numbers.
id string Yes Policy identifier (unique, namespaced). Use at least four dot-separated segments. Each starts with a lowercase letter and continues with lowercase letters or digits.
name string Yes Human-readable policy name. Length: 2–100 characters.
version string Yes Policy version. Use three dot-separated numbers.
status string Yes Lifecycle status. Allowed values are draft, active, deprecated, removed.
scope string Yes Policy scope. Allowed values are global, service, capability.
condition object Yes Test the host evaluates before applying a decision.
decision object Yes Outcomes the host can apply. The schema allows this object to be empty.
metadata object No Additional information about this policy.
target object No Identifies the capability, event, function, interaction or operations to which the policy applies.

condition

Field JSON type Required Meaning and constraints
expression string Yes Expression the host evaluates against its context.
inputs array of strings Yes Names of the context values used by the expression.
language string No Expression language used by the evaluator, such as CEL.

decision

Field JSON type Required Meaning and constraints
allow object No Outcome for a permitted operation.
constrain object No Restrictions to apply to the requested operation.
deny object No Outcome for a refused operation.
warn object No Warning to report to the caller.

decision.allow, decision.deny

Field JSON type Required Meaning and constraints
code string No Machine-readable result code.
log_level string No Level at which the host should record this outcome.
message string No Explanation the host can give the caller.

decision.constrain

Field JSON type Required Meaning and constraints
constraints array of strings Yes Restrictions for the host to enforce.
message string No Explanation the host can give the caller.

decision.warn

Field JSON type Required Meaning and constraints
message string Yes Explanation the host can give the caller.
log_level string No Level at which the host should record this outcome.

target

Field JSON type Required Meaning and constraints
capability string No Identifier of a capability governed by this policy.
event string No Identifier of an event governed by this policy.
function string No Identifier of a function governed by this policy.
interaction string No Identifier of an interaction governed by this policy.
operations array of strings No Operations governed by this policy.

Example: authorising a write in OKHAM Memory

The write policy names CEL as its expression language and declares context.memoryWriteAllowed as its input. When the rule allows a write, decision.allow.message explains the outcome. The denial branch supplies a different message.

Both allow and deny accept an optional code, message and log_level. A warn outcome requires a message and can set log_level. A constrain outcome requires constraints, a list of strings, and can supply a message.

Edition 0.2.0 · JSON Schema · Full example

Ver especificación en GitHub