Kubernetes and edge security: clusters, containers, CDN and WAF
You do not run the clusters or the CDN, but you answer for them: trace the attacker's path from one pod to the cloud account, check what fronts the origin, and review both with the team that owns them
An attacker gets code execution inside one pod of Ojaline's seller-reports service on EKS. Which fact about that pod most decides whether this becomes an incident in the AWS account?
The security engineer at a company the size of Ojaline does not run Kubernetes. A platform team does, and an infrastructure team owns the CDN account. You still answer for both, because the clusters hold every service and the edge is where every request from the internet arrives. Your job is to reason about their risk precisely enough that the people who own them change something.
This chapter assumes cloud and infrastructure security, which covers AWS accounts, IAM, the metadata service and the shared-responsibility model; it does not repeat them. It picks up where that chapter’s short section on Kubernetes stops.
The model: an attacker’s path through a cluster
Read a cluster the way you read an account: as a path from an entry point to something that matters. The usual path has five steps, and each step is a control you can ask about.
| Step | What the attacker does | The question for the platform team |
|---|---|---|
| 1. Foothold | Exploits a bug in an exposed workload: injection, deserialisation, an SSRF (the SSRF lesson) | Which workloads take traffic from the internet, and what runs as root in them? |
| 2. Service account token | Reads the token Kubernetes mounted into the pod | Does this pod need a token at all, and what may it do? |
| 3. API server | Uses the token to list Secrets, create a pod, or exec into another | Which service accounts can read Secrets, create workloads or bind roles? |
| 4. The node | Creates a privileged pod or one with a hostPath mount, and escapes to the node |
Does admission reject privileged pods outside system namespaces? |
| 5. The cloud | Uses the pod’s AWS role, or the node’s role through the metadata service | What can each workload role do, and can pods reach the node’s role? |
Two things make this model useful in a meeting. First, the steps are independent controls, so the platform team can close any one of them without the others. Second, a cluster is a shared building. Ojaline runs about 150 services; a foothold in the least important one starts at the same step 1 as a foothold in the seller wallet. That is why the review is of the cluster, not of one service.
Identity inside the cluster: RBAC and service accounts
Every pod runs as a service account. If nobody names one, it gets the namespace’s default account, and Kubernetes mounts a token for it. Since Kubernetes 1.22 that token is projected when the pod runs and expires (and since 1.24 Kubernetes no longer creates long-lived Secret tokens automatically), which is better than the old long-lived Secret, but a pod that never calls the API server still carries one. The Kubernetes RBAC good practices page recommends setting automountServiceAccountToken: false where the token is not needed.
What the token can do is set by Roles and RoleBindings. The same page lists the permissions that are worth more than they look, and these are the ones to search for:
listandwatchon Secrets. The page warns that they “effectively allow for users to reveal the Secret contents”, because a list response carries every Secret in full. Many teams grantgetcarefully andlistcarelessly.- Creating pods or any workload. The page says this implicitly grants access to the namespace’s Secrets, ConfigMaps and volumes, and to the API rights of any service account in it, because the new pod can mount them. A CI service account that can create Deployments in a namespace can read that namespace’s Secrets.
- Wildcards and
cluster-admin. A*covers resource types that do not exist yet. Prefer RoleBindings in a namespace to ClusterRoleBindings. system:masters. Members bypass RBAC entirely, and removing a binding does not revoke it.
On EKS, people reach the cluster through IAM. AWS’s EKS best practices guide now recommends access entries over the older aws-auth ConfigMap, and warns that the identity that created a cluster may hold system:masters permissions. Ask who created each production cluster, and whether that role is now a break-glass role with an owner, as identity, access and secrets describes for any emergency access.
What a pod may be: Pod Security Standards and admission
A container is a process with some kernel isolation, not a virtual machine. Run it privileged, share the host’s network or mount the host’s filesystem, and the isolation is gone. The Pod Security Standards define three levels. Privileged is unrestricted and “allows for known privilege escalations”. Baseline “prevents known privilege escalations”: no privileged containers, no hostPath volumes, no host network. Restricted follows current hardening practice: run as non-root, drop all capabilities, no privilege escalation, a seccomp profile.
Kubernetes enforces them with Pod Security Admission, built in and stable since 1.25. You label a namespace with a level for each of three modes: enforce rejects the pod, audit records it in the audit log, warn tells the person deploying.
metadata:
labels:
pod-security.kubernetes.io/enforce: baseline
pod-security.kubernetes.io/warn: restricted
pod-security.kubernetes.io/audit: restricted
That pattern is the usual way in: enforce Baseline, which most application pods already meet, and warn at Restricted so teams see what they would have to change. Namespaces for system agents that need host access, such as the CNI plugin or a log shipper, stay Privileged by exception, with a list of what runs there.
Pod Security Admission checks pod fields and nothing else. For rules about anything in the API, such as “images only from our registry”, “every Deployment has an owner label” or “no Service of type LoadBalancer outside the ingress namespace”, teams add a policy engine as an admission webhook. Two common ones are Kyverno, which writes policies in YAML and CEL, and OPA Gatekeeper, “a validating and mutating webhook that enforces CRD-based policies” written in Rego. Either will do; the choice belongs to the platform team, who will maintain it. Your interest is the policy list and the exceptions.
Admission is also where image provenance is enforced. A rule that admits only images signed by your build pipeline, pulled by digest, is the deployment end of software supply chain security; Kyverno, for example, lists Sigstore cosign verification among its features. Agree the rule with whoever owns the pipeline before the platform team switches it to enforce.
Who can talk to whom: network policy
The NetworkPolicy documentation states the default plainly: a pod no policy selects accepts all inbound and makes all outbound connections. In a cluster with no policies, step 1 on any pod gives the attacker a network route to every database proxy, every internal admin endpoint and every other service’s port.
The fix is default-deny per namespace, then allow rules for the flows the service needs:
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: default-deny
spec:
podSelector: {}
policyTypes: [Ingress, Egress]
Three facts matter in review. Policies need a network plugin that enforces them; the docs say a policy with no controller “will have no effect”, so check the plugin before you trust the YAML. Policies are additive: one broad allow rule anywhere in the namespace opens the door for every pod it selects. And egress default-deny breaks DNS until you allow it, which is the most common reason teams roll it back. Go namespace by namespace, starting with the ones that hold money and personal data, and allow DNS in the first change.
Egress is the half teams skip, and it is the half that stops step 5. A pod that cannot reach the metadata address or arbitrary internet hosts is a poorer foothold.
Secrets in a cluster
A Kubernetes Secret’s values are base64-encoded in the manifest. That is an encoding, and base64 -d reverses it. The Secrets documentation is blunt: Secrets are by default “stored unencrypted in the API server’s underlying data store (etcd)”, and “anyone who is authorized to create a Pod in a namespace can use that access to read any Secret in that namespace”. It lists the steps to take: encryption at rest, least-privilege RBAC on Secrets, Secrets mounted only into the containers that need them, and external secret stores.
On EKS, the first step is done for you: AWS envelope-encrypts all Kubernetes API data by default on clusters running 1.28 or later, with an AWS-owned key or your own KMS key. That protects etcd’s storage. It does nothing about the API, which decrypts the Secret for anyone allowed to read it. So the RBAC questions above are the real control.
The external store moves the source of truth out of the cluster: AWS Secrets Manager or a vault, synced in by the External Secrets Operator or mounted with the Secrets Store CSI driver. That gives you rotation, an audit trail in CloudTrail and one place to revoke. It does not stop a compromised pod from reading the secret it was given. Credentials for AWS itself should not be Secrets at all: Pod Identity or IRSA issues short-lived role credentials per service account, and AWS’s guide recommends Pod Identity unless you have a reason for IRSA. Then close the side door: require IMDSv2 with a hop limit of 1 on the nodes, which the same guide gives as the way to stop pods inheriting the node’s role.
The shared-responsibility line on EKS
AWS’s EKS security guide draws the line: AWS manages the control plane, “the Kubernetes control plane nodes, the ETCD database”, and you are “largely responsible” for IAM, pod security, runtime security and network security. The line moves with the data plane: with Fargate, AWS also secures the instance and runtime under your pods; with managed node groups, AWS publishes patched images and you roll them out.
| Concern | Self-run control plane | EKS with managed node groups |
|---|---|---|
| API server, etcd, their patching and backups | You | AWS |
| etcd encryption at rest | You configure it | On by default from 1.28 |
| API endpoint exposure | You | You: public by default, restrict by CIDR or make private |
| Node image patching | You | AWS publishes; you roll out |
| RBAC, admission, network policy, Pod Security | You | You |
| Workload IAM roles and the metadata service | You | You |
Read the bottom three rows twice. A managed control plane removes a class of work, mostly patching and etcd; it does not remove any step of the attacker’s path above. When someone says “it’s managed, AWS handles security”, the table is your answer. The CIS Kubernetes Benchmark has an EKS edition that splits the checks the same way, and the NSA and CISA Kubernetes Hardening Guide is the readable long version.
The edge: what stands in front of the origin
Most SaaS companies put a CDN and reverse proxy in front of everything public. Ojaline uses Cloudflare. The proxy terminates TLS, caches, absorbs DDoS traffic and runs the WAF. All of that protects only traffic that goes through it. The first question of an edge review is therefore whether the origin can be reached without it.
Origins leak. Cloudflare’s origin protection guide lists the ways: DNS records that are not proxied, SPF and TXT records that name the server, mail sent from the same host, and historical DNS records from before the CDN, which is why it recommends rotating origin addresses after onboarding. On AWS add one more: the load balancer has a public DNS name of its own. If it accepts traffic from anywhere, the WAF is a suggestion.
There are three ways to lock the origin, and they prove different things.
| Method | What it proves | Watch for |
|---|---|---|
| Allow-list the CDN’s IP ranges | The connection came from the CDN’s network | Any account on the same CDN can send traffic from those ranges; Cloudflare rates it moderately secure. Ranges change, so automate the list |
| Authenticated origin pulls (mTLS) | The CDN presented a client certificate | Cloudflare’s shared global certificate “only guarantees that a request is coming from the Cloudflare network”. Use a zone-level or per-hostname certificate of your own to prove it came through your zone |
Tunnel (cloudflared) |
The origin has no inbound path at all | The connector runs in your cluster and is itself a credential; the Tunnel docs describe outbound-only connections with all inbound blocked |
The allow-list is a good first step and a poor last one. Pair it with mTLS using your own certificate, or move to a tunnel, for anything that holds customer data.
WAF, rate limits, bots and DDoS
Managed rules are written by the vendor. Cloudflare’s managed rulesets include its own ruleset and its implementation of the OWASP Core Rule Set, which the CRS project describes as “a set of generic attack detection rules”. The OWASP ruleset scores each request and acts above a threshold, so you tune it: too low and it blocks real sellers uploading product descriptions full of HTML, too high and it catches little. Turn them on, tune them on real traffic, and expect them to catch the generic attacks, not the bugs in your business logic.
Custom rules are yours: expressions on path, method, header, parameter and score, with actions such as block, managed challenge or skip. They are how you answer a specific exploit in hours. The log action, which records matches without acting, is Enterprise only; on other plans, test a new rule by scoping it narrowly and watching its matches.
Rate limiting rules count requests per characteristic and act when a limit is passed. What you can count by depends on the plan: by IP on every plan, by header, cookie or JSON field only on Enterprise with Advanced Rate Limiting, and by JA3/JA4 fingerprint only with Bot Management as well. For an API, counting by API key or session is worth far more than counting by IP, so price that add-on in. The rate limiting lesson covers the algorithms; the edge is where you apply them before traffic costs you a pod.
Bot management ranges from a single toggle on the free plan to per-request bot scores on Enterprise (Cloudflare bots). Scores are inputs to rules on login, checkout and search, not a control in themselves.
DDoS protection at layers 3 to 7 is automatic and unmetered on all Cloudflare plans. It protects what is proxied. An origin reachable directly is outside it.
The edge is a layer, not a fix. A WAF rule matches patterns; an attacker who finds the encoding it misses goes through. The IDOR and tenant isolation lessons describe bugs whose requests look exactly like legitimate ones, and no WAF rule sees them.
Edge configuration is production code
The edge is the one system that touches every request, and its configuration propagates in seconds. That is what makes it useful in an incident and dangerous in a change. The 2019 outage in the Why was a managed rule. On 18 November 2025 Cloudflare had a larger one with no rule change at all: a database permissions change made the query that builds a Bot Management feature file return duplicate rows, the file doubled in size past a limit in the proxy, and the proxy failed across the network; core traffic was largely flowing again about three hours later (Cloudflare’s postmortem). One of its remedies is to treat internally generated configuration files with the same rigour as user input.
You do not run Cloudflare’s network, but your zone’s configuration has the same shape on a smaller scale. One custom rule with a wrong expression blocks every buyer at checkout, in every city, at once. So:
- Edge config as code. Rules, rate limits and origin settings live in Terraform, reviewed like application code, with dashboard edit rights limited to break-glass.
- An emergency path. During an exploit you cannot wait for the weekly change window. Agree in advance who may push a rule directly, with a second person reading the expression, and that the change is back-ported to code the same day.
- Narrow first. Scope a new rule to one host and path, watch its matches, then widen.
- An expiry. Every emergency rule carries an owner and a removal date tied to the code fix. Old rules nobody understands are how a WAF ends up blocking a feature a year later.
Where practitioners disagree
| Question | One view | The other view |
|---|---|---|
| Separate clusters or namespaces | Namespaces with RBAC, admission and network policy are enough for one company’s services | The RBAC page calls namespace boundaries weak; put payments and untrusted workloads in their own cluster |
| Policy engine | Pod Security Admission plus a few rules; every webhook is another thing that can block deploys | A policy engine from day one, because image and label rules need one anyway |
| WAF as a control | Managed rules catch real attacks cheaply; keep them on everywhere | WAFs create false confidence and false positives; spend the effort on code |
| Service mesh mTLS | Encrypt and authenticate every pod-to-pod call | Network policy plus TLS where data is sensitive is cheaper and easier to reason about |
Most teams at Ojaline’s size land on namespaces plus a separate cluster for money, Baseline enforced with a short exception list, managed rules tuned rather than switched off, and a mesh only where a compliance requirement asks for it.
Running the review without owning the cluster
You will not get cluster-admin, and you should not want it. Ask for read access instead: a read-only ClusterRole that excludes Secrets, read access to the edge account, and the Terraform repositories. Then run the review as a joint exercise.
Before the meeting, gather evidence the platform team can rerun: every ClusterRoleBinding and the subjects bound to cluster-admin; every service account that can list Secrets or create workloads (kubectl auth can-i --list --as=system:serviceaccount:<ns>:<sa>); the Pod Security labels per namespace; which namespaces have a default-deny policy; the IAM role behind each service account and its policies; node metadata settings; and, at the edge, every public hostname, whether it is proxied, and whether its origin answers directly.
In the meeting, walk the five steps with one real service, not the checklist. “If the seller-reports pod were compromised, here is what it could do” lands with engineers in a way that “41 CIS failures” does not. Rank findings by how far they move an attacker along the path, as cloud and infrastructure security ranks account findings.
After it, each fix gets an owner on the platform team and a guardrail where one exists: an admission policy rather than a wiki page, a Terraform check rather than a reminder. Your residual-risk list names who accepted each item. When the review finds a path that is open right now, it is an incident, and detection and incident response takes over.
Day to day
Weekly, an hour. Read new ClusterRoleBindings, new public hostnames and new admission exceptions. Each of these should arrive as a pull request you are tagged on; if they do not, that is the first thing to fix.
On every new service or cluster. A short review in the design-doc process: does it take internet traffic, which identity does it run as, which AWS role does it get, does it need a token, which namespace and Pod Security level.
On every exploit report against a public endpoint. Decide within the hour whether an edge rule is worth shipping while the code fix is written, and write its expiry into the ticket.
Monthly. With the platform tech lead, 30 minutes on the exception list and the metrics: namespaces at Baseline or better, namespaces with default-deny, service accounts with Secret-list rights, origins reachable directly, emergency edge rules past their removal date.
Quarterly. The full cluster and edge review below, and a tabletop where a pod is compromised and the team traces how far it gets.
The meetings that matter are the platform team’s planning, where your findings compete with upgrades for the quarter, and the change review for edge configuration, where a bad expression is cheapest to catch.
There is probably no Kubernetes, and there should not be: a managed container service or a platform-as-a-service removes most of this chapter. If a cluster exists, one engineer built it. Your three checks are the ones that matter most: no pod gets a powerful AWS role or the node’s role, the API endpoint is restricted, and the origin accepts only the CDN. Put the CDN in front from the first day, with managed rules on, DDoS protection included, and the config in the same repository as the infrastructure.
The platform team is forming and the cluster grew by copy and paste. This is the stage to set defaults rather than review exceptions: Baseline enforced on every new namespace, default-deny in the template, Pod Identity as the only way to get AWS credentials, and edge rules moved from the dashboard into Terraform. Customers’ security questionnaires begin to ask about segmentation and the WAF, and SOC 2 auditors ask who can change production. Agree the emergency edge path before the first exploit, not during it.
Many clusters, several teams and an edge account with years of rules. The problem is drift and ownership: which of 400 custom rules still matters, which cluster was set up before the standards, which exception was meant to be temporary. Policy lives in a policy engine and is reported per cluster; edge changes go through code review with an emergency path; the separate cluster for payments is a standing decision. Your leverage is the quarterly review and a metric the platform director reports alongside reliability.
Template
# Cluster and edge review: <cluster(s) and zone>
Reviewer · With: <platform tech lead, edge owner> · Date · Evidence: <repo or folder>
Read access used: <role, scope, expiry>
## 1. Inventory
| Cluster | Version | Control plane | Node types | Namespaces | Services |
|---|---|---|---|---|---|
| Public hostname | Proxied? | Origin | Origin lock (IP list / mTLS own cert / tunnel) | Answers directly? |
|---|---|---|---|---|
## 2. Attack path walk: <service>
| Step | What the attacker gets | Control today | Gap |
|---|---|---|---|
| Foothold | | | |
| Service account token | | | |
| API server | | | |
| Node | | | |
| Cloud | | | |
## 3. Identity
| Subject | Binding | Rights of concern (cluster-admin, list Secrets, create workloads, bind) | Reason or fix |
|---|---|---|---|
| Service account | AWS role (Pod Identity / IRSA) | What it can reach | Too broad? |
|---|---|---|---|
Node metadata: IMDSv2 required? Hop limit:
## 4. Workloads and network
| Namespace | PSA enforce / warn | Default-deny in / out | Exceptions and owner |
|---|---|---|---|
Admission policies (engine, rules, mode):
Image rule (registry, signature, digest):
Secrets: encryption at rest; external store; who can list:
## 5. Edge
Managed rules (sets, threshold, last tuned):
Custom rules (count; emergency rules with owner and removal date):
Rate limits (endpoint, counted by, limit):
Bots and DDoS:
Config as code? Who has dashboard edit rights:
## 6. Findings, ranked
| # | Finding | Steps it moves | Fix | Guardrail | Owner | Date |
|---|---|---|---|---|---|---|
## 7. Residual risk
| Risk | Why accepted | Accepted by | Review date |
|---|---|---|---| WORKED EXAMPLE
Ojaline (1,400 staff, about 150 services, 300 engineers) runs on AWS with two production EKS clusters: prod-a for marketplace and seller services, prod-b for dispatch and payment jobs, about 60 namespaces between them. A platform team of eight runs them; Idrissa is its tech lead. Cloudflare fronts the web, seller dashboard and public API hosts. Uzo, a security engineer, ran the quarterly review with Idrissa over two 90-minute sessions, using a read-only role without Secrets. All figures are illustrative.
Attack path, seller-reports on prod-a. Foothold: the service parses uploaded spreadsheets. Token: mounted, unused. API server: its account had list on Secrets in its namespace, granted for a migration two years ago. Node: the namespace had no Pod Security label. Cloud: its Pod Identity role read one bucket, but the node group it ran on had a metadata hop limit of 2, so the node role was reachable too.
| # | Finding | Steps | Fix and guardrail | Owner |
|---|---|---|---|---|
| 1 | Seller API load balancer accepts traffic from anywhere; origin answers directly | Bypasses WAF and DDoS | Cloudflare IP list now, mTLS with Ojaline’s own certificate in 4 weeks; Terraform check | Idrissa |
| 2 | One node group with hop limit 2 | 5 | Launch template to hop limit 1; policy that fails the plan | Platform on-call |
| 3 | 11 service accounts can list Secrets beyond their own needs | 3 | Remove; Kyverno rule flags new grants | Idrissa |
| 4 | 4 humans and CI bound to cluster-admin | 3 | CI to a namespaced role; humans to break-glass | Idrissa |
| 5 | PSA labels on 9 of about 60 namespaces; default-deny on none | 4, and lateral moves | Baseline enforce on all but 3 agent namespaces in 6 weeks; default-deny in money namespaces first | Platform |
| 6 | Two emergency WAF rules from March with no owner | Outage risk | Removed after Uzo confirmed both fixes shipped | Uzo |
Accepted. prod-a and prod-b share the AWS account’s network; separation by account waits for the second-region work. Accepted by the head of infrastructure, review in one quarter.
Now you
You are a security engineer at Ojaline. The platform team is building prod-c, a cluster in a second AWS region for dispatch routing and the nightly seller-wallet payout job, live in five weeks. Idrissa, the platform tech lead, asks you to review it before launch. Complications: prod-c was built from the staging configuration, so every namespace is labelled Privileged; the payout job needs the credential for the NIP payment provider, currently a Kubernetes Secret created by hand; the dispatch API for the delivery fleet’s app sits behind a public load balancer, and the plan is to add it to Cloudflare after launch; CI deploys with a cluster-admin binding; three people outside the platform team still have dashboard edit rights on the Cloudflare account; and the platform team says network policy will wait for the next quarter. Write the review: inventory, an attack-path walk for the payout job, the findings ranked, which must close before launch, and the risks the head of infrastructure would have to accept.
Self-check
At 10:15 Uzo sees that since 09:40 someone has been fetching other sellers' invoice files through a path traversal in the file parameter of Ojaline's seller invoice download, about 1,900 requests from about 60 addresses. The code fix is small; the service's pipeline takes about 90 minutes to production with its canary. A Cloudflare custom rule on that host, path and parameter can block traversal patterns. Edge changes normally go through a 30-minute Terraform review; an emergency change with a second reviewer is allowed. The origin accepts only Cloudflare's IP ranges. What do you do?
- DOC Pod Security Standards Kubernetes
The three levels and every field each one checks. Use it to read a namespace's label and know what it permits.
- DOC Role Based Access Control Good Practices Kubernetes
The list of permissions that escalate, from listing Secrets to creating workloads. Search your bindings for each one.
- DOC Kubernetes Hardening Guide (version 1.2) NSA and CISA, 2022
The long-form hardening guidance for a cluster, version 1.2 of August 2022. Read it once end to end before your first review.
- DOC CIS Kubernetes Benchmark Center for Internet Security
The checklist auditors recognise, with separate editions for EKS, GKE and AKS that split control-plane and customer checks.
- DOC Amazon EKS Best Practices: Security AWS
The shared-responsibility line for EKS, and the identity section on access entries, Pod Identity and blocking the node's metadata service.
- DOC Protect your origin server Cloudflare
Every way an origin leaks and every way to lock it, with Cloudflare's own rating of how secure each method is.
- POST Details of the Cloudflare outage on July 2, 2019 Cloudflare, 2019
A WAF rule that took down the network, and the changes that followed, including staged rollout for rules. Read it before you write your first emergency rule.
- DOC OWASP CRS OWASP CRS project
The generic attack rules behind most managed WAF rulesets, including Cloudflare's OWASP ruleset. Useful for understanding why a request was blocked.
All companies and people in these examples are fictional. Any resemblance to a real business or person is unintended.