README
ΒΆ
KubeUser
Lightweight Kubernetes-native user management operator that simplifies user authentication and authorization through declarative custom resources.
π Project Overview
KubeUser is a Kubernetes operator that automates user management by providing a declarative API for creating and managing user access to Kubernetes clusters. It streamlines the process of granting temporary or permanent access to users through role-based access control (RBAC).
Why KubeUser?
- Declarative User Management: Define users and their permissions using Kubernetes custom resources
- Certificate Expiry: Automatically tracks and manages certificate expiration
- Certificate-based Authentication: Automatically generates client certificates and kubeconfig files
- RBAC Integration: Seamlessly integrates with existing Kubernetes Role and ClusterRole resources
- Kubernetes Native: Built using controller-runtime, following Kubernetes best practices
- Multi-tenancy Support: Namespace-scoped and cluster-wide permission management
Main Use Cases
- Developer Onboarding: Quickly grant new developers access to specific namespaces
- Certificate Management: Automatic certificate generation and expiration handling
- Audit and Compliance: Centralized user management with clear access tracking
- GitOps Integration: Manage user permissions through version-controlled YAML files
ποΈ Architecture & Features
Architecture Overview
KubeUser follows the standard Kubernetes operator pattern:
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β User CRD βββββΆβ User Controller βββββΆβ RBAC Resources β
β (Custom Res.) β β (Reconciler) β β (Roles/Bindings)β
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β
βΌ
βββββββββββββββββββ
β Certificate & β
β Kubeconfig Gen β
βββββββββββββββββββ
π§ implemented Features
- Reconciliation Loop: Continuous monitoring and enforcement of user permissions
- Finalizers: Proper cleanup of user resources when User objects are deleted
- Certificate Management: Automatic generation of client certificates using Kubernetes CSR API
- Kubeconfig Generation: Creates ready-to-use kubeconfig files stored as secrets
- RBAC Integration: Creates RoleBindings and ClusterRoleBindings based on User spec
- Role Validation: Validates that referenced Roles and ClusterRoles exist
- Webhook validation for User resources
- Certificate rotation and renewal (30 days before expiry)
- High availability: support for multi-replica deployments
- Health Checks: Liveness and readiness probes for robust deployments
π§ Planned Features
- existingClusterRole implementation under user.roles
- User group management with UserGroup crd
- Templated Roles/clusterRoles: Provide predefined reusable RBAC role templates for common use cases
- Audit logging for user access changes
- Metrics Endpoint: Prometheus-compatible metrics on port 8080
π¦ Installation Instructions
Prerequisites
- Kubernetes cluster (v1.28+)
- kubectl configured to access your cluster with cluster-admin permissions
- cert-manager (required for webhook certificates)
- Docker (for building images locally)
- kind or minikube (for local testing)
Install cert-manager
KubeUser requires cert-manager for webhook certificate management:
# Install cert-manager
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.13.0/cert-manager.yaml
# Wait for cert-manager to be ready
kubectl wait --for=condition=ready pod -l app=cert-manager -n cert-manager --timeout=60s
Deployment Options
Option 1: Using Helm (Recommended)
KubeUser publishes Helm charts via GitHub Pages. To install using Helm:
helm repo add kubeuser https://openkube-hub.github.io/KubeUser
helm repo update
# Install a specific released version (recommended)
helm upgrade --install kubeuser kubeuser/kubeuser \
--namespace kubeuser \
--create-namespace \
--version <version>
# List available versions
helm search repo kubeuser --versions
# Upgrade to a new version later
# helm upgrade kubeuser kubeuser/kubeuser -n kubeuser --version <new-version>
# Uninstall
# helm uninstall kubeuser -n kubeuser
Notes:
- All resource names are prefixed by the Helm release name (e.g.,
kubeuser). - The chart defaults the image.tag to the chart version; override with
--set image.tag=<tag>if needed.
Option 2: Using Kustomize
# Clone the repository
git clone https://github.com/openkube-hub/KubeUser.git
cd KubeUser
# Deploy using kustomize
kubectl apply -k config/default
# Wait for controller to be ready
kubectl wait --for=condition=ready pod -l control-plane=controller-manager -n kubeuser --timeout=120s
Option 3: Local Development with kind
For local testing and development:
# Build the Docker image
make docker-build
# Load image into kind cluster
kind load docker-image ghcr.io/openkube-hub/kubeuser-controller:latest --name <your-cluster-name>
# Deploy with local image
kubectl apply -k config/default
# Update deployment to use local image
kubectl patch deployment kubeuser-controller-manager -n kubeuser -p '{"spec":{"template":{"spec":{"containers":[{"name":"manager","imagePullPolicy":"Never"}]}}}}'
Verification
Verify the installation:
# Check controller status
kubectl get pods -n kubeuser
# Check webhook certificate
kubectl get certificates -n kubeuser
# Check CRDs
kubectl get crd users.auth.openkube.io
π Quick Start / Usage
Basic User Creation
Create a user with namespace-scoped access:
apiVersion: auth.openkube.io/v1alpha1
kind: User
metadata:
name: alice
spec:
roles:
- namespace: "development"
existingRole: "developer"
- namespace: "staging"
existingRole: "viewer"
User with Cluster-wide Access
apiVersion: auth.openkube.io/v1alpha1
kind: User
metadata:
name: bob-admin
spec:
clusterRoles:
- existingClusterRole: "cluster-admin"
Mixed Permissions Example
apiVersion: auth.openkube.io/v1alpha1
kind: User
metadata:
name: contractor-jane
spec:
roles:
- namespace: "project-x"
existingRole: "developer"
- namespace: "testing"
existingRole: "tester"
clusterRoles:
- existingClusterRole: "view" # Read-only cluster access
Field Reference
| Field | Type | Required | Description |
|---|---|---|---|
spec.roles |
[]RoleSpec |
No | List of namespace-scoped role bindings |
spec.roles[].namespace |
string |
Yes | Target namespace for the role binding |
spec.roles[].existingRole |
string |
Yes | Name of the existing Role in the namespace |
spec.clusterRoles |
[]ClusterRoleSpec |
No | List of cluster-wide role bindings |
spec.clusterRoles[].existingClusterRole |
string |
Yes | Name of the existing ClusterRole |
Managing Users
# Create sample namespace and role
kubectl create ns dev
kubectl create role developer --verb=get,list,watch --resource=pods -n dev
# Apply user configuration
kubectl apply -f test/test-user.yaml
# Check user status
kubectl get users
kubectl describe user jane
# Get the generated kubeconfig
kubectl get secret jane-kubeconfig -n kubeuser -o jsonpath='{.data.config}' | base64 -d > ~/tmp/kubeconfig
# Test user access
kubectl --kubeconfig ~/tmp/kubeconfig get pods -n dev
# Delete user (cleans up all associated resources)
kubectl delete user jane
Comprehensive Testing
For thorough testing of all features, use the provided test script:
# Run the comprehensive test suite
./test-kubeuser.sh
This script tests:
- Prerequisites validation
- Controller deployment health
- User creation and RBAC bindings
- Certificate generation and kubeconfig creation
- User access validation
- Certificate rotation
- Resource cleanup
Manual Testing Steps
-
Setup test environment:
kubectl apply -f test/test-setup.yaml -
Create a test user:
kubectl apply -f test/test-user-jane-1.yaml -
Verify user creation:
kubectl get users kubectl describe user jane -
Check generated resources:
# Check secrets kubectl get secrets -n kubeuser | grep jane # Check RBAC bindings kubectl get rolebindings -n dev | grep jane kubectl get clusterrolebindings | grep jane # Check CSR (if still present) kubectl get csr -l auth.openkube.io/user=jane -
Test user access:
# Extract kubeconfig kubectl get secret jane-kubeconfig -n kubeuser -o jsonpath='{.data.config}' | base64 -d > /tmp/jane.kubeconfig # Test authentication kubectl --kubeconfig /tmp/jane.kubeconfig auth can-i get pods -n dev # Test actual access kubectl --kubeconfig /tmp/jane.kubeconfig get pods -n dev
βοΈ Configuration
Environment Variables
The operator supports the following environment variables:
| Variable | Default | Description |
|---|---|---|
KUBERNETES_API_SERVER |
https://kubernetes.default.svc |
Kubernetes api address |
π§ Troubleshooting
Common Issues
Controller Pod Not Starting
# Check pod status
kubectl get pods -n kubeuser
# Check pod logs
kubectl logs -n kubeuser deployment/kubeuser-controller-manager
# Check events
kubectl get events -n kubeuser --sort-by=.lastTimestamp
Common causes:
- Missing cert-manager installation
- Webhook certificate not ready
- Image pull issues (for local development)
Webhook Certificate Issues
# Check certificate status
kubectl get certificates -n kubeuser
kubectl describe certificate kubeuser-webhook-cert -n kubeuser
# Check cert-manager logs
kubectl logs -n cert-manager deployment/cert-manager
# Force certificate recreation
kubectl delete certificate kubeuser-webhook-cert -n kubeuser
kubectl apply -k config/default
User Creation Fails
# Check user status
kubectl describe user <username>
# Check controller logs
kubectl logs -n kubeuser deployment/kubeuser-controller-manager | grep -i error
# Check webhook validation
kubectl get validatingwebhookconfiguration kubeuser-validating-webhook-configuration -o yaml
Common causes:
- Referenced roles don't exist
- RBAC permission issues
- Webhook validation failures
Certificate Generation Issues
# Check CSR status
kubectl get csr -l auth.openkube.io/user=<username>
# Check CSR details
kubectl describe csr <csr-name>
# Check controller RBAC permissions
kubectl auth can-i create certificatesigningrequests --as=system:serviceaccount:kubeuser:kubeuser-controller-manager
Getting Help
For additional support:
- Check the comprehensive documentation in
docs/ - Review logs for specific error messages
- Ensure all prerequisites are properly installed
- Verify RBAC permissions are correctly configured
π Documentation
- Certificate Management Guide - Comprehensive certificate management details
- Webhook Validation - Webhook validation and troubleshooting
- Test Script - Automated testing script
π Quick Reference
Essential Commands
# Deploy KubeUser
kubectl apply -k config/default
# Check deployment status
kubectl get pods -n kubeuser
kubectl get certificates -n kubeuser
# Create a user
kubectl apply -f test/test-user-jane-1.yaml
# Get user kubeconfig
kubectl get secret jane-kubeconfig -n kubeuser -o jsonpath='{.data.config}' | base64 -d > jane.kubeconfig
# Test user access
kubectl --kubeconfig jane.kubeconfig auth can-i get pods -n dev
# Clean up
kubectl delete user jane
kubectl delete -k config/default
Key Resources Created
- Namespace:
kubeuser - CRD:
users.auth.openkube.io - Controller:
kubeuser-controller-manager - Webhook:
kubeuser-validating-webhook-configuration - Certificates:
kubeuser-webhook-cert(managed by cert-manager)
User Resource Secrets
For each user, the controller creates:
<username>-key: Private key secret<username>-kubeconfig: Complete kubeconfig file- CSR:
<username>-csr(temporary, cleaned up after use)
π» Development Guide
Prerequisites
- Go: Version 1.24+ (as specified in go.mod)
- Docker: For building container images
- kubectl: Kubernetes command-line tool
- Kind: For local testing (optional but recommended)
- Kustomize: For manifest management
- Kubebuilder: v3.0+ (for code generation)
Local Development Setup
- Clone the repository:
git clone https://github.com/openkube-hub/KubeUser.git
cd KubeUser
- Install dependencies:
go mod tidy
- Generate code and manifests:
make generate
make manifests
- Run tests:
make test
Building and Running Locally
# Build the manager binary
make build
# Run against a Kubernetes cluster (requires kubeconfig)
make run
# Build and load Docker image (requires Docker)
make docker-build
Testing
Unit Tests
# Run all unit tests
make test
# Run tests with coverage
go test ./... -coverprofile=coverage.out
go tool cover -html=coverage.out
End-to-End Tests
# Run e2e tests (creates Kind cluster)
make test-e2e
# Manual e2e testing
make setup-test-e2e # Creates Kind cluster
# ... run manual tests ...
make cleanup-test-e2e # Cleanup
Linting and Code Quality
# Run linter
make lint
# Fix linting issues automatically
make lint-fix
# Verify linting configuration
make lint-config
# Format code
make fmt
# Vet code
make vet
Development Workflow
- Make changes to the code
- Generate code:
make generate manifests - Run tests:
make test - Test locally:
make run - Build image:
make docker-build - Run e2e tests:
make test-e2e
π€ Contributing
We welcome contributions to KubeUser! Please follow these guidelines:
Submitting Pull Requests
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Follow the development setup above
- Make your changes with tests
- Ensure all tests pass:
make test lint - Commit with conventional commit format:
feat: add user group management - Implement UserGroup CRD - Add controller logic for group management - Include comprehensive tests Fixes #123 - Push to your fork:
git push origin feature/amazing-feature - Create a Pull Request
Code Style
- Follow standard Go conventions
- Use
gofmtfor formatting - Pass
golangci-lintchecks - Write comprehensive tests for new features
- Update documentation for user-facing changes
Commit Message Format
We use Conventional Commits:
feat:New featuresfix:Bug fixesdocs:Documentation changestest:Test-related changesrefactor:Code refactoringci:CI/CD changeschore:Maintenance tasks
If you find KubeUser useful, please consider giving it a β on GitHub!