Kubeconfig Security Considerations¶
This document outlines important security considerations when working with kubeconfig files for InSpec container scanning.
File Permissions¶
Always set restrictive permissions on kubeconfig files:
This ensures only the file owner can read or write to the file, preventing unauthorized access.
Token Expiration¶
Service account tokens have expiration times. For enhanced security, use shorter-lived tokens:
In CI/CD environments, generate tokens with just enough time for the scanning job to complete.
Namespace Limitation¶
The kubeconfig sets a default namespace, but doesn't restrict access to that namespace. Access control still relies on the RBAC configuration. For proper security:
- Apply appropriate RBAC rules to limit service accounts
- Use label-based RBAC for fine-grained access control
- Specify the namespace in the context to set a default, but don't rely on it for security
Environment Variable Security¶
When using the KUBECONFIG
environment variable:
Be aware that environment variables may be visible in process listings or logs. In shared environments, prefer file-based configuration with proper permissions.
Secret Management¶
In CI/CD environments, store kubeconfig files as secrets:
GitHub Actions¶
GitLab CI¶
Multiple Environments¶
For different environments (dev, test, prod), create separate kubeconfig files with appropriate RBAC permissions:
This approach prevents development credentials from accessing production systems.
Audit and Rotation¶
Regularly rotate service account tokens and audit kubeconfig usage: