Comment j'ai réussi la sécurité Kubernetes certifiée

Bonjour à tous.





J'aimerais partager mon expérience de réussite à l' examen Certified Kubernetes Security (CKS) de la Linux Foundation . Cet examen, comme vous pouvez le deviner, teste notre capacité à configurer divers aspects de la sécurité du cluster Kubernetes et des applications qui y sont exécutées. J'ai aimé l'examen, il aborde la sécurité de différents points de vue, et utilise également des outils externes très utiles tels que Falco, Trivy, kube-bench, Open Policy Agent, gVisor, etc. CKA, qui s'adresse davantage aux nouveaux arrivants sur Kubernetes.





Je parlerai d'abord de l'examen et de sa préparation en général, puis je passerai aux sujets abordés dans l'examen.





Pour le moment, il n'y a que deux examens de sécurité Kubernetes - il s'agit en fait de CKS lui-même, ainsi que du spécialiste certifié Red Hat en sécurité: conteneurs et OpenShift , qui traite de la sécurité OpenShift. Ces deux examens se chevauchent à bien des égards, cependant, selon OpenShift, je pense que l'examen est encore plus difficile (j'ai échoué avec succès).





L'examen coûte 300 USD séparément , le cours officiel Kubernetes Security Fundamentals (LFS260) coûte 299 USD , vous pouvez acheter le cours et l'examen ensemble pour 499 USD . J'ai acheté le cours et l'examen ensemble pour 200 $ à la traditionnelle vente du Nouvel An de la Linux Foundation.





CKS CKA (Certified Kubernetes Administrator). CKS, , CKA. , CKS CKA.





. :





  1. Linux Foundation: Kubernetes Security Fundamentals (LFS260). Linux Foundation, . , , , , - PDF ( , ?!), . , . , .





  2. Udemy 3599 . , " ", . , , . https://killer.sh. , , .. - . , , .. , . , .





15-20 , 2 .. 6-8 . . , Kubernetes killer.sh, 1 40 .





67%, . , "".





. , .





- . CKS. :





Cluster Setup (10%)





  1. Use Network security policies to restrict cluster level access





  2. Use CIS benchmark to review the security configuration of Kubernetes components (etcd, kubelet, kubedns, kubeapi)





  3. Properly set up Ingress objects with security control





  4. Protect node metadata and endpoints





  5. Minimize use of, and access to, GUI elements





  6. Verify platform binaries before deploying









Cluster Hardening (15%)





  1. Restrict access to Kubernetes API





  2. Use Role Based Access Controls to minimize exposure





  3. Exercise caution in using service accounts e.g. disable defaults, minimize permissions on newly created ones





  4. Update Kubernetes frequently









System Hardening15%





  1. Minimize host OS footprint (reduce attack surface)





  2. Minimize IAM roles





  3. Minimize external access to the network





  4. Appropriately use kernel hardening tools such as AppArmor, seccomp









Minimize Microservice Vulnerabilities (20%)





  1. Setup appropriate OS level security domains e.g. using PSP, OPA, security contexts





  2. Manage Kubernetes secrets





  3. Use container runtime sandboxes in multi-tenant environments (e.g. gvisor, kata containers)





  4. Implement pod to pod encryption by use of mTLS









Supply Chain Security20%





  1. Minimize base image footprint





  2. Secure your supply chain: whitelist allowed registries, sign and validate images





  3. Use static analysis of user workloads (e.g.Kubernetes resources, Docker files)





  4. Scan images for known vulnerabilities









Monitoring, Logging and Runtime Security20%





  1. Perform behavioral analytics of syscall process and file activities at the host and container level to detect malicious activities





  2. Detect threats within physical infrastructure, apps, networks, data, users and workloads





  3. Detect all phases of attack regardless where it occurs and how it spreads





  4. Perform deep analytical investigation and identification of bad actors within environment





  5. Ensure immutability of containers at runtime





  6. Use Audit Logs to monitor access









, , , - . , , . .





. Falco Sysdig. Linux , . Falco , :





  1. hostPID



    hostNetwork







  2. hostPath











  3. , /etc







  4. IP-









... .





, Falco Kubernetes, Kubernetes API, :





  1. hostPID



    hostNetwork



    .













  2. kube-system





  3. ClusterRoleBinding



    cluster-admin





... .





, Falco . , .. , . , Falco , .





Kubernetes, RBAC , Open Policy Agent (OPA). Kubernetes , Rego. Kubernetes validating admission webhook OPA Gatekeeper. Custom Resource Definition. , costcenter.





apiVersion: templates.gatekeeper.sh/v1beta1
kind: ConstraintTemplate
metadata:
  name: k8srequiredlabels
spec:
  crd:
    spec:
      names:
        kind: K8sRequiredLabels
      validation:
        openAPIV3Schema:
          properties:
            labels:
              type: array
              items: string
  targets:
    - target: admission.k8s.gatekeeper.sh
      rego: |
        package k8srequiredlabels
        
        violation[{"msg": msg, "details": {"missing_labels": missing}}] {
          provided := {label | input.review.object.metadata.labels[label]}
          required := {label | label := input.parameters.labels[_]}
          missing := required - provided
          count(missing) > 0
          msg := sprintf("you must provide labels: %v", [missing])
        }
---
apiVersion: constraints.gatekeeper.sh/v1beta1
kind: K8sRequiredLabels
metadata:
  name: ns-must-have-costcenter
spec:
  match:
    kinds:
      - apiGroups: [""]
        kinds: ["Namespace"]
  parameters:
    labels: ["costcenter"]
      
      



costcenter :





Error from server (you must provide labels: "costcenter"): error when creating "ns.yaml": admission webhook "validating-webhook.openpolicyagent.org" denied the request: you must provide labels: "costcenter"
      
      



OPA Gatekeeper , , .. Kubernetes, , . , Gatekeeper mutating webhook, .. , .





, Rego playground, . , Kubernetes, .





, , Trivy Aquasecurity. , , , Clair, .





:





  1. Network Policy. , from to . .





  2. RBAC. Role



    ClusterRole



    , RoleBinding



    ClusterRoleBinding



    . , ClusterRole



    ClusterRoleBinding



    , , RoleBinding



    , ClusterRole



    ( , admin



    , edit



    view



    , ).

    Role



    RoleBinding



    , , . , .

    , , , ("Authorization: Bearer $TOKEN" ).





  3. Kubernetes. Falco, . , kube-apiserver, .





  4. Kube-bench. .





  5. kube-apiserver, kube-scheduler, kube-controller-manager kubelet. , kubeadm, . , , , kube-apiserver, , (/var/log/pods/*



    ), .. .





  6. kubeadm .





  7. YAML- Kubernetes . , , , .





  8. TLS-enabled Ingress.





  9. ImagePolicyWebhook.





  10. AppArmor. AppArmor . (!)





  11. Seccomp. , AppArmor.





  12. RuntimeClass, gVisor. , , .





  13. PodSecurityPolicy (PSP). , PSP , .. , , AppArmor securityContext, defaultAllowPrivilegeEscalation



    defaultAddCapabilities



    .

    , PodSecurityPolicy use PSP . .





  14. Kubernetes Dashboard. Kubernetes Dashboard, , .





(, Chrome, Vivaldi). :





  1. https://kubernetes.io/docs





  2. https://github.com/kubernetes





  3. https://kubernetes.io/blog





  4. https://github.com/aquasecurity/trivy





  5. https://docs.sysdig.com





  6. https://falco.org/docs





  7. https://gitlab.com/apparmor/apparmor/-/wikis/Documentation





, . https://kubernetes.io/docs.





, Certified Kubernetes Security.












All Articles