Federated APIOps with Kong · Part 2. Part 1 is the design. This part builds it. The code is in kong-federated-apiops.

Three GitHub Actions workflows run the design: a platform workflow (Terraform), a reusable team pipeline (decK, lint, oasdiff) and a drift workflow. You’ll run them against two Kong Gateway Enterprise environments in Docker, then try the changes a team must not be able to make.

At a glance

How it works

The team pipeline is the part teams touch; the platform and drift workflows appear in steps 2 and 5.

Step 1: Start and bootstrap

Versions used: Kong Gateway Enterprise 3.16.0.3 · decK 1.70.1 · Terraform 1.17.2, kong/kong-gateway provider 1.4.1 · oasdiff 1.38.0 · act 0.2.98

Put the license in ~/.kong-license-data/license.json (or set KONG_LICENSE_FILE), then:

git clone https://github.com/bhatikuldeep/kong-federated-apiops.git
cd kong-federated-apiops
mise install
make up

make up takes about two minutes. It starts dev and prod with enforce_rbac = on, runs the one-time bootstrap workflow for each (one Admin API call per step), switches Kong to both, then runs the platform and team workflows locally with act:

✅  Success - Main The super admin sees every entity
✅  Success - Main User ci-platform
✅  Success - Main   has the built-in role super-admin

The platform pipeline runs as ci-platform with Kong’s built-in super-admin role, “Full access to all endpoints, across all Workspaces, including the ability to assign and modify RBAC permissions”. Under entity-level RBAC it also needs an entity permission; entity_id "* matches any entity ID".

The first time, I ran act with --bind to keep Terraform state between runs. A checkout step wiped my working copy. The lab now refuses --bind and keeps state in Postgres.

Step 2: Lock the mandatory plugins (Terraform)

The platform workflow creates each team’s workspace, two roles, pipeline RBAC user and mandatory plugins. The pipeline gets a custom apiops-deployer role; people get workspace-read-only, named after Kong’s workspace role with “Read access to all endpoints in the Workspace”. Two entity permissions give the team its workspace and lock the mandatory plugins:

# platform/foundation/rbac.tf (excerpt)
resource "kong-gateway_rbac_role_entity" "deployer_all" {
  entity_id   = "*"          # every entity
  entity_type = "wildcard"
  actions     = ["read", "create", "update", "delete"]
}

resource "kong-gateway_rbac_role_entity" "deployer_protect" {
  for_each    = local.mandatory_plugin_ids
  entity_id   = each.value.id   # one mandatory plugin
  entity_type = "plugins"
  actions     = ["update", "delete"]
  negative    = true            # denied, despite the wildcard
}
Kong Manager showing the first permissions of the apiops-deployer role in the payments workspace
The first rows of the team's deployer role: every endpoint in its workspace, no changes to Kong Manager admins or groups, and no access at all to event hooks or the keyring. The list continues with the license, RBAC, vaults and workspaces.

Step 3: Ship a team’s API from OpenAPI

A team folder holds openapi.yaml, plugins.yaml, consumers.yaml and, optionally, rules/ and environments/. The build action runs five decK commands in it, with TAG=team-<team>:

cd teams/payments && TAG=team-payments
deck file openapi2kong -s openapi.yaml \
  --select-tag "$TAG" --uuid-base "$TAG" -o 1-oas.yaml
deck file add-plugins -s 1-oas.yaml -o 2-plugins.yaml plugins.yaml
deck file merge -o 3-merged.yaml 2-plugins.yaml consumers.yaml
deck file add-tags -s 3-merged.yaml -o 4-tagged.yaml "$TAG"
deck file patch -s 4-tagged.yaml -o kong.yaml --selector '$' \
  --value "_info:{\"select_tags\":[\"$TAG\"]}" \
  --value '_workspace:"payments"'

Each ruleset then runs as its own deck file lint step. On pull requests, oasdiff compares the spec with the base branch. Try it on the repository’s example of a removed operation:

oasdiff breaking teams/payments/openapi.yaml \
  tests/fixtures/breaking/openapi.yaml --fail-on MISSING-VERSION-BUMP
1 changes: 1 error, 0 warning, 0 info
error	[api-path-removed-without-deprecation] at teams/payments/openapi.yaml
	in API GET /payments/{paymentId}
		API path removed without deprecation

versioning policy: violated. info.version moved from 1.2.0 to 1.3.0 without a major version increase.

Job 2 then pings the environment, applies environments/<env>.yaml if there is one, dumps the team’s config as a rollback point and syncs with the team’s token. Pass --workspace on every call. Without it, decK used the default workspace and stopped with HTTP status 403.

deck gateway sync --workspace payments kong.yaml
Summary:
  Created: 8
  Updated: 0
  Deleted: 0
Kong Manager routes of the payments workspace, one per operationId, tagged team-payments
Routes generated from the payments spec, one per operationId.

Step 4: Try what a team must not do

make test

make test runs a rogue team’s files through the rulesets, then tries each forbidden change with the payments pipeline token. The rogue spec, then the decK file built from it:

[error][3:7] info.contact is required (who owns this API?)
[error][17:7] operationId is required
[error][2:1] a top-level security requirement is required

[error][10:9] plugin is not on the platform's allowed list
[error][22:11] plugin is not on the platform's allowed list
[error][1:1] top-level (global) plugins are reserved for the platform team
[error][26:5] the ordering field is reserved for the platform team
Who tries whatResult
A payments developer with workspace-read-only: read payments200; any change or orders 403
Payments token: read or write in orders403
Payments token: create an RBAC user, role or workspace403
Payments token: switch off or delete a mandatory plugin403
Payments token: add its own rate-limiting to its service201, and it replaces the platform’s limit: drift catches it (step 5)
Payments token: update its own plugin200
Platform token: update the mandatory plugin200

Step 5: Drift and repair

Changed outside the pipelinesCaught byRepaired by
A service edited by handdeck gateway diff --non-zero-exit-codethe team pipeline
A plugin added by hand, even one tagged platformlint of a workspace dump with the team’s rulesdeleting it
A mandatory plugin switched off or deletedterraform plan -detailed-exitcodethe platform workflow

To see one, edit the payments service with its token, then run the drift workflow:

curl -s -X PATCH http://127.0.0.1:18001/payments/services/team-payments \
  -H "Kong-Admin-Token: $(lab/lab.sh token dev payments)" \
  -H 'Content-Type: application/json' -d '{"retries":9}'
lab/lab.sh act drift.yaml

Only the payments job in dev fails (act’s output):

updating service team-payments  {
-  "retries": 9,
+  "retries": 5,
❌  Failure - Main Drift: managed config differs from the repository

Use it for your own gateways

  1. Add a team: an entry in teams.yaml, platform/governance/teams/<team>.yaml, and its secrets in the GitHub environments, from terraform output ci_tokens (the checklist). For a read-only Kong Manager, have your identity provider send <team>:workspace-read-only, Kong’s WORKSPACE_NAME:ROLE_NAME claim format. Part 3 shows it with Keycloak.
  2. Bootstrap each environment once with enforce_rbac = on, then switch to both.
  3. Keep Terraform state in a locked remote backend; it holds every team’s token.
  4. Keep Kong tokens in GitHub environments, not repository secrets: “Secrets stored in an environment are only available to workflow jobs that reference the environment”. Pull requests plan against dev only; prod takes main only, with reviewers (all settings).
  5. Use runners that can reach the Admin API, and put TLS on it.
  6. Rotate a team token with terraform apply -replace='random_password.ci_token["<team>"]', then redeploy once.
  7. Roll back a deploy with deck gateway sync --workspace <team> --select-tag team-<team> --skip-consumers <backup>.yaml.

With one repository per team (how to split one out), the team owns its workflow file and could stop calling the central rulesets. Keep its prod token behind a prod environment with the platform team as reviewers. This setup doesn’t cover hybrid mode, Kong upgrades or Konnect.

Next: Part 3 lets people sign in to Kong Manager with Keycloak, their group deciding which workspace they can read.

Troubleshooting

You seeFix
Empty lists or 403 for the super admin after switching to bothBootstrap with enforce_rbac = on first.
403 from deck gatewayPass --workspace.
403 on PATCH of a plugin or consumer by IDUse PUT, as decK does.
426 Please use HTTPS protocolRoutes default to HTTPS since 3.14, so serve TLS.
deck gateway validate: config.namespace: required field missingSet a namespace on rate-limiting-advanced.

Clean up

make clean

References