Network Security Policy
This guide demonstrates how to configure Kyverno to enforce network security policies that control container network access and prevent network-based attacks.
TOC
What is Network Security?Quick Start1. Disallow Host Network Access2. Test the PolicyCore Network Security PoliciesPolicy 1: Disallow Host PortsPolicy 2: Restrict Host Port RangePolicy 3: Require Network PoliciesPolicy 4: Restrict Service TypesPolicy 5: Control Ingress ConfigurationsPolicy 6: Restrict DNS ConfigurationAdvanced ScenariosScenario 1: Environment-Specific Network PoliciesScenario 2: Application-Specific Network PoliciesScenario 3: Network Segmentation EnforcementTesting and ValidationTest Host Network Access (Should Fail)Test Host Port Binding (Should Fail)Test NodePort Service (Should Fail)Test Valid Network Configuration (Should Pass)What is Network Security?
Network security involves controlling how containers access and interact with network resources. Proper network security prevents:
- Host network access: Containers accessing host network interfaces
- Privilege escalation via networking: Using network access to gain elevated permissions
- Port scanning and reconnaissance: Unauthorized network discovery activities
- Lateral movement: Containers accessing unintended network resources
- Data exfiltration: Unauthorized network communications
Quick Start
1. Disallow Host Network Access
2. Test the Policy
Core Network Security Policies
Policy 1: Disallow Host Ports
Prevent containers from binding to host network ports:
Policy 2: Restrict Host Port Range
Allow specific host port ranges for controlled access:
Policy 3: Require Network Policies
Ensure pods have associated NetworkPolicies for traffic control:
Policy 4: Restrict Service Types
Control which service types can be created:
Policy 5: Control Ingress Configurations
Enforce secure Ingress configurations:
Policy 6: Restrict DNS Configuration
Control DNS settings to prevent DNS-based attacks:
Advanced Scenarios
Scenario 1: Environment-Specific Network Policies
Different network restrictions for different environments:
Scenario 2: Application-Specific Network Policies
Different network policies for different application types:
Scenario 3: Network Segmentation Enforcement
Enforce network segmentation between different tiers: