RBAC Configuration¶
Overview¶
Security Emphasis
Properly configured RBAC is the cornerstone of Kubernetes security. This task implements the principle of least privilege, ensuring that scanner components have only the minimum permissions required to perform their functions, minimizing the potential blast radius of any compromise.
This task guides you through setting up secure Role-Based Access Control (RBAC) for Kube CINC Secure Scanner. Proper RBAC configuration ensures that scanning operations maintain a strong security posture while having sufficient permissions to perform container inspections.
Time to complete: 20-30 minutes
Security risk: 🔴 High - Involves creating security-critical Kubernetes RBAC resources
Security approach: Implements least-privilege access controls, time-limited credentials, and precise permission scoping for container scanning operations
Security Architecture¶
Understanding Permission Layers
RBAC configuration for secure container scanning involves multiple permission layers:
1. Administrative Permissions * Control: Ability to create and manage RBAC resources (Roles, RoleBindings, ClusterRoles) * Risk area: Overly broad administrative access could compromise cluster security * Mitigation: Use dedicated admin service accounts with limited scope for RBAC management
2. Scanner Service Account Permissions * Control: Scanner's ability to interact with target containers through the Kubernetes API * Risk area: Excessive permissions could allow unauthorized container access * Mitigation: Create highly-scoped roles with precise resource and verb limitations
3. Pod-Level Security Context * Control: Container-level permissions affecting the scanner's capabilities * Risk area: Improper security contexts could grant excessive privileges * Mitigation: Apply restrictive pod security contexts with non-root execution
Security Prerequisites¶
- Administrative access to create service accounts, roles, and role bindings in your Kubernetes cluster
- Understanding of Kubernetes RBAC concepts (roles, bindings, service accounts)
- Knowledge of your target container scanning approach (Standard, Distroless, or Sidecar)
- Access to the kubectl command line tool configured for your cluster
Step-by-Step Instructions¶
Step 1: Create a Dedicated Namespace¶
Security Consideration
Using a dedicated namespace isolates scanner resources and simplifies permission management.
- Create a namespace for scanner operations:
- Add labels for better organization:
Step 2: Create a Service Account¶
Security Consideration
Each scanning operation should use a dedicated service account to maintain proper access controls and auditability.
- Create a service account for the scanner:
- For more advanced configuration, use a YAML definition:
Step 3: Create Role for Standard Container Scanning¶
Security Consideration
The role should only grant permissions to the specific resources needed for scanning, avoiding overly broad access.
- Create a role for standard container scanning:
- For target-specific scanning with even tighter restrictions:
Step 4: Create Label-Based RBAC (Advanced)¶
Security Consideration
Label-based RBAC allows for dynamic selection of containers to scan without modifying RBAC configurations.
- Create a role that uses label selectors for more dynamic targeting:
- To use this approach, ensure your target pods have the appropriate label:
Step 5: Create Role Binding¶
Security Consideration
The role binding links the service account to its permissions. Each scan role should have its own binding.
- Create a role binding for the scanner service account:
Step 6: Generate Short-Lived Token¶
Security Consideration
Using short-lived tokens limits the window of credential validity, enhancing security.
- Generate a token with a short expiration time (15 minutes):
- Create a kubeconfig file using this token:
Step 7: Test RBAC Configuration¶
- Verify scanner service account can list pods:
- Verify scanner can execute commands in a target pod:
- Verify the scanner cannot access other namespaces:
Security Best Practices¶
- Create dedicated service accounts for each scanning use case
- Use role bindings scoped to specific namespaces, avoiding cluster-wide permissions
- Generate short-lived tokens (15 minutes or less) for scanning operations
- Implement resource name restrictions when possible to limit access to specific pods
- Use label selectors for dynamic targeting of containers to scan
- Regularly audit and rotate all scanner credentials
- Apply the principle of least privilege by only granting required permissions
- Avoid giving scanner accounts permissions to modify pod specs or create new pods
- Use separate RBAC configurations for CI/CD scanning vs. operational scanning
Verification Steps¶
- Verify proper RBAC scoping
- Test token expiration
- Verify namespace isolation
Troubleshooting¶
Issue | Solution |
---|---|
Permission denied errors | Verify that the role and role binding are correctly configured and the service account has the necessary permissions |
Token expired errors | Generate a new token using kubectl create token with an appropriate duration |
Cannot access target pod | Check that the pod is in the correct namespace and that resourceNames are correctly specified in the role |
Cannot create token | Ensure you're using Kubernetes 1.24+ or implement an alternative token generation method for older versions |
Label selector not working | Verify that pods have the correct labels and that the label selector syntax is correct |
Next Steps¶
After completing this task, consider:
- Configure token management for more advanced credential handling
- Implement GitLab CI integration using the RBAC configuration
- Set up GitHub Actions integration with secure scanner credentials
- Configure namespace-specific scanning for multi-tenant environments