Entitlement statements¶
What a community holds of a plug-in (its allowance, the packs it bought) is decided by billing, not by Initiative. So that a compromised Initiative cannot grant itself an entitlement, billing signs each statement with a key of its own, Initiative stores the statement and hands it on verbatim, and your plug-in checks billing's signature. Initiative can withhold a statement; it cannot mint or change one.
A statement is a compact JWS. Its header is
{"alg": "EdDSA", "typ": "initiative-entitlement+jwt", "kid": …}, and its
claims are {"iss": "initiative-billing", "listing_uid", "community_ref",
"sub", "version", "values", "iat"}. community_ref is billing's own
reference for the community; sub is your plug-in's, the same
community_ref your plug-in's own tokens carry there. It has no expiry: it
holds until a higher version replaces it. The entitlement hook's body, and what
client.entitlement() reads, are both {"statement": "<jws>"}.
Billing's public key reaches your plug-in from the deployment, never from
Initiative: it is the runtime fact entitlement_issuer_key, an SPKI PEM in
INITIATIVE_ENTITLEMENT_ISSUER_KEY_PEM. initiative-plugin build adds that
fact to the runtime of every plug-in with an entitlement hook, so you need
not declare it, and refuses it under any other variable name.
The SDK checks every statement, on the hook and on client.entitlement(), in
this order, and refuses it at the first failure:
- the key is configured and is Ed25519; without one, every statement is refused, and the plug-in logs why once;
- the header's
algis exactlyEdDSAand itstypexactlyinitiative-entitlement+jwt: the header never chooses the algorithm, soalg: noneor an HMAC trick goes nowhere; - the Ed25519 signature over the JWS signing input;
issisinitiative-billingandlisting_uidis your plug-in's ownuid;subis the community the statement is checked for: on the hook, the lifecycle token'scommunity_ref; onclient.entitlement(), the client's installation;versionis a whole number of one or more, andvaluesis an object.
Only then is your hook called, with version and values taken from the
verified claims and nothing else in the body. A refused statement is answered
422 {"error": "statement-refused", "detail": "<reason>"} and never reaches
your hook; client.entitlement() throws EntitlementStatementError, whose
reason is one of no-key, bad-key, malformed, alg, typ,
signature, iss, listing, community or claims.
Which community. Billing learns your plug-in's reference for a community from Initiative the first time it signs a statement for it, and keeps it: it changes only when the community erases your plug-in's data, and a reference kept for one community is never signed for another. So a statement signed for one community is refused in another's. Billing learns which community is which from Initiative, so this binds a statement to the community billing first signed it for; it does not stop an Initiative that misnamed a community from the start.
Alerts. The SDK counts, for the process's life:
- every statement by outcome,
applied(verified and handed on) orrefused-<reason>; - every grant of an unlimited allowance (
monthly_allowance: null) to a community whose last statement the process saw did not grant one. The memory is the process's own, so after a restart the first such statement counts again.
entitlementMetrics() answers them as an object, and entitlementMetricsText()
in the Prometheus text format, to append to what your metrics endpoint serves:
initiative_plugin_entitlement_statements_total{outcome="…"} and
initiative_plugin_entitlement_unlimited_grants_total. Alert on any
refused-* and on any rise in unlimited grants. Neither ever refuses a
correctly signed statement.
If you self-host. A deployment that runs billing mints its statement
keypair and fills INITIATIVE_ENTITLEMENT_ISSUER_KEY_PEM for each plug-in that
declares the fact. A deployment with no billing leaves it unset: it sends no
statements, and any that did arrive would be refused.