5.2. Define a federation-specific policy operator
Feature guides / 5. Federation policy · Example context
eduGAIN has a framework-specific metadata rule that cannot be expressed by a standard operator. Its participating applications agree on the rule and register the same implementation.
How to use it
A PolicyOperatorDefinition supplies application, merge, combination, and ordering behavior. Install it in the consuming host's options.customPolicyOperators, or in a protocol role's options. Discovery and protocol operations then use it during chain validation. Core owns the extension interface because all packages share the same policy engine. The low-level policy helpers use their own customOperators option. Callbacks are synchronous and return controlled success/failure results. Additional operators; Critical policy claims.
import { Leaf } from "@oidfed/leaf";
import type { CryptoContext, PolicyOperatorDefinition, TrustAnchorSet } from "@oidfed/core";
export const minimumLength: PolicyOperatorDefinition = {
name: "urn:academic:min_length", order: 6.5, action: "check",
apply(value, limit) {
if (typeof limit !== "number" || !Number.isSafeInteger(limit) || limit < 0) {
return { ok: false, error: "Minimum length must be a nonnegative integer" };
}
// Let essential decide whether a missing value is required.
if (value === undefined) return { ok: true, value };
return typeof value === "string" && [...value].length >= limit
? { ok: true, value }
: { ok: false, error: "Value is shorter than the permitted minimum" };
},
merge(existing, incoming) {
if (![existing, incoming].every(value =>
typeof value === "number" && Number.isSafeInteger(value) && value >= 0)) {
return { ok: false, error: "Minimum lengths must be nonnegative integers" };
}
return { ok: true, value: Math.max(existing as number, incoming as number) };
},
canCombineWith() { return true; },
};
export async function ligoWiki(keys: CryptoContext, trustAnchors: TrustAnchorSet) {
return await Leaf.create({
entityId: "https://wiki.ligo.example", authorityHints: ["https://incommon.example"],
crypto: keys, trustAnchors, metadata: { federation_entity: {} },
options: { customPolicyOperators: [minimumLength] },
});
}
Call ligoWiki.discoverEntity(...) or the attached role's protocol operation to enforce the configured operator. eduGAIN publishes the operator under a subordinate's metadataPolicy; configuring a consumer does not publish policy by itself. Each participating consumer must understand a critical custom operator before using that statement.
What your application owns
Define semantics before writing the callback: what happens to absent values, how two policies combine, and which other operators may coexist. Names cannot replace standard operators; ordering must respect value and essential. Invalid definitions, thrown callbacks, async returns, or malformed callback results fail in a controlled way. Unknown noncritical operators are ignored; metadata_policy_crit makes understanding the named extension mandatory. Do not list standard operators there.
Deploy an operator as a federation agreement
An additional policy operator needs a shared definition across the federation: accepted input, merge behavior, application order, and how failures are reported. Passing a callback installs that behavior in one process; it does not distribute the implementation to other participants.
Keep callbacks synchronous and deterministic. Validate their configuration before publishing policy that depends on them. If the operator is critical, recipients that do not understand it must reject the affected policy, so deploy consumer support before requiring it in issued statements. Unknown non-critical operators being ignored is a compatibility rule, not evidence that their intended restriction was enforced.