Managed Kubernetes Cluster Configuration
Problem Description
Managed Kubernetes clusters like AKS (Azure Kubernetes Service), EKS (Amazon Elastic Kubernetes Service), etc., typically use exec plugins in their default kubeconfig to dynamically obtain authentication credentials. For example:
- AKS uses the
kubelogincommand - EKS uses the
awsCLI - GKE uses the
gcloudcommand - GitLab Agent uses the
glabcommand
This authentication method works well in local client environments, but can be challenging in server-side environments like Kube Sentinel because:
- These CLI tools may not be installed on the server
- Even if installed, the server environment may not have the corresponding authentication configuration
- Managing different user credentials in multi-tenant scenarios is difficult
Kube Sentinel provides two ways to solve this: Managed Authentication Support (for AWS and GitLab) and Service Account Tokens (for all others).
Managed Authentication Support [NEW]
Kube Sentinel natively supports authentication for specific managed Kubernetes providers by securely managing your credentials and injecting them into the CLI tools.
AWS EKS Authentication
For EKS clusters, Kube Sentinel supports authentication via aws or aws-iam-authenticator.
- Configure AWS Credentials: Navigate to Settings > AWS Settings and paste your AWS credentials file content (typically found at
~/.aws/credentials). - Add Cluster: Import your EKS kubeconfig. Kube Sentinel will detect the
awsexec command. - Secure Injection: The system automatically injects the
AWS_SHARED_CREDENTIALS_FILEenvironment variable for your requests, ensuring you only use your own credentials.
GitLab Agent Authentication
For clusters managed via GitLab Agent, Kube Sentinel supports authentication using the glab CLI.
- Configure GitLab Token: Navigate to Settings > GitLab Settings, add your GitLab host (e.g.,
gitlab.com), and provide a Personal Access Token (PAT). - Validate: Click Validate to initialize your
glabsession. - Add Cluster: Import your cluster kubeconfig that uses
glabfor authentication. - Context Management: Kube Sentinel automatically manages the
GLAB_CONFIG_DIRto use your validated session.
NOTE
Support for other managed providers like AKS (Azure) and GKE (Google) is coming soon.
Alternative: Using Service Account Token
If your provider is not yet natively supported, or if you prefer a more generic approach, you can create a dedicated Service Account for Kube Sentinel and use its token for authentication.
Kube Sentinel provides a helper script for creation:
wget https://raw.githubusercontent.com/pixelvide/kube-sentinel/refs/heads/main/scripts/generate-kube-sentinel-kubeconfig.sh -O generate-kube-sentinel-kubeconfig.sh
chmod +x generate-kube-sentinel-kubeconfig.sh
./generate-kube-sentinel-kubeconfig.shManual Steps:
- Create Service Account and RBAC permissions:
apiVersion: v1
kind: ServiceAccount
metadata:
name: kube-sentinel-admin
namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: kube-sentinel-admin
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: kube-sentinel-admin
namespace: kube-system- Create Long-lived Token Secret (Kubernetes 1.24+):
apiVersion: v1
kind: Secret
metadata:
name: kube-sentinel-admin-token
namespace: kube-system
annotations:
kubernetes.io/service-account.name: kube-sentinel-admin
type: kubernetes.io/service-account-token- Get token and cluster information:
# Get token
TOKEN=$(kubectl get secret kube-sentinel-admin-token -n kube-system -o jsonpath='{.data.token}' | base64 -d)
# Get CA certificate
CA_CERT=$(kubectl get secret kube-sentinel-admin-token -n kube-system -o jsonpath='{.data.ca\.crt}')
# Get API Server address
API_SERVER=$(kubectl config view --minify -o jsonpath='{.clusters[0].cluster.server}')- Generate kubeconfig:
cat > kube-sentinel-kubeconfig.yaml <<EOF
apiVersion: v1
kind: Config
clusters:
- cluster:
certificate-authority-data: ${CA_CERT}
server: ${API_SERVER}
name: kube-sentinel-cluster
contexts:
- context:
cluster: kube-sentinel-cluster
user: kube-sentinel-admin
name: kube-sentinel-context
current-context: kube-sentinel-context
users:
- name: kube-sentinel-admin
user:
token: ${TOKEN}
EOF