Label-Based RBAC Configuration¶
This document describes how to implement label-based RBAC for more flexible container scanning access.
Overview¶
Label-based RBAC allows you to grant access to containers based on their labels rather than their names. This approach is more flexible in dynamic environments where pod names change frequently.
Implementation¶
1. Pod Labeling¶
Label your target pods with a designated label:
2. Role Configuration¶
Create a role that doesn't specify resourceNames, but instead relies on the label selector:
Note: This role allows access to all pods in the namespace. The limitation will come from how we use this role.
3. Script-Based Access Control¶
Use a script to:
- Find pods with the target label
- Generate a temporary kubeconfig
- Run InSpec only against those pods
Advanced: LabelSelector with SubjectAccessReview¶
For more robust access control, you can use a Kubernetes ValidatingWebhook to perform SubjectAccessReview based on pod labels. This approach requires additional components:
- A ValidatingWebhookConfiguration
- A webhook server that performs label checks
- Integration with your authentication system
For a full implementation, see the advanced label RBAC section below.
Security Considerations¶
Label-based RBAC is more permissive than name-based RBAC:
- If a pod is mislabeled, it becomes accessible
- Users can potentially scan any pod with the target label
- More complex to audit and trace
Mitigations:
- Strict control over who can apply labels to pods
- Regular auditing of pod labels
- Isolated namespaces for different sensitivity levels
- Time-bound access tokens
Example YAML¶
A complete example configuration is available in the repository under kubernetes/templates/label-rbac.yaml
.