Script-Based Deployment¶
Overview¶
Security Emphasis
This task implements a secure script-based deployment that follows security best practices including temporary RBAC resources, ephemeral credentials, and automatic cleanup to maintain a strong security posture without requiring Helm or other complex deployment tools.
This task guides you through the hands-on approach of deploying and using Kube CINC Secure Scanner using direct shell scripts. These scripts provide a lightweight, flexible approach to container scanning with a focus on local Minikube environments and direct command execution.
Alternative Deployment Option
This task focuses on the script-based deployment approach with direct commands. If you prefer a more structured, repeatable deployment method, see the Helm Deployment task which uses Helm charts to accomplish similar goals.
Time to complete: 15-20 minutes
Security risk: 🟡 Medium - Involves creating and executing scripts with Kubernetes access
Security approach: Implements least-privilege access controls, time-limited credentials, and proper resource cleanup using simple shell scripts
Security Architecture¶
Understanding Permission Layers
Script-based deployment involves managing permissions across several layers:
1. Script Execution Permissions * Control: Who can run the scanning scripts and with what privileges * Risk area: Unrestricted script execution could lead to security issues * Mitigation: Implement proper file permissions and execute scripts with minimal privileges
2. Kubernetes API Permissions * Control: What Kubernetes resources the scripts can access * Risk area: Overly permissive kubeconfig could allow unintended access * Mitigation: Scripts generate dedicated service accounts with minimal, time-limited permissions
3. Scanner Runtime Permissions * Control: What the scanner can access within target containers * Risk area: Excessive access to container internals * Mitigation: Apply principle of least privilege with clearly defined resource scopes
Security Prerequisites¶
- Bash shell environment
- kubectl configured with access to your Kubernetes cluster
- CINC Auditor installed locally
- Permission to create service accounts, roles, and role bindings in your cluster
- Kubernetes cluster that meets the requirements for existing clusters
Step-by-Step Instructions¶
Step 1: Download Scanner Scripts¶
Security Consideration
Always verify scripts before executing them to ensure they don't contain malicious code.
- Clone the repository to access the scripts:
- Navigate to the scripts directory:
- Make the scripts executable:
Step 2: Understanding Available Scripts¶
Security Consideration
Different scanning approaches have different security implications. Choose the most appropriate one for your security requirements.
The repository includes several scripts for different scanning approaches:
- scan-container.sh: Standard container scanning using the Kubernetes API
- scan-distroless-container.sh: For scanning distroless containers using ephemeral debug containers
- scan-with-sidecar.sh: For scanning containers using the sidecar container approach
- generate-kubeconfig.sh: Helper script to create restricted kubeconfig files
- setup-minikube.sh: For setting up a local testing environment
Step 3: Review Script Security Features¶
Let's examine the security features in the scan-container.sh
script:
Step 4: Basic Container Scanning¶
Security Consideration
This script creates temporary RBAC resources for the duration of the scan and then removes them, minimizing the security risk.
- Scan a standard container using the scan-container.sh script:
Example:
- The script performs these actions:
- Creates a temporary service account
- Creates a role with minimal permissions
- Creates a role binding
- Generates a kubeconfig file with the service account token
- Runs the CINC Auditor scan
- Processes results with SAF-CLI
- Cleans up all resources
Step 5: Distroless Container Scanning¶
Security Consideration
Distroless scanning requires additional permissions for ephemeral containers, which should be handled carefully.
To scan a distroless container:
Example:
The script includes additional code to handle ephemeral debug containers:
Step 6: Sidecar Container Scanning¶
Security Consideration
Sidecar scanning requires shared process namespace, which must be properly secured.
To scan using the sidecar approach:
Example:
The script deploys a pod with shared process namespace:
Step 7: CI/CD Integration¶
Security Consideration
Embedding these scripts in CI/CD pipelines requires secure handling of Kubernetes credentials.
- To use these scripts in a GitHub Actions workflow:
- For GitLab CI:
Security Best Practices¶
- Review script content before execution
- Set restrictive file permissions (700 or 750) on scripts
- Store kubeconfig files securely with 600 permissions
- Use different threshold values for different environments
- Do not store tokens or credentials in version control
- Run scripts with the principle of least privilege
- Always enable script cleanup sections to remove temporary resources
- Verify script execution logs to ensure proper resource cleanup
- Keep scripts updated with the latest security practices
- Consider using OpenSSH's StrictModes feature when executing remotely
Verification Steps¶
- Check that temporary resources are properly cleaned up
- Verify script file permissions
- Verify successful scanning
Troubleshooting¶
Issue | Solution |
---|---|
Permission denied when running scripts | Ensure scripts are executable (chmod +x *.sh ) |
Kubernetes authentication failure | Verify your kubeconfig is valid and has required permissions |
CINC Auditor plugin missing | Install required plugins with cinc-auditor plugin install train-k8s-container |
Container not accessible | Check if pod is running and RBAC permissions are correct |
Script hangs during execution | Check for potential deadlocks or resource constraints |
Resources not cleaned up | Add trap commands to ensure cleanup on script failure |
Next Steps¶
After completing this task, consider:
- Configure scanning thresholds for customized security requirements
- Implement GitLab CI integration for automated scanning
- Set up GitHub Actions workflows for regular security scanning
- Create custom scanning profiles for your specific needs
Related Security Considerations¶
Related Learning Paths¶
Recommended Learning
These learning paths provide additional context and knowledge that will help you understand this task better:
- Implementation Guide - Comprehensive implementation instructions including script deployment
- Core Concepts - Understand the fundamental concepts behind the scanning approaches
- Security-First Implementation - Focus on security aspects of script-based deployment