TLS & Mutual mTLS Configuration
PiVirt enforces TLS 1.3 encryption for data in transit and mutual TLS (mTLS) for authenticated daemon-to-daemon communication across the cluster.
TLS Configuration
Section titled “TLS Configuration”Server TLS
Section titled “Server TLS”# pivirtd configserver: grpc_addr: "0.0.0.0:9001" tls: cert_file: "/etc/pivirtd/tls/server.crt" key_file: "/etc/pivirtd/tls/server.key" ca_file: "/etc/pivirtd/tls/ca.crt"Client TLS (pvcli)
Section titled “Client TLS (pvcli)”# pvcli configcontexts: - name: "production" endpoint: "pivirtd-prod.pilab.hu:9001" tls: ca_file: "~/.config/pvcli/ca.crt" cert_file: "~/.config/pvcli/client.crt" key_file: "~/.config/pvcli/client.key"mTLS Configuration
Section titled “mTLS Configuration”Mutual Authentication
Section titled “Mutual Authentication”# agent configserver: connectrpc: addr: "0.0.0.0:8443" tls: cert_file: "/etc/pivirt-agent/tls/server.crt" key_file: "/etc/pivirt-agent/tls/server.key" ca_file: "/etc/pivirt-agent/tls/ca.crt" client_ca_file: "/etc/pivirt-agent/tls/ca.crt" # Require client certsPiTrust mTLS Configuration
Section titled “PiTrust mTLS Configuration”# agent configtls: enabled: true ca_file: "/etc/pivirt/certs/ca-chain.pem" cert_file: "/etc/pivirt/certs/agent-client.crt" key_file: "/etc/pivirt/certs/agent-client.key" verify_peer: true require_client_cert: trueCertificate Management
Section titled “Certificate Management”Generate CA
Section titled “Generate CA”# Generate CA private keyopenssl genrsa -out ca.key 4096
# Generate CA certificateopenssl req -new -x509 -days 3650 -key ca.key -out ca.crt \ -subj "/CN=PiVirt CA/O=PiLab/C=HU"Generate Server Certificate
Section titled “Generate Server Certificate”# Generate server private keyopenssl genrsa -out server.key 2048
# Generate CSRopenssl req -new -key server.key -out server.csr \ -subj "/CN=pivirtd.pilab.hu/O=PiLab/C=HU"
# Sign with CAopenssl x509 -req -days 365 -in server.csr -CA ca.crt -CAkey ca.key \ -CAcreateserial -out server.crt \ -extfile <(echo "subjectAltName=DNS:pivirtd.pilab.hu,DNS:localhost,IP:127.0.0.1")Generate Client Certificate
Section titled “Generate Client Certificate”# Generate client private keyopenssl genrsa -out client.key 2048
# Generate CSRopenssl req -new -key client.key -out client.csr \ -subj "/CN=admin@pilab.hu/O=PiLab/C=HU"
# Sign with CAopenssl x509 -req -days 365 -in client.csr -CA ca.crt -CAkey ca.key \ -CAcreateserial -out client.crtVerify Certificate
Section titled “Verify Certificate”# Verify certificate chainopenssl verify -CAfile ca.crt server.crt
# View certificate detailsopenssl x509 -in server.crt -text -noout
# Check certificate expiryopenssl x509 -in server.crt -enddate -nooutPiTrust Automated Certificate Management
Section titled “PiTrust Automated Certificate Management”Automated Rotation via Kubernetes Operator
Section titled “Automated Rotation via Kubernetes Operator”# ManagedCertificate CRD for automated mTLS issuance and renewalapiVersion: certz.pilab.hu/v1alpha1kind: ManagedCertificatemetadata: name: pivirt-agent-tls namespace: pivirt-systemspec: commonName: agent.pivirt.svc.cluster.local type: mtls-server secretName: pivirt-agent-tls-secret duration: "8760h" renewBefore: "720h" # Auto-renews 30 days before expirationDirect CLI Certificate Issuance
Section titled “Direct CLI Certificate Issuance”# Issue mTLS server certpitrust issue-mtls-server --name "pivirtd.pilab.hu" --dns "pivirtd.pilab.hu" --days 365
# Issue mTLS client certpitrust issue-mtls-client --name "agent.pilab.hu" --days 365TLS Versions & Ciphers
Section titled “TLS Versions & Ciphers”Recommended Configuration
Section titled “Recommended Configuration”# agent configserver: connectrpc: tls: min_version: "1.2" cipher_suites: - "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384" - "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256" - "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384" - "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256"Certificate Pinning
Section titled “Certificate Pinning”Pin CA Certificate
Section titled “Pin CA Certificate”# Extract CA fingerprintopenssl x509 -in ca.crt -noout -fingerprint -sha256
# Configure pinning in pvclipvcli config set-context production \ --ca-fingerprint "SHA256:abc123..."Troubleshooting
Section titled “Troubleshooting”Certificate Errors
Section titled “Certificate Errors”# Check certificate validityopenssl x509 -in server.crt -text -noout | grep -E "(Not Before|Not After)"
# Verify certificate chainopenssl verify -CAfile ca.crt server.crt
# Check SAN (Subject Alternative Name)openssl x509 -in server.crt -text -noout | grep -A1 "Subject Alternative Name"Common Issues
Section titled “Common Issues”| Issue | Resolution |
|---|---|
| Certificate expired | Regenerate certificate or check PiTrust operator |
| Unknown CA | Install CA certificate in trust store |
| SAN mismatch | Regenerate certificate with correct SAN |
| Handshake failure | Check TLS version, cipher suites |
Debug TLS
Section titled “Debug TLS”# Test TLS connectionopenssl s_client -connect pivirtd.pilab.hu:9001 -CAfile ca.crt
# Debug with verbose outputopenssl s_client -connect pivirtd.pilab.hu:9001 -CAfile ca.crt -debug
# Check certificate chainopenssl s_client -connect pivirtd.pilab.hu:9001 -showcerts