This repository contains a comprehensive Bash script designed to automate the deployment and hardening of Kubernetes clusters. By leveraging the CIS Kubernetes Benchmark 2024, this project aims to enhance cluster security and compliance while streamlining the setup process.
- Project Overview
- Features
- Prerequisites
- Installation
- Usage
- Cluster Hardening
- Contributing
- License
- Acknowledgments
This project focuses on the automation and security hardening of a Kubernetes cluster. The objective is to automate the deployment, configuration, and hardening processes to ensure that the Kubernetes environment is secure, resilient, and ready for production use.
- Automated Kubernetes Cluster Setup: Scripts to automate the setup of a Kubernetes cluster.
- Security Hardening: Implementation of best practices for securing the Kubernetes environment, including network policies, RBAC, pod security policies, and more.
- Modular and Scalable: Easily adaptable to different environments and scales for clusters of various sizes.
- Compliance with Security Standards: Aligns with industry standards and guidelines like CIS Kubernetes Benchmark.
Before you begin, ensure you have met the following requirements:
- A system running Linux (CentOS, Ubuntu, Debian, or Kali).
- Root or sudo access to your system.
- Basic knowledge of Kubernetes, Docker, and Linux commands.
- The following software installed:
- Docker
- Kubernetes (
kubeadm
,kubectl
,kubelet
) git
curl
sed
,grep
, and other common Unix utilities
Follow these steps to set up the project:
-
Clone the Repository:
git clone https://github.com/yourusername/kubernetes-cluster-hardening.git cd kubernetes-cluster-hardening
-
Run the Setup Script: Execute the primary setup script to deploy the Kubernetes cluster:
bash setup.sh
-
Configure Environment: Edit any configuration files as necessary to match your environment. Key files to consider:
config/kubernetes.conf
config/firewall.conf
config/containerd-config.toml
-
Start the Hardening Process: Run the hardening script after the cluster is set up:
bash hardening.sh
Once the setup and hardening scripts have been executed, you can manage your Kubernetes cluster as usual with kubectl
commands. The cluster should now be secured according to the best practices outlined in the hardening script.
-
Check Cluster Nodes:
kubectl get nodes
-
Deploy an Application:
kubectl apply -f deployment.yaml
The hardening script implements several security measures, including but not limited to:
- Network Policies: Restricting network access between pods.
- Pod Security Policies: Ensuring pods run with the minimum necessary privileges.
- Role-Based Access Control (RBAC): Enforcing strict access controls on Kubernetes resources.
- Audit Logs: Setting up audit logging to track API server requests.
- Image Security: Using signed and verified container images.
For more details, refer to the hardening guide.
Contributions are welcome! Please follow these steps to contribute:
- Fork the repository.
- Create a new branch (
git checkout -b feature-branch
). - Make your changes and commit them (
git commit -m 'Add new feature'
). - Push to the branch (
git push origin feature-branch
). - Open a pull request.
Please ensure your code adheres to the existing code style and includes appropriate tests.
This project is licensed under the GNU GENERAL PUBLIC LICENSE. See the LICENSE file for details.