RBAC (Role-Based Access Control)
PiVirt uses Role-Based Access Control (RBAC) to enforce least-privilege security across organizations, namespaces, and virtual machine resources.
RBAC Model
Section titled “RBAC Model”| Role | Permissions | Use Case |
|---|---|---|
| admin | Full access to all resources | Cluster administrators |
| operator | Create, read, update resources (no delete) | Day-to-day operations |
| viewer | Read-only access | Monitoring, auditing |
| vm-owner | Access to own VMs only | End users |
Scopes
Section titled “Scopes”- Cluster: Access to all namespaces
- Namespace: Access to specific namespace
- Resource: Access to specific resource
RBAC Configuration
Section titled “RBAC Configuration”Policy File
Section titled “Policy File”apiVersion: rbac.pivirt.pilab.hu/v1kind: Policyrules: # Admin full access - roles: ["admin"] resources: ["*"] verbs: ["*"]
# Operator: VM lifecycle, no delete - roles: ["operator"] resources: ["virtualmachines", "volumes", "networks"] verbs: ["get", "list", "create", "update", "patch"]
# Viewer: Read-only - roles: ["viewer"] resources: ["*"] verbs: ["get", "list"]
# VM Owner: Own VMs only - roles: ["vm-owner"] resources: ["virtualmachines"] verbs: ["get", "list", "update", "patch", "start", "stop", "console"] conditions: - field: "metadata.owner" operator: "Equals" value: "{{.user.identity}}"Role Bindings
Section titled “Role Bindings”apiVersion: rbac.pivirt.pilab.hu/v1kind: RoleBindingmetadata: name: admin-binding namespace: productionsubjects: - kind: User name: "admin@pilab.hu" - kind: Group name: "platform-team"roleRef: kind: ClusterRole name: "admin"apiVersion: rbac.pivirt.pilab.hu/v1kind: RoleBindingmetadata: name: operator-binding namespace: productionsubjects: - kind: User name: "operator@pilab.hu"roleRef: kind: Role name: "operator"Resources & Verbs
Section titled “Resources & Verbs”Resources
Section titled “Resources”| Resource | Description |
|---|---|
virtualmachines |
VM lifecycle operations |
volumes |
Storage volume management |
networks |
Network configuration |
snapshots |
VM and volume snapshots |
clusters |
Cluster management |
nodes |
Node management |
namespaces |
Namespace management |
serviceaccounts |
Service account management |
roles |
Role definitions |
rolebindings |
Role bindings |
| Verb | Description |
|---|---|
get |
Read single resource |
list |
List multiple resources |
create |
Create new resource |
update |
Update existing resource |
patch |
Partially update resource |
delete |
Delete resource |
watch |
Watch for changes |
start |
Start VM |
stop |
Stop VM |
console |
Access VM console |
Conditions
Section titled “Conditions”Attribute-Based Conditions
Section titled “Attribute-Based Conditions”conditions: - field: "metadata.namespace" operator: "Equals" value: "production"
- field: "metadata.labels.env" operator: "In" values: ["prod", "staging"]
- field: "spec.cpu.cores" operator: "LessThan" value: "8"Time-Based Conditions
Section titled “Time-Based Conditions”conditions: - type: "time" operator: "Between" values: ["09:00", "17:00"] timezone: "Europe/Budapest"IP-Based Conditions
Section titled “IP-Based Conditions”conditions: - type: "source_ip" operator: "In" values: ["10.0.0.0/8", "192.168.0.0/16"]User Management
Section titled “User Management”Create User
Section titled “Create User”# Create user with OIDCpvcli auth user create \ --email "user@pilab.hu" \ --roles "operator" \ --namespace "production"Assign Role
Section titled “Assign Role”# Assign role to userpvcli auth rolebinding create \ --user "user@pilab.hu" \ --role "operator" \ --namespace "production"List Permissions
Section titled “List Permissions”# Check user permissionspvcli auth permissions --user "user@pilab.hu" --namespace "production"
# Check current user permissionspvcli auth permissionsService Accounts
Section titled “Service Accounts”Create Service Account
Section titled “Create Service Account”apiVersion: pivirt.pilab.hu/v1kind: ServiceAccountmetadata: name: ci-pipeline namespace: productionspec: roles: - "operator" token_ttl: "30d"Use Service Account
Section titled “Use Service Account”# Generate API keypvcli auth apikey create \ --service-account "ci-pipeline" \ --namespace "production"
# Use API keyexport PIVIRT_API_KEY="pivirt_apikey_..."pvcli vm listTroubleshooting
Section titled “Troubleshooting”Permission Denied
Section titled “Permission Denied”# Check user rolespvcli auth user get "user@pilab.hu" -o yaml
# Check role bindingspvcli auth rolebinding list --namespace "production"
# Check policycat /etc/pivirt-agent/rbac.yamlCommon Issues
Section titled “Common Issues”| Issue | Resolution |
|---|---|
| Permission denied | Check role bindings, verify RBAC policy |
| Cannot access namespace | Check namespace role binding |
| Cannot delete resource | Check if role has delete permission |
| Service account expired | Regenerate API key |