This document outlines security best practices for deploying and using K8sToolbox in your Kubernetes environment.
K8sToolbox is a powerful utility for Kubernetes management and troubleshooting. With great power comes great responsibility - many of the capabilities that make it useful for debugging can also create security risks if not properly managed.
K8sToolbox includes two RBAC configurations:
-
Restricted Permissions (Recommended):
- Uses the principle of least privilege
- Grants only the permissions needed for K8sToolbox to function
- Recommended for all environments, especially production
-
Cluster Admin (Not Recommended):
- Grants full administrative access to the cluster
- Only use in isolated, non-production environments
- Creates significant security risk
Best Practice: Always use restricted permissions by setting security.useRestrictedPermissions=true in Helm values.
security:
useRestrictedPermissions: trueThe security context defines privilege and access controls for the container.
Best Practice: Configure the security context with the following settings:
security:
podSecurityContext:
fsGroup: 10001
runAsUser: 10001
runAsGroup: 10001
runAsNonRoot: true
containerSecurityContext:
privileged: false
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities:
drop:
- ALL
add:
- NET_ADMIN # Only if needed for network diagnostics
- NET_RAW # Only if needed for network diagnosticsNote: Some network diagnostic tools may require NET_ADMIN and NET_RAW capabilities. If these aren't needed, don't add them.
K8sToolbox can be configured to access the host filesystem.
Best Practice: Avoid mounting the host filesystem unless absolutely necessary.
volumes:
mountHostRoot: falseIf host access is required, consider:
- Mounting only specific directories instead of the entire root filesystem
- Making the mounts read-only where possible
- Using this feature only in non-production environments
K8sToolbox provides scripts that can modify cluster resources.
Best Practices:
- Only run scripts in namespaces where changes are intended
- Consider executing scripts with
--dry-runfirst to preview changes - Implement proper access controls to limit who can execute these scripts
- Always review script output to understand what changed
Some K8sToolbox scripts provide network diagnostic capabilities that can potentially be used for unintended purposes.
Best Practices:
- Use Network Policies to limit which pods K8sToolbox can communicate with
- Only deploy K8sToolbox in namespaces where it's needed
- Restrict egress traffic from the K8sToolbox pod when in production
Example Network Policy:
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: k8stoolbox-network-policy
spec:
podSelector:
matchLabels:
app: k8stoolbox
policyTypes:
- Egress
egress:
- to:
- namespaceSelector:
matchLabels:
purpose: productionWhen using the K8sToolbox web interface (if enabled), proper authentication is essential.
Best Practices:
- Always enable authentication when using the web interface
- Generate strong passwords and rotate them regularly
- Consider integrating with existing identity providers
- Use HTTPS for all traffic to the web interface
auth:
enabled: true
generatePassword: trueFor production environments, follow these additional guidelines:
- Namespace Isolation: Deploy K8sToolbox in its own namespace with tight access controls
- Resource Limits: Set appropriate CPU and memory limits to prevent resource exhaustion
- Audit Logging: Enable Kubernetes audit logging to track actions performed by K8sToolbox
- Regular Updates: Keep K8sToolbox updated to the latest version to benefit from security patches
- Scheduled Deployments: Consider deploying K8sToolbox only when needed and removing it afterward
- Image Scanning: Scan the K8sToolbox image for vulnerabilities before deployment
Use this checklist before deploying K8sToolbox:
- RBAC is set to restricted permissions
- Container is not running as privileged
- Host root filesystem is not mounted
- Non-root user is configured
- Resource limits are defined
- Network policies are implemented
- Authentication is enabled for the web interface
- Image has been scanned for vulnerabilities
- Read-only root filesystem is enabled
- Unnecessary capabilities are dropped
- Deployment is in an isolated namespace
By following these security best practices, you can ensure that K8sToolbox enhances your Kubernetes management capabilities without introducing unnecessary risk to your environment.