- Ruleset management as code. The
TykRulesetcustom resource lets a ruleset definition live in Git next to the APIs it applies to. - Compliance enforcement and reporting for the APIs Operator manages. An admission webhook can reject a non-compliant
TykOasApiDefinitionoutright, so Kubernetes never saves it.
TykOasApiDefinition only.
Before you start:
- This requires a Tyk license with API Governance enabled. Without the license’s
governancescope, every governance endpoint returns403 Forbidden. Operator treats this as “not licensed”: it skips governance handling and does not fail (see Licensing and skip conditions). Contact your Tyk account team to have it enabled. - The
OperatorContextyourTykRulesetandTykOasApiDefinitionresources reference needs a Dashboard token withwriteoradminon the Governance permission group to manage rulesets. It also needsreadon Governance to run compliance checks.
A note on “blocking”: elsewhere in Tyk Governance, a ruleset’s
action is either none or warn. That’s true whether you save an API in Dashboard or run a CI/CD sandbox check. Nothing is ever stopped outright, only flagged. Tyk Operator is the exception.You can set a TykRuleset to action: block. The Kubernetes admission layer enforces this and can stop an API manifest before it ever reaches Kubernetes or Dashboard. See Action semantics for exactly how that works, and what it does and doesn’t affect.Manage Rulesets as Code
Step 1: Write a TykRuleset Resource
The Spectral rule body can live inline in the resource, or in a separate ConfigMap or Secret. Inline is the simplest option for small rulesets and keeps a ruleset change to a one-file diff:
contextRefis optional in both source modes. It falls back to the defaultOperatorContextfor the namespace when omitted. It’s included here for clarity, not because inlinerawrulesets need it any more thanobjRefones do.actionalso defaults tononeif you leave it out entirely. Tyk then evaluates the ruleset for visibility only. It never surfaces a warning or blocks anything until you explicitly setactiontowarnorblock.
TykRuleset resources. Do the same if the content shouldn’t sit in a plain ConfigMap, for example internal endpoint names or naming patterns:
ruleset.raw or ruleset.objRef must be set. The cluster rejects a resource that sets both, or neither, before it’s ever created, so Operator never has to guess which one you meant.
Step 2: Apply It
ConfigMap or Secret if you used objRef. If you edit either one, Operator triggers an update. If you delete the TykRuleset, Operator deletes the ruleset from Dashboard.
Step 3: Verify
RulesetID, and it only appears after the first successful reconcile. kubectl describe tykruleset payments-ruleset shows the full status, such as ObjectID, Owner, and OrgID, all read back from Dashboard, never set from the spec.
Step 4: Link It to the APIs It Governs
Rulesets apply to APIs through categories, the same mechanism used everywhere else in Tyk Governance. Add the matching category to theTykOasApiDefinition you want this ruleset to check. There’s no new field for this; spec.categories is the same field Operator already supports:
TykOasApiDefinition before the TykRuleset that references that category. Dashboard rejects a ruleset’s categories if no API carries them yet.
Enforce and Observe Compliance at Apply Time
Step 1: Enable the Webhook (Optional)
The admission webhook is an optional part of Operator’s existing webhook infrastructure, enabled by default. Teams that don’t need enforcement see no behavior change. Enable it in your Helm values:TykOasApiDefinition (see Step 4); you just don’t get a hard stop at kubectl apply time.
Step 2: Apply an API With Matching Categories
Take thepayments-api resource from the previous section. kubectl apply now runs it against every active TykRuleset in the same namespace whose categories intersect the API’s spec.categories (resourceType: oas-api only).
Step 3: See the Outcome
With the webhook enabled, one of three things happens: Denied, when a matchingblock ruleset has error-level findings:
block ruleset:
(results truncated). Violation details are only inlined for error-level findings. For a warnings-only case, you only get the summary line above. See status.governancePreflight or the Dashboard for the actual violations.
Admitted silently, when there are no categories, no matching active oas-api rulesets in the namespace, or nothing to flag:
Step 4: Check Compliance Status
Whether or not you enable the webhook, the reconciler records the result on every reconcile that resolves an OAS document:Detailed Reference
TykRuleset Spec
For all fields, see TykRuleset in the Tyk Operator CRD reference.
Action Semantics
status.governancePreflight Fields
Populated on TykOasApiDefinition by the reconciler on every reconcile that resolves an OAS document.
How Evaluation Gets Triggered
Governance is opt-in via categories. An API is only evaluated when itsspec.categories intersect the categories of active TykRuleset resources (resourceType: oas-api) in the same namespace.
- No categories on the
TykOasApiDefinition→ skipped, no Dashboard call. - No matching active
TykRulesetresources in the namespace → skipped, no Dashboard call. Operator checks this against the Kubernetes API directly, so it works even when governance isn’t licensed (see below). - Otherwise, Operator resolves the matching ruleset set locally and evaluates against it.
Operator always resolves rulesets to explicit ruleset IDs itself; it never asks Dashboard to resolve by category the way the CI/CD sandbox check can. That’s because Dashboard only ever sees
blockrulesets aswarn(see Action semantics). So the set ofTykRulesetresources in the namespace has to be the source of truth for what actually enforces.
Reconciler Behavior (Visibility)
The reconciler never blocks or withholds the Dashboard sync based on a governance result; that’s the webhook’s job. It only ever updates status and emits a Kubernetes Event (GovernancePreflightPassed / Warned / Blocked / Error):
- A
blockedresult does not fail the reconcile. The API still syncs to Dashboard, withstatus.governancePreflight.status: blockedrecorded for visibility. - A transport error or empty response from the evaluation call sets
status: errorand does fail the reconcile, which requeues. A cachederrorresult is always re-evaluated on the next reconcile rather than trusted. - Evaluation is hash-gated. Operator skips the call if nothing has changed since the last evaluation. That means the OAS document, and the matched ruleset set: which resources, their
action, their rule content. In steady state, a reconcile that resolves an already-evaluated API makes zero governance calls. - A
TykRulesetcreate, update, or delete requeues everyTykOasApiDefinitionin the namespace whose categories intersect it, for a status-only re-evaluation. The API is never re-pushed to Dashboard just because a ruleset changed. This also means the reconciler only reacts toTykRulesetchanges made through Kubernetes. A ruleset edited directly in the Dashboard UI doesn’t trigger a re-evaluation of already-synced APIs on its own.
Admission Outcomes
Licensing and Skip Conditions
Governance is a licensed feature. If your org’s license doesn’t include thegovernance scope, every governance endpoint, ruleset CRUD and evaluation alike, returns 403 Forbidden. Operator treats this as a permanent, expected condition rather than an infrastructure failure:
- A
TykRulesetwhose Create/Update call gets403stays in aFailedtransaction state with noRulesetID. In an unlicensed org, namespaces end up with zero workingTykRulesetresources. So step 2 above (no matching active rulesets) skips evaluation automatically, and Operator never needs a separate license check. - Sometimes a
TykRulesetresource is present and licensed, but the evaluation call itself returns403. This can happen after a license change. When that happens, both the webhook and the reconciler admit or continue anyway. They log a warning and recordstatus: skipped, notblockedorerror.
Failure Policy
The webhook needs its evaluation call to reach Tyk Dashboard.webhooks.governanceFailurePolicy controls what happens when it can’t. This one setting covers two distinct failure points: the kube-apiserver unable to reach the webhook pod, and the webhook pod unable to reach Dashboard.
RBAC
The Operator manager role needsevents: create;patch in addition to its existing tykrulesets read access. Without it, the API server rejects the Kubernetes event recorder used for GovernancePreflight* events. This is cluster-side RBAC for the Operator’s own service account, separate from the Dashboard-side OperatorContext token permissions listed under Before you start.