k8s-security-policy-auditor
is a Kubernetes controller designed to audit security policies and configurations within a Kubernetes cluster. It helps ensure that your cluster resources, such as ConfigMaps, Secrets, Roles, and RoleBindings, adhere to best security practices.
- Audits Kubernetes ConfigMaps for sensitive data.
- Audits Secrets to ensure encryption and minimal exposure.
- Checks Roles and RoleBindings for excessive permissions and role misconfigurations.
- Provides insights and logs for detected security issues.
- Kubernetes cluster (v1.20 or later recommended)
- kubectl command-line tool
- Docker for building the container image
- GitHub account for using GitHub Container Registry (GHCR)
git clone https://github.com/rorysavage77/k8s-security-policy-auditor.git
cd k8s-security-policy-auditor
Ensure you have the Dockerfile set up and use GitHub Actions for CI/CD:
GitHub Actions Workflow: Ensure you have the workflow set up in .github/workflows/go.yml to build and push your image to GHCR.
- Create a Docker Image Pull Secret:
If your image is private, create a pull secret:
kubectl create secret docker-registry ghcr-secret \
--docker-server=ghcr.io \
--docker-username=<your-username> \
--docker-password=<your-token> \
--docker-email=<your-email>
- Apply the RBAC Configuration:
Ensure your service account has the necessary permissions by applying the RBAC manifest:
kubectl apply -f rbac-config.yaml
- Deploy the Auditor:
Deploy the auditor to your Kubernetes cluster:
kubectl apply -f k8s-security-policy-auditor.yaml
Once deployed, the auditor will start monitoring your cluster's ConfigMaps, Secrets, Roles, and RoleBindings for security issues. It logs findings to the standard output, which you can view using:
kubectl logs -f deployment/k8s-security-policy-auditor
You can customize the auditor by modifying environment variables and resource configurations within the k8s-security-policy-auditor.yaml manifest.
Ensure you have the necessary Go tools installed:
go test -v ./...
Build the binary:
go build -o k8s-security-policy-auditor .
2024-08-07T21:56:59Z INFO Auditing RoleBinding {"Namespace": "litmus", "Name": "litmus-admin-ops-role-binding"}
2024-08-07T21:56:59Z INFO Reconciling resource {"Request.Namespace": "kyverno", "Request.Name": "sh.helm.release.v1.kyverno.v1", "Namespace": "kyverno", "Name": "sh.helm.release.v1.kyverno.v1"}
2024-08-07T21:56:59Z INFO Auditing Secret {"Namespace": "kyverno", "Name": "sh.helm.release.v1.kyverno.v1"}
2024-08-07T21:56:59Z INFO Reconciling resource {"Request.Namespace": "litmus", "Request.Name": "chaos-litmus-admin-secret", "Namespace": "litmus", "Name": "chaos-litmus-admin-secret"}
2024-08-07T21:56:59Z INFO Auditing Secret {"Namespace": "litmus", "Name": "chaos-litmus-admin-secret"}
2024-08-07T21:56:59Z INFO Reconciling resource {"Request.Namespace": "litmus", "Request.Name": "chaos-mongodb", "Namespace": "litmus", "Name": "chaos-mongodb"}
2024-08-07T21:56:59Z INFO Auditing Secret {"Namespace": "litmus", "Name": "chaos-mongodb"}
2024-08-07T21:56:59Z INFO Reconciling resource {"Request.Namespace": "default", "Request.Name": "ghcr-secret", "Namespace": "default", "Name": "ghcr-secret"}
2024-08-07T21:56:59Z INFO Auditing Secret {"Namespace": "default", "Name": "ghcr-secret"}
2024-08-07T21:56:59Z INFO Reconciling resource {"Request.Namespace": "kyverno", "Request.Name": "kyverno-cleanup-controller.kyverno.svc.kyverno-tls-pair", "Namespace": "kyverno", "Name": "kyverno-cleanup-controller.kyverno.svc.kyverno-tls-pair"}
2024-08-07T21:56:59Z INFO Auditing Secret {"Namespace": "kyverno", "Name": "kyverno-cleanup-controller.kyverno.svc.kyverno-tls-pair"}
2024-08-07T21:56:59Z INFO Reconciling resource {"Request.Namespace": "kyverno", "Request.Name": "kyverno-svc.kyverno.svc.kyverno-tls-ca", "Namespace": "kyverno", "Name": "kyverno-svc.kyverno.svc.kyverno-tls-ca"}
2024-08-07T21:56:59Z INFO Auditing Secret {"Namespace": "kyverno", "Name": "kyverno-svc.kyverno.svc.kyverno-tls-ca"}
2024-08-07T21:56:59Z INFO Reconciling resource {"Request.Namespace": "kyverno", "Request.Name": "kyverno-svc.kyverno.svc.kyverno-tls-pair", "Namespace": "kyverno", "Name": "kyverno-svc.kyverno.svc.kyverno-tls-pair"}
2024-08-07T21:56:59Z INFO Auditing Secret {"Namespace": "kyverno", "Name": "kyverno-svc.kyverno.svc.kyverno-tls-pair"}
2024-08-07T21:56:59Z INFO Reconciling resource {"Request.Namespace": "kyverno", "Request.Name": "kyverno-cleanup-controller.kyverno.svc.kyverno-tls-ca", "Namespace": "kyverno", "Name": "kyverno-cleanup-controller.kyverno.svc.kyverno-tls-ca"}
2024-08-07T21:56:59Z INFO Auditing Secret {"Namespace": "kyverno", "Name": "kyverno-cleanup-controller.kyverno.svc.kyverno-tls-ca"}
2024-08-07T21:56:59Z INFO Reconciling resource {"Request.Namespace": "litmus", "Request.Name": "sh.helm.release.v1.chaos.v1", "Namespace": "litmus", "Name": "sh.helm.release.v1.chaos.v1"}
2024-08-07T21:56:59Z INFO Auditing Secret {"Namespace": "litmus", "Name": "sh.helm.release.v1.chaos.v1"}
2024-08-07T21:56:59Z INFO Reconciling resource {"Request.Namespace": "litmus", "Request.Name": "subscriber-secret", "Namespace": "litmus", "Name": "subscriber-secret"}
Contributions are welcome! Please open an issue or submit a pull request with your changes. Ensure that your code is well-documented and includes tests where applicable.
This project is licensed under the MIT License. See the LICENSE file for more information.
Special thanks to the Kubernetes community for providing an extensive set of tools and libraries that make projects like this possible.