Showing posts with label K8s. Show all posts
Showing posts with label K8s. Show all posts

Nov 30, 2022

Zero Effort Zero Trust for Blocking Zero Days in Kubernetes


Let's learn the zero trust segmentation for network, process, and file access within K8s cluster with Tracy Walker. 


Threat-Based Controls Zero-Trust Controls
CVEs Automated Learning
DLP Network
Network Attacks Process
OWASP Top 10 WAF File Access
Admission Control Security as Code



The Automated Behavioral-based Zero-Trust covers:

  • Discover mode - identifies apps behavior (learning mode)
  • Monitor mode - alerts to any anomalous app behavior
  • Protect mode - denies on any anomalous app behavior

 

The demo will show how Zero Trust can protect against zero-day attacks as well as exploits such as Log4j and Spring4shell.


Links:

Oct 20, 2022

Start MicroK8s with Multipass

This post is for me to learn how to create a highly available Kubernetes cluster using the MicroK8s and multipass.

Kubernetes clusters host containerised applications in a reliable and scalable way. Having DevOps in mind, Kubernetes makes maintenance tasks such as upgrades and security patching simple.

MicroK8s is a zero-ops, CNCF certified lightweight Kubernetes distribution for workstations, clusters, edge and IoT devices.

Again, the prerequisite is  there must be a working copy multipass, and I'm using WSL. 😎

Here are the setup configuration:

$ multipass launch --name kmaster -m 4G

$ multipass shell kmaster

ubuntu@kmaster:~$ sudo snap install microk8s --classic

ubuntu@kmaster:~$ sudo usermod -a -G microk8s ubuntu
ubuntu@kmaster:~$ sudo chown -f -R ubuntu ~/.kube

ubuntu@kmaster:~$ exit

$ multipass shell kmaster  

ubuntu@kmaster:~$ microk8s status --wait-ready

Next, let setup a second node:

$ multipass launch --name kworker1 -m 4G

$ multipass shell kworker1

ubuntu@kworker1:~$ sudo snap install microk8s --classic

ubuntu@kworker1:~$ sudo usermod -a -G microk8s ubuntu
ubuntu@kworker1:~$ sudo chown -f -R ubuntu ~/.kube

ubuntu@kworker1:~$ exit

$ multipass shell kworker1

ubuntu@kworker1:~$ microk8s status --wait-ready

 Both nodes are ready, let's join them:

$ multipass exec kmaster -- microk8s add-node

From the node you wish to join to this cluster, run the following:
microk8s join 172.22.71.179:25000/daaad28e6febfbdaa5e228479e5f3f7c/8ee2423760f2

Use the '--worker' flag to join a node as a worker not running the control plane, eg:
microk8s join 172.22.71.179:25000/daaad28e6febfbdaa5e228479e5f3f7c/8ee2423760f2 --worker

If the node you are adding is not reachable through the default interface you can use one of the following:
microk8s join 172.22.71.179:25000/daaad28e6febfbdaa5e228479e5f3f7c/8ee2423760f2

Copy the line (in bold) and paste to the second node (kworker), and wait for a few minutes.

Sep 22, 2022

Kubernetes Tutorials

Kubernetes tutorials with hands-on labs with certification at IBM.

This is an interactive browser-based training for deploying and operating a cluster on IBM Cloud® Kubernetes Service. No downloads or configuration required.

There 3 labs are available:

  1. Containers and Kubernetes essentials  - To learn the core concepts of Kubernetes and how to use Docker containers on Kubernetes.
  2. Scalable web applications on Kubernetes - To learn how to scaffold a web application, run it locally in a container and deploy it to a Kubernetes cluster.
  3. Analyze logs and monitor application health - To learn how to analyze different types of logs and monitor the performance of your applications and clusters.

It is estimated to deploy and manage applications in a preconfigured Kubernetes environment available for four hours at no charge.

 

Links:

Sep 9, 2022

Kubernetes crash course: In less than 15 minutes


One of the best video that talks about Kubernetes (within 15 min), which covers the architecture or relationship between API, Scheduler, Controller, Data Store (etcd), Kubelet, KubeProxy, Docker, Pod, Container, Cluster.


Jul 25, 2022

Kubernetes Attack and Defense: Break Out and Escalate!



My notes:

  • Pod vs container.
  • Pod has a IP address.
  • Nodes run kubelet, container runtime, kube-proxy
  • Attack K8s from a compromised node
    • break out of a container (5 CVEs)
    • over-privilege pod - mount /dev, access to node filesystem, use of node's network namespace, load module, root access, hostPID, hostNetwork Pods
    • phish login access to node
  • steal kubelet and kube-proxy auth cred, /var/lib/kubelet, service account token
  • steal secrets from other pods with env
  • run programs on the node
  • create "mirror pods"
  • steal cred to the vault
  • pull cred for nod's cloud IAM account, http://169.254.169.254/latest/meta-data/iam/security-credentials/<name>/
  • access to bucket storage/S3
  • Defenses:
    • Admission control, SeccompDefault, Security Profiles Operator, Steering Workloads to Nodes, Upgrade the Cluster.
    • Pod Security Policy, Pod Security Standards.
    • Open Policy Agent (OPA) Gatekeeper
    • Kyverno


Links:

Jun 4, 2022

DevSecOps 101

This is 4 parts tutorial on DevSecOps 101.

In part 1, we will learn how to detect and avoid vulnerable dependencies when developing applications.In the first step of DevSecOps, the first step towards building more secure apps is detecting and avoid using dependencies that have known vulnerabilities. This process is called Software Component Analysis or SCA. 

There are a few commercial options like Snyk, but for this tutorial, we will use the open-source pip package safety.

$ pip install safety

$ safety check --full-report

The 2nd step is to integrate SCA into the CI/CD process by adding GitHub workflow to our repository.

Next, we will perform analysis on the source code to find security vulnerabilities. This process is known as Static Application Security Testing, and this has been part of the enterprise software development lifecycle (SDLC) for years.

Recently, there are opensource tools like pylint, eslint or semgrep.

semgrep is, as its names suggest, like grep, but for source code. It allows developers to automatically find patterns in their source code while taking into account semantics like variable renaming. You can find an example of semgrep finding XSS in Django code here.

Even better, semgrep supports a lot of languages, and the semgrep community already has written plenty of rulesets to detect bad practices and security flaws for those.

$ pip install semgrep

$ semgrep --config "p/ci" --exclude .venv --error

  •     --config "p/ci" means "use the community-written security rules for running in a ci environment"
  •     --exclude .venv means "do not search for vulnerable source code in the .venv folder" (otherwise it would return hundreds of alerts!)
  •     --error means return a non-zero error code if alerts are found. Useful for making the CI fail if insecure patterns are detected

Next, we need to add semgrep to the CI/CD to avoid ever doing the in the future. With this, we just installed a tool that scans all our python code to find insecure patterns, gives us recommendations on how to solve them, and integrates seamlessly into our CI/CD.

In part 3, we will be moving into Security Integration Testing (SIT) with automation.

To have an additional layer of security testing that is closer to the application's production context, security teams use specialized tools that will simulate attacks against the running application and report the successful ones.

This process is called Dynamic Application Security Testing (DAST).

Nuclei is an easy-to-use application security testing tool written in go-lang. It leverages the community to create new automated tests using simple YAML template files.  

$ go install -v github.com/projectdiscovery/nuclei/v2/cmd/nuclei@latest

$ docker-compose up

$ nuclei -u http://localhost:8080

Next, we will be integrating Nuclei inside the CI/CD process. Again,, in only a few steps, we just install a tool that scans for vulnerabilitites directly inside CI/CD. We scannd our live running app using nuclei web-app security scanner.

In part 4, we will be learning how to scan Docker images using Trivy. This is an opensource security scanner to find mis-configuration and vulnerabilities.

Thanks to trivy, one can scan its docker images to know literally in seconds if they contain packages with known vulnerabilities. Even cooler, trivy is free, open-source, and well maintained.

$  curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sh -s -- -b /usr/local/bin v0.21.0

$ docker build . --file Dockerfile.app -t dvpwa.app

$ trivy image dvpwa.app:latest

Lastly, we will be integrating trivy in GitHub Actions by following a template from AquaSec. So we just set up a tool that automatically detects vulnerable packages inside our docker images, directly in the CI/CD.

In fact trivy can scan way more than docker images: filesystems, requirements.txt, package.json, Dockerfiles and K8s configs.

$ trivy config .

This will scan Dockerfile.app and Docker.db automatic.


Links:

Mar 2, 2022

Containerless on Kubernetes

WebAssembly (Wasm) is one of the most exciting and underestimated software technologies invented in recent times. It's a binary instruction format for a stack-based virtual machine that aims to execute at native speeds with a memory-safe and secure sandbox. 

Wasm is portable, cross-platform, and language-agnostic—designed as a compilation target for languages. Though originally part of the open web platform, it has found use cases beyond the web. WebAssembly is now used in browsers, Node.js, Deno, Kubernetes, and IoT platforms.

WebAssembly on Kubernetes

Though initially designed for the web, WebAssembly proved to be an ideal format for writing platform and language-agnostic applications. 

You may be aware of something similar in the container world—Docker containers. 

People, including Docker co-founder Solomon Hykes, recognized the similarity and acknowledged that WebAssembly is even more efficient (than Docker) since it's fast, portable, and secure, running at native speeds. This means that you can use WebAssembly alongside containers as workloads on Kubernetes. 

Another WebAssembly initiative known as WebAssembly System Interface (WASI) along with the Wasmtime project make this possible.

    If WASM+WASI existed in 2008, we wouldn't have needed to created Docker. That's how important it is. Webassembly on the server is the future of computing. A standardized system interface was the missing link. Let's hope WASI is up to the task! twitter.com/linclark/statu…
    20:39 PM - 27 Mar 2019
    Lin Clark @linclark
    

WebAssembly on Kubernetes is relatively new, but it's already proving to be revolutionary. Wasm workloads can be extremely fast as they can execute faster than a container takes to start. The workloads are sandboxed and hence much more secure than containers; they are way smaller in size due to the binary format than containers.

If you want to learn more about WASI, check out the original announcement from Mozilla.


Links:

  • Learn more about WebAssembly (WASM) at WebAssembly.org.
  • https://dev.to/oktadev/containerless-how-to-run-webassembly-workloads-on-kubernetes-with-rust-2j8f

Feb 28, 2022

Setting Up Pod Security Policies in Kubernetes


This video demonstrates how to configure Pod Security Policies in Kubernetes. To me, this has the difficulty level at 8/10.

It covers the admission controller, and how important on the service account. Then it talks about policies and RBAC. 

The written instruction is available at https://octetz.com/docs/2018/2018-12-07-psp/


Feb 27, 2022

Hacking and Hardening Kubernetes Clusters by Example [I]


Although this is a 4 years old webinar, I found it is still worth for today. The goals of this webinar is to raise the awareness risk in K8s and demonstrate the 'live' hacking and attacking a K8s. It also provides some hardening methods and tips.

  • Defaults in use early tend to stay in use.
  • Systems hardened late tend to break.

The webinar introduces a number of tools for securing K8s and a lot of hardening tips for your K8s cluster.

KubeATF - A tool used to automate the creation, validation, and destruction of K8s in a consistent way.

Bulkhead - A plugin that perform security posture scans on all nodes from within your K8s.


Links:

 

Feb 25, 2022

Kubernetes Security Best Practices


Kubernetes Security Best Practices by Ian Lewis, Google 

Containers give developers the ability to isolate applications from one another, but that’s not enough. Resource isolation is much different that security isolation. How do we make applications deployed in containers more secure? What tools can be we apply to our containers running in Kubernetes to make them more secure? How can we apply policy to our network and services to make sure applications only have access to what they need and nothing more? 

In this talk, attendees will learn about the risks and attack surfaces of a Kubernetes cluster. s-We'll look at tools like PodSecurityPolicy, SELinux, AppArmor, seccomp, and sandboxed containers in action to improve the security of containers. We’ll then go up the stack and learn how to apply network policy to containers to further improve security.

Agenda:

  • Security 101
    • Defense in depth (redundant 
    • Limit the attack surface 
    • Least privilege
  • Runtime security
    • Attacking Kubernetes cluster itself, Kubernetes API server
  • Host security
    • RBAC
    • API Firewall
  • Network security
    • NetworkPolicy
    • Secured access to etcd
    • Run as non-root
    • Read-only root filesystem
    • no new privileges (allowPrivilegeEscalation:false)
    • Sandboxed Pod
    • seccomp/AppArmor/SELinux
    • restrict kubelet permissions
    • Policy enforcement
    • istio
  • Use kube-bench



Feb 23, 2022

Kubernetes Security: Attacking and Defending K8s Clusters

Note:

  • Initial access with 
    • known vuln
    • Exposed dashboard or 
    • Kube API server 
  • Exploitation / Execution 
    • API endpoint
    • get a shell access
  • Internal recon 
    •  env | grep -i kube
    • /var/run/secrets/kubernetes.io/serviceaccount
    • container introspection
  • Post-exploitation / Presistence
    • privilege escalation
    • pod/container escape via privileged pod
  • Defending K8s
    • curl -k https://192.168.1.1:6443
    • CIS Kebernetes Benchmark (120+ security checks)
    • kube-bench (golang)
  • Image scan
    • Clair, docker scan, smartcheck, snyk, Trivy
  • Cloud-native runtime protection
    • Falco (CNCF)
  • The Pods
    • AllowPrivilegeEscalation = false
    • ReadOnlyRootFileSystem = true
    • RunAsNonRoot = true 
    • Use Seccomp, AppArmor and SELinux
  • Pod Security Policies (PSP) - applied at cluster level (deprecated)
  • PSP replacement
    • OPA / Gatekeeper
    • Kyverno (yaml)
    • PodSecurity
  • RBAC (Role Based Access Control)
    • --authorization-mode=Node,RBAC
  • Secure those exposed etcd (cluster objects)
    • Encryption at rest not default
  • The Network Policy
    • Among all the pods
    • Pods with kube-system namespace
  • The Audit Logs
    • not enabled by default
  • Update K8s !!

 

Links:

Dec 5, 2021

OpenShift and Kubernetes

 



These are the 2 videos that can explain quickly about what Kubernetes and OpenShift is.

Nov 2, 2021

Tools for Kubernetes

Here are some useful Interactive Terminal and Graphical UI Tools for managing multiple Kubernetes or K8s clusters.

Octant (graphical-based UI)

Octant is a browser-based UI aimed at application developers giving them visibility into how their application is running. It is useful for anyone who forget the various options to kubectl to inspect your K8s Cluster and/or workloads. 

Octant is also a VMware Open Source project and it is supported on Windows, Mac and Linux (including ARM) and runs locally on a system that has access to a K8S Cluster. After installing Octant, just type octant and it will start listening on localhost:7777 and you just launch your web browser to access the UI.

It is easy to switch context between different K8s Cluster with a simple drop down along with namespace filtering which is quite helpful in narrowing down a specific deployments, usually for informational or troubleshooting purposes.

With Octant, you just select the pod that you are interested in and clicking on the Logs tab (for debugging). You can also filter on specific key words which can be handy when the logs are flying across your screen; or you may just choose to access the pod with the built in terminal access.

Kubevious 

Kubevious comes with a slick browser-based UI, and allow you to navigate through your application in a hierarchal fashion and quickly drill down into the application details and configurations within a single view. 

Kubevious has a nice visual graphics, and requires to deploy  it at ever K8s Cluster.

kubelive

Kubelive is a terminal-based UI using Node.js. It is easy to use but it currently is limited to just a handful of kubectl commands. It has the ability to easily navigate through the various namespaces for a given K8s Cluster and quickly show the status of given set of pods.

It allowed you to quickly show the various namespaces without typing a bunch of commands and the underlying containers that we had just deployed. 

K9s (terminal-based UI)

K9s is another terminal-based UI that highly recommended, and it has a similar experience like Kubelive with the ability to easily navigate through namespaces and pods. 

K9s works just like Kubelive, you just type the command after installing the binary and it will give you access to the specific K8s Cluster which you have context in.

Lens

Lens an Electron-based desktop application that runs on Windows, Mac and Linux. It integrates with Prometheus to visualize and see trends in resource usage metrics, including CPU, memory, network and disk, with the total capacity, actual usage, requests and limits 

It can connect to a local K8s Cluster and you can also add a custom configuration by copying/pasting the kube configuration which I thought was pretty nice. 

Lens has the capability to quickly search for filter out the things, and supports terminal access to a pod directly.

Lens Open Source Project (OpenLens)

OpenLens is where Team Lens develops the Lens IDE product together with the community. It is backed by a number of Kubernetes and cloud native ecosystem pioneers.

Lens - The Kubernetes IDE

Lens - The Kubernetes IDE ("Lens IDE") is a distribution of the OpenLens repository with Team Lens specific customizations released under a traditional EULA.

Lens IDE is a standalone application that runs on MacOS, Windows and Linux operating systems. It provides the full situational awareness for everything that runs in Kubernetes, and makes it easy for people just getting started.


Links:

  • bat - https://github.com/sharkdp/bat
  • kube-ps1 - https://github.com/jonmosco/kube-ps1
  • Octant - https://github.com/vmware-tanzu/octant
  • Kubevious - https://github.com/kubevious/kubevious
  • kubelive - https://github.com/ameerthehacker/kubelive
  • K9s - https://github.com/derailed/k9s
  • OpenLens - https://github.com/lensapp/lens
  • Lens - https://k8slens.dev/
  • https://williamlam.com/2020/04/useful-interactive-terminal-and-graphical-ui-tools-for-kubernetes.html

 

Jul 30, 2021

Learn K8s with Minikube

Here're the steps that I follow in setting up my Minikube in Ubuntu.


$ sudo apt update && apt upgrade -y

$ sudo apt install virtualbox virtualbox-ext-pack

$ curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
$ chmod +x ./kubectl
$ sudo mv ./kubectl /usr/local/bin/kubectl

$ kubectl version --output=yaml

$ curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/

$ minikube version -o json 

$ minikube start --vm-driver=docker

$ kubectl get pods

$ kubectl get nodes

$ kubectl config view

$ kubectl cluster-info

$ minikube ssh 

$ minikube status

$ minikube dashboard

$ minikube dashboard --url

 

Links:

  • https://phoenixnap.com/kb/install-minikube-on-ubuntu

Jul 29, 2021

Docker Learning Guides

Here're a few links for beginner to learn about Docker and Kubernetes. Things like docker, containers, kubernetes, images, registries, pods, replica sets, services deployment, and microservices.

 

Links:

  • https://dev.to/educative/absolute-beginner-s-guide-to-docker-what-is-a-container-lck
  • https://www.educative.io/blog/docker-kubernetes-beginners-guide
  • https://www.educative.io/blog/kubernetes-deployments-pods-services
  • https://www.educative.io/blog/microservices-architecture-tutorial-all-you-need-to-get-started

Jul 13, 2021

Simply Explaining K8s and Containers

This is the best explanation about Kubernetes, container, pod and images for beginners.

Links:

  • https://css-tricks.com/kubernetes-explained-simply-containers-pods-and-images/ 

Here's another article that talks about the basic Kubernetes architecture.

Links:

  • https://www.analyticsvidhya.com/blog/2021/07/kubernetes-lets-learn-the-basic-tenets/


Jan 10, 2019

CVE-2018-1002105 PoC

In all Kubernetes versions prior to v1.10.11, v1.11.5, and v1.12.3, incorrect handling of error responses to proxied upgrade requests in the kube-apiserver allowed specially crafted requests to establish a connection through the Kubernetes API server to backend servers, then send arbitrary requests over the same connection directly to the backend, authenticated with the Kubernetes API server's TLS credentials used to establish the backend connection.

There are 2 POC been released for CVE-2018-1002105.

Authenticated PoC

Proof-of-Concept exploit for CVE-2018-1002105. The current exploit requires create and get privileges on pods and pods/exec. Support has been added for portforward and attach, which require similar permissions.

The current PoC dumps the secrets from the default etcd-kubernetes pod. 

Unauthenticated PoC

The unauthenticated PoC allows privilege escalation within the context of the exposed API. Depending on the functionalities of the API it might be possible to get code execution on pods. This demo currently exploits the bug to gain cluster-admin rights on the servicecatalog.k8s.io API. This exploit should also work for metrics.k8s.io or any API exposed through the aggregated layer.


Links: