KCSA Isolation, Image Security and Application Code Security
Isolation, image security and workload code security are the KCSA competencies about limiting what a compromised container can reach and making sure what you deploy is minimal, known and trustworthy. This lesson covers the Domain 1 competencies Isolation Techniques, Artifact Repository and Image Security, and Workload and Application Code Security: why containers share the host kernel, what Linux and Kubernetes namespaces do and don't isolate, dedicated nodes, sandboxed runtimes and RuntimeClass, minimal images, scanning, digests, signing and trusted registries, and keeping secrets and vulnerable dependencies out of your code and images.
On this page10 sections
- Why containers need extra isolation: the shared kernel
- Linux building blocks: namespaces, cgroups, seccomp and capabilities
- What a Kubernetes namespace isolates, and what it doesn't
- Node isolation: dedicated nodes for sensitive workloads
- Sandboxed runtimes: gVisor, Kata Containers and RuntimeClass
- Choosing an isolation boundary
- Minimal base images and multi-stage builds
- Image scanning, rescanning and digest pinning
- Image signing and trusted registries
- Workload and application code security
- Explain why standard containers share the host kernel and how a virtual machine or sandboxed runtime changes that
- Distinguish what Linux namespaces, cgroups, seccomp and capabilities each isolate
- Describe what a Kubernetes namespace isolates, what it leaves shared, and which objects are cluster-scoped
- Keep sensitive Pods on dedicated nodes with taints, tolerations and node affinity, and choose gVisor or Kata Containers through RuntimeClass
- Order isolation boundaries by strength and choose one against a cost or trust constraint
- Reduce image risk with minimal bases, multi-stage builds, scanning and rescanning, digest pinning, signing and trusted registries
- Keep secrets out of image layers and use SCA, lockfiles, SAST and a non-root USER for secure application code
Linux building blocks: namespaces, cgroups, seccomp and capabilities
Container isolation is built from several Linux kernel features, and each one isolates something different. Namespaces control what a process can see; control groups (cgroups) control how much it can use.
| Kernel feature | What it does for a container | Example |
|---|---|---|
| Namespaces (PID, mount, network, UTS, IPC, user) | Give the process its own view of a resource | The container sees only its own processes, mounts and network interfaces, not the host's |
| cgroups | Limit and account for CPU, memory and other resources | A noisy or compromised container can't starve its neighbours of memory or CPU |
| seccomp | Filters which system calls the process may make | Blocks rarely needed calls that are common in kernel exploits |
| Linux capabilities | Split root's powers into smaller privileges | A process can bind low ports without being able to load kernel modules |
In Kubernetes, the CPU and memory requests and limits on a container are enforced through cgroups, and the Pod's network namespace is shared by all containers in that Pod. All four features reduce what a container can do, but none of them gives the container its own kernel, which is why the shared-kernel risk remains. How to set seccomp profiles, capabilities and other securityContext fields is covered in the workload security lessons of the later domains.
What a Kubernetes namespace isolates, and what it doesn't
A Kubernetes namespace is an administrative boundary, not a security boundary on its own: it scopes object names, RBAC Roles and RoleBindings, ResourceQuotas, LimitRanges and namespaced policies, but it does not isolate network traffic or the kernel. It is the starting point of soft multi-tenancy, and it needs other controls added to it.
- Network: the Kubernetes network model lets every Pod reach every other Pod, across namespaces, unless NetworkPolicies (enforced by the network plugin) restrict it. Tenants in separate namespaces with no other controls can still connect to each other.
- Nodes and kernel: Pods from different namespaces are scheduled onto the same nodes and share their kernels unless you separate them.
- Cluster-scoped objects: some resources don't belong to any namespace, so a namespaced Role can never grant access to them.
| Namespaced (a Role can grant access) | Cluster-scoped (only a ClusterRole can) |
|---|---|
| Pods, Deployments, Services, Secrets, ConfigMaps, ServiceAccounts, PersistentVolumeClaims, Roles, RoleBindings | Nodes, Namespaces, PersistentVolumes, StorageClasses, ClusterRoles, ClusterRoleBindings, CustomResourceDefinitions |
The shared control plane is a further limit: every tenant's namespace is served by the same API server and etcd. List them with kubectl api-resources --namespaced=true or --namespaced=false.
Node isolation: dedicated nodes for sensitive workloads
Node isolation runs sensitive or untrusted workloads on their own set of nodes, so a compromise of one node (for example after a container escape) exposes only the Pods that were meant to share it. It limits the blast radius of a node takeover because it decides which machine a Pod runs on, and controls that never influence scheduling can't provide that separation.
Kubernetes keeps Pods on a dedicated pool with two mechanisms that work in opposite directions, and you usually need both:
| Mechanism | Set on | Effect | What it does not do |
|---|---|---|---|
Taint (e.g. effect NoSchedule) | The node | Repels every Pod that doesn't tolerate it | Doesn't pull any Pod onto the node |
| Toleration | The Pod | Allows the Pod onto a node with a matching taint | Doesn't require the Pod to go there; it can still land on untainted nodes |
Node affinity or nodeSelector | The Pod | Requires (or prefers) nodes with a given label | Doesn't keep other Pods away |
So taints plus tolerations keep other Pods off the pool, and a required node affinity or nodeSelector on the sensitive Pods keeps them on it. The taint effect sets how strictly other Pods are repelled: NoSchedule keeps new non-tolerating Pods off the node, and NoExecute also repels new Pods and additionally evicts non-tolerating Pods already running there. Neither effect attracts Pods to the node. Dedicated nodes cost more, because capacity can no longer be shared freely.
Sandboxed runtimes: gVisor, Kata Containers and RuntimeClass
A sandboxed runtime puts an extra kernel layer between a container and the host kernel, so an exploit of the system call interface no longer reaches the host directly, while the Pod keeps running on a shared node. The two common open source sandboxes do this in different ways:
| gVisor | Kata Containers | |
|---|---|---|
| How it isolates | Implements the Linux system call interface itself in a user-space kernel (the Sentry), so the container's calls are serviced there rather than by the host kernel | Each Pod runs inside a lightweight virtual machine with its own guest kernel |
| Typical runtime handler | runsc | kata (name depends on node configuration) |
| Main trade-off | System call overhead; not every Linux system call or host feature is implemented, so some workloads fail or behave differently | VM boot and memory overhead per Pod; needs virtualisation support on the node |
Kubernetes selects a runtime per Pod with RuntimeClass. A cluster administrator creates a RuntimeClass object whose handler names a runtime configured in each node's CRI implementation (such as containerd), and a Pod opts in by setting spec.runtimeClassName:
apiVersion: node.k8s.io/v1
kind: RuntimeClass
metadata:
name: gvisor
handler: runsc
---
# in the Pod spec
spec:
runtimeClassName: gvisorBecause sandboxes add CPU, memory and start-up overhead and can break compatibility, they are usually applied selectively to untrusted workloads (customer-supplied code, third-party plugins) rather than to the whole cluster. The cost of a sandbox is paid in performance and compatibility on the node, which is why teams usually test a workload under it before adopting it.
Choosing an isolation boundary
Pick the weakest boundary that still matches how much the tenants distrust each other, because each step up in strength removes more shared components and costs more. The Kubernetes multi-tenancy guidance describes this range from soft multi-tenancy (cooperating teams) to hard multi-tenancy (mutually untrusted customers):
| Boundary (weaker to stronger) | Still shared between tenants | Typical use |
|---|---|---|
| Namespace with RBAC, quotas and NetworkPolicies | Nodes, kernel, control plane | Teams in one organisation that trust each other |
| Dedicated nodes per tenant | Control plane and the Pod network (unless NetworkPolicies restrict it); no node or kernel | Sensitive workloads that must not share a machine |
| Sandboxed runtime per untrusted Pod | Nodes and control plane, but the host kernel is behind a sandbox | Untrusted code running alongside other workloads |
| Separate cluster per tenant, on its own VMs | Nothing in Kubernetes (only the provider's infrastructure) | Hard multi-tenancy between mutually untrusted tenants |
Match the boundary to two things: the threat (which shared component an attacker would abuse) and the constraint (what the organisation is willing to stop sharing or pay for). A boundary that leaves the threatened component shared doesn't meet the requirement, and one that removes more sharing than the constraint allows doesn't fit the design. Dedicated nodes and sandboxes also defend against different things, so they are often combined: dedicated nodes limit what a node takeover reaches, a sandbox makes the takeover harder.
Minimal base images and multi-stage builds
A minimal image reduces attack surface by shipping only what the application needs at run time. Distroless images contain the application's runtime dependencies (for example a language runtime and CA certificates) and no shell or package manager; scratch is a completely empty base, suitable for a statically linked binary. With fewer packages there are fewer known vulnerabilities to patch, and an attacker who gains code execution has no shell, package manager or debugging tools to work with.
A multi-stage build compiles in one stage and copies only the finished artifact into a small final stage, so compilers and build tools never ship:
FROM golang:1.25 AS build
WORKDIR /src
COPY . .
RUN CGO_ENABLED=0 go build -o /app ./cmd/server
FROM gcr.io/distroless/static-debian12:nonroot
COPY --from=build /app /app
USER 65532
ENTRYPOINT ["/app"]Attack surface is about what the image contains. Only changes to the contents reduce it. Supply-chain controls such as signing and trusted registries protect something different, where an image came from and whether it was altered, and the user a container runs as is set separately in the image or Pod spec.
Image scanning, rescanning and digest pinning
An image vulnerability scanner (for example Trivy or Grype) inventories the OS packages and language libraries inside an image and matches their versions against CVE databases, reporting known vulnerabilities and usually the fixed version. Because it works from published vulnerability data about components it can identify, it is a check on what is already known; integrity, first-party code flaws and runtime behaviour are covered by other controls.
A scan result is a snapshot of the vulnerability database at scan time. New CVEs are published every day, so an image that was clean at build time can be vulnerable months later without a single byte changing. Scan in CI, and also rescan stored and running images on a schedule; many registries do this automatically.
An image tag (payments:1.4.2, latest) is a movable pointer in a registry: someone can push different content under the same name and tag. A digest (payments@sha256:<digest>) is computed from the image manifest, so a reference by digest always resolves to exactly the same content, or fails to pull.
| Control | What it guarantees | What it leaves open |
|---|---|---|
| Digest reference | The content that runs never changes | Whether that content has vulnerabilities disclosed since |
| Scheduled rescanning | The vulnerability verdict stays current | Whether the content behind a reference changes |
The two controls answer different requirements, so you need both together: a digest keeps the reviewed build unchanged, and rescanning keeps the security verdict on that build current.
Image signing and trusted registries
Signing an image proves who published it and that it hasn't changed since it was signed; it says nothing about whether the image is free of vulnerabilities. Tools such as Sigstore cosign sign the image digest, either with a key pair or keylessly with a short-lived certificate tied to an identity (recorded in a transparency log). Verification confirms the expected signer and that the content still matches the signed digest. A trusted publisher can still ship a vulnerable or misconfigured image, so signing complements scanning and minimal images rather than replacing them.
A trusted registry controls where images come from. A common pattern is to mirror or proxy approved public images into an organisation-controlled private registry, scan and review them there, and have workloads pull only from that registry. Developers keep using familiar open source images, and the security team decides what enters. The point is control of the source itself: the organisation, rather than a public registry, decides which images exist to be pulled. Private Kubernetes registries are accessed with imagePullSecrets on the Pod or its service account.
Enforcing these rules at deploy time (admission policies that require signatures or allowed registries) and software bills of materials and provenance belong to the supply-chain topics of the Platform Security domain.
Workload and application code security
Workload and application code security means keeping the code you write, the dependencies it pulls in and the image defaults it ships with free of weaknesses before anything is deployed. Four practices cover most of it.
Keep secrets out of images
Each RUN, COPY or ADD instruction adds a filesystem layer, and image layers are immutable. A token copied in and deleted by a later instruction is only hidden: the earlier layer still contains it and anyone who can pull the image can extract it. ENV values are stored in the image configuration, and ARG build arguments can appear in the image history, so neither is safe for credentials. If a build step needs a secret, use a BuildKit secret mount, which exposes it to one instruction without writing it into any layer:
RUN --mount=type=secret,id=npm_token \
NPM_TOKEN=$(cat /run/secrets/npm_token) npm ciCredentials the application needs at run time come from a Kubernetes Secret injected when the Pod starts (as an environment variable or a mounted file). ConfigMaps are meant for non-confidential configuration; a Secret can be restricted separately with RBAC, encrypted at rest and rotated without rebuilding the image. A credential that has already leaked must be rotated, whatever else changes.
Know what your dependencies contain
Software composition analysis (SCA) builds an inventory of the open source components an application uses, including transitive dependencies pulled in by direct ones, and matches their versions against vulnerability databases. A committed lockfile records the exact version and integrity hash of every dependency, so each build installs what was reviewed instead of whatever release is newest; updates arrive through approved changes. Floating version ranges are how a freshly compromised release reaches production, often before any CVE exists for it to be scanned for.
| Practice | Looks at | Finds |
|---|---|---|
| SAST (static application security testing) | Your own source code, without running it | Injection flaws, unsafe functions, hard-coded secrets in first-party code |
| SCA (software composition analysis) | Third-party dependencies, direct and transitive | Known-vulnerable or unwanted open source components |
| DAST (dynamic application security testing) | The running application, from outside | Exploitable behaviour such as injection or misconfigured responses |
| Image scanning | The built image's packages and libraries | Known CVEs, including in the base image |
Ship safe defaults in the image
A container runs as the user its image specifies, and as root if none is set. Adding a USER instruction with a non-root UID to the Dockerfile makes the unprivileged user the default of the artifact itself, so every deployment inherits it. Steps that prepare an account or file ownership support it, but it is the USER instruction that sets who the process runs as. Pod-level runAsNonRoot: true is good defence in depth, though it lives in each Pod spec, and against an image that defaults to root it blocks the container from starting rather than changing the user.
Tip. KCSA questions on this topic are short scenarios and definitions. Expect to explain the shared-kernel limit of standard containers, to contrast containers with virtual machines, and to match a Linux feature (namespaces, cgroups, seccomp, capabilities) to what it isolates. Namespace questions check what a namespace does not isolate: network traffic by default and cluster-scoped objects such as PersistentVolumes, which a namespaced Role cannot grant. Isolation-design scenarios state a constraint, such as sharing nodes to cut cost, accepting cost for the strongest isolation or not relying on per-Pod settings, and ask for the boundary that meets it; know dedicated nodes, the one-way behaviour of taints and tolerations, gVisor versus Kata, RuntimeClass and the overhead trade-off of sandboxes. Image questions separate controls that look alike: minimal bases and multi-stage builds change what the image contains, scanning finds known CVEs and must be repeated, digests pin content while tags move, signatures prove publisher and integrity rather than safety, and private mirrors control the image source. Code questions cover secrets left in layers or build arguments, BuildKit secret mounts, Kubernetes Secrets versus ConfigMaps, SCA and lockfiles for dependencies, SAST for first-party code and a non-root USER in the Dockerfile. Some items are Select TWO.
- Standard containers share the host kernel, so a kernel vulnerability is a risk shared by every workload on the node.
- Namespaces control what a process sees, cgroups control how much it uses; neither gives a container its own kernel.
- A Kubernetes namespace scopes names, RBAC, quotas and policies, but Pods in different namespaces can talk by default and cluster-scoped objects (Nodes, PersistentVolumes, ClusterRoles) sit outside it.
- Taints keep other Pods off a dedicated pool; node affinity or a nodeSelector keeps the sensitive Pods on it. You need both.
- gVisor intercepts system calls in a user-space kernel, Kata Containers runs each Pod in a lightweight VM; select either per Pod with runtimeClassName and apply them selectively because of overhead and compatibility.
- Isolation strength runs from namespace to dedicated nodes to sandboxed runtime to separate clusters on separate VMs; the scenario's cost or trust constraint decides.
- Distroless or scratch bases and multi-stage builds shrink what an image contains; signing and registry controls protect provenance and integrity, not contents.
- Scan in CI and rescan on a schedule, and reference production images by digest so the reviewed build is what runs.
- A signature proves publisher and integrity, not the absence of vulnerabilities; mirror approved images into a private registry to control their source.
- Secrets in a layer, ENV or build argument stay recoverable; use BuildKit secret mounts at build time and Kubernetes Secrets at run time, and set a non-root USER in the image.
Check yourself: 3 questions on this topic
Exam-style KCSA questions on Isolation techniques, artifact and image security, and workload code security, answered right here with an explanation after each. Want more? KCSA Overview of Cloud Native Security practice questions.
Frequently asked questions
Are Kubernetes namespaces a security boundary?
Not on their own. A Kubernetes namespace scopes object names, RBAC, resource quotas and namespaced policies, but Pods in different namespaces share nodes and kernels and can reach each other over the network unless NetworkPolicies restrict them. Cluster-scoped objects such as Nodes and PersistentVolumes are outside every namespace. Namespaces are the base of soft multi-tenancy and need network policies, dedicated nodes or sandboxes added for stronger isolation.
What is the difference between gVisor and Kata Containers?
Both are sandboxed container runtimes that keep a workload from calling the host kernel directly. gVisor runs a user-space application kernel that intercepts and handles the container's system calls. Kata Containers runs each Pod inside a lightweight virtual machine with its own guest kernel. In Kubernetes, either is selected per Pod by setting runtimeClassName to a RuntimeClass whose handler names that runtime.
Why isn't a toleration enough to keep Pods on dedicated nodes?
A toleration only allows a Pod onto nodes with a matching taint; it doesn't require the Pod to go there, so the scheduler can still place it on untainted nodes. The taint keeps other Pods off the dedicated nodes, and a required node affinity rule or nodeSelector on the sensitive Pods keeps them on those nodes. Kubernetes multi-tenancy guidance uses the two together.
Why should a container image be referenced by digest instead of a tag?
An image tag is a movable pointer, so the same name and tag can point to different content after someone pushes a new image. A digest such as image@sha256:... is computed from the image manifest and always resolves to exactly the same content. Referencing by digest guarantees that Pods run the build that was scanned and reviewed.
Does a signed image mean the image is secure?
No. A verified signature, for example with Sigstore cosign, proves the image came from the expected signer and hasn't changed since it was signed. It says nothing about known vulnerabilities, the base image or how the container runs, so a trusted publisher can still ship a vulnerable image. Signing complements image scanning and minimal base images.
Why rescan a container image that hasn't changed?
Because a vulnerability scan only reflects the CVE data that existed when it ran. New vulnerabilities are disclosed every day for packages that images already contain, so an unchanged image that was clean at build time can be vulnerable later. Registries and security teams therefore rescan stored and running images on a schedule as well as scanning in CI.
Is deleting a secret in a later Dockerfile step safe?
No. Each RUN, COPY or ADD instruction creates an immutable layer, so deleting a file in a later step only hides it; the earlier layer still contains it and can be extracted by anyone who can pull the image. Build arguments and ENV values are also unsafe for credentials. Use a BuildKit secret mount for build-time secrets, Kubernetes Secrets for run-time credentials, and rotate any secret that has already leaked.
What is the difference between SAST and SCA?
SAST (static application security testing) analyses your own first-party source code for weaknesses such as injection flaws without running it. SCA (software composition analysis) inventories the third-party open source dependencies an application uses, including transitive ones, and flags known-vulnerable versions. Most pipelines run both, together with image scanning of the built artifact.
Source
This lesson covers the "Overview of Cloud Native Security" domain of the official KCSA exam guide. Vendors revise their guides — check the source for the current version.
- KCSA certification page and curriculum — The Linux Foundation
Sign up free to mark lessons complete, bookmark topics and track your exam readiness.