This is Part 5 of the six-part build in the Sprint 6 project overview. Parts 1 to 4 left a working ERP, its data and events, a served model and a copilot, all reachable only inside the cluster. Now the front and the road to production: CloudFront and WAF in front of an Istio gateway, Kuadrant for authentication and per-tenant plans, Keycloak for tokens, OpenFGA for record-level permissions, Unleash with OpenFeature for flags, and Backstage, Tekton, in-toto, Kyverno and Argo CD to ship only evidence-backed images.
Where this part fits. This part builds the edge, access and delivery (marked Part 5 on the overall diagram). Open the zoomable Sprint 6 architecture or read the Overview.
What this is and is not. This is engineering guidance, not legal or financial advice. It is a reference blueprint: the intended flow and the wiring between the tools. Versions, chart keys, resource fields and policy schemas change between releases, so each section gives a check to confirm them on your version. If you hit a bug or a mismatch, use the “Suggest a correction” link on this page.
The open question, settled: Kuadrant runs on Istio, not kgateway
The Overview left one item open: whether Kuadrant can sit on kgateway. What I read on 5 December 2026: Kuadrant’s architecture material names Istio or Envoy Gateway as the Gateway API providers it integrates with, and a Red Hat write-up on Kuadrant says Istio is the supported provider. kgateway is not named in either. kgateway has its own policy objects for JWT and global rate limits, so it could do the job without Kuadrant, but then Kuadrant would have nothing to attach to.
Decision: Kuadrant on an Istio gateway. Istio is already in the mesh from Part 1, so the public edge, the mesh and the policy engine share one Envoy-based data plane, and the combination is a documented one. kgateway leaves the public path of this project (it stays covered in its own earlier brief). The Overview diagram, tables and animation were redrawn in the same commit to match. agentgateway from Part 4 is unchanged: it is still a separate gateway for model and tool traffic. I did not run this combination; the checks below are how you confirm it on your cluster.
What you build, and in what order
One image, the layers of this part. Open the zoomable diagram, or download it as SVG or PNG.
Where each piece lives: Keycloak, OpenFGA and Unleash keep their data in one CloudNativePG cluster (platform-pg, three databases), a CNCF-first choice that keeps RDS for ERP business data. Kuadrant’s rate counters live in ElastiCache from Part 1, so every gateway replica sees the same count. Images and their signed provenance live in ECR.
- The gateway and its certificate
- The edge: CloudFront, WAF, private origin
- Keycloak: tenant and plan claims
- Kuadrant: authentication and plan limits
- OpenFGA: a store per tenant
- Flags: Unleash through OpenFeature
- The build: Backstage, Tekton, Chains
- The gate: Kyverno and Argo CD
- Troubleshooting, cost, cleanup, checklist
Prerequisites
From earlier parts: the cluster, Karpenter, Istio with strict mutual TLS, Argo CD, Capsule tenants (acme, globex), ElastiCache, KMS and the Route 53 zone. New in this part, install once through Argo CD or Helm: the Gateway API standard CRDs (use the version Kuadrant’s install guide names), cert-manager, and the AWS Load Balancer Controller with a Pod Identity role. Create the shared database cluster:
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata: { name: platform-pg, namespace: iam }
spec:
instances: 2
storage: { size: 20Gi }
bootstrap: { initdb: { database: keycloak, owner: keycloak } }
Create the openfga and unleash databases and roles beside it (a one-off SQL statement, or the CloudNativePG Database resource). Check: kubectl -n iam get cluster platform-pg shows two ready instances.
1. The gateway and its certificate
An Istio Gateway (the Gateway API kind) creates the proxy and a Service. The annotations make that Service an internal network load balancer with a fixed name, so OpenTofu can find it in the next section:
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: erp-gateway
namespace: gateway
labels: { kuadrant.io/gateway: "true" }
annotations:
service.beta.kubernetes.io/aws-load-balancer-type: external
service.beta.kubernetes.io/aws-load-balancer-nlb-target-type: ip
service.beta.kubernetes.io/aws-load-balancer-scheme: internal
service.beta.kubernetes.io/aws-load-balancer-name: erp-gw
spec:
gatewayClassName: istio
listeners:
- name: https
hostname: origin.erp.example.com
port: 443
protocol: HTTPS
tls: { mode: Terminate, certificateRefs: [{ name: origin-erp-tls }] }
allowedRoutes: { namespaces: { from: All } }
CloudFront checks the origin certificate against public authorities, so issue it with cert-manager and a public ACME issuer using the Route 53 DNS challenge:
apiVersion: cert-manager.io/v1
kind: Certificate
metadata: { name: origin-erp-tls, namespace: gateway }
spec:
secretName: origin-erp-tls
dnsNames: [origin.erp.example.com]
issuerRef: { name: letsencrypt-dns, kind: ClusterIssuer }
Then one route sends the API hostname to the ERP service:
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata: { name: erp-api, namespace: gateway }
spec:
parentRefs: [{ name: erp-gateway }]
hostnames: [api.erp.example.com]
rules:
- backendRefs: [{ name: erp-api, namespace: erp, port: 80 }]
A cross-namespace backend needs a ReferenceGrant in the erp namespace. Check: kubectl -n gateway get gateway erp-gateway shows Programmed, and the generated Service gets an internal NLB DNS name. Whether the controller passes these annotations to the Service it generates depends on your Istio version; if it does not, set them through the Gateway’s infrastructure settings. You can also issue the origin certificate from Kuadrant’s TLSPolicy instead of a plain Certificate (not tried here).
2. The edge: CloudFront, WAF, private origin
This is the piece Part 1 deferred. CloudFront’s VPC origin reaches a private load balancer, so the NLB never has a public address. Two limits from the AWS page I read: the NLB must have a security group attached, and an NLB with a TLS listener cannot be a VPC origin, which is why the gateway above terminates TLS itself behind a plain TCP listener. Recent Load Balancer Controller versions attach a security group to new NLBs; confirm on yours. The WAF web ACL for CloudFront must be created in us-east-1, as must the viewer certificate in ACM.
provider "aws" {
alias = "use1"
region = "us-east-1"
}
data "aws_lb" "gateway" { name = "erp-gw" } # created by the controller from the Gateway above
resource "aws_cloudfront_vpc_origin" "gw" {
vpc_origin_endpoint_config {
name = "erp-gateway"
arn = data.aws_lb.gateway.arn
http_port = 80
https_port = 443
origin_protocol_policy = "https-only"
origin_ssl_protocols {
quantity = 1
items = ["TLSv1.2"]
}
}
}
resource "aws_wafv2_web_acl" "edge" {
provider = aws.use1
name = "erp-edge"
scope = "CLOUDFRONT"
default_action {
allow {}
}
rule {
name = "common"
priority = 10
override_action {
none {}
}
statement {
managed_rule_group_statement {
name = "AWSManagedRulesCommonRuleSet"
vendor_name = "AWS"
}
}
visibility_config {
cloudwatch_metrics_enabled = true
metric_name = "common"
sampled_requests_enabled = true
}
}
rule {
name = "per-ip"
priority = 20
action {
block {}
}
statement {
rate_based_statement {
limit = 2000
aggregate_key_type = "IP"
}
}
visibility_config {
cloudwatch_metrics_enabled = true
metric_name = "per-ip"
sampled_requests_enabled = true
}
}
visibility_config {
cloudwatch_metrics_enabled = true
metric_name = "erp-edge"
sampled_requests_enabled = true
}
}
Then an aws_cloudfront_distribution with the alias api.erp.example.com, an ACM certificate from us-east-1, the VPC origin (domain name origin.erp.example.com, so the certificate name matches), web_acl_id set to the ACL above, caching disabled for the API path, and a Route 53 alias record to it. Creating the VPC origin also creates a service security group (CloudFront-VPCOrigins-Service-SG); allow it on the NLB’s security group, or CloudFront cannot connect. The WAF per-IP limit is a blunt edge guard; the per-tenant plan limit comes later in Kuadrant, where the tenant is known. Check: a request to https://api.erp.example.com/ reaches the gateway, and the NLB’s DNS name is not reachable from your laptop. Argument names and the managed rule set are what to confirm in the provider documentation for your version.
3. Keycloak: tenant and plan claims
Deploy Keycloak with its Operator, pointed at platform-pg, behind the same gateway on login.erp.example.com (a second HTTPRoute). One realm, erp, serves all tenants. Each user carries two attributes, and two protocol mappers put them in the access token:
| User attribute | Token claim | Example | Used by |
|---|---|---|---|
tenant_id |
tenant_id |
acme |
Kuadrant counters, the ERP API, the OpenFGA store lookup |
plan |
plan |
starter or business |
Kuadrant limit selection |
Create the mappers as “User Attribute” mappers on a client scope added to the erp-web and erp-api clients, with “Add to access token” on. Keep the plan on the tenant side of your own data and sync it to the users; never let a user edit these attributes. Check: get a token for a user of acme (call the token endpoint with a test client) and decode it: tenant_id and plan are present, and iss is https://login.erp.example.com/realms/erp. The Keycloak Operator resources and the mapper screens differ between Keycloak releases.
4. Kuadrant: authentication and plan limits
Install the operator, then create the one Kuadrant resource (it deploys Authorino for authentication and Limitador for counting):
helm repo add kuadrant https://kuadrant.io/helm-charts && helm repo update
helm upgrade --install kuadrant-operator kuadrant/kuadrant-operator -n kuadrant-system --create-namespace
kubectl apply -f - <<'YAML'
apiVersion: kuadrant.io/v1beta1
kind: Kuadrant
metadata: { name: kuadrant, namespace: kuadrant-system }
YAML
Point Limitador at ElastiCache for shared counters (its resource takes a Redis URL from a Secret; the exact field is in Kuadrant’s docs for your version). Then one policy checks the token, and one applies the plan:
apiVersion: kuadrant.io/v1
kind: AuthPolicy
metadata: { name: erp-api-auth, namespace: gateway }
spec:
targetRef: { group: gateway.networking.k8s.io, kind: HTTPRoute, name: erp-api }
rules:
authentication:
keycloak:
jwt:
issuerUrl: https://login.erp.example.com/realms/erp
---
apiVersion: kuadrant.io/v1
kind: RateLimitPolicy
metadata: { name: erp-api-plans, namespace: gateway }
spec:
targetRef: { group: gateway.networking.k8s.io, kind: HTTPRoute, name: erp-api }
limits:
starter:
rates: [{ limit: 100, window: 1m }]
counters: [{ expression: auth.identity.tenant_id }]
when: [{ predicate: "auth.identity.plan == 'starter'" }]
business:
rates: [{ limit: 1000, window: 1m }]
counters: [{ expression: auth.identity.tenant_id }]
when: [{ predicate: "auth.identity.plan == 'business'" }]
The counter is the tenant, not the user, so one noisy tenant exhausts its own plan and nobody else’s. Authentication runs before the limit, which is what lets the limit read auth.identity. The ERP services still validate the same token themselves and read tenant_id from it; the gateway is a front door, not the only check. Check: with no token a call returns 401; with an acme starter token the hundred-and-first call in a minute returns 429, while a globex business token on the same route still succeeds. The policy field names follow the v1 examples I read; confirm with kubectl explain on your install.
5. OpenFGA: a store per tenant
Authentication says who. OpenFGA says whether that person may touch this record. One model, one store per tenant, so a mistaken tuple in acme cannot grant anything in globex:
model
schema 1.1
type user
type tenant
relations
define buyer: [user]
define approver: [user]
define finance: [user]
define member: buyer or approver or finance
type purchase_order
relations
define owner: [tenant]
define can_view: member from owner
define can_draft: buyer from owner or approver from owner
define can_approve: approver from owner
type invoice
relations
define owner: [tenant]
define can_view: finance from owner or approver from owner
Deploy OpenFGA with its Helm chart against the openfga database, then create each tenant’s store, load the model and add people and records:
S=$(fga store create --name acme --api-url http://openfga.iam:8080 | jq -r .store.id)
fga model write --store-id $S --file model.fga
fga tuple write --store-id $S user:alice buyer tenant:acme
fga tuple write --store-id $S tenant:acme owner purchase_order:po-1001
fga query check --store-id $S user:alice can_draft purchase_order:po-1001 # allowed: true
fga query check --store-id $S user:alice can_approve purchase_order:po-1001 # allowed: false
Keep a table or ConfigMap mapping tenant_id to store id. This closes the gap Part 4 left: the ERP API, and the MCP tools in front of it, ask before they act.
from openfga_sdk import ClientConfiguration, OpenFgaClient
from openfga_sdk.client.models import ClientCheckRequest
async def allowed(store_id: str, sub: str, relation: str, obj: str) -> bool:
cfg = ClientConfiguration(api_url="http://openfga.iam:8080", store_id=store_id)
async with OpenFgaClient(cfg) as c:
r = await c.check(ClientCheckRequest(user=f"user:{sub}", relation=relation, object=obj))
return bool(r.allowed)
# in the ERP API handler, before a draft is saved (sketch):
# if not await allowed(store_of(token["tenant_id"]), token["sub"], "can_draft", f"purchase_order:{po_id}"):
# raise HTTPException(403)
The MCP draft_purchase_order tool makes the same check first, so a refusal reads clearly to the agent, but the ERP API is the enforcement point, because it sees every caller. Row-level security from Part 2 is still the last line. The ERP API code is not shown in these posts, so the handler lines are a sketch, and the CLI flags and SDK calls should be checked against your versions. Check: alice (a buyer) may draft but not approve; a globex user asking about an acme order is denied because that store has no such object; the copilot refuses a draft for a user without can_draft.
6. Flags: Unleash through OpenFeature
Install Unleash with its Helm chart against the unleash database. In its UI, create a custom context field tenantId, a flag po-auto-suggest, and one strategy constrained to tenantId IN acme. Services call the vendor-neutral OpenFeature API, so the flag server can be swapped later:
from openfeature import api
from openfeature.evaluation_context import EvaluationContext
from unleash_openfeature_python_provider import UnleashFlagProvider
api.set_provider_and_wait(UnleashFlagProvider(
url="http://unleash.unleash:4242/api", app_name="erp-api",
custom_headers={"Authorization": UNLEASH_TOKEN}))
flags = api.get_client()
ctx = EvaluationContext(targeting_key=token["sub"], attributes={"tenantId": token["tenant_id"]})
if flags.get_boolean_value("po-auto-suggest", False, ctx):
... # the new behaviour
The Unleash docs mark this provider as beta, and Unleash reads custom fields from the context’s properties; confirm that your attribute arrives there and that the constraint matches. Unleash is not a CNCF project, so it carries the NON CNCF label here. Check: the flag is true for an acme user and false for a globex user; add globex to the strategy and the second call flips without a deploy.
7. The build: Backstage, Tekton, Chains
Backstage is the front door for developers: a software template creates a service repository with the code skeleton, a catalog-info.yaml and a pipeline definition, and registers it in the catalog.
apiVersion: scaffolder.backstage.io/v1beta3
kind: Template
metadata: { name: erp-service, title: New ERP service }
spec:
owner: platform
type: service
parameters:
- title: Service
required: [name]
properties: { name: { type: string } }
steps:
- id: fetch
name: Fetch skeleton
action: fetch:template
input: { url: ./skeleton, values: { name: "${{ parameters.name }}" } }
- id: publish
name: Create repo
action: publish:github
input: { repoUrl: "github.com?owner=erp-demo&repo=${{ parameters.name }}" }
- id: register
name: Register
action: catalog:register
input: { repoContentsUrl: "${{ steps.publish.output.repoContentsUrl }}", catalogInfoPath: /catalog-info.yaml }
Install Backstage from its Helm chart. Adding the Kubernetes and Argo CD plugins to the catalog page is a code change in the Backstage app and is not covered here.
Tekton builds. The build task must publish two results, IMAGE_URL and IMAGE_DIGEST, because that is how Tekton Chains knows which image to sign. Build with a catalog task such as buildah, push to ECR (Pod Identity gives the pipeline service account push rights), then commit the new digest into the GitOps repository so Argo CD deploys exactly what was built. Starting a run from a Git push needs Tekton Triggers, which this part does not set up; start runs by hand with tkn pipeline start.
Chains signs. Its format value slsa/v1 produces an in-toto statement carrying SLSA provenance; storage oci puts the signed statement next to the image in ECR. The signing key is an AWS KMS key (create it with the Part 1 KMS setup), so no private key sits in the cluster:
kubectl -n tekton-chains patch configmap chains-config --type merge -p '{"data":{
"artifacts.taskrun.format":"slsa/v1","artifacts.taskrun.storage":"oci",
"artifacts.pipelinerun.format":"slsa/v1","artifacts.pipelinerun.storage":"oci",
"artifacts.oci.storage":"oci","artifacts.oci.signer":"kms",
"signers.kms.kmsref":"awskms:///alias/erp-signing"}}'
What in-toto means in this design: it is the statement format (the signed envelope) that Chains writes and Kyverno checks. The heavier classic in-toto workflow, with a layout and named functionary keys verified by in-toto-verify, is not used here. The ConfigMap keys, the kms signer and the predicate type name differ between Chains releases, so check Chains’ own SLSA provenance page for your version. Check: after a run, ECR shows the image plus signature and attestation artifacts, and cosign verify-attestation --key awskms:///alias/erp-signing --type slsaprovenance1 <image@digest> prints the statement.
8. The gate: Kyverno and Argo CD
Export the public key once (cosign public-key --key awskms:///alias/erp-signing) and put it in a Kyverno policy that applies to every Capsule tenant namespace:
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata: { name: require-signed-provenance }
spec:
webhookTimeoutSeconds: 30
rules:
- name: verify-provenance
match:
any:
- resources:
kinds: [Pod]
namespaceSelector:
matchExpressions:
- { key: capsule.clastix.io/tenant, operator: Exists }
verifyImages:
- imageReferences: ["ACCOUNT.dkr.ecr.ap-south-1.amazonaws.com/erp/*"]
failureAction: Enforce
mutateDigest: true
verifyDigest: true
attestors:
- entries:
- keys:
publicKeys: |-
-----BEGIN PUBLIC KEY-----
(the exported key)
-----END PUBLIC KEY-----
attestations:
- type: https://slsa.dev/provenance/v1
attestors:
- entries:
- keys:
publicKeys: |-
-----BEGIN PUBLIC KEY-----
(the exported key)
-----END PUBLIC KEY-----
conditions:
- all:
- key: "{{ buildDefinition.buildType }}"
operator: Equals
value: "https://tekton.dev/chains/v2/slsa"
Print a real statement with cosign download attestation before you trust the condition, and add a second condition on the source repository field you find there, so an image built from the wrong repository is refused too. Decide deliberately what happens if Kyverno is down (the webhook’s failure policy): failing closed protects the gate and can block every deploy. Older Kyverno releases spell type as predicateType, and newer ones add an ImageValidatingPolicy kind; use whichever your version documents.
Argo CD delivers from Git, one application per tenant from a single ApplicationSet:
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata: { name: erp-tenants, namespace: argocd }
spec:
generators:
- list: { elements: [{ tenant: acme }, { tenant: globex }] }
template:
metadata: { name: "erp-{{tenant}}" }
spec:
project: default
source: { repoURL: "https://github.com/erp-demo/gitops", targetRevision: main, path: "tenants/{{tenant}}" }
destination: { server: "https://kubernetes.default.svc", namespace: "{{tenant}}-erp" }
syncPolicy: { automated: { prune: true, selfHeal: true } }
Check, the whole gate: run a pod in acme-erp with an image pushed to the ECR path by hand, outside the pipeline: Kyverno rejects it. Then let the pipeline build and Argo CD roll out the real one: it is admitted, and kubectl describe pod shows the image pinned by digest.
9. Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| Gateway never gets an NLB address | Load Balancer Controller missing or no Pod Identity role | Install it; check its logs and the Service events |
| CloudFront returns 502 or 504 | NLB security group does not allow the CloudFront service group, or the certificate name does not match the origin domain | Allow CloudFront-VPCOrigins-Service-SG; use the certificate’s hostname as the origin domain |
| WAF ACL cannot be attached | ACL created outside us-east-1 |
Create it with the us-east-1 provider alias |
| Kuadrant policies show not enforced | Gateway not accepted, or Kuadrant installed before the gateway provider | Check policy status conditions; install the provider first |
| Every call is 401 | Issuer URL differs from the token’s iss |
Match the realm URL exactly, including scheme and host |
| Everyone shares one limit | Counter not set to the tenant | Use auth.identity.tenant_id as the counter expression |
| 403 for a user who should pass | Wrong store for the tenant, or the owner tuple is missing |
Check the store map and fga tuple read |
| Flag always false | tenantId not delivered as a property, or the constraint is on another field |
Log the evaluation context; check the constraint field name |
| Chains does not sign | Build task lacks IMAGE_URL and IMAGE_DIGEST results |
Add both results to the build task |
| Kyverno rejects the good image | Public key or predicate type differs from what Chains wrote | Compare with cosign download attestation output |
| Argo CD stuck on a pod | Kyverno refused it | Read the admission message in the ReplicaSet events |
Cost note
New AWS lines in this part: CloudFront and WAF (request and rule based), an internal NLB (hourly plus usage), and the extra ECR storage for signatures and attestations. I did not read current prices for these, so none are quoted; price them with the AWS calculator for ap-south-1 and your expected traffic before leaving them running. In the cluster, platform-pg, Keycloak, OpenFGA, Unleash, Kuadrant, Backstage and the Tekton controllers are a handful of small pods; measure them with OpenCost in Part 6.
Cleanup
kubectl delete applicationset -n argocd erp-tenants
kubectl delete clusterpolicy require-signed-provenance
kubectl -n kuadrant-system delete kuadrant kuadrant && helm -n kuadrant-system uninstall kuadrant-operator
kubectl -n gateway delete gateway erp-gateway # removes the NLB; do this before destroying the VPC
helm -n unleash uninstall unleash; helm -n openfga uninstall openfga
kubectl -n iam delete cluster.postgresql.cnpg.io platform-pg
# then: tofu destroy for CloudFront, the VPC origin and the WAF ACL (us-east-1); delete ECR images you no longer need
Design notes and version checks
- Nothing here was run on AWS, a cluster or a pipeline. The likeliest differences: Kuadrant policy fields and the Limitador Redis setting, the Istio-generated Service and annotation behaviour, the CloudFront VPC origin arguments, Chains ConfigMap keys and the KMS signer, Kyverno’s
typefield, the Unleash OpenFeature attribute mapping, and the OpenFGA CLI flags. - Kuadrant provider. Decided above from the documents I read on 5 December 2026; confirm the supported-provider list in Kuadrant’s current release notes before you rely on it.
- The gateway is not the only check. Token validation at the edge, OpenFGA in the API and row-level security in the database are three layers on purpose.
- Rate limits count tenants, not users, so plans are fair between tenants; add a per-user counter if one user inside a tenant can starve the others.
- Flags are not security. A flag decides who sees a feature; OpenFGA decides who may act.
- Provenance proves where an image came from, not that it is safe. It does not replace vulnerability scanning or code review.
- Synthetic data only. Tenants, users and orders here are demo data.
Setup checklist
- 1. Gateway: done when
erp-gatewayisProgrammedand has an internal NLB. - 2. Edge: done when
https://api.erp.example.comanswers through CloudFront and the NLB is unreachable directly. - 3. Identity: done when a decoded token shows
tenant_idandplan. - 4. Policy: done when no token gives 401 and a starter tenant gets 429 after its limit while another tenant is unaffected.
- 5. Permissions: done when a buyer may draft but not approve, and no tenant sees another’s objects.
- 6. Flags: done when a flag flips for one tenant only, without a deploy.
- 7. Build: done when ECR holds the image with a verifiable signed provenance statement.
- 8. Gate: done when Kyverno refuses a hand-pushed image and Argo CD rolls out the pipeline’s image.
Tools used
Istio, Kuadrant, Keycloak, OpenFGA, Unleash, OpenFeature, Backstage, Tekton, in-toto, Kyverno, Argo CD, cert-manager, CloudNativePG, OpenTofu.
What comes next
Part 6 runs it: Prometheus and OpenTelemetry for signals, HolmesGPT for investigations, Litmus game days, Kanister and Velero restore tests, OpenCost, the teardown order, and a proposal for Sprint 7. Back to the Overview.


