Ingress controllers are your cluster’s front door to the internet. Securing them properly is critical to protecting your applications from external threats.
Ingress Security Fundamentals
TLS Configuration
Always use TLS with strong settings:
YAML
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: secure-ingress
annotations:
nginx.ingress.kubernetes.io/ssl-redirect: "true"
nginx.ingress.kubernetes.io/ssl-protocols: "TLSv1.3"
spec:
tls:
- hosts:
- app.example.com
secretName: app-tls
rules:
- host: app.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: app
port:
number: 80Rate Limiting
Protect against brute force and DoS:
YAML
metadata:
annotations:
nginx.ingress.kubernetes.io/limit-rps: "10"
nginx.ingress.kubernetes.io/limit-connections: "5"
nginx.ingress.kubernetes.io/limit-rpm: "100"Security Headers
YAML
metadata:
annotations:
nginx.ingress.kubernetes.io/configuration-snippet: |
add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";
add_header X-XSS-Protection "1; mode=block";
add_header Content-Security-Policy "default-src 'self'";
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains";Web Application Firewall
ModSecurity with NGINX Ingress
YAML
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-configuration
data:
enable-modsecurity: "true"
enable-owasp-modsecurity-crs: "true"
modsecurity-snippet: |
SecRuleEngine On
SecAuditLog /dev/stdoutCustom Rules
YAML
modsecurity-snippet: |
SecRule REQUEST_URI "@contains /admin" \
"id:1001,phase:1,deny,status:403,msg:'Admin access blocked'"Authentication
Basic Auth
YAML
metadata:
annotations:
nginx.ingress.kubernetes.io/auth-type: basic
nginx.ingress.kubernetes.io/auth-secret: basic-auth
nginx.ingress.kubernetes.io/auth-realm: "Authentication Required"OAuth2 Proxy
YAML
metadata:
annotations:
nginx.ingress.kubernetes.io/auth-url: "https://oauth2.example.com/oauth2/auth"
nginx.ingress.kubernetes.io/auth-signin: "https://oauth2.example.com/oauth2/start"DDoS Protection
- Use cloud provider DDoS protection
- Deploy in front of CDN (Cloudflare, AWS CloudFront)
- Implement geographic restrictions if applicable
Monitoring
- Log all requests
- Alert on error rate spikes
- Monitor for attack patterns
- Track certificate expiration
Your ingress is your perimeter—defend it well.