21. What is a Kubernetes manifest, and what security controls can it define?
Define a Kubernetes manifest as YAML or JSON that declares desired API objects. Explain metadata, specifications, namespaces, workloads, services, service accounts, security contexts, resources, secrets, network policies, and admission controls. Connect it to authorized cluster-configuration review and schema validation.
A Kubernetes manifest is YAML or JSON that declares desired Kubernetes API objects. I review metadata and specs for namespaces, workloads, Services, ServiceAccounts, security contexts, resources, Secrets, NetworkPolicies, and admission controls, then validate the schema and, when authorized, verify what the cluster actually enforces.
See the Code while reading this explanation.
A Kubernetes manifest is a YAML or JSON document that declares the desired state of one or more Kubernetes API objects. It normally identifies an API version and object kind, gives metadata such as a name, namespace, labels, or annotations, and supplies the object's specification. For security review, I do more than check whether the file parses. I examine workload identity, privileges, resource controls, secret handling, network access, and admission policy, validate the object against the target Kubernetes API, and separate declared configuration from controls that the cluster actually enforces.
- Am I reviewing manifest files only, or may I compare them with objects deployed in an authorized cluster?
- Which namespaces, workloads, and related policy objects are in scope?
- Should I assess only built-in Kubernetes controls, or also approved admission policies used by the environment?
- Is there an organization-defined Kubernetes security baseline that the manifests must satisfy?
I would start with the manifest structure. apiVersion selects the Kubernetes API group and version used for the object. kind identifies the object type, such as Deployment, Service, ServiceAccount, Secret, or NetworkPolicy. metadata identifies the object and can contain its name, namespace, labels, and annotations. spec normally describes the desired configuration for that object's type.
Namespaces organize namespaced resources and provide a scope for authorization and policy. I check that a workload is placed in the intended namespace and that the expected namespace-level controls apply there. I would not call a namespace a complete security boundary by itself because effective isolation also depends on authorization, admission policy, networking, node security, and other cluster controls.
For workloads such as Pods, Deployments, and Jobs, I inspect the Pod specification or Pod template. A securityContext can constrain how a Pod or container runs. Important examples include requiring a non-root identity, preventing privilege escalation, dropping unnecessary Linux capabilities, using a read-only root filesystem where the application supports it, and applying an appropriate seccomp profile. Some settings are Pod-level and others are container-level, so I check the exact field rather than treating the presence of one securityContext as proof that the workload is hardened.
I also review workload identity. serviceAccountName selects the Kubernetes ServiceAccount used by a Pod. The ServiceAccount provides an identity; authorization controls such as RBAC determine what that identity is permitted to do. If a workload does not need Kubernetes API credentials, disabling automatic ServiceAccount-token mounting can reduce unnecessary credential exposure. I therefore review ServiceAccount selection, token mounting, and the identity's effective authorization separately.
Resource requests and limits describe CPU and memory requirements or constraints. Requests help the scheduler make placement decisions, while limits constrain resource use according to Kubernetes runtime behavior. From a security perspective, reasonable resource controls can reduce the effect of accidental or abusive resource consumption, but they are not a complete denial-of-service defense. I compare them with the environment's workload requirements rather than assuming one fixed value is correct everywhere.
Secrets are Kubernetes API objects used to hold sensitive data. Workload manifests can reference Secrets through mechanisms such as volumes or environment variables. During a penetration-test review, I avoid exposing Secret values unless access is explicitly required and authorized. I look for sensitive values embedded directly in ordinary manifests, unnecessary Secret access, and broad workload permissions. I also remember that the Secret kind by itself does not guarantee complete confidentiality; storage protection, authorization, encryption configuration, and application handling still matter.
A Service provides a stable network endpoint for selected Pods. I review its selectors, ports, and type to understand how the workload can be reached. A Service is not an authorization control by itself. Exposure must be considered together with authentication, authorization, NetworkPolicy, ingress or gateway configuration, and any external infrastructure that is in scope.
A NetworkPolicy can define allowed ingress and egress for selected Pods. I inspect Pod selectors, namespace selectors, IP blocks when present, ports, and policyTypes. A key limitation is that a NetworkPolicy object only produces the intended filtering when the cluster networking implementation supports and enforces Kubernetes NetworkPolicy. Therefore, the manifest shows intended policy, while authorized runtime verification is needed before claiming that traffic is actually blocked or allowed.
Admission controls sit at the Kubernetes API request boundary. Admission controllers can validate or mutate requests before an object is persisted. Kubernetes includes Pod Security Admission, which can apply Pod Security Standards to namespaces through enforce, audit, and warn labels. Kubernetes also supports admission-related API objects such as ValidatingAdmissionPolicy and admission webhook configurations. Some admission behavior, however, comes from API-server configuration rather than an ordinary workload manifest. I therefore identify which admission mechanism is being reviewed and verify that it is active instead of assuming that a policy file automatically controls the cluster.
For an authorized configuration review, I begin read-only. I parse each YAML or JSON document, identify its apiVersion and kind, and validate its fields against the Kubernetes API schema appropriate to the target environment. Schema validation can catch malformed values, unknown fields, unsupported structures, or type errors. It does not prove that a valid object is secure. I then perform semantic checks for excessive privileges, unnecessary ServiceAccount credentials, unsafe Secret handling, unintended Service exposure, missing resource controls, overly broad network access, and weak or missing admission requirements.
If cluster access is explicitly in scope, I compare source manifests with effective deployed objects and relevant policy configuration. Defaults, admission mutation, controllers, deployment tooling, or later configuration changes can make the live object different from the source file. I collect only the evidence needed to support the finding, redact credentials and Secret values, and avoid modifying production resources unless the rules of engagement expressly authorize a controlled change.
The main tradeoff is that static manifest review is safe, repeatable, and useful before deployment, but it cannot prove runtime enforcement. Cluster-side verification gives stronger evidence about effective configuration and policy behavior, but it requires authorized access and greater operational care. I therefore report separately what the manifest declares, what schema validation accepts, what policy intends to require, and what the authorized environment demonstrably enforces.
- Confirm the authorized manifests, namespaces, workloads, policy objects, and any permitted cluster access.
- Parse every YAML or JSON document and identify its apiVersion, kind, metadata, and spec.
- Validate each object against the Kubernetes API schema appropriate to the target environment.
- Review namespace placement and namespace-level policy.
- Inspect workload Pod specifications for security contexts, ServiceAccount selection, token mounting, and resource requests or limits.
- Review Services for unintended exposure.
- Review Secret references without unnecessarily retrieving or displaying Secret values.
- Review NetworkPolicies for intended ingress and egress restrictions and verify that the cluster networking implementation supports enforcement before claiming isolation.
- Review applicable admission controls, including Pod Security Admission or other authorized admission-policy objects.
- When explicitly authorized, compare source manifests with effective deployed objects and active policy configuration.
- Record redacted evidence and distinguish declared configuration from demonstrated enforcement.
This Kubernetes YAML example shows several security-relevant controls in one bounded configuration. The Namespace demonstrates Pod Security Admission labels. The ServiceAccount avoids automatic API-token mounting because the example workload does not require Kubernetes API access. The Deployment uses non-root execution, RuntimeDefault seccomp, blocked privilege escalation, dropped Linux capabilities, a read-only root filesystem, and resource requests and limits. The NetworkPolicy demonstrates a default-deny policy for the selected example Pods. It contains no real credentials or Secret values. Before using similar settings in production, validate the manifest against the target cluster's API and confirm that the application's required traffic and filesystem behavior are compatible.
apiVersion: v1
kind: Namespace
metadata:
name: example
labels:
# Enforce the built-in Restricted Pod Security Standard in this namespace.
pod-security.kubernetes.io/enforce: restricted
# Warn when submitted Pods do not satisfy the same intended level.
pod-security.kubernetes.io/warn: restricted
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: example-app
namespace: example
# This synthetic workload does not need Kubernetes API credentials.
automountServiceAccountToken: false
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: example-app
namespace: example
spec:
replicas: 2
selector:
matchLabels:
app: example-app
template:
metadata:
labels:
app: example-app
spec:
# Use a dedicated workload identity.
serviceAccountName: example-app
# Do not mount an API token when the application does not need one.
automountServiceAccountToken: false
securityContext:
# Require containers in the Pod to run as non-root.
runAsNonRoot: true
# Use the container runtime's default seccomp profile.
seccompProfile:
type: RuntimeDefault
containers:
- name: app
# Synthetic placeholder image; replace only with an approved application image.
image: example.invalid/authorized-demo/app:1.0
securityContext:
# Prevent this process from gaining additional privileges.
allowPrivilegeEscalation: false
# Remove Linux capabilities unless a reviewed application need requires one.
capabilities:
drop:
- ALL
# Make the image filesystem read-only when application behavior permits it.
readOnlyRootFilesystem: true
resources:
# Requests assist scheduling; limits constrain CPU and memory consumption.
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 500m
memory: 256Mi
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: example-app-default-deny
namespace: example
spec:
# Apply the policy only to the example application's Pods.
podSelector:
matchLabels:
app: example-app
# With no allow rules, selected Pods are isolated for both directions
# when the cluster networking implementation enforces NetworkPolicy.
policyTypes:
- Ingress
- EgressThis approach is used in authorized Kubernetes configuration assessments, cloud-native penetration tests, CI/CD security reviews, pre-deployment manifest checks, container-platform reviews, and remediation verification. It is useful when testers need to evaluate workload privilege, identity, secret handling, resource controls, network exposure, and admission policy without starting with intrusive runtime testing.
Interviewers want to know whether the candidate understands Kubernetes declarative configuration and can identify where security-relevant settings are expressed. For a Penetration Tester, the important judgment is recognizing risky configuration while separating desired state in a manifest from admission decisions, authorization, network enforcement, and the effective deployed state.
Common mistakes include calling YAML itself a security control, forgetting that Kubernetes manifests can also be JSON, treating namespaces as complete isolation, and assuming a ServiceAccount automatically has least privilege. Other mistakes are assuming a Secret object is completely protected just because its kind is Secret, treating a Service as an authorization mechanism, or claiming that NetworkPolicy blocks traffic without confirming enforcement by the cluster networking implementation. Testers may also see a valid securityContext and overlook ServiceAccount tokens, resource settings, Service exposure, admission policy, or other container-level and Pod-level fields. Finally, schema-valid configuration can still be insecure, and a secure-looking source manifest may differ from the effective deployed object.
Start with the definition: a manifest is YAML or JSON describing desired Kubernetes API objects. Then group the security review into identity, privilege, resources, secrets, network exposure, and admission. Finish by explaining that schema validation checks structure, while authorized cluster verification is needed to prove effective enforcement.










