Skip to content
Wallet and Entity Collection draft updates
Documentation menu

5.1. Apply federation metadata policy

Feature guides / 5. Federation policy · Example context

eduGAIN constrains the scope value in LIGO Wiki's RP metadata. The operator publishes policy in the statement about that subordinate, and consumers derive the effective value while validating its chain. The OP's authorization engine still decides which scopes a particular request may receive.

How to use it

Publish policy through registerSubordinate() or updateSubordinate() on the Superior. The receiving host or protocol role resolves and applies it during trust processing. In the example, InCommon narrows LIGO Wiki's requested scopes, and Umeå University OP processes the signed registration request through its initialized OP role. The publisher and consumer normally run in separate applications. Enforcement.

import type { TrustAnchor, Intermediate } from "@oidfed/authority";
import type { OidcProviderRole } from "@oidfed/oidc";
import { entityId } from "@oidfed/core";

export async function constrainResearchScopes(
  inCommon: TrustAnchor | Intermediate, umeaOp: OidcProviderRole, requestJwt: string,
) {
  await inCommon.updateSubordinate(entityId("https://wiki.ligo.example"), {
    metadataPolicy: { openid_relying_party: {
      scope: { subset_of: ["openid", "profile"] },
    } },
  });
  // Later, in UmeaOp's OP process, registration validates and applies the policy.
  return umeaOp.processAutomaticRegistration(requestJwt);
}

What your application owns

Set metadataPolicy per subordinate; reuse the same policy object as input where common rules are desired. Contradictory operator combinations are errors. An empty one_of intersection fails, while subset_of can produce an empty list.

subset_of operates on arrays. For openid_relying_party.scope and oauth_client.scope, applyMetadataPolicy() implements the special scope handling in Federation §6.1.3.1.8: split the space-delimited value before applying operators, then return the resolved value as a string. Other string parameters do not receive that conversion.

Applying an isolated policy is not proof that its issuer was authorized. The application still decides whether the effective capabilities suffice for its protocol operation.

A published metadata_policy needs at least one member at each of its three levels. Omit the claim when there is no policy. Unknown non-critical operators remain ignored, even when that leaves the resolved policy empty. Duplicate members in the original signed JSON invalidate the statement.

Preview policy before enrolling participants

eduGAIN should test a proposed policy against representative Umeå and LIGO Wiki metadata before publishing it. The resolved value can differ from the participant's self-declared value, and incompatible operators can make the entire path unusable.

Keep a positive example that produces the intended metadata and a negative example that must fail. If a production consumer rejects the policy, inspect the complete Superior path rather than only the nearest statement. Editing the subordinate's local metadata cannot override a more superior policy rule. Roll out policy changes with evidence lifetimes in mind so operators understand when consumers will observe them.

Resolve and apply a policy

Resolve policies from the chain, then apply the combined policy to metadata. The standard operators in Federation §6.1.3 are value, default, one_of, subset_of, superset_of, add, and essential.

Overrides and policies apply only to entity types present in the input metadata, following §3.1.1 and §6.1.1. When calling applyMetadataPolicy() directly, include an object for each intended type; {} allows its parameters to be supplied by overrides or policies. Types removed by allowed_entity_types remain absent. Policy syntax, critical operators, and merge conflicts are still checked during resolution under §6.1.4.1.

Core validates known federation_entity fields in Entity Configurations and Subordinate Statements under §3.2 and §5.1.1. applyMetadataPolicy() checks these fields after all operators finish; validateTrustChain() also checks the final metadata when no policy applies. Invalid results return validation errors, as required by §6.1.4.2. Custom entity types and extension parameters are preserved. Protocol packages and applications validate their protocol-specific fields.

Standalone resolveMetadataPolicy() and applyMetadataPolicy() are for policy editors and custom engines that need to inspect individual stages. They are not additional steps after role registration or host discovery. See the policy API for their contracts.

Metadata policy value and default operators support JSON objects under Federation §6.1.3.1.8. Merging compares complete values structurally: object member order is immaterial, array order is significant, and conflicting values fail. Nested objects are not recursively combined. Resolved values are detached from the supplied policy.

validateMetadataPolicy(policy, { customOperators }) checks a policy declaration without applying it to metadata. Each of its three declaration levels must contain at least one member (Federation §6.1.2). Omit metadata_policy when there is no declaration. A resolved policy can become empty after unknown non-critical operators are ignored. It checks supported operator values and combinations, while preserving unknown extension operators. The standalone policy and Subordinate Statement publication validators traverse value and default data iteratively, so deeply nested JSON does not overflow the call stack. Cycles and values that cannot be represented as JSON are rejected. Statement builders also reject invalid standard declarations before signing. Custom operator callbacks are synchronous: thrown exceptions, malformed results, and promises become policy errors. Operator order must be finite and respect the standard value and essential boundaries.

validateSubordinateStatementPublicationClaims(claims, { customOperators }) checks supplied publication claims, including critical-claim declarations and constraints, without requiring issuer, key, or time claims. It does not authenticate a statement or resolve a Trust Chain.

Validate policy before publication

registerSubordinate() and updateSubordinate() validate supplied publication claims before writing the resulting record. Invalid critical claims, malformed constraints, and incompatible standard policy operators produce configuration errors. Updates fail before persistence or lifecycle-event creation, including with custom storage adapters. Publication checks remain in place for records loaded from existing stores and for Extended Listing.

TrustAnchor and Intermediate configurations also accept additionalClaims and crit for their own EC. Construction validates and deeply copies them. Subordinate extensions belong to each registration record instead:

import type { TrustAnchor } from "@oidfed/authority";
import type { EntityId, JWKSet } from "@oidfed/core";

export async function publishExtension(authority: TrustAnchor, subordinateId: EntityId, subordinateKeys: JWKSet) {
  await authority.registerSubordinate({
    entityId: subordinateId, jwks: subordinateKeys,
    additionalClaims: { "https://edugain.example/claims/access-profile": "research-v1" },
    crit: ["https://edugain.example/claims/access-profile"],
  });
  await authority.updateSubordinate(subordinateId, {
    additionalClaims: { "https://edugain.example/claims/access-profile": "research-v2" },
  });
}

An update replaces the supplied additionalClaims map; it does not merge individual extension values. The resulting record must still contain every claim named in its crit. If you remove an extension, update crit in the same call (omit it from new records, or set it to undefined in an update when none remain). Empty crit arrays are rejected. Custom storage adapters must persist both fields unchanged. Signed Fetch responses and the subordinate_statement returned by Extended Listing carry the extensions.

These publication checks protect the statement's shape. They do not decide your extension's meaning. Recipients still need to implement it before declaring it understood, as Federation §13.4 requires. See core's extension API.

Policies are validated as declarations; missing subordinate metadata may still be supplied by a Superior. The host may reuse a policy across registrations or provide a different metadataPolicy per subordinate. Custom constraints remain in the published statement:

import { type TrustAnchor } from "@oidfed/authority";
import { type EntityId, type JWKSet } from "@oidfed/core";

export async function publishSubordinateExtension(authority: TrustAnchor, subordinateId: EntityId, subordinateKeys: JWKSet) {
  await authority.registerSubordinate({
    entityId: subordinateId,
    jwks: subordinateKeys,
    constraints: {
      allowed_trust_anchors: ["https://anchor.example"],
    },
  });
}

Set options.customConstraintChecks on an authority to enforce registered constraints when it validates received chains, including Resolve requests. Publication preserves extension constraints without running chain-dependent checks. See custom constraints for the receiving application’s checker.

Next: 5.2. Define a federation-specific policy operator

View source on GitHub