How to enhance the security of your cluster
Diese Seite ist noch nicht in deiner Sprache verfügbar. Englische Seite aufrufen
This page contains helpful information on how to improve the security of your SKE cluster.
Workload security
Section titled “Workload security”The security of your workloads is central to the health of your Kubernetes environment. The following recommendations will help you secure your workloads optimally:
Container image security
Section titled “Container image security”- Only use trusted container registries
- Implement an automated scanning process for security vulnerabilities
- Use multi-stage builds to minimize image size
- Avoid using the
"latest"tag - Document the origin of your images (software supply chain / bill of materials)
Pod security standards
Section titled “Pod security standards”Pod security standards define different security levels for pods:
Restricted profile (recommended)
Section titled “Restricted profile (recommended)”- Prevents privileged containers
- Forces non-root users
- Restricts Linux capabilities
- Blocks privilege escalation
Baseline profile
Section titled “Baseline profile”- Blocks known privilege escalation
- Allows standard Linux capabilities
- Requires container user/group
Privileged profile (only if absolutely necessary)
Section titled “Privileged profile (only if absolutely necessary)”- No restrictions
- Only use for system components
Implementation:
PSS
apiVersion: pod-security.kubernetes.io/v1kind: Namespacemetadata: name: mein-namespace labels: pod-security.kubernetes.io/enforce: restricted pod-security.kubernetes.io/warn: restrictedResource management
Section titled “Resource management”Resource and request limits are essential for the stability of your cluster. You can implement this as follows:
Resource Limits & Requests
spec: containers: - name: app resources: requests: memory: "64Mi" cpu: "250m" limits: memory: "128Mi" cpu: "500m"Namespace resource quotas:
Resource Limits & Requests
apiVersion: v1kind: ResourceQuotametadata: name: compute-quota namespace: my-namespacespec: hard: requests.cpu: "4" requests.memory: 4Gi limits.cpu: "8" limits.memory: 8GiNetwork isolation
Section titled “Network isolation”Api server access control (ACL)
Section titled “Api server access control (ACL)”Securing Kubernetes API server access is one of the most important aspects of Kubernetes cluster security. The ACL functionality allows you to restrict access to the API server of your cluster to certain IP ranges.
The following configurations are recommended:
Production environments
Section titled “Production environments”- Restrict access to known corporate IP ranges
- Use dedicated IP ranges for CI/CD systems
- Avoid using
0.0.0.0/0(open access)
Example configurations
Section titled “Example configurations”- Internal STACKIT access:
193.148.160.0/19and45.129.40.0/21(you can find the current STACKIT public IP ranges here) - Company network: your specific IP range (for example,
1.2.3.0/24) - Individual systems: specific IP addresses (for example,
1.2.3.4/32)
Best practices
Section titled “Best practices”- Document all permitted IP ranges
- Check the ACL configuration regularly
- Implement a process for ACL changes
- Consider backup and disaster recovery (DR) locations in ACL configuration
Network policies
Section titled “Network policies”Network policies are your primary tool for controlling pod-to-pod traffic:
Default deny policy (starting point for each namespace):
Default Deny Policy
apiVersion: networking.k8s.io/v1kind: NetworkPolicymetadata: name: default-deny namespace: mein-namespacespec: podSelector: {} policyTypes: - Ingress - EgressExample of a granular policy:
Granular Policy (example)
apiVersion: networking.k8s.io/v1kind: NetworkPolicymetadata: name: api-allow namespace: mein-namespacespec: podSelector: matchLabels: app: api policyTypes: - Ingress ingress: - from: - namespaceSelector: matchLabels: purpose: frontend ports: - protocol: TCP port: 8080Ingress/egress control
Section titled “Ingress/egress control”- Use
IngressControllerfor external access - Limit egress traffic to necessary destinations
- Use
ExternalNameservices for external services
Role based access control (RBAC)
Section titled “Role based access control (RBAC)”Role based access control (RBAC) is the primary means of access control in Kubernetes. Here are best practices for implementing in your cluster:
Roles and cluster roles
Section titled “Roles and cluster roles”Example of a restricted developer role:
RBAC
apiVersion: rbac.authorization.k8s.io/v1kind: Rolemetadata: namespace: mein-namespace name: developerrules: - apiGroups: [""] resources: ["pods", "services"] verbs: ["get", "list", "watch"] - apiGroups: ["apps"] resources: ["deployments", "statefulsets"] verbs: ["get", "list", "watch", "create", "update", "patch"]Service accounts
Section titled “Service accounts”Best practices for service accounts:
Service Accounts
apiVersion: v1kind: ServiceAccountmetadata: name: app-service-account namespace: mein-namespaceautomountServiceAccountToken: false # deactivate if not necessarySecret management
Section titled “Secret management”Kubernetes secrets
Section titled “Kubernetes secrets”Basic secret creation:
Kubernetes Secret (example)
apiVersion: v1kind: Secretmetadata: name: app-secretstype: Opaquedata: username: BASE64_ENCODED_USERNAME password: BASE64_ENCODED_PASSWORDBest Practices:
- Use external secret management systems where possible, such as the STACKIT Secrets Manager
- Implement secret rotation
- Restrict access through RBAC
Monitoring and logging
Section titled “Monitoring and logging”Monitoring
Section titled “Monitoring”Example for Prometheus scrape configuration via annotations:
Kubernetes Secret (example)
apiVersion: apps/v1kind: Deploymentmetadata: name: meine-appspec: template: metadata: annotations: prometheus.io/scrape: "true" prometheus.io/port: "9090" prometheus.io/path: "/metrics" spec: containers: - name: my-app #... further configurationLogging
Section titled “Logging”- Implement structured logging
- Centralize logs
- Set log retention policies
- Implement log rotation
Sources of information on known vulnerabilities
Section titled “Sources of information on known vulnerabilities”Update mechanisms
Section titled “Update mechanisms”- Container image updates via CI/CD pipeline
- Kubernetes version updates (provider-controlled)
- Dependency updates in applications
Error handling and logging mechanisms
Section titled “Error handling and logging mechanisms”Health checks
Section titled “Health checks”Implement liveness and readiness probes:
Liveness & Readiness probes
spec: containers: - name: app livenessProbe: httpGet: path: /healthz port: 8080 initialDelaySeconds: 3 periodSeconds: 3 readinessProbe: httpGet: path: /ready port: 8080 initialDelaySeconds: 3 periodSeconds: 3Pod disruption budgets
Section titled “Pod disruption budgets”Protect your workloads from unwanted downtime:
PDBs (example)
apiVersion: policy / v1kind: PodDisruptionBudgetmetadata: name: app-pdbspec: minAvailable: 2 selector: matchLabels: app: my-appTips for the role and rights concept
Section titled “Tips for the role and rights concept”Best practices for roles
Section titled “Best practices for roles”- Enforce namespace isolation
- Assign minimum authorizations
- Carry out regular audits
Risky combinations to avoid
Section titled “Risky combinations to avoid”- Cluster admin rights for service accounts
- Wildcards in RBAC Rules
- Excessive permissions in multiple namespaces
Appendix
Section titled “Appendix”Useful kubectl commands
Section titled “Useful kubectl commands”Kubectl commands
## RBAC Checkskubectl auth can-i --list --namespace=mein-namespace### Pod Security Standards Checkkubectl get ns mein-namespace -o yaml | grep pod-security### Network Policy Testkubectl run nginx --image=nginx --restart=Never --namespace=my-namespacekubectl exec nginx -n mein-namespace -- wget -qO- --timeout=2 http://another-serviceSecurity checklist for you
Section titled “Security checklist for you”- Pod security standards implemented
- Network policies defined
- RBAC configuration checked
- Resource limits set
- Monitoring activated
- Logging configured
- Secret management implemented
- Health checks configured