Lab 03 — Kyverno
In the previous lab, you controlled:
Who can perform an action?using Kubernetes RBAC.
Now you will control:
What kind of Kubernetes resourceshould be allowed to exist?This lab introduces Kyverno, a Kubernetes-native policy engine used to enforce security and governance rules against Kubernetes resources.
The progression is:
Identity ↓RBAC ↓Permission Granted ↓Resource Submitted ↓Kyverno Policy ↓Allow / Reject / Modify / ReportThis is a major step toward enterprise Kubernetes security.
Mission Information
Section titled “Mission Information”Difficulty: Intermediate
Estimated Time: 90–120 minutes
Primary Skills:
Kubernetes Admission Control
Policy-as-Code
Kyverno
Validation Policies
Workload Guardrails
Security Context Enforcement
Image Governance
Policy Testing
Policy Reporting
Security RemediationLab Scenario
Section titled “Lab Scenario”Your organization operates multiple Kubernetes clusters.
Development teams deploy applications independently, which has resulted in inconsistent workload security.
The platform security team has identified several recurring issues:
Privileged Containers
Containers Running as Root
Missing Resource Limits
Unapproved Container Registries
Missing Required LabelsManual review is no longer scalable.
You have been asked to implement automated policy controls using Kyverno.
Your mission is to create security policies that evaluate Kubernetes workloads before they are accepted into the cluster.
Lab Objectives
Section titled “Lab Objectives”By the end of this lab, you should be able to:
- Explain Kubernetes admission control
- Understand where Kyverno fits in the request lifecycle
- Verify Kyverno installation
- Inspect Kyverno components
- Understand ClusterPolicy and Policy
- Create validation policies
- Test compliant workloads
- Test non-compliant workloads
- Block privileged containers
- Require non-root execution
- Require resource controls
- Enforce image registry standards
- Require application labels
- Understand audit vs enforce behavior
- Review policy results
- Troubleshoot policy failures
- Document policy violations
- Apply policy-as-code thinking
Lab Architecture
Section titled “Lab Architecture”Your security architecture will look like:
Developer ↓kubectl / CI/CD ↓Kubernetes API ↓Authentication ↓RBAC Authorization ↓Admission Request ↓Kyverno ↓Security Policy Evaluation ↓Allow / Deny ↓Kubernetes ResourceWhy Kyverno Matters
Section titled “Why Kyverno Matters”Without policy enforcement:
Developer ↓Creates Insecure Workload ↓Deployment Succeeds ↓Security Team Finds It LaterWith preventive policy enforcement:
Developer ↓Creates Insecure Workload ↓Kyverno Evaluates It ↓Deployment RejectedThis shifts security from:
Detect Laterto:
Prevent EarlierBefore You Start
Section titled “Before You Start”You need:
Authorized Kubernetes Training Cluster
kubectl
Kyverno Installed
Permission to Create a Lab Namespace
Permission to Create PoliciesFor cluster-wide policy exercises, you may require permissions to create:
ClusterPolicyIf you do not have cluster-scoped permissions, perform equivalent namespace-scoped exercises with Policy where practical.
Lab Safety Rules
Section titled “Lab Safety Rules”Perform this lab only in:
Your Own Cluster
Training Environment
Explicitly Authorized Kubernetes EnvironmentDo not apply new admission policies directly to production without:
Testing
Change Approval
Impact Analysis
Rollback PlanningA badly designed admission policy can prevent legitimate workloads from deploying.
Part 01 — Understand Admission Control
Section titled “Part 01 — Understand Admission Control”A Kubernetes API request typically passes through several security stages.
Conceptually:
API Request ↓Authentication ↓Authorization ↓Admission Control ↓Resource StoredAuthentication asks:
Who are you?RBAC asks:
Are you allowed to create this resource?Admission control asks:
Should this resource configurationbe accepted?Example
Section titled “Example”A developer may legitimately have:
create podspermission.
But they attempt to create:
Privileged PodRBAC may say:
AllowedKyverno can still say:
Rejectedbecause the configuration violates security policy.
Security Architecture
Section titled “Security Architecture”Identity Control +Configuration Control ↓Stronger SecurityPart 02 — Kyverno Capabilities
Section titled “Part 02 — Kyverno Capabilities”Kyverno can support capabilities such as:
Validate
Mutate
Generate
Verify Images
Report Policy ResultsThis lab focuses mainly on:
Validationbecause it directly demonstrates security guardrails.
Validate
Section titled “Validate”Validation checks whether a resource complies with policy.
Example:
Container Privileged? ↓Yes ↓RejectMutate
Section titled “Mutate”Mutation can automatically modify resources.
Conceptually:
Missing Standard Configuration ↓Kyverno Adds ConfigurationGenerate
Section titled “Generate”Kyverno can generate supporting Kubernetes resources based on policy.
Image Verification
Section titled “Image Verification”Kyverno can also participate in container supply-chain controls by enforcing image-related policies.
Part 03 — Verify Cluster Access
Section titled “Part 03 — Verify Cluster Access”Check:
kubectl config current-contextThen:
kubectl cluster-infoAlways verify:
Cluster
Context
Environmentbefore applying admission policies.
Part 04 — Verify Kyverno Installation
Section titled “Part 04 — Verify Kyverno Installation”Check Kyverno namespace resources.
A common installation uses:
kubectl get pods -n kyvernoYou may see several Kyverno components depending on version and deployment architecture.
Also inspect:
kubectl get deployments -n kyvernoWhat You Are Validating
Section titled “What You Are Validating”Confirm:
Kyverno Components Exist
Pods Are Healthy
Controllers Are AvailableIf Kyverno Is Not Installed
Section titled “If Kyverno Is Not Installed”Use the installation procedure approved for your training environment.
Do not blindly apply external installation manifests to enterprise clusters.
Your organization may manage Kyverno through:
Helm
GitOps
Platform Automation
Cluster Add-On ManagementPart 05 — Inspect Kyverno Policy Resources
Section titled “Part 05 — Inspect Kyverno Policy Resources”Run:
kubectl api-resources | grep -i kyvernoDepending on the installed version, you may see resources related to:
Policy
ClusterPolicy
PolicyReport
ClusterPolicyReportPolicy vs ClusterPolicy
Section titled “Policy vs ClusterPolicy”A namespace Policy applies within a namespace context.
Conceptually:
Policy ↓NamespaceA ClusterPolicy can apply across the cluster depending on its matching rules.
Conceptually:
ClusterPolicy ↓Multiple Namespaces / Cluster ScopeSecurity Principle
Section titled “Security Principle”Start with the smallest practical scope.
Do not begin with:
Apply Everything Everywherewhen:
One Training Namespaceis sufficient for testing.
Part 06 — Create the Lab Namespace
Section titled “Part 06 — Create the Lab Namespace”Create:
kubectl create namespace ghc-kyverno-labVerify:
kubectl get namespace ghc-kyverno-labSet it as your current namespace if desired:
kubectl config set-context --current --namespace=ghc-kyverno-labPart 07 — Create a Baseline Workload
Section titled “Part 07 — Create a Baseline Workload”Create:
baseline-deployment.yamlAdd:
apiVersion: apps/v1kind: Deploymentmetadata: name: baseline-app namespace: ghc-kyverno-lab labels: app: baseline-appspec: replicas: 1 selector: matchLabels: app: baseline-app template: metadata: labels: app: baseline-app spec: containers: - name: web image: nginxApply:
kubectl apply -f baseline-deployment.yamlVerify:
kubectl get deploymentskubectl get podsSecurity Review
Section titled “Security Review”The workload works.
But ask:
Does it run as root?
Does it define resource limits?
Is the image source approved?
Does it use strong security settings?This is the difference between:
Operationally Functionaland:
Security CompliantPart 08 — Policy 01: Require Application Labels
Section titled “Part 08 — Policy 01: Require Application Labels”Organizations often require metadata for:
Ownership
Cost Allocation
Monitoring
Incident Response
ComplianceYou will require:
owneron Deployments in the lab namespace.
Create:
require-owner-label.yamlAdd:
apiVersion: kyverno.io/v1kind: Policymetadata: name: require-owner-label namespace: ghc-kyverno-labspec: validationFailureAction: Enforce background: true rules: - name: require-owner-label match: any: - resources: kinds: - Deployment validate: message: "Deployments must include the owner label." pattern: metadata: labels: owner: "?*"Apply:
kubectl apply -f require-owner-label.yamlWhat This Policy Means
Section titled “What This Policy Means”Conceptually:
New Deployment ↓Does metadata.labels.owner exist? ↓Yes → AllowNo → RejectPart 09 — Test the Label Policy
Section titled “Part 09 — Test the Label Policy”Create:
bad-label-app.yamlAdd:
apiVersion: apps/v1kind: Deploymentmetadata: name: bad-label-app namespace: ghc-kyverno-labspec: replicas: 1 selector: matchLabels: app: bad-label-app template: metadata: labels: app: bad-label-app spec: containers: - name: web image: nginxTry:
kubectl apply -f bad-label-app.yamlThe deployment should be rejected when the policy is operating in enforce mode.
Security Lesson
Section titled “Security Lesson”The user may have valid:
create deploymentpermission.
But policy prevents deployment because:
Required Governance MetadataIs MissingPart 10 — Correct the Workload
Section titled “Part 10 — Correct the Workload”Modify the metadata:
metadata: name: good-label-app namespace: ghc-kyverno-lab labels: owner: platform-teamEnsure the Deployment selector and Pod labels remain valid.
Apply again.
The compliant workload should now pass.
Validation Principle
Section titled “Validation Principle”Always test:
Negative Case +Positive CaseA policy is incomplete if you only confirm that it blocks something.
You must also confirm legitimate workloads succeed.
Part 11 — Policy 02: Block Privileged Containers
Section titled “Part 11 — Policy 02: Block Privileged Containers”Privileged containers can significantly weaken container isolation.
Attack path:
Application Vulnerability ↓Container Compromise ↓Privileged Container ↓Potential Host ImpactCreate:
disallow-privileged.yamlAdd:
apiVersion: kyverno.io/v1kind: Policymetadata: name: disallow-privileged namespace: ghc-kyverno-labspec: validationFailureAction: Enforce background: true rules: - name: block-privileged-containers match: any: - resources: kinds: - Pod validate: message: "Privileged containers are not permitted." pattern: spec: containers: - securityContext: privileged: "false"Apply:
kubectl apply -f disallow-privileged.yamlImportant
Section titled “Important”Policy syntax and behavior can vary based on the Kyverno version and the exact resource structure being evaluated.
Treat the lab YAML as a learning pattern and validate it against the Kyverno version deployed in your training environment.
Part 12 — Test a Privileged Pod
Section titled “Part 12 — Test a Privileged Pod”Create:
privileged-pod.yamlAdd:
apiVersion: v1kind: Podmetadata: name: privileged-test namespace: ghc-kyverno-labspec: containers: - name: test image: nginx securityContext: privileged: trueApply:
kubectl apply -f privileged-pod.yamlExpected result:
Rejected by PolicySecurity Milestone
Section titled “Security Milestone”You have now moved from:
Security Recommendation:Do Not Use Privileged Containersto:
Security Enforcement:Privileged Containers Cannot Be CreatedPart 13 — Create a Compliant Pod
Section titled “Part 13 — Create a Compliant Pod”Create:
restricted-pod.yamlAdd:
apiVersion: v1kind: Podmetadata: name: restricted-test namespace: ghc-kyverno-labspec: containers: - name: web image: nginx securityContext: privileged: falseApply:
kubectl apply -f restricted-pod.yamlValidate:
kubectl get podsPart 14 — Policy 03: Require Non-Root Workloads
Section titled “Part 14 — Policy 03: Require Non-Root Workloads”Running applications as unnecessary root increases risk.
Desired:
Application ↓Non-Root UserInstead of:
Application ↓RootCreate:
require-non-root.yamlAdd:
apiVersion: kyverno.io/v1kind: Policymetadata: name: require-non-root namespace: ghc-kyverno-labspec: validationFailureAction: Enforce background: true rules: - name: require-run-as-non-root match: any: - resources: kinds: - Pod validate: message: "Pods must require non-root execution." pattern: spec: securityContext: runAsNonRoot: trueApply:
kubectl apply -f require-non-root.yamlPolicy Logic
Section titled “Policy Logic”Pod Submitted ↓runAsNonRoot = true? ↓Yes → Allow
No → RejectPart 15 — Test the Non-Root Policy
Section titled “Part 15 — Test the Non-Root Policy”Create:
missing-nonroot.yamlAdd:
apiVersion: v1kind: Podmetadata: name: missing-nonroot namespace: ghc-kyverno-labspec: containers: - name: web image: nginxTry:
kubectl apply -f missing-nonroot.yamlThe policy should reject the workload if it does not meet the required structure.
Fix the Workload
Section titled “Fix the Workload”Update:
apiVersion: v1kind: Podmetadata: name: nonroot-app namespace: ghc-kyverno-labspec: securityContext: runAsNonRoot: true containers: - name: web image: nginx securityContext: privileged: falseImportant Application Reality
Section titled “Important Application Reality”A policy-compliant configuration may expose an application compatibility problem.
Some container images may expect to run as root.
This is useful security feedback.
The solution is not necessarily:
Disable the PolicyInstead ask:
Can We Use a Better Image?
Can We Configure the App Correctly?
Does the Workload Truly Need Root?Part 16 — Security vs Availability
Section titled “Part 16 — Security vs Availability”Policy engineering must balance:
Security +Application RequirementsAn overly strict policy applied without testing can:
Block Legitimate Workload ↓Deployment Failure ↓Business ImpactThis is why enterprise policy rollout often uses stages.
Part 17 — Audit vs Enforce
Section titled “Part 17 — Audit vs Enforce”A useful rollout model is:
Audit ↓Observe Violations ↓Understand Impact ↓Remediate Workloads ↓EnforceThis is safer than immediately blocking everything.
Audit Mode Concept
Section titled “Audit Mode Concept”Audit-style behavior allows teams to discover:
Which Existing WorkloadsWould Violate the Policy?before enforcement.
Enforce Mode Concept
Section titled “Enforce Mode Concept”Enforce prevents non-compliant resources from being accepted.
Use:
Audit for Discovery
Enforce for Preventionaccording to change-management requirements.
Part 18 — Policy 04: Require Resource Requests and Limits
Section titled “Part 18 — Policy 04: Require Resource Requests and Limits”Resource governance contributes to:
Availability
Scheduling Reliability
Multi-Tenant StabilityWorkloads without resource controls may contribute to:
Resource Exhaustion
Node Pressure
Application InstabilityCreate:
require-resources.yamlAdd:
apiVersion: kyverno.io/v1kind: Policymetadata: name: require-resources namespace: ghc-kyverno-labspec: validationFailureAction: Enforce background: true rules: - name: require-container-resources match: any: - resources: kinds: - Pod validate: message: "CPU and memory requests and limits are required." pattern: spec: containers: - resources: requests: cpu: "?*" memory: "?*" limits: cpu: "?*" memory: "?*"Apply:
kubectl apply -f require-resources.yamlPart 19 — Test Missing Resource Controls
Section titled “Part 19 — Test Missing Resource Controls”Create a workload without resources.
Attempt deployment.
It should be rejected if the policy applies.
Then update the container:
resources: requests: cpu: "100m" memory: "64Mi" limits: cpu: "250m" memory: "128Mi"Security Connection
Section titled “Security Connection”Resource controls support:
Availabilityby reducing the risk of uncontrolled workload consumption.
Part 20 — Build a Fully Compliant Pod
Section titled “Part 20 — Build a Fully Compliant Pod”Create:
compliant-pod.yamlUse:
apiVersion: v1kind: Podmetadata: name: compliant-app namespace: ghc-kyverno-lab labels: owner: platform-teamspec: securityContext: runAsNonRoot: true containers: - name: web image: nginx securityContext: privileged: false resources: requests: cpu: "100m" memory: "64Mi" limits: cpu: "250m" memory: "128Mi"Apply:
kubectl apply -f compliant-pod.yamlDepending on the container image and runtime behavior, you may need to use an image compatible with non-root execution.
Policy Stack
Section titled “Policy Stack”Your workload now has to satisfy:
Non-Privileged +Non-Root +Resource ControlsThis demonstrates how multiple policy controls create:
Defense in DepthPart 21 — Policy 05: Image Registry Governance
Section titled “Part 21 — Policy 05: Image Registry Governance”Organizations may want workloads to use images from approved registries.
Why?
Because:
Unknown Image Source ↓Unknown Supply Chain ↓Higher Security RiskA desired model may be:
Approved Registry ↓Validated Images ↓Production ClusterTraining Example
Section titled “Training Example”For learning purposes, imagine your organization allows images only from:
registry.example.internalDo not expect this example registry to contain usable images.
The goal is to understand the policy pattern.
Policy Concept
Section titled “Policy Concept”Container Image ↓Approved Registry? ↓Yes → Allow
No → RejectPart 22 — Registry Policy Example
Section titled “Part 22 — Registry Policy Example”A Kyverno policy can validate image references using pattern matching.
Conceptually:
validate: message: "Images must come from the approved registry." pattern: spec: containers: - image: "registry.example.internal/*"Important
Section titled “Important”For real implementation, validate the policy syntax against your deployed Kyverno version and your organization’s image naming convention.
Registry policy design needs to consider:
Init Containers
Ephemeral Containers
Mirrors
Digests
Approved ExceptionsPart 23 — Why Registry Policies Matter
Section titled “Part 23 — Why Registry Policies Matter”Without control:
Developer ↓Random Public Image ↓ProductionPotential risks include:
Malware
Typosquatting
Compromised Image
Unpatched Packages
Unverified PublisherRegistry restrictions can reduce this attack surface.
Part 24 — Image Tag Security
Section titled “Part 24 — Image Tag Security”Consider:
nginx:latestversus:
Explicit Versionor immutable image identifiers.
Mutable tags can create uncertainty:
Same Manifest ↓Different Image LaterAn enterprise policy may restrict:
latestto improve deployment consistency.
Part 25 — Policy 06: Disallow Latest Tag
Section titled “Part 25 — Policy 06: Disallow Latest Tag”Conceptual policy objective:
IF image ends with :latestTHEN rejectThis supports:
Version Control
Repeatability
Change TraceabilityPart 26 — Policy Exception Thinking
Section titled “Part 26 — Policy Exception Thinking”Sometimes a workload legitimately requires an exception.
The wrong approach is:
Disable Security EverywhereThe better approach is:
Specific Exception ↓Documented Reason ↓Limited Scope ↓Approval ↓Expiration / ReviewException Governance
Section titled “Exception Governance”Record:
Policy
Workload
Namespace
Business Owner
Justification
Compensating Controls
Review DatePart 27 — Policy Layering
Section titled “Part 27 — Policy Layering”You can now visualize:
RBAC ↓Can developer create Pod? ↓Yes ↓Kyverno ↓Is Pod compliant? ↓Yes ↓Create PodThis is stronger than either control alone.
Part 28 — Test Multiple Violations
Section titled “Part 28 — Test Multiple Violations”Create an intentionally non-compliant Pod that has:
No Owner Label
Privileged Container
No Non-Root Setting
No Resource ControlsSubmit it.
Observe which policy violations are reported.
Security Lesson
Section titled “Security Lesson”One workload may violate:
Multiple Security ControlsA mature security platform should report them clearly enough for the developer to remediate.
Part 29 — Developer Experience
Section titled “Part 29 — Developer Experience”Security policy messages matter.
Bad message:
Request DeniedBetter:
Privileged containers are not permitted.Set securityContext.privileged to false.Good policy design should help users understand:
What Failed
Why
How to Fix ItPart 30 — Inspect Policies
Section titled “Part 30 — Inspect Policies”Run:
kubectl get policiesInspect a policy:
kubectl describe policy require-non-rootYou can also inspect YAML:
kubectl get policy require-non-root -o yamlReview
Section titled “Review”Identify:
Policy Name
Rules
Matched Resources
Validation Logic
Failure ActionPart 31 — Review Policy Reports
Section titled “Part 31 — Review Policy Reports”If policy reporting resources are available in your installed Kyverno environment, inspect them.
Examples may include:
kubectl get policyreportsand cluster-level reporting where permitted.
The exact resource behavior depends on the installed Kyverno version and configuration.
Policy Reports Help Answer
Section titled “Policy Reports Help Answer”Which Resource Failed?
Which Policy?
Which Rule?
What Was the Result?Security Operations Connection
Section titled “Security Operations Connection”Policy reports can contribute to:
Compliance Monitoring
Security Dashboards
Developer Feedback
Risk TrackingPart 32 — Policy Enforcement vs Detection
Section titled “Part 32 — Policy Enforcement vs Detection”Policy enforcement provides:
Preventive ControlRuntime security provides:
Detective ControlExample:
Kyverno ↓Blocks Privileged Podversus:
Runtime Security ↓Detects Suspicious ShellStrong Kubernetes security uses both.
Part 33 — Policy and Compliance
Section titled “Part 33 — Policy and Compliance”A compliance requirement may state:
Containers must not run with excessive privileges.Translate that into:
Control Requirement ↓Kyverno Policy ↓Automated Evaluation ↓EvidenceThis converts policy-as-code into compliance evidence.
Part 34 — Control Mapping Example
Section titled “Part 34 — Control Mapping Example”| Security Requirement | Kyverno Control |
|---|---|
| Containers must not be privileged | Validation policy |
| Workloads must run as non-root | Validation policy |
| Resources must be defined | Validation policy |
| Approved images only | Image policy |
| Required ownership metadata | Label validation |
Part 35 — Enterprise Policy Workflow
Section titled “Part 35 — Enterprise Policy Workflow”A professional rollout may follow:
Identify Risk ↓Define Security Requirement ↓Write Policy ↓Test in Lab ↓Run in Audit ↓Review Violations ↓Remediate Workloads ↓Enforce ↓MonitorPart 36 — Policy Testing Strategy
Section titled “Part 36 — Policy Testing Strategy”Always test:
Expected Pass
Expected Fail
Boundary Condition
Exception
Existing Workload ImpactExample
Section titled “Example”Policy:
Containers Must Not Be PrivilegedTests:
privileged: true ↓Reject
privileged: false ↓AllowAlso test:
securityContext missingto verify the policy behaves as intended.
Part 37 — Avoid Weak Policies
Section titled “Part 37 — Avoid Weak Policies”A policy that only checks one specific YAML shape may be bypassed by another workload structure.
For example, enterprise policy design may need to consider:
Containers
Init Containers
Ephemeral ContainersThis is why security policies should be:
Reviewed
Tested
Version ControlledPart 38 — Avoid Overly Broad Policies
Section titled “Part 38 — Avoid Overly Broad Policies”A poorly scoped policy could accidentally affect:
System Namespaces
Platform Controllers
Security AgentsUse:
Match
Exclude
Namespace Scope
Exception Processcarefully.
Part 39 — System Namespace Protection
Section titled “Part 39 — System Namespace Protection”Be especially cautious before applying experimental policies to:
kube-system
kyverno
Monitoring Namespaces
CNI NamespacesPlatform components may have legitimate security requirements different from ordinary application workloads.
Part 40 — Policy Failure Troubleshooting
Section titled “Part 40 — Policy Failure Troubleshooting”If an expected policy does not block a resource, check:
Is Kyverno Healthy?
Is the Policy Created?
Is the Correct Namespace Used?
Does Match Select the Resource?
Is the Resource Kind Correct?
Is the Pattern Correct?
Is the Failure Mode Enforcing?
Is There an Exclusion?Troubleshooting Flow
Section titled “Troubleshooting Flow”Policy Not Working ↓Check Policy Exists ↓Check Policy Status ↓Check Matching ↓Check Rule ↓Check Kyverno Logs ↓RetestPart 41 — Kyverno Logs
Section titled “Part 41 — Kyverno Logs”If your permissions allow, inspect Kyverno component logs using the deployment or Pod names in your environment.
First identify components:
kubectl get pods -n kyvernoThen use:
kubectl logs -n kyverno <kyverno-pod-name>Do not assume a fixed Pod name.
Logs May Help Identify
Section titled “Logs May Help Identify”Policy Processing Errors
Admission Issues
Configuration Errors
Controller ProblemsPart 42 — Policy Status
Section titled “Part 42 — Policy Status”Inspect:
kubectl get policy <policy-name> -o yamlReview status-related information exposed by your Kyverno version.
A policy file that exists is not enough.
Confirm:
Policy Is Accepted
Policy Is Active
Policy Matches Intended ResourcesPart 43 — Controlled Policy Failure Exercise
Section titled “Part 43 — Controlled Policy Failure Exercise”Create a safe policy with an incorrect match target.
For example:
Policy Matches:ConfigMap
But You Test:PodObserve that:
Pod Is Not Evaluated by That RuleThen correct the match.
Lesson
Section titled “Lesson”Security policy effectiveness depends on:
Correct Requirement +Correct Policy Logic +Correct ScopePart 44 — Security Finding Exercise
Section titled “Part 44 — Security Finding Exercise”Document a workload violation.
Example:
Finding:Privileged Container Deployment Attempt
Affected Resource:privileged-test
Namespace:ghc-kyverno-lab
Security Control:disallow-privileged
Evidence:Kyverno rejected the Pod becausesecurityContext.privileged was set to true.
Risk:High
Threat Scenario:If the workload were compromised,privileged container access could increasethe potential impact on the Kubernetes node.
Recommendation:Run the application without privileged modeand grant only the minimum required capabilities.Part 45 — Policy Finding Template
Section titled “Part 45 — Policy Finding Template”Use:
Finding:
Policy:
Rule:
Affected Resource:
Namespace:
Observed Configuration:
Expected Configuration:
Evidence:
Security Impact:
Risk:
Recommendation:
Validation:Part 46 — Remediation Validation
Section titled “Part 46 — Remediation Validation”Suppose:
Before:privileged = truePolicy result:
RejectedDeveloper remediates:
privileged = falseNow validate:
Deployment Accepted +Application FunctionalImportant Principle
Section titled “Important Principle”Successful security remediation requires:
Security Compliance +Operational FunctionalityPart 47 — Policy Evidence Collection
Section titled “Part 47 — Policy Evidence Collection”Capture:
Kyverno Components
Lab Namespace
Policy List
Require Label Policy
Privileged Container Policy
Non-Root Policy
Resource Policy
Rejected Workload
Compliant Workload
Policy Result
Remediation ValidationLab Evidence Template
Section titled “Lab Evidence Template”Lab:Kyverno Policy Enforcement
Date:
Cluster:
Namespace:
Policy 01:Require Owner Label
Test Result:
Policy 02:Disallow Privileged Containers
Test Result:
Policy 03:Require Non-Root
Test Result:
Policy 04:Require Resource Controls
Test Result:
Security Finding:
Remediation:
Validation:Part 48 — Policy Security Assessment
Section titled “Part 48 — Policy Security Assessment”Review all policies and ask:
What Risk Does This Policy Address?
Which Resources Does It Match?
Which Namespaces?
What Is Excluded?
Does It Prevent the Risk?
Could It Break Legitimate Workloads?
How Is Compliance Measured?Part 49 — Policy Risk Model
Section titled “Part 49 — Policy Risk Model”Think:
Security Requirement ↓Policy Logic ↓Resource Match ↓Enforcement ↓Security OutcomeWeakness at any step reduces effectiveness.
Part 50 — Kyverno and RBAC Together
Section titled “Part 50 — Kyverno and RBAC Together”You now have two important Kubernetes controls.
RBAC:
WHOcan perform the request?Kyverno:
WHATresource configuration is acceptable?Together:
Identity ↓Authorization ↓Policy Validation ↓Secure ResourcePart 51 — Kyverno and NetworkPolicy
Section titled “Part 51 — Kyverno and NetworkPolicy”Kyverno can also enforce that teams follow networking standards.
For example, an organization may require:
Production Namespace ↓NetworkPolicy PresentNetworkPolicy defines:
Allowed CommunicationKyverno can help enforce:
Required Security ConfigurationPart 52 — Kyverno and Supply Chain
Section titled “Part 52 — Kyverno and Supply Chain”Kyverno policies can support image governance.
Security model:
Source ↓Build ↓Image ↓Registry ↓Image Policy ↓KubernetesThis can help enforce:
Trusted Registries
Approved Image Patterns
Image Verification RequirementsPart 53 — Kyverno and DevSecOps
Section titled “Part 53 — Kyverno and DevSecOps”Policy-as-code fits naturally into DevSecOps.
Developer ↓Manifest ↓CI Validation ↓Git ↓Deployment ↓Kyverno AdmissionInstead of security being:
Final Manual Reviewsecurity becomes:
Continuous GuardrailPart 54 — Policy Repository
Section titled “Part 54 — Policy Repository”In an enterprise environment, policies should be treated like code.
Store them in:
Version ControlReview changes through:
Pull Requests
Peer Review
Security Review
TestingPolicy Lifecycle
Section titled “Policy Lifecycle”Create ↓Test ↓Review ↓Approve ↓Deploy ↓Monitor ↓ImprovePart 55 — Policy Naming
Section titled “Part 55 — Policy Naming”Use clear names.
Good:
disallow-privileged-containers
require-non-root
require-resource-limitsPoor:
policy1
security-rule
testClear naming helps:
Operations
Audit
Troubleshooting
CompliancePart 56 — Policy Messages
Section titled “Part 56 — Policy Messages”Use messages that explain remediation.
Example:
Privileged containers are prohibited.Set securityContext.privileged to false.Instead of:
Denied.Part 57 — Exception Management
Section titled “Part 57 — Exception Management”If a policy exception is needed, capture:
Who Requested It?
Why?
Which Resource?
Which Namespace?
Which Policy?
What Compensating Control?
When Does It Expire?Exceptions should not become permanent security bypasses without review.
Part 58 — Policy Metrics
Section titled “Part 58 — Policy Metrics”A mature policy program may track:
Number of Policies
Violations
Blocked Deployments
Audit Findings
Exceptions
Remediation TimeSecurity Operations Value
Section titled “Security Operations Value”This helps answer:
Are Developers Becoming More Compliant?
Which Policies Cause Most Failures?
Where Is Security Debt Increasing?Part 59 — Lab Challenge 01
Section titled “Part 59 — Lab Challenge 01”Create a policy requirement:
Every Deploymentmust contain:environmentlabelUse acceptable values such as:
dev
test
productionTest:
Missing Label → Reject
Valid Label → AllowPart 60 — Lab Challenge 02
Section titled “Part 60 — Lab Challenge 02”Design a policy that conceptually requires:
readOnlyRootFilesystem: truefor appropriate application containers.
Before enforcing it broadly, consider:
Which Applications Require Writable Paths?
Should Writable Paths Use Volumes?
Which Exceptions Are Required?Part 61 — Lab Challenge 03
Section titled “Part 61 — Lab Challenge 03”Design an image policy for:
Approved Registry OnlyDocument:
Allowed Pattern
Blocked Pattern
Business Justification
Exception ProcessPart 62 — Lab Challenge 04
Section titled “Part 62 — Lab Challenge 04”Create a policy rollout plan for production.
Use:
Stage 1Develop Policy
Stage 2Test in Lab
Stage 3Audit in Development
Stage 4Audit in Production
Stage 5Remediate Violations
Stage 6Enforce
Stage 7MonitorPart 63 — Lab Challenge 05
Section titled “Part 63 — Lab Challenge 05”Map each control to a threat.
| Policy | Threat Reduced |
|---|---|
| Disallow privileged | Host-level impact |
| Require non-root | Excessive container privilege |
| Resource controls | Resource exhaustion |
| Approved registry | Untrusted software supply chain |
| Required labels | Poor ownership/governance |
Part 64 — Cleanup Strategy
Section titled “Part 64 — Cleanup Strategy”Before deleting everything, capture your lab evidence.
List:
kubectl get policies -n ghc-kyverno-labList resources:
kubectl get all -n ghc-kyverno-labThen remove the training namespace:
kubectl delete namespace ghc-kyverno-labNamespace-scoped Policies and workloads inside it will be removed.
If You Created ClusterPolicies
Section titled “If You Created ClusterPolicies”Delete only ClusterPolicies created specifically for this lab.
Example:
kubectl delete clusterpolicy <lab-policy-name>Do not remove:
Production Policies
Platform Policies
Kyverno System ComponentsRestore Namespace Context
Section titled “Restore Namespace Context”If you changed the active namespace:
kubectl config set-context --current --namespace=defaultVerify:
kubectl config view --minifyLab Completion Checklist
Section titled “Lab Completion Checklist”Kyverno
Section titled “Kyverno”- Verified Kyverno availability
- Inspected Kyverno resources
- Understood Policy vs ClusterPolicy
- Understood admission control
Policy Creation
Section titled “Policy Creation”- Created label validation policy
- Created privileged-container policy
- Created non-root policy
- Created resource-control policy
- Understood registry policy concepts
Testing
Section titled “Testing”- Tested non-compliant workload
- Observed policy rejection
- Created compliant workload
- Verified successful deployment
- Tested positive and negative cases
Policy Operations
Section titled “Policy Operations”- Inspected Policies
- Reviewed policy results
- Understood audit vs enforce
- Troubleshot policy matching
- Understood exception requirements
Security
Section titled “Security”- Identified privileged workload risk
- Identified root execution risk
- Identified image supply-chain risk
- Identified resource exhaustion risk
- Documented policy violation
Enterprise Skills
Section titled “Enterprise Skills”- Mapped requirements to policy
- Understood staged enforcement
- Understood policy version control
- Understood exception governance
- Understood policy metrics
Skills You Practiced
Section titled “Skills You Practiced”You have now worked with:
Admission Control
Kyverno
Policy-as-Code
Kubernetes Policies
Validation
Security Guardrails
Workload Hardening
Image Governance
Resource Governance
Compliance Evidence
Policy TroubleshootingCareer Connection
Section titled “Career Connection”These skills are valuable for:
Kubernetes Security Engineer
Platform Security Engineer
DevSecOps Engineer
Cloud Security Engineer
Cloud Security Architect
Platform Engineer
Security ConsultantKyverno skills are especially valuable in environments where teams need:
Self-Service Kubernetes +Central Security GovernanceInterview Questions
Section titled “Interview Questions”- What is Kubernetes admission control?
- Where does admission control occur in the API request lifecycle?
- What is Kyverno?
- Why is Kyverno considered Kubernetes-native?
- What is policy-as-code?
- What is a Kyverno Policy?
- What is a ClusterPolicy?
- What is the difference between Policy and ClusterPolicy?
- How is RBAC different from Kyverno?
- Can a user with Pod creation permission still be blocked by Kyverno?
- What does validation do?
- What is mutation?
- What is resource generation?
- Why would you block privileged containers?
- Why should workloads run as non-root where possible?
- Why are resource requests and limits security-relevant?
- Why should organizations restrict container registries?
- What risk does the
latestimage tag create? - What is an admission policy violation?
- What is the difference between audit and enforce?
- Why might an organization deploy policy in audit mode first?
- Why should policies have clear failure messages?
- Why should you test both compliant and non-compliant workloads?
- What could happen if a policy is scoped incorrectly?
- Why should system namespaces be treated carefully?
- How would you troubleshoot a policy that is not matching workloads?
- Why should Kyverno policies be stored in version control?
- What is a policy exception?
- Why should exceptions have review dates?
- How does Kyverno support compliance?
- How does Kyverno support DevSecOps?
- How can Kyverno contribute to software supply-chain security?
- What is an approved image registry?
- How can policy prevent insecure workload configuration?
- How do RBAC and admission policy complement each other?
- How do Kyverno and NetworkPolicy complement each other?
- Why is policy testing important?
- What is defense in depth?
- How would you introduce a new security policy into production safely?
- How would you measure whether a Kubernetes policy program is effective?
Practical Readiness Milestone
Section titled “Practical Readiness Milestone”You should now be able to receive a security requirement such as:
Production containersmust not run privileged.and translate it into:
Security Requirement ↓Kyverno Policy ↓Resource Match ↓Validation Rule ↓Violation Message ↓Enforcement ↓TestingThen validate:
Privileged Workload ↓Rejectedand:
Compliant Workload ↓AllowedSecurity Readiness Milestone
Section titled “Security Readiness Milestone”You should also understand the difference between:
RBAC:Can the developer deploy?and:
Kyverno:Is the deployment secure enoughto be accepted?Together:
IDENTITY ↓AUTHORIZATION ↓POLICY ↓SECURE CONFIGURATIONFinal Lab Mental Model
Section titled “Final Lab Mental Model”Remember:
SECURITY REQUIREMENT ↓POLICY-AS-CODE ↓ADMISSION CONTROL ↓RESOURCE VALIDATION ↓ALLOW / DENY ↓COMPLIANT KUBERNETESThe goal is not to write policies simply because policy engines exist.
The goal is to turn:
Security Standardsinto:
Automated,Repeatable,EnforceableGuardrails.Lab Outcome
Section titled “Lab Outcome”Before this lab:
You understood that Kubernetes workloadsshould follow security standards.After this lab:
You translated standards into policies,
tested secure and insecure workloads,
blocked unsafe configurations,
validated compliant resources,
reviewed policy results,
and practiced policy governance.You have moved from:
Security Recommendationto:
Automated Security Enforcement.What’s Next?
Section titled “What’s Next?”➡️ Lab 04 — Network Policies
In the next lab, you will move from:
Can This Workload Be Deployed?to:
Who Can This WorkloadCommunicate With?You will build practical Kubernetes network segmentation using:
Pod Communication
Ingress Rules
Egress Rules
Namespace Segmentation
Default-Deny
Application Allow Rules
Lateral Movement ReductionThe lab progression becomes:
Lab 01 — Kubernetes Fundamentals ↓Understand Resources
Lab 02 — Kubernetes RBAC ↓Control Identity
Lab 03 — Kyverno ↓Control Configuration
Lab 04 — Network Policies ↓Control CommunicationYou are now building Kubernetes security layer by layer.