Skip to main content
100%

patch all deployments and stateful sets containers in your kubernetes cluster for log4shell CVE-2021-44228 by appending environment variable that prevents the exploit. .

✓ Published0🌍 Public
Aaharonh
Last edited Dec 15, 2021
Created on Dec 15, 2021

This example demonstrates a Kubernetes remediation script that scans all deployments and stateful sets across every namespace, appending the `LOG4J_FORMAT_MSG_NO_LOOKUPS=true` environment variable to any container lacking it, thereby mitigating the log4shell CVE-2021-44228 exploit. The code uses the official `kubernetes` Python client, loading the kubeconfig via `config.load_kube_config()` and leveraging `AppsV1Api` to list and patch resources with `list_deployment_for_all_namespaces()` and `patch_namespaced_deployment()`. It iterates through each app, checks existing environment variables for the marker, and only applies patches when changes are required, printing progress and error messages for each modified workload.

AI-generated description

Similar vizzes